题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem Statement
--------
There is a floor consisting of $50\times 50$ squares.
The floor is covered with rectangular tiles without any gaps.
Each tile has a size of either $1\times 1$, $1\times 2$, or $2\times 1$ squares.
Let $(0, 0)$ denote the top-left square, and $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
Takahashi starts from $(si, sj)$ and walks along a path satisfying the following conditions.
- From $(i, j)$, he can move to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, or $(i,j+1)$ in one step.
- He can step on the same tile only once. The tile at the initial position is assumed to have already been stepped on.
Each square has an integer value, and the score of a path is the sum of the values of the visited squares, including the square at the initial position.
Your goal is to find a path with as high a score as possible.
Moving between two squares of the same tile is invalid, as is returning to a tile after leaving it.
Raw task objective
--------
The formulas in this section define the raw reward V, not final benchmark points. The Scoring section specifies the per-file award and its aggregation.
The raw task reward V is the sum of the visited-square values, including the starting square.
If the output does not satisfy the conditions, it is judged as `WA`.
Input
--------
Input is given from Standard Input in the following format:
~~~
$si$ $sj$
$t_{0,0}$ $t_{0,1}$ $\ldots$ $t_{0,49}$
$\vdots$
$t_{49,0}$ $t_{49,1}$ $\ldots$ $t_{49,49}$
$p_{0,0}$ $p_{0,1}$ $\ldots$ $p_{0,49}$
$\vdots$
$p_{49,0}$ $p_{49,1}$ $\ldots$ $p_{49,49}$
~~~
- $(si,sj)$ denotes the initial position and satisfies $0\leq si,sj\leq 49$.
- $t_{i,j}$ is an integer representing the tile placed on $(i,j)$. $(i,j)$ and $(i',j')$ are covered by the same tile if and only if $t_{i,j}=t_{i',j'}$ holds. Let the total number of tiles be $M$, then $0\leq t_{i,j}\leq M-1$ is satisfied.
- $p_{i,j}$ is an integer value satisfying $0\leq p_{i,j}\leq 99$ which represents the score obtained when visiting $(i,j)$.
Output
--------
Let `U`, `D`, `L`, and `R` represent the movement from $(i,j)$ to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, and $(i,j+1)$, respectively.
Output a string representing a path in one line.
Input Generation
--------
#### Generation of $si,sj$
Generate an integer between $0$ and $49$ uniformly at random.
#### Generation of $t_{i,j}$
We start from an initial configuration where tiles of size $1\times 1$ are placed on all squares.
We shuffle the 50x50 squares in random order and perform the following process for each square in order.
- If the tile placed on the current square is $1\times 1$, we randomly select one of the adjacent squares whose tile is $1\times 1$ and connect the two tiles into one tile. If there are no such adjacent squares, we do nothing.
- If the tile placed on the current square is not $1\times 1$, we do nothing.
#### Generation of $p_{i,j}$
Generate an integer between $0$ and $99$ uniformly at random independently for each square.
Tools
--------
- <a href="https://img.atcoder.jp/ahc002/8c847d8177acc2dd417be4327252e39e.zip">Inputs</a>: A set of 100 inputs (seed 0-99) for local testing, including the sample input (seed 0). These inputs are different from the actual test case.
- <a href="https://img.atcoder.jp/ahc002/e5b2b399792299b5b35543c219e89601.html">Visualizer on the web</a>
- <a href="https://img.atcoder.jp/ahc002/c993bb7f09d9f8857fc90951fc6af11d.zip">Input generator and visualizer</a>: If you want to use more inputs, or if you want to visualize your output locally, you can use this program. You need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.
{sample example}
## Scoring
All feasibility and interaction limits apply before scoring; invalid output receives zero. Points are averaged over test files. For the logarithmic branch, write x for the original maximizing quantity or quality and a for its physical 60-point reference. The improvement factor is r=x/a, and the upper-band award is P=min(100,60+ln(r)). Here ln is natural: r=1 corresponds to 60 points, and on the uncapped logarithmic upper band, r=exp(P-60). Each additional point multiplies the physical improvement factor by e (divides a minimizing objective by e or multiplies a maximizing objective by e, as applicable). The lower-band, zero-objective, and completion rules below still apply.
Let V be the raw task reward defined in the problem, and let B and R be the stored baseline and reference rewards. They are calibration values, not assertions of optimality. The stored reward reference R is distinct from the physical reference a used in the logarithm; a is defined by the inverse or stage-specific formula below. Set L=60*max(0,(V-B)/(R-B)), with R>B, and T=R. For nonzero minimizing objectives, and all maximizing objectives, keep L exactly whenever L<=60. The following describes the upper band and any valid zero-cost optimum.
The original objective is the task reward V itself, including any task-defined composite weighting, rather than the calibrated improvement (V-B)/(R-B). When L>60, take x=V, a=T, and r=x/a; award min(100,60+ln(r)). V=0 is not a perfect solution and receives no special full-score award.
The checker reports points/100.
结果
Kimi K3.1 ProKimi
max
0.0
平均得分 ↑
- 0.0采样 1 · 答案错误
- 20.7k平均输出 token(含思考) ↓
- 28.6输出速度 tokens/s ↑
- 725 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
0.0
平均得分 ↑
- 0.0采样 1 · 编译错误
- 12.6k平均输出 token(含思考) ↓
- 25.8输出速度 tokens/s ↑
- 493 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
0.0
平均得分 ↑
- 0.0采样 1 · 答案错误
- 24.6k平均输出 token(含思考) ↓
- 178.2输出速度 tokens/s ↑
- 138 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
14.2
平均得分 ↑
- 14.2采样 1 · 部分分
- 65.4k平均输出 token(含思考) ↓
- 103.0输出速度 tokens/s ↑
- 636 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 399 行
#include <bits/stdc++.h> using namespace std; class Solver { static constexpr int H = 50; static constexpr int W = 50; static constexpr int dr[4] = {-1, 1, 0, 0}; static constexpr int dc[4] = {0, 0, -1, 1}; int si, sj, startCell, M = 0; int id[H][W], val[H][W]; vector<int> tileWeight; vector<vector<int>> adj; vector<unsigned char> vis; vector<int> pos; vector<int> path, bestPath; int bestScore = 0; vector<int> seen, bfsQueue; int bfsStamp = 0; uint32_t rngState = 0x9e3779b9u; chrono::steady_clock::time_point deadline; uint32_t rnd() { rngState ^= rngState << 13; rngState ^= rngState >> 17; rngState ^= rngState << 5; return rngState; } int randint(int n) { return n <= 0 ? 0 : int(rnd() % uint32_t(n)); } bool expired() const { return chrono::steady_clock::now() >= deadline; } inline bool inside(int r, int c) const { return 0 <= r && r < H && 0 <= c && c < W; } int onwardDegree(int cell, int enteringTile) const { int r = cell / W, c = cell % W; int degree = 0; for (int d = 0; d < 4; ++d) { int nr = r + dr[d], nc = c + dc[d]; if (!inside(nr, nc)) continue; int nt = id[nr][nc]; if (nt != enteringTile && !vis[nt]) ++degree; } return degree; } void reachableFrom(int cell, int enteringTile, int &count, int &weightSum) { vis[enteringTile] = 1; ++bfsStamp; int qh = 0, qt = 0; count = 0; weightSum = 0; int r = cell / W, c = cell % W; for (int d = 0; d < 4; ++d) { int nr = r + dr[d], nc = c + dc[d]; if (!inside(nr, nc)) continue; int nt = id[nr][nc]; if (!vis[nt] && seen[nt] != bfsStamp) { seen[nt] = bfsStamp; bfsQueue[qt++] = nt; } } while (qh < qt) { int t = bfsQueue[qh++]; ++count; weightSum += tileWeight[t]; for (int u : adj[t]) { if (!vis[u] && seen[u] != bfsStamp) { seen[u] = bfsStamp; bfsQueue[qt++] = u; } } } vis[enteringTile] = 0; } void considerPath(bool allowEqualRandom = false) { int score = 0; for (int cell : path) score += val[cell / W][cell % W]; bool replace = false; if (score > bestScore) replace = true; else if (score == bestScore && path.size() > bestPath.size()) replace = true; else if (allowEqualRandom && score == bestScore && path.size() == bestPath.size() && randint(8) == 0) replace = true; if (replace) { bestScore = score; bestPath = path; } } bool applyBackbite(int &stallLimit) { const int n = int(path.size()); if (n < 3) return false; int endpoint = path.back(); int er = endpoint / W, ec = endpoint % W; int candidateK[4]; long long candidateKey[4]; int candidateCount = 0; for (int d = 0; d < 4; ++d) { int nr = er + dr[d], nc = ec + dc[d]; if (!inside(nr, nc)) continue; int t = id[nr][nc]; if (!vis[t]) continue; int k = pos[t]; if (k < 0 || k > n - 3) continue; int newEndpoint = path[k + 1]; int rr = newEndpoint / W, cc = newEndpoint % W; int mobility = 0, bestNextValue = 0; for (int e = 0; e < 4; ++e) { int tr = rr + dr[e], tc = cc + dc[e]; if (!inside(tr, tc)) continue; int nt = id[tr][tc]; if (!vis[nt]) { ++mobility; bestNextValue = max(bestNextValue, val[tr][tc]); } } long long key; if (mobility > 0) { key = 1000000LL + bestNextValue * 100LL + mobility * 20LL + randint(256); } else { key = randint(10000); } candidateK[candidateCount] = k; candidateKey[candidateCount] = key; ++candidateCount; } if (candidateCount == 0) return false; int chosen = 0; for (int i = 1; i < candidateCount; ++i) { if (candidateKey[i] > candidateKey[chosen]) chosen = i; } int k = candidateK[chosen]; reverse(path.begin() + k + 1, path.end()); for (int i = k + 1; i < n; ++i) { int cell = path[i]; pos[id[cell / W][cell % W]] = i; } return true; } void runAttempt(bool fromBest, int cut, int style, bool useConnectivity, int rotationLimit) { path.clear(); if (fromBest && !bestPath.empty()) { path = bestPath; cut = min(cut, int(path.size()) - 1); path.resize(path.size() - cut); } else { path.push_back(startCell); } fill(vis.begin(), vis.end(), 0); fill(pos.begin(), pos.end(), -1); int score = 0; for (int i = 0; i < int(path.size()); ++i) { int cell = path[i]; int t = id[cell / W][cell % W]; vis[t] = 1; pos[t] = i; score += val[cell / W][cell % W]; } int stall = 0; const int stepCap = useConnectivity ? 6500 : 10000; for (int step = 0; step < stepCap; ++step) { if ((step & 7) == 0 && expired()) break; int endpoint = path.back(); int r = endpoint / W, c = endpoint % W; int bestCell = -1, bestTile = -1; long long bestKey = numeric_limits<long long>::min(); for (int d = 0; d < 4; ++d) { int nr = r + dr[d], nc = c + dc[d]; if (!inside(nr, nc)) continue; int nt = id[nr][nc]; if (vis[nt]) continue; int nextCell = nr * W + nc; int degree = onwardDegree(nextCell, nt); int squareValue = val[nr][nc]; long long key = 0; if (useConnectivity) { int reach = 0, reachWeight = 0; if (degree > 0) { reachableFrom(nextCell, nt, reach, reachWeight); } if ((style & 1) == 0) { key = (reach + 1) * 100000LL - degree * 1000LL + squareValue * 8LL + randint(128); } else { key = (reachWeight + tileWeight[nt]) * 1000LL - degree * 180LL + squareValue * 20LL + randint(256); } } else { int terminalPenalty = (degree == 0 ? 200000 : 0); switch (style % 6) { case 0: key = -degree * 2000LL + squareValue * 5LL + randint(256); break; case 1: key = -degree * 600LL + squareValue * 15LL + randint(512); break; case 2: key = -degree * 200LL + squareValue * 5LL + randint(3000); break; case 3: key = degree * 350LL + squareValue * 8LL + randint(1200); break; case 4: key = -degree * 1000LL + squareValue * 2LL + randint(1800); break; default: key = -degree * 800LL + squareValue * 25LL + randint(256); break; } key -= terminalPenalty; } if (key > bestKey) { bestKey = key; bestCell = nextCell; bestTile = nt; } } if (bestCell >= 0) { vis[bestTile] = 1; pos[bestTile] = int(path.size()); path.push_back(bestCell); score += val[bestCell / W][bestCell % W]; stall = 0; if (score > bestScore && (path.size() & 31ULL) == 0) { bestScore = score; bestPath = path; } } else { if (stall >= rotationLimit) break; if (!applyBackbite(rotationLimit)) break; ++stall; } } considerPath(true); } public: void solve() { auto beginTime = chrono::steady_clock::now(); deadline = beginTime + chrono::milliseconds(1850); cin >> si >> sj; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> id[i][j]; M = max(M, id[i][j] + 1); } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> val[i][j]; } } startCell = si * W + sj; vector<int> tileSum(M, 0), tileCells(M, 0); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { int t = id[i][j]; tileSum[t] += val[i][j]; ++tileCells[t]; } } tileWeight.resize(M); for (int t = 0; t < M; ++t) { tileWeight[t] = tileSum[t] / max(1, tileCells[t]); } adj.assign(M, {}); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { int a = id[i][j]; if (i + 1 < H) { int b = id[i + 1][j]; if (a != b) { adj[a].push_back(b); adj[b].push_back(a); } } if (j + 1 < W) { int b = id[i][j + 1]; if (a != b) { adj[a].push_back(b); adj[b].push_back(a); } } } } for (auto &v : adj) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } vis.assign(M, 0); pos.assign(M, -1); seen.assign(M, 0); bfsQueue.resize(M); bestPath = {startCell}; bestScore = val[si][sj]; int attempt = 0; while (!expired()) { bool fromBest = attempt >= 2 && randint(100) < 74; int cut = 0; if (fromBest) { int maxCut = int(bestPath.size()) - 1; if (maxCut > 0) { int type = randint(12); if (type < 2) { cut = 0; } else if (type < 6) { cut = 1 + randint(min(maxCut, 24)); } else if (type < 9) { cut = 1 + randint(min(maxCut, 160)); } else { cut = 1 + randint(maxCut); } } } int style = attempt < 2 ? attempt : randint(6); bool useConnectivity = attempt < 2 || randint(100) < (fromBest ? 58 : 40); int rotationLimit = 35 + randint(100); if (fromBest && cut == 0) rotationLimit += 100; runAttempt(fromBest, cut, style, useConnectivity, rotationLimit); ++attempt; } string answer; answer.reserve(bestPath.size()); for (int i = 1; i < int(bestPath.size()); ++i) { int a = bestPath[i - 1], b = bestPath[i]; if (b == a - W) answer.push_back('U'); else if (b == a + W) answer.push_back('D'); else if (b == a - 1) answer.push_back('L'); else answer.push_back('R'); } cout << answer << '\n'; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solver solver; solver.solve(); return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 267 行
#include <bits/stdc++.h> using namespace std; using Clock = chrono::steady_clock; struct XorShift { uint64_t x = 0x9e3779b97f4a7c15ULL; uint32_t next() { x ^= x << 7; x ^= x >> 9; x ^= x << 8; return static_cast<uint32_t>(x >> 32); } int nextInt(int n) { return static_cast<int>(next() % n); } }; struct Node { int parent; char dir; }; struct State { array<uint64_t, 40> used{}; int pos = 0; int score = 0; int node = 0; }; struct Candidate { int rank; int score; int pos; int tile; int parent; char dir; }; struct RankConfig { int lookahead; int mobility; uint32_t noiseMask; }; const int H = 50, W = 50; const int dr[4] = {-1, 1, 0, 0}; const int dc[4] = {0, 0, -1, 1}; const char dchar[4] = {'U', 'D', 'L', 'R'}; int startI, startJ; int tileAt[H][W]; int tileWeight[2500]; int startPos; XorShift rng; Clock::time_point deadline; int bestScore = -1; string bestPath; int charToDir(char c) { if (c == 'U') return 0; if (c == 'D') return 1; if (c == 'L') return 2; return 3; } void beamSearch(const string &prefix, int width, const RankConfig &cfg) { vector<Node> nodes; nodes.reserve(1024); nodes.push_back({-1, 0}); State initial; initial.used.fill(0); initial.pos = startPos; int currentTile = tileAt[startPos / W][startPos % W]; initial.used[currentTile >> 6] |= 1ULL << (currentTile & 63); initial.score = tileWeight[currentTile]; initial.node = 0; int pos = startPos; int currentNode = 0; for (char c : prefix) { int d = charToDir(c); int r = pos / W + dr[d]; int col = pos % W + dc[d]; pos = r * W + col; int t = tileAt[r][col]; initial.used[t >> 6] |= 1ULL << (t & 63); initial.score += tileWeight[t]; nodes.push_back({currentNode, c}); currentNode = static_cast<int>(nodes.size()) - 1; } initial.pos = pos; initial.node = currentNode; vector<State> current, next; vector<Candidate> candidates; current.reserve(width); next.reserve(width); candidates.reserve(width * 4); current.push_back(initial); auto buildPath = [&](int node, char extra) { string path; while (nodes[node].parent != -1) { path.push_back(nodes[node].dir); node = nodes[node].parent; } reverse(path.begin(), path.end()); path.push_back(extra); return path; }; while (!current.empty()) { if (Clock::now() >= deadline) return; candidates.clear(); bool stopped = false; for (int i = 0; i < static_cast<int>(current.size()); ++i) { if ((i & 63) == 0 && Clock::now() >= deadline) { stopped = true; break; } const State &state = current[i]; int r = state.pos / W; int c = state.pos % W; for (int d = 0; d < 4; ++d) { int nr = r + dr[d]; int nc = c + dc[d]; if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue; int np = nr * W + nc; int nt = tileAt[nr][nc]; if ((state.used[nt >> 6] >> (nt & 63)) & 1ULL) continue; int ns = state.score + tileWeight[nt]; if (ns > bestScore) { bestScore = ns; bestPath = buildPath(state.node, dchar[d]); } int degree = 0; int lookahead = 0; for (int e = 0; e < 4; ++e) { int rr = nr + dr[e]; int cc = nc + dc[e]; if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue; int tt = tileAt[rr][cc]; if (tt == nt) continue; if ((state.used[tt >> 6] >> (tt & 63)) & 1ULL) continue; ++degree; lookahead += tileWeight[tt]; } if (degree == 0) continue; int rank = ns * 64 + lookahead * cfg.lookahead + degree * cfg.mobility; if (cfg.noiseMask) rank += static_cast<int>(rng.next() & cfg.noiseMask); candidates.push_back({rank, ns, np, nt, i, dchar[d]}); } } if (stopped) return; if (candidates.empty()) break; int keep = min(width, static_cast<int>(candidates.size())); if (keep < static_cast<int>(candidates.size())) { nth_element(candidates.begin(), candidates.begin() + keep, candidates.end(), [](const Candidate &a, const Candidate &b) { return a.rank > b.rank; }); candidates.resize(keep); } next.clear(); for (const Candidate &cand : candidates) { int newNode = static_cast<int>(nodes.size()); nodes.push_back({current[cand.parent].node, cand.dir}); State state = current[cand.parent]; state.used[cand.tile >> 6] |= 1ULL << (cand.tile & 63); state.pos = cand.pos; state.score = cand.score; state.node = newNode; next.push_back(state); } current.swap(next); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> startI >> startJ; startPos = startI * W + startJ; int maxTile = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> tileAt[i][j]; maxTile = max(maxTile, tileAt[i][j]); } } fill(tileWeight, tileWeight + maxTile + 1, 0); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { int p; cin >> p; tileWeight[tileAt[i][j]] += p; } } rng.x ^= static_cast<uint64_t>(startPos + 1) * 0xbf58476d1ce4e5b9ULL; bestScore = tileWeight[tileAt[startI][startJ]]; bestPath.clear(); deadline = Clock::now() + chrono::milliseconds(1850); beamSearch("", 1800, {8, 80, 0}); int iteration = 0; while (Clock::now() < deadline) { string base = bestPath; int len = static_cast<int>(base.size()); int cut = 0; auto remaining = duration_cast<chrono::milliseconds>( deadline - Clock::now()).count(); if (len > 1) { int lo, hi; if (remaining < 180) { lo = len * 4 / 5; hi = len * 19 / 20; } else { lo = len / 4; hi = len * 3 / 4; } hi = min(hi, len - 1); lo = min(lo, hi); cut = lo + rng.nextInt(hi - lo + 1); } if (iteration % 7 == 6 && remaining > 650) cut = 0; string prefix = base.substr(0, cut); RankConfig cfg; cfg.lookahead = rng.nextInt(13); cfg.mobility = rng.nextInt(201) - 50; cfg.noiseMask = (1U << (5 + rng.nextInt(8))) - 1; int width = (cut == 0 ? 1000 : 650); if (remaining < 180) width = 400; beamSearch(prefix, width, cfg); ++iteration; } cout << bestPath << '\n'; return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 190 行
#include <bits/stdc++.h> using namespace std; using namespace chrono; struct Edge { int to; char dir; }; struct Node { int parent; char move; }; struct State { int pos, score, node; uint64_t used[40]; }; struct Candidate { int pos, score, parent, move, avail, rank; uint64_t used[40]; }; int tileId[2500], val[2500]; vector<Edge> neigh[2500]; int B; int startPos; struct BeamResult { int score; string path; }; BeamResult runBeam(int W, int alpha, int seed, double timeLimitSec) { auto startTime = steady_clock::now(); vector<State> cur, next; cur.reserve(W); next.reserve(W); vector<Candidate> candidates; candidates.reserve(W * 4); vector<Node> nodes; nodes.reserve(W * 1500); nodes.push_back({-1, 0}); State root; root.pos = startPos; root.score = val[startPos]; root.node = 0; memset(root.used, 0, sizeof(root.used)); int stTile = tileId[startPos]; root.used[stTile >> 6] |= 1ULL << (stTile & 63); cur.push_back(root); int bestScore = val[startPos]; int bestParent = -1; char bestMove = 0; bool bestHasExtra = false; uint32_t rng = seed; while (!cur.empty()) { auto now = steady_clock::now(); double elapsed = duration<double>(now - startTime).count(); if (elapsed > timeLimitSec) break; candidates.clear(); for (auto &st : cur) { for (auto &e : neigh[st.pos]) { int nt = tileId[e.to]; if (!((st.used[nt >> 6] >> (nt & 63)) & 1ULL)) { candidates.emplace_back(); Candidate &cand = candidates.back(); cand.pos = e.to; cand.score = st.score + val[e.to]; cand.parent = st.node; cand.move = e.dir; memcpy(cand.used, st.used, B * sizeof(uint64_t)); cand.used[nt >> 6] |= 1ULL << (nt & 63); int avail = 0; for (auto &e2 : neigh[e.to]) { int nt2 = tileId[e2.to]; if (!((cand.used[nt2 >> 6] >> (nt2 & 63)) & 1ULL)) avail++; } cand.avail = avail; rng ^= rng << 13; rng ^= rng >> 17; rng ^= rng << 5; cand.rank = cand.score * 1000 + alpha * avail + (rng & 127); if (cand.score > bestScore) { bestScore = cand.score; bestParent = st.node; bestMove = e.dir; bestHasExtra = true; } } } } if (candidates.empty()) break; vector<int> idx; idx.reserve(candidates.size()); for (int i = 0; i < (int)candidates.size(); ++i) { if (candidates[i].avail > 0) idx.push_back(i); } if (idx.empty()) break; int take = min((int)idx.size(), W); if (take < (int)idx.size()) { nth_element(idx.begin(), idx.begin() + take, idx.end(), [&](int a, int b) { return candidates[a].rank > candidates[b].rank; }); idx.resize(take); } next.clear(); next.reserve(take); for (int id : idx) { Candidate &cand = candidates[id]; int nodeId = (int)nodes.size(); nodes.push_back({cand.parent, cand.move}); next.emplace_back(); State &st = next.back(); st.pos = cand.pos; st.score = cand.score; st.node = nodeId; memcpy(st.used, cand.used, B * sizeof(uint64_t)); } cur.swap(next); } string ans; int node = bestParent; while (node != -1) { ans.push_back(nodes[node].move); node = nodes[node].parent; } reverse(ans.begin(), ans.end()); if (bestHasExtra) ans.push_back(bestMove); return {bestScore, ans}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int si, sj; cin >> si >> sj; for (int i = 0; i < 50; ++i) { for (int j = 0; j < 50; ++j) { cin >> tileId[i * 50 + j]; } } int maxTile = 0; for (int i = 0; i < 2500; ++i) maxTile = max(maxTile, tileId[i]); int M = maxTile + 1; B = (M + 63) / 64; for (int i = 0; i < 50; ++i) { for (int j = 0; j < 50; ++j) { cin >> val[i * 50 + j]; } } startPos = si * 50 + sj; for (int r = 0; r < 50; ++r) { for (int c = 0; c < 50; ++c) { int idx = r * 50 + c; if (r > 0) neigh[idx].push_back({idx - 50, 'U'}); if (r < 49) neigh[idx].push_back({idx + 50, 'D'}); if (c > 0) neigh[idx].push_back({idx - 1, 'L'}); if (c < 49) neigh[idx].push_back({idx + 1, 'R'}); } } auto overallStart = steady_clock::now(); const double totalLimit = 1.8; int globalBestScore = -1; string globalBestPath = ""; int runIndex = 0; while (true) { double elapsed = duration<double>(steady_clock::now() - overallStart).count(); double remaining = totalLimit - elapsed; if (remaining < 0.02) break; int W; int alpha; if (runIndex == 0) { W = 4000; alpha = 50000; } else if (runIndex == 1) { W = 3000; alpha = 0; } else if (runIndex == 2) { W = 2500; alpha = 100000; } else if (runIndex == 3) { W = 2500; alpha = -50000; } else { W = 2000; alpha = 30000; } int seed = 12345 + runIndex * 98765; double perRunLimit = min(remaining, 0.8); BeamResult res = runBeam(W, alpha, seed, perRunLimit); if (res.score > globalBestScore) { globalBestScore = res.score; globalBestPath = res.path; } ++runIndex; } cout << globalBestPath << '\n'; return 0; }
MiniMax M3.1 Flash · 采样 1 · 872 行
#include <bits/stdc++.h> using namespace std; static constexpr int SIDE = 50; static constexpr int CELLS = SIDE * SIDE; int tileId[CELLS]; int cellValue[CELLS]; bool tileUsed[CELLS]; vector<int> neighbors[CELLS]; uint64_t rngState = 88172645463325252ULL; uint32_t random32() { rngState ^= rngState >> 7; rngState ^= rngState << 9; return static_cast<uint32_t>(rngState); } int randomInt(int n) { return static_cast<int>(random32() % static_cast<uint32_t>(n)); } double randomDouble() { return (static_cast<double>(random32()) + 0.5) / 4294967296.0; } using Clock = chrono::steady_clock; Clock::time_point startTime; double elapsedSeconds() { return chrono::duration<double>(Clock::now() - startTime).count(); } bool adjacentCells(int a, int b) { int ar = a / SIDE, ac = a % SIDE; int br = b / SIDE, bc = b % SIDE; return abs(ar - br) + abs(ac - bc) == 1; } // --------------------------------------------------------------------------- // Initial path construction: randomized Warnsdorff DFS with backtracking. // --------------------------------------------------------------------------- vector<int> dfsPath; vector<int> initialBestPath; int dfsPathScore = 0; int initialBestScore = -1; int dfsNodeCount = 0; int dfsNodeLimit = 0; void considerCurrentDFSPath() { if (dfsPathScore > initialBestScore || (dfsPathScore == initialBestScore && static_cast<int>(dfsPath.size()) > static_cast<int>(initialBestPath.size()))) { initialBestScore = dfsPathScore; initialBestPath = dfsPath; } } void constructDFS(int current) { if (dfsNodeCount >= dfsNodeLimit || ((dfsNodeCount & 2047) == 0 && elapsedSeconds() > 0.245)) { considerCurrentDFSPath(); return; } ++dfsNodeCount; int t = tileId[current]; tileUsed[t] = true; dfsPath.push_back(current); dfsPathScore += cellValue[current]; struct Candidate { int cell; int exits; int noise; }; Candidate candidates[4]; int candidateCount = 0; for (int next : neighbors[current]) { if (tileUsed[tileId[next]]) continue; int exits = 0; for (int exit : neighbors[next]) { if (!tileUsed[tileId[exit]] && tileId[exit] != tileId[next]) { ++exits; } } candidates[candidateCount++] = { next, exits, static_cast<int>(random32() & 15ULL) }; } for (int i = 1; i < candidateCount; ++i) { Candidate x = candidates[i]; int j = i - 1; while (j >= 0) { bool xBefore = x.exits < candidates[j].exits || (x.exits == candidates[j].exits && x.noise < candidates[j].noise); bool sameNoise = x.exits == candidates[j].exits && x.noise == candidates[j].noise; if (!xBefore && !(sameNoise && cellValue[x.cell] > cellValue[candidates[j].cell])) { break; } candidates[j + 1] = candidates[j]; --j; } candidates[j + 1] = x; } if (candidateCount == 0) { considerCurrentDFSPath(); } else { for (int i = 0; i < candidateCount; ++i) { if (dfsNodeCount >= dfsNodeLimit || elapsedSeconds() > 0.245) break; constructDFS(candidates[i].cell); } } dfsPathScore -= cellValue[current]; dfsPath.pop_back(); tileUsed[t] = false; } // --------------------------------------------------------------------------- // Implicit treap storing the ordered path. // --------------------------------------------------------------------------- struct Treap { struct Node { int left = 0; int right = 0; int parent = 0; int size = 0; int sum = 0; int cell = -1; uint32_t priority = 0; bool reversed = false; }; vector<Node> nodes; vector<int> freeNodes; int cellNode[CELLS]; int root = 0; Treap() { nodes.reserve(CELLS + 16); reset(); } void reset() { nodes.clear(); nodes.emplace_back(); freeNodes.clear(); fill(cellNode, cellNode + CELLS, 0); root = 0; } int nodeSize(int t) const { return t ? nodes[t].size : 0; } int nodeSum(int t) const { return t ? nodes[t].sum : 0; } void pull(int t) { int l = nodes[t].left; int r = nodes[t].right; nodes[t].size = 1 + nodeSize(l) + nodeSize(r); nodes[t].sum = cellValue[nodes[t].cell] + nodeSum(l) + nodeSum(r); if (l) nodes[l].parent = t; if (r) nodes[r].parent = t; } void applyReverse(int t) { if (!t) return; swap(nodes[t].left, nodes[t].right); nodes[t].reversed = !nodes[t].reversed; } void push(int t) { if (!t || !nodes[t].reversed) return; applyReverse(nodes[t].left); applyReverse(nodes[t].right); nodes[t].reversed = false; } int newNode(int cell) { int id; if (freeNodes.empty()) { id = static_cast<int>(nodes.size()); nodes.emplace_back(); } else { id = freeNodes.back(); freeNodes.pop_back(); nodes[id] = Node(); } nodes[id].cell = cell; nodes[id].size = 1; nodes[id].sum = cellValue[cell]; nodes[id].priority = random32(); cellNode[cell] = id; return id; } pair<int, int> split(int t, int count) { if (!t) return {0, 0}; push(t); int leftSize = nodeSize(nodes[t].left); if (count <= leftSize) { auto [a, b] = split(nodes[t].left, count); nodes[t].left = b; pull(t); nodes[t].parent = 0; if (a) nodes[a].parent = 0; return {a, t}; } else { auto [a, b] = split(nodes[t].right, count - leftSize - 1); nodes[t].right = a; pull(t); nodes[t].parent = 0; if (b) nodes[b].parent = 0; return {t, b}; } } int merge(int a, int b) { if (!a) { if (b) nodes[b].parent = 0; return b; } if (!b) { nodes[a].parent = 0; return a; } if (nodes[a].priority < nodes[b].priority) { push(a); nodes[a].right = merge(nodes[a].right, b); pull(a); nodes[a].parent = 0; return a; } else { push(b); nodes[b].left = merge(a, nodes[b].left); pull(b); nodes[b].parent = 0; return b; } } int size() const { return nodeSize(root); } int nodeAt(int rank) { int t = root; while (t) { push(t); int leftSize = nodeSize(nodes[t].left); if (rank < leftSize) { t = nodes[t].left; } else if (rank == leftSize) { return t; } else { rank -= leftSize + 1; t = nodes[t].right; } } return 0; } int getRank(int node) { int chain[256]; int chainLength = 0; for (int t = node; t; t = nodes[t].parent) { chain[chainLength++] = t; } for (int i = chainLength - 1; i >= 0; --i) push(chain[i]); int rank = nodeSize(nodes[node].left); int t = node; while (nodes[t].parent) { int p = nodes[t].parent; if (nodes[p].right == t) { rank += nodeSize(nodes[p].left) + 1; } t = p; } return rank; } int prefixSum(int count) { int result = 0; int t = root; while (t && count > 0) { push(t); int leftSize = nodeSize(nodes[t].left); if (count <= leftSize) { t = nodes[t].left; } else { result += nodeSum(nodes[t].left) + cellValue[nodes[t].cell]; count -= leftSize + 1; t = nodes[t].right; } } return result; } int rangeSum(int left, int right) { if (left > right) return 0; return prefixSum(right + 1) - prefixSum(left); } void collect(int t, vector<int>& result) { if (!t) return; push(t); collect(nodes[t].left, result); result.push_back(nodes[t].cell); collect(nodes[t].right, result); } void collect(vector<int>& result) { result.clear(); collect(root, result); } void releaseTree(int t) { if (!t) return; push(t); int l = nodes[t].left; int r = nodes[t].right; releaseTree(l); releaseTree(r); int cell = nodes[t].cell; tileUsed[tileId[cell]] = false; cellNode[cell] = 0; freeNodes.push_back(t); } } treap; // --------------------------------------------------------------------------- // Local-search operations. // --------------------------------------------------------------------------- int currentScore = 0; int bestScore = -1; vector<int> bestPath; vector<int> temporaryPath; uint32_t seenTile[CELLS]; uint32_t seenStamp = 1; void rememberBest() { int currentLength = treap.size(); if (currentScore > bestScore || (currentScore == bestScore && currentLength > static_cast<int>(bestPath.size()))) { treap.collect(temporaryPath); bestPath = temporaryPath; bestScore = currentScore; } } void buildTreapFrom(const vector<int>& path) { treap.reset(); fill(tileUsed, tileUsed + CELLS, false); currentScore = 0; for (int cell : path) { tileUsed[tileId[cell]] = true; currentScore += cellValue[cell]; int node = treap.newNode(cell); treap.root = treap.merge(treap.root, node); } } struct Detour { int cells[20]; int count = 0; int gain = 0; bool valid = false; }; bool validateDetour(Detour& d) { ++seenStamp; if (seenStamp == 0) { fill(seenTile, seenTile + CELLS, 0); seenStamp = 1; } d.valid = true; d.gain = 0; for (int i = 0; i < d.count; ++i) { int cell = d.cells[i]; int t = tileId[cell]; if (tileUsed[t] || seenTile[t] == seenStamp) { d.valid = false; return false; } seenTile[t] = seenStamp; d.gain += cellValue[cell]; } return true; } bool buildDetour(int u, int v, int side, int height, Detour& d) { d.count = 0; int ur = u / SIDE, uc = u % SIDE; int vr = v / SIDE, vc = v % SIDE; if (ur == vr) { if (side > 0 && ur + height >= SIDE) return false; if (side < 0 && ur - height < 0) return false; for (int k = 1; k <= height; ++k) { d.cells[d.count++] = (ur + side * k) * SIDE + uc; } d.cells[d.count++] = (ur + side * height) * SIDE + vc; for (int k = height - 1; k >= 1; --k) { d.cells[d.count++] = (ur + side * k) * SIDE + vc; } } else { if (side > 0 && uc + height >= SIDE) return false; if (side < 0 && uc - height < 0) return false; for (int k = 1; k <= height; ++k) { d.cells[d.count++] = ur * SIDE + uc + side * k; } d.cells[d.count++] = vr * SIDE + uc + side * height; for (int k = height - 1; k >= 1; --k) { d.cells[d.count++] = vr * SIDE + uc + side * k; } } return true; } void insertCells(int position, const int* cells, int count, int gain) { for (int i = 0; i < count; ++i) { tileUsed[tileId[cells[i]]] = true; } auto [a, b] = treap.split(treap.root, position); int middle = 0; for (int i = 0; i < count; ++i) { int node = treap.newNode(cells[i]); middle = treap.merge(middle, node); } treap.root = treap.merge(treap.merge(a, middle), b); currentScore += gain; } bool insertRectangleDetour() { int n = treap.size(); if (n < 2) return false; int edgeRank = randomInt(n - 1); int u = treap.nodes[treap.nodeAt(edgeRank)].cell; int v = treap.nodes[treap.nodeAt(edgeRank + 1)].cell; int ur = u / SIDE, uc = u % SIDE; bool horizontal = (ur == v / SIDE); int maxPlus, maxMinus; if (horizontal) { maxPlus = SIDE - 1 - ur; maxMinus = ur; } else { maxPlus = SIDE - 1 - uc; maxMinus = uc; } int feasible[2]; int feasibleCount = 0; if (maxPlus > 0) feasible[feasibleCount++] = 1; if (maxMinus > 0) feasible[feasibleCount++] = -1; if (feasibleCount == 0) return false; int chosenSide = feasible[randomInt(feasibleCount)]; int maximumHeight = chosenSide > 0 ? maxPlus : maxMinus; int height = 1; if (maximumHeight > 1 && randomInt(8) == 0) { int choices = min(7, maximumHeight - 1); height = 2 + randomInt(choices); } Detour candidates[2]; int candidateCount = 0; for (int offset = 0; offset < feasibleCount; ++offset) { int side = feasible[(offset + randomInt(feasibleCount)) % feasibleCount]; int limit = side > 0 ? maxPlus : maxMinus; if (limit < height) continue; Detour d; if (!buildDetour(u, v, side, height, d)) continue; validateDetour(d); if (d.valid) candidates[candidateCount++] = d; } if (candidateCount == 0) return false; int selected = 0; if (candidateCount == 2) { if (candidates[0].gain != candidates[1].gain && randomInt(100) < 60) { selected = candidates[0].gain > candidates[1].gain ? 0 : 1; } else { selected = randomInt(2); } } const Detour& chosen = candidates[selected]; insertCells(edgeRank + 1, chosen.cells, chosen.count, chosen.gain); return true; } bool insertAtEndpoint() { int n = treap.size(); if (n == 0) return false; int endpoint = treap.nodes[treap.nodeAt(n - 1)].cell; int candidates[4]; int candidateCount = 0; for (int next : neighbors[endpoint]) { if (!tileUsed[tileId[next]]) candidates[candidateCount++] = next; } if (candidateCount == 0) return false; int selected = 0; if (candidateCount > 1) { if (randomInt(100) < 60) { int best = 0; for (int i = 1; i < candidateCount; ++i) { if (cellValue[candidates[i]] > cellValue[candidates[best]]) best = i; } selected = best; } else { selected = randomInt(candidateCount); } } int cell = candidates[selected]; tileUsed[tileId[cell]] = true; currentScore += cellValue[cell]; int node = treap.newNode(cell); treap.root = treap.merge(treap.root, node); return true; } void deleteRange(int left, int right) { if (left > right) return; auto [a, rest] = treap.split(treap.root, left); auto [middle, c] = treap.split(rest, right - left + 1); currentScore -= treap.nodeSum(middle); treap.root = treap.merge(a, c); treap.releaseTree(middle); } struct RangeProposal { int left; int right; int loss; int length; }; bool proposeChordDeletion(RangeProposal& proposal) { int n = treap.size(); if (n < 4) return false; int firstRank = randomInt(n); int firstCell = treap.nodes[treap.nodeAt(firstRank)].cell; int maximumLength = (randomInt(20) == 0 ? n : 32); RangeProposal proposals[4]; int proposalCount = 0; for (int secondCell : neighbors[firstCell]) { int secondNode = treap.cellNode[secondCell]; if (!secondNode) continue; int secondRank = treap.getRank(secondNode); if (abs(secondRank - firstRank) <= 1) continue; int left = min(firstRank, secondRank) + 1; int right = max(firstRank, secondRank) - 1; int length = right - left + 1; if (length <= 0 || (length & 1) || length > maximumLength) continue; proposals[proposalCount++] = { left, right, treap.rangeSum(left, right), length }; } if (proposalCount == 0) return false; int selected; if (randomInt(4) == 0) { selected = randomInt(proposalCount); } else { int shortest = INT_MAX; for (int i = 0; i < proposalCount; ++i) { shortest = min(shortest, proposals[i].length); } int choices[4]; int choiceCount = 0; for (int i = 0; i < proposalCount; ++i) { if (proposals[i].length == shortest) choices[choiceCount++] = i; } selected = choices[randomInt(choiceCount)]; } proposal = proposals[selected]; return true; } bool proposeEndpointDeletion(RangeProposal& proposal) { int n = treap.size(); if (n <= 2) return false; int rank = n - 1; int cell = treap.nodes[treap.nodeAt(rank)].cell; proposal = {rank, rank, cellValue[cell], 1}; return true; } bool acceptLoss(int loss, double temperature, bool force) { if (force || loss == 0) return true; return randomDouble() < exp(-static_cast<double>(loss) / temperature); } void applyTwoOpt(int firstRank, int secondRank) { if (firstRank < secondRank) { auto [a, rest] = treap.split(treap.root, firstRank + 1); auto [middle, c] = treap.split(rest, secondRank - firstRank); treap.applyReverse(middle); treap.root = treap.merge(treap.merge(a, middle), c); } else { auto [a, rest] = treap.split(treap.root, secondRank + 1); auto [middle, c] = treap.split(rest, firstRank - secondRank); treap.applyReverse(middle); treap.root = treap.merge(treap.merge(a, middle), c); } } bool tryTwoOpt() { int n = treap.size(); if (n < 4) return false; int rank = randomInt(n - 1); int u = treap.nodes[treap.nodeAt(rank)].cell; int v = treap.nodes[treap.nodeAt(rank + 1)].cell; int ur = u / SIDE, uc = u % SIDE; int vr = v / SIDE, vc = v % SIDE; for (int side : {-1, 1}) { int oppositeU, oppositeV; if (ur == vr) { oppositeU = (ur + side) * SIDE + uc; oppositeV = (ur + side) * SIDE + vc; } else { oppositeU = ur * SIDE + uc + side; oppositeV = vr * SIDE + uc + side; } if (oppositeU < 0 || oppositeU >= CELLS || oppositeV < 0 || oppositeV >= CELLS) { continue; } int nodeU = treap.cellNode[oppositeU]; int nodeV = treap.cellNode[oppositeV]; if (!nodeU || !nodeV) continue; int rankU = treap.getRank(nodeU); int rankV = treap.getRank(nodeV); if (rankV != rankU + 1) continue; applyTwoOpt(rank, rankU); return true; } return false; } bool tryRotation() { int n = treap.size(); if (n < 3) return false; int endpoint = treap.nodes[treap.nodeAt(n - 1)].cell; int candidates[4]; int candidateCount = 0; for (int cell : neighbors[endpoint]) { int node = treap.cellNode[cell]; if (!node) continue; int rank = treap.getRank(node); if (rank >= n - 2) continue; candidates[candidateCount++] = rank; } if (candidateCount == 0) return false; int rank = candidates[randomInt(candidateCount)]; auto [a, suffix] = treap.split(treap.root, rank + 1); treap.applyReverse(suffix); treap.root = treap.merge(a, suffix); return true; } // --------------------------------------------------------------------------- int main() { startTime = Clock::now(); ios::sync_with_stdio(false); cin.tie(nullptr); int si, sj; cin >> si >> sj; for (int i = 0; i < CELLS; ++i) cin >> tileId[i]; for (int i = 0; i < CELLS; ++i) cin >> cellValue[i]; for (int r = 0; r < SIDE; ++r) { for (int c = 0; c < SIDE; ++c) { int cell = r * SIDE + c; if (r > 0) neighbors[cell].push_back(cell - SIDE); if (r + 1 < SIDE) neighbors[cell].push_back(cell + SIDE); if (c > 0) neighbors[cell].push_back(cell - 1); if (c + 1 < SIDE) neighbors[cell].push_back(cell + 1); } } rngState ^= static_cast<uint64_t>( chrono::duration_cast<chrono::nanoseconds>( Clock::now().time_since_epoch()).count()); random32(); int startCell = si * SIDE + sj; for (int run = 0; run < 200 && elapsedSeconds() < 0.225; ++run) { fill(tileUsed, tileUsed + CELLS, false); dfsPath.clear(); dfsPathScore = 0; dfsNodeCount = 0; dfsNodeLimit = 25000 + run * 1000; constructDFS(startCell); if (elapsedSeconds() > 0.245) break; } if (initialBestPath.empty()) { initialBestPath.push_back(startCell); initialBestScore = cellValue[startCell]; } buildTreapFrom(initialBestPath); bestPath = initialBestPath; bestScore = currentScore; constexpr double GROW_END = 0.35; while (elapsedSeconds() < GROW_END) { for (int iteration = 0; iteration < 32 && elapsedSeconds() < GROW_END; ++iteration) { int operation = randomInt(100); bool changed = false; if (operation < 50) { changed = insertRectangleDetour(); } else if (operation < 75) { changed = insertAtEndpoint(); } else if (operation < 88) { changed = tryTwoOpt(); } else { changed = tryRotation(); } if (changed) rememberBest(); } } constexpr double SA_END = 1.66; constexpr double FINAL_END = 1.82; const double saStart = elapsedSeconds(); while (elapsedSeconds() < SA_END) { double progress = (elapsedSeconds() - saStart) / max(0.001, SA_END - saStart); progress = clamp(progress, 0.0, 1.0); double temperature = 120.0 * pow(0.02, progress) + 0.3; for (int iteration = 0; iteration < 64 && elapsedSeconds() < SA_END; ++iteration) { int operation = randomInt(100); if (operation < 38) { if (insertRectangleDetour()) rememberBest(); } else if (operation < 56) { if (insertAtEndpoint()) rememberBest(); } else if (operation < 76) { RangeProposal proposal; if (proposeChordDeletion(proposal)) { bool force = (randomInt(256) == 0); if (acceptLoss(proposal.loss, temperature, force)) { deleteRange(proposal.left, proposal.right); } } } else if (operation < 83) { RangeProposal proposal; if (proposeEndpointDeletion(proposal)) { bool force = (randomInt(256) == 0); if (acceptLoss(proposal.loss, temperature, force)) { deleteRange(proposal.left, proposal.right); } } } else if (operation < 92) { tryTwoOpt(); } else { tryRotation(); } } } while (elapsedSeconds() < FINAL_END) { for (int iteration = 0; iteration < 64 && elapsedSeconds() < FINAL_END; ++iteration) { int operation = randomInt(100); if (operation < 48) { if (insertRectangleDetour()) rememberBest(); } else if (operation < 73) { if (insertAtEndpoint()) rememberBest(); } else if (operation < 82) { RangeProposal proposal; if (proposeChordDeletion(proposal) && proposal.loss == 0) { deleteRange(proposal.left, proposal.right); } } else if (operation < 92) { tryTwoOpt(); } else { tryRotation(); } } } vector<int> answer = bestPath; if (answer.empty()) answer.push_back(startCell); string directions; directions.reserve(answer.size()); for (int i = 1; i < static_cast<int>(answer.size()); ++i) { int a = answer[i - 1], b = answer[i]; int ar = a / SIDE, ac = a % SIDE; int br = b / SIDE, bc = b % SIDE; if (br < ar) directions.push_back('U'); else if (br > ar) directions.push_back('D'); else if (bc < ac) directions.push_back('L'); else directions.push_back('R'); } cout << directions << '\n'; return 0; }