ASeDatAb Solution Round 1B 2022 - Code Jam 2022
Problem
A research consortium has been looking for the best possible database for three years, but they are still having problems. The database stores values as records that hold -bit binary strings. Unfortunately, their implementation of the function to set the value of a record is flawed.
Each record of the database is an -bit binary string. The bits of the binary string are indexed from to from left to right. When an instruction to set a specific record to a new value is received, instead of setting the value to the database does the following:
- Choose an integer between and , inclusive, and let be like but rotated by to the right. That is, the -th bit of is the -th bit of .
- Replace the current value of the record with XOR . That is, the new value of the record has a as its -th bit if and only if the -th bits of and are different.
- Finally, return the number of bits that are in the new value to the user.
Luckily, it turns out that no matter what the initial value is or what rotation values the database chooses, it is always possible to reset the value of a record to have all bits be with no more than uses of this operation. Implement a program to interact with the database that does this.
Input and output
This is an interactive problem. You should make sure you have read the information in the Interactive Problems section of our FAQ.
Initially, your program should read a single line containing an integer , the number of test cases. Then, test cases must be processed.
At the beginning of each test case, the record in the database is set to a value that is not 00000000
. In each test case, your program must process up to exchanges.
The -th exchange starts with you outputting a single line containing a single -bit binary string to be used as the value for the operation above. Then, the judge program performs the operation as described and sends you a single line containing a single integer representing the number of bits that are equal to in the updated value of the record.
- If , it means that you have succeeded and you must start the next test case, or finish the program if it was the last one.
- If it means that this was the -th exchange of the test case but the record never got to a value of all zeroes, so the test is failed. No further test cases will be processed.
- If , it means that the updated value of the record has ones and you may proceed to the next exchange to keep trying to make it contain only zeroes.
Your solution is considered correct if and only if you succeed in setting the value of the record to 00000000
for all test cases.
If the judge receives an invalidly formatted or invalid line from your program at any moment, the judge will print a single number and will not print any further output. If you receive a , you must finish correctly and without exceeding the time or memory limits to receive a Wrong Answer judgement. Otherwise, you will receive a judgement informing the exceeded resource or the incorrect termination condition.
Limits
Time limit: 10 seconds.
Memory limit: 1 GB.
.
for all .
Test Set 1 (Visible Verdict)
The initial value of the record is chosen uniformly at random from all -bit binary strings that are not 00000000
.
Each rotation value is chosen uniformly at random, and independently of all previous choices and interactions.
Test Set 2 (Visible Verdict)
The judge is adversarial. This means, among other things, that the judge can change the initial value or rotation values as long as it is consistent with all interactions. The initial value is guaranteed to never be 00000000
.
Testing Tool
You can use this testing tool to test locally or on our platform. To test locally, you will need to run the tool in parallel with your code; you can use our interactive runner for that. For more information, read the instructions in comments in that file, and also check out the Interactive Problems section of the FAQ.
Instructions for the testing tool are included in comments within the tool. We encourage you to add your own test cases. Please be advised that although the testing tool is intended to simulate the judging system, it is NOT the real judging system and might behave differently. If your code passes the testing tool but fails the real judge, please check the Coding section of the FAQ to make sure that you are using the same compiler as us.
Pancake Deque Solution Round 1B 2022 - Code Jam 2022
Controlled Inflation Solution Round 1B 2022 - Code Jam 2022
No comments:
Post a Comment