Repository navigation
Fix #208: seed problem 59 interactor from a per-test secret - #209
Closed
Kingpython123 wants to merge 1 commit into
Closed
Kingpython123 wants to merge 1 commit into
Kingpython123 wants to merge 1 commit into
Conversation
The problem 59 interactor is non-adaptive but built its hidden array with testlib's rng at the fixed default seed and never reseeded, so the array was a deterministic function of n. A program replaying that stream reconstructed the array and answered with zero comparison queries, scoring 100 on every test. Read a per-test secret seed from the hidden answer file and setSeed() the rng before generating the array, as the other non-adaptive interactors in this repo take their hidden data from the answer file. The contestant still receives only n, so the array is no longer predictable. Each public testdata answer file gets a distinct seed; private test answer files need one integer seed added too. Add algorithmic/tests/test_problem59.py as a regression test.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
algorithmic/problems/59/interactor.cppis non-adaptive but built its hidden array with testlib'srndat the fixed default seed (3905348978240129619) and never reseeded it (registerInteractiondoes not seedrnd). The.ansfiles were empty and unused, so the array was a deterministic function ofn, identical across every test with the samen. A submission that replays the samerndstream reconstructs the array and answers with zero comparison queries, scoring 100 on every test (same class as #202–#205).Fix
Read a per-test secret seed from the hidden answer file and
rnd.setSeed()before generating the array:This follows the repo's other non-adaptive interactors, which take their hidden data from the answer file (for example problems 2, 89, 124, 135). The contestant still receives only
n, so the array is no longer predictable from a fixed seed. Each publictestdata/*.ansnow holds a distinct seed.Reproduction
A standalone program (no testlib) that replays the default stream and makes no query:
Piping it through the interactor (g++ 11.4,
-O2 -std=gnu++17):Tests
algorithmic/tests/test_problem59.pyreconstructs the array the interactor will use from each committed secret seed and feeds it back with no queries. The array from the committed seed is accepted (Ratio: 1.0); the array from the old default seed is rejected on every test withn >= 2. All 19 checks pass with this change (onen = 1case is skipped, since a length-1 array is unique); onmainthe accept checks fail because the interactor ignores the seed.Fixes #208.