- Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathParentingPartneringReturns.java
80 lines (66 loc) · 2.28 KB
/
ParentingPartneringReturns.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Problem Link - https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/000000000020bdf9
*/
importjava.util.*;
classtimeimplementsComparable<time>{
intstart;
intend;
time(ints, inte){
start = s;
end = e;
}
publicintcompareTo(timet){
if(this.start == t.start) return0;
elseif(this.start > t.start) return1;
elsereturn -1;
}
}
classSolution{
publicstaticvoidmain(Stringargs[]){
Scanners = newScanner(System.in);
intt = s.nextInt();
for(inti=0;i<t;i++){
intn = s.nextInt();
ArrayList<time> l = newArrayList<time>();
HashMap<String, ArrayList<Integer>> indexMap = newHashMap<String,ArrayList<Integer>>();
for(intj=0;j<n;j++){
intss = s.nextInt();
inte = s.nextInt();
timetm = newtime(ss,e);
l.add(tm);
Stringkey = ss+"|"+e;
ArrayList<Integer> val = indexMap.getOrDefault(key,newArrayList<Integer>());
val.add(j);
indexMap.put(key,val);
}
Collections.sort(l);
intltej = Integer.MIN_VALUE;
intltec = Integer.MIN_VALUE;
charres[] = newchar[n];
intcnt = 0;
for(intj=0;j<n;j++){
timetm = l.get(j);
Stringkey = tm.start+"|"+tm.end;
ArrayList<Integer> index = indexMap.get(key);
intind = index.get(0);
index.remove(0);
indexMap.put(key,index);
if(ltej <= tm.start){
res[ind] = 'J';
ltej = tm.end;
cnt++;
}
elseif(ltec <= tm.start){
res[ind] = 'C';
ltec = tm.end;
cnt++;
}
else{
break;
}
}
if(cnt != n) System.out.println("Case #"+(i+1)+": IMPOSSIBLE");
elseSystem.out.println("Case #"+(i+1)+": " + String.valueOf(res));
}
}
}