-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
111 lines (107 loc) · 2.74 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
111 lines (107 loc) · 2.74 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
diff --git a/CodeJam/Main.cpp b/examples/2020/Qualification/C/Main.cpp
index 2150379..1385033 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2020/Qualification/C/Main.cpp
@@ -1,11 +1,11 @@
-// #define DEFAULT_VAL_MODE //remove comment on this line, to activate default value trigger
+#define DEFAULT_VAL_MODE //remove comment on this line, to activate default value trigger
#define DEFAULT_VAL_TRIGGER result.sz == 0
#define DEFAULT_VAL "IMPOSSIBLE"
// #define IA_MODE //remove comment on this line, to activate interactive problem mode
#define IA_ERROR_CODE -1
#define IA_COMM_LOG //add comment on this line, to deactivate the interactive communication error log
// #define XY_NOTATION //remove commment on this line, to activate xy notation on complex numbers
-#define COMM_TYPE ll
+#define COMM_TYPE str
// The maintained and empty code template can be found at:
// https://github.com/demmerichs/CodeJamTemplate
@@ -1570,11 +1570,92 @@ void init(){
cin >> T;
}
+ll N;
+v(ll) Si, Ei;
+
void readInput(){
+ Si.cl;
+ Ei.cl;
+ cin >> N;
+ ll s,e;
+ forn(i,N){
+ cin >> s >> e;
+ Si.pb(s);
+ Ei.pb(e);
+ }
+}
+
+v(v(ll)) overlaps;
+void compute_overlaps(){
+ overlaps.cl;
+ overlaps = v(v(ll))(N);
+ forn(i, N){
+ forn(j,i){
+ if(Si[i]<Ei[j] && Ei[i]>Si[j]){
+ overlaps[i].pb(j);
+ overlaps[j].pb(i);
+ }
+ }
+ }
+}
+
+v(ll) resultv;
+
+bool recur(ll act, ll p){
+ lassert(1<=p, "1<=p");
+ lassert(2>=p, "2>=p");
+ if(resultv[act] > 0 && resultv[act] != p){
+ return false;
+ }
+ if(resultv[act] == p){
+ return true;
+ }
+ resultv[act] = p;
+ if(overlaps[act].sz == 0){
+ return true;
+ } else {
+ foreach(other_act, overlaps[act]){
+ bool r = recur(other_act, 3-p);
+ if(!r){
+ return false;
+ }
+ }
+ return true;
+ }
}
// write to COMM_TYPE result
void calcFunction() {
+ compute_overlaps();
+ llog(overlaps);
+ resultv.cl;
+ resultv = v(ll)(N, 0);
+ result.cl;
+ bool possible=true;
+ while(true){
+ ll unfilled = distance(resultv.bn, find(all(resultv), 0));
+ if(unfilled != resultv.sz){
+ llog("resultv", resultv);
+ possible &= recur(unfilled, 1);
+ llog("resultv", resultv);
+ if(!possible){
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ if(possible){
+ foreach(p, resultv){
+ if(p==1){
+ result += "C";
+ } else{
+ lassert(p==2,"p==2");
+ result += "J";
+ }
+ }
+ }
+
}
} // namespace task