I am trying to solve Parenting Partnering Returns in CodeJam 2020
Qualifying round.
I am getting the wrong answer response for my code. Can anyone help me know
what is wrong?
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(new BufferedReader(new
InputStreamReader(System.in)));
int T = sc.nextInt();
for(int i = 0;i < T;i++) {
int N = sc.nextInt();
Integer[][] arr = new Integer[N][3]; //This stores
{starting,ending,activity number} for each activity
for(int l = 0;l<N;l++) {
arr[l][0] = sc.nextInt();
arr[l][1] = sc.nextInt();
arr[l][2] = l+1;
}
Arrays.sort(arr, new Comparator<Integer[]>() {
@Override
//arguments to this method represent the arrays to be
sorted
public int compare(Integer[] o1, Integer[] o2) {
//get the item ids which are at index 0 of the array
Integer itemIdOne = o1[0];
Integer itemIdTwo = o2[0];
// sort on item id
return itemIdOne.compareTo(itemIdTwo);
}
});
String s = "";
int C = 0;
int J = 0;
boolean cam = false;
boolean jam = false;
for(int n = 0;n<N;n++) {
if(arr[n][0] > arr[n][1]) {
s = "IMPOSSIBLE";
break;
}
if(cam) {
if(arr[n][0] >= C) {
cam = false;
}
}
if(jam) {
if(arr[n][0] >= J) {
jam = false;
}
}
if(!cam) {
s = s + "C";
C = arr[n][1];
cam = true;
}
else if(!jam) {
s = s + "J";
J = arr[n][1];
// System.out.println(J);
jam = true;
}
else if(cam && jam) {
s = "IMPOSSIBLE";
break;
}
}
//System.out.println(s);
String result = new String();
if(s == "IMPOSSIBLE") {
System.out.println("Case #"+(i+1)+": "+s);
}
else {
for(int n = 0;n<N;n++) {
//System.out.println(arr[n][2]);
result = result + Character.toString(s.charAt(arr[n][2]-1));
}
System.out.println("Case #"+(i+1)+": "+result);
}
}
sc.close();
}
}
Output from my local idea :
6
3
360 480
420 540
600 660
Case #1: CJC
3
0 1440
1 3
2 4
Case #2: IMPOSSIBLE
5
99 150
1 100
100 301
2 5
150 250
Case #3: JCCJJ
2
0 720
720 1440
Case #4: CC
2
1 10
1 10
Case #5: CJ
2
1 10
100 90
Case #6: IMPOSSIBLE
--
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/8891299c-db6e-4732-a9e1-6e64e1cf35f9%40googlegroups.com.