Hi, so for this problem, my initial thought was to do it exactly as stated
in the solution for it, but I thought I came up with a more creative/better
way to do it by creating pseudo calendars using an array.
For some reason I was getting WA the whole time and because I started super
late, I couldn't debug it. Spent a couple of hours trying not really sure
what's wrong.
Can someone help me out please? It's using java
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(
System.in)));
int t = in.nextInt(); // Scanner has functions to read ints, longs,
strings, chars, etc.
for (int i = 1; i <= t; ++i) {
int n = in.nextInt();
//schedules for c and j false is free true is busy 0-1440
int[] c = new int[1441];
int[] j = new int[1441];
boolean busyC = false;
boolean busyJ = false;
boolean impossibleFlag = false;
int start = 0;
int end = 0;
String output = "";
//go through n tasks to try and assign
for(int x=1; x<=n; x++){
start = in.nextInt();
end = in.nextInt();
if(!impossibleFlag) {
for(int k=start; k<end; k++){
//check schedule for c and j
if(c[k]==1){
busyC = true;
}
if(j[k]==1){
busyJ = true;
}
}
if(!busyC){
output+="C";
//fill C's schedule
for(int k=start; k<end; k++){
c[k] = 1;
}
}
else if(!busyJ){
output+="J";
//fill J's schedule
for(int k=start; k<end; k++){
j[k] = 1;
}
}
else{
output="IMPOSSIBLE";
impossibleFlag = true;
}
busyC=false;
busyJ=false;
}
}
System.out.println("Case #" + i + ": " + output);
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/479e900f-0815-45cf-80d2-e311b1bf156d%40googlegroups.com.