题目 › fcs-148

FrontierCS #148

FrontierCS 算法赛道 v1.1 · 2026-05 · L5 开放式 · C++17 · 时限 10 秒 · 0–100 连续分

查看原题跳到结果

题面

来源: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;
}