problem_id
stringlengths 1
66
| category
stringclasses 2
values | statement
stringlengths 0
1.07M
| config
stringlengths 0
357
|
|---|---|---|---|
0
|
algorithmic
|
# Pack the Polyominoes (Reflections Allowed)
## Problem
You are given a set of n polyominoes placed on a unit square grid. Each polyomino consists of between 1 and 10 unit cells, connected edge-to-edge (4-connectivity). Your task is to place all polyominoes—allowing **rotations, reflections, and translations**—into an axis-aligned rectangle of the grid with no overlaps and no cells outside the rectangle, minimizing the rectangle’s area.
A placement specifies, for every polyomino, an integer translation, an optional reflection, and a rotation by a multiple of 90°, such that:
- every cell lands on integer grid coordinates,
- no two placed cells overlap,
- all placed cells lie within a single axis-aligned rectangle of width W and height H.
The objective is to minimize A = W × H. In case of ties on area, prefer smaller H, then smaller W.
---
## Input Format
- Line 1: integer n (100 <= n <= 10^4) — number of polyominoes.
- For each polyomino i = 1 … n:
- One line: integer kᵢ (1 ≤ kᵢ ≤ 10) — number of cells.
- Next kᵢ lines: two integers xᵢⱼ, yᵢⱼ — cell coordinates in the polyomino’s local frame.
These coordinates define a 4-connected polyomino.
Notes:
- Coordinates may be negative.
- Shapes may have internal holes.
- Shapes are defined by structure; initial placement does not matter.
---
## Output Format
- Line 1: two integers W and H — width and height of the chosen rectangle.
- Then n lines — one per polyomino i, each containing:
$$X_i\ Y_i\ R_i\ F_i$$
Where:
- (Xᵢ, Yᵢ): integer translation
- Rᵢ ∈ {0,1,2,3}: number of 90° clockwise rotations
- Fᵢ ∈ {0,1}: reflection flag (**1 = reflect across the y-axis before rotation**, 0 = no reflection)
All transformed cells must satisfy:
0 ≤ xᵢⱼ′ < W, 0 ≤ yᵢⱼ′ < H, W=H
---
## Rules
1. All cells occupy unit squares with integer coordinates.
2. **Allowed transforms: reflection (optional) → rotation (0°, 90°, 180°, 270°) → translation (in that order).**
3. Distinct polyomino cells must not overlap.
4. Every cell must lie inside [0, W) × [0, H).
5. Scoring: Minimize A = W × H.
---
## Constraints
- 100 ≤ n ≤ 10000
- 1 ≤ kᵢ ≤ 10
---
## Validation
A solution is valid if:
- All rules are satisfied.
- The judge verifies non-overlap and bounding-box compliance.
---
## Scoring (for heuristic / leaderboard contests)
- Per test case: score = 1e5*Σkᵢ/A
- Any invalid test case → entire submission rejected
---
## Example
Input
```
3
1
0 0
3
0 0
1 0
0 1
4
0 0
1 0
0 1
1 1
```
Output
```
3 3
0 0 0 0
2 0 1 0
1 1 0 0
```
This places the monomino at (0,0), rotates the triomino by 90° (R=1), and fits all shapes into a 3×3 rectangle. (Reflections are allowed, but not used in this example: F=0.)
---
## Generation
Let $S$ be the set of all pieces from size 1-10. Each piece is chosen uniformly at random with replacement from $S$.
$n$ is chosen as $10^p$, where $p \sim U(2, 4)$.
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 70
|
1
|
algorithmic
|
Problem F: Treasure Packing
A dragon has terrorized the region for decades, breathing fire and stealing treasures. A hero has decided to steal back the treasures and return them to the community. However, they drastically underestimated the size of the dragon's hoard, bringing only a single 25 liter bag, only strong enough to hold 20 kg, to carry out the treasures. The hero has decided to try to return as much value as possible. The dragon has 12 different types of items of different values, masses, and volumes: crowns, figurines, jeweled goblets, gold helms, etc., where each item of the same type has the same mass and volume. For example, all goblets have the same mass and volume. Write a program helping the hero determine what items they should put in the bag so as to maximize value accounting for the constraints on the bag.
Input
The input is JSON keyed by treasure category name, such as "goblet". Every category has a unique name composed of at most 100 lowercase ASCII characters. There are exactly twelve treasure categories. Each corresponding value is a list with one integer q (1 <= q <= 10000) and three integers v (0 < v <= 10^9), m (0 < m <= 20 * 10^6), and l (0 < l <= 25 * 10^6), where q is the maximum number of treasures of this category that can be looted, v is the value of one item, m is the mass (in mg) of one item, and l the volume (in µliters) of one item. (There are one million mg per kg and µliters per liter.)
Please see the sample input for an example of how the JSON is formatted.
Output
Print a JSON with the same keys as the input, but with single a nonnegative integer values giving the numbers of items of that category added to the bag in your solution.
Scoring
Producing an algorithm that always generates optimal solutions is very difficult, so your solution only needs to be "good enough". We will compare your output to a baseline heuristic provided by the NSA, and to a best effort to compute the true optimum. You must beat the NSA heuristic to receive points; after that, the better your solution, the higher your score. Specifically, your score on this problem is your average of the per-test-case score.
100 * clamp((your value - baseline value) / (best value - baseline value), 0, 1).
Time limit:
1 second
Memoriy limit:
1024 MB
Sample input:
{
"circlet": [
19,
113005,
146800,
514247
],
"coppercoin": [
887,
6171,
12593,
18081
],
"crown": [
13,
726439,
1079353,
1212213
],
"dagger": [
21,
279513,
558367,
522344
],
"figurine": [
18,
26272,
1488281,
2295986
],
"goblet": [
22,
300053,
698590,
986387
],
"goldcoin": [
129,
14426,
82176,
27597
],
"helm": [
3,
974983,
2470209,
882803
],
"jewelry": [
23,
272450,
171396,
262226
],
"plate": [
22,
98881,
246257,
363420
],
"silvercoin": [
288,
12587,
53480,
28654
],
"torc": [
17,
244957,
388222,
500000
]
}
Sample Output:
{
"circlet": 2,
"coppercoin": 8,
"crown": 13,
"dagger": 0,
"figurine": 0,
"goblet": 0,
"goldcoin": 0,
"helm": 0,
"jewelry": 23,
"plate": 0,
"silvercoin": 1,
"torc": 4
}
|
type: default
# The time limit is now 1 second.
time: 1s
memory: 1024m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
- score: 100
n_cases: 3
|
10
|
algorithmic
|
Problem: Tree distance
Time limit: 2 second
Memory limit: 512 MB
This is an interactive problem.
Little Cyan Fish has a weighted tree of n verticies generated in the following way:
- First, generate a random labeled tree: uniformly randomly select from all nn−2 possible labeled trees.
- Then, independently assign random integer edge weights in the range [1, K] to each edge, where K is a hidden parameter.
You cannot directly observe the structure of the tree or the edge weights, but Little Cyan Fish grants
you a superpower: querying! Each time, you can query the distance between two vertices. Specifically, you
can choose two vertices u, v (1 \leq u, v \leq n, u \neq v), and we will tell you the distance between these two
vertices (i.e., the sum of the edge weights on the simple path connecting these two vertices).
Now, Little Cyan Fish wants you to determine all the edges and their weights within queries as less as you can.
Scoring
The score is calculated based on the linear formula determined by the range [5n, Z]:
- Score = 100 * (Z - Q) / (Z - 5n)
Interaction Protocol
Each test case contains multiple sets of test data. First, you need to read an integer T (1 \leq T \leq 10^4)
indicating the number of data sets.
For each set of test data, you first need to read an integer n (1 \leq n \leq 10^5).
Next, the interaction process begins. To
make a query, you need to output a line “? u v” (1 \leq u, v \leq n, u \neq v), describing a query. Then, you need
to read the result from standard input.
To provide your answer, you need to output “! u_1 v_1 w_1 u_2 v_2 w_2··· u_{n−1} v_{n−1} w_{n−1}”. You can output
these edges in any order. The output of the answer will not count towards the n * n / 3 query limit. After you
output the answer, you need to immediately read the next set of test data or terminate your program.
After outputting a query, do not forget to output a newline character and flush the output stream.
To do this, you can use fflush(stdout) or cout.flush() in C++, System.out.flush() in Java,
flush(output) in Pascal, or stdout.flush() in Python.
It is guaranteed that 1 \leq K \leq 10^4, and the sum of all n in the test data does not exceed 10^5.
In this problem, it is guaranteed that the interaction library is non-adaptive. That is, the shape of the
tree and the edge weights are determined before the interaction process. They will not change with your
queries.
Example input:
2
3
3
4
7
4
3
7
2
4
5
9
Example Output:
? 1 2
? 2 3
? 1 3
! 1 2 3 2 3 4
? 1 2
? 2 3
? 2 4
? 1 3
? 1 4
? 3 4
! 1 2 3 1 3 4 2 4 2
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 512m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
101
|
algorithmic
|
Problem Name: Circuit
Description:
You are given a circuit board consisting of N component slots and R external switches.
Each slot contains either an AND gate (&) or an OR gate (|). The actual type of each slot is hidden.
Your task is to determine the true type of every slot by interacting with the judge.
Specifications of the Circuit Board:
- The board consists of 2N+1 switches numbered 0..2N, each with an ON/OFF state, outputting 0 or 1.
- The board also consists of N component slots numbered 0..N-1, each outputting 0 or 1.
- The outputs are determined from the highest index down to 0, according to the following rules:
* For j = 2N, 2N-1, ..., N:
- If switch j is OFF, it outputs 0.
- If switch j is ON, it outputs 1.
* For j = N-1, N-2, ..., 0:
- Let the output of slot j be x.
- If switch j is OFF, it outputs x.
- If switch j is ON, it outputs 1-x.
* For i = N-1, N-2, ..., 0:
- Slot i is connected to two switches Ui, Vi (i < Ui < Vi ≤ 2N).
- If slot i is AND, it outputs min(output(Ui), output(Vi)).
- If slot i is OR, it outputs max(output(Ui), output(Vi)).
- For each j = 1..2N, exactly one slot i satisfies Ui=j or Vi=j.
- The output of the circuit is defined as the output of switch 0.
Interaction:
At the beginning of the interaction, the judge prints N and R, followed by N lines each containing Ui Vi.
This describes the wiring of the board. Then your program must interact as follows:
1. Query:
You may print a line of the form: "? s"
where s is a binary string of length 2N+1. Each character sets the ON/OFF state of the corresponding switch.
The judge replies with a single line containing 0 or 1, the output of the circuit (switch 0).
2. Answer:
When you have determined the types of all slots, you must print a line of the form: "! t"
where t is a string of length N, each character being & or |, representing your guess of the hidden circuit.
If your guess is completely correct, the judge accepts. Otherwise, you receive Wrong Answer.
Constraints:
- 1 ≤ N ≤ 8000
- 1 ≤ R ≤ min(N, 120)
- i < Ui < Vi ≤ 2N for all 0 ≤ i < N
- For each j=1..2N, exactly one i satisfies Ui=j or Vi=j
- At most 5000 queries may be made. Exceeding this limit results in Wrong Answer.
Special Requirement:
- Your program must be written in C++.
Scoring:
- If the number of queries ≤ 900, you receive full score (100 points).
- If the number of queries ≥ 5000, you receive 0 points.
- Otherwise, the score is computed by linear interpolation:
Score = (5000 - queries) / (5000 - 900) * 100
Sample Interaction:
Suppose the input file contains:
3 2
3 4
2 4
0 1
&&|
The judge first outputs:
3 2
3 4
2 4
0 1
(Here the hidden true circuit is T = "&&|".)
Then the interaction may proceed as follows (lines beginning with '#' are explanations):
? 01001
# Player asks a query with binary string s.
1
# Judge replies that the circuit output is 1.
? 11111
# Another query.
0
# Judge replies with 0.
! &&|
# Player outputs the final answer.
# The hidden circuit matches the answer, so the judge accepts.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 5s
memory: 1024m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
104
|
algorithmic
|
Time Limit: 2 s
Memory Limit: 256 MB
This is an interactive problem.
There are n students, having roll numbers 1 to n. Mr. 1048576 knows that exactly 1 student is absent today. In order to determine who is absent, he can ask some queries to the class. In each query, he provide two integers l and r (1≤l≤r≤n) and all students whose roll numbers are between l and r (inclusive) are expected to raise their hands.
But the students are dishonest. Some students whose roll numbers lie in the given range may not raise their hands, while some other students whose roll number does not lie in the given range may raise their hands. But only the following 4 cases are possible for a particular query (l,r) —
1. True Positive: r−l+1 students are present and r−l+1 students raised their hands.
2. True Negative: r−l students are present and r−l students raised their hands.
3. False Positive: r−l students are present but r−l+1 students raised their hands.
4. False Negative: r−l+1 students are present but r−l students raised their hands.
In the first two cases, the students are said to be answering honestly, while in the last two cases, the students are said to be answering dishonestly. The students can mutually decide upon their strategy, not known to Mr. 1048576. Also, their strategy always meets the following two conditions —
1. The students will never answer honestly 3 times in a row.
2. The students will never answer dishonestly 3 times in a row.
Mr. 1048576 is willing to mark at most 2 students as absent (though he knows that only one is). The attendance is said to be successful if the student who is actually absent is among those two. Also, he can only ask up to 2* ⌈log_{1.116}n⌉ queries. Help him complete a successful attendance.
Interaction
First read a line containing a single integer t (1≤t≤2048) denoting the number of independent test cases that you must solve.
For each test case, first read a line containing a single integer n (5≤n≤10^5). Then you may ask up to 2* ⌈log_{1.116}n⌉ queries.
Your score is inversely linear related to the max number of queries.
To ask a query, print a single line in the format "? l r" (without quotes) (1≤l≤r≤n). Then read a single line containing a single integer x (r−l≤x≤r−l+1) denoting the number of students who raised their hands corresponding to the query.
To mark a student as absent, print a single line in the format "! a" (without quotes) (1≤a≤n). Then read a single integer y (y∈{0,1}). If the student with roll number a was absent, y=1, else, y=0. Note that this operation does not count as a query but you can do this operation at most 2 times.
To end a test case, print a single line in the format "#" (without quotes). Then you must continue solving the remaining test cases.
The sum of n over all test cases does not exceed 10^5.
To flush the buffer, use fflush(stdout) or cout.flush()
The answer may change depending on your queries but will always remain consistent with the constraints and the answer to the previous queries.
Example
input
2
5
3
2
1
2
0
1
0
2
0
1
6
6
2
2
0
1
1
0
0
0
1
output
? 1 4
? 3 5
? 2 2
? 1 3
? 3 3
? 3 3
! 3
? 2 4
? 4 4
! 2
#
? 1 6
? 1 3
? 4 6
? 1 1
? 3 3
? 5 5
! 3
? 2 2
? 4 4
! 4
#
|
type: interactive
time: 2s
memory: 256m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
- score: 100
n_cases: 3
|
106
|
algorithmic
|
Hidden Bipartite Graph
This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.
Bob has a simple undirected connected graph (without self-loops and multiple edges). He wants to learn whether his graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color) or not. As he is not very good at programming, he asked Alice for help. He does not want to disclose his graph to Alice, but he agreed that Alice can ask him some questions about the graph.
The only question that Alice can ask is the following: she sends s — a subset of vertices of the original graph. Bob answers with the number of edges that have both endpoints in s. Since he doesn't want Alice to learn too much about the graph, he allows her to ask no more than 50000 questions.
Furthermore, he suspects that Alice might introduce false messages to their communication channel, so when Alice finally tells him whether the graph is bipartite or not, she also needs to provide a proof — either the partitions themselves or a cycle of odd length.
Your task is to help Alice to construct the queries, find whether the graph is bipartite. Let q be the number of queries you asked, your score will be (5000 - q) / 5000.
Input
The first line contains a single integer n (1 ≤ n ≤ 600) — the number of vertices in Bob's graph.
Interaction
First, read an integer n (1≤ n ≤ 600) — the number of vertices in Bob's graph.
To make a query, print two lines. First of which should be in the format "? k" (1 ≤ k ≤ n), where k is the size of the set to be queried. The second line should contain k space separated distinct integers s1, s2, ..., sk (1 ≤ si ≤ n) — the vertices of the queried set.
After each query read a single integer m (0 ≤ m ≤ n(n-1)/2) — the number of edges between the vertices of the set {si}.
You are not allowed to ask more than 50000 queries.
If m = -1, it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive Wrong Answer; it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.
After printing a query do not forget to print end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
When you know the answer, you need to print it.
The format of the answer depends on whether the graph is bipartite or not.
If the graph is bipartite, print two lines. The first should contain the letter "Y" (short for "YES") followed by a space, and then a single integer s (0 ≤ s ≤ n) — the number of vertices in one of the partitions. Second line should contain s integers a1, a2, ..., as — vertices belonging to the first partition. All ai must be distinct, and all edges in the main graph must have exactly one endpoint in the set {ai}.
If the graph is not bipartite, print two lines. The first should contain the letter "N" (short for "NO") followed by a space, and then a single integer l (3 ≤ l ≤ n) — the length of one simple cycle of odd length. Second line should contain l integers c1, c2, ..., cl — the vertices along the cycle. It must hold that for all 1 ≤ i ≤ l, there is an edge {ci, c_{(i mod l)+1}} in the main graph, and all ci are distinct.
If there are multiple possible answers, you may print any of them.
Examples
Input
4
4
0
1
1
1
0
Output
? 4
1 2 3 4
? 2
1 2
? 2
1 3
? 2
1 4
? 2
2 4
? 2
3 4
Y 2
1 2
Input
4
4
3
Output
? 4
1 4 2 3
? 3
1 2 4
N 3
2 1 4
Note
In the first case, Alice learns that there are 4 edges in the whole graph. Over the course of the next three queries, she learns that vertex 1 has two neighbors: 3 and 4. She then learns that while vertex 2 is adjacent to 4, the vertex 3 isn't adjacent to 4. There is only one option for the remaining edge, and that is (2, 3). This means that the graph is a cycle on four vertices, with (1, 2) being one partition and (3, 4) being the second.
Here, it would be also valid to output "3 4" on the second line.
In the second case, we also have a graph on four vertices and four edges. In the second query, Alice learns that there are three edges among vertices (1, 2, 4). The only way this could possibly happen is that those form a triangle. As the triangle is not bipartite, Alice can report it as a proof. Notice that she does not learn where the fourth edge is, but she is able to answer Bob correctly anyway.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
107
|
algorithmic
|
F. Guess Divisors Count
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.
We have hidden an integer 1 ≤ X ≤ 10^9. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have to find the exact number: your answer will be considered correct if its absolute error is not greater than 7 or its relative error is not greater than 0.5.
More formally, let your answer be ans and the number of divisors of X be d, then your answer will be considered correct if at least one of the two following conditions is true:
* | ans - d | ≤ 7;
* 1/2 ≤ ans / d ≤ 2.
You can make at most 100 queries. One query consists of one integer 1 ≤ Q ≤ 10^18. In response, you will get gcd(X, Q) — the greatest common divisor of X and Q.
The number X is fixed before all queries. In other words, interactor is not adaptive.
Let's call the process of guessing the number of divisors of number X a game. In one test you will have to play T independent games, that is, guess the number of divisors T times for T independent values of X. Let q be the maximum number of queries you asked among all games, your score will be (100 - q) / 100.
Input
The first line of input contains one integer T (1 ≤ T ≤ 100) — the number of games.
Interaction
To make a query print a line "0 Q" (1 ≤ Q ≤ 10^18). After that read one integer gcd(X, Q). You can make no more than 100 such queries during one game.
If you are confident that you have figured out the number of divisors of X with enough precision, you can print your answer in "1 ans" format. ans have to be an integer. If this was the last game, you have to terminate the program, otherwise you have to start the next game immediately. Note that the interactor doesn't print anything in response to you printing answer.
After printing a query do not forget to output end of line and flush the output. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Example
Input (from interactor to you)
2
1
1
1
1024
1048576
4194304
Output (from you to interactor)
0 982306799268821872
0 230856864650023977
0 134690134760714371
1 5
0 1024
0 1048576
0 1073741824
1 42
Note
Let's look at the example.
In the first game X = 998244353 is hidden. Would be hard to guess this, right? This number is prime, so the number of its divisors is 2. The solution has made several random queries, and all the responses turned out to be 1 (strange things, not even one of three random numbers is divisible by 998244353). It's fare to assume that the hidden number doesn't have many divisors, so the solution has answered 5. Why not. This answer will be considered correct since | 5 - 2 | = 3 ≤ 7.
In the second game X = 4,194,304 = 2^22 is hidden, it has 23 divisors. The solution has made queries 1024 = 2^10, 1,048,576 =2^20, 1,073,741,824 = 2^30 and got responses 1024 = 2^10, 1,048,576 =2^20, 4,194,304 = 2^22, respectively. Then the solution got completely confused and answered the answer to The Ultimate Question of Life, the Universe, and Everything.
This answer will be considered correct since 1/2 ≤ 42 / 23 ≤ 2.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
108
|
algorithmic
|
time limit per test: 1 second
memory limit per test: 256 megabytes
This is an interactive problem.
Zookeeper has set up a special lock for the rabbit enclosure.
The lock consists of n concentric rings numbered from 0 to n−1. The innermost ring is ring 0 and the outermost ring is ring n−1. All rings are split equally into n*m sections each. Each of those rings contains a single metal arc that covers exactly m contiguous sections. At the center of the ring is a core and surrounding the entire lock are n*m receivers aligned to the n*m sections.
The core has n*m lasers that shine outward from the center, one for each section. The lasers can be blocked by any of the arcs. A display on the outside of the lock shows how many lasers hit the outer receivers.
For example, there are n=3 rings, each covering m=4 sections. There are n*m=12 sections. The ring 0 covers sections 0, 1, 2, 3, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 7, 8, 9, 10. Three of the lasers (sections 5, 6, 11) are not blocked by any arc, thus the display will show 3 in this case.
Wabbit cannot see where any of the arcs are. Given the relative positions of the arcs, Wabbit can open the lock on his own.
To be precise, Wabbit needs n−1 integers p_1,p_2,…,p_{n−1} satisfying 0≤p_i<n*m such that for each i (1≤i<n), Wabbit can rotate ring 0 clockwise exactly p_i times such that the sections that ring 0 covers perfectly aligns with the sections that ring i covers. In the example above, the relative positions are p_1=1 and p_2=7.
To operate the lock, he can pick any of the n rings and rotate them by 1 section either clockwise or anti-clockwise. You will see the number on the display after every rotation.
Wabbit has asked you to help him to find the relative positions of the arcs after all of your rotations are completed. You may perform up to 30000 rotations before Wabbit gets impatient, and your score is inversely linear related to the max number of queries.
Input
The first line consists of 2 integers n and m (2≤n≤100,2≤m≤20), indicating the number of rings and the number of sections each ring covers.
Interaction
To perform a rotation, print on a single line "? x d" where x (0≤x<n) is the ring that you wish to rotate and d (d∈{−1,1}) is the direction that you would like to rotate in. d=1 indicates a clockwise rotation by 1 section while d=−1 indicates an anticlockwise rotation by 1 section.
For each query, you will receive a single integer a: the number of lasers that are not blocked by any of the arcs after the rotation has been performed.
Once you have figured out the relative positions of the arcs, print ! followed by n−1 integers p_1,p_2,…,p_{n−1}.
Do note that the positions of the rings are predetermined for each test case and won't change during the interaction process.
After printing a query do not forget to output the end of line and flush the output. Use fflush(stdout) or cout.flush() to flush.
Example
Input
3 4
4
4
3
Output
? 0 1
? 2 -1
? 1 1
! 1 5
Note
For the first test, the configuration is the same as the example form the statement.
After the first rotation (which is rotating ring 0 clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 7, 8, 9, 10. The sections 0, 5, 6, 11 are not blocked by any arc.
After the second rotation (which is rotating ring 2 counter-clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 1, 2, 3, 4, and ring 2 covers sections 6, 7, 8, 9. The sections 0, 5, 10, 11 are not blocked by any arc.
After the third rotation (which is rotating ring 1 clockwise by 1 section), we have the ring 0 covers sections 1, 2, 3, 4, the ring 1 covers sections 2, 3, 4, 5, and ring 2 covers sections 7, 8, 9, 10. The sections 0, 6, 11 are not blocked by any arc.
If we rotate ring 0 clockwise once, we can see that the sections ring 0 covers will be the same as the sections that ring 1 covers, hence p_1=1.
If we rotate ring 0 clockwise five times, the sections ring 0 covers will be the same as the sections that ring 2 covers, hence p_2=5.
Note that if we will make a different set of rotations, we can end up with different values of p_1 and p_2 at the end.
|
type: interactive
time: 1s
memory: 256m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
- score: 100
n_cases: 3
|
109
|
algorithmic
|
Time Limit: 1 second
Memory Limit: 128 MB
Description
A knight moves on an N×N chessboard and must try to visit every square exactly once (no revisiting). Given the board size and the starting square, output the longest possible path.
Note that this problem doesn't require a full complete path. It only asks you to find the longest path possible, and output that path.
Constraints
- 6 ≤ N ≤ 666
Input
- The first line contains the integer N.
- The second line contains two integers r c — the starting position (row and column), 1-indexed.
Output
- The first line of output should be an integer l: the length of the path you found(remember to include r0, c0)
- Then output l lines. Each line must contain two integers r c (1-indexed), the successive positions visited by the knight, starting with the given starting position.
When outputting the answer, make sure to not have an extra empty line at the end of the output after printing out the final move.
- The first pair of coordinates in your path must be the starting points r0 and c0.
Sample Input
6
1 1
Sample Output
36
1 1
3 2
5 1
6 3
5 5
3 6
2 4
1 6
3 5
5 6
4 4
5 2
3 1
1 2
3 3
2 1
1 3
2 5
4 6
6 5
5 3
6 1
4 2
5 4
6 6
4 5
6 4
4 3
6 2
4 1
2 2
1 4
2 6
3 4
1 5
2 3
|
type: default
time: 1s
memory: 128m
checker: chk.cc
subtasks:
- score: 100
n_cases: 3 # auto-picks 1.in…10.in and (logically) 1.out…10.out,
# but your JudgeEngine first tries "X.ans" before "X.out".
|
11
|
algorithmic
|
# Palindrome Path
**Input file:** standard input
**Output file:** standard output
**Time limit:** 1 second
**Memory limit:** 256 megabytes
## Problem Description
Given an \( n \times m \) grid maze, each cell \((i,j)\) is either blank or blocked. George starts at cell \((sr,sc)\) and needs to visit all blank cells in the maze, finally ending at the exit cell \((er,ec)\). George can perform four types of moves, denoted as "L" (left), "R" (right), "U" (up), and "D" (down). When attempting a move, if the adjacent cell in that direction is blank and within bounds, George moves to it; otherwise, he stays in the current cell.
The move sequence must be a palindrome. That is, if the sequence is \( M_1, M_2, \cdots, M_k \) where each \( M_i \in \{L, R, U, D\} \), then for every \( i \) from 1 to \( k \), \( M_i = M_{k-i+1} \).
Your task is to find such a palindrome move sequence that visits all blank cells and ends at the exit cell. If multiple solutions exist, print any one. If no solution exists, output "-1". You need to minimize the number of moves.
Scoring:
Clamp(1.0 - (your sequence length - bound) / bound, 0, 1) where bound is a defined reachable solution number
## Input Format
The first line contains two integers \( n \) and \( m \) (\( 1 \leq n, m \leq 30 \)), the dimensions of the maze.
The next \( n \) lines each contain a binary string of length \( m \). A "1" indicates a blank cell, and a "0" indicates a blocked cell.
The following line contains four integers \( sr \), \( sc \), \( er \), \( ec \) (\( 1 \leq sr, er \leq n \), \( 1 \leq sc, ec \leq m \)), representing the start and exit cells. It is guaranteed that both cells are blank.
## Output Format
If a solution exists, print a string \( S \) (\( 0 \leq |S| \leq 10^6 \)) of moves on one line. If no moves are needed, output an empty line. If no solution exists, output "-1" on one line.
Do not include any extra spaces at the end of your output.
## Examples
### Example 1
**Input:**
```
2 2
11
11
1 1 2 2
```
**Output:**
```
RDLUULDR
```
**Explanation:**
The move sequence "RDLUULDR" results in the following path:
- Move right from (1,1) to (1,2)
- Move down from (1,2) to (2,2)
- Move left from (2,2) to (2,1)
- Move up from (2,1) to (1,1)
- Attempt up from (1,1) but stay (since i=1)
- Attempt left from (1,1) but stay (since j=1)
- Move down from (1,1) to (2,1)
- Move right from (2,1) to (2,2)
All blank cells are visited, and the path ends at (2,2).
### Example 2
**Input:**
```
2 2
10
01
1 1 2 2
```
**Output:**
```
-1
```
**Explanation:** George cannot reach (2,2) from (1,1) due to blocked cells.
## Constraints
- \( n, m \leq 30 \)
- The number of blank cells is at most \( 30 \times 30 = 900 \).
- The move sequence length must not exceed \( 10^6 \).
## Notes
- The start cell is considered visited at the beginning.
- If no moves are required (e.g., start and exit are the same, and only one blank cell), output an empty string.
- Ensure the output sequence is a palindrome and satisfies the visiting condition.
|
type: default
time: 2s
memory: 512m
checker: chk.cc
cheker_type: testlib
subtasks:
- score: 100
n_cases: 3
|
110
|
algorithmic
|
TIME LIMIT: 1 minute
MEMORY LIMIT: 814 MB
Description
Create and print an 8 × 14 table (grid) whose cells contain only digits 0–9. We say a number can be “read” from the grid if it can be formed as follows:
- Start at any cell in the grid.
- Move to an adjacent cell each step, where adjacency includes up, down, left, right, and the four diagonals (8 directions in total).
- Append the digit in each visited cell, in order, to form the number.
Additional rules:
- You may revisit cells you have previously visited while forming a number.
- You may not skip over cells (i.e., you cannot move to a non-adjacent cell in one step).
- You may not remain in the same cell to append additional digits without moving (i.e., no “stay” moves).
Example (conceptual, 2 × 3 grid):
Starting at a cell containing 1, moving down, then right, then up-left, then left, you could form 12314, so the number 12,314 is readable on that grid. If you begin at the cell with 4 and traverse the reverse path, you could read 41,321. However, you cannot jump to skip cells (so 46 would be unreadable if it requires a jump), and you cannot repeatedly stay on one cell (so 11 would be unreadable if it requires staying).
Input
There is no input. DO NOT TRY TO READ INPUT. WE WILL GIVE YOU THE WRONG ANSWER VERDICT.
Output
Print an 8 × 14 grid consisting only of digits 0–9.
Scoring
If every integer from 1 up to X (inclusive) can be read from your printed grid, but X+1 cannot, then your score is X.
Sample Output
10203344536473
01020102010201
00000000008390
00000000000400
00000000000000
55600000000089
78900066000089
00000789000077
Explanation of Sample
For the grid above, all integers from 1 through 112 can be read, but 113 cannot, so the score is 112.
NOTE: THE CODE IS REQUIRED, NOT THE ACTUAL OUTPUT, AND YOU CODE HAS 1 MINUTE TO GENERATE AN 8X14 GRID. AND DO NOT JUST HAVE THE CODE PRINT OUT A GRID YOU PREDETERMINED.
|
type: default
time: 1s
memory: 128m
checker: chk.cc
subtasks:
- score: 100
n_cases: 3 # auto-picks 1.in…10.in and (logically) 1.out…10.out,
# but your JudgeEngine first tries "X.ans" before "X.out".
|
111
|
algorithmic
|
Problem: Distinct Pairwise XOR Set
Time Limit: 1 second
Memory Limit: 512 MB
Description
Given an integer n, find a subset S ⊆ {1, 2, ..., n} such that:
1) For all pairs (a, b) with a, b ∈ S and a < b, the values (a XOR b) are all distinct (i.e., no two different unordered pairs produce the same XOR).
2) |S| ≥ floor(sqrt(n / 2)).
Input
A single integer n (1 ≤ n ≤ 10^7).
Output
- First line: an integer m — the size of the set S.
- Second line: m distinct integers in the range [1, n] — the elements of S, in any order.
Notes
- Any valid S is accepted. You do NOT need to maximize m; you only need m ≥ floor(sqrt(n/2)).
- The pairwise XOR distinctness means the set {a_i XOR a_j | 1 ≤ i < j ≤ m} has size m*(m-1)/2.
- Multiple correct outputs may exist for the same n.
- Print out the sequence with the longest length.
Sample
Input
49
Output
4
1 2 3 4
|
type: default
time: 1s
memory: 128m
checker: chk.cc
subtasks:
- score: 100
n_cases: 3 # auto-picks 1.in…10.in and (logically) 1.out…10.out,
# but your JudgeEngine first tries "X.ans" before "X.out".
|
112
|
algorithmic
|
SphereSpread
You are given an integer n. You need to place n points in 3D space such that all points lie within or on
a unit sphere centered at the origin (i.e., the distance from each point to the origin is at most 1).
Your goal is to maximize the minimum pairwise distance between any two points. In other words, you want
to spread the points out as much as possible, maximizing the distance between the closest pair.
Input
The first line contains a single integer n — the number of points to place.
Output
On the first line, print a single real number min_dist — the minimum pairwise distance achieved by your
point placement.
The next n lines should each contain three real numbers xi, yi, zi — the coordinates of the i-th point.
All coordinates must satisfy xi² + yi² + zi² ≤ 1 (the point lies within or on the unit sphere).
Constraints
2 <= n <= 1000
Your answer will be accepted if:
- All points are within or on the unit sphere (with absolute or relative error at most 10^-9)
- The actual minimum pairwise distance matches your claimed min_dist (with absolute or relative error at most 10^-6)
Scoring
You will be graded based on the minimum pairwise distances you achieve.
To be more specific, your answer will be compared to a reference solution ref_answer.
Your final score will be calculated as the average of 100 * min(your_answer / ref_answer, 1) across all test cases.
Time limit: 2 seconds
Memory limit: 512 MB
Sample Input:
2
Sample Output:
2
0 0 1
0 0 -1
|
type: default
time: 2s
memory: 512m
checker: chk.cc
subtasks:
- score: 100
n_cases: 3
|
113
|
algorithmic
|
Problem
There are $N$ balls numbered from $1$ to $N$, and three baskets numbered from $1$ to $3$. Initially, all $N$ balls are in basket $1$.
Balls can be moved from one basket to another according to the following rules:
When the balls in a basket are arranged in numerical order, the ball in the middle is called the center ball.
If the number of balls is even, the center ball is the one with the larger number between the two middle balls.
When moving a ball from basket $a$ to basket $b$, the center ball of basket $a$ must be moved to basket $b$, and the moved ball must become the center ball of basket $b$.
Using this rule, output the process of moving all $N$ balls from basket $1$ to basket $3$.
Input
The first line contains the number of balls $N$. ($1 \le N \le 30$)
Output
The first line should output the number of moves $M$.
The next $M$ lines should each contain two integers $a$ and $b$, separated by a space. ($1 \le a, b \le 3; a \ne b$) This indicates that the $i$-th operation moves a ball from basket $a$ to basket $b$ according to the problem's rules.
After the output, all balls originally in basket $1$ must be moved to basket $3$.
|
type: default
time: 1s
memory: 512m
subtasks:
- score: 100
n_cases: 3
checker: chk.cc
checker_type: testlib
filename: std.cc
|
117
|
algorithmic
|
Line
The territory of country P is a square with side length 2 * 10^12.
The origin is placed at the center of the square, and a Cartesian coordinate system is established so that the sides of the square are parallel to the axes.
Thus, the territory of country P is the region [-10^12, 10^12] × [-10^12, 10^12].
There are N lines on this territory, each of the form y = a_i * x + b_i.
Both a_i and b_i are unknown integers between -10^4 and 10^4.
You do not know their values.
Your task is to recover all these N lines.
To do this, you may ask the king up to Q_max queries of the following type:
- You give a point (x, y), and the king tells you the sum of the distances from (x, y) to all N lines.
You need to recover all the lines by making no more than Q_max queries.
Input
The only line of input contains one integer n.
Implementation details
You may issue queries by writing to standard output lines of the form
? x y
This query sends the interactor a query point (x, y).
You must ensure that (x, y) is inside the region [-10^12, 10^12] × [-10^12, 10^12], x and y do not have to be integers.
The interactor returns the sum of distances from (x, y) to all N lines.
You may call this function at most Q_max times.
You must also make a guess exactly once of the form
! a_1 a_2 ... a_n b_1 b_2 ... b_n
You may output the lines in any order.
Subtasks and scoring
If your program fails the time limit (1.0 s), memory limit (256 MiB),
or produces wrong output, the score for that test point is 0.
Otherwise, let Q be the number of queries you made and S be the full score of that test point:
- If Q > Q_max, score = 0.
- If Q_min < Q <= Q_max, score = S * (1 - 0.7 * (Q - Q_min) / (Q_max - Q_min)).
- If Q <= Q_min, score = S.
Constraints:
1 <= N <= 100
-10^4 <= a_i, b_i <= 10^4
Q_max = 10^4, Q_min = 402
No two lines are parallel.
Time limit: 1 second
Memory limit: 256 MB
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
119
|
algorithmic
|
Operators
- You are given n operators op₁, op₂, …, opₙ. For an input sequence of
n+1 integers a₀, a₁, …, aₙ, you need to compute the following value:
(((…(a₀ op₁ a₁) op₂ a₂) op₃ a₃)… opₙ aₙ) mod (10⁹ + 7).
- For any 0 ≤ i ≤ n, we have 0 ≤ aᵢ < 10⁹ + 7.
- For any 1 ≤ i ≤ n, opᵢ ∈ {+, ×}; that is, each operator is either
addition “+” or multiplication “×”.
You quickly wrote a program to solve this problem. Unfortunately,
because you were over‑excited after solving it, you accidentally deleted
the original problem statement and your code. As a result, you lost the
information about the n operators op₁, …, opₙ. Fortunately, you still
have the program you just compiled, so you can recover these operators
by querying your program.
Since the contest is about to end, and the program you wrote is not
efficient enough, you cannot ask more than Qₘₐₓ = 600 queries.
Implementation details
This is an interactive problem. As usual, you should submit a source code file that can compile.
Initially, you should read an integer n, the number of operators.
You may issue queries by writing to standard output lines of the form
? a₀ a₁ … aₙ
1 <= a_i < 10^9+7
Then you must flush output, and read from standard input one integer in [0, 10⁹ + 6], representing the interactor’s response.
When you have determined the operators, output a line of the form
! o₁ o₂ … oₙ
o_i is 0 if op_i is "+", is 1 if op_i is "×".
Remember to flush after your output.
Subtasks
- For all data, 1 ≤ n ≤ 600.
- Let your program make Q queries:
- If your program exceeds time limit, memory limit, or returns
incorrect answer → score=0.
- Otherwise, your score depends on Q:
- score(Q) = 41 / (Q + 1)
- In other words, a solution with Q ≤ 40 is awarded the full score.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 512m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
120
|
algorithmic
|
“Da Bai” (Interactive)
There is an undirected simple graph with 100 vertices.
In each query, you can ask the interactor by choosing three distinct vertices a, b, c.
The interactor will tell you how many edges exist among the three vertices {a, b, c}, i.e., the number of edges in the induced sub-graph on {a, b, c}. The answer will be an integer in {0, 1, 2, 3}.
You must ensure that a, b, c are pairwise distinct.
Your goal: reconstruct the entire graph.
Implementation details
This is an interactive problem. As usual, you should submit a source code file that can compile.
Initially, you should read no input.
You may issue queries by writing to standard output lines of the form
? a b c
Then you must flush output, and read from standard input one integer in [0, 3], representing the interactor’s response.
When you have determined the graph, output a line
!
Then output 100 lines, each with a length-100 binary string s_i (i from 1 to 100), describing the graph. Here s_{i,j} = ‘1’ if and only if there is an edge between vertex i and j in the graph.
Remember to flush after your output.
Sample
For convenience, in this sample we assume the graph has only **4** vertices. (In actual tests the graph has 100 vertices.)
Contestant prints | Interactor replies
---------------------|--------------------
`? 1 2 3` | 0
`? 1 2 4` | 2
`? 1 3 4` | 2
`!` |
0001
0001
0001
1110
Constraints
- All test instances have exactly 100 vertices.
- Let Q = the number of queries you make.
- If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.
- Otherwise, your score depends on Q:
- score(Q) = 3400 / (Q + 1)
- In other words, a solution with Q < 3400 is awarded the full score.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 512m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
121
|
algorithmic
|
DNA Matching
Time Limit: 2 s
Memory Limit: 512 MB
A string s is called a “DNA sequence” if and only if s consists only of the characters A, C, G, T.
You are given m strings s1, s2, ..., sm, each of length n, and each of them consists only of the characters A, C, G, T, ?.
For a DNA sequence t of length n, we call t valid if and only if there exists an index i (1 ≤ i ≤ m) and a way to replace each ? in si by one of A,C,G,T, so that after replacement the resulting string s_i' is exactly equal to t.
You need to compute the probability that a randomly chosen DNA sequence t (of length n, where each of the 4^n possible DNA sequences is equally likely) is valid.
Input Format
The first line contains two positive integers n, m.
Then follow m lines, each line contains a string si of length n. It is guaranteed that each si only uses characters from A, C, G, T, ?.
Output Format
Output one real number — the probability. Make sure the number is precise enough.
Sample 1
input
3 1
AC?
output
0.0625
Sample 2
input
6 2
AC??A?
A??A?T
output
0.0302734375
|
# Set the problem type to interactive
type: default
# Specify the interactor source file
interactor: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 512m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
122
|
algorithmic
|
This is an interactive problem.
The RiOI Team has recently developed a text editor named RiOI Editor. The editor works with exactly one integer parameter W
— the width of each line. It is known that 1≤W≤10^5
.
As you cannot understand the RiOI Language, from your point of view, words differ from each other only by their length. Hence, an article of length n
is defined as a sequence a
consisting of n
positive integers, where ai
is the length of the i
-th word in the article. The RiOI Editor displays the article [a1,a2,…,an]
on screen as follows:
If max(a1,a2,…,an)>W
, the editor is unable to display the article;
Otherwise, the editor is able to display the article by the following process:
Initially, l=1
, and s=0
. During the whole process, l
always denotes the current number of lines in the editor, and s
always denotes the sum of lengths of words in the last line;
Then, for each 1≤i≤n
:
If s+ai≤W
, the word is inserted at the end of the current line. Thus, l
remains unchanged, and s
gets increased by ai
.
Otherwise, the word is inserted into a new line. Thus, l
becomes l+1
, and s
becomes ai
.
The number of lines needed to display the article is the final value of l
.
You are very interested in the editor, so you decide to find out the value of W
by inputting some articles into the editor and observing the number of lines needed to display each article.
Formally, you can query the jury at most 2
times. In each query, you input an article [a1,a2,…,an]
(1≤n≤10^5
) to the editor, and the jury will respond to you with:
The number of lines needed to display the article, if the editor is able to display it;
0
, if the editor is unable to display the article.
Input
Each test contains multiple test cases. The first line contains the number of test cases t
(1≤t≤10
). The description of the test cases follows.
Interaction
For each test case, you can make up to 2
queries to find out the value of W
. It is guaranteed that 1≤W≤10^5
.
To make a query, you should print a new line in the following format:
? n a1 a2 … an
(1≤n,ai≤10^5
) — the article you input to the editor.
At the end of each query, the jury will print an integer, as described in the statements.
You need to minimize the sum of length of the articles in your queries. That is, the sum of n in your queries. A smaller sum will result in a better score.
To report that you have found the value of W
, print a new line in the following format:
! W
— the parameter of the editor.
Printing the answer does not count as one of the 2
queries.
After that, proceed to process the next test case or terminate the program if it was the last test case.
After printing each query do not forget to output the end of line and flush∗
the output. Otherwise, you will get Idleness limit exceeded verdict.
If, at any interaction step, you read −1
instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.
|
type: interactive
time: 3s
memory: 512m
subtasks:
- score: 100
n_cases: 3
interactor: interactor.cc
checker_type: testlib
|
123
|
algorithmic
|
Time limit per test: 1 second
Memory limit per test: 256 megabytes
Goal
-----
There is a hidden integer x with 1 ≤ x ≤ n that you must determine.
What you can do
----------------
1) Ask membership questions (up to 53 total):
- Choose any non-empty set S ⊆ {1, 2, …, n}.
- Ask whether x ∈ S.
- The judge replies “YES” if x ∈ S, otherwise “NO”.
2) Make guesses (up to 2 total):
- Output a single number as your guess for x.
- The reply is always truthful:
• “:)” if your guess equals x (you must terminate immediately).
• “:(” if your guess is wrong.
Noisy answers & guarantee
--------------------------
- Not all “YES”/“NO” answers are guaranteed to be truthful.
- However, for every pair of consecutive questions, at least one answer is correct.
- This remains true across guesses: if you ask a question, then make a guess, then ask another question, the “consecutive questions” rule applies to those two questions surrounding the guess.
- Guesses themselves are always judged correctly.
Adaptive x
----------
- The judge does not fix x in advance; it may change over time.
- Changes are constrained so that all previous responses remain valid and consistent with:
• the rule “for each two consecutive questions, at least one answer is correct,” and
• the correctness of guess judgments.
Input
-----
- A single integer n (1 ≤ n ≤ 100000), the maximum possible value of x.
Interactive protocol (I/O format)
----------------------------------
To ask a question about a set S:
- Print a line: “? k s1 s2 … sk”
• k = |S| (k ≥ 1)
• s1, s2, …, sk are distinct integers in [1, n]
- Flush output immediately.
- Read a single word reply: “YES” or “NO”.
To make a guess for x:
- Print a line: “! g” where g is your guess (1 ≤ g ≤ n).
- Flush output immediately.
- Read the judge’s reply:
• “:)” if correct — your program must terminate immediately.
• “:(” if incorrect — you may continue if you still have remaining queries/guesses.
Flushing
--------
After every printed line, flush the output to avoid idleness/timeout:
- C++: fflush(stdout) or cout.flush()
- Java: System.out.flush()
- Pascal: flush(output)
- Python: sys.stdout.flush()
- See language docs for others.
Limits
------
- Maximum questions: 53
- Maximum guesses: 2
- n up to 100000
Important notes
----------------
- Because at least one of every two consecutive question answers is correct, you can design strategies that compare adjacent answers to filter lies.
- Guesses are always reliable; use them sparingly (you only have 2).
- Note that this problem has a scoring system. You are graded based on the # of queries you use. The lower the # of queries you use, the higher the score you get.
Example
--------
Input
6
(Sequence of interactions as seen by the contestant)
? 5 1 2 5 4 3
NO
! 6
:(
? 4 1 2 3 4
NO
! 5
:)
Explanation
- If the first question’s “NO” had been truthful, x would have to be 6.
- The guess “! 6” receives “:(“, so 6 is not the answer. Therefore, the first answer must have been a lie.
- By the guarantee, the next question’s answer must then be truthful.
- From “? 4 1 2 3 4” with reply “NO”, we conclude x ∉ {1,2,3,4}; combined with “6 is wrong”, x must be 5.
- The final guess “! 5” is confirmed with “:)”.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 4s
memory: 1024m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
124
|
algorithmic
|
AveragePermutation
This is an interactive problem.
There is a hidden permutation p of n, where n is even. You want to discover this permutation using queries.
Each query consists of asking about k specific positions a1, a2, ..., ak. The query is answered with 1 if the average of the elements at these positions is an integer, and 0 otherwise.
Note that permutations [p1, p2, ..., pn] and [n+1-p1, n+1-p2, ..., n+1-pn] are indistinguishable using these queries. Therefore, you are guaranteed that p1 ≤ n/2.
This problem is graded based on the number of queries you use. Specifically, your answer will be compared to a reference solution ref_queries.
Your final score will be calculated as the average of 100 * min((ref_queries + 1) / (your_queries + 1), 1) across all test cases.
Input
The first line of the input contains an even integer n (2 ≤ n ≤ 800) indicating the length of the hidden permutation.
Interaction
To ask a query, output one line. First output ? followed by a space, then print an integer k (1 ≤ k ≤ n), then print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) separated by spaces. After flushing your output, your program should read a single integer (0 or 1) indicating whether the average is an integer.
If you want to guess the permutation, output one line. First output ! followed by a space, then print a permutation of n separated by spaces, satisfying the constraint that p1 ≤ n/2. After flushing your output, your program should exit immediately.
Note that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.
To flush your output, you can use:
fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
System.out.flush() in Java.
stdout.flush() in Python.
Time limit: 4 seconds
Memory Limit: 256 MB
Example input:
? 2 1 2
! 1 3 2
Example output:
3
1
|
type: interactive
interactor: interactor.cc
time: 4s
memory: 256m
subtasks:
- score: 100
n_cases: 3
|
125
|
algorithmic
|
Time Limit: 1 second
Memory Limit: 256 MB
Overview
This is an INTERACTIVE PROBLEM. There are N kinds of minerals. For each kind there are exactly 2 slices, for a total of 2N slices numbered 1..2N. The judge fixes a hidden pairing: for each kind, the two slices of that kind form one pair. Your task is to determine all N pairs.
You have access to a device. You may insert or extract slices from the device one at a time. After each operation, you learn how many DISTINCT kinds of minerals are currently present among the slices inside the device.
Goal
Determine all N pairs while MINIMIZING the number of queries you use. You may use at most 1,000,000 queries. Any correct solution using ≤ 1,000,000 queries is accepted; fewer queries are considered better.
Interaction Protocol (standard input/output)
1) At the start, the judge outputs a single integer:
N
• 1 ≤ N ≤ 43,000.
2) You may then repeatedly perform queries. To toggle the presence of slice x in the device:
• Output a line: ? x
where 1 ≤ x ≤ 2N
• Flush stdout.
• Read a single integer r from stdin.
r is the number of DISTINCT kinds currently present among all slices inside the device after this toggle:
– If x was not in the device, it is now inserted.
– If x was already in the device, it is extracted.
– r counts how many mineral kinds appear at least once among the slices currently in the device.
3) When you have determined a pair (a, b), output exactly one line:
• Output: ! a b
where 1 ≤ a ≤ 2N and 1 ≤ b ≤ 2N.
Over the entire run you must output exactly N such lines, and together they must use each index 1..2N exactly once.
4) Order is flexible:
• You may interleave “? x” queries and “! a b” answers in any order.
• The judge terminates the interaction immediately after reading the N-th valid “! a b” line. Do not send any further output after that point.
Important Rules and Constraints
• Only print lines of the form “? x” and “! a b”.
• Indices in queries and answers must satisfy their ranges.
• Exactly N answer lines must be printed and together cover each index 1..2N exactly once.
• A “query” is defined as one printed line “? x”. You may perform at most 1,000,000 queries.
• Flush stdout after every line you print (interactive).
• If you violate the protocol (bad format, invalid index, wrong pairings, too many queries, wrong number of answers), the judge will return a Wrong Answer verdict with a message.
Device Behavior (for clarity)
• The device maintains a set S of slices currently inside.
• Query “? x” toggles membership of x in S:
– If x ∉ S, insert x.
– Else (x ∈ S), remove x.
• The judge replies with r = number of DISTINCT mineral kinds represented by S. If S is empty, r = 0.
Scoring / Ratio (informative)
• Let Q be your total number of “? x” queries.
• The judge also knows an optimal_queries value for the instance.
• Your ratio is (1,000,000 − Q) / (1,000,000 − optimal_queries).
• The judge reports this ratio and scores only on Accepted submissions.
Sample Communication
Judge → program:
4
Program → judge:
? 1
Judge → program:
1
Program → judge:
? 2
Judge → program:
2
Program → judge:
? 5
Judge → program:
2
Program → judge:
? 2
Judge → program:
1
Program → judge:
! 3 4
Program → judge:
! 5 1
Program → judge:
! 8 7
Program → judge:
! 2 6
(Here, the program used 4 queries total.)
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 20s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
127
|
algorithmic
|
Time Limit: 1 second
Memory Limit: 256 mb
Interactive Problem
YOU MUST USE INTERACTIVE FORMAT FOR THIS PROBLEM.
You are standing in front of a row of n boxes, labeled 0 through n−1 from left to right.
Each box contains a prize that cannot be seen until the box is opened. There are v ≥ 2
different prize types, numbered from 1 to v in decreasing order of value:
type 1 is the most expensive (the diamond), and type v is the cheapest (a lollipop).
There is exactly one diamond in the boxes.
The number of cheaper prizes is much larger than the number of more expensive ones.
More precisely, for all 2 ≤ t ≤ v: if there are k prizes of type t−1, then there are
strictly more than k^2 prizes of type t.
Your task is to find the index i of the box containing the diamond using as few
queries as possible.
-------------------------------------------------------------------------------
Input
-------------------------------------------------------------------------------
Standard input (stdin) initially contains a single integer:
n — the number of boxes.
Box indices are 0-based: 0, 1, …, n−1.
-------------------------------------------------------------------------------
Interaction protocol (stdin/stdout)
-------------------------------------------------------------------------------
Your program communicates using standard input and standard output only.
There is no provided procedure to call; write a normal main program.
To ask about a box i (0 ≤ i < n):
• Print a line: ? i
• Flush the output stream immediately.
Then read from stdin two integers a0 and a1 (on the same line):
• a0 — among the boxes strictly to the left of i, the number of boxes that
contain a more expensive prize than the one in box i.
• a1 — among the boxes strictly to the right of i, the number of boxes that
contain a more expensive prize than the one in box i.
When you have determined the index i of the diamond (type 1), finish by:
• Printing a line: ! i
• Flushing the output, then terminating the program.
Notes:
• You may output extra whitespace on lines you print, but each command must be
on its own line.
• After each query line you print ("? i"), you must read exactly two integers.
• In some test cases, the judge may be adaptive: its answers may depend on the
questions you ask, but it will always remain consistent with the constraints.
-------------------------------------------------------------------------------
Constraints
-------------------------------------------------------------------------------
3 ≤ n ≤ 200000.
Each prize type is an integer between 1 and v, inclusive.
There is exactly one prize of type 1 (the diamond).
For all 2 ≤ t ≤ v, if there are k prizes of type t−1, then there are strictly
more than k^2 prizes of type t.
-------------------------------------------------------------------------------
Subtasks
-------------------------------------------------------------------------------
Single subtask: n ≤ 200000. (All constraints above apply.)
-------------------------------------------------------------------------------
Example (verbal transcript; no image)
-------------------------------------------------------------------------------
Suppose n = 8 and the hidden prize types are:
index: 0 1 2 3 4 5 6 7
types: 3 2 3 1 3 3 2 3
Here, index 3 holds the diamond (type 1).
Possible interaction:
(read) 8
(you) ? 0 → (judge replies) 0 3
Meaning: left of 0 there are 0 more-expensive prizes; right of 0 there
are 3 more-expensive prizes than the prize at 0.
(you) ? 2 → (judge replies) 1 2
Meaning: among indices {0,1}, exactly one is more expensive than 2’s;
among {3,4,5,6,7}, exactly two are more expensive than 2’s.
(you) ? 3 → (judge replies) 0 0
Meaning: no box on either side is more expensive than 3’s prize.
(you) ! 3 (finish)
The exact sequence of queries you make can differ; this is only an illustrative
transcript of the format.
-------------------------------------------------------------------------------
Scoring
-------------------------------------------------------------------------------
Let q be the number of queries you print (i.e., the number of lines of the form "? i").
Your raw score for a test is:
5000 − q (clamped below at 0 if needed).
Your overall score is your average raw score divided by the best score.
-------------------------------------------------------------------------------
Output
-------------------------------------------------------------------------------
Print exactly one final line of the form:
! i
where i is the index (0 ≤ i < n) of the box containing the diamond.
IMPORTANT NOTE: Make sure to print out answer at the end of your code. Even if you did not find the diamond, print any arbitrary index before exiting.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 8s # Giving buffer for grading time
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
13
|
algorithmic
|
Time limit: 2 seconds
Memory limit: 1024 megabytes
This is an interactive problem.
A mischievous robot is navigating an infinitely large 2D grid. However, its movement is confined to the first quadrant, meaning its coordinates (x, y) must always satisfy x > 0 and y > 0. Initially, the robot is located at grid coordinates (s_x, s_y). All grid cells are initially white.
Set T = 3000. The game proceeds in discrete time steps. In each time step, the following sequence occurs:
1. Your Move: You choose integer coordinates (x_m, y_m) such that 1 <= x_m <= T and 1 <= y_m <= T. You then mark this cell black. A cell, once marked black, remains black for the rest of the game. You can mark any cell within the range, including the cell where the robot is currently located.
2. Robot’s Move: The robot, currently at position (r_x, r_y), observes the grid (including the cell you just marked black). It knows the locations of all currently black cells. It then moves to a new position (n_x, n_y). The new position (n_x, n_y) must be one of the 8 cells immediately adjacent (horizontally, vertically, or diagonally) to (r_x, r_y). That is, |n_x - r_x| <= 1 and |n_y - r_y| <= 1, and (n_x, n_y) ̸= (r_x, r_y). Additionally, the robot must stay within the first quadrant, so n_x > 0 and n_y > 0. The interactor (controlling the robot) will choose one valid move for the robot. The robot’s strategy is unknown to you.
3. Outcome Check: After the robot moves to (n_x, n_y), the system checks if the cell (n_x, n_y) is black.
• If (n_x, n_y) is black, the robot explodes.
• If (n_x, n_y) is white, the game continues to the next time step, with the robot now at (n_x, n_y).
Your goal is to make the robot explode within as less steps as possiable. Answers exceeding 3000 steps are considered as incorrect answers.
Input
The first line of input contains two integers sx and sy (1 <= s_x, s_y <= 20), the initial coordinates of the robot.
Interaction Protocol
The interaction proceeds in turns for at most T turns. In each turn t (from t = 1 to T):
1. Your program must print one line containing two space-separated integers x_m and y_m, representing the coordinates of the cell you choose to mark black in this turn. Remember to flush the output stream.
2. The interactor reads your chosen coordinates (x_m, y_m).
3. The interactor determines the robot’s next move to (n_x, n_y) based on its current position and the set of all black cells (including the one just marked at (x_m, y_m) ).
4. The interactor checks if the cell (n_x, n_y) is black.
• If it is black (robot explodes), the interactor will print a single line containing '0 0' and terminate. Your program should then read these values and terminate successfully.
• If it is white, the interactor will print a single line containing two space-separated integers n_x and n_y, the new coordinates of the robot. Your program should read these coordinates to know the robot’s current position for the next turn.
If the robot has not exploded after you have made T moves, your program should terminate. Your solution will be judged as incorrect in this case (or if you exceed the turn limit or make an invalid move). To flush your output, you can use fflush(stdout) (if you use printf) or cout.flush() (if you use cout).
Example
standard input
5 5
5 4
5 3
5 2
5 1
0 0
standard output
6 1
4 1
6 2
4 2
5 2
|
type: interactive
time: 2s
memory: 1024m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
- score: 100
n_cases: 3
|
132
|
algorithmic
|
time limit per test: 0.25 second
memory limit per test: 512 megabytes
This is an interactive problem.
You have 𝑅 vacuum cleaner robots left over from your trade with your fellow contestants. You want to use these robots to locate the two chairmen. You can instruct each robot to scout several of 1000 positions where the chairmen could be located.
Each robot can only detect whether or not there is at least one chairman at its scouted positions. Every robot needs a full hour to scout its positions before returning with its result to you. Because this will drain the robot’s battery, you can send out each robot only once.
You want to know the positions of the chairmen after at most 𝐻 hours. In particular, you might be forced to send out several robots at once without waiting for the previous robots to return. You can assume that the two chairmen stay at the same positions all the time.
Write a program which plans this scouting mission and determines where the two chairmen are located.
Input
The first line consists of 2 integers R and H (R=75,H=1), indicating the number of vacuum cleaner robots and the number of hours.
Interaction
To send a robot to scout the positions, print on a single line "? k, 𝑃[0],…,𝑃[𝑘 − 1]" (where 𝑘 is the length of the array 𝑃). The positions 𝑃[𝑖] must be pairwise distinct integers between 1 and 1000. You can 'send' at most 𝑅 times per testcase.
To get the answers of robot that sent before, print on a single line '@', then you will receive an integer L and a array (with length L) with exactly one entry for each robot sent out one hour ago (by a 'send' after the previous 'get' to wait or after the beginning of the program). The entry at index 𝑖 is 1 if the (𝑖 +1)-th of these robots has detected at least one chairman at its scouted positions, and 0 otherwise. You can 'get' at most 𝐻 times per testcase.
Once you have figured out the positions, print '!' followed by 2 integers a and b (1 ≤ 𝑎,𝑏 ≤ 1000, 𝑎 = 𝑏 is allowed), representing the positions of the two chairmen.
After printing a query do not forget to output the end of line and flush the output. Use fflush(stdout) or cout.flush() to flush.
Grading
your actual score depends on the number rmax of robots sent out. Specifically,
rmax<=30, score=-20/3*rmax+820/3;
30<rmax<=35, score=-4*rmax+580/3;
35<rmax<=40, score=-8/3*rmax+440/3;
40<rmax<=60, score=-4/3*rmax+280/3;
60<rmax<=75, score=13;
75<rmax, score=0;
Example
Consider a testcase with 𝑅 = 75 and 𝐻 = 20 where the chairmen are located at positions 13 and 37.
First, the grader calls your function scout as scout(75,20). Then, an interaction between your program and the grader could look as follows:
Your program | read | Explanation
? 3 42 13 37 | none | send a robot to positions 13, 37 and 42
? 2 47 11 | none |send a robot to positions 13, 37 and 42
@ | 2 1 0|wait an hour for the return of two robots; only the first robot has detected a chairman
? 1 42 | none |send a robot to position 42
@ | 1 0 |wait an hour; there is no chairman at position 42 you are convinced that the chairmen are located
! 13 37 | none |you are convinced that the chairmen are located at positions 13 and 37
Returning the pair {37,13} would be accepted as well.
Note that the above queries are of course not sufficient to determine the positions of the chairmen with certainty: For example, both being at position 37 or one chairman being at position 13 while the other is at position 100 would also be consistent with all answers to wait, so the grader could also have rejected this solution.
Moreover, the grader is adaptive, i.e. the positions of the chairmen may depend on the behavior of your program in the current as well as in earlier runs.
|
type: interactive
time: 0.25s
memory: 512m
# A custom checker is required for the special scoring.
checker: interactor.cc
subtasks:
- score: 100
n_cases: 3
|
134
|
algorithmic
|
Guess Number
This is an interactive problem.
Vasya has thought of two secret integers a and b, both in the range [1, n]. Your task is to determine these two numbers by asking queries.
Each query consists of two integers x and y (both in the range [1, n]). The interactor will respond with one of the following:
- 0: Both x = a and y = b. You have successfully found the answer!
- 1: x is less than a (x < a)
- 2: y is less than b (y < b)
- 3: x is greater than a OR y is greater than b (x > a or y > b)
Important: If multiple responses are true for your query, the interactor may choose any of them.
Your goal is to find both numbers a and b using as few queries as possible.
This problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 10,000 queries. Your answer will be compared to a reference solution ref_queries. Your final score will be calculated as the average of 100 * min((ref_queries + 1) / (your_queries + 1), 1) across all test cases.
Input
There is only one test case in each test file.
The first line of the input contains an integer n (1 ≤ n ≤ 10^18) indicating the range of possible values.
Interaction
To ask a query, output one line containing two integers x and y (1 ≤ x, y ≤ n) separated by a space. After flushing your output, your program should read a single integer representing the interactor's response (0, 1, 2, or 3).
When you receive response 0, your program should terminate immediately.
To flush your output, you can use:
- fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
- System.out.flush() in Java.
- stdout.flush() in Python.
Example
Input:
5
3
3
2
1
0
Output:
4 3
3 4
3 3
1 5
2 4
Time limit: 2 seconds
Memory Limit: 512 MB
|
type: interactive
interactor: interactor.cc
time: 2s
memory: 512m
subtasks:
- score: 100
n_cases: 3
|
135
|
algorithmic
|
Problem Type: INTERACTIVE(STANDARD SOLUTIONS WILL NOT WORK)
There are many legends concerning the Leaning Tower of Toruń. The wall of the tower is a circle with N ≥ 3 evenly spaced doors (in other words, the doors are the vertices of a regular N-gon). The doors are numbered from 0 to N−1, but in a random order. Please refer to the scoring section for more details about this.
One of the less known legends describes how every new inhabitant of the tower had to complete a certain challenge. The goal of the challenge was to list the doors, starting with some door and then walking around the circle (clockwise or counterclockwise), visiting each door exactly once.
This needs to be done without actually seeing the tower. Instead, the new inhabitant can ask questions of the following form: “Given three distinct doors x, y, z, which pairs of doors are the closest to each other: {x, y}, {y, z}, or {z, x}?”. The answer to such a question are all pairs (among {x, y}, {y, z} and {z, x}) of doors with the smallest Euclidean distance. The distance is simply the length of the shortest segment connecting the doors. Your task is to write a program that will ask a small number of such questions to determine the order
of the doors.
Interaction
This is an interactive task. You should write a program which finds a correct solution to the task and communicates with the interactor by reading from the standard input and writing to the standard output.
At the beginning of the interaction, your program should read two integers k and n (k = 12000, n = 500) from the standard input, denoting the maximum allowed number of queries and the number of doors in the tower respectively.
Then your program should ask the questions in the following way:
• Your program should write a single line in the form of
? x y z
to the standard output, where x, y, and z are distinct integers (0 ≤ x, y, z ≤ n−1). This line represents a single question concerning doors x, y, and z.
• The response will be given as:
r
a1 b1
. . .
ar br
where r is an integer (1 ≤ r ≤ 3) representing the number of pairs of doors with the smallest distance.
Each such pair is described by two integers ai and bi (ai, bi ∈ {x, y, z} and ai < bi).
Once you have determined the order of the doors, you should write a single line in the form of
! x0 x1 . . . xn−1
to the standard output, where x0, x1, . . . , xn−1 is the order of the doors as described in the task statement.
Please note that there are exactly 2n possible correct answers since you can output the order starting from any door and then going in either direction. Any of them will be accepted.
Keep in mind that after each query or answer you have to flush the output buffer using
cout.flush() (or fflush(stdout) if using printf) in C++ or sys.stdout.flush() in Python. Otherwise your program may receive a Time Limit Exceeded verdict.
After writing the answer to the interactor, your program should immediately end the interaction.
Your program cannot open any files or use any other resources.
Please also note that the interactor is not adaptive, meaning that the initial order of the doors is fixed beforehand in each test case and does not change during the interaction.
Example interaction
Suppose we have one test case with n = 6, and the order of the doors is 5, 3, 0, 2, 1, 4. The interaction could look as follows:
Interactor
100 6
Comment
k = 100 and n = 6.
Your program
? 0 1 2
Comment
Your program asks which pairs of doors are the closest.
Interactor
2
0 2
1 2
Comment
Pairs of doors {0, 2} and {1, 2} are the closest.
Your program
? 4 1 3
Comment
Your program asks which pairs of doors are the closest.
Interactor
1
1 4
Comment
Pair {1, 4} is the closest.
Your program
? 0 5 1
Comment
Your program asks which pairs of doors are the closest.
Interactor
3
0 5
0 1
1 5
Comment
Pairs {0, 5}, {0, 1}, and {1, 5} are the closest.
Your program
! 4 5 3 0 2 1
Comment
Your program correctly outputs the order of the doors.
Please note that the sequences 0, 2, 1, 4, 5, 3 or 5, 4, 1, 2, 0, 3 (and a couple others) would also be correct answers in this case.
Scoring
Your score will be calculated as follows. Let k∗ be the actual number of queries asked by your program. Then, the number of points is given by the following formula:
ceil(100*min(1, (12000-k∗)/7800))
meaning that your score increases linearly from 0 to 100 as k∗ goes from 12000 to 4200.
Please note that if your program gives an incorrect answer, you will receive a score of 0 for that test case regardless of the number of queries asked.
The contraints for the problem are repeated once again below.
Problem Constraints
k = 12000, n = 500
Moreover, you can assume that each test case has been generated by first choosing n uniformly at random from all values of n satisfying the constraints of the problem, and then choosing the order of the doors uniformly at random from all orders of n doors satisfying the constraints of the problem.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 2s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
137
|
algorithmic
|
Title: Kangaroos
Goal
You must print a grid (“map”) on which a simple multi-agent movement game is played. The judge will run 500 random control sequences on your map. Your map is accepted if at least 125 of those sequences fail to gather all agents into a single cell.
World
- The world is an n-by-m grid (1 ≤ n, m ≤ 20).
- Each cell is either empty (1) or a wall (0).
- Initially, every empty cell contains exactly one kangaroo (agent).
- A move command is one of: U (up), D (down), L (left), R (right).
- On each command, all kangaroos move simultaneously:
* If the adjacent cell in that direction exists and is empty, the kangaroo moves there.
* Otherwise, it stays where it is.
Map requirements
- Grid size at most 20 × 20.
- There must be at least two empty cells.
- The subgraph of empty cells must be connected (you can go between any two empty cells by moving only through empty cells).
- The subgraph of empty cells must be acyclic (no cycles). In other words, the empty cells form a tree.
Judging
- The judge generates 500 random control strings, each of length 50,000.
- Each character in a control string is chosen independently and uniformly from {U, D, L, R}.
- In 1 string, if after applying all 50,000 moves there are still at least two kangaroos in different cells (i.e., not all agents have gathered into one cell), then you earn 1 point for that testcase.
- Your goal is to try and maximize your score over 500 random testcases.
- If your map violates any of the legality rules above (size, connectedness, no cycles, etc.), it is rejected regardless of performance.
Input
- There is no input. You only print the map.
Output
1) Print two integers: n m (1 ≤ n, m ≤ 20).
2) Then print n lines, each a string of length m consisting only of characters ‘0’ and ‘1’.
- ‘1’ means the cell is empty.
- ‘0’ means the cell is a wall.
Example (format only; not necessarily valid as a final map)
3 4
1111
1010
1100
Notes
- The judge’s random strings are produced by a standard uniform choice among U, D, L, R (e.g., typical rand()%4 mapping).
- Make sure your map satisfies all “Map requirements”; otherwise it will be rejected even if it performs well on the random tests.
- When printing out the grid, you should actually provide a c++ code which will print out the grid when run.
|
type: default
# The time limit is now 1 second.
time: 1s
memory: 512m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
- score: 100
n_cases: 1
|
138
|
algorithmic
|
### Problem C. Fabulous Fungus Frenzy
As the Traveler in the game Genshin Impact, you are exploring Sumeru. You are invited to the Nilotpala Cup Beast Tamers Tournament. To win, you must pass the Coruscating Potential challenge to cultivate Fungi.
During this challenge, you must use Floral Jellies to form blends for your fungi. You are given an initial configuration of jellies, represented by an n x m matrix. Each entry (i, j) contains a Floral Jelly. The value of the entry represents its type, and equal values mean they are the same type.
The goal is to turn the initial configuration into a target configuration. After all operations, each position must be occupied by a Floral Jelly of the required type.
You can use three kinds of operations: Switch, Rotate, and Preset.
* **Switch:** Exchange the positions of any two adjacent Floral Jellies. Two jellies at (x1, y1) and (x2, y2) are adjacent if |x1 - x2| + |y1 - y2| = 1.
* **Rotate:** Select any 2x2 block of jellies at (x, y), (x, y+1), (x+1, y+1), and (x+1, y). Shift their positions one step in a clockwise direction. The new jellies at these positions will be the ones previously at (x+1, y), (x, y), (x, y+1), and (x+1, y+1), respectively.
* **Preset:** Choose a pre-existing n' x m' formula (Matrix F) and a top-left starting position (x, y). Replace all jellies in the block from (x, y) to (x+n'-1, y+m'-1) with the jellies from the formula F.
-----
### Input
The first line contains three integers n, m, and k (2 \<= n, m \<= 20, 1 \<= k \<= 20), indicating the size of the jelly configuration and the number of preset formulas.
The following n lines each contain a string of m characters, representing the initial n x m configuration.
An empty line follows.
The following n lines each contain a string of m characters, representing the target n x m configuration.
Then, k preset formulas follow. Each preset formula starts with an empty line. The next line contains two integers np and mp (1 \<= np \<= n, 1 \<= mp \<= m), indicating the matrix size of the preset. The following np lines contain the mp-character strings for that formula.
There are 62 types of Floral Jellies, denoted by 'a'-'z', 'A'-'Z', and '0'-'9'.
-----
### Output
If the puzzle is unsolvable, output "-1".
Otherwise, output an integer r (0 \<= r \<= 4x10^5) in the first line, indicating the number of moves needed.
Then, output r lines, each containing three integers op, x, and y, describing an operation. The jelly at (x, y) is in the x-th row from the top and y-th column from the left. The operations are:
* **-4 x y**: Swaps jellies at (x, y) and (x+1, y). Requires 1 \<= x \< n, 1 \<= y \<= m.
* **-3 x y**: Swaps jellies at (x, y) and (x-1, y). Requires 1 \< x \<= n, 1 \<= y \<= m.
* **-2 x y**: Swaps jellies at (x, y) and (x, y-1). Requires 1 \<= x \<= n, 1 \< y \<= m.
* **-1 x y**: Swaps jellies at (x, y) and (x, y+1). Requires 1 \<= x \<= n, 1 \<= y \< m.
* **0 x y**: Rotates the 2x2 block at (x, y), (x, y+1), (x+1, y+1), and (x+1, y) clockwise. Requires 1 \<= x \< n, 1 \<= y \< m.
* **op x y** (where 1 \<= op \<= k): Covers the submatrix starting at (x, y) with the op-th preset formula. Requires 1 \<= x \<= n-nop+1 and 1 \<= y \<= m-mop+1.
The total number of preset operations (op \>= 1) cannot exceed 400. The total number of operations cannot exceed 4x10^5. You do not need to minimize the number of operations.
-----
### Examples
**Example 1**
**Input:**
```
3 3 1
000
GOG
BGB
000
GGG
BBB
3 1
B
G
B
```
**Output:**
```
4
1 1 3
0 1 2
-1 3 2
-4 3 3
```
**Example 2**
**Input:**
```
2 2 1
00
00
PP
PP
1 2
OP
```
**Output:**
```
-1
```
**Example 3**
**Input:**
```
4 8 4
11122222
33344444
55556666
77777777
NIXSHUOX
DEXDUIxx
DANXSHIX
YUANSHEN
2 3
NIy
DEX
3 8
ZZZZZZZZ
DANNSH9I
YUA9SHEN
1 1
X
2 5
SH08y
DUUI8
```
**Output:**
```
13
2 2 1
-3 3 4
-2 3 8
1 1 1
4 1 4
0 1 6
3 1 3
3 1 8
3 2 3
3 2 7
3 2 8
3 3 4
3 3 8
```
|
type: default
time: 5s
memory: 1024m
subtasks:
- score: 100
n_cases: 3
checker: chk.cpp
checker_type: testlib
|
14
|
algorithmic
|
Problem Statement
There are n vertices forming a simple cycle. It is guaranteed that the graph satisfies the following property:
- There exists a permutation p of length n such that for every i (1 ≤ i < n), the vertices p_i and p_{i+1} are adjacent in the graph, and also p_n and p_1 are adjacent.
At the beginning of the interaction, a token is placed at a predetermined starting vertex s (1 ≤ s ≤ n).
The value of n is hidden from the contestant. The contestant may interact with the judge in order to determine n.
---
Interaction Protocol
The contestant may issue the following commands:
1. walk x
- Input: a nonnegative integer x (0 ≤ x ≤ 10^9).
- Effect: the token moves x steps forward along the cycle from its current position.
- Output: the label of the vertex reached after the move.
2. guess g
- Input: an integer g (1 ≤ g ≤ 10^9).
- Effect: ends the interaction.
- If g = n, the answer is considered correct. Otherwise, it is considered wrong.
Constraints:
- 1 ≤ n ≤ 10^9
- 1 ≤ s ≤ n
- The number of walk operations must not exceed 200000.
---
Scoring
Let q be the number of walk operations made before the guess.
- If the guess is wrong or q > 200000, the score is 0.
- Otherwise, the score is f(q), where f is a continuous, monotonically decreasing function defined in log10-space by linear interpolation through the following anchor points:
f(1) = 100
f(10000) = 95
f(20000) = 60
f(50000) = 30
and further decreasing linearly to
f(200000) = 0.
Thus, fewer walk queries yield a higher score, with a perfect solution scoring close to 100.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cpp
# Time and memory limits still apply to the contestant's solution
time: 5s
memory: 1024m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
140
|
algorithmic
|
Mineral Deposits (interactive)
You handle signal processing for an extra-terrestrial mining company. Your vessel is approaching an asteroid.
Preliminary scans show the presence of k mineral deposits on the asteroid, but their precise locations are unknown.
The surface of the asteroid is modeled as a grid of integer coordinates. Each mineral deposit i is at unknown integer
coordinates (x_i, y_i) with −b ≤ x_i ≤ b and −b ≤ y_i ≤ b, for some integer b corresponding to the size of your initial scan.
You may send probes to the surface in waves.
If you send a wave of d probes at coordinates (s_j, t_j) for j = 1..d, then when a probe arrives, it measures the Manhattan
distance to each of the k deposits. All data packets arrive together and are indistinguishable across probes.
Thus, one wave returns the k·d integer distances:
|x_i − s_j| + |y_i − t_j| for all i in {1..k} and j in {1..d}.
The list of returned distances is in non-decreasing order.
Goal
— Minimize the number of probe waves needed to determine all deposit locations.
Interaction
At the start, read a single line containing three integers: b, k, w — the scan boundary, the number of deposits,
and the maximum number of waves you may send.
You may then make at most w queries, each representing one wave. A query is printed as:
? d s1 t1 s2 t2 ... sd td
with 1 ≤ d ≤ 2000. Each probe coordinate must satisfy −10^8 ≤ s_j, t_j ≤ 10^8.
The judge replies with one line containing k·d integers in non-decreasing order: the multiset of all Manhattan
distances between the deposits and the d probe coordinates.
The total number of probes across all waves must not exceed 2·10^4.
To finish, print one line:
! x1 y1 x2 y2 ... xk yk
containing the coordinates of all k deposits in any order. This must be your last line of output.
Base Constraints
1 ≤ b ≤ 10^8, 1 ≤ k ≤ 20, and 2 ≤ w ≤ 10^4.
Scoring
For each test case, your score is:
(# of mineral deposits found) / k
Your overall score is the average over all test cases. There are no point-based subtasks in this version.
Example
If k = 2 deposits are at (1, 2) and (−3, −2), and you send d = 3 probes to (−4, −3), (−1, 0), and (2, −1),
you must print:
? 3 -4 -3 -1 0 2 -1
and the response would be the six distances:
2 4 4 4 6 10
If the next wave has d = 2 probes at (1, 2) and (0, −2), you must print:
? 2 1 2 0 -2
and the response would be:
0 3 5 8
Finally you might answer:
! 1 2 −3 −2
Implementation notes:
You may not ask more than w queries. Once you ask w queries and do the respective calculations, you should just print out the locations of the mineral deposits.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 1s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
141
|
algorithmic
|
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
Your answer will be compared to a reference solution ref_cost. Your final score will be calculated as the average of 100 × min(ref_cost / your_cost, 1) across all test cases.
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
|
type: interactive
interactor: interactor.cc
time: 4s
memory: 512m
subtasks:
- score: 100
n_cases: 3
|
142
|
algorithmic
|
Ball Game
You are given n+1 poles numbered from 1 to n+1. Initially, poles 1 through n each contain m balls stacked vertically, while pole n+1 is empty. There are n*m balls in total, with n different colors, where each color appears exactly m times.
Your task is to rearrange the balls so that all balls of the same color are on the same pole. The final distribution of colors to poles does not matter, as long as each pole contains balls of at most one color.
You can perform operations to move balls between poles. In one operation, you can move the topmost ball from pole x to the top of pole y, subject to the following constraints:
- Pole x must have at least one ball
- Pole y must have at most m-1 balls
Your goal is to minimize the number of operations needed. You must use at most 2,000,000 operations.
Input
The first line contains two integers n and m (2 ≤ n ≤ 50, 2 ≤ m ≤ 400) — the number of colors and the number of balls of each color.
The next n lines each contain m integers. The i-th line describes the color of balls on pole i from bottom to top. (colors are numbered from 1 to n).
Output
On the first line, print a single integer k (0 ≤ k ≤ 2,000,000) — the number of operations in your solution.
The next k lines should each contain two integers x and y (1 ≤ x, y ≤ n+1, x ≠ y), indicating that you move the topmost ball from pole x to pole y.
It is guaranteed that a valid solution exists.
Scoring
You will be graded based on the number of operations you use.
In order to receive any points, you must use no more than 2,000,000 operations.
After that, your answer will be compared to a reference solution ref_ops. Your final score will be calculated as the average of 100 * min((ref_ops + 1) / (your_ops + 1), 1) across all test cases.
Time limit: 4 seconds
Memory limit: 512 MB
Sample Input:
2 3
1 1 2
2 1 2
Sample Output:
6
1 3
2 3
2 3
3 1
3 2
3 2
|
type: default
time: 4s
memory: 512m
checker: chk.cc
subtasks:
- score: 100
n_cases: 3
|
143
|
algorithmic
|
Problem: Texas Hold’em Training (Terminal I/O Interactive)
Time limit: 10 seconds
Memory limit: 512 MB
Overview
You will write a program that plays a large number of very simplified heads-up Texas Hold’em hands against a fixed opponent policy. The judge runs the game and reveals exactly the information you are allowed to know. Your program must decide whether to CHECK, FOLD, or RAISE an integer number of chips each betting round to maximize your chip profit. Interaction is via standard input/output (stdin/stdout). You must flush after every line you print.
Cards, ranks, and hand comparison
- Deck: 52 cards, 4 suits labeled 0,1,2,3. Each suit has 13 values labeled 1..13 corresponding to 2,3,4,5,6,7,8,9,T,J,Q,K,A (in strictly increasing order).
- A 5-card hand type ranking (highest to lowest):
1) Straight flush (a straight with all five cards same suit)
2) Four of a kind
3) Full house (three of a kind + a pair)
4) Flush (five cards same suit)
5) Straight (five consecutive values; A-2-3-4-5 is valid and is the lowest straight; K-A-2-3-4 is not)
6) Three of a kind
7) Two pairs
8) One pair
9) High card
- Comparing two hands:
- If hand types differ, higher type wins.
- If both are straights or straight flushes: compare by the straight’s rank. Ten-to-Ace (T-J-Q-K-A) is the highest; A-2-3-4-5 is the lowest.
- Otherwise, sort the 5 cards by the tuple (multiplicity, value) in descending order, where multiplicity is how many times the value appears in the hand. Compare these 5-card sequences lexicographically. Suits never break ties beyond determining flush/straight flush.
- Examples:
- Same-suit 5-6-7-8-9 > same-suit A-2-3-4-5.
- Same-suit A-2-3-4-5 > same-suit 2-4-5-6-7 (the latter is not a straight).
- 3-3-8-8-K > 5-5-7-7-A (two pairs with higher top pair/tiebreakers).
- Q-Q-Q-T-T > J-J-J-A-A.
- Board-of-7 rule: At showdown each player forms their best 5-card hand from their 7 available cards (2 private + 5 community). The higher best 5-card hand wins; equal best hands tie.
Game flow (per hand)
- Shuffling and dealing:
- The 52 cards are uniformly randomly permuted.
- You (Alice) receive the top 2 cards; the opponent (Bob) receives the next 2 (unknown to you).
- A “pot” starts with 10 chips. Both players start the hand with 100 chips behind (stacks). All chip counts are integers.
- Four betting rounds, with at most one action from you and one response from Bob per round:
1) Round 1 (preflop): no community cards are visible.
2) Reveal 3 community cards (the flop).
3) Round 2.
4) Reveal 1 community card (the turn).
5) Round 3.
6) Reveal 1 community card (the river).
7) Round 4.
- Your options when it is your turn in any round:
- CHECK: no chips move.
- FOLD: the hand ends immediately; Bob wins the entire pot.
- RAISE x: choose an integer x with 1 ≤ x ≤ your current stack; you move x chips into the pot.
- Bob’s response after your action:
- If you CHECK: Bob always CHECKS (no bet this round).
- If you RAISE x: Bob either FOLDs (you win the pot immediately) or CALLs (she moves x chips into the pot).
- It is guaranteed Bob always has enough chips to call any allowed raise x (by construction of this single-raise-per-round process).
- Showdown and payouts:
- If nobody folds by the end of Round 4, reveal all community cards (already visible) and both hole cards are implicitly known to the judge; the judge determines the winner using the rules above.
- Winner gets the entire pot; if tie, the pot is split evenly (integer arithmetic; pot is always even here).
- Your profit for the hand is (your ending stack) − 100. Positive means you won chips; negative means you lost chips.
Opponent policy (Bob)
- If you CHECK, she CHECKs.
- If you RAISE x, she compares:
- EV(FOLD) = (her current stack) − 100.
- EV(CALL) = estimated via 100 Monte Carlo rollouts:
- Consider all yet-unseen cards (your hole cards are hidden from Bob, and unrevealed community cards are unknown).
- For each rollout: take a uniform random permutation of the remaining unseen cards; assign them to all unknown positions in natural order (your hidden cards remain unknown to Bob but are assigned in the simulation; remaining community cards are dealt next).
- Assume that after she calls now, you will CHECK in all future rounds (this is how she evaluates the call).
- Compute her resulting profit in that simulation.
- EV(CALL) is the average over the 100 rollouts.
- She CALLs if and only if EV(CALL) > EV(FOLD); otherwise she FOLDs.
Terminal I/O protocol
All lines are plain ASCII tokens separated by spaces. You must flush after every line you print. If you ever read -1, you must exit immediately.
Start of the match
- Read a single integer G: the number of hands the judge will play (up to 10,000 in official tests).
Per-hand loop
The judge will drive the hand by repeatedly sending a STATE describing your next decision point. After a STATE, you may ask for Monte Carlo equity estimates, then you must output exactly one ACTION.
State description (from judge to you)
- STATE h r a b P k
- h: 1-based hand index
- r: current round in {1,2,3,4} (you act first in each round)
- a: your current stack (chips behind)
- b: Bob’s current stack
- P: current pot size
- k: number of currently revealed community cards; k ∈ {0,3,4,5}
- ALICE c1 v1 c2 v2
- Your two hole cards as (suit, value) pairs; suit in [0..3], value in [1..13] for 2..A
- BOARD followed by 2k integers
- Exactly k cards, each as (suit, value); if k = 0, the line is just “BOARD” with no numbers.
Optional helper query (from you to judge)
- RATE t
- t: positive integer number of sampling rollouts the judge should use to estimate your win/draw rates from the current partial state (this mimics getRatesBySampling). The judge responds:
- RATES w d
- w: estimated probability that your final 7-card hand will be strictly better than Bob’s (double)
- d: estimated probability of a tie (double)
- The sampling completes the currently unknown cards (Bob’s hole, unrevealed community) uniformly at random from the remaining deck.
- Global budget: sum of all t over the entire match must be ≤ 3,000,000. If you exceed this, the judge may reply with -1 and terminate. RATE does not advance the hand; you may issue multiple RATE queries per STATE within the budget.
Your decision (exactly one per STATE)
- ACTION CHECK
- ACTION FOLD
- ACTION RAISE x
- x must be an integer with 1 ≤ x ≤ your current stack a.
Judge’s immediate response after your ACTION
- If ACTION CHECK:
- OPP CHECK
- If r < 4, dealing proceeds and you will receive the next STATE for round r+1 (with updated k = 3,4,5).
- If r = 4, the hand ends by showdown; judge then prints RESULT delta.
- If ACTION RAISE x:
- OPP FOLD
- The hand ends immediately; judge prints RESULT delta (your profit for this hand).
- or OPP CALL x
- The hand continues. If r < 4, the judge proceeds to the next STATE (round r+1 with more community cards). If r = 4, the hand ends by showdown and judge prints RESULT delta.
- RESULT delta
- delta is your integer profit for this hand: ending stack − 100. The next hand then begins (or the match ends if h = G).
End of the match
- After all G hands, the judge prints:
- SCORE W
- W is your average profit per hand (double), i.e., mean of all delta.
Validity and termination
- Any malformed command, out-of-range raise, or protocol violation may cause the judge to print -1 and terminate immediately; your program must exit upon reading -1.
- Always flush after printing RATE or ACTION (e.g., in C++: cout << line << endl; or fflush(stdout)).
Constraints and guarantees
- G ≤ 10,000 in official tests.
- Sum of t over all RATE queries ≤ 3,000,000.
- All chip movements are integers. Pot and stacks fit in 32-bit signed integers in all official tests.
- The hidden deck for each hand is fixed before the hand begins and does not depend on your queries.
- With this single-raise-per-round structure and symmetric stacks, Bob always has enough chips to CALL any legal RAISE you declare.
Scoring
Only programs that follow the protocol, do not exceed the RATE budget, and finish all hands are scored.
Let W be the final average profit per hand printed by the judge (the SCORE value). Your points are a piecewise-linear function of W:
- If W ≤ 8.0: score = 0.
- If 8.0 < W ≤ 11.0: score increases linearly from 0 to 40:
score = round(13.3 × (W − 8)).
- If 11.0 < W ≤ 14.0: score increases linearly from 40 to 82:
score = 40 + round(14 × (W − 11)).
- If 14.0 < W: score increases linearly from 82 to Infinite:
score = 82 + round(3 × (W − 14)).
Interpretation:
- Around W ≥ 11 indicates you beat a simple baseline (roughly “Small Task”).
- Around W ≥ 16 indicates a strong strategy (roughly “Large Task”).
Example interaction (illustrative only)
Judge: 1
Judge: STATE 1 1 100 100 10 0
Judge: ALICE 0 12 2 1
Judge: BOARD
You: RATE 100
Judge: RATES 0.421000 0.010000
You: ACTION RAISE 5
Judge: OPP FOLD
Judge: RESULT 15
Judge: SCORE 15.000000
Notes and clarifications
- Card encoding:
- Each card is printed as two integers: suit in [0..3], value in [1..13] corresponding to 2..A.
- Community cards appear in deal order on BOARD (first the 3-card flop, then turn, then river).
- You do not need to implement hand evaluation to be correct; the judge handles showdowns. However, to plan your actions you may use RATE queries (within budget) or implement your own simulation/evaluation.
- Precision of RATES and SCORE is implementation-defined by the judge; treat them as doubles. Do not rely on a fixed number of decimals.
- If you ever read -1, exit immediately without printing anything further.
Strategy discussion (non-binding)
- The opponent’s CALL decision underestimates your future aggression (she assumes you will CHECK afterwards), which can be exploited by well-timed raises.
- RATE queries give you (win, tie) probabilities under random completions; combined with current pot and effective stacks, you can estimate immediate fold equity versus call equity to choose raise sizes.
- Budget your RATE calls: preflop and early-street coarse estimates (small t) and larger t near pivotal decisions can perform well within the 3,000,000 budget.
|
# Set the problem type to interactive
type: interactive
# Specify the interactor source file
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 100s
memory: 512m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3 # Looks for 1.in, 2.in, ... 5.in
|
144
|
algorithmic
|
Find Median
This is an interactive problem.
There is a hidden permutation p of length n, where n is even.
You are allowed to make queries by choosing a subsequence of indices with even length k (where 4 ≤ k ≤ n). For a chosen subsequence, the interactor will return the two median values.
For a subsequence of even length k, the two medians are defined as the k/2-th and (k/2+1)-th smallest values in that subsequence.
Your goal is to find the index of the two medians in permutation p. This problem is graded based on the number of queries you use. In order to receive any points, you must use no more than 500 queries. After that, your answer will be compared to a solution ref_queries. Your final score will be calculated as the average of 100 * min(ref_queries / your_queries, 1) across all cases.
Input
The first line contains a single integer n (6 ≤ n ≤ 100, n is even) — the length of the hidden permutation.
Interaction
To make a query, output one line in the following format:
0 k x1 x2 ... xk
where:
- k is the length of the subsequence (4 ≤ k ≤ n, k must be even)
- x1, x2, ..., xk are distinct indices between 1 and n
After each query, read a line containing two integers m1 and m2 (1 ≤ m1 < m2 ≤ n) — the two median values of the subsequence.
When you have found the answer, output one line in the following format:
1 i1 i2 - the index of the two medians.
After printing the answer, your program should terminate immediately.
Note: The interactor is non-adaptive. The permutation is fixed before you start querying.
To flush your output, use:
- fflush(stdout) or cout.flush() in C++
- System.out.flush() in Java
- stdout.flush() in Python
Example Interaction
Input:
6
3 4
3 4
2 3
Output:
0 6 1 2 3 4 5 6
0 4 3 6 1 5
0 4 3 6 2 5
1 3 6
Time limit: 4 seconds
Memory limit: 512 MB
|
type: interactive
interactor: interactor.cc
time: 4s
memory: 512m
subtasks:
- score: 100
n_cases: 3
|
145
|
algorithmic
|
# Meituan Cup Warm-up Problem — Number Loop
This year's Meituan Cup warm-up problem is a **Number Loop**.
When designing this problem, Suanxie first selected the following template, ensuring that the puzzle must contain the two patterns **MT** and **PKU**.
The next step is to replace all `?` in the template with digits from `0` to `3`, thus forming a valid Number Loop puzzle. An important requirement is that the puzzle must have a **unique solution** (the definition of a solution can be found in the warm-up problem).
However, Suanxie found that creating a puzzle of suitable difficulty with a unique solution on this template was extremely challenging. Therefore, he temporarily modified the template, which resulted in the final warm-up problem used in the contest.
Although he eventually managed to produce a valid puzzle, the feeling of failure still bothered him. Now, he hopes that you can help him achieve his original goal — **to construct a unique-solution Number Loop puzzle based on the original template.**
---
## Problem Description
You need to construct a valid Number Loop puzzle according to the given input type.
* If the input is `0`, this corresponds to the **Small Task**: replace all `?` in the template with integers from `0` to `3`, ensuring the resulting puzzle has a **unique solution**.
* If the input is `1`, this corresponds to the **Large Task**: replace all `?` in the template with integers from `1` to `3`, ensuring the resulting puzzle has a **unique solution**.
Your program should output a $12\times12$ grid consisting only of spaces and digits `0`–`3`, representing the constructed puzzle. Each row of the grid corresponds to one line of output (including spaces).
---
## Input Format
The input contains a single integer:
* `0` — requires output of the Small Task solution.
* `1` — requires output of the Large Task solution.
---
## Output Format
Output a $12\times12$ character matrix containing only spaces and digits `0`–`3`, representing your constructed Number Loop puzzle.
---
## Sample Output
Below is a sample output (note that this example has **multiple solutions** and therefore does **not** satisfy the problem requirement; it is shown only to illustrate the format):
```
0 0 000
00 00 0 0
0 0 0 0 0
0 0 0 0000
0 0 0 0
0 0 0
0 0 00000
0 0 0
00 0 0 0
0 0 0 0 0
0 0 000 0
```
|
type: default
time: 3s
memory: 1024m
checker: checker.cpp
cheker_type: testlib
subtasks:
- score: 100
n_cases: 2
|
147
|
algorithmic
|
Problem Statement
--------
AtCoder has decided to place web advertisements of $n$ companies on the top page.
The space for placing advertisements is a square of size 10000 x 10000.
The space for each company must be an axis-parallel rectangle with positive area, and the coordinates of the vertices must be integer values.
Different rectangles may touch on their sides, but they must not overlap. In other words, the common area must not have positive area.
It is allowed to leave some free space that does not belong to any ad.
President Takahashi asked each company for their desired location and area. Company $i$ wants an ad space with area $r_i$ including point $(x_i+0.5, y_i+0.5)$.
The satisfaction level $p_i$ of company $i$ is determined as follows.
- If the ad space for company $i$ does not contain the point $(x_i+0.5, y_i+0.5)$, then $p_i = 0$.
- If the ad space for company $i$ contains the point $(x_i+0.5, y_i+0.5)$ and the area is $s_i$, then $p_i = 1 - (1 - \min(r_i,s_i) / \max(r_i, s_i))^2$.
Your task is to determine the placement of the ads so that the sum of the satisfaction levels is maximized.
You will get a score of $10^9 \times \sum_{i=0}^{n-1} p_i / n$ rounded to the nearest integer.

Input
--------
Input is given from Standard Input in the following format:
~~~
$n$
$x_0$ $y_0$ $r_0$
$\vdots$
$x_{n-1}$ $y_{n-1}$ $r_{n-1}$
~~~
- $50\leq n\leq 200$
- $x_i$ and $y_i$ are integers satisfying $0\leq x_i\leq 9999$ and $0\leq y_i\leq 9999$. For any $i\neq j$, $(x_i,y_i)\neq (x_j,y_j)$ holds.
- $r_i$ is an integer at least one and satisfies $\sum_{i=0}^{n-1} r_i=10000\times 10000$.
Output
--------
Let $(a_i, b_i)$ and $(c_i, d_i)$ ($0\leq a_i<c_i\leq 10000$, $0\leq b_i<d_i\leq 10000$) be the coordinates of the two diagonal vertices of the rectangle representing the ad space for company $i$.
Output to standard output in the following format.
~~~
$a_0$ $b_0$ $c_0$ $d_0$
$\vdots$
$a_{n-1}$ $b_{n-1}$ $c_{n-1}$ $d_{n-1}$
~~~
Input Generation
--------
Let $rand()$ be a function that generates a uniformly random double-precision floating point number at least zero and less than one.
#### Generation of $n$
The number of companies $n$ is generated by rounding $50 × 4^{rand()}$ to the nearest integer value.
#### Generation of $x_i$ and $y_i$
The list of desired locations $(x_1,y_i),\ldots,(x_n,y_n)$ is generated by randomly sampling $n$ distinct coordinates from $\\{(x, y) \mid x\in \\{0,1,\ldots,9999\\}, y\in\\{0,1,\ldots,9999\\}\\}$.
#### Generation of $r_i$
Let $q_1,\ldots,q_{n-1}$ be a sorted list of $n-1$ distinct integers randomly sampled from $\\{1,2,\ldots,99999999\\}$.
Let $q_0=0$ and $q_n=100000000$.
Then $r_i=q_{i+1}-q_i$.
Number of test cases
--------
- Provisional test: 50
- System test: 1000. We will publish seeds.txt (md5=8fc1ce3f4beabac6abc1bdb4206d7f7e) after the contest is over.
The score of a submission is the total scores for each test case.
In the provisional test, if your submission produces illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA or TLE, and the score of the submission will be zero.
In the system test, if your submission produces illegal output or exceeds the time limit for some test cases, only the score for those test cases will be zero.
Tools
--------
You can download an input generator and visualizer <a href="https://img.atcoder.jp/ahc001/ded8fd3366b4ff0b0d7d053f553cdb84.zip">here</a>.
To use them, you need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
148
|
algorithmic
|
Problem Statement
--------
There is a floor consisting of $50\times 50$ squares.
The floor is covered with rectangular tiles without any gaps.
Each tile has a size of either $1\times 1$, $1\times 2$, or $2\times 1$ squares.
Let $(0, 0)$ denote the top-left square, and $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
Takahashi starts from $(si, sj)$ and walks along a path satisfying the following conditions.
- From $(i, j)$, he can move to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, or $(i,j+1)$ in one step.
- He can step on the same tile only once. The tile at the initial position is assumed to have already been stepped on.
Each square has an integer value, and the score of a path is the sum of the values of the visited squares, including the square at the initial position.
Your goal is to find a path with as high a score as possible.
Examples
--------
<img src="./images/out1.svg" width=200>
<img src="./images/out2.svg" width=200>
<img src="./images/out3.svg" width=200>
Of the above three figures, only the path in the left figure satisfies the conditions.
In the middle figure, the same tile is stepped on twice in a row.
In the right figure, he left a tile once and then came back to the same tile.
<img src="./images/out.min.svg" width=1002>
Visualization result of the sample output.
The red circle represents the initial position, and the green circle represents the final position.
The tiles stepped on are painted in light blue.
Scoring
--------
The score of the output path is the score for the test case.
If the output does not satisfy the conditions, it is judged as `WA`.
There are 100 test cases, and the score of a submission is the total score for each test case.
If you get a result other than `AC` for one or more test cases, the score of the submission will be zero.
The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest.
If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input
--------
Input is given from Standard Input in the following format:
~~~
$si$ $sj$
$t_{0,0}$ $t_{0,1}$ $\ldots$ $t_{0,49}$
$\vdots$
$t_{49,0}$ $t_{49,1}$ $\ldots$ $t_{49,49}$
$p_{0,0}$ $p_{0,1}$ $\ldots$ $p_{0,49}$
$\vdots$
$p_{49,0}$ $p_{49,1}$ $\ldots$ $p_{49,49}$
~~~
- $(si,sj)$ denotes the initial position and satisfies $0\leq si,sj\leq 49$.
- $t_{i,j}$ is an integer representing the tile placed on $(i,j)$. $(i,j)$ and $(i',j')$ are covered by the same tile if and only if $t_{i,j}=t_{i',j'}$ holds. Let the total number of tiles be $M$, then $0\leq t_{i,j}\leq M-1$ is satisfied.
- $p_{i,j}$ is an integer value satisfying $0\leq p_{i,j}\leq 99$ which represents the score obtained when visiting $(i,j)$.
Output
--------
Let `U`, `D`, `L`, and `R` represent the movement from $(i,j)$ to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, and $(i,j+1)$, respectively.
Output a string representing a path in one line.
Input Generation
--------
#### Generation of $si,sj$
Generate an integer between $0$ and $49$ uniformly at random.
#### Generation of $t_{i,j}$
We start from an initial configuration where tiles of size $1\times 1$ are placed on all squares.
We shuffle the 50x50 squares in random order and perform the following process for each square in order.
- If the tile placed on the current square is $1\times 1$, we randomly select one of the adjacent squares whose tile is $1\times 1$ and connect the two tiles into one tile. If there are no such adjacent squares, we do nothing.
- If the tile placed on the current square is not $1\times 1$, we do nothing.
#### Generation of $p_{i,j}$
Generate an integer between $0$ and $99$ uniformly at random independently for each square.
Tools
--------
- <a href="https://img.atcoder.jp/ahc002/8c847d8177acc2dd417be4327252e39e.zip">Inputs</a>: A set of 100 inputs (seed 0-99) for local testing, including the sample input (seed 0). These inputs are different from the actual test case.
- <a href="https://img.atcoder.jp/ahc002/e5b2b399792299b5b35543c219e89601.html">Visualizer on the web</a>
- <a href="https://img.atcoder.jp/ahc002/c993bb7f09d9f8857fc90951fc6af11d.zip">Input generator and visualizer</a>: If you want to use more inputs, or if you want to visualize your output locally, you can use this program. You need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
149
|
algorithmic
|
Story
--------
AtCoder is developing a route navigation application that utilizes shortest path algorithms.
The service area is represented as a road network of 30x30 vertices connected in a grid.
When a user specifies the vertex of the current location and the vertex of the destination, the app will output the shortest path between them.
The trouble is that, even though the scheduled release date is approaching, the measurement of the length of each edge, which is essential for shortest path computations, is not finished at all.
Therefore, AtCoder decided to give up measuring the edge length in advance and allows the app to output paths that are not the shortest.
It should be possible to gradually improve the performance by estimating the length of each edge based on the information about the actual time users take to arrive at their destinations.
Problem Statement
--------
There is an undirected grid graph with 30x30 vertices with unknown edge lengths.
Let $(0, 0)$ denote the top-left vertex, and $(i, j)$ denote the vertex at the $i$-th row from the top and $j$-th column from the left.
Your task is to process the following query 1000 times.
In the $k$-th query, your program first receives the vertices $s_k=(si_k,sj_k)$ and $t_k=(ti_k,tj_k)$ from Standard Input in the following format:
~~~
$si_k$ $sj_k$ $ti_k$ $tj_k$
~~~
Then, your program should compute a path $P_k$ from $s_k$ to $t_k$.
Let `U`, `D`, `L`, and `R` represent the movement from $(i,j)$ to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, and $(i,j+1)$, respectively.
Output a string representing the path $P_k$ to Standard Output in one line.
**After the output, you have to flush Standard Output.** Otherwise, the submission might be judged as TLE.
After your program outputs a path, the judge program calculates the length $b_k$ of the path, generates a uniform random number $e_k$ between $0.9$ and $1.1$, and gives an integer value $\mathrm{round}(b_k\times e_k)$ to Standard Input.
By reading that integer, the $k$-th query completes, and you should proceed to the $k+1$-th query.
Examples
-----------------
<table class="table table-bordered">
<thead>
<tr>
<th align="left">Input</th>
<th align="left">Output</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><pre>3 19 16 17</pre></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><pre>DDDDDDDDDDDDDLL</pre></td>
</tr>
<tr>
<td align="left"><pre>99561</pre></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><pre>26 18 13 18</pre></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><pre>UUUUUUUUUUUUU</pre></td>
</tr>
<tr>
<td align="left"><pre>72947</pre></td>
<td align="left"></td>
</tr>
</tbody>
</table>
Scoring
--------
Let $a_k$ and $b_k$ be the lengths of the shortest path and the output path for the $k$-th query ($1\leq k\leq 1000$), respectively.
Then the score for the test case is
$\mathrm{round}(2312311\times \sum_{k=1}^{1000}0.998^{1000-k} \frac{a_k}{b_k})$
The score of a submission is the total score for each test case.
If your program outputs an illegal path (visiting the same vertex multiple times, going outside of 30x30, or not a path from $s$ to $t$), it is judged as `WA`.
After the contest is over, the final ranking will be determined by system tests against the last submission.
- Provisional tests consist of 100 test cases. If you get a result other than `AC` for one or more test cases, the score of the submission will be zero.
- System tests consist of 3000 test cases. If you get a result other than `AC` for some test cases, only the score for those test cases will be zero. We will publish seeds.txt (md5=0cf5051d586e7f62c0b3527f6f7fbb1c) after the contest is over.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniformly random integer between $L$ and $U$, inclusive.
We first generate two parameters $D=\mathrm{rand}(100, 2000)$ and $M=\mathrm{rand}(1, 2)$.
Let $h_{i,j}$ be the length of the edge between $(i, j)$ and $(i,j+1)$, and let $v_{i,j}$ be the length of the edge between $(i, j)$ and $(i+1,j)$.
#### Generation of $h_{i,j}$
1. For each $i\in\\{0,\ldots,29\\}$ and $p\in\\{0,\ldots,M-1\\}$, we independently generate a random integer $H_{i,p}=\mathrm{rand}(1000+D,9000-D)$.
2. For each $i\in\\{0,\ldots,29\\}$ and $j\in\\{0,\ldots,28\\}$, we independently generate a random integer $\delta_{i,j}=\mathrm{rand}(-D,D)$.
3. If $M=1$, for each $i\in\\{0,\ldots,29\\}$ and $j\in\\{0,\ldots,28\\}$, we set $h_{i,j}=H_{i,0}+\delta_{i,j}$.
4. If $M=2$, for each $i\in\\{0,\ldots,29\\}$, we generate a random integer $x_i=\mathrm{rand}(1,28)$, and then for each $j\in\\{0,\ldots,x_i-1\\}$, we set $h_{i,j}=H_{i,0}+\delta_{i,j}$, and for each $j\in\\{x_i,\ldots,28\\}$, we set $h_{i,j}=H_{i,1}+\delta_{i,j}$.
#### Generation of $v_{i,j}$
1. For each $j\in\\{0,\ldots,29\\}$ and $p\in\\{0,\ldots,M-1\\}$, we independently generate a random integer $V_{j,p}=\mathrm{rand}(1000+D,9000-D)$.
2. For each $i\in\\{0,\ldots,28\\}$ and $j\in\\{0,\ldots,29\\}$, we independently generate a random integer $\gamma_{i,j}=\mathrm{rand}(-D,D)$.
3. If $M=1$, for each $j\in\\{0,\ldots,29\\}$ and $i\in\\{0,\ldots,28\\}$, we set $v_{i,j}=V_{j,0}+\gamma_{i,j}$.
4. If $M=2$, for each $j\in\\{0,\ldots,29\\}$, we generate a random integer $y_j=\mathrm{rand}(1,28)$, and then for each $i\in\\{0,\ldots,y_j-1\\}$, we set $v_{i,j}=V_{j,0}+\gamma_{i,j}$, and for each $i\in\\{y_j,\ldots,28\\}$, we set $v_{i,j}=V_{j,1}+\gamma_{i,j}$.
#### Generation of $s_k$, $t_k$
The vertices $s_k$ and $t_k$ given in the query are chosen uniformly at random among all the vertices.
If the Manhattan distance between $s_k$ and $t_k$ ($|si_k-ti_k|+|sj_k-tj_k|$) is strictly less than 10, we repeat the random selection until the distance becomes at least 10.
Tools
--------
- <a href="https://img.atcoder.jp/ahc003/c1ae4a8996958aa31f5f9d3aa3f51033.zip">Local tester</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
- <a href="https://img.atcoder.jp/ahc003/e7eb814463364c249c93216eee64275.html">Visualizer</a>
- <a href="https://img.atcoder.jp/ahc003/499df4d8fb8c9326c7b718917d14f17a.zip">Inputs</a>: If you don't use the above local tester, you can instead use these 100 inputs (seed 0-99) for local testing. These inputs are different from the actual test cases. The inputs are in the following format, and you can use them by writing a judge program by yourself.
~~~
$h_{0,0}$ $\ldots$ $h_{0,28}$
$\vdots$
$h_{29,0}$ $\ldots$ $h_{29,28}$
$v_{0,0}$ $\ldots$ $v_{0,29}$
$\vdots$
$v_{28,0}$ $\ldots$ $v_{28,29}$
$si_1$ $sj_1$ $ti_1$ $tj_1$ $a_1$ $e_1$
$\vdots$
$si_{1000}$ $sj_{1000}$ $ti_{1000}$ $tj_{1000}$ $a_{1000}$ $e_{1000}$
~~~
#### Example of judge program (pseudo code)
~~~
string query(s, t, prev_result) {
// WRITE YOUR SOLUTION HERE
}
int main() {
if (LOCAL_TEST) {
read_h_v();
}
prev_result = 0;
score = 0.0;
for (int k = 0; k < 1000; k++) {
if (LOCAL_TEST) {
read_s_t_a_e();
} else {
read_s_t();
}
path = query(s, t, prev_result);
print(path);
if (LOCAL_TEST) {
b = compute_path_length(path);
score = score * 0.998 + a / b;
prev_result = round(b * e);
} else {
prev_result = read_result();
}
}
if (LOCAL_TEST) {
print(round(2312311 * score));
}
return 0;
}
~~~
|
type: interactive
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
15
|
algorithmic
|
Problem Statement
You are given a sequence p of length n, which is a permutation of the numbers 1, 2, ..., n.
Your goal is to make the permutation lexicographically as small as possible by performing a specific operation at most 4n times, and then minimize the number of operations needed to reach that.
More specifically, you must do operations to get the lexicographically smallest permutation that's possible after 4n operations, and then you will be scored based on the number of operations needed to reach it.
Your final score will be calculated as the average of 100 * clamp((4 * n - your_operations)/(4 * n - best_operations), 0, 1) across all cases
The Operation
You can cut the sequence into three consecutive non-empty parts and swap the first part with the last part.
Formally, you select two integers x and y that represent the lengths of the prefix and suffix, respectively. These integers must satisfy:
x > 0
y > 0
x + y < n
This splits the sequence into [Prefix | Middle | Suffix]. The operation transforms the sequence to [Suffix | Middle | Prefix].
Input
The first line contains an integer n, the length of the permutation.
The second line contains n space-separated integers, p_1, p_2, ..., p_n.
Output
On the first line, print an integer m, the total number of operations you performed.
On the following m lines, print the two integers x and y you chose for each operation, separated by a space.
Constraints
3 <= n <= 1000
The input sequence p is guaranteed to be a valid permutation.
|
type: default
# The time limit is now 1 second.
time: 1s
memory: 512m
# A custom checker is required for the special scoring.
checker: chk.cc
subtasks:
- score: 100
n_cases: 3
|
150
|
algorithmic
|
Story
--------
Human genetic information is recorded in DNA with a double helix structure and is represented by a very long string consisting of four characters, `A`, `G`, `C`, and `T`.
Recently, alien cells were found in a meteorite.
As a result of research, it was found that the genetic information of this alien is recorded in a <a href="https://en.wikipedia.org/wiki/Torus">torus</a>-shaped material and is represented as an $N\times N$ matrix consisting of eight characters, `A`, `B`, `C`, `D`, `E`, `F`, `G`, and `H`.
Existing devices have failed to read this matrix directly, but they have succeeded in reading many one-dimensional subsequences that are contiguous vertically or horizontally.
Please estimate the matrix based on this information.
Problem Statement
--------
We define that a one-dimensional sequence $b=(b_0, \ldots, b_{k-1})$ is a **subsequence** of a matrix $a=(a_{i,j})_{0\leq i,j\leq N-1}$ if and only if there exists $(i, j)$ satisfying at least one of the following two conditions:
- For all $p=0,\ldots,k-1$, $b_p=a_{i,(j+p)\bmod N}$ holds. (horizontal match)
- For all $p=0,\ldots,k-1$, $b_p=a_{(i+p)\bmod N,j}$ holds. (vertical match)
Note that if the index is greater than or equal to $N$, we take the remainder divided by $N$ (in other words, $a$ is connected at the left and right ends, and the top and bottom ends).
Given $M$ strings $s_1, \ldots, s_M$ consisting of eight characters, `A`, `B`, $\ldots$, `H`, your goal is to find an $N\times N$ matrix consisting of characters `A`, `B`, $\ldots$, `H`, or `.` which contains as many of the given strings as possible as subsequences.
Here, `.` indicates an empty.
Scoring
--------
Let $c$ ($\leq M$) be the number of $i$'s such that $s_i$ is a subsequence of the output matrix, and let $d$ ($\leq N^2$) be the number of `.` contained in the output.
Then, you will obtain the following score.
- If $c<M$, $\mathrm{round}(10^8\times \frac{c}{M})$.
- If $c=M$, $\mathrm{round}(10^8\times \frac{2 N^2}{2 N^2-d})$.
If the output is illegal (not an $N\times N$ matrix, or containing a character other than `A`, `B`, $\ldots$, `H`, `.`), it is judged as `WA`.
There are 100 test cases, and the score of a submission is the total score for each test case.
If you get a result other than `AC` for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest.
If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input
--------
Input is given from Standard Input in the following format:
~~~
$N$ $M$
$s_1$
$\vdots$
$s_M$
~~~
- $N$ is fixed to 20 throughout all the test cases.
- $M$ is an integer satisfying $400\leq M\leq 800$.
- Each $s_i$ is a string consisting of characters `A`, `B`, $\ldots$, `H`, and its length is at least 2 and at most 12.
Output
--------
Output $N$ lines, each containing a string of length exactly $N$ consisting of characters `A`, `B`, $\ldots$, `H`, or `.`.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniformly random integer between $L$ and $U$, inclusive.
We first generate an $N\times N$ matrix $a=(a_{i,j})_{0\leq i,j\leq N-1}$ by generating each element uniformly randomly from `A`, `B`, $\ldots$, `H`.
We then generate a parameter $L=\mathrm{rand}(4, 10)$, which decides the average length of the strings, and the number of strings $M=\mathrm{rand}(400, 800)$.
We generate $M$ strings $s_1,\ldots,s_M$ by repeating the following process $M$ times.
We generate two integers $i=\mathrm{rand}(0, N-1)$ and $j=\mathrm{rand}(0, N-1)$ representing a starting point, an integer $d=\mathrm{rand}(0,1)$ representing a direction, and an integer $k=\mathrm{rand}(L-2, L+2)$ representing the length of the string.
- If $d=0$, we choose a horizontal subsequence $(a_{i,j},a_{i,(j+1)\bmod N},\ldots,a_{i,(j+k-1)\bmod N})$.
- If $d=1$, we choose a vertical subsequence $(a_{i,j},a_{(i+1)\bmod N,j},\ldots,a_{(i+k-1)\bmod N,j})$.
Tools
--------
- <a href="https://img.atcoder.jp/ahc004/a45fa3f18ab177158bf5961b12872f93.zip">Inputs</a>: A set of 100 inputs (seed 0-99) for local testing, including the sample input (seed 0). These inputs are different from the actual test cases.
- <a href="https://img.atcoder.jp/ahc004/a42b6f0655821d8b384b31377108e5512.html">Visualizer on the web</a>
- <a href="https://img.atcoder.jp/ahc004/222362f13a30b1342bf79d0041bd4d39.zip">Input generator and visualizer</a>: If you want to use more inputs, or if you want to visualize your output locally, you can use this program. You need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
151
|
algorithmic
|
Story
--------
To solve the shortage of police officers, the Takahashi City Police Department has decided to introduce automated patrols with unmanned patrol cars.
The unmanned patrol car is equipped with a high-resolution omnidirectional camera on the roof, which can see the entire road at once in a straight line from the current position. And then, it uses image processing technology to automatically detect suspicious activities.
In order to provide a safe and secure life for the citizens, we want to set up a patrol route that allows the patrol car to see every corner of the city at least once.
Among such patrol routes, please find as short a one as possible.
Problem Statement
--------
You are given a map consisting of $N\times N$ squares.
Let $(0,0)$ denote the top-left square, and $(i,j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
Each square is either an obstacle (`#`) or a road, and you can move up, down, left, or right on the road squares.
Each road square contains a number `5`-`9`, which represents the amount of time you take to move from an adjacent square to that square.
We define that a road square $(i',j')$ is visible from $(i,j)$ if and only if the following conditions are satisfied:
- $i=i'$ and for every $j''$ with $\min(j,j')\leq j''\leq\max(j,j')$, $(i,j'')$ is a road square, or
- $j=j'$ and for every $i''$ with $\min(i,i')\leq i''\leq\max(i,i')$, $(i'',j)$ is a road square.
For example, in the figure below, the gray squares represent obstacles, the white and light yellow squares represent roads, and the road squares that are visible from the green circle are colored light yellow.

Your task is to find a route starting from a specified square $(si,sj)$, moving up, down, left, or right on road squares, and returning to $(si,sj)$, such that all the road squares become visible at least once.
The shorter the route, the higher the score.
You can move on the same square multiple times and even make a U-turn.
Scoring
--------
Let $r$ be the total number of road squares, $v$ be the number of road squares that become visible at least once, and $t$ be the total travel time of the output route. Then you will obtain the following score.
- If $v<r$, $\mathrm{round}(10^4\times \frac{v}{r})$.
- If $v=r$, $\mathrm{round}(10^4+10^7\times \frac{N}{t})$.
If the output is illegal (going out of $N\times N$ squares, moving on obstacle squares, or not returning to $(si,sj)$), it will be judged as `WA`.
There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than `AC` for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input
--------
Input is given from Standard Input in the following format:
~~~
$N$ $si$ $sj$
$c_0$
$\vdots$
$c_{N-1}$
~~~
- $N$ is an odd integer between $49$ and $69$, inclusive.
- $si, sj$ are integers satisfying $0\leq si\leq N-1$ and $0\leq sj\leq N-1$.
- Each $c_i$ is a string of length exactly $N$ consisting of characters `5`, `6`, `7`, `8`, `9`, and `#`. The $j$-th character ($0\leq j\leq N-1$) represents the square $(i,j)$ as follows.
- `#` means that the square contains an obstacle. It is guaranteed that $(si, sj)$ does not contain obstacles.
- `5`-`9` show that the square is a road, and the number represents the amount of time you take to move from an adjacent square to that square.
Output
--------
Let `U`, `D`, `L`, and `R` represent the movement from $(i, j)$ to $(i-1,j)$, $(i+1,j)$, $(i,j-1)$, and $(i,j+1)$, respectively.
Output a string representing the route to Standard Output in one line.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniformly random integer between $L$ and $U$, inclusive.
We first generate an odd integer $N=\mathrm{rand}(25, 35)\times 2 - 1$ which represents the size of the map and a parameter $K=\mathrm{rand}(2 N, 4 N)$ which represents the number of roads.
Starting from an initial map where all squares are obstacles, we repeat the following procedure $K$ times.
1. Generate an integer $d=\mathrm{rand}(0, 1)$ representing the direction of the road.
1. Generate two integers $i=\mathrm{rand}(0, (N-1)/2)\times 2$ and $j=\mathrm{rand}(0, N-1)$ representing the center of the road.
1. Generate an integer $h=\mathrm{rand}(3, 10)$ representing the length of the road.
1. Generate an integer $w=\mathrm{rand}(5, 9)$ representing the travel time.
1. For each $k$ with $\max(j-h,0)\leq k\leq \min(j+h,N-1)$, we overwrite square $(i,k)$ when $d=0$ or square $(k,i)$ when $d=1$ with a road square with travel time $w$.
After the repetition, we keep only the largest connected component of road squares and replace the rest with obstacles.
Finally, we select $(si,sj)$ uniformly at random from the road squares.
Tools
--------
- <a href="https://img.atcoder.jp/ahc005/c746dac8cc11fd18c68063546997666e.zip">Inputs</a>: A set of 100 inputs (seed 0-99) for local testing, including the sample input (seed 0). These inputs are different from the actual test cases.
- <a href="https://img.atcoder.jp/ahc005/dc9ed10f037e2dd4b48ca255dbd470d9.html">Visualizer on the web</a>
- <a href="https://img.atcoder.jp/ahc005/dc9ed10f037e2dd4b48ca255dbd470d9.zip">Input generator and visualizer</a>: If you want to use more inputs, or if you want to visualize your output locally, you can use this program. You need a compilation environment of <a href="https://www.rust-lang.org/ja">Rust language</a>.
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
152
|
algorithmic
|
Problem Statement
--------
AtCoder Inc. operates a food delivery service, AtCoder Foods, that leisurely delivers food that tastes good even if it gets cold.
This service receives a large number of delivery orders in advance, and processes multiple deliveries simultaneously to improve efficiency.
The current service area is represented as a square area $\\{(x,y)\mid 0\leq x, y\leq 800\\}$ on a two-dimensional plane, with AtCoder's office located at the center $(400, 400)$.
There are 1000 orders today, and the $i$ ($1\leq i\leq 1000$)-th order is a food delivery request from a restaurant in $(a_i, b_i)$ to a location in $(c_i, d_i)$.
Today's quota for Takahashi, a delivery man, is to process 50 orders.
He can freely choose a subset $S\subseteq\\{1,\cdots,1000\\}$ of size exactly 50 from the 1000 orders and deliver on a route $(x_1,y_1),\cdots,(x_n,y_n)$ satisfying the following conditions.
1. For each $i\in S$, visit $(c_i, d_i)$ after visiting $(a_i,b_i)$. That is, there exists an integer pair $(s, t)$ such that $(x_s,y_s)=(a_i,b_i)$, $(x_t,y_t)=(c_i,d_i)$, and $s<t$.
2. $(x_1,y_1)=(x_n,y_n)=(400, 400)$.
After picking up food at one restaurant, he may pick up food at another restaurant or deliver food to another destination before delivering that food to the destination.
He is so powerful that he can carry arbitrary numbers of dishes simultaneously.
Moving from $(x_i,y_i)$ to $(x_{i+1},y_{i+1})$ takes time equal to the Manhattan distance $|x_i-x_{i+1}|+|y_i-y_{i+1}|$, and
the total travel time for the delivery route is $T=\sum_{i=1}^{n-1} |x_i - x_{i+1}|+|y_i - y_{i+1}|$.
Please optimize $S$ and delivery routes so that the total travel time is as short as possible.
Scoring
--------
For the total travel time $T$ of the output delivery route, you will get a score of $\mathrm{round}(10^8/(1000+T))$.
There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input
--------
Input is given from Standard Input in the following format:
~~~
$a_1$ $b_1$ $c_1$ $d_1$
$\vdots$
$a_{1000}$ $b_{1000}$ $c_{1000}$ $d_{1000}$
~~~
Each $a_i, b_i, c_i, d_i$ is an integer between $0$ and $800$, inclusive, where $(a_i, b_i)$ represents the coordinates of the restaurant, and $(c_i, d_i)$ represents the coordinates of the destination.
$(a_i,b_i)\neq (c_i,d_i)$ is satisfied, but for different orders $j$, there is a possibility that $\\{(a_i,b_i),(c_i,d_i)\\}\cap\\{(a_j,b_j),(c_j,d_j)\\}\neq\emptyset$.
Output
--------
Let the set of chosen orders be $r_1,\cdots,r_m$ ($1\leq r_i\leq 1000$), and the delivery route be $(x_1,y_1),\cdots,(x_n,y_n)$ ($0\leq x_i,y_i\leq 800$), output to Standard Output in the following format.
~~~
$m$ $r_1$ $\cdots$ $r_m$
$n$ $x_1$ $y_1$ $\cdots$ $x_n$ $y_n$
~~~
You may output multiple times for visualization purposes.
If your program outputs multiple times, only the last output will be used for scoring.
The final output must satisfy $m=50$, but intermediate outputs with $m\neq 50$ are allowed for visualization.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.
For each $i=1,\cdots,1000$, we generate an order $(a_i, b_i, c_i, d_i)$ as follows.
We generate $a_i=\mathrm{rand}(0, 800)$, $b_i=\mathrm{rand}(0, 800)$, $c_i=\mathrm{rand}(0, 800)$, and $d_i=\mathrm{rand}(0, 800)$.
Redo the generation as long as the Manhattan distance $|a_i-c_i|+|b_i-d_i|$ is less than 100.
Tools (Input generator and visualizer)
--------
- <a href="https://img.atcoder.jp/ahc006/c21daebb77aa4d38d65f4d7f7c7249.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
- <a href="https://img.atcoder.jp/ahc006/c21daebb77aa4d38d65f4d7f7c7249.html">Web version</a>: This is more powerful than the local version and can display animations.
**Sharing visualization results is not allowed until the end of the contest. **
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
153
|
algorithmic
|
Story
--------
AtCoder, a big tech company, has many offices.
In order to securely share super-secret information of problem statements for future contests, we decided to set up private lines using quantum cryptography between the offices.
There are several candidates for office pairs that can be connected by private lines, and we want to make sure that all offices are connected by private lines.
The cost of setting up a private line is proportional to the length of the line, but due to physical limitations, it is not always possible to set up a straight line, so we have asked vendors to estimate the exact cost for each candidate.
Since CEO Takahashi is impatient, once he receives the estimate for one candidate, he immediately decides whether to set up that line or not.
Please support Takahashi and help him achieve his goal at a lower cost as possible.
Problem Statement
--------
You are given an undirected graph with $N$ vertices and $M$ edges.
Each vertex is on a two-dimensional plane, and the coordinates of the $i$-th vertex is $(x_i, y_i)$.
The $i$-th edge connects vertices $u_i$ and $v_i$, and we know in advance that its length $l_i$ satisfies $d_i \leq l_i \leq 3 d_i$, where $d_i=\mathrm{round}(\sqrt{(x_{u_i}-x_{v_i})^2+(y_{u_i}-y_{v_i})^2})$ is the Euclidean distance between the endpoints rounded to the nearest integer.
The true edge length $l_i$ will be given one by one in order from $i=0$ to $i=M-1$.
After receiving the length $l_i$ of the $i$-th edge, you have to decide whether to adopt that edge or not before receiving the length $l_{i+1}$ of the next edge.
Let $S$ be the set edges you eventually adopt, then for every vertex pair $(u,v)$, $S$ must contain a path between $u$ and $v$.
Please make decisions so that the total length of the adopted edges is as short as possible.
Input and Output
--------
For all test cases, we fix $N=400$ and $M=1995$.
At the start of the execution, the coordinates of $N$ vertices $(x_0,y_0), \cdots, (x_{N-1},y_{N-1})$ and the endpoints of $M$ edges $(u_0,v_0), \cdots, (u_{M-1},v_{M-1})$ are given from Standard Input in the following format.
~~~
$x_0$ $y_0$
$\vdots$
$x_{N-1}$ $y_{N-1}$
$u_0$ $v_0$
$\vdots$
$u_{M-1}$ $v_{M-1}$
~~~
It is guaranteed to satisfy the following.
- $0\leq x_i,y_i\leq 800$
- $0\leq u_i<v_i\leq N-1$
- The same $(u_i,v_i)$ pair never appears more than once.
- The graph is connected.
Then, repeat the following process $M$ times.
In the $i$-th ($0\leq i\leq M-1$) process, the length $l_i$ of the $i$-th edge is generated uniformly at random from integers between $d_i$ and $3 d_i$, and given to Standard Input in a single line.
After reading $l_i$, output `1` if you adopt the $i$-th edge, or `0` if you don't, in one line to Standard Output.
<font color="red">**Note that the next input is not given until your program outputs 0 or 1. After the output, you have to flush Standard Output.**</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> .
Example
-----------------
<table class="table table-bordered">
<thead>
<tr>
<th align="left">$i$</th>
<th align="left">Input</th>
<th align="left">Output</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Prior information</td>
<td align="left"><pre>
406 19
347 786
$\vdots$
21 191
</pre></td>
<td align="left"></td>
<tr>
<td align="left">$0$</td>
<td align="left"><pre>69</pre></td>
<td align="left"><pre>1</pre></td>
</tr>
<tr>
<td align="left">$1$</td>
<td align="left"><pre>89</pre></td>
<td align="left"><pre>0</pre></td>
</tr>
<tr>
<td align="center" colspan="3">$\vdots$</td>
</tr>
<tr>
<td align="left">$M-1$</td>
<td align="left"><pre>175</pre></td>
<td align="left"><pre>0</pre></td>
</tr>
</tbody>
</table>
Scoring
--------
Let $A$ be the total length of the set of adopted edges,
$B$ be the total length of the optimal set of edges under the condition that the true length $l_i$ of every edge is known in advance (<a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree">minimum spanning tree</a>).
Then, you will get a score of $\mathrm{round}(10^8\times B/A)$.
When the set of adopted edges does not make the graph connected, your submission will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span>.
Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>.
There are 150 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.
#### Generation of $(x_i,y_i)$
For each $i=0,\cdots,N-1$, we generate $x_i=\mathrm{rand}(0,800)$ and $y_i=\mathrm{rand}(0,800)$.
If the Euclidean distance to the coordinates $(x_j,y_j)$ of an already generated vertex $(j<i)$ is less than or equal to $5$, we regenerate $(x_i,y_i)$.
#### Generation of $(u_i,v_i)$
Let $G$ be a complete graph with edge length $\mathrm{round}(\sqrt{(x_i-x_j)^2+(y_i-y_j)^2})$ between vertex $i$ and $j$.
By repeating the following process $5$ times, we generate a set $E$ of $M=5(N-1)$ edges.
> We compute a minimum spanning tree $T$ of $G$, and remove all edges in $T$ from $G$ and insert them to $E$.
Finally, by randomly shuffling the order of edges in $E$, we generate the list of edges $(u_0,v_0),\cdots,(u_{M-1},v_{M-1})$.
#### Generation of $l_i$
Let $d_i=\mathrm{round}(\sqrt{(x_{u_i}-x_{v_i})^2+(y_{u_i}-y_{v_i})^2})$ be the Euclidean distance between the endpoints rounded to the nearest integer.
Then we generate $l_i=\mathrm{rand}(d_i,3 d_i)$.
Tools (Input generator and visualizer)
--------
- <a href="https://img.atcoder.jp/ahc007/a855b6a456c9892b747e147001b0f89.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
- <a href="https://img.atcoder.jp/ahc007/a855b6a456c9892b747e147001b0f89.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
<font color="red">You are allowed to share output images (png or gif) of the provided visualizer for seed=0 on twitter during the contest.</font> You have to use the specified hashtag and public account. <a href="https://twitter.com/search?q=%23AHC007%20%23visualizer&src=typed_query&f=live">List of shared images.</a>
|
type: interactive
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
154
|
algorithmic
|
Story
--------
AtCoder's CEO, Takahashi, loves animals and has a number of pets running free in the AtCoder office.
AtCoder's employees have trouble with the pets interrupting their work, so they have decided to place partitions in the office to create a space where pets cannot come in.
Please create as large a space as possible.
Problem Statement
--------
There are $N$ pets and $M$ people in a room with a floor of $30 \times 30$ squares.
All squares are initially passable, and outside of the $30 \times 30$ squares are impassable.
Let $(x, y)$ be the coordinates of the square in row $x$ from the top ($1\leq x\leq 30$) and column $y$ from the left ($1\leq y\leq 30$).
Repeat the following process for $300$ turns.
First, you choose each person's action from the following three types, and perform each action simultaneously.
- Do nothing and stay in the current position.
- Choose a square adjacent to the current position and make it impassable. You cannot choose a square that contains pets or humans at the start of this turn. <b>You cannot choose a square whose adjacent square contains a pet, either.</b> If you choose a square that is already impassable, nothing happens.
- Move to an adjacent passable square. It is not possible to move to a square that becomes impassable by another person's action in this turn.
After all the people have completed their actions for that turn, each pet moves independently.
Rules for pet movement depend on the type of pet, and some pets may move multiple squares in a single turn.
Details are described later.
Squares containing humans or pets are also passable, and each square can contain any number of humans and pets.
Scoring
--------
At the end of $300$ turn, for each $i=1,\cdots,M$, let $R_i$ be the set of squares reachable from the final position of person $i$ through only passable squares, and $n_i$ be the number of pets whose final position is in $R_i$.
Then, person $i$ obtains satisfaction of $s_i=\frac{|R_i|}{900}\times 2^{-n_i}$.
The score for the test case is $\mathrm{round}\left(10^8\times\frac{1}{M}\sum_{i=1}^M s_i\right)$.
#### Number of test cases
- Provisional test: 100
- System test: 2000. We will publish <a href="https://img.atcoder.jp/ahc008/seeds.txt">seeds.txt</a> (md5=27bf0702bbe0265900374c3b6b9846b4, sha256=33973e4ded08e3a607fc2e841e14751ff110ae10154b286e7fd5f766ff86d706) after the contest is over.
The score of a submission is the total scores for each test case.
In the provisional test, if your submission produces illegal output or exceeds the time limit for some test cases, the submission itself will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> or <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> , and the score of the submission will be zero.
In the system test, if your submission produces illegal output or exceeds the time limit for some test cases, only the score for those test cases will be zero.
Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>.
#### About execution time
Execution time may vary slightly from run to run.
In addition, since system tests simultaneously perform a large number of executions, it has been observed that execution time increases by several percent compared to provisional tests.
For these reasons, submissions that are very close to the time limit may result in <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Time Limit Exceeded">TLE</span> in the system test.
Please measure the execution time in your program to terminate the process, or have enough margin in the execution time.
Input and Output
--------
First, the initial position and type of each pet, and the initial position of each person are given from Standard Input in the following format
~~~
$N$
$px_1$ $py_1$ $pt_1$
$\vdots$
$px_N$ $py_N$ $pt_N$
$M$
$hx_1$ $hy_1$
$\vdots$
$hx_M$ $hy_M$
~~~
$N$ is an integer between $10$ and $20$ representing the number of pets.
$(px_i,py_i)$ represents the coordinates of the initial position of the $i$-th pet, and $pt_i$ is an integer between $1$ and $5$ representing the type of the $i$-th pet.
$M$ is an integer between $5$ and $10$ representing the number of humans.
$(hx_i,hy_i)$ represents the coordinates of the initial position of the $i$-th human.
The initial positions of all pets and humans are guaranteed to be distinct.
After reading the above information, repeat the following process $300$ turns.
First, output a string of length $M$ where the $i$-th character represents the action of the $i$th person as follows on a single line to Standard Output.
<font color="red">**After the output, you have to flush Standard Output.**</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' tit
le="Time Limit Exceeded">TLE</span> .
- `.`: Do nothing and stay in the current position.
- `u`, `d`, `l`, `r`: Let $(x,y)$ be the current position. Make the square $(x-1,y)$, $(x+1,y)$, $(x,y-1)$, or $(x,y+1)$ impassable, respectively.
- `U`, `D`, `L`, `R`: Let $(x,y)$ be the current position. Move to the the square $(x-1,y)$, $(x+1,y)$, $(x,y-1)$, or $(x,y+1)$, respectively.
After the output, $N$ strings are given to Standard Input in a single line, separated by spaces.
The $i$-th string represents movement of the $i$-th pet in that turn.
If the pet does not move, the string is `.`.
If it does move, the string is a sequence of characters `U`, `D`, `L`, and `R` representing the movement of one square up, down, left, and right, respectively.
<a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en&show=example">Show example</a>
Pets Movement Rules
--------
We define a basic move as follows: move to a square chosen at random among the adjacent passable squares. From the condition of the squares that can be made impassable, such squares always exist.
Each pet $i$ performs the following moves depending on $pt_i$, an integer value between $1$ and $5$ representing its type.
1. <img src="./images/cow.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Cow: Perform one basic move.
2. <img src="./images/pig.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Pig: Perform two basic moves.
3. <img src="./images/rabbit.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Rabbit: Perform three basic moves.
4. <img src="./images/dog.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Dog: Move toward a target person as follows. The first turn starts with no target. If it has no target, the target person is in the current position, or there exists no path to the target person, then it selects one person uniformly at random among those reachable from the current position, excluding those in the current position. If there is no such person, reset to no target and perform one basic move. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target person (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target.
5. <img src="./images/cat.png" width="30" height="30" style="background-color:silver;image-rendering:pixelated"> Cat: Move toward a target square as follows. The first turn starts with no target. If it has no target or there exists no path to the target square, then it selects one square uniformly at random among those reachable from the current position, excluding the current position. If there exists no such square, do nothing. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target square (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target.
Input Generation
--------
Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.
We generate the number of pets by $N=\mathrm{rand}(10, 20)$.
The initial position of each pet is chosen uniformly at random from the coordinates that have not been chosen yet.
We generate the type of each pet by $pt_i=\mathrm{rand}(1, 5)$.
We generate the number of humans by $M=\mathrm{rand}(5, 10)$.
The initial position of each human is chosen uniformly at random from the coordinates that have not been chosen yet.
Tools
--------
- <a href="https://img.atcoder.jp/ahc008/tools_v3.zip">Local tester</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
- For those who are not familiar with the Rust language environment, we have prepared a pre-compiled binary for Windows. <a href="https://img.atcoder.jp/ahc008/tools_x86_64-pc-windows-gnu_v3.zip">tools_x86_64-pc-windows-gnu.zip</a>
- <font color="red">The first version contained a bug in the cat's movement, which has been fixed at 130 minutes after the contest started. Please re-download it.</font>
- We have added more examples in README. If you don't know how to use the tools, please refer to README. Also, as stated in the rules, you are free to share information on how to run the provided tools.
- <a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en">Web visualizer</a>: By pasting the output generated by the local tester into the Output field, you can display the animation of the execution result.
<font color="red">You are allowed to share output images (png or gif) of the provided visualizer for seed=0 on twitter during the contest.</font> You have to use the specified hashtag and public account. You can only share visualization results and scores for seed=0. Do not share scores for other seeds or mention solutions or discussions. <a href="https://twitter.com/search?q=%23AHC008%20%23visualizer&src=typed_query&f=live">List of shared images.</a>
#### Specification of input/output files used by the tools
Input files for the local tester consist of the prior information (the initial position and type of each pet, and the initial position of each person) followed by a random seed value to generate pet movements.
Since the pet's movement depends on human actions, the input file contains only the random seed value and not specific movements.
The local tester writes outputs from your program directly to the output file.
Your program may output comment lines starting with `#`.
The web version of the visualizer displays the comment lines at the time they are output, which may be useful for debugging and analysis.
Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is.
|
type: interactive
interactor: interactor.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
155
|
algorithmic
|
Story
--------
A map like in the figure below is given.
Takahashi's home is located in the square with the red circle, and AtCoder's office is located in the square with the blue circle.
He memorizes his commuting route to the office as a string of characters such as DRDR, which means Down, Right, Down, and Right.
Because he is quite forgetful, he sometimes forgets some parts of the string he has memorized.
For example, if he forgets the third character, he will move down, right, and right, and will be lost without reaching the office.
Therefore, he decided to memorize a robust string that would allow him to reach the office with a high probability even if he forgets some parts of the string.
For example, if he memorizes a string DRDRDR, he can reach the office even if he forgets any one of the characters.
Your task is to find a string that will allow Takahashi to reach the office quickly and with a high probability.
<table>
<tr>
<td>
<figure style="text-align:center">
<img src="./images/f29506fb2_1.svg">
<figcaption>DRDR</figcaption>
</figure>
</td>
<td>
<figure style="text-align:center">
<img src="./images/f29506fb2_2.svg">
<figcaption>DR<del>D</del>R</figcaption>
</figure>
</td>
<td>
<figure style="text-align:center">
<img src="./images/f29506fb2_3.svg">
<figcaption>DR<del>D</del>RDR</figcaption>
</figure>
</td>
</tr>
</table>
Problem Statement
--------
You are given a map consisting of $20\times 20$ squares.
The outside of the map is surrounded by walls.
There may also be walls between adjacent squares.
Let $(0,0)$ denote the top-left square, and $(i,j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
Takahashi's home is located at $(s_i, s_j)$ and AtCoder's office is located at $(t_i, t_j)$.
By representing up, down, left, and right movements as `U`, `D`, `L`, and `R`, respectively, output a commuting route from the home to the office as a string of length less than or equal to $200$.
Let $L$ be the length of the output string.
Starting from the home, Takahashi will do the following action in each $t=1,\cdots,L$ turn.
- With constant probability $p$, he cannot recall the $t$-th character and stays in the current square.
- With the remaining probability $1-p$, he moves one square in the direction represented by the $t$-th character. If there is a wall in that direction, he stays in the current square.
When he gets to the office, he immediately terminate the move.
Scoring
--------
Let $S$ be a random variable defined as $S=401-t$ if he gets to the office after $t$ turns of actions and $S=0$ if he fails to get to the office, and compute its expected value, $E[S]$.
Then, you will get a score of $\mathrm{round}(250000\times E[S])$.
If your output is invalid (the length exceeds 200 or contains characters other than `U`, `D`, `L`, and `R`), it will be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span>.
There are 100 test cases, and the score of a submission is the total score for each test case. If you get a result other than <span class='label label-success' data-toggle='tooltip' data-placement='top' title="Accepted">AC</span> for one or more test cases, the score of the submission will be zero. The highest score obtained during the contest time will determine the final ranking, and there will be no system test after the contest. If more than one participant gets the same score, the ranking will be determined by the submission time of the submission that received that score.
Input
--------
Input is given from Standard Input in the following format:
~~~
$s_i$ $s_j$ $t_i$ $t_j$ $p$
$h_{0,0}$ $\cdots$ $h_{0,18}$
$\vdots$
$h_{19,0}$ $\cdots$ $h_{19,18}$
$v_{0,0}$ $\cdots$ $v_{0,19}$
$\vdots$
$v_{18,0}$ $\cdots$ $v_{18,19}$
~~~
The coordinates of the home and the office satisfy $0\leq s_i\leq 4$, $0\leq s_j\leq 4$, $15\leq t_i\leq 19$, and $15\leq t_j\leq 19$.
$p$ is a real number representing the probability of forgetting each character and satisfies $0.1\leq p\leq 0.5$.
$h_{i,0}$ $\cdots$ $h_{i,18}$ is a string of $19$ characters consisting of only $0$ or $1$.
If there is a wall between the squares $(i,j)$ and $(i,j+1)$, then $h_{i,j}=1$, otherwise $h_{i,j}=0$.
$v_{i,0}$ $\cdots$ $v_{i,19}$ is a string of $20$ characters consisting of only $0$ or $1$.
If there is a wall between the squares $(i,j)$ and $(i+1,j)$, then $v_{i,j}=1$, otherwise $v_{i,j}=0$.
It is guaranteed that all squares are reachable from the home.
Output
--------
Output a string that Takahashi memorizes in one line to Standard Output.
<a href="https://img.atcoder.jp/ahc009/cf3f791aac0f80374c60.html?lang=en&show=example">Show example</a>
Input Generation
--------
<details>
Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive.
#### Generation of $(s_i, s_j)$, $(t_i, t_j)$, and $p$
We generate $s_i=\mathrm{rand}(0, 4)$, $s_j=\mathrm{rand}(0, 4)$, $t_i=\mathrm{rand}(15, 19)$, $t_j=\mathrm{rand}(15, 19)$, and $p=\mathrm{rand}(10, 50) / 100$.
#### Generation of $h_{i,j}$ and $v_{i,j}$
Let $[k]=\\{0,1,\cdots,k-1\\}$.
Let $G=(V,E)$ be a grid graph such that $V=[20]\times[20]$ and $E=\\{\\{(i,j),(i,j+1)\\}\mid i\in[20],j\in[19]\\}\cup\\{\\{(i,j),(i+1,j)\\}\mid i\in[19],j\in[20]\\}$.
We generate two spanning trees $G_r=(V,E_r)$ $(r=1,2)$ of $G$ by performing the following process twice independently.
1. First, we randomly shuffle the edges $E$ and obtain an ordered edge list $e_0,\cdots,e_{759}$.
2. Starting from $E_r=\emptyset$, for each $e_k=\\{(i,j),(i',j')\\}$ in order from $k=0$ to $k=759$, we insert $e_k$ into $E_r$ if $(i,j)$ and $(i',j')$ are not connected in $G_r$.
Using the obtained two spanning trees, we generate $h$ and $v$ as follows.
- $h_{i,j}=0 \iff \\{(i,j),(i,j+1)\\}\in E_1\cup E_2$
- $v_{i,j}=0 \iff \\{(i,j),(i+1,j)\\}\in E_1\cup E_2$
</details>
Tools (Input generator and visualizer)
--------
- <a href="https://img.atcoder.jp/ahc009/cf3f791aac0f80374c60.html?lang=en">Web version</a>: This is more powerful than the local version and can display animations.
- <a href="https://img.atcoder.jp/ahc009/cf3f791aac0f80374c60.zip">Local version</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>.
- <a href="https://img.atcoder.jp/ahc009/cf3f791aac0f80374c60_windows.zip">Pre-compiled binary for Windows</a>: If you are not familiar with the Rust language environment, please use this instead.
<font color="red">**Sharing visualization results is not allowed until the end of the contest. **</font>
{sample example}
|
type: default
checker: chk.cc
# Time and memory limits still apply to the contestant's solution
time: 10s
memory: 256m
# The subtasks section works the same way
subtasks:
- score: 100
n_cases: 3
|
Evolving Challenges for Evolving Intelligence
What is Frontier-CS?
Frontier-CS is an unsolved, open-ended, verifiable, and diverse benchmark for evaluating AI on challenging computer science problems.
Think of it as an "exam" for AI, but instead of easy textbook questions, we give problems that are genuinely difficult: ones that researchers struggle with, that have no known optimal solutions, or that require deep expertise to even attempt.
Why Frontier-CS?
Current benchmarks are becoming too easy. Models score 90%+ on many existing coding benchmarks, but that doesn't mean they can actually do useful research or solve real-world engineering challenges.
Frontier-CS is different:
| Traditional Benchmarks | Frontier-CS | |
|---|---|---|
| Difficulty | Often saturated with evolving intelligence | Unsolved: no solution has achieved perfect scores |
| Problems | Textbook-style, known solutions | Open-ended research & optimization challenges |
| Evaluation | Binary pass-or-fail | Verifiable continuous scoring, always room to improve |
| Scope | Usually one domain | Diverse: systems, ML, algorithms, security, and more |
Leaderboard → | Browse example problems at frontier-cs.org
Getting Started
Installation
git clone https://github.com/FrontierCS/Frontier-CS.git
cd Frontier-CS
# Install dependencies (using uv, recommended)
uv sync
# Or with pip:
pip install -e .
Try it yourself
Here's Algorithmic Problem 0 - try to beat GPT-5!
# Start the judge server
cd algorithmic && docker compose up -d
# Run the example solution (Human Expert Solution)
frontier-eval --algorithmic 0 problems/0/examples/reference.cpp
# Run the example solution (GPT-5 Thinking Solution)
frontier-eval --algorithmic 0 problems/0/examples/gpt5.cpp
# Try you own solution!
frontier-eval --algorithmic 0 <your_solution.cpp>
Research Problems
# List all problems
frontier-eval --list
# Evaluate a generated solution locally for flash_attn problem (requires Docker)
frontier-eval flash_attn <your_solution.py>
# Evaluate on cloud (requires SkyPilot)
frontier-eval flash_attn <your_solution.py> --skypilot
See research/README.md for full documentation.
Algorithmic Problems
# Start the judge server
cd algorithmic && docker compose up -d
# Evaluate a solution
frontier-eval --algorithmic 1 <your_solution.cpp>
Raw Score
Frontier-CS supports unbounded scoring for algorithmic problems, enabling open-ended evaluation compatible with algorithm evolution frameworks such as OpenEvolve.
# Get unbounded score (without clipping to 100)
frontier-eval --algorithmic --unbounded 1 <your_solution.cpp>
Note
- We currently support C++17 only for algorithmic problem solutions.
- Reference solutions and hidden tests are withheld; full evaluation and leaderboard inclusion require submission.
See algorithmic/README.md for full documentation.
Python API
from frontier_cs import FrontierCSEvaluator
evaluator = FrontierCSEvaluator()
# Evaluate a research problem
result = evaluator.evaluate("research", problem_id="flash_attn", code=my_code)
print(f"Score: {result.score}")
# Evaluate an algorithmic problem
result = evaluator.evaluate("algorithmic", problem_id=1, code=cpp_code)
print(f"Score: {result.score}")
# Get unbounded score for algorithmic problems
result = evaluator.evaluate("algorithmic", problem_id=1, code=cpp_code, unbounded=True)
print(f"Score (bounded): {result.score}")
print(f"Score (unbounded): {result.score_unbounded}")
Submitting Results
We release partial test cases so you can develop and debug locally. For full evaluation and leaderboard inclusion, submit your solutions to [email protected], or [email protected], or [email protected] following the instructions in SUBMIT.md.
Questions? Join our Discord
Acknowledgments
Some problems are adapted from ALE-bench and AI-Driven Research for Systems (ADRS).
Citing Us
If you use Frontier-CS in your research, please cite:
- Downloads last month
- -