problem_statement stringlengths 147 8.53k | input stringlengths 1 771 | output stringlengths 1 592 ⌀ | time_limit stringclasses 32
values | memory_limit stringclasses 21
values | tags stringlengths 6 168 |
|---|---|---|---|---|---|
A. Reordertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way that \sum_{i=1}^{n}{\sum_{j=i}^{n}{\frac{a_j}{j}}} equals m? It is for... | 2
3 8
2 5 1
4 4
0 1 2 3
| YES NO | 1 second | 256 megabytes | ['math', '*800'] |
E. A Convex Gametime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputShikamaru and Asuma like to play different games, and sometimes they play the following: given an increasing list of numbers, they take turns to move. Each move consists of picking a number from the lis... | 1
10
1 2 3 4 5 6 7 8 9 10
| YES | 3 seconds | 512 megabytes | ['dsu', 'games', '*3500'] |
G. Reducing Delivery Costtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a mayor of Berlyatov. There are n districts and m two-way roads between them. The i-th road connects districts x_i and y_i. The cost of travelling along this road is w_i. There is some p... | 6 5 2
1 2 5
2 3 7
2 4 4
4 5 2
4 6 8
1 6
5 3
| 22 | 1 second | 256 megabytes | ['brute force', 'graphs', 'shortest paths', '*2100'] |
F. Zero Remainder Sum time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a matrix a of size n \times m consisting of integers.You can choose no more than \left\lfloor\frac{m}{2}\right\rfloor elements in each row. Your task is to choose these elements in su... | 3 4 3
1 2 3 4
5 2 2 2
7 1 1 4
| 24 | 1 second | 256 megabytes | ['dp', '*2100'] |
E. Two Round Dancestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day, n people (n is an even number) met on a plaza and made two round dances, each round dance consists of exactly \frac{n}{2} people. Your task is to find the number of ways n people can make two... | Input2 | Output1 | 1 second | 256 megabytes | ['combinatorics', 'math', '*1300'] |
D. Districts Connectiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n districts in the town, the i-th district belongs to the a_i-th bandit gang. Initially, no districts are connected to each other.You are the mayor of the city and want to build n-1 two-... | 4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
| YES 1 3 3 5 5 4 1 2 NO YES 1 2 2 3 3 4 YES 1 2 1 3 1 4 | 1 second | 256 megabytes | ['constructive algorithms', 'dfs and similar', '*1200'] |
C. Dominant Piranhatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n piranhas with sizes a_1, a_2, \ldots, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.Scientists of the Berland State University want to f... | 6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
| 3 -1 4 3 3 1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', '*900'] |
B. Yet Another Bookshelftime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a bookshelf which can fit n books. The i-th position of bookshelf is a_i = 1 if there is a book on this position and a_i = 0 otherwise. It is guaranteed that there is at least one book o... | 5
7
0 0 1 0 1 0 1
3
1 0 0
5
1 1 0 0 1
6
1 0 0 0 0 1
5
1 1 0 1 1
| 2 0 2 4 1 | 1 second | 256 megabytes | ['greedy', 'implementation', '*800'] |
A. Boring Apartmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a building consisting of 10~000 apartments numbered from 1 to 10~000, inclusive.Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are 11, 2, 7... | 4
22
9999
1
777
| 13 90 1 66 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
J. Zero-XOR Arraytime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of integers a of size n. This array is non-decreasing, i. e. a_1 \le a_2 \le \dots \le a_n.You have to find arrays of integers b of size 2n - 1, such that: b_{2i-1} = a_i (1 \le... | 3
0 1 3
| 2 | 6 seconds | 256 megabytes | ['*special problem', 'dp', '*3400'] |
I. Cyclic Shiftstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a matrix consisting of n rows and m columns. The matrix contains lowercase letters of the Latin alphabet.You can perform the following operation any number of times you want to: choose two... | 3 5 4
abacc
ccbba
ccabc
abacc
acbbc
ababa
acbbc
| 0 2 1 2 | 3 seconds | 512 megabytes | ['*special problem', 'strings', '*2900'] |
H. Rogue-like Gametime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMarina plays a new rogue-like game. In this game, there are n different character species and m different classes. The game is played in runs; for each run, Marina has to select a species and a class ... | 3 4 2
0 5 7
0 2 6 10
2 5 5 2
5 3 4 4
3 4 2 4
| 3 | 4 seconds | 256 megabytes | ['*special problem', 'brute force', 'greedy', 'two pointers', '*2600'] |
G. Number Deletion Gametime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlice and Bob play a game. They have a set that initially consists of n integers. The game is played in k turns. During each turn, the following events happen: firstly, Alice chooses an integer ... | 5 2
3 4 1 5 2
| 4 | 2 seconds | 512 megabytes | ['*special problem', 'dp', 'games', 'greedy', '*2100'] |
F. Neural Network Problemtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to train a neural network model for your graduation work. There are n images in the dataset, the i-th image's size is a_i bytes.You don't have any powerful remote servers to train this... | 5 5 4
1 1 5 4 5
| 0 | 5 seconds | 256 megabytes | ['*special problem', 'binary search', 'greedy', '*2100'] |
E. Chess Matchtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe final of Berland Chess Team Championship is going to be held soon. Two teams consisting of n chess players each will compete for first place in the tournament. The skill of the i-th player in the firs... | 4
4
1 2 3 4
1 2 3 4
2
1 100
100 101
2
1 100
50 51
5
1 1 1 1 1
3 3 3 3 3
| 3 4 1 2 1 2 2 1 5 4 2 3 1 | 2 seconds | 512 megabytes | ['*special problem', '*2000'] |
D. Used Markerstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour University has a large auditorium and today you are on duty there. There will be n lectures today — all from different lecturers, and your current task is to choose in which order ord they will happ... | 4
4
1 2 1 2
2
2 1
3
1 1 1
4
2 3 1 3
| 4 1 3 2 1 2 3 1 2 4 3 2 1 | 3 seconds | 256 megabytes | ['*special problem', 'greedy', '*1500'] |
C. Black Fridaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a local shop in your area getting prepared for the great holiday of Black Friday. There are n items with prices p_1, p_2, \dots, p_n on the display. They are ordered by price, so p_1 \le p_2 \le... | 5
5 2
1 3 4 6 7
6 3
1 2 3 4 5 6
6 3
3 3 4 4 5 5
1 1
7
4 4
1 3 3 7
| 7 4 6 7 1 | 2 seconds | 256 megabytes | ['*special problem', 'implementation', '*1600'] |
B. Polycarp and the Language of Godstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has just finished writing down the lecture on elvish languages. The language this week was "VwV" (pronounced as "uwu"). The writing system of this language consists of only ... | 5
vv
v
w
vwv
vwvvwv
| 1 0 1 1 3 | 2 seconds | 256 megabytes | ['*special problem', 'implementation', 'two pointers', '*1400'] |
A. Selling Hamburgerstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n customers in the cafeteria. Each of them wants to buy a hamburger. The i-th customer has a_i coins, and they will buy a hamburger if it costs at most a_i coins.Suppose the cost of the h... | 6
3
1 1 1
3
4 1 1
3
2 4 2
8
1 2 3 4 5 6 7 8
1
1000000000000
3
1000000000000 999999999999 1
| 3 4 6 20 1000000000000 1999999999998 | 2 seconds | 512 megabytes | ['*special problem', '*800'] |
G. Yet Another DAG Problemtime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_... | 3 2
2 1 4
1 3 2
| 1 2 0 | 2 seconds | 1024 megabytes | ['bitmasks', 'dfs and similar', 'dp', 'flows', 'graphs', 'math', '*2600'] |
F. Realistic Gameplaytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently you've discovered a new shooter. They say it has realistic game mechanics.Your character has a gun with magazine size equal to k and should exterminate n waves of monsters. The i-th wave co... | 2 3
2 3 6
3 4 3
| 9 | 1 second | 256 megabytes | ['dp', 'greedy', '*2600'] |
E. String Reversaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last let... | 5
aaaza
| 2 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'strings', '*1900'] |
D. String Deletiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string s consisting of n characters. Each character is either 0 or 1.You can perform operations on the string. Each operation consists of two steps: select an integer i from 1 to the lengt... | 5
6
111010
1
0
1
1
2
11
6
101010
| 3 1 1 1 3 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', 'two pointers', '*1700'] |
C. Numbers on Whiteboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNumbers 1, 2, 3, \dots n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer \frac{a + b}{2} round... | 1
4
| 2 2 4 3 3 3 1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'greedy', 'implementation', 'math', '*1000'] |
B. Barrelstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water.You can pour water from one barrel to another. In one act of pouring, you ca... | 2
4 1
5 5 5 5
3 2
0 0 0
| 10 0 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*800'] |
A. Number of Apartmentstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven... | 4
30
67
4
14
| 2 2 2 7 5 3 -1 0 0 2 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'math', '*900'] |
H. Rotary Laser Locktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.To prevent the mischievous rabbits from freely roaming around the zoo, Zookeeper has set up a special lock for the rabbit enclosure. This lock is called the Rotary Lase... | 3 4
4
4
3
| ? 0 1 ? 2 -1 ? 1 1 ! 1 5 | 1 second | 256 megabytes | ['binary search', 'interactive', '*3500'] |
G2. Lucky Numbers (Hard Version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference is in the constraint on q. You can make hacks only if all versions of the problem are solved.Zookeeper has been teaching his ... | 3
1 2 3 4 5 6
2
57
63
| 11 8 | 3 seconds | 256 megabytes | ['dp', 'greedy', '*3000'] |
G1. Lucky Numbers (Easy Version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference is that in this version q=1. You can make hacks only if all versions of the problem are solved.Zookeeper has been teaching hi... | 3
1 2 3 4 5 6
1
57
| 11 | 3 seconds | 256 megabytes | ['dp', 'greedy', '*2900'] |
F. Fruit Sequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZookeeper is buying a carton of fruit to feed his pet wabbit. The fruits are a sequence of apples and oranges, which is represented by a binary string s_1s_2\ldots s_n of length n. 1 represents an app... | 4
0110
| 12 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'divide and conquer', 'dp', 'two pointers', '*2400'] |
E. Carrots for Rabbitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, \ldots, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now... | 3 6
5 3 1
| 15 | 1 second | 256 megabytes | ['binary search', 'data structures', 'greedy', 'math', 'sortings', '*2200'] |
D. Bouncing Boomerangstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTo improve the boomerang throwing skills of the animals, Zookeeper has set up an n \times n grid with some targets, where each row and each column has at most 2 targets each. The rows are numbered... | 6
2 0 3 0 1 1
| 5 2 1 2 5 3 3 3 6 5 6 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1900'] |
C. ABBBtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputZookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a s... | 3
AAA
BABA
AABBBABBBB
| 3 2 0 | 1 second | 256 megabytes | ['brute force', 'data structures', 'greedy', 'strings', '*1100'] |
B. Belted Roomstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the snake exhibition, there are n rooms (numbered 0 to n - 1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms... | 4
4
-><-
5
>>>>>
3
<--
2
<>
| 3 5 3 0 | 1 second | 256 megabytes | ['graphs', 'implementation', '*1200'] |
A. Box is Pulltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).He has a rope, which he can use to pull the box. He can only p... | 2
1 2 2 2
1 1 2 2
| 1 4 | 1 second | 256 megabytes | ['math', '*800'] |
H. Prison Breaktime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA prisoner wants to escape from a prison. The prison is represented by the interior of the convex polygon with vertices P_1, P_2, P_3, \ldots, P_{n+1}, P_{n+2}, P_{n+3}. It holds P_1=(0,0), P_{n+1}=(0, h... | 2
0 0
223 464
0 749
| 1 | 4 seconds | 256 megabytes | ['binary search', 'games', 'geometry', 'ternary search', '*3500'] |
G. One Billion Shades of Greytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have to paint with shades of grey the tiles of an n\times n wall. The wall has n rows of tiles, each with n tiles.The tiles on the boundary of the wall (i.e., on the first row, last row... | 3
1 7 6
4 0 6
1 1 1
| 26 | 3 seconds | 256 megabytes | ['flows', 'graphs', '*3300'] |
F. Boring Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen they are bored, Federico and Giada often play the following card game with a deck containing 6n cards.Each card contains one number between 1 and 6n and each number appears on exactly one card. I... | 2
2 3 4 9 10 11
| 9 10 11 6 7 8 2 3 4 1 5 12 | 1 second | 256 megabytes | ['data structures', 'greedy', 'trees', '*3200'] |
E. Xumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a blackboard and initially only an odd number x is written on it. Your goal is to write the number 1 on the blackboard.You may write new numbers on the blackboard with the following two operations. You... | 3
| 5 3 + 3 3 ^ 6 3 + 5 3 + 6 8 ^ 9 | 2 seconds | 256 megabytes | ['bitmasks', 'constructive algorithms', 'math', 'matrices', 'number theory', '*2500'] |
D. Unshuffling a Decktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation. Choose 2 \le k \le n and split the... | 4
3 1 2 4
| 2 3 1 2 1 2 1 3 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*2000'] |
C. The Hard Work of Paparazzitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a paparazzi working in Manhattan.Manhattan has r south-to-north streets, denoted by numbers 1, 2,\ldots, r in order from west to east, and r west-to-east streets, denoted by numbers... | 10 1
11 6 8
| 0 | 2 seconds | 256 megabytes | ['dp', '*2000'] |
B. Chess Cheatertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou like playing chess tournaments online.In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points... | 8
5 2
WLWLL
6 5
LLLWWL
7 1
LWLWLWL
15 5
WWWLLLWWWLLLWWW
40 7
LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL
1 0
L
1 1
L
6 1
WLLWLW
| 7 11 6 26 46 0 1 6 | 1 second | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1400'] |
A. Avoiding Zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integers a_1,a_2,\dots,a_n.You have to create an array of n integers b_1,b_2,\dots,b_n such that: The array b is a rearrangement of the array a, that is, it contains the sam... | 4
4
1 -2 3 -4
3
0 0 0
5
1 -1 1 -1 1
6
40 -31 -9 0 13 -40
| YES 1 -2 3 -4 NO YES 1 1 -1 1 -1 YES -40 13 40 0 -9 -31 | 1 second | 256 megabytes | ['math', 'sortings', '*900'] |
F. Number of Subsequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s consisting of lowercase Latin letters "a", "b" and "c" and question marks "?".Let the number of question marks in the string s be k. Let's replace each question mark wit... | 6
ac?b?c
| 24 | 1 second | 256 megabytes | ['combinatorics', 'dp', 'strings', '*2000'] |
E. Rock, Paper, Scissorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob have decided to play the game "Rock, Paper, Scissors". The game consists of several rounds, each round is independent of each other. In each round, both players show one of the foll... | 2
0 1 1
1 1 0
| 0 1 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'flows', 'greedy', 'math', '*1800'] |
D. Non-zero Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKolya got an integer array a_1, a_2, \dots, a_n. The array can contain both positive and negative integers, but Kolya doesn't like 0, so the array doesn't contain any zeros.Kolya doesn't like that t... | 4
1 -5 3 2
| 1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'greedy', 'sortings', '*1500'] |
C. Increase and Copytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputInitially, you have the array a consisting of one element 1 (a = [1]).In one move, you can do one of the following things: Increase some (single) element of a by 1 (choose some i from 1 to the curre... | 5
1
5
42
1337
1000000000
| 0 3 11 72 63244 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'math', '*1100'] |
B. Symmetric Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMasha has n types of tiles of size 2 \times 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type.Masha decides to construct the square of size m \times m c... | 6
3 4
1 2
5 6
5 7
7 4
8 9
9 8
2 5
1 1
1 1
2 2
2 2
1 100
10 10
10 10
1 2
4 5
8 4
2 2
1 1
1 1
1 2
3 4
1 2
1 1
1 1
| YES NO YES NO YES YES | 1 second | 256 megabytes | ['implementation', '*900'] |
A. Floor Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor co... | 4
7 3
1 5
22 5
987 13
| 3 1 5 77 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
I. Impressive Harvesting of The Orchardtime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Chanek has an orchard structured as a rooted ternary tree with N vertices numbered from 1 to N. The root of the tree is vertex 1. P_i denotes the parent of vertex i, for (2 \l... | 2 3
1 2
1
2
1
1
| 0 1 0 1 1 2 | 7 seconds | 256 megabytes | ['data structures', '*2800'] |
H. Huge Boxes of Animal Toystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification: The first box stores toys ... | 2
1 2 0 1
0 1 0 0
| Ya Ya Tidak Tidak Tidak Ya Tidak Tidak | 2 seconds | 256 megabytes | ['constructive algorithms', '*1300'] |
F. Flamingoes of Mysterytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. You have to use a flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout), in Java — System.out.flush(), in... | Input6 5 15 10 | Output ? 1 2 ? 5 6 ? 3 4 ! 1 4 4 6 7 8 | 2 seconds | 256 megabytes | ['interactive', '*1400'] |
E. Excitation of Atomstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it.There are N atoms numbered from 1 to N. These atoms a... | 6 1
5 6 7 8 10 2
3 5 6 7 1 10
| 35 | 2 seconds | 256 megabytes | ['greedy', 'implementation', '*2200'] |
D. Danger of Mad Snakestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Chanek The Ninja is one day tasked with a mission to handle mad snakes that are attacking a site. Now, Mr. Chanek already arrived at the hills where the destination is right below these hills... | 4 2 1
1 1 10
2 2 20
2 3 30
5 2 40
| 33800 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'math', '*2300'] |
C. Captain of Knightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Chanek just won the national chess tournament and got a huge chessboard of size N \times M. Bored with playing conventional chess, Mr. Chanek now defines a function F(X, Y), which denotes the m... | 2
3 4 5 6
5 5 8 8
| 27 70 | 2 seconds | 256 megabytes | ['math', '*3100'] |
B. Blue and Red of Our Faculty!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's our faculty's 34th anniversary! To celebrate this great event, the Faculty of Computer Science, University of Indonesia (Fasilkom), held CPC - Coloring Pavements Competition. The gis... | 5 6
1 2
2 3
3 4
4 1
1 5
5 1
| 8 | 2 seconds | 256 megabytes | ['divide and conquer', 'dp', '*2600'] |
A. Arena of Greedtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLately, Mr. Chanek frequently plays the game Arena of Greed. As the name implies, the game's goal is to find the greediest of them all, who will then be crowned king of Compfestnesia.The game is played... | 2
5
6
| 2 4 | 2 seconds | 256 megabytes | ['games', 'greedy', '*1400'] |
M. Ancient Languagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile exploring the old caves, researchers found a book, or more precisely, a stash of mixed pages from a book. Luckily, all of the original pages are present and each page contains its number. There... | 3 3
2
b
b
bbac
0
a
aca
acba
1
ab
c
ccb
| acb | 2 seconds | 256 megabytes | ['graphs', 'sortings', '*2200'] |
G. Yearstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at... | 3
1 5
2 4
5 6
| 2 2 | 1 second | 256 megabytes | ['data structures', 'sortings', '*1300'] |
N. BubbleSquare Tokenstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBubbleSquare social network is celebrating 13^{th} anniversary and it is rewarding its members with special edition BubbleSquare tokens. Every member receives one personal token. Also, two additio... | 2 1
1 2
| 1 1 1 2 0 | 2 seconds | 256 megabytes | ['*3500'] |
M. Milutin's Plumstime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputAs you all know, the plum harvesting season is on! Little Milutin had his plums planted in an orchard that can be represented as an n by m matrix. While he was harvesting, he wrote the heights of all ... | 5 5
13 15 10 9 15
15 17 12 11 17
10 12 7 6 12
17 19 14 13 19
16 18 13 12 18
| null | 1 second | 1024 megabytes | ['interactive', '*2800'] |
L. Light switchestime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputNikola owns a large warehouse which is illuminated by N light bulbs, numbered 1 to N. At the exit of the warehouse, there are S light switches, numbered 1 to S. Each switch swaps the on/off state for ... | 4 3 4
2 1 2
2 2 3
1 2
1 1
2 1 3
3 1 2 3
3 1 2 4
| 2 2 3 -1 | 3 seconds | 1024 megabytes | ['meet-in-the-middle', '*2600'] |
K. Lonely Numberstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn number world, two different numbers are friends if they have a lot in common, but also each one has unique perks.More precisely, two different numbers a and b are friends if gcd(a,b), \frac{a}{gcd... | 3
1 5 10
| 1 3 3 | 1.5 seconds | 256 megabytes | ['binary search', 'math', 'number theory', 'two pointers', '*1600'] |
J. Bubble Cup hypothesistime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Bubble Cup hypothesis stood unsolved for 130 years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed... | 2
2 4
| 2 4 | 1 second | 256 megabytes | ['bitmasks', 'constructive algorithms', 'dp', 'math', '*2400'] |
I. Lookup Tablestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn has Q closed intervals of consecutive 2K-bit numbers [l_i, r_i] and one 16-bit value v_i for each interval. (0 \leq i < Q)John wants to implement a function F that maps 2K-bit numbers to 16-bit numb... | 1 2
0 2 1
3 3 3
| possible 1 3 1 3 | 1 second | 256 megabytes | ['bitmasks', '*3000'] |
H. Virustime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Bubbleland a group of special programming forces gets a top secret job to calculate the number of potentially infected people by a new unknown virus. The state has a population of n people and every day ther... | 5 12 1
1 1 2
1 1 3
1 3 4
2 4
2 5
3
2 1
1 1 2
1 3 2
2 1
3
2 1
| 4 1 1 3 1 | 5 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'dsu', 'graphs', '*2500'] |
G. Growing flowerstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSarah has always been a lover of nature, and a couple of years ago she saved up enough money to travel the world and explore all the things built by nature over its lifetime on earth. During this time... | 5 5
1 2 3 4 5
2 3
1 1 2 5
2 4
1 2 4 5
2 2
| 9 6 4 | 4 seconds | 256 megabytes | ['data structures', '*3500'] |
F. Coinstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial ad... | 4 2
1 2
2 2
| 1 | 1 second | 256 megabytes | ['math', '*2700'] |
E. 5G Antenna Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter making a strategic plan with carriers for expansion of mobile network throughout the whole country, the government decided to cover rural areas with the last generation of 5G network.Since 5G ... | 10 10 3
4 2 2 3 2 3 3 2 3
3 3.5 2 4.5 2 4.5 3
4 7 8 7.5 8.5 8 8 7.5 9
5
2 3.5 0.5
3.3 2 0.4
5 2.5 0.5
7.5 8.5 0.5
3 7 0.5
| 1.000000 1 0 1.500000 2 0 1 0.500000 1 1 0.250000 1 2 0.000000 0 | 2 seconds | 256 megabytes | ['geometry', '*2700'] |
D. Does anyone else hate the wind?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMark and his crew are sailing across the sea of Aeolus (in Greek mythology Aeolus was the keeper of the winds). They have the map which represents the NxM matrix with land and sea field... | 3 3
5 2 15
M S S
S S S
S S P
S W N N N N N N N N N N N N N
2 1 0
1 2 0
| -1 | 1 second | 256 megabytes | ['*3100'] |
C. Dušan's Railwaytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs you may already know, Dušan is keen on playing with railway models. He has a big map with cities that are connected with railways. His map can be seen as a graph where vertices are cities and the ra... | 10 3
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
| 8 3 7 3 5 3 6 3 1 7 9 7 10 7 4 7 5 | 1 second | 256 megabytes | ['divide and conquer', 'graphs', 'trees', '*3500'] |
B. Valuable Papertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help all other world nati... | 3 5
1 2 1
2 3 2
3 3 3
2 1 4
2 2 5
| 4 | 2 seconds | 256 megabytes | ['binary search', 'flows', 'graph matchings', 'graphs', '*1900'] |
A. Wakanda Forevertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the Kingdom of Wakanda, the 2020 economic crisis has made a great impact on each city and its surrounding area. Cities have made a plan to build a fast train rail between them to boost the economy, ... | 4
35 19 20
76 14 75
23 43 78
14 76 98
| 3 4 1 2 | 1 second | 256 megabytes | ['*3500'] |
F. Boring Queriestime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYura owns a quite ordinary and boring array a of length n. You think there is nothing more boring than that, but Vladik doesn't agree!In order to make Yura's array even more boring, Vladik makes q bori... | 3
2 3 5
4
1 3
3 3
2 3
2 3
| 6 2 15 30 | 3 seconds | 512 megabytes | ['data structures', 'math', 'number theory', '*2700'] |
E. Minlexestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome time ago Lesha found an entertaining string s consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.... | abcdd
| 3 abc 2 bc 1 c 0 1 d | 1 second | 256 megabytes | ['dp', 'greedy', 'implementation', 'strings', '*2700'] |
D. Returning Hometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city.Let's repre... | 5 3
1 1 5 5
1 2
4 1
3 3
| 5 | 2 seconds | 256 megabytes | ['graphs', 'shortest paths', 'sortings', '*2300'] |
C. Bargaintime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can't come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the pr... | 107
| 42 | 1 second | 256 megabytes | ['combinatorics', 'dp', 'math', '*1700'] |
B. Nice Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA matrix of size n \times m is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers (a_1, a_2, \dots , a_k) is a palindrome, if for any integer i (1 \le i \le k) the e... | 2
4 2
4 2
2 4
4 2
2 4
3 4
1 2 3 4
5 6 7 8
9 10 11 18
| 8 42 | 1 second | 256 megabytes | ['greedy', 'implementation', 'math', '*1300'] |
A. Fencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some p... | 2
1 2 3
12 34 56
| 4 42 | 1 second | 256 megabytes | ['geometry', 'math', '*800'] |
E. Swedish Heroestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile playing yet another strategy game, Mans has recruited n Swedish heroes, whose powers which can be represented as an array a.Unfortunately, not all of those mighty heroes were created as capable a... | 4
5 6 7 8
| 26 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'implementation', '*2700'] |
D. Hexagonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLindsey Buckingham told Stevie Nicks "Go your own way". Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.Consider a hexagonal tiling of the plane as on the ... | 2
-3 1
1 3 5 7 9 11
1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
| 18 1000000000000000000 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'implementation', 'math', 'shortest paths', '*1900'] |
C. Palindromifiertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRingo found a string s of length n in his yellow submarine. The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the str... | abac
| 2 R 2 R 5 | 1 second | 256 megabytes | ['constructive algorithms', 'strings', '*1400'] |
B. Putting Bricks in the Walltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPink Floyd are pulling a prank on Roger Waters. They know he doesn't like walls, he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a gri... | 3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
| 1 3 4 2 1 2 2 1 0 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*1100'] |
A. XORwicetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers a and b and a really important quest.In order to complete the quest, Sana has to output the sma... | 6
6 12
4 9
59 832
28 14
4925 2912
1 1
| 10 13 891 18 6237 0 | 1 second | 256 megabytes | ['bitmasks', 'greedy', 'math', '*800'] |
E. Battle Lemmingstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputA lighthouse keeper Peter commands an army of n battle lemmings. He ordered his army to stand in a line and numbered the lemmings from 1 to n from left to right. Some of the lemmings hold shields. Eac... | 5
1 0 0 0 1
| 0 2 3 3 3 3 3 3 3 3 3 | 2 seconds | 512 megabytes | ['dp', 'greedy', '*2500'] |
D. Rescue Nibel!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOri and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing h... | 7 3
1 7
3 8
4 5
6 7
1 3
5 10
8 9
| 9 | 2 seconds | 256 megabytes | ['combinatorics', 'data structures', 'sortings', '*1800'] |
C2. Pokémon Army (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are so... | 3
3 1
1 3 2
1 2
2 2
1 2
1 2
1 2
7 5
1 2 5 4 3 6 7
1 2
6 7
3 4
1 2
2 3
| 3 4 2 2 2 9 10 10 10 9 11 | 2 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'dp', 'greedy', 'implementation', '*2100'] |
C1. Pokémon Army (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are so... | 3
3 0
1 3 2
2 0
1 2
7 0
1 2 5 4 3 6 7
| 3 2 9 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dp', 'greedy', '*1300'] |
B. Rock and Levertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output "You must lift the dam. With a lever. I will give it to you.You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to ... | 5
5
1 4 3 7 10
3
1 1 1
4
6 2 5 3
2
2 4
1
1
| 1 3 2 0 0 | 1 second | 256 megabytes | ['bitmasks', 'math', '*1200'] |
A. Cubes Sortingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because w... | 3
5
5 3 2 1 4
6
2 2 2 2 2 2
2
2 1
| YES YES NO | 1 second | 256 megabytes | ['math', 'sortings', '*900'] |
F. Rain of Firetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points.Brimstone should visit e... | 4
100 0
0 100
-100 0
0 -100
| 100 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'dfs and similar', 'dsu', 'graphs', 'implementation', '*2800'] |
E. Decryptiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn agent called Cypher is decrypting a message, that contains a composite number n. All divisors of n, which are greater than 1, are placed in a circle. Cypher can choose the initial order of numbers in the... | 3
6
4
30
| 2 3 6 1 2 4 0 2 30 6 3 15 5 10 0 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', 'math', 'number theory', '*2100'] |
D2. Sage's Birthday (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both ... | 7
1 3 2 2 4 5 4
| 3 3 1 4 2 4 2 5 | 1 second | 256 megabytes | ['binary search', 'brute force', 'constructive algorithms', 'greedy', 'sortings', 'two pointers', '*1500'] |
D1. Sage's Birthday (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both ... | 5
1 2 3 4 5
| 2 3 1 4 2 5 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'greedy', 'sortings', '*1000'] |
C. Killjoytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).Killjoy's account is a... | 3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
| 1 0 2 | 1 second | 256 megabytes | ['greedy', 'implementation', 'math', '*1500'] |
B. Stairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.A staircase is a squared figur... | 4
1
8
6
1000000000000000000
| 1 2 1 30 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'implementation', 'math', '*1200'] |
A. Digit Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...In each of t matches of the ... | 4
1
2
1
3
3
102
4
2069
| 2 1 1 2 | 1 second | 256 megabytes | ['games', 'greedy', 'implementation', '*900'] |
G. Three Occurrencestime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. We denote the subarray a[l..r] as the array [a_l, a_{l + 1}, \dots, a_r] (1 \le l \le r \le n).A subarray is considered good if every integer that ... | 9
1 2 2 2 1 1 2 2 2
| 3 | 5 seconds | 512 megabytes | ['data structures', 'divide and conquer', 'hashing', 'two pointers', '*2500'] |
F. Equal Producttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given four integers n, m, l and r.Let's name a tuple (x_1, y_1, x_2, y_2) as good if: 1 \le x_1 < x_2 \le n; 1 \le y_2 < y_1 \le m; x_1 \cdot y_1 = x_2 \cdot y_2; l \le x_1 \cdot y_1 \le r.... | 8 20
91 100
| -1 -1 -1 -1 -1 6 16 8 12 -1 -1 | 2 seconds | 256 megabytes | ['data structures', 'math', 'number theory', 'two pointers', '*3000'] |
E. Expected Damagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a computer game. In this game, you have to fight n monsters.To defend from monsters, you need a shield. Each shield has two parameters: its current durability a and its defence rating ... | 3 2
1 3 1
2 1
1 2
| 665496237 1 | 2 seconds | 256 megabytes | ['binary search', 'combinatorics', 'probabilities', '*2400'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.