-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
112 lines (106 loc) · 2.7 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
112 lines (106 loc) · 2.7 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
112
diff --git a/CodeJam/Main.cpp b/examples/2020/Qualification/D_interactive/Main.cpp
index 2150379..4e8ebd1 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2020/Qualification/D_interactive/Main.cpp
@@ -1,11 +1,11 @@
// #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_MODE //remove comment on this line, to activate interactive problem mode
+#define IA_ERROR_CODE "N"
#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
@@ -1566,15 +1566,91 @@ using namespace std;
namespace task {
+ll B;
void init(){
- cin >> T;
+ cin >> T >> B;
}
+v(bool) start;
+v(bool) end;
+
void readInput(){
+ start.cl;
+ end.cl;
+}
+
+void invert(){
+ forn(i, start.sz){
+ start[i] = !start[i];
+ end[i] = !end[i];
+ }
+}
+
+bool ask(ll pos){
+ out(pos+1);
+ return in() == "1";
+}
+
+void reorganize(){
+ ll same_pos = 0;
+ while(same_pos < start.sz){
+ if(start[same_pos] == end[same_pos]){
+ break;
+ }
+ same_pos++;
+ }
+ if(same_pos == start.sz){
+ ask(0);
+ } else {
+ bool bit = ask(same_pos);
+ if(bit != start[same_pos]){
+ invert();
+ }
+ }
+ ll diff_pose = 0;
+ while(diff_pose < start.sz){
+ if(start[diff_pose] != end[diff_pose]){
+ break;
+ }
+ diff_pose++;
+ }
+ if(diff_pose == start.sz){
+ ask(0);
+ } else {
+ bool bit = ask(diff_pose);
+ if(bit != start[diff_pose]){
+ v(bool) t = start;
+ start = end;
+ end = t;
+ }
+ }
}
// write to COMM_TYPE result
void calcFunction() {
+ while(start.sz + end.sz < B){
+ reorganize();
+ forn(i, 4){
+ start.pb(ask(start.sz));
+ end.pb(ask(B-1-end.sz));
+ }
+ }
+ reorganize();
+ while(start.sz + end.sz > B){
+ start.popb;
+ end.popb;
+ }
+ sstr outr;
+ foreachc(bit, start){
+ if(bit) outr << "1"; else outr << "0";
+ }
+ forn(i, end.sz){
+ if(end[end.sz-1-i]) outr << "1"; else outr << "0";
+ }
+ llog("start", start);
+ llog("end", end);
+ out(outr.str());
+ in();
}
} // namespace task