题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Time limit: 2 seconds
Memory limit: 1024 megabytes
This is an interactive problem.
A mischievous robot is navigating an infinitely large 2D grid. However, its movement is confined to the first quadrant, meaning its coordinates (x, y) must always satisfy x > 0 and y > 0. Initially, the robot is located at grid coordinates (s_x, s_y). All grid cells are initially white.
Set T = 3000. The game proceeds in discrete time steps. In each time step, the following sequence occurs:
1. Your Move: You choose integer coordinates (x_m, y_m) such that 1 <= x_m <= T and 1 <= y_m <= T. You then mark this cell black. A cell, once marked black, remains black for the rest of the game. You can mark any cell within the range, including the cell where the robot is currently located.
2. Robot’s Move: The robot, currently at position (r_x, r_y), observes the grid (including the cell you just marked black). It knows the locations of all currently black cells. It then moves to a new position (n_x, n_y). The new position (n_x, n_y) must be one of the 8 cells immediately adjacent (horizontally, vertically, or diagonally) to (r_x, r_y). That is, |n_x - r_x| <= 1 and |n_y - r_y| <= 1, and (n_x, n_y) ̸= (r_x, r_y). Additionally, the robot must stay within the first quadrant, so n_x > 0 and n_y > 0. The interactor (controlling the robot) will choose one valid move for the robot. The robot’s strategy is unknown to you.
3. Outcome Check: After the robot moves to (n_x, n_y), the system checks if the cell (n_x, n_y) is black.
• If (n_x, n_y) is black, the robot explodes.
• If (n_x, n_y) is white, the game continues to the next time step, with the robot now at (n_x, n_y).
Your goal is to make the robot explode within as less steps as possiable. Answers exceeding 3000 steps are considered as incorrect answers.
Input
The first line of input contains two integers sx and sy (1 <= s_x, s_y <= 20), the initial coordinates of the robot.
Interaction Protocol
The interaction proceeds in turns for at most T turns. In each turn t (from t = 1 to T):
1. Your program must print one line containing two space-separated integers x_m and y_m, representing the coordinates of the cell you choose to mark black in this turn. Remember to flush the output stream.
2. The interactor reads your chosen coordinates (x_m, y_m).
3. The interactor determines the robot’s next move to (n_x, n_y) based on its current position and the set of all black cells (including the one just marked at (x_m, y_m) ).
4. The interactor checks if the cell (n_x, n_y) is black.
• If it is black (robot explodes), the interactor will print a single line containing '0 0' and terminate. Your program should then read these values and terminate successfully.
• If it is white, the interactor will print a single line containing two space-separated integers n_x and n_y, the new coordinates of the robot. Your program should read these coordinates to know the robot’s current position for the next turn.
If the robot has not exploded after you have made T moves, your program should terminate. Your solution will be judged as incorrect in this case (or if you exceed the turn limit or make an invalid move). To flush your output, you can use fflush(stdout) (if you use printf) or cout.flush() (if you use cout).
Example
standard input
5 5
5 4
5 3
5 2
5 1
0 0
standard output
6 1
4 1
6 2
4 2
5 2
## Scoring
Let x be q, the number of turns used. R is the comparison turn count stored with the test, R<3000. The first turn is numbered 1. The physical reference (the 60-point level) is a=R. Define the lower-band continuation:
L(x) = 60*max(0,(3000-x)/(3000-R)).
For positive x and positive physical reference a, define the improvement factor r=a/x. The physical reference has r=1 and earns 60 points. For a valid output on this branch, the points P are:
P = 100, if x=0;
P = L(x), if L(x)<=60;
P = min(100,60+ln(r)), otherwise.
Here ln is the natural logarithm. In the upper branch before the 100-point cap, r=exp(P-60): each additional point requires an e-fold improvement in the physical objective (division by e). If a=0, the zero-cost rule still applies; positive x uses L(x). All feasibility, correctness, and hard resource-limit checks remain required; invalid output receives 0.
Across test files, use the arithmetic mean of the file scores.
结果
Kimi K3.1 ProKimi
max
49.0
平均得分 ↑
- 49.0采样 1 · 部分分
- 52.3k平均输出 token(含思考) ↓
- 24.2输出速度 tokens/s ↑
- 2167 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
16.3
平均得分 ↑
- 16.3采样 1 · 部分分
- 30.7k平均输出 token(含思考) ↓
- 22.8输出速度 tokens/s ↑
- 1349 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
53.6
平均得分 ↑
- 53.6采样 1 · 部分分
- 103.8k平均输出 token(含思考) ↓
- 181.0输出速度 tokens/s ↑
- 574 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
0.0
平均得分 ↑
- 0.0采样 1 · 答案错误
- 65.2k平均输出 token(含思考) ↓
- 95.4输出速度 tokens/s ↑
- 684 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 376 行
#include <bits/stdc++.h> using namespace std; using P = pair<int, int>; static const int T = 3000; static const int N = 60; static const int LOCAL_LIMIT = 180; static const int EMERGENCY_LIMIT = 40; set<P> blackCells; vector<P> wallCells; vector<P> fillCells; int rx, ry, vx = 0, vy = 0; int localUsed = 0, emergencyUsed = 0; bool markable(P p) { return p.first >= 1 && p.first <= T && p.second >= 1 && p.second <= T; } bool isBlack(P p) { return blackCells.count(p); } vector<P> neighbors(P p) { vector<P> res; for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx == 0 && dy == 0) continue; P q = {p.first + dx, p.second + dy}; if (q.first > 0 && q.second > 0) res.push_back(q); } } return res; } int wallIndex(P p) { return p.first == N ? p.second : p.first; } bool baseWallCell(P p) { int i = wallIndex(p); return i % 3 != 0 || i <= 2 || i >= N - 2; } bool specialWallCell(P p) { int i = wallIndex(p); return i <= 2 || i >= N - 2; } bool adjacent(P a, P b) { return max(abs(a.first - b.first), abs(a.second - b.second)) <= 1; } vector<P> urgentWallCells(P p) { vector<P> res; for (P w : wallCells) { if (!isBlack(w) && adjacent(p, w)) res.push_back(w); } return res; } pair<int, int> deadlineInfo(P w, P p) { int best = 1000000; if (w.first == N) { int qx = N - 1; int lo = max(1, w.second - 1); int hi = min(N - 1, w.second + 1); for (int qy = lo; qy <= hi; ++qy) { best = min(best, max(abs(qx - p.first), abs(qy - p.second))); } return {best, abs(w.second - p.second)}; } else { int qy = N - 1; int lo = max(1, w.first - 1); int hi = min(N - 1, w.first + 1); for (int qx = lo; qx <= hi; ++qx) { best = min(best, max(abs(qx - p.first), abs(qy - p.second))); } return {best, abs(w.first - p.first)}; } } int dangerAfterMark(P candidate) { P p = {rx, ry}; int danger = 0; for (P q : neighbors(p)) { if (q == candidate || isBlack(q)) continue; if (q.first >= N || q.second >= N) { danger += 1000; continue; } int whiteExits = 0; for (P w : wallCells) { if (w == candidate || isBlack(w)) continue; if (adjacent(q, w)) ++whiteExits; } if (whiteExits >= 2) danger += 10 * (whiteExits - 1); } return danger; } struct Plan { bool ok = false; int eta = 1000000; P target = {-1, -1}; vector<P> offPath; }; Plan makePlan(bool restrictToBox) { vector<P> dirs; if (vx != 0 || vy != 0) { dirs.push_back({vx, vy}); } else { dirs = { {0, -1}, {-1, 0}, {1, -1}, {-1, -1}, {1, 0}, {0, 1}, {1, 1}, {-1, 1} }; } Plan best; int limit = restrictToBox ? N - 1 : T - 1; for (P d : dirs) { for (int k = 1; k <= 12; ++k) { P c = {rx + d.first * k, ry + d.second * k}; if (c.first < 1 || c.second < 1 || c.first > limit || c.second > limit) continue; if (isBlack(c)) continue; bool bad = false; set<P> futurePath; for (int j = 1; j < k; ++j) { P q = {rx + d.first * j, ry + d.second * j}; futurePath.insert(q); if (isBlack(q)) bad = true; } if (bad) continue; P previous = {c.first - d.first, c.second - d.second}; vector<P> off; for (P q : neighbors(c)) { if (!markable(q) || q == previous || isBlack(q)) continue; if (futurePath.count(q)) { bad = true; break; } off.push_back(q); } if (bad) continue; if ((int)off.size() > k) continue; sort(off.begin(), off.end(), [](P a, P b) { if (a.second != b.second) return a.second < b.second; return a.first > b.first; }); int eta = k + 1; if (eta < best.eta) { best.ok = true; best.eta = eta; best.target = c; best.offPath = off; } } } return best; } pair<P, bool> chooseWallMove() { vector<P> base, other; for (P w : wallCells) { if (isBlack(w)) continue; if (baseWallCell(w)) base.push_back(w); else other.push_back(w); } vector<P> candidates = !base.empty() ? base : other; if (candidates.empty()) return {{-1, -1}, false}; int minimumDeadline = 1000000; for (P w : candidates) { minimumDeadline = min(minimumDeadline, deadlineInfo(w, {rx, ry}).first); } if (!base.empty() && minimumDeadline > 5) { vector<P> special; for (P w : candidates) { if (specialWallCell(w)) special.push_back(w); } if (!special.empty()) candidates = special; } P best = {-1, -1}; int bestDanger = 1000000000; pair<int, int> bestInfo = {1000000000, 1000000000}; for (P w : candidates) { int danger = dangerAfterMark(w); auto info = deadlineInfo(w, {rx, ry}); if (best.first == -1 || danger < bestDanger || (danger == bestDanger && info < bestInfo)) { best = w; bestDanger = danger; bestInfo = info; } } if (bestDanger > 0 && emergencyUsed < EMERGENCY_LIMIT && (rx >= N - 5 || ry >= N - 5)) { P emergency = {-1, -1}; int emergencyDanger = bestDanger; for (P q : neighbors({rx, ry})) { if (q.first >= N || q.second >= N || !markable(q) || isBlack(q)) continue; int danger = dangerAfterMark(q); if (danger < emergencyDanger) { emergencyDanger = danger; emergency = q; } } if (emergency.first != -1) return {emergency, true}; } return {best, false}; } P chooseFillMove() { P best = {-1, -1}; pair<int, pair<int, int>> bestScore = {1000000000, {1000000000, 1000000000}}; for (P q : fillCells) { if (isBlack(q)) continue; int d = max(abs(q.first - rx), abs(q.second - ry)); auto score = make_pair(d, make_pair(q.second, q.first)); if (best.first == -1 || score < bestScore) { best = q; bestScore = score; } } return best; } P anyWhiteCell() { for (int x = 1; x <= 3000; ++x) { for (int y = 1; y <= 3000; ++y) { if (!isBlack({x, y})) return {x, y}; } } return {1, 1}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (!(cin >> rx >> ry)) return 0; for (int y = 1; y <= N; ++y) wallCells.push_back({N, y}); for (int x = 1; x < N; ++x) wallCells.push_back({x, N}); for (int x = 1; x < N; ++x) { for (int y = 1; y < N; ++y) { if (!(x % 2 == 0 && y % 2 == 0)) fillCells.push_back({x, y}); } } bool escaped = false; for (int turn = 1; turn <= T; ++turn) { bool wallSolid = true; for (P w : wallCells) { if (!isBlack(w)) { wallSolid = false; break; } } bool inside = rx > 0 && ry > 0 && rx < N && ry < N; if (!inside) escaped = true; vector<P> whiteMoves; bool unmarkableWhite = false; for (P q : neighbors({rx, ry})) { if (isBlack(q)) continue; if (!markable(q)) unmarkableWhite = true; whiteMoves.push_back(q); } P move = {-1, -1}; bool emergencyMove = false; bool localMove = false; if (!unmarkableWhite && whiteMoves.size() <= 1) { if (whiteMoves.size() == 1) move = whiteMoves[0]; else move = anyWhiteCell(); } if (move.first == -1 && escaped) { Plan plan = makePlan(false); if (plan.ok && !plan.offPath.empty()) { move = plan.offPath.front(); } else if (markable({rx, ry}) && !isBlack({rx, ry})) { move = {rx, ry}; } else { for (P q : neighbors({rx, ry})) { if (markable(q) && !isBlack(q)) { move = q; break; } } } } if (move.first == -1 && !wallSolid) { vector<P> urgent = urgentWallCells({rx, ry}); if (!urgent.empty()) { move = urgent[0]; int bestDanger = dangerAfterMark(move); for (P w : urgent) { int danger = dangerAfterMark(w); if (danger < bestDanger || (danger == bestDanger && baseWallCell(w) && !baseWallCell(move))) { move = w; bestDanger = danger; } } } } if (move.first == -1) { Plan plan = makePlan(true); bool canUse = plan.ok && !plan.offPath.empty() && localUsed < LOCAL_LIMIT; if (canUse && !wallSolid) { int distanceToWall = min(N - rx, N - ry); if (distanceToWall <= 20 && plan.eta > 4) canUse = false; } if (canUse) { move = plan.offPath.front(); localMove = true; } } if (move.first == -1 && !wallSolid) { auto choice = chooseWallMove(); move = choice.first; emergencyMove = choice.second; } if (move.first == -1 && wallSolid) { move = chooseFillMove(); } if (move.first == -1 || !markable(move)) move = anyWhiteCell(); if (localMove) ++localUsed; if (emergencyMove) ++emergencyUsed; cout << move.first << ' ' << move.second << endl; blackCells.insert(move); int nx, ny; if (!(cin >> nx >> ny)) return 0; if (nx == 0 && ny == 0) return 0; vx = nx - rx; vy = ny - ry; rx = nx; ry = ny; } return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 269 行
#include <bits/stdc++.h> using namespace std; struct Cell { int x, y; bool operator==(const Cell& other) const { return x == other.x && y == other.y; } }; struct Plan { Cell center{}; Cell opening{}; Cell approach{}; vector<Cell> order; int age = 0; }; static set<pair<int, int>> blackCells; static bool markable(int x, int y) { return 1 <= x && x <= 3000 && 1 <= y && y <= 3000; } static bool isBlack(int x, int y) { return blackCells.count({x, y}); } static int dist2(const Cell& a, const Cell& b) { int dx = a.x - b.x, dy = a.y - b.y; return dx * dx + dy * dy; } static int cheb(const Cell& a, const Cell& b) { return max(abs(a.x - b.x), abs(a.y - b.y)); } static vector<Cell> cageNeighbors(Cell c) { vector<Cell> result; for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx == 0 && dy == 0) continue; int x = c.x + dx, y = c.y + dy; if (markable(x, y)) result.push_back({x, y}); } } return result; } static Plan makePlan(Cell r, const vector<Cell>& history) { Plan p; Cell d{0, 0}; if (history.size() == 1) { if (r.y <= r.x) d = {0, -1}; else d = {-1, 0}; } else { int back = max(0, (int)history.size() - 7); int vx = r.x - history[back].x; int vy = r.y - history[back].y; Cell last = history[history.size() - 2]; int lx = r.x - last.x; int ly = r.y - last.y; if (vx == 0 && vy == 0) { vx = lx; vy = ly; } int ax = abs(vx), ay = abs(vy); if (ax > 2 * ay) vy = 0; if (ay > 2 * ax) vx = 0; d.x = (vx > 0) - (vx < 0); d.y = (vy > 0) - (vy < 0); if (d.x == 0 && d.y == 0) { d.x = (lx > 0) - (lx < 0); d.y = (ly > 0) - (ly < 0); } if (d.x == 0 && d.y == 0) { if (r.y <= r.x) d = {0, -1}; else d = {-1, 0}; } } p.approach = d; int boundaryDistance = INT_MAX; if (d.x < 0) boundaryDistance = min(boundaryDistance, r.x - 1); if (d.y < 0) boundaryDistance = min(boundaryDistance, r.y - 1); if (history.size() == 1) { if (d.x < 0) p.center = {1, r.y}; else p.center = {r.x, 1}; } else if (boundaryDistance != INT_MAX && boundaryDistance > 0 && boundaryDistance <= 16) { p.center = {r.x + boundaryDistance * d.x, r.y + boundaryDistance * d.y}; } else { p.center = {r.x + 8 * d.x, r.y + 8 * d.y}; } p.center.x = max(1, min(3000, p.center.x)); p.center.y = max(1, min(3000, p.center.y)); vector<Cell> around = cageNeighbors(p.center); Cell candidate{p.center.x - d.x, p.center.y - d.y}; bool found = false; for (Cell c : around) { if (c == candidate) { found = true; break; } } if (found) { p.opening = candidate; } else { p.opening = around[0]; for (Cell c : around) { if (dist2(c, r) < dist2(p.opening, r)) p.opening = c; } } for (Cell c : around) { if (!(c == p.opening)) p.order.push_back(c); } stable_sort(p.order.begin(), p.order.end(), [&](const Cell& a, const Cell& b) { return dist2(a, r) > dist2(b, r); }); return p; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Cell robot{}; cin >> robot.x >> robot.y; vector<Cell> history; history.push_back(robot); Plan plan; bool havePlan = false; for (int turn = 1; turn <= 3000; ++turn) { vector<Cell> whiteNeighbors; int inaccessible = 0; for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx == 0 && dy == 0) continue; int x = robot.x + dx, y = robot.y + dy; if (x <= 0 || y <= 0) continue; if (!isBlack(x, y)) { if (markable(x, y)) whiteNeighbors.push_back({x, y}); else ++inaccessible; } } } Cell chosen{0, 0}; if (whiteNeighbors.size() == 1 && inaccessible == 0) { chosen = whiteNeighbors[0]; } else if (whiteNeighbors.empty() && inaccessible == 0) { chosen = {1, 1}; } if (chosen.x == 0) { if (!havePlan) { plan = makePlan(robot, history); havePlan = true; } ++plan.age; if (robot == plan.center) { if (markable(plan.opening.x, plan.opening.y) && !isBlack(plan.opening.x, plan.opening.y)) { chosen = plan.opening; } else { for (Cell c : cageNeighbors(plan.center)) { if (!isBlack(c.x, c.y)) { chosen = c; break; } } } } if (chosen.x == 0) { bool complete = true; for (Cell c : plan.order) { if (!isBlack(c.x, c.y)) { complete = false; break; } } if (complete && cheb(robot, plan.center) > 2) { plan = makePlan(robot, history); plan.age = 1; } else if (plan.age > 10) { plan = makePlan(robot, history); plan.age = 1; } } if (chosen.x == 0) { bool complete = true; for (Cell c : plan.order) { if (!isBlack(c.x, c.y)) { complete = false; chosen = c; break; } } if (complete) { if (robot == plan.opening && markable(plan.opening.x, plan.opening.y) && !isBlack(plan.opening.x, plan.opening.y)) { chosen = plan.opening; } else if (cheb(robot, plan.center) <= 2 && markable(robot.x, robot.y) && !isBlack(robot.x, robot.y)) { chosen = robot; } else if (markable(robot.x, robot.y) && !isBlack(robot.x, robot.y)) { chosen = robot; } else if (!isBlack(plan.opening.x, plan.opening.y)) { chosen = plan.opening; } } } } if (chosen.x == 0) { if (markable(robot.x, robot.y) && !isBlack(robot.x, robot.y)) { chosen = robot; } else { chosen = {1, 1}; for (Cell c : whiteNeighbors) { chosen = c; break; } } } cout << chosen.x << ' ' << chosen.y << '\n'; cout.flush(); blackCells.insert({chosen.x, chosen.y}); Cell response{}; cin >> response.x >> response.y; if (response.x == 0 && response.y == 0) return 0; robot = response; history.push_back(robot); } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 61 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int sx, sy; cin >> sx >> sy; int rx = sx, ry = sy; const int MAXC = 3005; vector<vector<bool>> black(MAXC, vector<bool>(MAXC, false)); auto is_black = [&](int x, int y) -> bool { if (x < 1 || x >= MAXC || y < 1 || y >= MAXC) return true; return black[x][y]; }; for (int turn = 0; turn < 3000; ++turn) { int bx = -1, by = -1; vector<pair<int,int>> candidates; if (rx >= ry) { candidates.push_back({rx+1, ry}); candidates.push_back({rx, ry+1}); candidates.push_back({rx+1, ry+1}); } else { candidates.push_back({rx, ry+1}); candidates.push_back({rx+1, ry}); candidates.push_back({rx+1, ry+1}); } for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx == 0 && dy == 0) continue; candidates.push_back({rx+dx, ry+dy}); } } for (auto [x, y] : candidates) { if (x >= 1 && x < MAXC && y >= 1 && y < MAXC && !black[x][y]) { bx = x; by = y; break; } } if (bx == -1) { bx = 1; by = 1; while (is_black(bx, by)) { bx = rand() % 3000 + 1; by = rand() % 3000 + 1; } } black[bx][by] = true; cout << bx << " " << by << endl; int nx, ny; cin >> nx >> ny; if (nx == 0 && ny == 0) { return 0; } rx = nx; ry = ny; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 200 行
#include <bits/stdc++.h> using namespace std; struct Position { int x, y; }; struct Candidate { Position target; double weight = 0.0; }; static constexpr int LIMIT = 3000; bool operator<(const Position &a, const Position &b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } Position clampPosition(int x, int y) { x = max(1, min(LIMIT, x)); y = max(1, min(LIMIT, y)); return {x, y}; } Position projectToBoundary(const Position &p, int vx, int vy) { if (vx == 0 && vy == 0) return p; int steps = INT_MAX; if (vx < 0) steps = min(steps, p.x - 1); if (vx > 0) steps = min(steps, LIMIT - p.x); if (vy < 0) steps = min(steps, p.y - 1); if (vy > 0) steps = min(steps, LIMIT - p.y); if (steps == INT_MAX) return p; return clampPosition(p.x + vx * steps, p.y + vy * steps); } vector<Position> buildCage(Position target) { vector<Position> cage; if (target.y == 1) { cage.push_back({target.x + 1, target.y}); cage.push_back({target.x - 1, target.y}); cage.push_back({target.x + 1, target.y + 1}); cage.push_back({target.x - 1, target.y + 1}); cage.push_back({target.x, target.y + 1}); } else if (target.y == LIMIT) { cage.push_back({target.x + 1, target.y}); cage.push_back({target.x - 1, target.y}); cage.push_back({target.x + 1, target.y - 1}); cage.push_back({target.x - 1, target.y - 1}); cage.push_back({target.x, target.y - 1}); } else if (target.x == 1) { cage.push_back({target.x, target.y + 1}); cage.push_back({target.x, target.y - 1}); cage.push_back({target.x + 1, target.y + 1}); cage.push_back({target.x + 1, target.y - 1}); cage.push_back({target.x + 1, target.y}); } else if (target.x == LIMIT) { cage.push_back({target.x, target.y + 1}); cage.push_back({target.x, target.y - 1}); cage.push_back({target.x - 1, target.y + 1}); cage.push_back({target.x - 1, target.y - 1}); cage.push_back({target.x - 1, target.y}); } else { cage.push_back({target.x + 1, target.y}); cage.push_back({target.x + 1, target.y + 1}); cage.push_back({target.x, target.y + 1}); cage.push_back({target.x - 1, target.y + 1}); cage.push_back({target.x - 1, target.y}); cage.push_back({target.x - 1, target.y - 1}); cage.push_back({target.x, target.y - 1}); cage.push_back({target.x + 1, target.y - 1}); } for (int radius = 2; radius <= 3; ++radius) { for (int dx = -radius; dx <= radius; ++dx) { for (int dy = -radius; dy <= radius; ++dy) { if (max(abs(dx), abs(dy)) != radius) continue; int x = target.x + dx; int y = target.y + dy; if (1 <= x && x <= LIMIT && 1 <= y && y <= LIMIT) { cage.push_back({x, y}); } } } } cage.push_back(target); return cage; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Position current; if (!(cin >> current.x >> current.y)) return 0; set<Position> black; vector<Position> history; history.push_back(current); for (int turn = 1; turn <= LIMIT; ++turn) { map<Position, double> targetWeights; if (history.size() == 1) { targetWeights[clampPosition(current.x, 1)] += 2.0; targetWeights[clampPosition(1, current.y)] += 1.2; targetWeights[current] += 0.15; } else { int transitions = min<int>(5, history.size() - 1); for (int age = 0; age < transitions; ++age) { const Position &a = history[history.size() - 2 - age]; const Position &b = history[history.size() - 1 - age]; int vx = (b.x > a.x) - (b.x < a.x); int vy = (b.y > a.y) - (b.y < a.y); double weight = (age == 0 ? 6.0 : 2.5 / (age + 1)); Position target = projectToBoundary(current, vx, vy); targetWeights[target] += weight; } double sx = 0.0, sy = 0.0; for (int i = max(1, (int)history.size() - 5); i < (int)history.size(); ++i) { sx += history[i].x - history[i - 1].x; sy += history[i].y - history[i - 1].y; } int vx = (sx > 0.05) - (sx < -0.05); int vy = (sy > 0.05) - (sy < -0.05); if (vx || vy) { targetWeights[projectToBoundary(current, vx, vy)] += 3.0; } if (current.x <= 3 || current.y <= 3 || current.x >= LIMIT - 3 || current.y >= LIMIT - 3) { targetWeights[current] += 2.5; } } Position chosenTarget = current; double bestWeight = -1.0; vector<Position> chosenCage; size_t chosenIndex = 0; for (const auto &[target, weight] : targetWeights) { vector<Position> cage = buildCage(target); for (size_t i = 0; i < cage.size(); ++i) { if (!black.count(cage[i])) { if (weight > bestWeight) { bestWeight = weight; chosenTarget = target; chosenCage = move(cage); chosenIndex = i; } break; } } } Position toMark; if (!chosenCage.empty()) { toMark = chosenCage[chosenIndex]; } else { bool found = false; const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; for (int d = 0; d < 8; ++d) { Position p{current.x + dx[d], current.y + dy[d]}; if (p.x < 1 || p.x > LIMIT || p.y < 1 || p.y > LIMIT) continue; if (black.count(p)) continue; toMark = p; found = true; break; } if (!found) toMark = clampPosition(current.x, current.y); } black.insert(toMark); cout << toMark.x << ' ' << toMark.y << endl; Position next; if (!(cin >> next.x >> next.y)) return 0; if (next.x == 0 && next.y == 0) return 0; current = next; history.push_back(current); } return 0; }