PopcountRobot
2015 TCO Parallel 2C · 2015-04-08 · by rng_58
2015 TCO Parallel 2C · 2015-04-08 · by rng_58 · Math
Problem Statement
Problem Statement
In this problem, popcount(n) denotes the number of ones in the binary representation of n.
For example, popcount(2015) = 10 because 2015 is 11111011111 in binary.
The horizontal plane is divided into an infinite grid of unit square cells. All cells are currently white. Cat Snuke has just bought a strange robot and placed it onto the grid. The current coordinates of the robot are (0, 0). The robot is going to paint some of the cells black.
You are given along T.
For each t from 0 to T-1, inclusive, the robot will execute the following sequence of steps:
You are also given fourint s: Q, M, x, and y.
Compute ans in the following pseudocode:
The horizontal plane is divided into an infinite grid of unit square cells. All cells are currently white. Cat Snuke has just bought a strange robot and placed it onto the grid. The current coordinates of the robot are (0, 0). The robot is going to paint some of the cells black.
You are given a
- The robot paints the current cell black. (If the cell is already black, the robot does nothing.)
- If popcount(t) mod 4 = 0, the robot increases its x-coordinate by 1.
- If popcount(t) mod 4 = 1, the robot increases its y-coordinate by 1.
- If popcount(t) mod 4 = 2, the robot decreases its x-coordinate by 1.
- If popcount(t) mod 4 = 3, the robot decreases its y-coordinate by 1.
You are also given four
ans = 0;
for(i = 0; i < Q; i++){
if(the cell (x,y) is black after the robot stops working) ans++;
x = ((x + M) * 7180087 + 5205425) % (2 * M + 1) - M;
y = ((y + M) * 6132773 + 9326231) % (2 * M + 1) - M;
}
return ans;
Notes
- The intended solution can compute the colors of any set of up to 500,000 cells in the range [-10^9, 10^9] x [-10^9, 10^9].
Constraints
- T will be between 1 and 10^18, inclusive.
- Q will be between 1 and 500,000, inclusive.
- M will be between 0 and 1,000,000,000, inclusive.
- x and y will be between -M and M, inclusive.
Examples
0)
5 10 2 -1 -2 Returns: 2
The ten coordinates you get in the pseudocode are: (-1, -2), (0, -1), (2, 2), (1, 1), (-1, -2), (0, -1), (2, 2), (1, 1), (-1, -2), and (0, -1). Two of them ((1, 1) twice) are colored black when T = 5.
1)
30 500000 5 3 4 Returns: 0
2)
2015 500000 50 12 34 Returns: 40000
3)
1000000000000000000 500000 1000000000 94296562 -42562967 Returns: 32306
4)
720875421873 500000 312 -288 36 Returns: 68000
Submissions are judged against all 104 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PopcountRobot with a public method int countBlack(long long T, int Q, int M, int x, int y) · 104 test cases · 2 s / 256 MB per case