题目 › fcs-141

FrontierCS #141

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

查看原题跳到结果

题面

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

Bakery Survey This is an interactive problem. Your city has n bakeries (where n is a power of 2), and bakery i specializes in one type of cake a_i. You want to determine d — the number of distinct cake types available in the city. You don't know the values of a_1, ..., a_n. However, your friend can help you by tasting cakes. Your friend has a memory capacity of k (where k is also a power of 2), which works as follows: Your friend's memory is a queue S. You can perform two types of operations: 1. Query operation: Ask your friend to taste the cake from bakery c. This will: - Tell you whether a_c is already in S (the last k cake types tasted) - Add a_c to the end of S - If |S| > k, remove the front element from S 2. Reset operation: Clear your friend's memory, making S empty. Your goal is to find d while minimizing the total cost of operations. This problem is graded based on the total cost of operations. The cost is calculated as: Total Cost = (number of resets) × n + (number of queries) + 1 You must use at most 100,000 operations in total. Input The first line contains two integers n and k (1 ≤ k ≤ n ≤ 1024, both k and n are powers of 2). Interaction To perform an operation, output one line in one of the following formats: ? c — Ask your friend to taste the cake from bakery c (1 ≤ c ≤ n). R — Reset your friend's memory. After a query operation, read a single character: - Y (Yes) if a_c is in the memory S - N (No) if a_c is not in the memory S When you have found the answer, output: ! d — where d is the number of distinct cake types. After printing the answer, your program should terminate immediately. To flush your output, use: - fflush(stdout) or cout.flush() in C++ - System.out.flush() in Java - stdout.flush() in Python Example Input: 4 2 N N Y N N N N Output: ? 1 ? 2 ? 3 ? 4 R ? 4 ? 1 ? 2 ! 3 Time limit: 4 seconds Memory limit: 512 MB ## 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. C=n*reset_count+query_count+1 is the total operation cost, and R>0 is the stored reference cost. Define the objective x=C, its physical reference a=A=R, and the lower-band calculation L=60*R/C. ```text P = 100, if x = 0 P = L, if L <= 60 and x > 0 P = min(100, 60 + ln(r)), otherwise ``` Zero is tested on the valid original count, cost, or error, before the lower-band test. A zero reference anchor has no positive improvement branch; positive objectives keep their lower-band score. The +1 in C is part of the defined operation cost, so C is always positive. The checker reports P/100.

结果

Kimi K3.1 ProKimi

max

58.5

平均得分 ↑

  • 58.5采样 1 · 部分分
  • 64.3k平均输出 token(含思考) ↓
  • 25.1输出速度 tokens/s ↑
  • 2564 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

60.5

平均得分 ↑

  • 60.5采样 1 · 部分分
  • 25.7k平均输出 token(含思考) ↓
  • 24.3输出速度 tokens/s ↑
  • 1060 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

7.9

平均得分 ↑

  • 7.9采样 1 · 部分分
  • 101.5k平均输出 token(含思考) ↓
  • 167.3输出速度 tokens/s ↑
  • 607 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

39.5

平均得分 ↑

  • 39.5采样 1 · 部分分
  • 119.5k平均输出 token(含思考) ↓
  • 144.0输出速度 tokens/s ↑
  • 831 秒延迟 ↓

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

代码

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

int n, k;

char ask(int c) {
    cout << "? " << c << '\n';
    cout.flush();
    char r;
    if (!(cin >> r)) exit(0);
    return r;
}

struct Node {
    int side;
    int idx;
};

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

    if (!(cin >> n >> k)) return 0;

    if (n == 1) {
        cout << "! 1\n";
        cout.flush();
        return 0;
    }

    if (k == 1) {
        vector<int> reps;

        for (int i = 1; i <= n; i++) {
            if (ask(i) == 'Y') continue;

            if (reps.empty()) {
                reps.push_back(i);
                continue;
            }

            int p = (int)reps.size();

            ask(reps[0]);
            if (ask(i) == 'Y') continue;

            if (p == 1) {
                reps.push_back(i);
                continue;
            }

            bool duplicate = false;
            for (int j = 1; j < p; j++) {
                if (ask(reps[j]) == 'Y') {
                    duplicate = true;
                    break;
                }
                if (j + 1 < p) ask(i);
            }

            if (!duplicate) reps.push_back(i);
        }

        cout << "! " << reps.size() << '\n';
        cout.flush();
        return 0;
    }

    vector<int> reps;

    for (int block = 0; block < n; block += k) {
        vector<int> cand;

        for (int j = 0; j < k; j++) {
            int id = block + j + 1;
            if (ask(id) == 'N') cand.push_back(id);
        }

        if (cand.empty()) continue;

        if (reps.empty()) {
            reps = cand;
            continue;
        }

        int p = (int)reps.size();
        int q = (int)cand.size();

        vector< bitset<1024> > compared(q);
        vector<int> comparedCount(q, 0);
        vector<unsigned char> state(q, 0);
        int resolved = 0;

        auto addComparison = [&](int b, int g) {
            if (!compared[b].test(g)) {
                compared[b].set(g);
                comparedCount[b]++;
                if (state[b] == 0 && comparedCount[b] == p) {
                    state[b] = 2;
                    resolved++;
                }
            }
        };

        deque<Node> memory;

        int firstLen = min(p, k);
        int initialPadding = k - firstLen;

        for (int i = 0; i < initialPadding; i++) {
            ask(reps[0]);
            memory.push_back({0, 0});
        }
        for (int i = 0; i < firstLen; i++) {
            ask(reps[i]);
            memory.push_back({0, i});
        }

        auto processNode = [&](int side, int idx) {
            int bakery = (side == 0 ? reps[idx] : cand[idx]);
            char response = ask(bakery);

            if (response == 'N') {
                if (side == 1) {
                    for (const Node &node : memory) {
                        if (node.side == 0) addComparison(idx, node.idx);
                    }
                } else {
                    for (const Node &node : memory) {
                        if (node.side == 1) addComparison(node.idx, idx);
                    }
                }
            } else if (side == 1 && state[idx] == 0) {
                bool selfInMemory = false;
                for (const Node &node : memory) {
                    if (node.side == 1 && node.idx == idx) {
                        selfInMemory = true;
                        break;
                    }
                }
                if (!selfInMemory) {
                    state[idx] = 1;
                    resolved++;
                }
            }

            memory.push_back({side, idx});
            if ((int)memory.size() > k) memory.pop_front();
        };

        int groups = (p + k - 1) / k;

        for (int i = 0; i < groups && resolved < q; i++) {
            for (int b = 0; b < q && resolved < q; b++) {
                processNode(1, b);
            }

            if (resolved == q) break;

            int gblock = (i + 1 < groups ? i + 1 : 0);
            int begin = gblock * k;
            int end = min(p, begin + k);

            for (int g = begin; g < end && resolved < q; g++) {
                processNode(0, g);
            }
        }

        vector<int> unresolved;
        for (int b = 0; b < q; b++) {
            if (state[b] == 0) unresolved.push_back(b);
        }

        if (!unresolved.empty()) {
            for (int i = 0; i < k; i++) ask(reps[0]);

            int h = k / 2;
            int u = (int)unresolved.size();

            for (int ds = 0; ds < u; ds += h) {
                int de = min(u, ds + h);
                int dsize = de - ds;

                for (int gs = 0; gs < p; gs += h) {
                    bool needed = false;
                    for (int di = ds; di < de; di++) {
                        if (state[unresolved[di]] == 0) {
                            needed = true;
                            break;
                        }
                    }
                    if (!needed) break;

                    int ge = min(p, gs + h);
                    int gsize = ge - gs;

                    if (gs > 0) {
                        int padding = k - gsize - dsize + 1;
                        for (int i = 0; i < padding; i++) ask(reps[0]);
                    }

                    for (int g = gs; g < ge; g++) ask(reps[g]);

                    for (int di = ds; di < de; di++) {
                        int b = unresolved[di];
                        if (ask(cand[b]) == 'Y') state[b] = 1;
                    }
                }
            }
        }

        for (int b = 0; b < q; b++) {
            if (state[b] != 1) reps.push_back(cand[b]);
        }
    }

    cout << "! " << reps.size() << '\n';
    cout.flush();
    return 0;
}