-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdiff_Main.cpp
More file actions
88 lines (85 loc) · 2.33 KB
/
Copy pathdiff_Main.cpp
File metadata and controls
88 lines (85 loc) · 2.33 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
diff --git a/CodeJam/Main.cpp b/examples/2019/Round1C/C/Main.cpp
index 2150379..d085a6d 100644
--- a/CodeJam/Main.cpp
+++ b/examples/2019/Round1C/C/Main.cpp
@@ -1570,11 +1570,83 @@ void init(){
cin >> T;
}
+ll R, C;
+bool block[15][15];
+ll nimber[16][16][16][16];
+
void readInput(){
+ cin >> R >> C;
+ char t;
+ forn(r, R) forn(c, C){
+ cin >> t;
+ block[r][c] = t=='#';
+ }
+ forn(i, 16) forn(j, 16) forn(k, 16) forn(l, 16) nimber[i][j][k][l] = -1;
+}
+
+ll mex(s(ll) vals){
+ ll c = 0;
+ foreach(v, vals){
+ if(v==c){
+ c++;
+ continue;
+ }
+ return c;
+ }
+ return c;
+}
+
+ll recur(ll rl, ll ru, ll clow, ll cu){
+ if(nimber[rl][ru][clow][cu] >= 0) return -1;
+ if(rl == ru || clow == cu){
+ nimber[rl][ru][clow][cu] = 0;
+ return 0;
+ }
+ lassert(rl<ru, "no valid row bounds");
+ lassert(0<=rl, "no valid row bounds");
+ lassert(ru<=R, "no valid row bounds");
+ lassert(clow<cu, "no valid col bounds");
+ lassert(0<=clow, "no valid col bounds");
+ lassert(cu<=C, "no valid col bounds");
+
+ s(ll) found_nimber_moves;
+ ll win_move_count = 0;
+
+ fornn(rmove, rl, ru){
+ bool move_valid=true;
+ fornn(c, clow, cu)
+ if(block[rmove][c]){
+ move_valid=false;
+ break;
+ }
+ if(!move_valid) continue;
+ recur(rl, rmove, clow, cu);
+ recur(rmove+1, ru, clow, cu);
+ ll cur_nimber = nimber[rl][rmove][clow][cu] ^ nimber[rmove+1][ru][clow][cu];
+ if(cur_nimber == 0) win_move_count+=cu-clow;
+ found_nimber_moves.insert(cur_nimber);
+ }
+ fornn(cmove, clow, cu){
+ bool move_valid=true;
+ fornn(r, rl, ru)
+ if(block[r][cmove]){
+ move_valid=false;
+ break;
+ }
+ if(!move_valid) continue;
+ recur(rl, ru, clow, cmove);
+ recur(rl, ru, cmove+1, cu);
+ ll cur_nimber = nimber[rl][ru][clow][cmove] ^ nimber[rl][ru][cmove+1][cu];
+ if(cur_nimber == 0) win_move_count+=ru-rl;
+ found_nimber_moves.insert(cur_nimber);
+ }
+ nimber[rl][ru][clow][cu] = mex(found_nimber_moves);
+ return win_move_count;
}
// write to COMM_TYPE result
void calcFunction() {
+ result = recur(0, R, 0, C);
}
} // namespace task