problem_id stringlengths 5 6 | url stringlengths 48 49 | title stringlengths 2 46 | rating int64 800 3.5k | tags listlengths 1 11 | div stringclasses 16
values | time_limit_ms int64 1k 13k | memory_limit_mb int64 32 1.02k | description stringlengths 67 2.52k | input stringlengths 99 1.93k ⌀ | output stringlengths 47 1.35k ⌀ | examples listlengths 1 5 | note stringlengths 0 1.68k | prompt stringlengths 505 6.96k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2038A | https://codeforces.com/problemset/problem/2038/A | Bonus Project | 1,400 | [
"games",
"greedy"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | There is a team of $$$n$$$ software engineers numbered from $$$1$$$ to $$$n$$$. Their boss promises to give them a bonus if they complete an additional project. The project requires $$$k$$$ units of work in total. The bonus promised to the $$$i$$$-th engineer is $$$a_i$$$ burles. The boss doesn't assign specific tasks ... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 1000$$$; $$$1 \le k \le 10^6$$$) — the number of engineers in the company and the number of work units the project requires, respectively.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a... | Print $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$0 \le c_i \le k$$$) — the amount of work completed by each engineer given that every engineer behaves optimally. Note that the answer is unique. | [
[
"3 6\n4 7 6\n1 2 3",
"1 3 2"
],
[
"3 12\n4 7 6\n1 2 3",
"0 0 0"
],
[
"3 11\n6 7 8\n1 2 3",
"6 3 2"
]
] | In the first example, engineers distributed the work across them and got the bonus, even though the benefit for the third engineer is zero.
In the second example, the bonus project requires too many work units to complete, so it's more beneficial for engineers not to work at all. | Title: Bonus Project
time_limit_ms: 2000
memory_limit_mb: 512
Description: There is a team of $$$n$$$ software engineers numbered from $$$1$$$ to $$$n$$$. Their boss promises to give them a bonus if they complete an additional project. The project requires $$$k$$$ units of work in total. The bonus promised to the $$$i$... |
2038B | https://codeforces.com/problemset/problem/2038/B | Make It Equal | 2,100 | [
"greedy",
"brute force",
"binary search",
"math"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | You are given an integer array $$$a$$$ of size $$$n$$$. The elements of the array are numbered from $$$1$$$ to $$$n$$$.
You can perform the following operation any number of times (possibly, zero): choose an index $$$i$$$ from $$$1$$$ to $$$n$$$; decrease $$$a_i$$$ by $$$2$$$ and increase $$$a_{(i \bmod n) + 1}$$$ by ... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
... | For each test case, print a single integer — the minimum number of operations you have to perform. If it is impossible to make all elements of the array equal, print -1. | [
[
"3\n2\n1 1\n3\n1 3 2\n4\n2 1 2 6",
"0\n-1\n3"
]
] | Title: Make It Equal
time_limit_ms: 2000
memory_limit_mb: 512
Description: You are given an integer array $$$a$$$ of size $$$n$$$. The elements of the array are numbered from $$$1$$$ to $$$n$$$.
You can perform the following operation any number of times (possibly, zero): choose an index $$$i$$$ from $$$1$$$ to $$$n$$... | |
2038C | https://codeforces.com/problemset/problem/2038/C | DIY | 1,400 | [
"data structures",
"geometry",
"greedy",
"sortings"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | You are given a list of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You need to pick $$$8$$$ elements from the list and use them as coordinates of four points. These four points should be corners of a rectangle which has its sides parallel to the coordinate axes. Your task is to pick coordinates in such a way that the... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 25\,000$$$) — the number of test cases.
The first line of each test case contains one integer $$$n$$$ ($$$8 \le n \le 2 \cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$).
Ad... | For each test case, print the answer as follows:
- if it is impossible to construct a rectangle which meets the constraints from the statement, print a single line containing the word NO (case-insensitive);
- otherwise, in the first line, print YES (case-insensitive). In the second line, print $$$8$$$ integers $$$x_1,... | [
[
"3\n16\n-5 1 1 2 2 3 3 4 4 5 5 6 6 7 7 10\n8\n0 0 -1 2 2 1 1 3\n8\n0 0 0 0 0 5 0 5",
"YES\n1 2 1 7 6 2 6 7\nNO\nYES\n0 0 0 5 0 0 0 5"
]
] | Title: DIY
time_limit_ms: 2000
memory_limit_mb: 512
Description: You are given a list of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You need to pick $$$8$$$ elements from the list and use them as coordinates of four points. These four points should be corners of a rectangle which has its sides parallel to the coordin... | |
2038D | https://codeforces.com/problemset/problem/2038/D | Divide OR Conquer | 2,400 | [
"dp",
"binary search",
"implementation",
"data structures",
"bitmasks"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 3,000 | 512 | You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers between $$$0$$$ and $$$10^9$$$. You have to split this array into several segments (possibly one) in such a way that each element belongs to exactly one segment.
Let the first segment be the array $$$[a_{l_1}, a_{l_1 + 1}, \ldots, a_{r_1}]$$$, ... | The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10 ^9$$$) — the elements of the given array. | Print one integer — the number of ways to split the array, taken modulo $$$998\,244\,353$$$. | [
[
"3\n1 2 3",
"4"
],
[
"5\n1000 1000 1000 1000 1000",
"16"
],
[
"3\n3 4 6",
"3"
]
] | In the first two examples, every way to split the array is valid.
In the third example, there are three valid ways to split the array:
- $$$k = 3$$$; $$$l_1 = 1, r_1 = 1, l_2 = 2, r_2 = 2, l_3 = 3, r_3 = 3$$$; the resulting arrays are $$$[3]$$$, $$$[4]$$$, $$$[6]$$$, and $$$3 \le 4 \le 6$$$;
- $$$k = 2$$$; $$$l_1 = 1... | Title: Divide OR Conquer
time_limit_ms: 3000
memory_limit_mb: 512
Description: You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers between $$$0$$$ and $$$10^9$$$. You have to split this array into several segments (possibly one) in such a way that each element belongs to exactly one segment.
Let... |
2038G | https://codeforces.com/problemset/problem/2038/G | Guess One Character | 1,900 | [
"constructive algorithms",
"interactive",
"implementation"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.stdout.flush().
The jury has a string $$$s$$$ consisting of characters 0 and/or 1. ... | null | null | [
[
"3 // 3 test cases\n3 // the length of the string is 3\n\n1 // 101 occurs once\n\n1 // guessed correctly\n2 // the length of the string is 2\n\n0 // 00 occurs zero times\n\n0 // 0 occurs zero times\n\n1 // guessed correctly\n2 // the length of the string is 2\n\n1 // 1 ... | In the example, there are $$$3$$$ test cases: 101, 11 and 10. Note that everything after the // sign is a comment that explains which line means what in the interaction. The jury program won't print these comments in the actual problem, and you shouldn't print them. The empty lines are also added for your convenience, ... | Title: Guess One Character
time_limit_ms: 2000
memory_limit_mb: 512
Description: This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout) or cout.flush(), in Java or Kotlin — System.out.flush(), and in Python — sys.std... |
2038J | https://codeforces.com/problemset/problem/2038/J | Waiting for... | 800 | [
"greedy",
"implementation"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | Monocarp is waiting for a bus at the bus stop. Unfortunately, there are many people who want to ride a bus too.
You are given a list of events of two types:
- B $$$b_i$$$ — a bus with $$$b_i$$$ free seats arrives at the stop;
- P $$$p_i$$$ — $$$p_i$$$ people arrive at the stop.
These events are listed in a chronolog... | The first line contains one integer $$$n$$$ $$$(1 \le n \le 10^3)$$$ — the number of events.
Then, $$$n$$$ lines follow. The $$$i$$$-th of them contains the description of the $$$i$$$-th event in one of the two following formats:
- B $$$b_i$$$ ($$$1 \le b_i \le 10^6$$$) — a bus with $$$b_i$$$ free seats arrives at th... | For each event of type B, print YES if it is possible for Monocarp to take the corresponding bus, or NO otherwise (case-insensitive). | [
[
"10\nP 2\nP 5\nB 8\nP 14\nB 5\nB 9\nB 3\nP 2\nB 1\nB 2",
"YES\nNO\nNO\nYES\nNO\nYES"
]
] | Title: Waiting for...
time_limit_ms: 2000
memory_limit_mb: 512
Description: Monocarp is waiting for a bus at the bus stop. Unfortunately, there are many people who want to ride a bus too.
You are given a list of events of two types:
- B $$$b_i$$$ — a bus with $$$b_i$$$ free seats arrives at the stop;
- P $$$p_i$$$ — ... | |
2038K | https://codeforces.com/problemset/problem/2038/K | Grid Walk | 2,100 | [
"brute force",
"dp",
"math",
"number theory",
"greedy"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | You have an $$$n \times n$$$ grid and two integers $$$a$$$ and $$$b$$$. Both the rows and the columns are numbered from $$$1$$$ to $$$n$$$. Let's denote the cell at the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.
You are standing in the cell $$$(1, 1)$$$ and want to move into the cell... | The only line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$2 \le n \le 10^6$$$; $$$1 \le a, b \le 10^6$$$). | Print one integer — the cost of the cheapest route from $$$(1, 1)$$$ to $$$(n, n)$$$. | [
[
"4 2 4",
"21"
],
[
"10 210 420",
"125"
]
] | The first example is described in the picture above. | Title: Grid Walk
time_limit_ms: 2000
memory_limit_mb: 512
Description: You have an $$$n \times n$$$ grid and two integers $$$a$$$ and $$$b$$$. Both the rows and the columns are numbered from $$$1$$$ to $$$n$$$. Let's denote the cell at the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.
Y... |
2038L | https://codeforces.com/problemset/problem/2038/L | Bridge Renovation | 1,400 | [
"brute force",
"dp",
"math",
"two pointers",
"greedy"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 512 | Recently, Monocarp started working as a director of a park located near his house. The park is quite large, so it even has a small river splitting it into several zones. Several bridges are built across this river. Three of these bridges are especially old and need to be repaired.
All three bridges have the same lengt... | The first and only line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of planks required for each of the three bridges. | Print a single integer — the minimum number of planks of standard length ($$$60$$$ units) Monocarp needs to cover all three bridges if the planks can be cut into parts. | [
[
"1",
"2"
],
[
"3",
"4"
],
[
"1000",
"1167"
]
] | In the first example, it is possible to cut one plank of length $$$60$$$ into three planks with lengths $$$25$$$, $$$18$$$ and $$$17$$$, and cut another plank of length $$$60$$$ into two planks with lengths $$$39$$$ and $$$21$$$. That way, Monocarp will have all the required planks. | Title: Bridge Renovation
time_limit_ms: 2000
memory_limit_mb: 512
Description: Recently, Monocarp started working as a director of a park located near his house. The park is quite large, so it even has a small river splitting it into several zones. Several bridges are built across this river. Three of these bridges are... |
2042A | https://codeforces.com/problemset/problem/2042/A | Greedy Monocarp | 800 | [
"greedy",
"sortings"
] | Div. 2 | 2,000 | 512 | There are $$$n$$$ chests; the $$$i$$$-th chest initially contains $$$a_i$$$ coins. For each chest, you can choose any non-negative ($$$0$$$ or greater) number of coins to add to that chest, with one constraint: the total number of coins in all chests must become at least $$$k$$$.
After you've finished adding coins to ... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each test case consists of two lines:
- the first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 50$$$; $$$1 \le k \le 10^7$$$);
- the second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1... | For each test case, print one integer — the minimum number of coins you have to add so that, when Monocarp stops taking the chests, he has exactly $$$k$$$ coins. It can be shown that under the constraints of the problem, it is always possible. | [
[
"4\n5 4\n4 1 2 3 2\n5 10\n4 1 2 3 2\n2 10\n1 1\n3 8\n3 3 3",
"0\n1\n8\n2"
]
] | In the first test case of the example, you don't have to add any coins. When Monocarp arrives, he will take the chest with $$$4$$$ coins, so he will have exactly $$$4$$$ coins.
In the second test case of the example, you can add $$$1$$$ coin to the $$$4$$$-th chest, so, when Monocarp arrives, he will take a chest with... | Title: Greedy Monocarp
time_limit_ms: 2000
memory_limit_mb: 512
Description: There are $$$n$$$ chests; the $$$i$$$-th chest initially contains $$$a_i$$$ coins. For each chest, you can choose any non-negative ($$$0$$$ or greater) number of coins to add to that chest, with one constraint: the total number of coins in all... |
2042B | https://codeforces.com/problemset/problem/2042/B | Game with Colored Marbles | 900 | [
"games",
"greedy"
] | Div. 2 | 2,000 | 512 | Alice and Bob play a game. There are $$$n$$$ marbles, the $$$i$$$-th of them has color $$$c_i$$$. The players take turns; Alice goes first, then Bob, then Alice again, then Bob again, and so on.
During their turn, a player must take one of the remaining marbles and remove it from the game. If there are no marbles left... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of marbles;
- the second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \l... | For each test case, print one integer — Alice's score at the end of the game, assuming that both players play optimally. | [
[
"3\n5\n1 3 1 3 4\n3\n1 2 3\n4\n4 4 4 4",
"4\n4\n1"
]
] | In the second test case of the example, the colors of all marbles are distinct, so, no matter how the players act, Alice receives $$$4$$$ points for having all marbles of two colors, and no marbles of the third color.
In the third test case of the example, the colors of all marbles are the same, so, no matter how the ... | Title: Game with Colored Marbles
time_limit_ms: 2000
memory_limit_mb: 512
Description: Alice and Bob play a game. There are $$$n$$$ marbles, the $$$i$$$-th of them has color $$$c_i$$$. The players take turns; Alice goes first, then Bob, then Alice again, then Bob again, and so on.
During their turn, a player must take... |
2042C | https://codeforces.com/problemset/problem/2042/C | Competitive Fishing | 1,800 | [
"greedy"
] | Div. 2 | 2,000 | 512 | Alice and Bob participate in a fishing contest! In total, they caught $$$n$$$ fishes, numbered from $$$1$$$ to $$$n$$$ (the bigger the fish, the greater its index). Some of these fishes were caught by Alice, others — by Bob.
Their performance will be evaluated as follows. First, an integer $$$m$$$ will be chosen, and ... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le 10^9$$$).
The second line contains a string, consisting of exactly $$$n$$$ characters. The $$... | For each test case, print a single integer — the minimum number of groups you have to split the fishes into; or -1 if it's impossible. | [
[
"7\n4 1\n1001\n4 1\n1010\n4 1\n0110\n4 2\n0110\n6 3\n001110\n10 20\n1111111111\n5 11\n11111",
"2\n-1\n2\n-1\n3\n4\n-1"
]
] | In the first test case of the example, you can split the fishes into groups as follows: the first three fishes form the $$$1$$$-st group, the last fish forms the $$$2$$$-nd group. Then, Bob's score will be $$$1$$$, and Alice's score will be $$$0$$$.
In the third test case of the example, you can split the fishes into ... | Title: Competitive Fishing
time_limit_ms: 2000
memory_limit_mb: 512
Description: Alice and Bob participate in a fishing contest! In total, they caught $$$n$$$ fishes, numbered from $$$1$$$ to $$$n$$$ (the bigger the fish, the greater its index). Some of these fishes were caught by Alice, others — by Bob.
Their perform... |
2042D | https://codeforces.com/problemset/problem/2042/D | Recommendations | 1,900 | [
"two pointers",
"data structures",
"implementation",
"sortings"
] | Div. 2 | 2,000 | 512 | Suppose you are working in some audio streaming service. The service has $$$n$$$ active users and $$$10^9$$$ tracks users can listen to. Users can like tracks and, based on likes, the service should recommend them new tracks.
Tracks are numbered from $$$1$$$ to $$$10^9$$$. It turned out that tracks the $$$i$$$-th user... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next, $$$t$$$ cases follow.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of users.
The next $$$n$$$ lines contain two integers $$$l_i$$$ and $$$r_i$$$ per lin... | For each test case, print $$$n$$$ integers, where the $$$i$$$-th integer is the number of strongly recommended tracks for the $$$i$$$-th user (or $$$0$$$, if that user doesn't have any predictors). | [
[
"4\n3\n3 8\n2 5\n4 5\n2\n42 42\n1 1000000000\n3\n42 42\n1 1000000000\n42 42\n6\n1 10\n3 10\n3 7\n5 7\n4 4\n1 2",
"0\n0\n1\n999999999\n0\n0\n0\n0\n0\n2\n3\n2\n4\n8"
]
] | In the first test case:
- the first user has no predictors;
- the second user has no predictors;
- the third user has two predictors: users $$$1$$$ and $$$2$$$; only track $$$3$$$ is liked by both of them and not liked by the third user.
In the second test case, the second user is a predictor for the first user. Ther... | Title: Recommendations
time_limit_ms: 2000
memory_limit_mb: 512
Description: Suppose you are working in some audio streaming service. The service has $$$n$$$ active users and $$$10^9$$$ tracks users can listen to. Users can like tracks and, based on likes, the service should recommend them new tracks.
Tracks are numbe... |
2009A | https://codeforces.com/problemset/problem/2009/A | Minimize! | 800 | [
"brute force",
"math"
] | Div. 4 | 1,000 | 256 | You are given two integers $$$a$$$ and $$$b$$$ ($$$a \leq b$$$). Over all possible integer values of $$$c$$$ ($$$a \leq c \leq b$$$), find the minimum value of $$$(c - a) + (b - c)$$$. | The first line contains $$$t$$$ ($$$1 \leq t \leq 55$$$) — the number of test cases.
Each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a \leq b \leq 10$$$). | For each test case, output the minimum possible value of $$$(c - a) + (b - c)$$$ on a new line. | [
[
"3\n1 2\n3 10\n5 5",
"1\n7\n0"
]
] | In the first test case, you can choose $$$c = 1$$$ and obtain an answer of $$$(1 - 1) + (2 - 1) = 1$$$. It can be shown this is the minimum value possible.
In the second test case, you can choose $$$c = 6$$$ and obtain an answer of $$$(6 - 3) + (10 - 6) = 7$$$. It can be shown this is the minimum value possible. | Title: Minimize!
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given two integers $$$a$$$ and $$$b$$$ ($$$a \leq b$$$). Over all possible integer values of $$$c$$$ ($$$a \leq c \leq b$$$), find the minimum value of $$$(c - a) + (b - c)$$$.
Input: The first line contains $$$t$$$ ($$$1 \leq t \leq 55$$$)... |
2009B | https://codeforces.com/problemset/problem/2009/B | osu!mania | 800 | [
"brute force",
"implementation"
] | Div. 4 | 1,000 | 256 | You are playing your favorite rhythm game, osu!mania. The layout of your beatmap consists of $$$n$$$ rows and $$$4$$$ columns. Because notes at the bottom are closer, you will process the bottommost row first and the topmost row last. Each row will contain exactly one note, represented as a '#'.
For each note $$$1, 2,... | The first line contains $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases.
For each test case, the first line contains $$$n$$$ ($$$1 \leq n \leq 500$$$) — the number of rows of the beatmap.
The following $$$n$$$ lines contain $$$4$$$ characters. The $$$i$$$-th line represents the $$$i$$$-th row of the beat... | For each test case, output $$$n$$$ integers on a new line, the column that the $$$i$$$-th note appears in for all $$$i$$$ from $$$1$$$ to $$$n$$$. | [
[
"3\n4\n#...\n.#..\n..#.\n...#\n2\n.#..\n.#..\n1\n...#",
"4 3 2 1 \n2 2 \n4"
]
] | Title: osu!mania
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are playing your favorite rhythm game, osu!mania. The layout of your beatmap consists of $$$n$$$ rows and $$$4$$$ columns. Because notes at the bottom are closer, you will process the bottommost row first and the topmost row last. Each row will ... | |
2009C | https://codeforces.com/problemset/problem/2009/C | The Legend of Freya the Frog | 1,100 | [
"implementation",
"math"
] | Div. 4 | 2,000 | 256 | Freya the Frog is traveling on the 2D coordinate plane. She is currently at point $$$(0,0)$$$ and wants to go to point $$$(x,y)$$$. In one move, she chooses an integer $$$d$$$ such that $$$0 \leq d \leq k$$$ and jumps $$$d$$$ spots forward in the direction she is facing.
Initially, she is facing the positive $$$x$$$ d... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
Each test case contains three integers $$$x$$$, $$$y$$$, and $$$k$$$ ($$$0 \leq x, y \leq 10^9, 1 \leq k \leq 10^9$$$). | For each test case, output the number of jumps Freya needs to make on a new line. | [
[
"3\n9 11 3\n0 10 8\n1000000 100000 10",
"8\n4\n199999"
]
] | In the first sample, one optimal set of moves is if Freya jumps in the following way: ($$$0,0$$$) $$$\rightarrow$$$ ($$$2,0$$$) $$$\rightarrow$$$ ($$$2,2$$$) $$$\rightarrow$$$ ($$$3,2$$$) $$$\rightarrow$$$ ($$$3,5$$$) $$$\rightarrow$$$ ($$$6,5$$$) $$$\rightarrow$$$ ($$$6,8$$$) $$$\rightarrow$$$ ($$$9,8$$$) $$$\rightarr... | Title: The Legend of Freya the Frog
time_limit_ms: 2000
memory_limit_mb: 256
Description: Freya the Frog is traveling on the 2D coordinate plane. She is currently at point $$$(0,0)$$$ and wants to go to point $$$(x,y)$$$. In one move, she chooses an integer $$$d$$$ such that $$$0 \leq d \leq k$$$ and jumps $$$d$$$ spot... |
2009D | https://codeforces.com/problemset/problem/2009/D | Satyam and Counting | 1,400 | [
"geometry",
"math"
] | Div. 4 | 2,000 | 256 | Satyam is given $$$n$$$ distinct points on the 2D coordinate plane. It is guaranteed that $$$0 \leq y_i \leq 1$$$ for all given points $$$(x_i, y_i)$$$. How many different nondegenerate right triangles$$$^{\text{∗}}$$$ can be formed from choosing three different points as its vertices?
Two triangles $$$a$$$ and $$$b$$... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the number of points.
The following $$$n$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \leq x_i \leq n$$$, $... | Output an integer for each test case, the number of distinct nondegenerate right triangles that can be formed from choosing three points. | [
[
"3\n5\n1 0\n1 1\n3 0\n5 0\n2 1\n3\n0 0\n1 0\n3 0\n9\n1 0\n2 0\n3 0\n4 0\n5 0\n2 1\n7 1\n8 1\n9 1",
"4\n0\n8"
]
] | The four triangles in question for the first test case: | Title: Satyam and Counting
time_limit_ms: 2000
memory_limit_mb: 256
Description: Satyam is given $$$n$$$ distinct points on the 2D coordinate plane. It is guaranteed that $$$0 \leq y_i \leq 1$$$ for all given points $$$(x_i, y_i)$$$. How many different nondegenerate right triangles$$$^{\text{∗}}$$$ can be formed from c... |
2009E | https://codeforces.com/problemset/problem/2009/E | Klee's SUPER DUPER LARGE Array!!! | 1,400 | [
"ternary search",
"binary search",
"math"
] | Div. 4 | 2,000 | 256 | Klee has an array $$$a$$$ of length $$$n$$$ containing integers $$$[k, k+1, ..., k+n-1]$$$ in that order. Klee wants to choose an index $$$i$$$ ($$$1 \leq i \leq n$$$) such that $$$x = |a_1 + a_2 + \dots + a_i - a_{i+1} - \dots - a_n|$$$ is minimized. Note that for an arbitrary integer $$$z$$$, $$$|z|$$$ represents the... | The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
Each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n, k \leq 10^9$$$) — the length of the array and the starting element of the array. | For each test case, output the minimum value of $$$x$$$ on a new line. | [
[
"4\n2 2\n7 2\n5 3\n1000000000 1000000000",
"1\n5\n1\n347369930"
]
] | In the first sample, $$$a = [2, 3]$$$. When $$$i = 1$$$ is chosen, $$$x = |2-3| = 1$$$. It can be shown this is the minimum possible value of $$$x$$$.
In the third sample, $$$a = [3, 4, 5, 6, 7]$$$. When $$$i = 3$$$ is chosen, $$$x = |3 + 4 + 5 - 6 - 7| = 1$$$. It can be shown this is the minimum possible value of $$$... | Title: Klee's SUPER DUPER LARGE Array!!!
time_limit_ms: 2000
memory_limit_mb: 256
Description: Klee has an array $$$a$$$ of length $$$n$$$ containing integers $$$[k, k+1, ..., k+n-1]$$$ in that order. Klee wants to choose an index $$$i$$$ ($$$1 \leq i \leq n$$$) such that $$$x = |a_1 + a_2 + \dots + a_i - a_{i+1} - \do... |
2009F | https://codeforces.com/problemset/problem/2009/F | Firefly's Queries | 1,700 | [
"bitmasks",
"data structures",
"flows",
"math"
] | Div. 4 | 2,000 | 256 | Firefly is given an array $$$a$$$ of length $$$n$$$. Let $$$c_i$$$ denote the $$$i$$$'th cyclic shift$$$^{\text{∗}}$$$ of $$$a$$$. She creates a new array $$$b$$$ such that $$$b = c_1 + c_2 + \dots + c_n$$$ where $$$+$$$ represents concatenation$$$^{\text{†}}$$$.
Then, she asks you $$$q$$$ queries. For each query, out... | The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 2 \cdot 10^5$$$) — the length of the array and the number of queries.
The following line contains $$$n$$$ integers $$$a_1, a_2, ..., a_... | For each query, output the answer on a new line. | [
[
"5\n3 3\n1 2 3\n1 9\n3 5\n8 8\n5 5\n4 8 3 2 4\n1 14\n3 7\n7 10\n2 11\n1 25\n1 1\n6\n1 1\n5 7\n3 1 6 10 4\n3 21\n6 17\n2 2\n1 5\n1 14\n9 15\n12 13\n5 3\n4 9 10 10 1\n20 25\n3 11\n20 22",
"18\n8\n1\n55\n20\n13\n41\n105\n6\n96\n62\n1\n24\n71\n31\n14\n44\n65\n15"
]
] | For the first test case, $$$b = [1, 2, 3, 2, 3, 1, 3, 1, 2]$$$. | Title: Firefly's Queries
time_limit_ms: 2000
memory_limit_mb: 256
Description: Firefly is given an array $$$a$$$ of length $$$n$$$. Let $$$c_i$$$ denote the $$$i$$$'th cyclic shift$$$^{\text{∗}}$$$ of $$$a$$$. She creates a new array $$$b$$$ such that $$$b = c_1 + c_2 + \dots + c_n$$$ where $$$+$$$ represents concatena... |
2009G1 | https://codeforces.com/problemset/problem/2009/G1 | Yunli's Subarray Queries (easy version) | 1,900 | [
"two pointers",
"data structures",
"binary search"
] | Div. 4 | 3,000 | 512 | This is the easy version of the problem. In this version, it is guaranteed that $$$r=l+k-1$$$ for all queries.
For an arbitrary array $$$b$$$, Yunli can perform the following operation any number of times:
- Select an index $$$i$$$. Set $$$b_i = x$$$ where $$$x$$$ is any integer she desires ($$$x$$$ is not limited to... | The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$k$$$, and $$$q$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq q \leq 2 \cdot 10^5$$$) — the length of the array, the length of the consecutive subarray, an... | Output $$$\sum_{j=l+k-1}^{r} f([a_l, a_{l+1}, \ldots, a_j])$$$ for each query on a new line. | [
[
"3\n7 5 3\n1 2 3 2 1 2 3\n1 5\n2 6\n3 7\n8 4 2\n4 3 1 1 2 4 3 2\n3 6\n2 5\n5 4 2\n4 5 1 2 3\n1 4\n2 5",
"2\n3\n2\n2\n2\n2\n1"
]
] | In the first query of the first testcase, $$$b=[1,2,3,2,1]$$$. Yunli can make a consecutive subarray of length $$$5$$$ in $$$2$$$ moves:
- Set $$$b_4=4$$$
- Set $$$b_5=5$$$
In the second query of the first testcase, $$$b=[2,3,2,1,2]$$$. Yunli can make a consecutive subarray of length $$$5$$$ in $$$3$$$ moves:
- Set ... | Title: Yunli's Subarray Queries (easy version)
time_limit_ms: 3000
memory_limit_mb: 512
Description: This is the easy version of the problem. In this version, it is guaranteed that $$$r=l+k-1$$$ for all queries.
For an arbitrary array $$$b$$$, Yunli can perform the following operation any number of times:
- Select an... |
2009G2 | https://codeforces.com/problemset/problem/2009/G2 | Yunli's Subarray Queries (hard version) | 2,200 | [
"data structures",
"dp",
"binary search"
] | Div. 4 | 3,000 | 512 | This is the hard version of the problem. In this version, it is guaranteed that $$$r \geq l+k-1$$$ for all queries.
For an arbitrary array $$$b$$$, Yunli can perform the following operation any number of times:
- Select an index $$$i$$$. Set $$$b_i = x$$$ where $$$x$$$ is any integer she desires ($$$x$$$ is not limit... | The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$k$$$, and $$$q$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq q \leq 2 \cdot 10^5$$$) — the length of the array, the length of the consecutive subarray, an... | Output $$$\sum_{j=l+k-1}^{r} f([a_l, a_{l+1}, \ldots, a_j])$$$ for each query on a new line. | [
[
"3\n7 5 3\n1 2 3 2 1 2 3\n1 7\n2 7\n3 7\n8 4 2\n4 3 1 1 2 4 3 2\n3 6\n1 5\n5 4 2\n4 5 1 2 3\n1 4\n1 5",
"6\n5\n2\n2\n5\n2\n3"
]
] | In the second query of the first testcase, we calculate the following function values:
- $$$f([2,3,2,1,2])=3$$$ because Yunli can set $$$b_3=4$$$, $$$b_4=5$$$, and $$$b_5=6$$$, making a consecutive subarray of size $$$5$$$ in $$$3$$$ moves.
- $$$f([2,3,2,1,2,3])=2$$$ because we can set $$$b_3=0$$$ and $$$b_2=-1$$$, ma... | Title: Yunli's Subarray Queries (hard version)
time_limit_ms: 3000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is guaranteed that $$$r \geq l+k-1$$$ for all queries.
For an arbitrary array $$$b$$$, Yunli can perform the following operation any number of times:
- Sele... |
2046A | https://codeforces.com/problemset/problem/2046/A | Swap Columns and Find a Path | 1,200 | [
"greedy",
"sortings"
] | Div. 1 | 2,000 | 512 | There is a matrix consisting of $$$2$$$ rows and $$$n$$$ columns. The rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom; the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. Let's denote the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i,j)$$$. Each cell con... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows.
Each test case consists of three lines:
- the first line contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$) — the number of columns in the matrix;
- ... | For each test case, print one integer — the maximum cost of a path you can obtain. | [
[
"3\n1\n-10\n5\n3\n1 2 3\n10 -5 -3\n4\n2 8 5 3\n1 10 3 4",
"-5\n16\n29"
]
] | Here are the explanations of the first three test cases of the example. The left matrix is the matrix given in the input, the right one is the state of the matrix after several column swaps (possibly zero). The optimal path is highlighted in green. | Title: Swap Columns and Find a Path
time_limit_ms: 2000
memory_limit_mb: 512
Description: There is a matrix consisting of $$$2$$$ rows and $$$n$$$ columns. The rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom; the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. Let's denote the cell on the ... |
2046B | https://codeforces.com/problemset/problem/2046/B | Move Back at a Cost | 1,600 | [
"data structures",
"binary search",
"sortings",
"greedy"
] | Div. 1 | 2,000 | 256 | You are given an array of integers $$$a$$$ of length $$$n$$$. You can perform the following operation zero or more times:
- In one operation choose an index $$$i$$$ ($$$1 \le i \le n$$$), assign $$$a_i := a_i + 1$$$, and then move $$$a_i$$$ to the back of the array (to the rightmost position). For example, if $$$a = [... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the length of the array.
The second line contains $$$n$$$ integers $$$a_1, a_... | For each test case, print the lexicographically smallest array you can get. | [
[
"3\n3\n2 1 3\n5\n1 2 2 1 4\n6\n1 2 3 6 5 4",
"1 3 3 \n1 1 3 3 5 \n1 2 3 4 6 7"
]
] | Title: Move Back at a Cost
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given an array of integers $$$a$$$ of length $$$n$$$. You can perform the following operation zero or more times:
- In one operation choose an index $$$i$$$ ($$$1 \le i \le n$$$), assign $$$a_i := a_i + 1$$$, and then move $$$a_i$... | |
2039C1 | https://codeforces.com/problemset/problem/2039/C1 | Shohag Loves XOR (Easy Version) | 1,200 | [
"bitmasks",
"brute force",
"math",
"number theory"
] | Div. 1 + Div. 2, Rated, Prizes! | 2,000 | 256 | This is the easy version of the problem. The differences between the two versions are highlighted in bold. You can only make hacks if both versions of the problem are solved.
Shohag has two integers $$$x$$$ and $$$m$$$. Help him count the number of integers $$$1 \le y \le m$$$ such that $$$\mathbf{x \neq y}$$$ and $$$... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first and only line of each test case contains two space-separated integers $$$x$$$ and $$$m$$$ ($$$1 \le x \le 10^6$$$, $$$1 \le m \le 10^{18}$$$).
It is guaranteed that the sum of $$$x$$$ over all test cases do... | For each test case, print a single integer — the number of suitable $$$y$$$. | [
[
"5\n6 9\n5 7\n2 3\n6 4\n4 1",
"3\n2\n1\n1\n0"
]
] | In the first test case, for $$$x = 6$$$, there are $$$3$$$ valid values for $$$y$$$ among the integers from $$$1$$$ to $$$m = 9$$$, and they are $$$4$$$, $$$5$$$, and $$$7$$$.
- $$$y = 4$$$ is valid because $$$x \oplus y = 6 \oplus 4 = 2$$$ and $$$2$$$ is a divisor of both $$$x = 6$$$ and $$$y = 4$$$.
- $$$y = 5$$$ is... | Title: Shohag Loves XOR (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the easy version of the problem. The differences between the two versions are highlighted in bold. You can only make hacks if both versions of the problem are solved.
Shohag has two integers $$$x$$$ and $$$m$$$. Help h... |
2039C2 | https://codeforces.com/problemset/problem/2039/C2 | Shohag Loves XOR (Hard Version) | 1,800 | [
"bitmasks",
"brute force",
"math",
"number theory"
] | Div. 1 + Div. 2, Rated, Prizes! | 2,000 | 256 | This is the hard version of the problem. The differences between the two versions are highlighted in bold. You can only make hacks if both versions of the problem are solved.
Shohag has two integers $$$x$$$ and $$$m$$$. Help him count the number of integers $$$1 \le y \le m$$$ such that $$$x \oplus y$$$ is divisible$$... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first and only line of each test case contains two space-separated integers $$$x$$$ and $$$m$$$ ($$$1 \le x \le 10^6$$$, $$$1 \le m \le 10^{18}$$$).
It is guaranteed that the sum of $$$x$$$ over all test cases do... | For each test case, print a single integer — the number of suitable $$$y$$$. | [
[
"5\n7 10\n2 3\n6 4\n1 6\n4 1",
"3\n2\n2\n6\n1"
]
] | In the first test case, for $$$x = 7$$$, there are $$$3$$$ valid values for $$$y$$$ among the integers from $$$1$$$ to $$$m = 10$$$, and they are $$$1$$$, $$$7$$$, and $$$9$$$.
- $$$y = 1$$$ is valid because $$$x \oplus y = 7 \oplus 1 = 6$$$ and $$$6$$$ is divisible by $$$y = 1$$$.
- $$$y = 7$$$ is valid because $$$x ... | Title: Shohag Loves XOR (Hard Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the hard version of the problem. The differences between the two versions are highlighted in bold. You can only make hacks if both versions of the problem are solved.
Shohag has two integers $$$x$$$ and $$$m$$$. Help h... |
2039D | https://codeforces.com/problemset/problem/2039/D | Shohag Loves GCD | 1,700 | [
"constructive algorithms",
"greedy",
"math",
"number theory"
] | Div. 1 + Div. 2, Rated, Prizes! | 2,000 | 256 | Shohag has an integer $$$n$$$ and a set $$$S$$$ of $$$m$$$ unique integers. Help him find the lexicographically largest$$$^{\text{∗}}$$$ integer array $$$a_1, a_2, \ldots, a_n$$$ such that $$$a_i \in S$$$ for each $$$1 \le i \le n$$$ and $$$a_{\operatorname{gcd}(i, j)} \neq \operatorname{gcd}(a_i, a_j)$$$$$$^{\text{†}}... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 10^5$$$).
The second line contains $$$m$$$ unique integers in increasing order, representing the elements of the set $$... | For each test case, if there is no solution print $$$-1$$$, otherwise print $$$n$$$ integers — the lexicographically largest integer array that satisfies the conditions. | [
[
"3\n6 3\n3 4 6\n1 1\n1\n2 1\n2",
"6 4 4 3 4 3 \n1 \n-1"
]
] | In the first test case, every element in the array belongs to the given set $$$S = \{3, 4, 6\}$$$, and all pairs of indices of the array satisfy the necessary conditions. In particular, for pair $$$(2, 3)$$$, $$$a_{\operatorname{gcd}(2, 3)} = a_1 = 6$$$ and $$$\operatorname{gcd}(a_2, a_3) = \operatorname{gcd}(4, 4) = 4... | Title: Shohag Loves GCD
time_limit_ms: 2000
memory_limit_mb: 256
Description: Shohag has an integer $$$n$$$ and a set $$$S$$$ of $$$m$$$ unique integers. Help him find the lexicographically largest$$$^{\text{∗}}$$$ integer array $$$a_1, a_2, \ldots, a_n$$$ such that $$$a_i \in S$$$ for each $$$1 \le i \le n$$$ and $$$a... |
2039E | https://codeforces.com/problemset/problem/2039/E | Shohag Loves Inversions | 2,200 | [
"combinatorics",
"dp",
"implementation",
"math"
] | Div. 1 + Div. 2, Rated, Prizes! | 2,000 | 256 | Shohag has an array $$$a$$$ of integers. Initially $$$a = [0, 1]$$$. He can repeatedly perform the following operation any number of times:
- Let $$$k$$$ be the number of inversions$$$^{\text{∗}}$$$ in the current array $$$a$$$.
- Insert $$$k$$$ at any position in $$$a$$$, including the beginning or the end.
For exam... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first and only line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^6$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. | For each test case, output an integer — the number of possible arrays modulo $$$998\,244\,353$$$. | [
[
"4\n4\n2\n7\n69",
"5\n1\n682\n325188814"
]
] | In the first test case, the following $$$5$$$ arrays can be obtained (the inserted inversion count is shown in bold):
- $$$[0, 1] \rightarrow [0, \textbf{0}, 1] \rightarrow [0, 0, 1, \textbf{0}]$$$,
- $$$[0, 1] \rightarrow [0, \textbf{0}, 1] \rightarrow [0, 0, \textbf{0}, 1]$$$,
- $$$[0, 1] \rightarrow [0, 1, \textbf{... | Title: Shohag Loves Inversions
time_limit_ms: 2000
memory_limit_mb: 256
Description: Shohag has an array $$$a$$$ of integers. Initially $$$a = [0, 1]$$$. He can repeatedly perform the following operation any number of times:
- Let $$$k$$$ be the number of inversions$$$^{\text{∗}}$$$ in the current array $$$a$$$.
- Ins... |
2043A | https://codeforces.com/problemset/problem/2043/A | Coin Transformation | 800 | [
"brute force",
"math"
] | Div. 2 | 2,000 | 512 | Initially, you have a coin with value $$$n$$$. You can perform the following operation any number of times (possibly zero):
- transform one coin with value $$$x$$$, where $$$x$$$ is greater than $$$3$$$ ($$$x>3$$$), into two coins with value $$$\lfloor \frac{x}{4} \rfloor$$$.
What is the maximum number of coins you c... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$). | For each test case, print one integer — the maximum number of coins you can have after performing the operation any number of times. | [
[
"4\n1\n5\n16\n1000000000000000000",
"1\n2\n4\n536870912"
]
] | In the first example, you have a coin of value $$$1$$$, and you can't do anything with it. So, the answer is $$$1$$$.
In the second example, you can transform a coin of value $$$5$$$ into two coins with value $$$1$$$.
In the third example, you can transform a coin of value $$$16$$$ into two coins with value $$$4$$$. ... | Title: Coin Transformation
time_limit_ms: 2000
memory_limit_mb: 512
Description: Initially, you have a coin with value $$$n$$$. You can perform the following operation any number of times (possibly zero):
- transform one coin with value $$$x$$$, where $$$x$$$ is greater than $$$3$$$ ($$$x>3$$$), into two coins with va... |
2043B | https://codeforces.com/problemset/problem/2043/B | Digits | 1,100 | [
"math",
"number theory"
] | Div. 2 | 1,000 | 256 | Artem wrote the digit $$$d$$$ on the board exactly $$$n!$$$ times in a row. So, he got the number $$$dddddd \dots ddd$$$ (exactly $$$n!$$$ digits).
Now he is curious about which odd digits from $$$1$$$ to $$$9$$$ divide the number written on the board. | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$t$$$ test cases follow.
Each test case consists of a single line containing two integers $$$n$$$ and $$$d$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le d \le 9$$$). | For each test case, output the odd digits in ascending order that divide the number written on the board. | [
[
"3\n2 6\n7 1\n8 5",
"1 3 \n1 3 7 9 \n1 3 5 7 9"
]
] | The factorial of a positive integer $$$n$$$ ($$$n!$$$) is the product of all integers from $$$1$$$ to $$$n$$$. For example, the factorial of $$$5$$$ is $$$1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 = 120$$$. | Title: Digits
time_limit_ms: 1000
memory_limit_mb: 256
Description: Artem wrote the digit $$$d$$$ on the board exactly $$$n!$$$ times in a row. So, he got the number $$$dddddd \dots ddd$$$ (exactly $$$n!$$$ digits).
Now he is curious about which odd digits from $$$1$$$ to $$$9$$$ divide the number written on the board... |
2043C | https://codeforces.com/problemset/problem/2043/C | Sums on Segments | 1,600 | [
"brute force",
"dp",
"binary search",
"math",
"data structures",
"greedy"
] | Div. 2 | 1,000 | 256 | You are given an array $$$a$$$ of $$$n$$$ integers, where all elements except for at most one are equal to $$$-1$$$ or $$$1$$$. The remaining element $$$x$$$ satisfies $$$-10^9 \le x \le 10^9$$$.
Find all possible sums of subarrays of $$$a$$$, including the empty subarray, whose sum is defined as $$$0$$$. In other wor... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then, $$$t$$$ test cases follow.
Each test case consists of two lines:
- The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array.
- The second line contains $$$n$$$ i... | For each test case, output two lines:
- In the first line, print a single integer — the number of distinct subarray sums.
- In the second line, print these sums in ascending order.
Each sum should be printed only once, even if it is produced by multiple subarrays. | [
[
"5\n5\n1 -1 10 1 1\n5\n-1 -1 -1 -1 -1\n2\n-1 2\n2\n7 1\n3\n1 4 -1",
"8\n-1 0 1 2 9 10 11 12 \n6\n-5 -4 -3 -2 -1 0 \n4\n-1 0 1 2 \n4\n0 1 7 8 \n6\n-1 0 1 3 4 5"
]
] | Let's define $$$a[i,j]$$$ as the subarray of $$$a$$$ from position $$$i$$$ to position $$$j$$$.
Consider the first test case of the example:
- $$$-1$$$ is produced by $$$a[2,2]$$$;
- $$$0$$$ is produced by the empty subarray;
- $$$1$$$ is produced by $$$a[4,4]$$$;
- $$$2$$$ is produced by $$$a[4,5]$$$;
- $$$9$$$ is p... | Title: Sums on Segments
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given an array $$$a$$$ of $$$n$$$ integers, where all elements except for at most one are equal to $$$-1$$$ or $$$1$$$. The remaining element $$$x$$$ satisfies $$$-10^9 \le x \le 10^9$$$.
Find all possible sums of subarrays of $$$a$$... |
2043D | https://codeforces.com/problemset/problem/2043/D | Problem about GCD | 1,800 | [
"brute force",
"flows",
"number theory",
"math"
] | Div. 2 | 1,000 | 256 | Given three integers $$$l$$$, $$$r$$$, and $$$G$$$, find two integers $$$A$$$ and $$$B$$$ ($$$l \le A \le B \le r$$$) such that their greatest common divisor (GCD) equals $$$G$$$ and the distance $$$|A - B|$$$ is maximized.
If there are multiple such pairs, choose the one where $$$A$$$ is minimized. If no such pairs e... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Then, $$$t$$$ test cases follow.
Each test case consists of a single line containing three integers $$$l, r, G$$$ ($$$1 \le l \le r \le 10^{18}$$$; $$$1 \le G \le 10^{18}$$$) — the range boundaries and the required GC... | For each test case, output two integers $$$A$$$ and $$$B$$$ — the solution to the problem, or "-1 -1" if no such pair exists. | [
[
"4\n4 8 2\n4 8 3\n4 8 4\n5 7 6",
"4 6\n-1 -1\n4 8\n6 6"
]
] | Title: Problem about GCD
time_limit_ms: 1000
memory_limit_mb: 256
Description: Given three integers $$$l$$$, $$$r$$$, and $$$G$$$, find two integers $$$A$$$ and $$$B$$$ ($$$l \le A \le B \le r$$$) such that their greatest common divisor (GCD) equals $$$G$$$ and the distance $$$|A - B|$$$ is maximized.
If there are mul... | |
2043E | https://codeforces.com/problemset/problem/2043/E | Matrix Transformation | 2,300 | [
"brute force",
"graphs",
"greedy",
"implementation",
"data structures",
"dfs and similar",
"bitmasks"
] | Div. 2 | 1,000 | 256 | You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, filled with integers between $$$0$$$ and $$$10^9$$$. You can perform the following operations on matrix $$$A$$$ in any order and any number of times:
- &=: choose two integers $$$i$$$ and $$$x$$$ ($$$1 \le i \le n$$$, $$$x \ge 0$$$) and replace e... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then, $$$t$$$ test cases follow.
Each test case is given as follows:
- the first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^3$$$; $$$n \cdot m \le 10^3$$$) — the dimensions of the matrices $$... | For each test case, output Yes if it is possible to transform the matrix $$$A$$$ into the matrix $$$B$$$; otherwise, output No. Each letter can be output in any case, upper or lower. | [
[
"4\n1 1\n12\n13\n2 2\n10 10\n42 42\n21 21\n21 21\n2 2\n74 10\n42 106\n21 85\n85 21\n2 4\n1 2 3 4\n5 6 7 8\n3 2 3 4\n1 0 1 0",
"Yes\nYes\nNo\nYes"
]
] | Let's consider the second set of input data and show a sequence of operations that transforms matrix $$$A$$$ into matrix $$$B$$$:
Initially, the matrix looks like this:
$$$\begin{bmatrix} 10&10\\ 42&42\\ \end{bmatrix}$$$
Apply an operation of the first type with parameters $$$i = 1$$$ and $$$x = 0$$$. As a result, w... | Title: Matrix Transformation
time_limit_ms: 1000
memory_limit_mb: 256
Description: You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, filled with integers between $$$0$$$ and $$$10^9$$$. You can perform the following operations on matrix $$$A$$$ in any order and any number of times:
- &=: choose ... |
2021C1 | https://codeforces.com/problemset/problem/2021/C1 | Adjust The Presentation (Easy Version) | 1,300 | [
"constructive algorithms",
"greedy"
] | Div. 2, based on COMPFEST 16 - Final Round | 2,000 | 256 | This is the easy version of the problem. In the two versions, the constraints on $$$q$$$ and the time limit are different. In this version, $$$q=0$$$. You can make hacks only if all the versions of the problem are solved.
A team consisting of $$$n$$$ members, numbered from $$$1$$$ to $$$n$$$, is set to present a slide... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$; $$$q=0$$$) — the number of memb... | For each test case, output $$$q+1$$$ lines corresponding to the $$$q+1$$$ states of the array $$$b$$$. Output "YA" if the slide show is good, and "TIDAK" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yA", "Ya", "ya", and "YA" will be recognized as positive responses. | [
[
"3\n4 2 0\n1 2 3 4\n1 1\n3 6 0\n1 2 3\n1 1 2 3 3 2\n4 6 0\n3 1 4 2\n3 1 1 2 3 4",
"YA\nYA\nTIDAK"
]
] | For the first test case, you do not need to move the members as both slides are presented by member $$$1$$$, who is already at the front of the line.
For the second test case, the following is a possible way to move members so that the presentation is good:
1. $$$[1,2,3]$$$, do not move member $$$1$$$.
2. $$$[1,2,3]$... | Title: Adjust The Presentation (Easy Version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the easy version of the problem. In the two versions, the constraints on $$$q$$$ and the time limit are different. In this version, $$$q=0$$$. You can make hacks only if all the versions of the problem are solved... |
2021C2 | https://codeforces.com/problemset/problem/2021/C2 | Adjust The Presentation (Hard Version) | 1,900 | [
"implementation",
"data structures",
"sortings",
"constructive algorithms",
"greedy"
] | Div. 2, based on COMPFEST 16 - Final Round | 5,000 | 256 | This is the hard version of the problem. In the two versions, the constraints on $$$q$$$ and the time limit are different. In this version, $$$0 \leq q \leq 2 \cdot 10^5$$$. You can make hacks only if all the versions of the problem are solved.
A team consisting of $$$n$$$ members, numbered from $$$1$$$ to $$$n$$$, is... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$; $$$0 \leq q \leq 2 \cdot 10^5$$... | For each test case, output $$$q+1$$$ lines corresponding to the $$$q+1$$$ states of the array $$$b$$$. Output "YA" if the slide show is good, and "TIDAK" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yA", "Ya", "ya", and "YA" will be recognized as positive responses. | [
[
"3\n4 2 2\n1 2 3 4\n1 1\n1 2\n1 1\n3 6 2\n1 2 3\n1 1 2 3 3 2\n3 3\n2 2\n4 6 2\n3 1 4 2\n3 1 1 2 3 4\n3 4\n4 2",
"YA\nTIDAK\nYA\nYA\nTIDAK\nYA\nTIDAK\nYA\nYA"
]
] | For the first test case, you do not need to move the members as both slides are presented by member $$$1$$$, who is already at the front of the line. After that, set $$$b_1 := 2$$$, now slide $$$1$$$ must be presented by member $$$2$$$ which is impossible as member $$$1$$$ will present slide $$$1$$$ first. Then, set $$... | Title: Adjust The Presentation (Hard Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: This is the hard version of the problem. In the two versions, the constraints on $$$q$$$ and the time limit are different. In this version, $$$0 \leq q \leq 2 \cdot 10^5$$$. You can make hacks only if all the versions of... |
2010A | https://codeforces.com/problemset/problem/2010/A | Alternating Sum of Numbers | 800 | [
"brute force",
"implementation",
"math"
] | Div. 3 | 2,000 | 256 | You are given a sequence of integers. Output the alternating sum of this sequence. In other words, output $$$a_1 - a_2 + a_3 - a_4 + a_5 - \dots$$$. That is, the signs of plus and minus alternate, starting with a plus. | The first line of the test contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then follow $$$t$$$ test cases.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the sequence. The second line of the test case contains $$$n$$$ integers $$$a... | Output $$$t$$$ lines. For each test case, output the required alternating sum of the numbers. | [
[
"4\n4\n1 2 3 17\n1\n100\n2\n100 100\n5\n3 1 4 1 5",
"-15\n100\n0\n10"
]
] | Title: Alternating Sum of Numbers
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a sequence of integers. Output the alternating sum of this sequence. In other words, output $$$a_1 - a_2 + a_3 - a_4 + a_5 - \dots$$$. That is, the signs of plus and minus alternate, starting with a plus.
Input: The f... | |
2010B | https://codeforces.com/problemset/problem/2010/B | Three Brothers | 800 | [
"brute force",
"implementation",
"math"
] | Div. 3 | 1,000 | 256 | Three brothers agreed to meet. Let's number the brothers as follows: the oldest brother is number 1, the middle brother is number 2, and the youngest brother is number 3.
When it was time for the meeting, one of the brothers was late. Given the numbers of the two brothers who arrived on time, you need to determine the... | The first line of input contains two different integers a and b (1 ≤ a, b ≤ 3, a ≠ b) — the numbers of the brothers who arrived on time. The numbers are given in arbitrary order. | Output a single integer — the number of the brother who was late to the meeting. | [
[
"3 1",
"2"
]
] | Title: Three Brothers
time_limit_ms: 1000
memory_limit_mb: 256
Description: Three brothers agreed to meet. Let's number the brothers as follows: the oldest brother is number 1, the middle brother is number 2, and the youngest brother is number 3.
When it was time for the meeting, one of the brothers was late. Given th... | |
2047A | https://codeforces.com/problemset/problem/2047/A | Alyona and a Square Jigsaw Puzzle | 800 | [
"implementation",
"math"
] | Div. 2 | 1,000 | 256 | Alyona assembles an unusual square Jigsaw Puzzle. She does so in $$$n$$$ days in the following manner:
- On the first day, she starts by placing the central piece in the center of the table.
- On each day after the first one, she places a certain number of pieces around the central piece in clockwise order, always fin... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of days.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldo... | For each test case, print a single integer: the number of days when Alyona is happy. | [
[
"5\n1\n1\n2\n1 8\n5\n1 3 2 1 2\n7\n1 2 1 10 2 7 2\n14\n1 10 10 100 1 1 10 1 10 2 10 2 10 1",
"1\n2\n2\n2\n3"
]
] | In the first test case, in the only day Alyona finishes the only layer.
In the second test case, on the first day, Alyona finishes the first layer, and on the second day, she finishes the second layer.
In the third test case, she finishes the second layer in a few days.
In the fourth test case, she finishes the seco... | Title: Alyona and a Square Jigsaw Puzzle
time_limit_ms: 1000
memory_limit_mb: 256
Description: Alyona assembles an unusual square Jigsaw Puzzle. She does so in $$$n$$$ days in the following manner:
- On the first day, she starts by placing the central piece in the center of the table.
- On each day after the first one... |
2053A | https://codeforces.com/problemset/problem/2053/A | Tender Carpenter | 800 | [
"greedy",
"geometry",
"dp",
"math"
] | Good Bye 2024: 2025 is NEAR | 1,000 | 256 | In his dream, Cocoly would go on a long holiday with no worries around him. So he would try out for many new things, such as... being a carpenter. To learn it well, Cocoly decides to become an apprentice of Master, but in front of him lies a hard task waiting for him to solve.
Cocoly is given an array $$$a_1, a_2,\ldo... | Each test contains multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 200$$$) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 200$$$) — the length of the array $$$a$... | For each test case, print $$$\texttt{YES}$$$ if there are at least two ways to partition $$$a$$$, and $$$\texttt{NO}$$$ otherwise.
You can output the answer in any case (upper or lower). For example, the strings $$$\texttt{yEs}$$$, $$$\texttt{yes}$$$, $$$\texttt{Yes}$$$, and $$$\texttt{YES}$$$ will be recognized as po... | [
[
"5\n4\n2 3 5 7\n4\n115 9 2 28\n5\n8 4 1 6 2\n6\n1 5 4 1 4 7\n2\n100000 100000",
"YES\nNO\nNO\nYES\nYES"
]
] | In the first test case, here are two possible partitions:
- $$$[2, 3], [5, 7]$$$, since $$$[2, 3]$$$ is stable because sticks of lengths $$$(2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3)$$$ respectively can all form non-degenerate triangles. $$$[5, 7]$$$ is stable because sticks of lengths $$$(5, 5, 5), (5, 5, 7), (5, ... | Title: Tender Carpenter
time_limit_ms: 1000
memory_limit_mb: 256
Description: In his dream, Cocoly would go on a long holiday with no worries around him. So he would try out for many new things, such as... being a carpenter. To learn it well, Cocoly decides to become an apprentice of Master, but in front of him lies a ... |
2053B | https://codeforces.com/problemset/problem/2053/B | Outstanding Impressionist | 1,200 | [
"data structures",
"brute force",
"binary search",
"greedy"
] | Good Bye 2024: 2025 is NEAR | 1,000 | 256 | Even after copying the paintings from famous artists for ten years, unfortunately, Eric is still unable to become a skillful impressionist painter. He wants to forget something, but the white bear phenomenon just keeps hanging over him.
Eric still remembers $$$n$$$ pieces of impressions in the form of an integer array... | Each test contains multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) — the number of impres... | For each test case, output a binary string $$$s$$$ of length $$$n$$$: for each $$$1 \leq i \leq n$$$, if impression $$$i$$$ is unique, $$$s_i=\texttt{1}$$$; otherwise, $$$s_i=\texttt{0}$$$. Do not output spaces. | [
[
"5\n2\n1 1\n1 1\n4\n1 3\n1 3\n1 3\n1 3\n6\n3 6\n2 2\n1 2\n1 1\n3 4\n2 2\n7\n3 4\n4 4\n4 4\n1 3\n2 5\n1 4\n2 2\n3\n4 5\n4 4\n5 5",
"00\n1111\n100110\n1001111\n011"
]
] | In the first test case, the only possible array $$$w$$$ is $$$[1, 1]$$$, making neither impression $$$1$$$ nor $$$2$$$ unique (since $$$w_1 = w_2$$$).
In the second test case, all impressions can be made unique:
- For $$$i = 1$$$, we can set $$$w$$$ to $$$[1, 3, 2, 3]$$$, in which $$$w_1 \neq w_2$$$, $$$w_1 \neq w_3$... | Title: Outstanding Impressionist
time_limit_ms: 1000
memory_limit_mb: 256
Description: Even after copying the paintings from famous artists for ten years, unfortunately, Eric is still unable to become a skillful impressionist painter. He wants to forget something, but the white bear phenomenon just keeps hanging over h... |
2053C | https://codeforces.com/problemset/problem/2053/C | Bewitching Stargazer | 1,500 | [
"bitmasks",
"dp",
"math",
"divide and conquer"
] | Good Bye 2024: 2025 is NEAR | 2,000 | 256 | Iris looked at the stars and a beautiful problem emerged in her mind. She is inviting you to solve it so that a meteor shower is believed to form.
There are $$$n$$$ stars in the sky, arranged in a row. Iris has a telescope, which she uses to look at the stars.
Initially, Iris observes stars in the segment $$$[1, n]$$... | Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows.
The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 2\cdot 10^9$$$). | For each test case, output a single integer — the final lucky value. | [
[
"6\n7 2\n11 3\n55 13\n5801 6\n8919 64\n8765432 1",
"12\n18\n196\n1975581\n958900\n38416403456028"
]
] | In the first test case, at the beginning, Iris observes $$$[1, 7]$$$. Since $$$[1, 7]$$$ has an odd length, she aims at star $$$4$$$ and therefore increases her lucky value by $$$4$$$. Then it is split into $$$2$$$ new segments: $$$[1, 3]$$$ and $$$[5, 7]$$$. The segment $$$[1, 3]$$$ again has an odd length, so Iris ai... | Title: Bewitching Stargazer
time_limit_ms: 2000
memory_limit_mb: 256
Description: Iris looked at the stars and a beautiful problem emerged in her mind. She is inviting you to solve it so that a meteor shower is believed to form.
There are $$$n$$$ stars in the sky, arranged in a row. Iris has a telescope, which she use... |
2053D | https://codeforces.com/problemset/problem/2053/D | Refined Product Optimality | 1,700 | [
"math",
"binary search",
"schedules",
"data structures",
"sortings",
"greedy"
] | Good Bye 2024: 2025 is NEAR | 3,000 | 512 | Although Iris occasionally sets a problem where the solution is possibly wrong, she still insists on creating problems with her imagination; after all, everyone has always been on the road with their stubbornness... And like ever before, Iris has set a problem to which she gave a wrong solution, but Chris is always sup... | Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$, $$$1 \leq q \leq 2... | For each test case, output $$$q + 1$$$ integers in a line, representing the answers that Chris will calculate, modulo $$$998\,244\,353$$$. | [
[
"4\n3 4\n1 1 2\n3 2 1\n1 3\n2 3\n1 1\n2 1\n6 8\n1 4 2 7 3 5\n7 6 5 6 3 3\n2 5\n1 6\n1 5\n1 5\n1 5\n2 3\n2 3\n1 6\n13 8\n7 7 6 6 5 5 5 2 2 3 4 5 1\n1 4 1 9 6 6 9 1 5 1 3 8 4\n2 2\n2 11\n2 4\n2 4\n1 7\n1 1\n2 12\n1 5\n5 3\n10000000 20000000 30000000 40000000 50000000\n10000000 20000000 30000000 40000000 5000000... | In the first test case:
- Before the modifications, Chris can rearrange $$$b$$$ to $$$[1, 2, 3]$$$ so that $$$P = \prod\limits_{i=1}^n \min(a_i, b_i) = 1 \cdot 1 \cdot 2 = 2$$$. We can prove that this is the maximum possible value. For example, if Chris rearranges $$$b = [2, 3, 1]$$$, $$$P$$$ will be equal $$$1 \cdot ... | Title: Refined Product Optimality
time_limit_ms: 3000
memory_limit_mb: 512
Description: Although Iris occasionally sets a problem where the solution is possibly wrong, she still insists on creating problems with her imagination; after all, everyone has always been on the road with their stubbornness... And like ever be... |
2031A | https://codeforces.com/problemset/problem/2031/A | Penchick and Modern Monument | 800 | [
"constructive algorithms",
"greedy",
"dp",
"math"
] | Div. 2 | 1,000 | 256 | Amidst skyscrapers in the bustling metropolis of Metro Manila, the newest Noiph mall in the Philippines has just been completed! The construction manager, Penchick, ordered a state-of-the-art monument to be built with $$$n$$$ pillars.
The heights of the monument's pillars can be represented as an array $$$h$$$ of $$$n... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of pillars.
The second line of each test case c... | For each test case, output a single integer representing the minimum number of operations needed to make the heights of the pillars non-decreasing. | [
[
"3\n5\n5 4 3 2 1\n3\n2 2 1\n1\n1",
"4\n1\n0"
]
] | In the first test case, the initial heights of pillars are $$$h = [5, 4, 3, 2, 1]$$$.
- In the first operation, Penchick changes the height of pillar $$$1$$$ to $$$h_1 := 2$$$.
- In the second operation, he changes the height of pillar $$$2$$$ to $$$h_2 := 2$$$.
- In the third operation, he changes the height of pilla... | Title: Penchick and Modern Monument
time_limit_ms: 1000
memory_limit_mb: 256
Description: Amidst skyscrapers in the bustling metropolis of Metro Manila, the newest Noiph mall in the Philippines has just been completed! The construction manager, Penchick, ordered a state-of-the-art monument to be built with $$$n$$$ pill... |
2031B | https://codeforces.com/problemset/problem/2031/B | Penchick and Satay Sticks | 900 | [
"greedy",
"brute force",
"sortings"
] | Div. 2 | 1,500 | 256 | Penchick and his friend Kohane are touring Indonesia, and their next stop is in Surabaya!
In the bustling food stalls of Surabaya, Kohane bought $$$n$$$ satay sticks and arranged them in a line, with the $$$i$$$-th satay stick having length $$$p_i$$$. It is given that $$$p$$$ is a permutation$$$^{\text{∗}}$$$ of lengt... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^5$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the number of satay sticks.
The second line ... | For each test case, output "YES" if it is possible to sort permutation $$$p$$$ by performing the operation. Otherwise, output "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"2\n4\n2 1 3 4\n4\n4 2 3 1",
"YES\nNO"
]
] | In the first test case, we can sort permutation $$$p = [2, 1, 3, 4]$$$ by performing an operation on index $$$1$$$ ($$$|p_2 - p_1| = |1 - 2| = 1$$$), resulting in $$$p = [1, 2, 3, 4]$$$.
In the second test case, it can be proven that it is impossible to sort permutation $$$p = [4, 2, 3, 1]$$$ by performing the operati... | Title: Penchick and Satay Sticks
time_limit_ms: 1500
memory_limit_mb: 256
Description: Penchick and his friend Kohane are touring Indonesia, and their next stop is in Surabaya!
In the bustling food stalls of Surabaya, Kohane bought $$$n$$$ satay sticks and arranged them in a line, with the $$$i$$$-th satay stick havin... |
2031D | https://codeforces.com/problemset/problem/2031/D | Penchick and Desert Rabbit | 1,700 | [
"dp",
"binary search",
"implementation",
"data structures",
"two pointers",
"dfs and similar",
"dsu",
"greedy"
] | Div. 2 | 3,000 | 256 | Dedicated to pushing himself to his limits, Penchick challenged himself to survive the midday sun in the Arabian Desert!
While trekking along a linear oasis, Penchick spots a desert rabbit preparing to jump along a line of palm trees. There are $$$n$$$ trees, each with a height denoted by $$$a_i$$$.
The rabbit can ju... | The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5 \cdot 10^5$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$) — the number of trees.
The second line of each test case contains $$$n$$$ integers... | For each test case, output $$$n$$$ integers. The $$$i$$$-th integer should contain the maximum height among all trees that the rabbit can reach if it starts from the $$$i$$$-th tree. | [
[
"5\n4\n2 3 1 4\n5\n5 4 3 2 1\n4\n2 1 1 3\n4\n1 1 3 1\n8\n2 4 1 6 3 8 5 7",
"3 3 3 4 \n5 5 5 5 5 \n2 2 2 3 \n1 1 3 3 \n8 8 8 8 8 8 8 8"
]
] | In the first test case, the initial heights of trees are $$$a = [2, 3, 1, 4]$$$.
- If the rabbit starts from the first tree, it can jump to the third tree as $$$3 > 1$$$ and $$$1 < 2$$$. Then, the rabbit can jump to the second tree as $$$2 < 3$$$ and $$$3 > 1$$$. It can be proved that the rabbit cannot reach the fourt... | Title: Penchick and Desert Rabbit
time_limit_ms: 3000
memory_limit_mb: 256
Description: Dedicated to pushing himself to his limits, Penchick challenged himself to survive the midday sun in the Arabian Desert!
While trekking along a linear oasis, Penchick spots a desert rabbit preparing to jump along a line of palm tre... |
2031E | https://codeforces.com/problemset/problem/2031/E | Penchick and Chloe's Trees | 2,100 | [
"dp",
"implementation",
"math",
"data structures",
"sortings",
"dfs and similar",
"greedy",
"trees"
] | Div. 2 | 3,500 | 512 | With just a few hours left until Penchick and Chloe leave for Singapore, they could hardly wait to see the towering trees at the Singapore Botanic Gardens! Attempting to contain their excitement, Penchick crafted a rooted tree to keep Chloe and himself busy.
Penchick has a rooted tree$$$^{\text{∗}}$$$ consisting of $$... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^6$$$) — the number of vertices in Penchick's tree.
The second line... | For each test case, output a single integer on each line: the minimum depth of Chloe's perfect binary tree. | [
[
"5\n6\n1 2 2 1 1\n15\n1 1 2 2 3 3 4 4 5 5 6 6 7 7\n5\n1 2 2 2\n7\n1 1 2 1 1 2\n10\n1 1 1 2 2 2 4 3 3",
"2\n3\n3\n3\n3"
]
] | For the first test case, create a perfect binary tree with depth $$$2$$$.
Consider carrying out the operation on edge $$$AC$$$. Then the edges $$$AC$$$, $$$CF$$$, and $$$CG$$$ are removed, and edges $$$AF$$$ and $$$AG$$$ are added.
The resulting tree is isomorphic to the tree given in the input. It can be proven that... | Title: Penchick and Chloe's Trees
time_limit_ms: 3500
memory_limit_mb: 512
Description: With just a few hours left until Penchick and Chloe leave for Singapore, they could hardly wait to see the towering trees at the Singapore Botanic Gardens! Attempting to contain their excitement, Penchick crafted a rooted tree to ke... |
1999G1 | https://codeforces.com/problemset/problem/1999/G1 | Ruler (easy version) | 1,500 | [
"interactive",
"binary search"
] | Div. 4 | 1,000 | 256 | This is the easy version of the problem. The only difference between the two versions is that in this version, you can make at most $$$\mathbf{10}$$$ queries.
This is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read the guide for participants.
We have a secret ru... | Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. | null | [
[
"2\n\n18\n\n25\n\n\n9999",
"? 3 5\n\n? 4 4\n\n! 4\n? 99 100\n\n! 100"
]
] | In the first test, the interaction proceeds as follows.
SolutionJuryExplanation$$$\texttt{2}$$$There are 2 test cases.$$$\texttt{? 3 5}$$$$$$\texttt{18}$$$Secretly, the jury picked $$$x=4$$$. The solution requests the $$$3 \times 5$$$ rectangle, and the jury responds with $$$3 \times 6 = 18$$$, as described in the sta... | Title: Ruler (easy version)
time_limit_ms: 1000
memory_limit_mb: 256
Description: This is the easy version of the problem. The only difference between the two versions is that in this version, you can make at most $$$\mathbf{10}$$$ queries.
This is an interactive problem. If you are unsure how interactive problems wor... |
1999G2 | https://codeforces.com/problemset/problem/1999/G2 | Ruler (hard version) | 1,700 | [
"ternary search",
"interactive",
"binary search"
] | Div. 4 | 1,000 | 256 | This is the hard version of the problem. The only difference between the two versions is that in this version, you can make at most $$$\mathbf{7}$$$ queries.
This is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read the guide for participants.
We have a secret rul... | Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. | null | [
[
"2\n\n18\n\n25\n\n\n9999",
"? 3 5\n\n? 4 4\n\n! 4\n? 99 100\n\n! 100"
]
] | In the first test, the interaction proceeds as follows.
SolutionJuryExplanation$$$\texttt{2}$$$There are 2 test cases.$$$\texttt{? 3 5}$$$$$$\texttt{18}$$$Secretly, the jury picked $$$x=4$$$. The solution requests the $$$3 \times 5$$$ rectangle, and the jury responds with $$$3 \times 6 = 18$$$, as described in the sta... | Title: Ruler (hard version)
time_limit_ms: 1000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference between the two versions is that in this version, you can make at most $$$\mathbf{7}$$$ queries.
This is an interactive problem. If you are unsure how interactive problems work... |
2041A | https://codeforces.com/problemset/problem/2041/A | The Bento Box Adventure | 1,300 | [
"implementation",
"sortings"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 1,000 | 1,024 | Image generated by ChatGPT 4o.
Boxed meals in Taiwan are very common, offering convenient and affordable nutrition-balanced choices for students and office workers. These meals typically include a variety of vegetables, protein, and rice, providing a well-rounded diet. With numerous options available at local self-ser... | A single line of input containing four integers $$$a, b, c, d$$$, each between 1 and 5 (inclusive), representing the restaurant numbers you visited from Monday to Thursday, in order.
- $$$1\le a, b, c, d\le 5$$$
- All four numbers will be different. | Output the restaurant number you should visit on Friday. | [
[
"1 3 2 5",
"4"
],
[
"2 5 4 3",
"1"
]
] | Title: The Bento Box Adventure
time_limit_ms: 1000
memory_limit_mb: 1024
Description: Image generated by ChatGPT 4o.
Boxed meals in Taiwan are very common, offering convenient and affordable nutrition-balanced choices for students and office workers. These meals typically include a variety of vegetables, protein, and ... | |
2041B | https://codeforces.com/problemset/problem/2041/B | Bowling Frame | 1,200 | [
"brute force",
"binary search",
"math"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 1,000 | 1,024 | Bowling is a national sport in Taiwan; everyone in the country plays the sport on a daily basis since their youth. Naturally, there are a lot of bowling alleys all over the country, and the competition between them is as intense as you can imagine.
Maw-Shang owns one such bowling alley. To stand out from other competi... | The first line of the input contains a single integer $$$t$$$, the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$w$$$ and $$$b$$$, the number of white and black pins, respectively.
- $$$1 \leq t \leq 100$$$
- $$$0 \leq w, b \leq 10^9$$$ | For each test case, output in a single line the side length $$$k$$$ of the largest pin satisfying Maw-Shang's requirement you can build with the given pins. | [
[
"4\n1 2\n3 2\n3 3\n12 0",
"2\n2\n3\n4"
]
] | Title: Bowling Frame
time_limit_ms: 1000
memory_limit_mb: 1024
Description: Bowling is a national sport in Taiwan; everyone in the country plays the sport on a daily basis since their youth. Naturally, there are a lot of bowling alleys all over the country, and the competition between them is as intense as you can imag... | |
2041C | https://codeforces.com/problemset/problem/2041/C | Cube | 2,000 | [
"dfs and similar",
"bitmasks",
"dp"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 3,000 | 1,024 | You are given an $$$n\times n\times n$$$ big three-dimensional cube that contains $$$n^3$$$ numbers. You have to choose $$$n$$$ of those numbers so that their sum is as small as possible. It is, however, forbidden to choose two numbers that are located in the same plane. That is, if we identify the positions in the cub... | The input consists of the number $$$n$$$ followed by $$$n^3$$$ numbers in the cube. The numbers are presented as $$$n$$$ two-dimensional matrices, one for each layer of the cube. More precisely, there will be $$$n^2$$$ lines follow, each having $$$n$$$ numbers. For each $$$x, y, z$$$ ($$$1\le x, y, z\le n$$$), the numb... | The output consists of a single number. It is the minimum sum of $$$n$$$ numbers chosen from the cube according to the above rules. | [
[
"3\n1 2 3\n4 5 6\n7 8 9\n1 1 1\n2 2 2\n3 3 3\n4 3 0\n2 1 4\n9 8 9",
"5"
]
] | Title: Cube
time_limit_ms: 3000
memory_limit_mb: 1024
Description: You are given an $$$n\times n\times n$$$ big three-dimensional cube that contains $$$n^3$$$ numbers. You have to choose $$$n$$$ of those numbers so that their sum is as small as possible. It is, however, forbidden to choose two numbers that are located ... | |
2041D | https://codeforces.com/problemset/problem/2041/D | Drunken Maze | 1,700 | [
"dfs and similar",
"brute force",
"graphs",
"shortest paths"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 1,024 | Image generated by ChatGPT 4o.
You are given a two-dimensional maze with a start and end position. Your task is to find the fastest way to get from the start to the end position. The fastest way is to make the minimum number of steps where one step is going left, right, up, or down. Of course, you cannot walk through ... | The first line contains two numbers $$$n$$$ and $$$m$$$, which are the height and width of the maze. This is followed by an ASCII-representation of the maze where $$$\tt{\#}$$$ is a wall, $$$\tt{.}$$$ is an empty space, and $$$\tt S$$$ and $$$\tt T$$$ are the start and end positions.
- $$$12 \leq n\times m \leq 200000... | The minimum number of steps to reach the end position from the start position or -1 if that is impossible. | [
[
"7 12\n############\n#S........T#\n#.########.#\n#..........#\n#..........#\n#..#..#....#\n############",
"15"
],
[
"5 8\n########\n#......#\n#.####.#\n#...T#S#\n########",
"14"
],
[
"5 8\n########\n#.#S...#\n#.####.#\n#...T#.#\n########",
"-1"
]
] | Title: Drunken Maze
time_limit_ms: 2000
memory_limit_mb: 1024
Description: Image generated by ChatGPT 4o.
You are given a two-dimensional maze with a start and end position. Your task is to find the fastest way to get from the start to the end position. The fastest way is to make the minimum number of steps where one ... | |
2041F | https://codeforces.com/problemset/problem/2041/F | Segmentation Folds | 2,400 | [
"dfs and similar",
"brute force",
"number theory"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 1,000 | 1,024 | Peter loves folding segments. There is a segment on a number line occupying the interval $$$[\ell, r]$$$. Since it is the prime time for folding the segments, Peter decides to fold the segment carefully. In each step, he chooses one of the two following operations whenever possible:
1. Operation $$$\tt{LTR}$$$: he fol... | The first line contains an integer $$$t$$$, denoting the number of test cases. In each of the following $$$t$$$ lines, there are two integers $$$\ell$$$ and $$$r$$$.
- $$$1 \le t \le 10$$$
- $$$1 \le \ell < r \le 10^{12}$$$
- $$$r - \ell \le 10^5$$$ | For each test case, please output a line denoting the number of ways to fold the given segment such that the resulting segment has the shortest possible length, modulo $$$998244353$$$. | [
[
"3\n1 30\n16 18\n142857 240135",
"3\n1\n63"
]
] | Title: Segmentation Folds
time_limit_ms: 1000
memory_limit_mb: 1024
Description: Peter loves folding segments. There is a segment on a number line occupying the interval $$$[\ell, r]$$$. Since it is the prime time for folding the segments, Peter decides to fold the segment carefully. In each step, he chooses one of the... | |
2041H | https://codeforces.com/problemset/problem/2041/H | Sheet Music | 2,300 | [
"combinatorics",
"dp",
"math"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 1,000 | 1,024 | Image generated by ChatGPT 4o.
Alice likes singing. As a singing enthusiast, Alice has listened to countless songs and has tried singing them many times. However, occasionally, some songs make Alice feel bored. After some research, Alice believes that this is because even though the songs she chose are all different, ... | The only line contains two integers $$$n, k$$$.
- $$$1\leq n\leq 10^6$$$
- $$$1\leq k \leq 10^9$$$ | Output the number of different songs modulo $$$998244353$$$. | [
[
"3 2",
"7"
],
[
"5 3",
"67"
]
] | Title: Sheet Music
time_limit_ms: 1000
memory_limit_mb: 1024
Description: Image generated by ChatGPT 4o.
Alice likes singing. As a singing enthusiast, Alice has listened to countless songs and has tried singing them many times. However, occasionally, some songs make Alice feel bored. After some research, Alice believe... | |
2041I | https://codeforces.com/problemset/problem/2041/I | Auto Complete | 2,300 | [
"binary search",
"implementation",
"data structures",
"sortings",
"hashing",
"strings",
"trees"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 4,000 | 1,024 | You are designing a snazzy new text editor, and you want to add a nifty auto-complete feature to help users save time. Here is how it will work: if a user types "App", your editor will magically suggest the word "Application"! Even better, users can personalize the words that auto-complete in your editor.
Your editor ... | The first line contains an integer $$$n$$$, followed by $$$n$$$ lines, with each line containing an action.
There are four types of actions:
1. $$$i$$$ $$$p_i$$$
2. $$$i$$$
3. $$$s$$$
4. $$$c$$$
- $$$1 \leq n \leq 10^6$$$
- The total number of characters in all $$$p_i$$$ and $$$s$$$ does not exceed $$$2\times 10^6$$... | The program should output $$$n$$$ lines. For each action, output an integer $$$i$$$, which means that after the action, $$$p_i$$$ is the suggested auto complete candidate. If there is no $$$p_i$$$ that matches the requirement, output -1. | [
[
"6\nadd 1 pattern1_alice\nadd 2 pattern2_bob\nadd 3 pattern3_charlie\nappend pattern\nappend 2_bobabc\nbackspace 3",
"1\n1\n3\n3\n-1\n2"
],
[
"6\nappend pattern\nadd 1 pattern1_alice____\nadd 2 pattern2_bob______\nadd 3 pattern3_charlie__\ndelete 1\ndelete 2",
"-1\n1\n1\n1\n2\n3"
]
] | Title: Auto Complete
time_limit_ms: 4000
memory_limit_mb: 1024
Description: You are designing a snazzy new text editor, and you want to add a nifty auto-complete feature to help users save time. Here is how it will work: if a user types "App", your editor will magically suggest the word "Application"! Even better, user... | |
2041M | https://codeforces.com/problemset/problem/2041/M | Selection Sort | 2,000 | [
"two pointers",
"data structures",
"binary search",
"greedy"
] | Unrated, Online Mirror, ICPC Rules, Preferably Teams | 2,000 | 1,024 | Every student enrolled in the algorithms course is required to submit an assignment this week. The task is to implement an $$$O(n^2)$$$-time algorithm to sort $$$n$$$ given integers in non-decreasing order. Alice has already completed her assignment, and her implementation is shown below.
While you have access to Alic... | The first line contains exactly one integer $$$n$$$ which indicates the number of integers in the array $$$s$$$. The second line contains the $$$n$$$ integers in $$$s=[s_0, s_1, \ldots, s_{n-1}]$$$.
- $$$1 \le n \le 10^6$$$
- For all $$$i$$$ ($$$0\le i < n$$$), $$$0\le s_i < 2^{31}-1$$$. | Output an integer on a line, indicating the minimum cost to sort the input array $$$s$$$ of $$$n$$$ integers in non-decreasing order using Alice's function, following the rules mentioned above. | [
[
"6\n3 2 5 5 4 1",
"25"
],
[
"4\n4 3 2 1",
"16"
]
] | Title: Selection Sort
time_limit_ms: 2000
memory_limit_mb: 1024
Description: Every student enrolled in the algorithms course is required to submit an assignment this week. The task is to implement an $$$O(n^2)$$$-time algorithm to sort $$$n$$$ given integers in non-decreasing order. Alice has already completed her assi... | |
2045A | https://codeforces.com/problemset/problem/2045/A | Scrambled Scrabble | 1,700 | [
"greedy",
"brute force"
] | Unrated, Online Mirror, ICPC Rules, Teams Preferred | 1,000 | 1,024 | You are playing a word game using a standard set of $$$26$$$ uppercase English letters: A — Z. In this game, you can form vowels and consonants as follows.
- The letters A, E, I, O, and U can only form a vowel.
- The letter Y can form either a vowel or a consonant.
- Each of the remaining letters other than A, E, I, O... | A single line consisting of a string $$$S$$$ ($$$1 \leq |S| \leq 5000$$$). The string $$$S$$$ consists of only uppercase English letters. | If a word cannot be created, output 0. Otherwise, output a single integer representing the length of longest word that can be created. | [
[
"ICPCJAKARTA",
"9"
],
[
"NGENG",
"5"
],
[
"YYY",
"3"
],
[
"DANGAN",
"6"
],
[
"AEIOUY",
"0"
]
] | Explanation for the sample input/output #1
A possible longest word is JAKCARTAP, consisting of the syllables JAK, CAR, and TAP.
Explanation for the sample input/output #2
The whole string $$$S$$$ is a word consisting of one syllable which is the concatenation of the consonant NG, the vowel E, and the consonant NG.
... | Title: Scrambled Scrabble
time_limit_ms: 1000
memory_limit_mb: 1024
Description: You are playing a word game using a standard set of $$$26$$$ uppercase English letters: A — Z. In this game, you can form vowels and consonants as follows.
- The letters A, E, I, O, and U can only form a vowel.
- The letter Y can form eit... |
2045B | https://codeforces.com/problemset/problem/2045/B | ICPC Square | 2,000 | [
"math",
"number theory"
] | Unrated, Online Mirror, ICPC Rules, Teams Preferred | 1,000 | 1,024 | ICPC Square is a hotel provided by the ICPC Committee for the accommodation of the participants. It consists of $$$N$$$ floors (numbered from $$$1$$$ to $$$N$$$). This hotel has a very unique elevator. If a person is currently at floor $$$x$$$, by riding the elevator once, they can go to floor $$$y$$$ if and only if $$... | A single line consisting of three integers $$$N$$$ $$$D$$$ $$$S$$$ ($$$2 \leq N \leq 10^{12}; 1 \leq D \leq N - 1; 1 \leq S \leq N$$$). | Output a single integer representing the highest floor you can reach by riding the elevator zero or more times. | [
[
"64 35 3",
"60"
],
[
"2024 2023 1273",
"1273"
]
] | Explanation for the sample input/output #1
First, ride the elevator from floor $$$3$$$ to floor $$$15$$$. This is possible because $$$15$$$ is a multiple of $$$3$$$ and $$$15 - 3 \leq 35$$$. Then, ride the elevator from floor $$$15$$$ to floor $$$30$$$. This is possible because $$$30$$$ is a multiple of $$$15$$$ and $... | Title: ICPC Square
time_limit_ms: 1000
memory_limit_mb: 1024
Description: ICPC Square is a hotel provided by the ICPC Committee for the accommodation of the participants. It consists of $$$N$$$ floors (numbered from $$$1$$$ to $$$N$$$). This hotel has a very unique elevator. If a person is currently at floor $$$x$$$, b... |
2045G | https://codeforces.com/problemset/problem/2045/G | X Aura | 2,200 | [
"shortest paths",
"graphs",
"math"
] | Unrated, Online Mirror, ICPC Rules, Teams Preferred | 1,000 | 1,024 | Mount ICPC can be represented as a grid of $$$R$$$ rows (numbered from $$$1$$$ to $$$R$$$) and $$$C$$$ columns (numbered from $$$1$$$ to $$$C$$$). The cell located at row $$$r$$$ and column $$$c$$$ is denoted as $$$(r, c)$$$ and has a height of $$$H_{r, c}$$$. Two cells are adjacent to each other if they share a side. ... | The first line consists of three integers $$$R$$$ $$$C$$$ $$$X$$$ ($$$1 \leq R, C \leq 1000; 1 \leq X \leq 9; X$$$ is an odd integer).
Each of the next $$$R$$$ lines consists of a string $$$H_r$$$ of length $$$C$$$. Each character in $$$H_r$$$ is a number from 0 to 9. The $$$c$$$-th character of $$$H_r$$$ represents t... | For each scenario, output the following in a single line. If the scenario is invalid, output INVALID. Otherwise, output a single integer representing the minimum total penalty to move from the starting cell to the destination cell. | [
[
"3 4 1\n3359\n4294\n3681\n5\n1 1 3 4\n3 3 2 1\n2 2 1 4\n1 3 3 2\n1 1 1 1",
"2\n4\n-7\n-1\n0"
],
[
"2 4 5\n1908\n2023\n2\n1 1 2 4\n1 1 1 1",
"INVALID\nINVALID"
],
[
"3 3 9\n135\n357\n579\n2\n3 3 1 1\n2 2 2 2",
"2048\n0"
]
] | Explanation for the sample input/output #1
For the first scenario, one of the solutions is to move as follows: $$$(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$$$. The total penalty of this solution is $$$(3 - 4)^1 + (4 - 3)^1 + (3 - 6)^1 + (6 - 8)^1 + (8 - 1)^1 ... | Title: X Aura
time_limit_ms: 1000
memory_limit_mb: 1024
Description: Mount ICPC can be represented as a grid of $$$R$$$ rows (numbered from $$$1$$$ to $$$R$$$) and $$$C$$$ columns (numbered from $$$1$$$ to $$$C$$$). The cell located at row $$$r$$$ and column $$$c$$$ is denoted as $$$(r, c)$$$ and has a height of $$$H_{... |
2045I | https://codeforces.com/problemset/problem/2045/I | Microwavable Subsequence | 2,100 | [
"data structures"
] | Unrated, Online Mirror, ICPC Rules, Teams Preferred | 1,000 | 1,024 | You are given an array of $$$N$$$ integers: $$$[A_1, A_2, \dots, A_N]$$$.
A subsequence can be derived from an array by removing zero or more elements without changing the order of the remaining elements. For example, $$$[2, 1, 2]$$$, $$$[3, 3]$$$, $$$[1]$$$, and $$$[3, 2, 1, 3, 2]$$$ are subsequences of array $$$[3, ... | The first line consists of two integers $$$N$$$ $$$M$$$ ($$$1 \leq N, M \leq 300\,000$$$).
The second line consists of $$$N$$$ integers $$$A_i$$$ ($$$1 \leq A_i \leq M$$$). | Output a single integer representing the sum of $$$f(x, y)$$$ for all $$$1 \leq x < y \leq M$$$. | [
[
"5 4\n3 2 1 3 2",
"13"
],
[
"3 3\n1 1 1",
"2"
]
] | Explanation for the sample input/output #1
The value of $$$f(1, 2)$$$ is $$$3$$$, taken from the subsequence $$$[2, 1, 2]$$$ that can be obtained by removing $$$A_1$$$ and $$$A_4$$$. The value of $$$f(1, 3)$$$ is $$$3$$$, taken from the subsequence $$$[3, 1, 3]$$$ that can be obtained by removing $$$A_2$$$ and $$$A_5$... | Title: Microwavable Subsequence
time_limit_ms: 1000
memory_limit_mb: 1024
Description: You are given an array of $$$N$$$ integers: $$$[A_1, A_2, \dots, A_N]$$$.
A subsequence can be derived from an array by removing zero or more elements without changing the order of the remaining elements. For example, $$$[2, 1, 2]$$... |
2045M | https://codeforces.com/problemset/problem/2045/M | Mirror Maze | 1,800 | [
"dfs and similar",
"brute force",
"graphs",
"implementation"
] | Unrated, Online Mirror, ICPC Rules, Teams Preferred | 1,000 | 1,024 | You are given a grid of $$$R$$$ rows (numbered from $$$1$$$ to $$$R$$$ from north to south) and $$$C$$$ columns (numbered from $$$1$$$ to $$$C$$$ from west to east). Every cell in this grid is a square of the same size. The cell located at row $$$r$$$ and column $$$c$$$ is denoted as $$$(r, c)$$$. Each cell can either ... | The first line consists of two integers $$$R$$$ $$$C$$$ ($$$1 \leq R, C \leq 200$$$).
Each of the next $$$R$$$ lines consists of a string $$$S_r$$$ of length $$$C$$$. The $$$c$$$-th character of string $$$S_r$$$ represents cell $$$(r, c)$$$. Each character can either be . if the cell is empty, / if the cell has type $... | Output a single integer representing the number of possible locations for the laser such that all mirrors are hit by the laser beam. Denote this number as $$$k$$$.
If $$$k > 0$$$, then output $$$k$$$ space-separated strings representing the location of the laser. Each string consists of a character followed without an... | [
[
"4 4\n.//.\n.\\\\.\n.\\/.\n....",
"2\nN3 W2"
],
[
"4 6\n./..\\.\n.\\...\\\n./../\\\n......",
"2\nE3 S2"
],
[
"4 4\n....\n./\\.\n.\\/.\n....",
"0"
]
] | Explanation for the sample input/output #1
The following illustration shows one of the solutions of this sample.
Explanation for the sample input/output #2
The following illustration shows one of the solutions of this sample. | Title: Mirror Maze
time_limit_ms: 1000
memory_limit_mb: 1024
Description: You are given a grid of $$$R$$$ rows (numbered from $$$1$$$ to $$$R$$$ from north to south) and $$$C$$$ columns (numbered from $$$1$$$ to $$$C$$$ from west to east). Every cell in this grid is a square of the same size. The cell located at row $$... |
2051A | https://codeforces.com/problemset/problem/2051/A | Preparing for the Olympiad | 800 | [
"greedy"
] | Div. 3 | 2,000 | 256 | Monocarp and Stereocarp are preparing for the Olympiad. There are $$$n$$$ days left until the Olympiad. On the $$$i$$$-th day, if Monocarp plans to practice, he will solve $$$a_i$$$ problems. Similarly, if Stereocarp plans to practice on the same day, he will solve $$$b_i$$$ problems.
Monocarp can train on any day he ... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$).
The third line contains $$$... | For each test case, print a single integer — the maximum possible difference between the number of problems Monocarp solves and the number of problems Stereocarp solves. | [
[
"4\n2\n3 2\n2 1\n1\n5\n8\n3\n1 1 1\n2 2 2\n6\n8 2 5 6 2 6\n8 2 7 4 3 4",
"4\n5\n1\n16"
]
] | Let's analyze the example from the statement:
- In the first test case, it is optimal for Monocarp to train both days; then Stereocarp will train on day $$$2$$$.
- In the second test case, it is optimal for Monocarp to train on the only day, and Stereocarp will not train at all.
- In the third test case, it is optimal... | Title: Preparing for the Olympiad
time_limit_ms: 2000
memory_limit_mb: 256
Description: Monocarp and Stereocarp are preparing for the Olympiad. There are $$$n$$$ days left until the Olympiad. On the $$$i$$$-th day, if Monocarp plans to practice, he will solve $$$a_i$$$ problems. Similarly, if Stereocarp plans to practi... |
2051B | https://codeforces.com/problemset/problem/2051/B | Journey | 800 | [
"binary search",
"math"
] | Div. 3 | 1,000 | 256 | Monocarp decided to embark on a long hiking journey.
He decided that on the first day he would walk $$$a$$$ kilometers, on the second day he would walk $$$b$$$ kilometers, on the third day he would walk $$$c$$$ kilometers, on the fourth day, just like on the first, he would walk $$$a$$$ kilometers, on the fifth day, j... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of one line containing four integers $$$n$$$, $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le a, b, c \le 10^6$$$). | For each test case, output one integer — the day on which Monocarp will have walked at least $$$n$$$ kilometers in total and will complete his journey. | [
[
"4\n12 1 5 3\n6 6 7 4\n16 3 4 1\n1000000000 1 1 1",
"5\n1\n6\n1000000000"
]
] | In the first example, over the first four days, Monocarp will cover $$$1 + 5 + 3 + 1 = 10$$$ kilometers. On the fifth day, he will cover another $$$5$$$ kilometers, meaning that in total over five days he will have covered $$$10 + 5 = 15$$$ kilometers. Since $$$n = 12$$$, Monocarp will complete his journey on the fifth... | Title: Journey
time_limit_ms: 1000
memory_limit_mb: 256
Description: Monocarp decided to embark on a long hiking journey.
He decided that on the first day he would walk $$$a$$$ kilometers, on the second day he would walk $$$b$$$ kilometers, on the third day he would walk $$$c$$$ kilometers, on the fourth day, just lik... |
2051C | https://codeforces.com/problemset/problem/2051/C | Preparing for the Exam | 1,000 | [
"constructive algorithms",
"implementation"
] | Div. 3 | 1,500 | 256 | Monocarp is preparing for his first exam at the university. There are $$$n$$$ different questions which can be asked during the exam, numbered from $$$1$$$ to $$$n$$$. There are $$$m$$$ different lists of questions; each list consists of exactly $$$n-1$$$ different questions. Each list $$$i$$$ is characterized by one i... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of three lines:
- the first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le m, k \le n$$$);
- the second line contains $$$m$$$ distinct integers ... | For each test case, print a string of $$$m$$$ characters. The $$$i$$$-th character should be 1 if Monocarp passes the exam if he receives the $$$i$$$-th question list, 0 if Monocarp won't pass. | [
[
"4\n4 4 3\n1 2 3 4\n1 3 4\n5 4 3\n1 2 3 4\n1 3 4\n4 4 4\n1 2 3 4\n1 2 3 4\n2 2 1\n1 2\n2",
"0100\n0000\n1111\n10"
]
] | In the first test case, Monocarp knows the questions $$$[1, 3, 4]$$$. Let's consider all the question lists:
- the first list consists of questions $$$[2, 3, 4]$$$. Monocarp doesn't know the $$$2$$$-nd question, so he won't pass;
- the second list consists of questions $$$[1, 3, 4]$$$. Monocarp knows all these questio... | Title: Preparing for the Exam
time_limit_ms: 1500
memory_limit_mb: 256
Description: Monocarp is preparing for his first exam at the university. There are $$$n$$$ different questions which can be asked during the exam, numbered from $$$1$$$ to $$$n$$$. There are $$$m$$$ different lists of questions; each list consists o... |
2051D | https://codeforces.com/problemset/problem/2051/D | Counting Pairs | 1,200 | [
"two pointers",
"binary search",
"sortings"
] | Div. 3 | 2,000 | 256 | You are given a sequence $$$a$$$, consisting of $$$n$$$ integers, where the $$$i$$$-th element of the sequence is equal to $$$a_i$$$. You are also given two integers $$$x$$$ and $$$y$$$ ($$$x \le y$$$).
A pair of integers $$$(i, j)$$$ is considered interesting if the following conditions are met:
- $$$1 \le i < j \le... | The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of two lines:
- The first line contains three integers $$$n, x, y$$$ ($$$3 \le n \le 2 \cdot 10^5$$$, $$$1 \le x \le y \le 2 \cdot 10^{14}$$$);
- The second line contains $$$n$$$ integers $$$a_1, a... | For each test case, output one integer — the number of interesting pairs of integers for the given sequence $$$a$$$. | [
[
"7\n4 8 10\n4 6 3 6\n6 22 27\n4 9 6 3 4 5\n3 8 10\n3 2 1\n3 1 1\n2 3 4\n3 3 6\n3 2 1\n4 4 12\n3 3 2 1\n6 8 8\n1 1 2 2 2 3",
"4\n7\n0\n0\n1\n5\n6"
]
] | In the first example, there are $$$4$$$ interesting pairs of integers:
1. $$$(1, 2)$$$;
2. $$$(1, 4)$$$;
3. $$$(2, 3)$$$;
4. $$$(3, 4)$$$. | Title: Counting Pairs
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a sequence $$$a$$$, consisting of $$$n$$$ integers, where the $$$i$$$-th element of the sequence is equal to $$$a_i$$$. You are also given two integers $$$x$$$ and $$$y$$$ ($$$x \le y$$$).
A pair of integers $$$(i, j)$$$ is consi... |
2051E | https://codeforces.com/problemset/problem/2051/E | Best Price | 1,600 | [
"brute force",
"binary search",
"data structures",
"sortings",
"greedy"
] | Div. 3 | 2,000 | 256 | A batch of Christmas trees has arrived at the largest store in Berland. $$$n$$$ customers have already come to the store, wanting to buy them.
Before the sales begin, the store needs to determine the price for one tree (the price is the same for all customers). To do this, the store has some information about each cus... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$0 \le k \le n$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le... | For each test case, print a single integer — the maximum possible earnings for the store, given that it can receive no more than $$$k$$$ negative reviews. | [
[
"5\n2 0\n2 1\n3 4\n1 1\n2\n5\n3 3\n1 5 2\n3 6 4\n4 3\n2 3 2 8\n3 7 3 9\n3 1\n2 9 5\n12 14 9",
"2\n5\n9\n14\n15"
]
] | Consider the example from the statement:
- In the first test case, the price should be set to $$$1$$$. Then both customers will buy one tree each and leave no negative reviews;
- In the second test case, the price should be set to $$$5$$$. Then the only customer will buy a tree and leave a negative review;
- In the th... | Title: Best Price
time_limit_ms: 2000
memory_limit_mb: 256
Description: A batch of Christmas trees has arrived at the largest store in Berland. $$$n$$$ customers have already come to the store, wanting to buy them.
Before the sales begin, the store needs to determine the price for one tree (the price is the same for a... |
2051F | https://codeforces.com/problemset/problem/2051/F | Joker | 2,000 | [
"greedy",
"brute force",
"implementation",
"math"
] | Div. 3 | 2,000 | 256 | Consider a deck of $$$n$$$ cards. The positions in the deck are numbered from $$$1$$$ to $$$n$$$ from top to bottom. A joker is located at position $$$m$$$.
$$$q$$$ operations are applied sequentially to the deck. During the $$$i$$$-th operation, you need to take the card at position $$$a_i$$$ and move it either to th... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$2 \le n \le 10^9$$$; $$$1 \le m \le n$$$; $$$1 \le q \le 2 \cdot 10^5$$$).
The second line contains $$$q$$$ integers $$$a_1, ... | For each test case, print $$$q$$$ integers — the number of distinct positions where the joker can be after each operation. | [
[
"5\n6 5 3\n1 2 3\n2 1 4\n2 1 1 2\n5 3 1\n3\n3 2 4\n2 1 1 1\n18 15 4\n13 15 1 16",
"2 3 5 \n2 2 2 2 \n2 \n2 3 3 3 \n2 4 6 8"
]
] | Title: Joker
time_limit_ms: 2000
memory_limit_mb: 256
Description: Consider a deck of $$$n$$$ cards. The positions in the deck are numbered from $$$1$$$ to $$$n$$$ from top to bottom. A joker is located at position $$$m$$$.
$$$q$$$ operations are applied sequentially to the deck. During the $$$i$$$-th operation, you n... | |
2051G | https://codeforces.com/problemset/problem/2051/G | Snakes | 2,100 | [
"graphs",
"bitmasks",
"dp",
"dsu"
] | Div. 3 | 3,000 | 512 | Suppose you play a game where the game field looks like a strip of $$$1 \times 10^9$$$ square cells, numbered from $$$1$$$ to $$$10^9$$$.
You have $$$n$$$ snakes (numbered from $$$1$$$ to $$$n$$$) you need to place into some cells. Initially, each snake occupies exactly one cell, and you can't place more than one snak... | The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 20$$$; $$$1 \le q \le 2 \cdot 10^5$$$) — the number of snakes and the number of events. Next $$$q$$$ lines contain the description of events — one per line.
The $$$i$$$-th line contains
- either "$$$s_i$$$ +" ($$$1 \le s_i \le n$$$) meaning that... | Print one integer — the minimum possible score. | [
[
"3 6\n1 +\n1 -\n3 +\n3 -\n2 +\n2 -",
"4"
],
[
"5 13\n5 +\n3 +\n5 -\n2 +\n4 +\n3 +\n5 +\n5 -\n2 +\n3 -\n3 +\n3 -\n2 +",
"11"
]
] | In the first test, the optimal strategy is to place the second snake at cell $$$1$$$, the third snake — at $$$2$$$, and the first one — at $$$3$$$. The maximum occupied cell is cell $$$4$$$, and it's the minimum possible score.
In the second test, one of the optimal strategies is to place:
- snake $$$2$$$ at position... | Title: Snakes
time_limit_ms: 3000
memory_limit_mb: 512
Description: Suppose you play a game where the game field looks like a strip of $$$1 \times 10^9$$$ square cells, numbered from $$$1$$$ to $$$10^9$$$.
You have $$$n$$$ snakes (numbered from $$$1$$$ to $$$n$$$) you need to place into some cells. Initially, each sna... |
2049A | https://codeforces.com/problemset/problem/2049/A | MEX Destruction | 800 | [
"greedy",
"implementation"
] | Div. 2 | 1,000 | 256 | Evirir the dragon snuck into a wizard's castle and found a mysterious contraption, and their playful instincts caused them to play with (destroy) it...
Evirir the dragon found an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ non-negative integers.
In one operation, they can choose a non-empty subarray$$$^{\text{∗}}$$$... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$), the length of $$$a$$$.
The second line of each test case conta... | For each test case, output a single integer on a line, the minimum number of operations needed to make $$$a$$$ contain only zeros. | [
[
"10\n4\n0 1 2 3\n6\n0 0 0 0 0 0\n5\n1 0 1 0 1\n5\n3 1 4 1 5\n4\n3 2 1 0\n7\n9 100 0 89 12 2 3\n4\n0 3 9 0\n7\n0 7 0 2 0 7 0\n1\n0\n2\n0 1",
"1\n0\n2\n1\n1\n2\n1\n2\n0\n1"
]
] | In the first test case, Evirir can choose the subarray $$$b = [1, 2, 3]$$$ and replace it with $$$\operatorname{mex}(1, 2, 3) = 0$$$, changing $$$a$$$ from $$$[0, \underline{1, 2, 3}]$$$ to $$$[0, 0]$$$ (where the chosen subarray is underlined). Therefore, the answer is $$$1$$$.
In the second test case, $$$a$$$ alread... | Title: MEX Destruction
time_limit_ms: 1000
memory_limit_mb: 256
Description: Evirir the dragon snuck into a wizard's castle and found a mysterious contraption, and their playful instincts caused them to play with (destroy) it...
Evirir the dragon found an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ non-negative integ... |
2049B | https://codeforces.com/problemset/problem/2049/B | pspspsps | 1,300 | [
"constructive algorithms",
"graph matchings",
"brute force",
"implementation"
] | Div. 2 | 1,000 | 256 | Cats are attracted to pspspsps, but Evirir, being a dignified dragon, is only attracted to pspspsps with oddly specific requirements...
Given a string $$$s = s_1s_2\ldots s_n$$$ of length $$$n$$$ consisting of characters p, s, and . (dot), determine whether a permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$ exis... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 500$$$), the length of $$$s$$$.
The second line of each test case con... | For each test case, output YES or NO on a line. Output YES if there is such a permutation and NO otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"9\n4\ns.sp\n6\npss..s\n5\nppppp\n2\nsp\n4\n.sp.\n8\npsss....\n1\n.\n8\npspspsps\n20\n....................",
"YES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES"
]
] | For the first test case, one permutation that works is $$$p = [3, 4, 1, 2]$$$. The restrictions are as follows:
- $$$s_1 =$$$ s: $$$[p_1, p_2, p_3, p_4] = [3, 4, 1, 2]$$$ forms a permutation.
- $$$s_2 =$$$ .: No additional restriction.
- $$$s_3 =$$$ s: $$$[p_3, p_4] = [1, 2]$$$ forms a permutation.
- $$$s_4 =$$$ p: $$... | Title: pspspsps
time_limit_ms: 1000
memory_limit_mb: 256
Description: Cats are attracted to pspspsps, but Evirir, being a dignified dragon, is only attracted to pspspsps with oddly specific requirements...
Given a string $$$s = s_1s_2\ldots s_n$$$ of length $$$n$$$ consisting of characters p, s, and . (dot), determine... |
2049D | https://codeforces.com/problemset/problem/2049/D | Shift + Esc | 1,900 | [
"brute force",
"dp"
] | Div. 2 | 2,500 | 512 | After having fun with a certain contraption and getting caught, Evirir the dragon decides to put their magical skills to good use — warping reality to escape fast!
You are given a grid with $$$n$$$ rows and $$$m$$$ columns of non-negative integers and an integer $$$k$$$. Let $$$(i, j)$$$ denote the cell in the $$$i$$$... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line contains three space-separated integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq n, m \leq 200$$$, $$$0 \leq k \leq 10^9$$$).
Then, $$$n$... | For each test case, output a single integer, the minimum cost to move from $$$(1, 1)$$$ to $$$(n, m)$$$. | [
[
"5\n3 3 100\n3 4 9\n5 2 4\n0 101 101\n3 4 1\n10 0 0 10\n0 0 10 0\n10 10 0 10\n1 1 3\n4\n3 2 3\n1 2\n3 6\n5 4\n10 10 14\n58 49 25 12 89 69 8 49 71 23\n45 27 65 59 36 100 73 23 5 84\n82 91 54 92 53 15 43 46 11 65\n61 69 71 87 67 72 51 42 55 80\n1 64 8 54 61 70 47 100 84 50\n86 93 43 51 47 35 56 20 33 61\n100 59... | In the first test case, the minimum cost of $$$113$$$ can be achieved as follows:
1. Cyclically shift row 3 once. The grid now becomes $$$$$$\begin{bmatrix}3 & 4 & 9\\5 & 2 & 4\\101 & 101 & 0\end{bmatrix}.$$$$$$
2. Move as follows: $$$(1, 1) \to (1, 2) \to (2, 2) \to (2, 3) \to (3, 3)$$$.
$$$x = 1$$$ operation is don... | Title: Shift + Esc
time_limit_ms: 2500
memory_limit_mb: 512
Description: After having fun with a certain contraption and getting caught, Evirir the dragon decides to put their magical skills to good use — warping reality to escape fast!
You are given a grid with $$$n$$$ rows and $$$m$$$ columns of non-negative integer... |
2049E | https://codeforces.com/problemset/problem/2049/E | Broken Queries | 2,400 | [
"brute force",
"binary search",
"implementation",
"constructive algorithms",
"interactive",
"bitmasks"
] | Div. 2 | 2,000 | 256 | You, a wizard whose creation was destroyed by a dragon, are determined to hunt it down with a magical AOE tracker. But it seems to be toyed with...
This is an interactive problem.
There is a hidden binary array $$$a$$$ of length $$$n$$$ ($$$\mathbf{n}$$$ is a power of 2) and a hidden integer $$$k\ (2 \le k \le n - 1)... | null | null | [
[
"2\n8\n\n0\n\n0\n\n1\n\n0\n\n4\n\n1\n\n0",
"? 3 5\n\n? 1 8\n\n? 4 8\n\n? 3 8\n\n! 6\n\n? 3 3\n\n? 3 4\n\n! 2"
]
] | In the first test case, $$$k = 6$$$ and the 1 in the hidden array is at index 6, so $$$a = [0, 0, 0, 0, 0, 1, 0, 0]$$$.
- For the query 3 5, since $$$5-3+1 = 3 < k$$$, the device answers correctly. Since 6 is not contained in the range $$$[3, 5]$$$, the device answers $$$0$$$.
- For the query 1 8, since $$$8 - 1 + 1 =... | Title: Broken Queries
time_limit_ms: 2000
memory_limit_mb: 256
Description: You, a wizard whose creation was destroyed by a dragon, are determined to hunt it down with a magical AOE tracker. But it seems to be toyed with...
This is an interactive problem.
There is a hidden binary array $$$a$$$ of length $$$n$$$ ($$$\... |
2037A | https://codeforces.com/problemset/problem/2037/A | Twice | 800 | [
"implementation"
] | Div. 3 | 1,000 | 256 | Kinich wakes up to the start of a new day. He turns on his phone, checks his mailbox, and finds a mysterious present. He decides to unbox the present.
Kinich unboxes an array $$$a$$$ with $$$n$$$ integers. Initially, Kinich's score is $$$0$$$. He will perform the following operation any number of times:
- Select two ... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 20$$$) — the length of $$$a$$$.
The following line of each test case contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$... | For each test case, output the maximum score achievable on a new line. | [
[
"5\n1\n1\n2\n2 2\n2\n1 2\n4\n1 2 3 1\n6\n1 2 3 1 2 3",
"0\n1\n0\n1\n3"
]
] | In the first and third testcases, Kinich cannot perform any operations.
In the second testcase, Kinich can perform one operation with $$$i=1$$$ and $$$j=2$$$.
In the fourth testcase, Kinich can perform one operation with $$$i=1$$$ and $$$j=4$$$. | Title: Twice
time_limit_ms: 1000
memory_limit_mb: 256
Description: Kinich wakes up to the start of a new day. He turns on his phone, checks his mailbox, and finds a mysterious present. He decides to unbox the present.
Kinich unboxes an array $$$a$$$ with $$$n$$$ integers. Initially, Kinich's score is $$$0$$$. He will ... |
2037C | https://codeforces.com/problemset/problem/2037/C | Superultra's Favorite Permutation | 1,000 | [
"constructive algorithms",
"greedy",
"math",
"number theory"
] | Div. 3 | 2,000 | 256 | Superultra, a little red panda, desperately wants primogems. In his dreams, a voice tells him that he must solve the following task to obtain a lifetime supply of primogems. Help Superultra!
Construct a permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$ such that $$$p_i + p_{i+1}$$$ is composite$$$^{\text{†}}$$$ o... | The first line contains $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
Each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the length of the permutation.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | For each test case, if it's not possible to construct $$$p$$$, output $$$-1$$$ on a new line. Otherwise, output $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$ on a new line. | [
[
"2\n3\n8",
"-1\n1 8 7 3 6 2 4 5"
]
] | In the first example, it can be shown that all permutation of size $$$3$$$ contain two adjacent elements whose sum is prime. For example, in the permutation $$$[2,3,1]$$$ the sum $$$2+3=5$$$ is prime.
In the second example, we can verify that the sample output is correct because $$$1+8$$$, $$$8+7$$$, $$$7+3$$$, $$$3+6... | Title: Superultra's Favorite Permutation
time_limit_ms: 2000
memory_limit_mb: 256
Description: Superultra, a little red panda, desperately wants primogems. In his dreams, a voice tells him that he must solve the following task to obtain a lifetime supply of primogems. Help Superultra!
Construct a permutation$$$^{\text... |
2037D | https://codeforces.com/problemset/problem/2037/D | Sharky Surfing | 1,300 | [
"two pointers",
"data structures",
"greedy"
] | Div. 3 | 3,000 | 256 | Mualani loves surfing on her sharky surfboard!
Mualani's surf path can be modeled by a number line. She starts at position $$$1$$$, and the path ends at position $$$L$$$. When she is at position $$$x$$$ with a jump power of $$$k$$$, she can jump to any integer position in the interval $$$[x, x+k]$$$. Initially, her ju... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$L$$$ ($$$1 \leq n, m \leq 2 \cdot 10^5, 3 \leq L \leq 10^9$$$) — the number of hurdles, the number of power-ups, and the position of the en... | For each test case, output the minimum number of power-ups she must collect to reach position $$$L$$$. If it is not possible, output $$$-1$$$. | [
[
"4\n2 5 50\n7 14\n30 40\n2 2\n3 1\n3 5\n18 2\n22 32\n4 3 50\n4 6\n15 18\n20 26\n34 38\n1 2\n8 2\n10 2\n1 4 17\n10 14\n1 6\n1 2\n1 2\n16 9\n1 2 10\n5 9\n2 3\n2 2",
"4\n-1\n1\n2"
]
] | In the first test case, she can collect power-ups $$$1$$$, $$$2$$$, $$$3$$$, and $$$5$$$ to clear all hurdles.
In the second test case, she cannot jump over the first hurdle.
In the fourth test case, by collecting both power-ups, she can jump over the hurdle. | Title: Sharky Surfing
time_limit_ms: 3000
memory_limit_mb: 256
Description: Mualani loves surfing on her sharky surfboard!
Mualani's surf path can be modeled by a number line. She starts at position $$$1$$$, and the path ends at position $$$L$$$. When she is at position $$$x$$$ with a jump power of $$$k$$$, she can ju... |
2037E | https://codeforces.com/problemset/problem/2037/E | Kachina's Favorite Binary String | 1,600 | [
"interactive",
"greedy",
"dp",
"two pointers"
] | Div. 3 | 2,000 | 256 | This is an interactive problem.
Kachina challenges you to guess her favorite binary string$$$^{\text{∗}}$$$ $$$s$$$ of length $$$n$$$. She defines $$$f(l, r)$$$ as the number of subsequences$$$^{\text{†}}$$$ of $$$\texttt{01}$$$ in $$$s_l s_{l+1} \ldots s_r$$$. Two subsequences are considered different if they are for... | The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^4$$$) — the length of $$$s$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$... | null | [
[
"2\n5\n\n4\n\n0\n\n1\n\n2\n\n2\n\n0",
"? 1 5\n\n? 2 4\n\n? 4 5\n\n? 3 5\n\n! 01001\n\n? 1 2\n\n! IMPOSSIBLE"
]
] | In the first test case:
In the first query, you ask Kachina for the value of $$$f(1, 5)$$$, and she responds with $$$4$$$ in the input stream.
In the second query, you ask Kachina for the value of $$$f(2, 4)$$$. Because there are no subsequences of $$$\texttt{01}$$$ in the string $$$\texttt{100}$$$, she responds with... | Title: Kachina's Favorite Binary String
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is an interactive problem.
Kachina challenges you to guess her favorite binary string$$$^{\text{∗}}$$$ $$$s$$$ of length $$$n$$$. She defines $$$f(l, r)$$$ as the number of subsequences$$$^{\text{†}}$$$ of $$$\texttt{01}... |
2037F | https://codeforces.com/problemset/problem/2037/F | Ardent Flames | 2,100 | [
"binary search",
"math",
"data structures",
"two pointers",
"sortings"
] | Div. 3 | 4,000 | 256 | You have obtained the new limited event character Xilonen. You decide to use her in combat.
There are $$$n$$$ enemies in a line. The $$$i$$$'th enemy from the left has health $$$h_i$$$ and is currently at position $$$x_i$$$. Xilonen has an attack damage of $$$m$$$, and you are ready to defeat the enemies with her.
Xi... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) – the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq k \leq n \leq 10^5$$$, $$$1 \leq m \leq 10^9$$$).
The following line contains $$$n$$$ integers $$$h_1, h_2, ..., h_n$$$ ($... | For each test case, output an integer on a new line, the minimum number of attacks that must be performed to defeat at least $$$k$$$ enemies. If it is impossible to find a $$$p$$$ such that eventually at least $$$k$$$ enemies will be defeated, output $$$-1$$$ instead. | [
[
"6\n5 5 3\n7 7 7 7 7\n1 2 3 4 5\n9 5 9\n2 4 6 8 10 8 6 4 2\n1 2 3 4 5 6 7 8 9\n2 10 2\n1 1\n1 20\n2 10 1\n69696969 420420420\n1 20\n2 10 2\n10 15\n1 19\n2 2 2\n1000000000 1\n1 3",
"2\n2\n-1\n6969697\n15\n1000000000"
]
] | In the first testcase, it is optimal to select $$$p=2$$$. Each attack, the first enemy takes $$$5-|2-1|=4$$$ damage, the second enemy takes $$$5$$$ damage, the third enemy takes $$$4$$$ damage, the fourth enemy takes $$$3$$$ damage, and the fifth enemy takes $$$2$$$ damage. After $$$2$$$ attacks, the first three enemie... | Title: Ardent Flames
time_limit_ms: 4000
memory_limit_mb: 256
Description: You have obtained the new limited event character Xilonen. You decide to use her in combat.
There are $$$n$$$ enemies in a line. The $$$i$$$'th enemy from the left has health $$$h_i$$$ and is currently at position $$$x_i$$$. Xilonen has an atta... |
2037G | https://codeforces.com/problemset/problem/2037/G | Natlan Exploring | 2,000 | [
"dp",
"math",
"data structures",
"number theory",
"combinatorics",
"bitmasks"
] | Div. 3 | 4,000 | 256 | You are exploring the stunning region of Natlan! This region consists of $$$n$$$ cities, and each city is rated with an attractiveness $$$a_i$$$. A directed edge exists from City $$$i$$$ to City $$$j$$$ if and only if $$$i < j$$$ and $$$\gcd(a_i,a_j)\neq 1$$$, where $$$\gcd(x, y)$$$ denotes the greatest common divisor ... | The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of cities.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$2 \leq a_i \leq 10^6$$$) — the attractiveness of each city. | Output the total number of distinct paths you can take to reach City $$$n$$$, modulo $$$998\,244\,353$$$. | [
[
"5\n2 6 3 4 6",
"5"
],
[
"5\n4 196 2662 2197 121",
"2"
],
[
"7\n3 6 8 9 11 12 20",
"7"
],
[
"2\n2 3",
"0"
]
] | In the first example, the five paths are the following:
- City $$$1\rightarrow$$$ City $$$5$$$
- City $$$1\rightarrow$$$ City $$$2\rightarrow$$$ City $$$5$$$
- City $$$1\rightarrow$$$ City $$$2\rightarrow$$$ City $$$3\rightarrow$$$ City $$$5$$$
- City $$$1\rightarrow$$$ City $$$2\rightarrow$$$ City $$$4\rightarrow$$$ ... | Title: Natlan Exploring
time_limit_ms: 4000
memory_limit_mb: 256
Description: You are exploring the stunning region of Natlan! This region consists of $$$n$$$ cities, and each city is rated with an attractiveness $$$a_i$$$. A directed edge exists from City $$$i$$$ to City $$$j$$$ if and only if $$$i < j$$$ and $$$\gcd(... |
2050A | https://codeforces.com/problemset/problem/2050/A | Line Breaks | 800 | [
"implementation"
] | Div. 3 | 1,000 | 256 | Kostya has a text $$$s$$$ consisting of $$$n$$$ words made up of Latin alphabet letters. He also has two strips on which he must write the text. The first strip can hold $$$m$$$ characters, while the second can hold as many as needed.
Kostya must choose a number $$$x$$$ and write the first $$$x$$$ words from $$$s$$$ o... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 50$$$; $$$1 \le m \le 500$$$) — the number of words in the list and the maximum number of characters that can be on the first strip.... | For each test case, output the maximum number of words $$$x$$$ such that the first $$$x$$$ words have a total length of no more than $$$m$$$. | [
[
"5\n3 1\na\nb\nc\n2 9\nalpha\nbeta\n4 12\nhello\nworld\nand\ncodeforces\n3 2\nab\nc\nd\n3 2\nabc\nab\na",
"1\n2\n2\n1\n0"
]
] | Title: Line Breaks
time_limit_ms: 1000
memory_limit_mb: 256
Description: Kostya has a text $$$s$$$ consisting of $$$n$$$ words made up of Latin alphabet letters. He also has two strips on which he must write the text. The first strip can hold $$$m$$$ characters, while the second can hold as many as needed.
Kostya must... | |
2050B | https://codeforces.com/problemset/problem/2050/B | Transfusion | 1,100 | [
"greedy",
"brute force",
"math"
] | Div. 3 | 2,000 | 256 | You are given an array $$$a$$$ of length $$$n$$$. In one operation, you can pick an index $$$i$$$ from $$$2$$$ to $$$n-1$$$ inclusive, and do one of the following actions:
- Decrease $$$a_{i-1}$$$ by $$$1$$$, then increase $$$a_{i+1}$$$ by $$$1$$$.
- Decrease $$$a_{i+1}$$$ by $$$1$$$, then increase $$$a_{i-1}$$$ by $$... | First line of input consists of one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
First line of each test case consists of one integer $$$n$$$ ($$$3 \le n \le 2\cdot 10^5$$$).
Second line of each test case consists of $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$).
It is guaranteed tha... | For each test case, print "YES" without quotation marks if it is possible to make all the elements equal after any number of operations; otherwise, print "NO" without quotation marks.
You can print answers in any register: "yes", "YeS", "nO" — will also be considered correct. | [
[
"8\n3\n3 2 1\n3\n1 1 3\n4\n1 2 5 4\n4\n1 6 6 1\n5\n6 2 1 4 2\n4\n1 4 2 1\n5\n3 1 2 1 3\n3\n2 4 2",
"YES\nNO\nYES\nNO\nYES\nNO\nNO\nNO"
]
] | Title: Transfusion
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given an array $$$a$$$ of length $$$n$$$. In one operation, you can pick an index $$$i$$$ from $$$2$$$ to $$$n-1$$$ inclusive, and do one of the following actions:
- Decrease $$$a_{i-1}$$$ by $$$1$$$, then increase $$$a_{i+1}$$$ by $$$1$$... | |
2050C | https://codeforces.com/problemset/problem/2050/C | Uninteresting Number | 1,200 | [
"brute force",
"dp",
"math"
] | Div. 3 | 2,000 | 256 | You are given a number $$$n$$$ with a length of no more than $$$10^5$$$.
You can perform the following operation any number of times: choose one of its digits, square it, and replace the original digit with the result. The result must be a digit (that is, if you choose the digit $$$x$$$, then the value of $$$x^2$$$ mu... | The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The only line of each test case contains the number $$$n$$$, without leading zeros. The length of the number does not exceed $$$10^5$$$.
It is guaranteed that the sum of the lengths of the numbers across all test cases doe... | For each test case, output "YES" if it is possible to obtain a number divisible by $$$9$$$ using the described operations, and "NO" otherwise.
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer. | [
[
"9\n123\n322\n333333333333\n9997\n5472778912773\n1234567890\n23\n33\n52254522632",
"NO\nYES\nYES\nNO\nNO\nYES\nNO\nYES\nYES"
]
] | In the first example, from the integer $$$123$$$, it is possible to obtain only $$$123$$$, $$$143$$$, $$$129$$$, and $$$149$$$, none of which are divisible by $$$9$$$.
In the second example, you need to replace the second digit with its square; then $$$n$$$ will equal $$$342 = 38 \cdot 9$$$.
In the third example, the... | Title: Uninteresting Number
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a number $$$n$$$ with a length of no more than $$$10^5$$$.
You can perform the following operation any number of times: choose one of its digits, square it, and replace the original digit with the result. The result must be... |
2050D | https://codeforces.com/problemset/problem/2050/D | Digital string maximization | 1,300 | [
"greedy",
"brute force",
"math",
"strings"
] | Div. 3 | 2,000 | 256 | You are given a string $$$s$$$, consisting of digits from $$$0$$$ to $$$9$$$. In one operation, you can pick any digit in this string, except for $$$0$$$ or the leftmost digit, decrease it by $$$1$$$, and then swap it with the digit left to the picked.
For example, in one operation from the string $$$1023$$$, you can ... | The first line of the input consists of an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case consists of a single line consisting of a digital string $$$s$$$ ($$$1 \le |s| \le 2\cdot 10^5$$$), where $$$|s|$$$ denotes the length of $$$s$$$. The string does not contain leading zeroes.
... | For each test case, print the answer on a separate line. | [
[
"6\n19\n1709\n11555\n51476\n9876543210\n5891917899",
"81\n6710\n33311\n55431\n9876543210\n7875567711"
]
] | In the first example, the following sequence of operations is suitable: $$$19 \rightarrow 81$$$.
In the second example, the following sequence of operations is suitable: $$$1709 \rightarrow 1780 \rightarrow 6180 \rightarrow 6710$$$.
In the fourth example, the following sequence of operations is suitable: $$$51476 \ri... | Title: Digital string maximization
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a string $$$s$$$, consisting of digits from $$$0$$$ to $$$9$$$. In one operation, you can pick any digit in this string, except for $$$0$$$ or the leftmost digit, decrease it by $$$1$$$, and then swap it with the digi... |
2050E | https://codeforces.com/problemset/problem/2050/E | Three Strings | 1,500 | [
"strings",
"dp",
"implementation"
] | Div. 3 | 2,500 | 256 | You are given three strings: $$$a$$$, $$$b$$$, and $$$c$$$, consisting of lowercase Latin letters. The string $$$c$$$ was obtained in the following way:
1. At each step, either string $$$a$$$ or string $$$b$$$ was randomly chosen, and the first character of the chosen string was removed from it and appended to the end... | The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases.
The first line of each test case contains one string of lowercase Latin letters $$$a$$$ ($$$1 \leq |a| \leq 10^3$$$) — the first string, where $$$|a|$$$ denotes the length of string $$$a$$$.
The second l... | For each test case, output a single integer — the minimum number of characters that could have been changed in string $$$c$$$. | [
[
"7\na\nb\ncb\nab\ncd\nacbd\nab\nba\naabb\nxxx\nyyy\nxyxyxy\na\nbcd\ndecf\ncodes\nhorse\ncodeforces\negg\nannie\negaegaeg",
"1\n0\n2\n0\n3\n2\n3"
]
] | Title: Three Strings
time_limit_ms: 2500
memory_limit_mb: 256
Description: You are given three strings: $$$a$$$, $$$b$$$, and $$$c$$$, consisting of lowercase Latin letters. The string $$$c$$$ was obtained in the following way:
1. At each step, either string $$$a$$$ or string $$$b$$$ was randomly chosen, and the first... | |
2050F | https://codeforces.com/problemset/problem/2050/F | Maximum modulo equality | 1,700 | [
"data structures",
"number theory",
"math",
"divide and conquer"
] | Div. 3 | 5,000 | 256 | You are given an array $$$a$$$ of length $$$n$$$ and $$$q$$$ queries $$$l$$$, $$$r$$$.
For each query, find the maximum possible $$$m$$$, such that all elements $$$a_l$$$, $$$a_{l+1}$$$, ..., $$$a_r$$$ are equal modulo $$$m$$$. In other words, $$$a_l \bmod m = a_{l+1} \bmod m = \dots = a_r \bmod m$$$, where $$$a \bmod... | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$, $$$q$$$ ($$$1 \le n, q \le 2\cdot 10^5$$$) — the length of the array and the number of queries.
The second line of each test case contains $$$n$$$ integ... | For each query, output the maximum value $$$m$$$ described in the statement. | [
[
"3\n5 5\n5 14 2 6 3\n4 5\n1 4\n2 4\n3 5\n1 1\n1 1\n7\n1 1\n3 2\n1 7 8\n2 3\n1 2",
"3 1 4 1 0 \n0 \n1 6"
]
] | In the first query of the first sample, $$$6 \bmod 3 = 3 \bmod 3 = 0$$$. It can be shown that for greater $$$m$$$, the required condition will not be fulfilled.
In the third query of the first sample, $$$14 \bmod 4 = 2 \bmod 4 = 6 \bmod 4 = 2$$$. It can be shown that for greater $$$m$$$, the required condition will no... | Title: Maximum modulo equality
time_limit_ms: 5000
memory_limit_mb: 256
Description: You are given an array $$$a$$$ of length $$$n$$$ and $$$q$$$ queries $$$l$$$, $$$r$$$.
For each query, find the maximum possible $$$m$$$, such that all elements $$$a_l$$$, $$$a_{l+1}$$$, ..., $$$a_r$$$ are equal modulo $$$m$$$. In oth... |
2050G | https://codeforces.com/problemset/problem/2050/G | Tree Destruction | 1,900 | [
"dfs and similar",
"dp",
"trees"
] | Div. 3 | 2,000 | 256 | Given a tree$$$^{\text{∗}}$$$ with $$$n$$$ vertices. You can choose two vertices $$$a$$$ and $$$b$$$ once and remove all vertices on the path from $$$a$$$ to $$$b$$$, including the vertices themselves. If you choose $$$a=b$$$, only one vertex will be removed.
Your task is to find the maximum number of connected compon... | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of the tree.
The next $$$n-1$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$... | For each test case, output one integer — the maximum number of connected components that can be achieved using the described operation. | [
[
"6\n2\n1 2\n5\n1 2\n2 3\n3 4\n3 5\n4\n1 2\n2 3\n3 4\n5\n2 1\n3 1\n4 1\n5 4\n6\n2 1\n3 1\n4 1\n5 3\n6 3\n6\n2 1\n3 2\n4 2\n5 3\n6 4",
"1\n3\n2\n3\n4\n3"
]
] | Title: Tree Destruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: Given a tree$$$^{\text{∗}}$$$ with $$$n$$$ vertices. You can choose two vertices $$$a$$$ and $$$b$$$ once and remove all vertices on the path from $$$a$$$ to $$$b$$$, including the vertices themselves. If you choose $$$a=b$$$, only one vertex... | |
2032D | https://codeforces.com/problemset/problem/2032/D | Genokraken | 1,800 | [
"graphs",
"implementation",
"data structures",
"two pointers",
"constructive algorithms",
"interactive",
"greedy",
"trees"
] | Div. 2 | 2,000 | 256 | This is an interactive problem.
Upon clearing the Waterside Area, Gretel has found a monster named Genokraken, and she's keeping it contained for her scientific studies.
The monster's nerve system can be structured as a tree$$$^{\dagger}$$$ of $$$n$$$ nodes (really, everything should stop resembling trees all the tim... | Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$4 \le n \le 10^4$$$) — the number of nodes in Genokraken's ne... | null | [
[
"3\n4\n\n1\n\n5\n\n1\n\n0\n\n9",
"? 2 3\n\n! 0 0 1\n\n? 2 3\n\n? 2 4\n\n! 0 0 1 2\n\n! 0 0 0 1 3 5 6 7"
]
] | In the first test case, Genokraken's nerve system forms the following tree:
- The answer to "? 2 3" is $$$1$$$. This means that the simple path between nodes $$$2$$$ and $$$3$$$ contains node $$$0$$$.
In the second test case, Genokraken's nerve system forms the following tree:
- The answer to "? 2 3" is $$$1$$$. Thi... | Title: Genokraken
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is an interactive problem.
Upon clearing the Waterside Area, Gretel has found a monster named Genokraken, and she's keeping it contained for her scientific studies.
The monster's nerve system can be structured as a tree$$$^{\dagger}$$$ of $$... |
2048A | https://codeforces.com/problemset/problem/2048/A | Kevin and Combination Lock | 800 | [
"brute force",
"implementation",
"math",
"number theory",
"greedy"
] | Codeforces Global Round 28 | 1,000 | 256 | Kevin is trapped in Lakeside Village by Grace. At the exit of the village, there is a combination lock that can only be unlocked if Kevin solves it.
The combination lock starts with an integer $$$ x $$$. Kevin can perform one of the following two operations zero or more times:
1. If $$$ x \neq 33 $$$, he can select t... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$).
The only line of each test case contains a positive integer $$$x$$$ ($$$1\leq x\leq 10^9$$$). | For each test case, output "YES" or "NO" (without quotes) in one line, representing whether Kevin can unlock the combination lock and escape. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. | [
[
"5\n165\n6369\n666\n114514\n133333332",
"YES\nYES\nNO\nNO\nYES"
]
] | For the first test case, $$$165\xrightarrow{-33}132\xrightarrow{-33}99\xrightarrow{-33}66\xrightarrow{-33}33\xrightarrow{-33}0$$$.
For the second test case, $$$6369\xrightarrow{-33}6{\color{red}{33}}6\xrightarrow{\text{remove "33"}}66\xrightarrow{-33}33\xrightarrow{-33}0$$$.
For the third test case, it can be proven ... | Title: Kevin and Combination Lock
time_limit_ms: 1000
memory_limit_mb: 256
Description: Kevin is trapped in Lakeside Village by Grace. At the exit of the village, there is a combination lock that can only be unlocked if Kevin solves it.
The combination lock starts with an integer $$$ x $$$. Kevin can perform one of th... |
2048D | https://codeforces.com/problemset/problem/2048/D | Kevin and Competition Memories | 1,600 | [
"brute force",
"binary search",
"data structures",
"two pointers",
"sortings",
"greedy"
] | Codeforces Global Round 28 | 2,000 | 256 | Kevin used to get into Rio's Memories, and in Rio's Memories, a series of contests was once held. Kevin remembers all the participants and all the contest problems from that time, but he has forgotten the specific rounds, the distribution of problems, and the exact rankings.
There are $$$ m $$$ problems in total, with... | Each test contains multiple test cases. The first line contains the number of test cases $$$ t $$$ ($$$ 1 \le t \le 5\cdot 10^4 $$$).
The first line of each test case contains two integers $$$ n $$$ and $$$ m $$$ ($$$ 1 \le n, m \leq 3\cdot 10^5 $$$) — the number of participants and the number of problems.
The second... | For each test case, output $$$m$$$ integers — the minimum sum of Kevin's ranks for each $$$ k = 1, 2, \ldots, m$$$. | [
[
"4\n4 4\n4 3 7 5\n2 5 4 6\n5 5\n5 0 4 8 6\n1 3 9 2 7\n6 7\n1 1 4 5 1 4\n1 9 1 9 8 1 0\n7 6\n1 9 1 9 8 1 0\n1 1 4 5 1 4",
"7 4 2 3\n6 2 1 1 2\n7 3 2 1 1 1 1\n15 9 5 4 4 4"
]
] | For the first test case:
When $$$k=1$$$, since each contest only contains one problem, the distribution is in fact unique. For example, in the contest which only includes the third problem (which has a difficulty of $$$4$$$), all participants except the $$$2$$$-nd can solve it. Since no one solves strictly more proble... | Title: Kevin and Competition Memories
time_limit_ms: 2000
memory_limit_mb: 256
Description: Kevin used to get into Rio's Memories, and in Rio's Memories, a series of contests was once held. Kevin remembers all the participants and all the contest problems from that time, but he has forgotten the specific rounds, the di... |
2036G | https://codeforces.com/problemset/problem/2036/G | Library of Magic | 2,200 | [
"binary search",
"math",
"divide and conquer",
"number theory",
"constructive algorithms",
"interactive"
] | Div. 3 | 2,000 | 256 | This is an interactive problem.
The Department of Supernatural Phenomena at the Oxenfurt Academy has opened the Library of Magic, which contains the works of the greatest sorcerers of Redania — $$$n$$$ ($$$3 \leq n \leq 10^{18}$$$) types of books, numbered from $$$1$$$ to $$$n$$$. Each book's type number is indicated ... | The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 300$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$3 \leq n \leq 10^{18}$$$) — the number of types of tomes. | null | [
[
"2\n6\n\n0\n\n2\n\n3\n\n5\n\n3",
"xor 1 1\n\nxor 2 2\n\nxor 3 3\n\nxor 4 6\n\nans 2 3 5\n\nans 1 2 3"
]
] | In the first test case, the books in the library after the theft look like this:
Now consider the answers to the queries:
- For the query "xor 1 1", you receive the result $$$1 \oplus 1 = 0$$$. Two tomes satisfy the condition specified in the query — both with the number $$$1$$$.
- For the query "xor 2 2", you receiv... | Title: Library of Magic
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is an interactive problem.
The Department of Supernatural Phenomena at the Oxenfurt Academy has opened the Library of Magic, which contains the works of the greatest sorcerers of Redania — $$$n$$$ ($$$3 \leq n \leq 10^{18}$$$) types of ... |
2040B | https://codeforces.com/problemset/problem/2040/B | Paint a Strip | 1,000 | [
"constructive algorithms",
"greedy",
"math"
] | Div. 2 | 1,000 | 256 | You have an array of zeros $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$.
You can perform two types of operations on it:
1. Choose an index $$$i$$$ such that $$$1 \le i \le n$$$ and $$$a_i = 0$$$, and assign $$$1$$$ to $$$a_i$$$;
2. Choose a pair of indices $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$, $$$... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array.
Note that there is no limit on the sum ... | For each test case, print one integer — the minimum number of needed operations of first type. | [
[
"4\n1\n2\n4\n20",
"1\n2\n2\n4"
]
] | In the first test case, you can perform an operation of the $$$1$$$st type with $$$i = 1$$$.
In the second test case, you can perform the following sequence of operations:
1. Operation of $$$1$$$st type, $$$i = 1$$$. After performing this operation, the array will look like this: $$$[1, 0]$$$.
2. Operation of $$$1$$$... | Title: Paint a Strip
time_limit_ms: 1000
memory_limit_mb: 256
Description: You have an array of zeros $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$.
You can perform two types of operations on it:
1. Choose an index $$$i$$$ such that $$$1 \le i \le n$$$ and $$$a_i = 0$$$, and assign $$$1$$$ to $$$a_i$$$;
2. Choose a p... |
2040C | https://codeforces.com/problemset/problem/2040/C | Ordered Permutations | 1,600 | [
"constructive algorithms",
"math",
"greedy",
"two pointers",
"combinatorics",
"bitmasks"
] | Div. 2 | 2,000 | 256 | Consider a permutation$$$^{\text{∗}}$$$ $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$. We can introduce the following sum for it$$$^{\text{†}}$$$:
$$$$$$S(p) = \sum_{1 \le l \le r \le n} \min(p_l, p_{l + 1}, \ldots, p_r)$$$$$$
Let us consider all permutations of length $$$n$$$ with the maximum possi... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le 10^{12}$$$) — the length of the... | For each test case, if there are less than $$$k$$$ suitable permutations, print $$$-1$$$.
Otherwise, print the $$$k$$$-th suitable permutation. | [
[
"6\n3 2\n3 3\n4 11\n4 6\n6 39\n7 34",
"1 3 2 \n2 3 1 \n-1\n2 4 3 1 \n-1\n2 3 4 5 7 6 1"
]
] | Let us calculate the required sum for all permutations of length $$$3$$$ (ordered lexicographically):
PermutationValue of $$$S(p)$$$$$$[1, 2, 3]$$$$$$10$$$$$$[1, 3, 2]$$$$$$10$$$$$$[2, 1, 3]$$$$$$9$$$$$$[2, 3, 1]$$$$$$10$$$$$$[3, 1, 2]$$$$$$9$$$$$$[3, 2, 1]$$$$$$10$$$
In the first test case, you have to print the sec... | Title: Ordered Permutations
time_limit_ms: 2000
memory_limit_mb: 256
Description: Consider a permutation$$$^{\text{∗}}$$$ $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$. We can introduce the following sum for it$$$^{\text{†}}$$$:
$$$$$$S(p) = \sum_{1 \le l \le r \le n} \min(p_l, p_{l + 1}, \ldots, p_r... |
2040E | https://codeforces.com/problemset/problem/2040/E | Control of Randomness | 2,100 | [
"dp",
"graphs",
"math",
"dfs and similar",
"probabilities",
"combinatorics",
"greedy",
"trees"
] | Div. 2 | 2,000 | 256 | You are given a tree with $$$n$$$ vertices.
Let's place a robot in some vertex $$$v \ne 1$$$, and suppose we initially have $$$p$$$ coins. Consider the following process, where in the $$$i$$$-th step (starting from $$$i = 1$$$):
- If $$$i$$$ is odd, the robot moves to an adjacent vertex in the direction of vertex $$$... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^3$$$; $$$1 \le q \le 2 \cdot 10^3$$$) — the number ... | For each test case, print $$$q$$$ integers: the values of $$$f(v_i, p_i)$$$ modulo $$$998\,244\,353$$$.
Formally, let $$$M = 998\,244\,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output... | [
[
"2\n4 4\n1 2\n2 3\n2 4\n2 0\n3 0\n4 0\n3 1\n12 10\n1 2\n2 3\n2 4\n1 5\n5 6\n6 7\n6 8\n6 9\n8 10\n10 11\n10 12\n6 0\n9 0\n10 0\n11 0\n3 1\n7 1\n10 1\n12 1\n12 2\n11 12",
"1\n6\n6\n2\n4\n9\n8\n15\n2\n3\n6\n9\n5\n5"
]
] | The tree in the first test case:
In the first query, the expected value is equal to $$$1$$$, since the robot starts moving from vertex $$$2$$$ to vertex $$$1$$$ in the first step and the process stops.
Let's calculate the expected value in the second query ($$$x$$$ is the number of steps):
- $$$P(x < 2) = 0$$$, the ... | Title: Control of Randomness
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a tree with $$$n$$$ vertices.
Let's place a robot in some vertex $$$v \ne 1$$$, and suppose we initially have $$$p$$$ coins. Consider the following process, where in the $$$i$$$-th step (starting from $$$i = 1$$$):
- If $... |
2022D1 | https://codeforces.com/problemset/problem/2022/D1 | Asesino (Easy Version) | 1,900 | [
"brute force",
"binary search",
"implementation",
"constructive algorithms",
"interactive"
] | Div. 2 | 2,500 | 256 | This is the easy version of the problem. In this version, you can ask at most $$$n+69$$$ questions. You can make hacks only if both versions of the problem are solved.
This is an interactive problem.
It is a tradition in Mexico's national IOI trainings to play the game "Asesino", which is similar to "Among Us" or "Ma... | The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of people playing the game.
It is guaranteed that the sum... | null | [
[
"2\n7\n\n1\n\n0\n\n0\n\n1\n\n1\n\n0\n\n0\n\n1\n\n4\n\n0\n\n1\n\n1\n\n1",
"? 1 3\n\n? 7 6\n\n? 2 5\n\n? 6 2\n\n? 4 5\n\n? 4 6\n\n? 1 4\n\n? 2 4\n\n! 4\n\n? 1 2\n\n? 2 3\n\n? 3 4\n\n? 4 1\n\n! 3"
]
] | Note that the example test cases do not represent an optimal strategy for asking questions and are only shown for the sake of demonstrating the interaction format. Specifically, we cannot determine which player is the Impostor from the questions asked in the examples.
In the first test case of the example, players at ... | Title: Asesino (Easy Version)
time_limit_ms: 2500
memory_limit_mb: 256
Description: This is the easy version of the problem. In this version, you can ask at most $$$n+69$$$ questions. You can make hacks only if both versions of the problem are solved.
This is an interactive problem.
It is a tradition in Mexico's nati... |
2013C | https://codeforces.com/problemset/problem/2013/C | Password Cracking | 1,400 | [
"constructive algorithms",
"interactive",
"strings"
] | Div. 2 | 2,000 | 256 | Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.
Believing in the strength of his password, Mansur stated that his password — is a binary string of length $$$n$$$. He is also ready to answer Dimash'... | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. | null | [
[
"4\n3\n\n0\n\n0\n\n1\n\n4\n\n4\n\n2",
"? 00\n\n? 000\n\n? 010\n\n! 010\n\n! 1100\n\n! 0110\n\n! 10"
]
] | In the first example, the string $$$010$$$ is given. Therefore, the answers to the queries are as follows:
"? 00" $$$00$$$ is not a substring of $$$010$$$, so the answer is $$$0$$$.
"? 000" $$$000$$$ is not a substring, so the answer is $$$0$$$.
"? 010" $$$010$$$ is a substring, so the answer is $$$1$$$.
In the sec... | Title: Password Cracking
time_limit_ms: 2000
memory_limit_mb: 256
Description: Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.
Believing in the strength of his password, Mansur stated that his pass... |
2044A | https://codeforces.com/problemset/problem/2044/A | Easy Problem | 800 | [
"brute force",
"math"
] | Div. 4 | 1,000 | 256 | Cube is given an integer $$$n$$$. She wants to know how many ordered pairs of positive integers $$$(a,b)$$$ there are such that $$$a=n-b$$$. Since Cube is not very good at math, please help her! | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 99$$$) — the number of test cases.
The only line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 100$$$). | For each test case, output the number of ordered pairs $$$(a, b)$$$ on a new line. | [
[
"3\n2\n4\n6",
"1\n3\n5"
]
] | In the first test case, the only ordered pair that works is $$$(a,b)=(1,1)$$$.
In the second test case, the three ordered pairs of $$$(a,b)$$$ that work are $$$(3,1), (2,2), (1,3)$$$. | Title: Easy Problem
time_limit_ms: 1000
memory_limit_mb: 256
Description: Cube is given an integer $$$n$$$. She wants to know how many ordered pairs of positive integers $$$(a,b)$$$ there are such that $$$a=n-b$$$. Since Cube is not very good at math, please help her!
Input: The first line contains an integer $$$t$$$ ... |
2044B | https://codeforces.com/problemset/problem/2044/B | Normal Problem | 800 | [
"strings",
"implementation"
] | Div. 4 | 1,000 | 256 | A string consisting of only characters 'p', 'q', and 'w' is painted on a glass window of a store. Ship walks past the store, standing directly in front of the glass window, and observes string $$$a$$$. Ship then heads inside the store, looks directly at the same glass window, and observes string $$$b$$$.
Ship gives yo... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases.
The only line of each test case contains a string $$$a$$$ ($$$1 \leq |a| \leq 100$$$) — the string Ship observes from outside the store. It is guaranteed that $$$a$$$ only contains characters 'p', 'q', and 'w'. | For each test case, output string $$$b$$$, the string Ship observes from inside the store, on a new line. | [
[
"5\nqwq\nppppp\npppwwwqqq\nwqpqwpqwwqp\npqpqpqpq",
"pwp\nqqqqq\npppwwwqqq\nqpwwpqwpqpw\npqpqpqpq"
]
] | Title: Normal Problem
time_limit_ms: 1000
memory_limit_mb: 256
Description: A string consisting of only characters 'p', 'q', and 'w' is painted on a glass window of a store. Ship walks past the store, standing directly in front of the glass window, and observes string $$$a$$$. Ship then heads inside the store, looks di... | |
2044C | https://codeforces.com/problemset/problem/2044/C | Hard Problem | 800 | [
"greedy",
"math"
] | Div. 4 | 1,000 | 256 | Ball is the teacher in Paperfold University. The seats of his classroom are arranged in $$$2$$$ rows with $$$m$$$ seats each.
Ball is teaching $$$a + b + c$$$ monkeys, and he wants to assign as many monkeys to a seat as possible. Ball knows that $$$a$$$ of them only want to sit in row $$$1$$$, $$$b$$$ of them only wan... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
Each test case contains four integers $$$m$$$, $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \leq m, a, b, c \leq 10^8$$$). | For each test case, output the maximum number of monkeys you can seat. | [
[
"5\n10 5 5 10\n3 6 1 1\n15 14 12 4\n1 1 1 1\n420 6 9 69",
"20\n5\n30\n2\n84"
]
] | In the second test case, $$$6$$$ monkeys want to sit in the front row, but only $$$3$$$ seats are available. The monkeys that have no preference and the monkeys who prefer sitting in the second row can sit in the second row together. Thus, the answer is $$$3+2=5$$$. | Title: Hard Problem
time_limit_ms: 1000
memory_limit_mb: 256
Description: Ball is the teacher in Paperfold University. The seats of his classroom are arranged in $$$2$$$ rows with $$$m$$$ seats each.
Ball is teaching $$$a + b + c$$$ monkeys, and he wants to assign as many monkeys to a seat as possible. Ball knows that... |
2044E | https://codeforces.com/problemset/problem/2044/E | Insane Problem | 1,300 | [
"math",
"binary search",
"implementation",
"number theory",
"greedy"
] | Div. 4 | 2,000 | 256 | Wave is given five integers $$$k$$$, $$$l_1$$$, $$$r_1$$$, $$$l_2$$$, and $$$r_2$$$. Wave wants you to help her count the number of ordered pairs $$$(x, y)$$$ such that all of the following are satisfied:
- $$$l_1 \leq x \leq r_1$$$.
- $$$l_2 \leq y \leq r_2$$$.
- There exists a non-negative integer $$$n$$$ such that ... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The only line of each test case contains five integers $$$k$$$, $$$l_1$$$, $$$r_1$$$, $$$l_2$$$, and $$$r_2$$$ ($$$2 \leq k \leq 10^9, 1 \leq l_1 \leq r_1 \leq 10^9, 1 \leq l_2 \leq r_2 \leq 10^9$$$). | For each test case, output the number of matching ordered pairs $$$(x, y)$$$ on a new line. | [
[
"5\n2 2 6 2 12\n2 1 1000000000 1 1000000000\n3 5 7 15 63\n1000000000 1 5 6 1000000000\n15 17 78 2596 20914861",
"12\n1999999987\n6\n1\n197"
]
] | In the third test case, the matching ordered pairs are the following:
- $$$(5,15)$$$
- $$$(5,45)$$$
- $$$(6,18)$$$
- $$$(6,54)$$$
- $$$(7,21)$$$
- $$$(7,63)$$$
In the fourth test case, the only valid ordered pair is $$$(1,1\,000\,000\,000)$$$ | Title: Insane Problem
time_limit_ms: 2000
memory_limit_mb: 256
Description: Wave is given five integers $$$k$$$, $$$l_1$$$, $$$r_1$$$, $$$l_2$$$, and $$$r_2$$$. Wave wants you to help her count the number of ordered pairs $$$(x, y)$$$ such that all of the following are satisfied:
- $$$l_1 \leq x \leq r_1$$$.
- $$$l_2 ... |
2044F | https://codeforces.com/problemset/problem/2044/F | Easy Demon Problem | 1,900 | [
"brute force",
"binary search",
"math",
"data structures",
"number theory"
] | Div. 4 | 4,000 | 256 | For an arbitrary grid, Robot defines its beauty to be the sum of elements in the grid.
Robot gives you an array $$$a$$$ of length $$$n$$$ and an array $$$b$$$ of length $$$m$$$. You construct a $$$n$$$ by $$$m$$$ grid $$$M$$$ such that $$$M_{i,j}=a_i\cdot b_j$$$ for all $$$1 \leq i \leq n$$$ and $$$1 \leq j \leq m$$$.... | The first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$1 \leq n,m \leq 2\cdot 10^5, 1 \leq q \leq 5\cdot 10^4$$$) — the length of $$$a$$$, the length of $$$b$$$, and the number of queries respectively.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq |a_i| \leq n$$$).
... | For each testcase, output "YES" (without quotes) if there is a way to perform the aforementioned operation such that the beauty is $$$x$$$, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response). | [
[
"3 3 6\n-2 3 -3\n-2 2 -1\n-1\n1\n-2\n2\n-3\n3",
"NO\nYES\nNO\nNO\nYES\nNO"
],
[
"5 5 6\n1 -2 3 0 0\n0 -2 5 0 -3\n4\n-3\n5\n2\n-1\n2",
"YES\nYES\nYES\nYES\nNO\nYES"
]
] | In the second example, the grid is
0 -2 5 0 -3
0 4 -10 0 6
0 -6 15 0 -9
0 0 0 0 0
0 0 0 0 0
By performing the operation with $$$r=4$$$ and $$$c=2$$$, we create the following grid:
0 0 5 0 -3
0 0 -10 0 6
0 0 15 0 -9
0 0 0 0 0
0 0 0 0 0
which has beauty $$$4$$$. Thus, we output YES.
In the second query, sele... | Title: Easy Demon Problem
time_limit_ms: 4000
memory_limit_mb: 256
Description: For an arbitrary grid, Robot defines its beauty to be the sum of elements in the grid.
Robot gives you an array $$$a$$$ of length $$$n$$$ and an array $$$b$$$ of length $$$m$$$. You construct a $$$n$$$ by $$$m$$$ grid $$$M$$$ such that $$$... |
2044G1 | https://codeforces.com/problemset/problem/2044/G1 | Medium Demon Problem (easy version) | 1,700 | [
"graphs",
"implementation",
"graph matchings",
"dfs and similar",
"trees"
] | Div. 4 | 2,000 | 256 | This is the easy version of the problem. The key difference between the two versions is highlighted in bold.
A group of $$$n$$$ spiders has come together to exchange plushies. Initially, each spider has $$$1$$$ plushie. Every year, if spider $$$i$$$ has at least one plushie, he will give exactly one plushie to spider ... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of spiders.
The following line contains $$$n$$$ integers $$$r_1, r_2, \ldots, r_n$$$ ($$$1 \leq r_i \leq n, r_i... | For each test case, output an integer on a new line, the first year in which the process becomes stable. | [
[
"5\n2\n2 1\n5\n2 3 4 5 1\n5\n2 1 4 2 3\n5\n4 1 1 5 4\n10\n4 3 9 1 6 7 9 10 10 3",
"2\n2\n5\n4\n5"
]
] | For the second test case:
- At year $$$1$$$, the following array shows the number of plushies each spider has: $$$[1, 1, 1, 1, 1]$$$. Then, year $$$1$$$'s exchange happens.
- At year $$$2$$$, the following array shows the number of plushies each spider has: $$$[1, 1, 1, 1, 1]$$$. Since this array is the same as the pr... | Title: Medium Demon Problem (easy version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the easy version of the problem. The key difference between the two versions is highlighted in bold.
A group of $$$n$$$ spiders has come together to exchange plushies. Initially, each spider has $$$1$$$ plushie. Ev... |
2044G2 | https://codeforces.com/problemset/problem/2044/G2 | Medium Demon Problem (hard version) | 1,900 | [
"dp",
"graphs",
"implementation",
"dfs and similar",
"dsu",
"trees"
] | Div. 4 | 2,000 | 256 | This is the hard version of the problem. The key difference between the two versions is highlighted in bold.
A group of $$$n$$$ spiders has come together to exchange plushies. Initially, each spider has $$$1$$$ plushie. Every year, if spider $$$i$$$ has at least one plushie, he will give exactly one plushie to spider ... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of spiders.
The following line contains $$$n$$$ integers $$$r_1, r_2, \ldots, r_n$$$ ($$$1 \leq r_i \leq n, r_i... | For each test case, output an integer on a new line, the first year in which the process becomes stable. | [
[
"5\n2\n2 1\n5\n2 3 4 5 1\n5\n2 1 4 2 3\n5\n4 1 1 5 4\n10\n4 3 9 1 6 7 9 10 10 3",
"2\n2\n5\n5\n5"
]
] | For the second test case:
- At year $$$1$$$, the following array shows the number of plushies each spider has: $$$[1, 1, 1, 1, 1]$$$. Then, year $$$1$$$'s exchange happens.
- At year $$$2$$$, the following array shows the number of plushies each spider has: $$$[1, 1, 1, 1, 1]$$$. Since this array is the same as the pr... | Title: Medium Demon Problem (hard version)
time_limit_ms: 2000
memory_limit_mb: 256
Description: This is the hard version of the problem. The key difference between the two versions is highlighted in bold.
A group of $$$n$$$ spiders has come together to exchange plushies. Initially, each spider has $$$1$$$ plushie. Ev... |
2044H | https://codeforces.com/problemset/problem/2044/H | Hard Demon Problem | 2,100 | [
"dp",
"implementation",
"math",
"data structures",
"constructive algorithms"
] | Div. 4 | 3,500 | 512 | Swing is opening a pancake factory! A good pancake factory must be good at flattening things, so Swing is going to test his new equipment on 2D matrices.
Swing is given an $$$n \times n$$$ matrix $$$M$$$ containing positive integers. He has $$$q$$$ queries to ask you.
For each query, he gives you four integers $$$x_1... | The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.
The first line of each test contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n \leq 2000, 1 \leq q \leq 10^6$$$) — the length of $$$M$$$ and the number of queries.
The following $$$n$$$ lines contain $$$n$$$ integers... | For each test case, output the results of the $$$q$$$ queries on a new line. | [
[
"2\n4 3\n1 5 2 4\n4 9 5 3\n4 5 2 3\n1 5 5 2\n1 1 4 4\n2 2 3 3\n1 2 4 3\n3 3\n1 2 3\n4 5 6\n7 8 9\n1 1 1 3\n1 3 3 3\n2 2 2 2",
"500 42 168 \n14 42 5"
]
] | In the second query of the first test case, $$$A = [9, 5, 5, 2]$$$. Therefore, the sum is $$$1 \cdot 9 + 2 \cdot 5 + 3 \cdot 5 + 4 \cdot 2 = 42$$$. | Title: Hard Demon Problem
time_limit_ms: 3500
memory_limit_mb: 512
Description: Swing is opening a pancake factory! A good pancake factory must be good at flattening things, so Swing is going to test his new equipment on 2D matrices.
Swing is given an $$$n \times n$$$ matrix $$$M$$$ containing positive integers. He ha... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.