dsh-eval-guard 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +91 -13
  2. package/assets/commit0/instance.json +30 -0
  3. package/assets/commit0/workspace.zip +0 -0
  4. package/assets/featurebench/hidden/test_regression.py +690 -0
  5. package/assets/featurebench/instance.json +16 -0
  6. package/assets/featurebench/workspace.zip +0 -0
  7. package/assets/swe-bench-pro/hidden/test.patch +36 -0
  8. package/assets/swe-bench-pro/instance.json +10 -0
  9. package/assets/swe-bench-pro/workspace.zip +0 -0
  10. package/eval/README.md +18 -0
  11. package/eval/arena/arena/README.md +21 -0
  12. package/eval/arena/arena/bt.py +104 -0
  13. package/eval/arena/arena/clock.py +15 -0
  14. package/eval/arena/arena/core.py +265 -0
  15. package/eval/arena/arena/run.cmd +24 -0
  16. package/eval/arena/arena/run.sh +11 -0
  17. package/eval/arena/arena/schedule.py +79 -0
  18. package/eval/arena/arena/tournament.py +183 -0
  19. package/eval/arena/bomberman/bots/README.md +16 -0
  20. package/eval/arena/bomberman/bots/deepseek-v4.1-flash.cpp +447 -0
  21. package/eval/arena/bomberman/bots/doubao-seed-2.1.cpp +542 -0
  22. package/eval/arena/bomberman/bots/glm-5.3.cpp +406 -0
  23. package/eval/arena/bomberman/bots/gpt-6-astra.cpp +768 -0
  24. package/eval/arena/bomberman/bots/gpt-6-sol.cpp +444 -0
  25. package/eval/arena/bomberman/bots/kimi-k3.cpp +432 -0
  26. package/eval/arena/bomberman/bots/mimo-v2.6-pro.cpp +529 -0
  27. package/eval/arena/bomberman/bots/opus-5.5.cpp +548 -0
  28. package/eval/arena/bomberman/bots/qwen-3.8-max.cpp +836 -0
  29. package/eval/arena/bomberman/tournament/README.md +11 -0
  30. package/eval/arena/bomberman/tournament/bt.py +56 -0
  31. package/eval/arena/bomberman/tournament/evaluate.py +199 -0
  32. package/eval/arena/bomberman/tournament/run.py +79 -0
  33. package/eval/arena/bomberman/tournament/schedule-2to10.json.gz +0 -0
  34. package/eval/arena/bomberman/workspace/MANIFEST.json +13 -0
  35. package/eval/arena/bomberman/workspace/README.md +29 -0
  36. package/eval/arena/bomberman/workspace/RULES.md +100 -0
  37. package/eval/arena/bomberman/workspace/baseline.cpp +240 -0
  38. package/eval/arena/bomberman/workspace/clock.py +25 -0
  39. package/eval/arena/bomberman/workspace/engine/arena.py +198 -0
  40. package/eval/arena/bomberman/workspace/engine/build.py +35 -0
  41. package/eval/arena/bomberman/workspace/engine/engine.py +256 -0
  42. package/eval/arena/bomberman/workspace/engine/verify_replay.py +24 -0
  43. package/eval/arena/bomberman/workspace/run.cmd +28 -0
  44. package/eval/arena/bomberman/workspace/run.sh +16 -0
  45. package/eval/arena/bomberman/workspace/viewer/index.html +42 -0
  46. package/eval/arena/ctf/bots/README.md +18 -0
  47. package/eval/arena/ctf/bots/deepseek-v4.1-flash.cpp +601 -0
  48. package/eval/arena/ctf/bots/doubao-seed-2.1-turbo.cpp +320 -0
  49. package/eval/arena/ctf/bots/fable-5.1.cpp +634 -0
  50. package/eval/arena/ctf/bots/glm-5.3.cpp +689 -0
  51. package/eval/arena/ctf/bots/gpt-6-astra.cpp +657 -0
  52. package/eval/arena/ctf/bots/gpt-6.1-sol.cpp +725 -0
  53. package/eval/arena/ctf/bots/kimi-k3.cpp +667 -0
  54. package/eval/arena/ctf/bots/mimo-v2.6-pro.cpp +533 -0
  55. package/eval/arena/ctf/bots/opus-5.5.cpp +645 -0
  56. package/eval/arena/ctf/bots/qwen-3.8-max.cpp +726 -0
  57. package/eval/arena/ctf/bots/sonnet-5.5.cpp +569 -0
  58. package/eval/arena/ctf/tournament/README.md +15 -0
  59. package/eval/arena/ctf/tournament/formal-2to8.json +31 -0
  60. package/eval/arena/ctf/tournament/formal-9to15.json +31 -0
  61. package/eval/arena/ctf/workspace/README.md +41 -0
  62. package/eval/arena/ctf/workspace/RULES.md +119 -0
  63. package/eval/arena/ctf/workspace/arena.py +186 -0
  64. package/eval/arena/ctf/workspace/baseline.cpp +257 -0
  65. package/eval/arena/ctf/workspace/clock.py +15 -0
  66. package/eval/arena/ctf/workspace/core.py +265 -0
  67. package/eval/arena/ctf/workspace/engine.py +389 -0
  68. package/eval/arena/ctf/workspace/run.cmd +24 -0
  69. package/eval/arena/ctf/workspace/run.sh +11 -0
  70. package/eval/arena/ctf/workspace/viewer.html +71 -0
  71. package/eval/arena/land/bots/README.md +17 -0
  72. package/eval/arena/land/bots/deepseek-4.1f@workbuddy#1/bot.cpp +608 -0
  73. package/eval/arena/land/bots/glm-5.3@workbuddy#1/bot.cpp +521 -0
  74. package/eval/arena/land/bots/gpt-6-astra@codex#1/bot.cpp +373 -0
  75. package/eval/arena/land/bots/gpt-6-sol@codex#1/bot.cpp +341 -0
  76. package/eval/arena/land/bots/kimi-k3@workbuddy#1/bot.cpp +492 -0
  77. package/eval/arena/land/bots/mimo-2.6-pro@zcode#1/bot.cpp +652 -0
  78. package/eval/arena/land/bots/mystery-model@zcode#1/bot.cpp +466 -0
  79. package/eval/arena/land/bots/opus-5.5@claude-code#1/bot.cpp +630 -0
  80. package/eval/arena/land/bots/sonnet-5@claude-code#1/bot.cpp +619 -0
  81. package/eval/arena/land/tournament/make_replay_page.py +17 -0
  82. package/eval/arena/land/tournament/rate.py +290 -0
  83. package/eval/arena/land/tournament/round_robin.py +172 -0
  84. package/eval/arena/land/tournament/sparring.cpp +356 -0
  85. package/eval/arena/land/workspace/RULES.md +114 -0
  86. package/eval/arena/land/workspace/TASK.md +46 -0
  87. package/eval/arena/land/workspace/anchors/.build/greedy_f2e6d2dea5ca +0 -0
  88. package/eval/arena/land/workspace/anchors/greedy.cpp +194 -0
  89. package/eval/arena/land/workspace/anchors/random.cpp +80 -0
  90. package/eval/arena/land/workspace/clock.py +64 -0
  91. package/eval/arena/land/workspace/engine/build.py +33 -0
  92. package/eval/arena/land/workspace/engine/game.py +273 -0
  93. package/eval/arena/land/workspace/engine/referee.py +308 -0
  94. package/eval/arena/land/workspace/starter/.build/bot_be32b45b4699 +0 -0
  95. package/eval/arena/land/workspace/starter/bot.cpp +82 -0
  96. package/eval/arena/land/workspace/viewer/viewer.html +210 -0
  97. package/eval/arena/tank/bots/README.md +24 -0
  98. package/eval/arena/tank/bots/half1/deepseek-v4.1-flash.cpp +367 -0
  99. package/eval/arena/tank/bots/half1/doubao-seed-evolving.cpp +402 -0
  100. package/eval/arena/tank/bots/half1/gemini-4-argon.cpp +1132 -0
  101. package/eval/arena/tank/bots/half1/glm-5.3.cpp +551 -0
  102. package/eval/arena/tank/bots/half1/gpt-6-astra.cpp +233 -0
  103. package/eval/arena/tank/bots/half1/gpt-6.1-sol-ultrafast.cpp +350 -0
  104. package/eval/arena/tank/bots/half1/gpt-6.1-sol.cpp +78 -0
  105. package/eval/arena/tank/bots/half1/grok-4.7.cpp +1099 -0
  106. package/eval/arena/tank/bots/half1/haiku-5.5.cpp +210 -0
  107. package/eval/arena/tank/bots/half1/kimi-k3.cpp +353 -0
  108. package/eval/arena/tank/bots/half1/mimo-v2.6-pro.cpp +336 -0
  109. package/eval/arena/tank/bots/half1/muse-wonder-full.cpp +560 -0
  110. package/eval/arena/tank/bots/half1/opus-5.5.cpp +435 -0
  111. package/eval/arena/tank/bots/half1/qwen-3.8-max.cpp +537 -0
  112. package/eval/arena/tank/bots/half2/deepseek-v4.1-flash.cpp +425 -0
  113. package/eval/arena/tank/bots/half2/doubao-seed-evolving.cpp +308 -0
  114. package/eval/arena/tank/bots/half2/gemini-4-argon.cpp +1390 -0
  115. package/eval/arena/tank/bots/half2/glm-5.3.cpp +651 -0
  116. package/eval/arena/tank/bots/half2/gpt-6-astra.cpp +241 -0
  117. package/eval/arena/tank/bots/half2/gpt-6.1-sol-ultrafast.cpp +356 -0
  118. package/eval/arena/tank/bots/half2/gpt-6.1-sol.cpp +87 -0
  119. package/eval/arena/tank/bots/half2/grok-4.7.cpp +1205 -0
  120. package/eval/arena/tank/bots/half2/haiku-5.5.cpp +210 -0
  121. package/eval/arena/tank/bots/half2/kimi-k3.cpp +487 -0
  122. package/eval/arena/tank/bots/half2/mimo-v2.6-pro.cpp +336 -0
  123. package/eval/arena/tank/bots/half2/muse-wonder-full.cpp +560 -0
  124. package/eval/arena/tank/bots/half2/opus-5.5.cpp +476 -0
  125. package/eval/arena/tank/bots/half2/qwen-3.8-max.cpp +392 -0
  126. package/eval/arena/tank/tournament/README.md +24 -0
  127. package/eval/arena/tank/tournament/bt.py +218 -0
  128. package/eval/arena/tank/tournament/final.json +202 -0
  129. package/eval/arena/tank/tournament/halftime.json +146 -0
  130. package/eval/arena/tank/tournament/progress.json +911 -0
  131. package/eval/arena/tank/tournament/schedule.py +100 -0
  132. package/eval/arena/tank/tournament/sparring.cpp +928 -0
  133. package/eval/arena/tank/tournament/tournament.py +1426 -0
  134. package/eval/arena/tank/workspace/README.md +169 -0
  135. package/eval/arena/tank/workspace/RULES.md +443 -0
  136. package/eval/arena/tank/workspace/arena.py +862 -0
  137. package/eval/arena/tank/workspace/baseline.cpp +259 -0
  138. package/eval/arena/tank/workspace/clock.py +103 -0
  139. package/eval/arena/tank/workspace/core.py +712 -0
  140. package/eval/arena/tank/workspace/engine.py +573 -0
  141. package/eval/arena/tank/workspace/history/.lock +0 -0
  142. package/eval/arena/tank/workspace/history/20261017-193610-08715287f91f-bot.cpp +109 -0
  143. package/eval/arena/tank/workspace/history/20261017-193619-f00b2d5635fa-gpt-6-astra.cpp +241 -0
  144. package/eval/arena/tank/workspace/history/20261017-193643-63319e0a2b1a-gpt-6_1-sol-ultrafast.cpp +356 -0
  145. package/eval/arena/tank/workspace/history/20261017-193647-41c1341d0a8a-gemini-4-argon.cpp +1390 -0
  146. package/eval/arena/tank/workspace/history/20261017-193652-e34c0f45539a-gpt-6_1-sol.cpp +87 -0
  147. package/eval/arena/tank/workspace/history/20261017-193654-c026348ce96e-opus-5_5.cpp +476 -0
  148. package/eval/arena/tank/workspace/history/20261017-193655-4a21366e94d1-muse-wonder-full.cpp +560 -0
  149. package/eval/arena/tank/workspace/history/20261017-193657-dbc4e9969c52-mimo-v2_6-pro.cpp +336 -0
  150. package/eval/arena/tank/workspace/history/20261017-193703-723cd036eb31-grok-4_7.cpp +1205 -0
  151. package/eval/arena/tank/workspace/history/20261017-193707-1ebbb227be68-deepseek-v4_1-flash.cpp +425 -0
  152. package/eval/arena/tank/workspace/history/20261017-193709-aeb0e7202ad5-doubao-seed-evolving.cpp +308 -0
  153. package/eval/arena/tank/workspace/history/20261017-193710-b21ebeb9bc76-kimi-k3.cpp +487 -0
  154. package/eval/arena/tank/workspace/history/20261017-193712-54cd86531905-haiku-5_5.cpp +210 -0
  155. package/eval/arena/tank/workspace/history/20261017-193714-efdb8e35c0bf-qwen-3_8-max.cpp +392 -0
  156. package/eval/arena/tank/workspace/history/20261017-193715-681423c23fdb-glm-5_3.cpp +651 -0
  157. package/eval/arena/tank/workspace/history/20261017-193717-1a8b3c75181d-sparring.cpp +928 -0
  158. package/eval/arena/tank/workspace/history/20261017-193720-1e0803a541e8-baseline.cpp +259 -0
  159. package/eval/arena/tank/workspace/history/log.jsonl +103 -0
  160. package/eval/arena/tank/workspace/judge/cycles.hpp +53 -0
  161. package/eval/arena/tank/workspace/judge/fast.cpp +337 -0
  162. package/eval/arena/tank/workspace/judge/referee.cpp +125 -0
  163. package/eval/arena/tank/workspace/judge/speed.cpp +99 -0
  164. package/eval/arena/tank/workspace/run.cmd +31 -0
  165. package/eval/arena/tank/workspace/run.sh +23 -0
  166. package/eval/arena/tank/workspace/tank.hpp +1762 -0
  167. package/eval/arena/tank/workspace/tank_main.cpp +215 -0
  168. package/eval/arena/tank/workspace/viewer.html +1150 -0
  169. package/eval/arena/warehouse/workspace/SPEC.md +130 -0
  170. package/eval/arena/warehouse/workspace/TASK.md +71 -0
  171. package/eval/arena/warehouse/workspace/baseline/common.h +88 -0
  172. package/eval/arena/warehouse/workspace/baseline/main.cpp +27 -0
  173. package/eval/arena/warehouse/workspace/baseline/old_stuff.cpp +87 -0
  174. package/eval/arena/warehouse/workspace/baseline/sim.cpp +427 -0
  175. package/eval/arena/warehouse/workspace/baseline/util.cpp +220 -0
  176. package/eval/arena/warehouse/workspace/clock.py +42 -0
  177. package/eval/arena/warehouse/workspace/src/common.h +88 -0
  178. package/eval/arena/warehouse/workspace/src/main.cpp +27 -0
  179. package/eval/arena/warehouse/workspace/src/old_stuff.cpp +87 -0
  180. package/eval/arena/warehouse/workspace/src/sim.cpp +427 -0
  181. package/eval/arena/warehouse/workspace/src/util.cpp +220 -0
  182. package/eval/arena/warehouse/workspace/tools/bench.py +119 -0
  183. package/eval/arena/warehouse/workspace/tools/check_input.py +161 -0
  184. package/eval/arena/warehouse/workspace/tools/gen.py +132 -0
  185. package/eval/arena/warehouse/workspace/tools/measure.py +107 -0
  186. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.in +1420 -0
  187. package/eval/arena/warehouse/workspace/workloads/public/pub_crowded.out +9162 -0
  188. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.in +1465 -0
  189. package/eval/arena/warehouse/workspace/workloads/public/pub_dynamic.out +3439 -0
  190. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.in +2757 -0
  191. package/eval/arena/warehouse/workspace/workloads/public/pub_flood.out +3126 -0
  192. package/eval/arena/warehouse/workspace/workloads/public/pub_small.in +731 -0
  193. package/eval/arena/warehouse/workspace/workloads/public/pub_small.out +2578 -0
  194. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.in +528 -0
  195. package/eval/arena/warehouse/workspace/workloads/public/pub_wide.out +2026 -0
  196. package/eval/bomberman.py +20 -0
  197. package/eval/commit0.py +21 -0
  198. package/eval/common.py +61 -0
  199. package/eval/ctf.py +20 -0
  200. package/eval/featurebench.py +25 -0
  201. package/eval/land.py +20 -0
  202. package/eval/legacy/bomberman-prices.json +4 -0
  203. package/eval/legacy/bomberman.py +161 -0
  204. package/eval/legacy/commit0.py +91 -0
  205. package/eval/legacy/ctf-prices.json +4 -0
  206. package/eval/legacy/ctf.py +178 -0
  207. package/eval/legacy/featurebench.py +103 -0
  208. package/eval/legacy/land-prices.json +4 -0
  209. package/eval/legacy/land.py +177 -0
  210. package/eval/legacy/swe_bench_pro.py +116 -0
  211. package/eval/legacy/tank-prices.json +3 -0
  212. package/eval/legacy/tank.py +408 -0
  213. package/eval/legacy/warehouse-prices.json +4 -0
  214. package/eval/legacy/warehouse.py +365 -0
  215. package/eval/swe-bench-pro.py +25 -0
  216. package/eval/tank.py +20 -0
  217. package/eval/warehouse.py +20 -0
  218. package/lib/client/index.js +376 -63
  219. package/lib/client/index.js.map +1 -1
  220. package/lib/index.js +684 -27
  221. package/package.json +2 -1
@@ -0,0 +1,630 @@
1
+ // Territory bot: safe-loop planner + guaranteed-kill hunter.
2
+ #include <bits/stdc++.h>
3
+ using namespace std;
4
+ using Clock = chrono::steady_clock;
5
+
6
+ const int DX[4] = {0, 0, -1, 1};
7
+ const int DY[4] = {-1, 1, 0, 0};
8
+ const char DC[4] = {'U', 'D', 'L', 'R'};
9
+ int dirIndex(char c) { return string("UDLR").find(c); }
10
+
11
+ struct Player { int x, y, dir, trailLen, area, deaths; };
12
+
13
+ int W, H, MAX_TURNS, N, ME, MOVE_MS, INIT_MS, NC;
14
+ vector<pair<int, int>> spawn;
15
+ int turnNo; int ENDG = 20;
16
+ vector<Player> P;
17
+ vector<int> own, trl, prot; // owner / trail per cell (-1 none)
18
+ vector<int> lastPos, stillCnt;
19
+ bool outP[4];
20
+ Clock::time_point T0;
21
+ double elapsedMs() { return chrono::duration<double, milli>(Clock::now() - T0).count(); }
22
+
23
+ inline int cid(int x, int y) { return y * W + x; }
24
+ inline bool inb(int x, int y) { return x >= 0 && x < W && y >= 0 && y < H; }
25
+
26
+ bool readState() {
27
+ string tok;
28
+ if (!(cin >> tok)) return false;
29
+ T0 = Clock::now();
30
+ cin >> turnNo;
31
+ P.assign(N, {});
32
+ for (int i = 0; i < N; i++) {
33
+ int id; char d; Player q;
34
+ cin >> tok >> id >> q.x >> q.y >> d >> q.trailLen >> q.area >> q.deaths;
35
+ q.dir = dirIndex(d);
36
+ P[id] = q;
37
+ }
38
+ cin >> tok;
39
+ string row;
40
+ for (int y = 0; y < H; y++) {
41
+ cin >> row;
42
+ for (int x = 0; x < W; x++) own[cid(x, y)] = row[x] == '.' ? -1 : row[x] - '0';
43
+ }
44
+ cin >> tok;
45
+ for (int y = 0; y < H; y++) {
46
+ cin >> row;
47
+ for (int x = 0; x < W; x++) trl[cid(x, y)] = row[x] == '.' ? -1 : row[x] - '0';
48
+ }
49
+ cin >> tok;
50
+ return true;
51
+ }
52
+
53
+ // ---------- BFS helpers ----------
54
+ // distance from player's head, first step cannot reverse; blocked cells: player's own trail
55
+ void bfsFromHead(int p, vector<int>& dist, vector<int>* par = nullptr, bool block = true) {
56
+ dist.assign(NC, INT_MAX);
57
+ if (par) par->assign(NC, -1);
58
+ int s = cid(P[p].x, P[p].y);
59
+ dist[s] = 0;
60
+ static vector<int> q; q.clear();
61
+ for (int d = 0; d < 4; d++) {
62
+ if (d == (P[p].dir ^ 1)) continue;
63
+ int nx = P[p].x + DX[d], ny = P[p].y + DY[d];
64
+ if (!inb(nx, ny)) continue;
65
+ int k = cid(nx, ny);
66
+ if (block && trl[k] == p) continue;
67
+ dist[k] = 1; if (par) (*par)[k] = s;
68
+ q.push_back(k);
69
+ }
70
+ for (size_t h = 0; h < q.size(); h++) {
71
+ int k = q[h], x = k % W, y = k / W;
72
+ for (int d = 0; d < 4; d++) {
73
+ int nx = x + DX[d], ny = y + DY[d];
74
+ if (!inb(nx, ny)) continue;
75
+ int nk = cid(nx, ny);
76
+ if (dist[nk] != INT_MAX || (block && trl[nk] == p)) continue;
77
+ dist[nk] = dist[k] + 1; if (par) (*par)[nk] = k;
78
+ q.push_back(nk);
79
+ }
80
+ }
81
+ }
82
+
83
+ vector<int> enemyDist; // min over enemies of distance
84
+ vector<int> enemyDistBy[4], headDistBy[4], spawnDist[4];
85
+ vector<int> myDist, myPar;
86
+ double oppW = 1.0;
87
+
88
+ // ---------- candidate evaluation ----------
89
+ vector<char> threat;
90
+ vector<int> mark; int markId = 1; // path cell marker
91
+ vector<int> fillSeen; int fillId = 1;
92
+ vector<int> bq;
93
+
94
+ // BFS from cell s (arrived with direction ld) back to own territory avoiding my trail and marked cells.
95
+ // Appends path cells to out. Returns false if impossible.
96
+ vector<int> bpar;
97
+ bool returnHome(int s, int ld, vector<int>& out) {
98
+ // use fillSeen as visited marker
99
+ fillId++;
100
+ bq.clear();
101
+ int sx = s % W, sy = s / W;
102
+ for (int d = 0; d < 4; d++) {
103
+ if (d == (ld ^ 1)) continue;
104
+ int nx = sx + DX[d], ny = sy + DY[d];
105
+ if (!inb(nx, ny)) continue;
106
+ int k = cid(nx, ny);
107
+ if (trl[k] == ME || mark[k] == markId) continue;
108
+ fillSeen[k] = fillId; bpar[k] = s; bq.push_back(k);
109
+ }
110
+ int found = -1;
111
+ for (size_t h = 0; h < bq.size(); h++) {
112
+ int k = bq[h];
113
+ if (own[k] == ME && !threat[k]) { found = k; break; }
114
+ int x = k % W, y = k / W;
115
+ for (int d = 0; d < 4; d++) {
116
+ int nx = x + DX[d], ny = y + DY[d];
117
+ if (!inb(nx, ny)) continue;
118
+ int nk = cid(nx, ny);
119
+ if (fillSeen[nk] == fillId || trl[nk] == ME || mark[nk] == markId) continue;
120
+ fillSeen[nk] = fillId; bpar[nk] = k; bq.push_back(nk);
121
+ }
122
+ }
123
+ if (found < 0) return false;
124
+ vector<int> rev;
125
+ for (int c = found; c != s; c = bpar[c]) rev.push_back(c);
126
+ for (int i = (int)rev.size() - 1; i >= 0; i--) out.push_back(rev[i]);
127
+ return true;
128
+ }
129
+
130
+ // gain of closing with trail = existing trail + newTrail cells (marked)
131
+ vector<char> wall;
132
+ double evalGain(const vector<int>& newTrail) {
133
+ fillId++;
134
+ // walls: own==ME or trl==ME or marked
135
+ bq.clear();
136
+ auto isWall = [&](int k) { return own[k] == ME || trl[k] == ME || mark[k] == markId; };
137
+ auto push = [&](int k) {
138
+ if (fillSeen[k] != fillId && !isWall(k)) { fillSeen[k] = fillId; bq.push_back(k); }
139
+ };
140
+ for (int x = 0; x < W; x++) { push(cid(x, 0)); push(cid(x, H - 1)); }
141
+ for (int y = 0; y < H; y++) { push(cid(0, y)); push(cid(W - 1, y)); }
142
+ for (size_t h = 0; h < bq.size(); h++) {
143
+ int k = bq[h], x = k % W, y = k / W;
144
+ if (y > 0) push(k - W);
145
+ if (y < H - 1) push(k + W);
146
+ if (x > 0) push(k - 1);
147
+ if (x < W - 1) push(k + 1);
148
+ }
149
+ double g = 0;
150
+ for (int k = 0; k < NC; k++) {
151
+ if (own[k] == ME) continue;
152
+ if (fillSeen[k] == fillId) continue;
153
+ // enclosed or trail
154
+ if (prot[k] >= 0 && prot[k] != ME) continue;
155
+ g += own[k] < 0 ? 1.0 : oppW;
156
+ }
157
+ return g;
158
+ }
159
+
160
+ struct Cand {
161
+ vector<int> dirs; // step directions
162
+ double est;
163
+ };
164
+
165
+ int bestMoveDir = -1;
166
+ double bestScore = -1e18;
167
+
168
+ // Simulate path from head along given dirs; returns false if invalid.
169
+ // Fills cells, closeIdx (step index at which we close, 1-based L) ; stops at closure.
170
+ bool simulate(const vector<int>& dirs, vector<int>& cells, int& L, bool& closed, int& lastDir) {
171
+ int x = P[ME].x, y = P[ME].y, cd = P[ME].dir;
172
+ bool hasTrail = P[ME].trailLen > 0;
173
+ markId++;
174
+ cells.clear();
175
+ closed = false;
176
+ for (size_t i = 0; i < dirs.size(); i++) {
177
+ int d = dirs[i];
178
+ if (d == (cd ^ 1)) return false;
179
+ x += DX[d]; y += DY[d];
180
+ if (!inb(x, y)) return false;
181
+ int k = cid(x, y);
182
+ if (trl[k] == ME || mark[k] == markId) return false;
183
+ cd = d;
184
+ if (own[k] == ME) {
185
+ if (hasTrail) { closed = true; L = i + 1; lastDir = cd; return true; }
186
+ } else {
187
+ hasTrail = true;
188
+ mark[k] = markId;
189
+ cells.push_back(k);
190
+ }
191
+ }
192
+ L = dirs.size();
193
+ lastDir = cd;
194
+ return true;
195
+ }
196
+
197
+ // ---------- attack ----------
198
+ int attackOne(int best, int bestD, int bestT);
199
+ int tryAttack() {
200
+ vector<tuple<int, int, int>> tg; // (my dist, cell, enemy)
201
+ for (int e = 0; e < N; e++) {
202
+ if (e == ME || outP[e] || P[e].trailLen == 0) continue;
203
+ // enemy home distance
204
+ vector<int> de;
205
+ bfsFromHead(e, de);
206
+ int homeE = INT_MAX;
207
+ for (int k = 0; k < NC; k++) if (own[k] == e && de[k] < homeE) homeE = de[k];
208
+ vector<pair<int, int>> ls;
209
+ for (int k = 0; k < NC; k++) {
210
+ if (trl[k] != e) continue;
211
+ int dm = myDist[k];
212
+ if (dm == INT_MAX || dm > homeE) continue;
213
+ ls.push_back({dm, k});
214
+ }
215
+ sort(ls.begin(), ls.end());
216
+ for (size_t i = 0; i < ls.size() && i < 6; i++) tg.push_back({ls[i].first, ls[i].second, e});
217
+ }
218
+ sort(tg.begin(), tg.end());
219
+ for (size_t i = 0; i < tg.size() && i < 12; i++) {
220
+ auto [dm, k, e] = tg[i];
221
+ int r = attackOne(k, dm, e);
222
+ if (r >= 0) return r;
223
+ }
224
+ return -1;
225
+ }
226
+
227
+ int attackOne(int best, int bestD, int bestT) {
228
+ vector<int> path;
229
+ int s = cid(P[ME].x, P[ME].y);
230
+ for (int c = best; c != s; c = myPar[c]) path.push_back(c);
231
+ reverse(path.begin(), path.end());
232
+ if (path.empty()) return -1;
233
+ // safety: my trail cells (existing + new path outside my territory)
234
+ // exposure time: bestD + distance home from target cell (approx via BFS later) -> approximate
235
+ int homeAfter = 0;
236
+ {
237
+ markId++;
238
+ for (int c : path) if (own[c] != ME) mark[c] = markId;
239
+ vector<int> tmp;
240
+ int ld = 0;
241
+ if (path.size() >= 2) {
242
+ int a = path[path.size() - 2], b = path.back();
243
+ int dx = b % W - a % W, dy = b / W - a / W;
244
+ for (int d = 0; d < 4; d++) if (DX[d] == dx && DY[d] == dy) ld = d;
245
+ } else {
246
+ int dx = best % W - P[ME].x, dy = best / W - P[ME].y;
247
+ for (int d = 0; d < 4; d++) if (DX[d] == dx && DY[d] == dy) ld = d;
248
+ }
249
+ bool newTrail = P[ME].trailLen > 0;
250
+ for (int c : path) if (own[c] != ME) newTrail = true;
251
+ if (newTrail && own[best] != ME) {
252
+ if (!returnHome(best, ld, tmp)) homeAfter = 60; else homeAfter = tmp.size();
253
+ for (int c : tmp) if (own[c] != ME) path.push_back(c); // exposure after the kill
254
+ }
255
+ }
256
+ int Ltot = bestD + homeAfter;
257
+ auto check = [&](int k) {
258
+ for (int e = 0; e < N; e++) {
259
+ if (e == ME || outP[e]) continue;
260
+ int de = enemyDistBy[e][k];
261
+ if (e == bestT) { if (headDistBy[e][k] <= bestD || spawnDist[e][k] + bestD <= Ltot) return false; }
262
+ else if (de <= Ltot) return false;
263
+ }
264
+ return true;
265
+ };
266
+ for (int k = 0; k < NC; k++) if (trl[k] == ME && !check(k)) return -1;
267
+ for (int c : path) if (own[c] != ME && !check(c)) return -1;
268
+ // head-on check first step
269
+ int f = path[0];
270
+ for (int e = 0; e < N; e++) {
271
+ if (e == ME || outP[e] || e == bestT) continue;
272
+ if (headDistBy[e][f] <= 1) return -1;
273
+ }
274
+ int dx = f % W - P[ME].x, dy = f / W - P[ME].y;
275
+ for (int d = 0; d < 4; d++) if (DX[d] == dx && DY[d] == dy) return d;
276
+ return -1;
277
+ }
278
+
279
+ // cells of mine an enemy would capture by closing its loop via the shortest way home
280
+ void computeThreat() {
281
+ threat.assign(NC, 0);
282
+ for (int e = 0; e < N; e++) {
283
+ if (e == ME || outP[e] || P[e].trailLen == 0) continue;
284
+ vector<int> de, par;
285
+ bfsFromHead(e, de, &par);
286
+ int best = -1;
287
+ for (int k = 0; k < NC; k++) if (own[k] == e && (best < 0 || de[k] < de[best])) best = k;
288
+ if (best < 0 || de[best] == INT_MAX) continue;
289
+ vector<char> wl(NC, 0);
290
+ for (int k = 0; k < NC; k++) if (own[k] == e || trl[k] == e) wl[k] = 1;
291
+ int s = cid(P[e].x, P[e].y);
292
+ for (int c = best; c != s && c >= 0; c = par[c]) wl[c] = 1;
293
+ vector<char> seen(NC, 0);
294
+ vector<int> q;
295
+ auto push = [&](int k) { if (!wl[k] && !seen[k]) { seen[k] = 1; q.push_back(k); } };
296
+ for (int x = 0; x < W; x++) { push(cid(x, 0)); push(cid(x, H - 1)); }
297
+ for (int y = 0; y < H; y++) { push(cid(0, y)); push(cid(W - 1, y)); }
298
+ for (size_t h = 0; h < q.size(); h++) {
299
+ int k = q[h], x = k % W, y = k / W;
300
+ if (y > 0) push(k - W);
301
+ if (y < H - 1) push(k + W);
302
+ if (x > 0) push(k - 1);
303
+ if (x < W - 1) push(k + 1);
304
+ }
305
+ for (int k = 0; k < NC; k++)
306
+ if (own[k] == ME && !seen[k] && prot[k] != ME) threat[k] = 1;
307
+ }
308
+ }
309
+
310
+ // ---------- main decision ----------
311
+ mt19937 rng(12345);
312
+
313
+ int decide() {
314
+ NC = W * H;
315
+ // detect eliminated players (don't move)
316
+ for (int i = 0; i < N; i++) {
317
+ int k = cid(P[i].x, P[i].y);
318
+ if (turnNo > 0 && k == lastPos[i] && k == cid(spawn[i].first, spawn[i].second)) stillCnt[i]++;
319
+ else stillCnt[i] = 0;
320
+ lastPos[i] = k;
321
+ outP[i] = (i != ME && stillCnt[i] >= 2);
322
+ }
323
+ enemyDist.assign(NC, INT_MAX);
324
+ for (int e = 0; e < N; e++) {
325
+ if (e == ME) continue;
326
+ if (outP[e]) { enemyDistBy[e].assign(NC, INT_MAX); headDistBy[e] = enemyDistBy[e]; continue; }
327
+ bfsFromHead(e, enemyDistBy[e], nullptr, false);
328
+ headDistBy[e] = enemyDistBy[e];
329
+ if (P[e].trailLen > 0)
330
+ for (int k = 0; k < NC; k++) enemyDistBy[e][k] = min(enemyDistBy[e][k], spawnDist[e][k] + 1);
331
+ for (int k = 0; k < NC; k++) enemyDist[k] = min(enemyDist[k], enemyDistBy[e][k]);
332
+ }
333
+ bfsFromHead(ME, myDist, &myPar);
334
+ oppW = (N == 2) ? 2.0 : 1.4;
335
+
336
+ computeThreat();
337
+ int atk = tryAttack();
338
+ if (atk >= 0) return atk;
339
+
340
+ const Player& me = P[ME];
341
+ int remain = MAX_TURNS - turnNo;
342
+ int head = cid(me.x, me.y);
343
+ bool inside = own[head] == ME && me.trailLen == 0;
344
+
345
+ // current min enemy distance to my existing trail
346
+ int trailMinE = INT_MAX;
347
+ for (int k = 0; k < NC; k++) if (trl[k] == ME) trailMinE = min(trailMinE, enemyDist[k]);
348
+
349
+ // prefixes
350
+ struct Pre { vector<int> dirs; int ex, ey, dir; };
351
+ vector<Pre> pres;
352
+ if (inside) {
353
+ // BFS inside territory from head
354
+ vector<int> dist(NC, INT_MAX), par(NC, -1), pd(NC, -1);
355
+ vector<int> q;
356
+ dist[head] = 0; q.push_back(head);
357
+ for (size_t h = 0; h < q.size(); h++) {
358
+ int k = q[h], x = k % W, y = k / W;
359
+ for (int d = 0; d < 4; d++) {
360
+ if (k == head && d == (me.dir ^ 1)) continue;
361
+ int nx = x + DX[d], ny = y + DY[d];
362
+ if (!inb(nx, ny)) continue;
363
+ int nk = cid(nx, ny);
364
+ if (own[nk] != ME || dist[nk] != INT_MAX) continue;
365
+ dist[nk] = dist[k] + 1; par[nk] = k; pd[nk] = d;
366
+ q.push_back(nk);
367
+ }
368
+ }
369
+ vector<pair<int, int>> exits; // (dist, cell*4+dir)
370
+ for (int k : q) {
371
+ int x = k % W, y = k / W;
372
+ for (int d = 0; d < 4; d++) {
373
+ int nx = x + DX[d], ny = y + DY[d];
374
+ if (!inb(nx, ny)) continue;
375
+ if (own[cid(nx, ny)] == ME) continue;
376
+ if (k == head && d == (me.dir ^ 1)) continue;
377
+ if (k != head && pd[k] == (d ^ 1)) continue;
378
+ exits.push_back({dist[k], k * 4 + d});
379
+ }
380
+ }
381
+ sort(exits.begin(), exits.end());
382
+ int mind = exits.empty() ? 0 : exits[0].first;
383
+ vector<pair<int, int>> pick, rest;
384
+ for (auto& e : exits) (e.first <= mind + 4 ? pick : rest).push_back(e);
385
+ shuffle(pick.begin(), pick.end(), rng);
386
+ if (pick.size() > 30) pick.resize(30);
387
+ shuffle(rest.begin(), rest.end(), rng);
388
+ for (size_t i = 0; i < rest.size() && i < 30; i++) pick.push_back(rest[i]);
389
+ for (auto& e : pick) {
390
+ int k = e.second / 4, d = e.second % 4;
391
+ Pre p;
392
+ for (int c = k; c != head; c = par[c]) p.dirs.push_back(pd[c]);
393
+ reverse(p.dirs.begin(), p.dirs.end());
394
+ p.ex = k % W; p.ey = k / W;
395
+ p.dir = d; // the next direction to take (outward)
396
+ pres.push_back(p);
397
+ }
398
+ } else {
399
+ Pre p; p.ex = me.x; p.ey = me.y; p.dir = -1;
400
+ pres.push_back(p);
401
+ }
402
+
403
+ // prefix sums of value for estimates
404
+ vector<double> ps((W + 1) * (H + 1), 0);
405
+ for (int y = 0; y < H; y++)
406
+ for (int x = 0; x < W; x++) {
407
+ int k = cid(x, y);
408
+ double v = own[k] == ME ? 0 : (own[k] < 0 ? 1 : ((prot[k] >= 0) ? 0 : oppW));
409
+ ps[(y + 1) * (W + 1) + x + 1] = v + ps[y * (W + 1) + x + 1] + ps[(y + 1) * (W + 1) + x] - ps[y * (W + 1) + x];
410
+ }
411
+ auto boxVal = [&](int x0, int y0, int x1, int y1) {
412
+ if (x0 > x1) swap(x0, x1);
413
+ if (y0 > y1) swap(y0, y1);
414
+ x0 = max(x0, 0); y0 = max(y0, 0); x1 = min(x1, W - 1); y1 = min(y1, H - 1);
415
+ return ps[(y1 + 1) * (W + 1) + x1 + 1] - ps[y0 * (W + 1) + x1 + 1] - ps[(y1 + 1) * (W + 1) + x0] + ps[y0 * (W + 1) + x0];
416
+ };
417
+
418
+ // home distance map (ignoring new path) for estimates
419
+ vector<int> homeD(NC, INT_MAX);
420
+ {
421
+ vector<int> q;
422
+ for (int k = 0; k < NC; k++) if (own[k] == ME && !threat[k]) { homeD[k] = 0; q.push_back(k); }
423
+ for (size_t h = 0; h < q.size(); h++) {
424
+ int k = q[h], x = k % W, y = k / W;
425
+ for (int d = 0; d < 4; d++) {
426
+ int nx = x + DX[d], ny = y + DY[d];
427
+ if (!inb(nx, ny)) continue;
428
+ int nk = cid(nx, ny);
429
+ if (homeD[nk] != INT_MAX || trl[nk] == ME) continue;
430
+ homeD[nk] = homeD[k] + 1; q.push_back(nk);
431
+ }
432
+ }
433
+ }
434
+
435
+ auto segMin = [&](int x, int y, int d, int len) {
436
+ int m = INT_MAX;
437
+ for (int i = 0; i < len; i++) {
438
+ x += DX[d]; y += DY[d];
439
+ int k = cid(x, y);
440
+ if (own[k] != ME) m = min(m, enemyDist[k]);
441
+ }
442
+ return m;
443
+ };
444
+ int maxTrip = (N == 2) ? 90 : 80;
445
+ static const int steps[] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 19, 22, 26, 30};
446
+ vector<Cand> cands;
447
+ int elapsed = me.trailLen;
448
+ for (auto& pr : pres) {
449
+ vector<int> d1s;
450
+ if (pr.dir >= 0) d1s.push_back(pr.dir);
451
+ else for (int d = 0; d < 4; d++) if (d != (me.dir ^ 1)) d1s.push_back(d);
452
+ for (int d1 : d1s) {
453
+ for (int a : steps) {
454
+ int ax = pr.ex + DX[d1] * a, ay = pr.ey + DY[d1] * a;
455
+ if (!inb(ax, ay)) break;
456
+ int pl = pr.dirs.size();
457
+ // pure segment then return
458
+ {
459
+ int Lest = pl + a + (homeD[cid(ax, ay)] == INT_MAX ? 99 : homeD[cid(ax, ay)]);
460
+ double est = boxVal(pr.ex, pr.ey, ax, ay) * 0.3;
461
+ Cand c; c.dirs = pr.dirs;
462
+ for (int i = 0; i < a; i++) c.dirs.push_back(d1);
463
+ c.est = est / (Lest + elapsed + 2);
464
+ cands.push_back(c);
465
+ }
466
+ for (int d2 = 0; d2 < 4; d2++) {
467
+ if (d2 == d1 || d2 == (d1 ^ 1)) continue;
468
+ for (int b : steps) {
469
+ int bx = ax + DX[d2] * b, by = ay + DY[d2] * b;
470
+ if (!inb(bx, by)) break;
471
+ // variants: return directly, or go back along d1^1 for c steps then return
472
+ for (int cv = 0; cv < 4; cv++) {
473
+ int cs = 0;
474
+ if (cv == 1) cs = a;
475
+ else if (cv == 2) cs = max(1, a / 2);
476
+ else if (cv == 3) cs = a + 2;
477
+ if (cv > 0 && cs == 0) continue;
478
+ int cx = bx + DX[d1 ^ 1] * cs, cy = by + DY[d1 ^ 1] * cs;
479
+ if (!inb(cx, cy)) continue;
480
+ int hd = homeD[cid(cx, cy)];
481
+ if (hd == INT_MAX) continue;
482
+ int Lest = pl + a + b + cs + hd;
483
+ if (Lest > remain) continue;
484
+ if (Lest + elapsed > maxTrip) continue;
485
+ {
486
+ int m = min(trailMinE, min(segMin(pr.ex, pr.ey, d1, a), segMin(ax, ay, d2, b)));
487
+ if (cs) m = min(m, segMin(bx, by, d1 ^ 1, cs));
488
+ if (m <= Lest) continue;
489
+ }
490
+ double est = boxVal(pr.ex, pr.ey, bx, by);
491
+ if (cv == 3) est = boxVal(pr.ex - DX[d1] * 2, pr.ey - DY[d1] * 2, bx, by);
492
+ est = est / (Lest + elapsed + 2);
493
+ Cand c; c.dirs = pr.dirs;
494
+ c.dirs.reserve(pl + a + b + cs);
495
+ for (int i = 0; i < a; i++) c.dirs.push_back(d1);
496
+ for (int i = 0; i < b; i++) c.dirs.push_back(d2);
497
+ for (int i = 0; i < cs; i++) c.dirs.push_back(d1 ^ 1);
498
+ c.est = est;
499
+ cands.push_back(c);
500
+ }
501
+ }
502
+ }
503
+ }
504
+ }
505
+ }
506
+ // always include pure return home
507
+ if (!inside) { Cand c; c.est = 1e9; cands.push_back(c); }
508
+ sort(cands.begin(), cands.end(), [](const Cand& a, const Cand& b) { return a.est > b.est; });
509
+ double genMs = elapsedMs();
510
+
511
+ double budget = (turnNo == 0) ? 300.0 : (N == 2 ? 14.0 : 12.0);
512
+ int bestFirst = -1;
513
+ double best = -1e18;
514
+ int fbFirst = -1; double fbScore = -1e18; // least-unsafe fallback
515
+ vector<int> cells, full;
516
+ int evals = 0;
517
+ for (auto& c : cands) {
518
+ if (evals > 0 && elapsedMs() > budget) break;
519
+ int L; bool closed; int ld;
520
+ if (!simulate(c.dirs, cells, L, closed, ld)) continue;
521
+ full = c.dirs;
522
+ if (!closed) {
523
+ int endc;
524
+ if (c.dirs.empty()) endc = head, ld = me.dir;
525
+ else {
526
+ int x = me.x, y = me.y;
527
+ for (int d : c.dirs) x += DX[d], y += DY[d];
528
+ endc = cid(x, y);
529
+ }
530
+ if (own[endc] == ME && me.trailLen == 0 && cells.empty()) continue; // never left
531
+ vector<int> ret;
532
+ if (!returnHome(endc, ld, ret)) continue;
533
+ // convert ret cells to dirs
534
+ int px = endc % W, py = endc / W;
535
+ for (int rc : ret) {
536
+ int dx = rc % W - px, dy = rc / W - py;
537
+ for (int d = 0; d < 4; d++) if (DX[d] == dx && DY[d] == dy) full.push_back(d);
538
+ if (own[rc] != ME) { mark[rc] = markId; cells.push_back(rc); }
539
+ px = rc % W; py = rc / W;
540
+ }
541
+ L = full.size();
542
+ }
543
+ if (full.empty()) continue;
544
+ evals++;
545
+ // safety
546
+ int minE = trailMinE;
547
+ for (int k : cells) minE = min(minE, enemyDist[k]);
548
+ int firstCell = cid(me.x + DX[full[0]], me.y + DY[full[0]]);
549
+ bool headRisk = enemyDist[firstCell] <= 1;
550
+ double slack = (double)minE - L;
551
+ if (L > remain) slack = min(slack, (double)(remain - L));
552
+ if (slack < 1 || headRisk) {
553
+ double fs = slack - (headRisk ? 5 : 0) - L * 0.01;
554
+ if (fs > fbScore) { fbScore = fs; fbFirst = full[0]; }
555
+ continue;
556
+ }
557
+ double g = evalGain(cells);
558
+ double sc = g / (L + elapsed + 2.0);
559
+ if (remain <= ENDG) sc = g - 0.01 * L;
560
+ // prefer a bit of slack
561
+
562
+ if (sc > best) { best = sc; bestFirst = full[0]; }
563
+ }
564
+ if (getenv("BOTDBG")) fprintf(stderr, "t%d in=%d tl=%d cands=%zu evals=%d best=%.3f fb=%.1f bf=%d gen=%.2f\n", turnNo, inside, me.trailLen, cands.size(), evals, best, fbScore, bestFirst, genMs);
565
+ if (bestFirst >= 0) return bestFirst;
566
+ if (inside) {
567
+ // stay inside, move to cell maximizing enemy distance
568
+ int bd = -1, bv = INT_MIN;
569
+ for (int d = 0; d < 4; d++) {
570
+ if (d == (me.dir ^ 1)) continue;
571
+ int nx = me.x + DX[d], ny = me.y + DY[d];
572
+ if (!inb(nx, ny)) continue;
573
+ int k = cid(nx, ny);
574
+ int v = (own[k] == ME ? 1000 : 0) + min(enemyDist[k], 50) * 2 - (enemyDist[k] <= 1 ? 500 : 0);
575
+ // prefer cells with many own neighbors (keep maneuvering room)
576
+ if (v > bv) { bv = v; bd = d; }
577
+ }
578
+ if (bd >= 0) return bd;
579
+ }
580
+ if (fbFirst >= 0) return fbFirst;
581
+ for (int d : {me.dir, 0, 1, 2, 3}) {
582
+ if (d == (me.dir ^ 1)) continue;
583
+ int nx = me.x + DX[d], ny = me.y + DY[d];
584
+ if (inb(nx, ny) && trl[cid(nx, ny)] != ME) return d;
585
+ }
586
+ return me.dir;
587
+ }
588
+
589
+ int main() {
590
+ ios::sync_with_stdio(false);
591
+ cin.tie(nullptr);
592
+ string tok;
593
+ cin >> tok;
594
+ cin >> W >> H >> MAX_TURNS >> N >> ME >> MOVE_MS >> INIT_MS;
595
+ NC = W * H;
596
+ spawn.resize(N);
597
+ for (int i = 0; i < N; i++) {
598
+ int id, x, y;
599
+ cin >> tok >> id >> x >> y;
600
+ spawn[id] = {x, y};
601
+ }
602
+ own.assign(NC, -1); trl.assign(NC, -1); prot.assign(NC, -1);
603
+ for (int i = 0; i < N; i++)
604
+ for (int dy = -1; dy <= 1; dy++)
605
+ for (int dx = -1; dx <= 1; dx++) {
606
+ int x = spawn[i].first + dx, y = spawn[i].second + dy;
607
+ if (inb(x, y)) prot[cid(x, y)] = i;
608
+ }
609
+ for (int i = 0; i < N; i++) {
610
+ spawnDist[i].assign(NC, INT_MAX);
611
+ vector<int> q{cid(spawn[i].first, spawn[i].second)};
612
+ spawnDist[i][q[0]] = 0;
613
+ for (size_t h = 0; h < q.size(); h++) {
614
+ int k = q[h], x = k % W, y = k / W;
615
+ for (int d = 0; d < 4; d++) {
616
+ int nx = x + DX[d], ny = y + DY[d];
617
+ if (!inb(nx, ny)) continue;
618
+ int nk = cid(nx, ny);
619
+ if (spawnDist[i][nk] != INT_MAX) continue;
620
+ spawnDist[i][nk] = spawnDist[i][k] + 1; q.push_back(nk);
621
+ }
622
+ }
623
+ }
624
+ mark.assign(NC, 0); fillSeen.assign(NC, 0); bpar.assign(NC, -1);
625
+ lastPos.assign(N, -1); stillCnt.assign(N, 0);
626
+ while (readState()) {
627
+ int d = decide();
628
+ cout << turnNo << ' ' << DC[d] << endl;
629
+ }
630
+ }