题目 › fcs-104

FrontierCS #104

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

查看原题跳到结果

题面

来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。

Time Limit: 2 s Memory Limit: 256 MB This is an interactive problem. There are n students, having roll numbers 1 to n. Mr. 1048576 knows that exactly 1 student is absent today. In order to determine who is absent, he can ask some queries to the class. In each query, he provide two integers l and r (1≤l≤r≤n) and all students whose roll numbers are between l and r (inclusive) are expected to raise their hands. But the students are dishonest. Some students whose roll numbers lie in the given range may not raise their hands, while some other students whose roll number does not lie in the given range may raise their hands. But only the following 4 cases are possible for a particular query (l,r) — 1. True Positive: r−l+1 students are present and r−l+1 students raised their hands. 2. True Negative: r−l students are present and r−l students raised their hands. 3. False Positive: r−l students are present but r−l+1 students raised their hands. 4. False Negative: r−l+1 students are present but r−l students raised their hands. In the first two cases, the students are said to be answering honestly, while in the last two cases, the students are said to be answering dishonestly. The students can mutually decide upon their strategy, not known to Mr. 1048576. Also, their strategy always meets the following two conditions — 1. The students will never answer honestly 3 times in a row. 2. The students will never answer dishonestly 3 times in a row. Mr. 1048576 is willing to mark at most 2 students as absent (though he knows that only one is). The attendance is said to be successful if the student who is actually absent is among those two. Also, he can only ask up to 2* ⌈log_{1.116}n⌉ queries. Help him complete a successful attendance. Interaction First read a line containing a single integer t (1≤t≤2048) denoting the number of independent test cases that you must solve. For each test case, first read a line containing a single integer n (5≤n≤10^5). Then you may ask up to 2* ⌈log_{1.116}n⌉ queries. Your score depends on the query count as specified below. To ask a query, print a single line in the format "? l r" (without quotes) (1≤l≤r≤n). Then read a single line containing a single integer x (r−l≤x≤r−l+1) denoting the number of students who raised their hands corresponding to the query. To mark a student as absent, print a single line in the format "! a" (without quotes) (1≤a≤n). Then read a single integer y (y∈{0,1}). If the student with roll number a was absent, y=1, else, y=0. Note that this operation does not count as a query but you can do this operation at most 2 times. To end a test case, print a single line in the format "#" (without quotes). Then you must continue solving the remaining test cases. The sum of n over all test cases does not exceed 10^5. To flush the buffer, use fflush(stdout) or cout.flush() The answer may change depending on your queries but will always remain consistent with the constraints and the answer to the previous queries. Example input 2 5 3 2 1 2 0 1 0 2 0 1 6 6 2 2 0 1 1 0 0 0 1 output ? 1 4 ? 3 5 ? 2 2 ? 1 3 ? 3 3 ? 3 3 ! 3 ? 2 4 ? 4 4 ! 2 # ? 1 6 ? 1 3 ? 4 6 ? 1 1 ? 3 3 ? 5 5 ! 3 ? 2 2 ? 4 4 ! 4 # ## 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 minimizing quantity and a for its physical 60-point reference. The improvement factor is r=a/x, 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. For subcase j, let Q_j be its query count and L_j>1 its query limit. Define the per-subcase physical reference a_j=A_j=0.4*L_j+0.6 and B_j=100*min(1,max(0,(L_j-Q_j)/(L_j-1))). Guess actions are not queries. For a valid subcase, award 100 if Q_j=0; otherwise award B_j when B_j<=60, and min(100,60+ln(r_j)) when B_j>60, where x_j=Q_j and r_j=a_j/x_j. The file score is the minimum subcase award. A failed subcase gives zero for the file. The checker reports the file score divided by 100.

结果

Kimi K3.1 ProKimi

max

0.0

平均得分 ↑

  • 0.0采样 1 · 编译错误
  • 47.9k平均输出 token(含思考) ↓
  • 27.1输出速度 tokens/s ↑
  • 1768 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

35.3

平均得分 ↑

  • 35.3采样 1 · 部分分
  • 25.5k平均输出 token(含思考) ↓
  • 24.0输出速度 tokens/s ↑
  • 1066 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0.0

平均得分 ↑

  • 0.0采样 1 · 答案错误
  • 63.1k平均输出 token(含思考) ↓
  • 169.7输出速度 tokens/s ↑
  • 373 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

0.0

平均得分 ↑

  • 0.0采样 1 · 答案错误
  • 83.9k平均输出 token(含思考) ↓
  • 88.3输出速度 tokens/s ↑
  • 952 秒延迟 ↓

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 251 行
#include <bits/stdc++.h>
using namespace std;

const int NXT[4][2] = {
    {1, 2},
    {-1, 2},
    {0, 3},
    {0, -1}
};

struct Endgame {
    static const int INF = 1000000000;
    vector<int> dist, move;
    vector<vector<int>> patterns;

    static int nextConfig(int key, int qmask, int reply) {
        int m = key >> 8;
        int states = key & 255;
        int newMask = 0, newM = 0;

        for (int i = 0; i < m; i++) {
            int s = (states >> (2 * i)) & 3;
            int b = (qmask >> i) & 1;
            int h = reply ^ b;
            int ns = NXT[s][h];
            if (ns != -1) {
                newMask |= ns << (2 * newM);
                newM++;
            }
        }

        if (newM <= 2) return -1;
        return (newM << 8) | newMask;
    }

    Endgame() {
        dist.assign(5 << 8, INF);
        move.assign(5 << 8, -1);
        patterns.resize(5);

        for (int m = 3; m <= 4; m++) {
            for (int i = 0; i < m; i++) {
                for (int j = i; j < m; j++) {
                    int mask = 0;
                    for (int k = i; k <= j; k++) mask |= 1 << k;
                    patterns[m].push_back(mask);
                }
            }
        }

        vector<int> configs;
        for (int m = 3; m <= 4; m++) {
            int lim = 1 << (2 * m);
            for (int mask = 0; mask < lim; mask++) {
                configs.push_back((m << 8) | mask);
            }
        }

        for (int pass = 0; pass < 1000; pass++) {
            bool changed = false;

            for (int key : configs) {
                int m = key >> 8;
                int best = dist[key];
                int bestMove = move[key];

                for (int qmask : patterns[m]) {
                    bool ok = true;
                    int worst = 0;

                    for (int reply = 0; reply < 2; reply++) {
                        int nk = nextConfig(key, qmask, reply);
                        if (nk == -1) continue;
                        if (dist[nk] >= INF) {
                            ok = false;
                            break;
                        }
                        worst = max(worst, dist[nk]);
                    }

                    if (ok && worst + 1 < best) {
                        best = worst + 1;
                        bestMove = qmask;
                    }
                }

                if (best < dist[key]) {
                    dist[key] = best;
                    move[key] = bestMove;
                    changed = true;
                }
            }

            if (!changed) break;
        }
    }
};

struct Candidate {
    int roll, state;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    Endgame endgame;

    int T;
    cin >> T;

    const long double PHI = (1.0L + sqrtl(5.0L)) / 2.0L;

    while (T--) {
        int n;
        cin >> n;

        vector<Candidate> candidates;
        candidates.reserve(n);

        auto ask = [&](int l, int r) {
            cout << "? " << l << ' ' << r << '\n' << flush;
            int x;
            cin >> x;
            return x - (r - l);
        };

        auto applyQuery = [&](int l, int r, int reply) {
            vector<Candidate> next;
            next.reserve(candidates.size());

            for (const Candidate &c : candidates) {
                int b = (l <= c.roll && c.roll <= r) ? 1 : 0;
                int h = reply ^ b;
                int ns = NXT[c.state][h];
                if (ns != -1) next.push_back({c.roll, ns});
            }

            candidates.swap(next);
        };

        int firstReply = ask(1, n);
        int firstHonesty = firstReply ^ 1;
        int initialState = (firstHonesty == 0 ? 0 : 2);

        for (int i = 1; i <= n; i++) {
            candidates.push_back({i, initialState});
        }

        auto configurationKey = [&]() {
            int m = (int)candidates.size();
            int mask = 0;
            for (int i = 0; i < m; i++) {
                mask |= candidates[i].state << (2 * i);
            }
            return (m << 8) | mask;
        };

        while (candidates.size() > 2) {
            bool usedEndgame = false;

            if (candidates.size() <= 4) {
                int key = configurationKey();
                if (endgame.dist[key] < Endgame::INF && endgame.move[key] != -1) {
                    int qmask = endgame.move[key];
                    int first = -1, last = -1;

                    for (int i = 0; i < (int)candidates.size(); i++) {
                        if ((qmask >> i) & 1) {
                            if (first == -1) first = i;
                            last = i;
                        }
                    }

                    int l = candidates[first].roll;
                    int r = candidates[last].roll;
                    int reply = ask(l, r);
                    applyQuery(l, r, reply);
                    usedEndgame = true;
                }
            }

            if (usedEndgame) continue;

            int m = candidates.size();
            vector<long double> d(m);
            long double U = 0, V = 0;

            for (int i = 0; i < m; i++) {
                int s = candidates[i].state;
                long double u, v;

                if (s == 0) {
                    u = 1;
                    v = PHI;
                } else if (s == 1) {
                    u = 0;
                    v = PHI;
                } else if (s == 2) {
                    u = PHI;
                    v = 1;
                } else {
                    u = PHI;
                    v = 0;
                }

                U += u;
                V += v;
                d[i] = v - u;
            }

            long double target = (V - U) / 2;
            long double prefix = 0;
            long double bestDifference = numeric_limits<long double>::infinity();
            int bestR = n;
            int index = 0;

            for (int r = 1; r <= n; r++) {
                while (index < m && candidates[index].roll == r) {
                    prefix += d[index];
                    index++;
                }

                long double difference = fabsl(prefix - target);
                if (difference < bestDifference) {
                    bestDifference = difference;
                    bestR = r;
                }
            }

            int reply = ask(1, bestR);
            applyQuery(1, bestR, reply);
        }

        auto guess = [&](int roll) {
            cout << "! " << roll << '\n' << flush;
            int y;
            cin >> y;
            return y;
        };

        int result = guess(candidates[0].roll);
        if (result == 0 && candidates.size() > 1) {
            guess(candidates[1].roll);
        }

        cout << "#\n" << flush;
    }

    return 0;
}