Skip to content

Problem 69 interactor: each round's pair is a fixed function of the round number, so a program that ignores every power scores 67 #212

Closed

Description

@XiaoyuanWang111

algorithmic/problems/69/interactor.cc (at 59687e5) does not pick the pair of a round at random. The statement says:

Two indices uj and vj were chosen independently and uniformly at random from {1, 2, ..., n}.

The interactor computes the pair from the round number j, the same way on every test (lines 131-135):

auto pickPair = [&](int j)->pair<int,int>{
    int u = (j % n) + 1;
    int v = ((j * 37 + 13) % n) + 1;
    return {u, v};
};

So a submission can print the expected pairs without decoding anything, and its words only have to be distinct. Repro, on any test:

#include <bits/stdc++.h>
int main() {
    int n, q;
    if (std::scanf("%d %d", &n, &q) != 2) return 0;
    // The n shortest distinct words: X, O, XX, XO, ...
    int printed = 0;
    for (int len = 1; printed < n; len++)
        for (int code = 0; code < (1 << len) && printed < n; code++, printed++) {
            for (int b = len - 1; b >= 0; b--) std::putchar((code >> b & 1) ? 'O' : 'X');
            std::putchar('\n');
        }
    std::fflush(stdout);
    for (int j = 0; j < q; j++) {
        long long p;
        if (std::scanf("%lld", &p) != 1) return 0;   // read the power and ignore it
        std::printf("%d %d\n", j % n + 1, (j * 37 + 13) % n + 1);
        std::fflush(stdout);
    }
}
g++ -O2 -std=gnu++17 -I algorithmic/judge/include -o interactor algorithmic/problems/69/interactor.cc
g++ -O2 -std=gnu++17 -o replay replay.cpp
mkfifo pipe
./replay < pipe | ./interactor algorithmic/problems/69/testdata/1.in /dev/null algorithmic/problems/69/testdata/1.ans > pipe

Result on the 10 tests (g++ 13.3):

test 1 : All 1000 answers valid. Total length = 7996, optimal = 11683787. Ratio: 0.672870160166
test 2 : All 1000 answers valid. Total length = 7987, optimal = 11683152. Ratio: 0.672880878631
...
test 10: All 1000 answers valid. Total length = 7915, optimal = 11675833. Ratio: 0.672965167357

Every test is accepted at 67.29 points. The six results in results/*-2026-10-17.csv score between 60.10 and 61.21 on this problem.

The words this program prints cannot be decoded. They have at most 9 letters, so a spell has at most 18 letters and its power is at most 18 * 19 / 2 = 171, while test 1 has 1,000,000 ordered pairs.

Suggested fix: draw the pairs from a per-test secret. Put a seed in each testdata/N.ans after the reference length and draw u and v from std::mt19937_64(seed), as problem 59 does since #211. I have a patch with tests and can open a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions