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
D. Rudolf and the Ball Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRudolf and Bernard decided to play a game with their friends. n people stand in a circle and start throwing a ball to each other. They are numbered from 1 to n in the clockwise order.Let's ca...
56 3 22 ?2 ?2 ?12 1 23 110 7 42 ?9 14 ?7 02 08 15 ?5 3 14 04 ?1 ?4 1 12 ?
3 2 4 6 1 11 4 3 5 7 9 3 2 3 5 1 3
2 seconds
256 megabytes
['dfs and similar', 'dp', 'implementation', '*1200']
C. Rudolf and the Ugly Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRudolf has a string s of length n. Rudolf considers the string s to be ugly if it contains the substring^\dagger "pie" or the substring "map", otherwise the string s will be considered beau...
69mmapnapie9azabazapi8mappppie18mapmapmapmapmapmap1p11pppiepieeee
2 0 2 6 0 2
2 seconds
256 megabytes
['dp', 'greedy', 'strings', '*900']
B. Rudolf and 121time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRudolf has an array a of n integers, the elements are numbered from 1 to n.In one operation, he can choose an index i (2 \le i \le n - 1) and assign: a_{i - 1} = a_{i - 1} - 1 a_i = a_i - 2 a_{i + 1...
751 3 5 5 252 4 4 5 150 1 3 3 165 6 0 2 3 041 2 7 237 1 041 1 1 1
YES NO YES NO NO NO NO
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'math', '*1000']
A. Rudolf and the Tickettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRudolf is going to visit Bernard, and he decided to take the metro to get to him. The ticket can be purchased at a machine that accepts exactly two coins, the sum of which does not exceed k.Rudol...
44 4 81 5 10 142 1 8 12 3 44 81 2 34 2 71 1 1 12 73 4 20001 1 11 1 1 1
6 0 4 12
1 second
256 megabytes
['brute force', 'math', '*800']
B. Binary Pathtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a 2 \times n grid filled with zeros and ones. Let the number at the intersection of the i-th row and the j-th column be a_{ij}.There is a grasshopper at the top-left cell (1, 1) that can only...
32000041101110080010011111101101
000 2 11000 1 001001101 4
1 second
256 megabytes
['dp', 'greedy', 'implementation', '*1300']
A. Shuffle Partytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \ldots, a_n. Initially, a_i=i for each 1 \le i \le n.The operation \texttt{swap}(k) for an integer k \ge 2 is defined as follows: Let d be the largest divisor^\dagger o...
4145120240229
1 4 4 67108864
1 second
256 megabytes
['implementation', 'math', '*800']
F. Grand Finale: Circlestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given n circles on the plane. The i-th of these circles is given by a tuple of integers (x_i, y_i, r_i), where (x_i, y_i) are the coordinates of its center, and r_i is the radius of the ...
4 1 1 3 -1 1 3 1 -1 2 -1 -1 2
0.0000000000000000 -0.7637626158259733 0.9724747683480533
2 seconds
512 megabytes
['binary search', 'geometry', '*3300']
E. Yet Yet Another Permutation Problemtime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of length n.Please count the number of permutations q of length n which satisfy the following: for each 1 \le i < n, \max(q_1,\ldots,q_i) \neq \max(p...
622 131 2 333 1 242 4 1 353 5 1 4 2156 13 2 8 7 11 1 3 9 15 4 5 12 10 14
1 3 2 4 18 424488915
5 seconds
1024 megabytes
['divide and conquer', 'fft', 'math', '*3400']
D. Bitwise Paradoxtime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b of size n along with a fixed integer v.An interval [l, r] is called a good interval if (b_l \mid b_{l+1} \mid \ldots \mid b_r) \ge v, where | denotes the bitwise OR o...
33 72 1 32 2 342 1 31 2 52 2 32 1 34 55 1 2 44 2 3 362 1 41 3 152 3 42 2 41 2 132 1 41 56412 1 1
-1 3 2 5 2 2 1 -1
5 seconds
1024 megabytes
['binary search', 'bitmasks', 'data structures', 'greedy', 'two pointers', '*3100']
C. Pokémon Arenatime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are at a dueling arena. You also possess n Pokémons. Initially, only the 1-st Pokémon is standing in the arena.Each Pokémon has m attributes. The j-th attribute of the i-th Pokémon is a_{i,j}. Each ...
43 32 3 12 9 96 1 71 2 13 32 3 19 9 96 1 71 2 14 22 8 3 518 2417 101 101 16 321412674 3212925 172015806 250849370 306960171 333018900950000001 950000001 950000001821757276 783362401 760000001570000001 700246226 600757652380000001 423513575 474035234315201473 300580025 2870234451 1 1
2 6 17 1224474550
3 seconds
512 megabytes
['data structures', 'graphs', 'greedy', 'implementation', 'shortest paths', 'sortings', '*2400']
B. Pinballtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a one-dimensional grid of length n. The i-th cell of the grid contains a character s_i, which is either '<' or '>'.When a pinball is placed on one of the cells, it moves according to the following ru...
33><<4<<<<6<><<<>
3 6 5 1 2 3 4 1 4 7 10 8 1
2 seconds
256 megabytes
['binary search', 'data structures', 'implementation', 'math', 'two pointers', '*2000']
A. Bitwise Operation Wizardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.There is a secret sequence p_0, p_1, \ldots, p_{n-1}, which is a permutation of \{0,1,\ldots,n-1\}.You need to find any two indices i and j such that p_i \oplus...
2 4 < = > 2
? 0 2 3 1 ? 1 1 2 3 ? 1 2 0 3 ! 3 2 ! 0 1
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'greedy', 'interactive', 'math', '*1700']
F. Andrey's Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMaster Andrey loves trees^{\dagger} very much, so he has a tree consisting of n vertices.But it's not that simple. Master Timofey decided to steal one vertex from the tree. If Timofey stole vertex v fro...
351 31 44 53 254 24 33 55 152 11 51 41 3
1 1 3 4 0 0 1 1 1 2 2 1 3 5 0 0 0 0 0 0 1 1 1 2 1 1 1 2 1 1 1 2 3 3 2 3 4 5 3 4 0 0 0 0 0 0 0 0
4 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'dfs and similar', 'dsu', 'greedy', 'implementation', 'trees', '*2800']
E. Distance Learning Courses in MACtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year has arrived in the Master's Assistance Center, which means it's time to introduce a new feature!Now students are given distance learning courses, with a total of n course...
320 13 431 11 22 241 71 73 102 251 33 42 31 41 261 22 20 11 13 30 043 45 52 51 2
1 5 4 15 11 15 15 7 1 3 3 3
2 seconds
256 megabytes
['bitmasks', 'brute force', 'data structures', 'greedy', 'math', '*2400']
D. Exam in MACtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Master's Assistance Center has announced an entrance exam, which consists of the following.The candidate is given a set s of size n and some strange integer c. For this set, it is needed to calculate ...
83 31 2 31 179574 60 3 5 61 115 100 2 4 8 105 101 3 5 7 94 102 4 6 73 1000000000228 1337 998244353
3 16139 10 2 33 36 35 499999998999122959
2 seconds
256 megabytes
['binary search', 'combinatorics', 'implementation', 'math', '*1800']
C. Messenger in MACtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the new messenger for the students of the Master's Assistance Center, Keftemerum, an update is planned, in which developers want to optimize the set of messages shown to the user. There are a tota...
55 84 31 52 44 32 31 64 103 124 82 12 125 2624 78 2830 223 817 175 1415 31000000000 998244353179 239228 1337993 1007
3 1 2 1 0
3 seconds
256 megabytes
['binary search', 'brute force', 'constructive algorithms', 'data structures', 'dp', 'greedy', 'sortings', '*1800']
B. Informatics in MACtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the Master's Assistance Center, Nyam-Nyam was given a homework assignment in informatics.There is an array a of length n, and you want to divide it into k > 1 subsegments^{\dagger} in such a way ...
520 050 1 2 3 480 1 7 1 0 1 0 332 2 240 1 2 0
2 1 1 2 2 -1 3 1 3 4 5 6 8 3 1 1 2 2 3 3 -1
1 second
256 megabytes
['constructive algorithms', '*1200']
A. Entertainment in MACtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCongratulations, you have been accepted to the Master's Assistance Center! However, you were extremely bored in class and got tired of doing nothing, so you came up with a game for yourself.You ar...
54cpm2grib10kupitimilablodarbuz1000000000capybara6abacaba
cpm birggrib kupitimilablodarbuz arabypaccapybara abacaba
1 second
256 megabytes
['constructive algorithms', 'strings', '*800']
E. Weird LCM Operationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an integer n, you construct an array a of n integers, where a_i = i for all integers i in the range [1, n]. An operation on this array is defined as follows: Select three distinct indices ...
3347
1 1 2 3 1 1 3 4 3 3 5 7 5 6 7 2 3 4
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'number theory', '*3000']
D2. XOR Break — Game Versiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.This is the game version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the solo version. You can solve...
4 1 0 0 3 0 0 13 3 4 0 0 777777770001 0 0
second first 2 1 first 10 7 1 2 first 777777770000 1
3 seconds
256 megabytes
['bitmasks', 'games', 'greedy', 'interactive', '*2400']
D1. XOR Break — Solo Versiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the solo version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the game version. You can solve and get points for both versio...
37 34 2481885160128643072 45035996273704960
1 7 3 -1 3 481885160128643072 337769972052787200 49539595901075456 45035996273704960
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'greedy', '*2100']
C. Find a Minetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.You are given a grid with n rows and m columns. The coordinates (x, y) represent the cell on the grid, where x (1 \leq x \leq n) is the row number counting from the top and ...
2 4 4 3 2 2 0 5 5 1 2 3
? 1 1 ? 1 4 ? 4 1 ? 2 3 ! 2 3 ? 5 5 ? 2 2 ? 3 3 ! 1 1
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'geometry', 'greedy', 'interactive', 'math', '*1700']
B. Yet Another Coin Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have 5 different types of coins, each with a value equal to one of the first 5 triangular numbers: 1, 3, 6, 10, and 15. These coin types are available in abundance. Your goal is to find th...
14123571112141617182098402931328
1 2 1 3 2 2 2 3 2 3 2 2 8 26862090
1 second
256 megabytes
['brute force', 'dp', 'greedy', 'math', '*1200']
A. Too Min Too Maxtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array a of n elements, find the maximum value of the expression:|a_i - a_j| + |a_j - a_k| + |a_k - a_l| + |a_l - a_i|where i, j, k, and l are four distinct indices of the array a, with 1 \le i...
541 1 1 151 1 2 2 385 1 3 2 -3 -1 10 343 3 1 141 2 2 -1
0 6 38 8 8
1 second
256 megabytes
['greedy', 'math', '*800']
G. Turtle Magic: Royal Turtle Shell Patterntime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTurtle Alice is currently designing a fortune cookie box, and she would like to incorporate the theory of LuoShu into it.The box can be seen as an n \times m grid (n, m \ge 5)...
26 7 43 3 circle3 6 square5 3 circle5 4 square5 5 31 1 circle1 2 circle1 3 circle
8 4 3 1 0 8 4 1 0
3 seconds
256 megabytes
['bitmasks', 'brute force', 'combinatorics', 'constructive algorithms', 'dfs and similar', 'math', '*2300']
F. Turtle Mission: Robot and the Earthquaketime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe world is a grid with n rows and m columns. The rows are numbered 0, 1, \ldots, n-1, while the columns are numbered 0, 1, \ldots, m-1. In this world, the columns are cyclic...
64 50 1 0 0 00 0 1 0 01 0 1 1 00 0 0 0 03 30 0 01 0 00 0 05 30 0 00 0 01 0 00 0 01 0 03 70 0 1 0 0 1 01 0 1 0 1 0 00 1 0 0 0 0 03 40 1 0 01 0 0 00 1 1 05 50 0 0 0 00 1 0 1 00 1 0 1 00 1 0 1 00 0 0 1 0
7 3 3 8 -1 12
3 seconds
256 megabytes
['dfs and similar', 'dp', 'graphs', 'shortest paths', '*2100']
E. Turtle vs. Rabbit Race: Optimal Trainingstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIsaac begins his training. There are n running tracks available, and the i-th track (1 \le i \le n) consists of a_i equal-length sections. Given an integer u (1 \le u \le 10^...
563 1 4 1 5 931 82 75 911011 195 10 9 6 8 3 10 7 358 561 129 31 275 4557 9 2 5 2101 372 93 334 324 152 24 22 193 72 7109 1 6 7 6 3 10 7 3 10510 433 239 36 85 14
3 4 5 1 9 2 9 4 9 5 2 5 5 5 2 4 5 4 2 10 6 9 7 7
5 seconds
256 megabytes
['binary search', 'implementation', 'math', 'ternary search', '*1500']
D. Turtle Tenacity: Continual Modstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array a_1, a_2, \ldots, a_n, determine whether it is possible to rearrange its elements into b_1, b_2, \ldots, b_n, such that b_1 \bmod b_2 \bmod \ldots \bmod b_n \neq 0.Here ...
861 2 3 4 5 653 3 3 3 332 2 351 1 2 3 731 2 231 1 265 2 10 10 10 243 6 9 3
YES NO YES NO YES NO YES NO
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'math', 'number theory', 'sortings', '*1200']
C. Turtle Fingers: Count the Values of ktime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three positive integers a, b and l (a,b,l>0). It can be shown that there always exists a way to choose non-negative (i.e. \ge 0) integers k, x, and y such that l = ...
112 5 202 5 214 6 482 3 723 5 752 2 10243 7 83349100 100 10000007 3 22 6 617 3 632043
6 1 5 12 6 11 24 4 1 3 24
5 seconds
256 megabytes
['brute force', 'implementation', 'math', 'number theory', '*1100']
B. Turtle Math: Fast Three Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \ldots, a_n.In one move, you can perform either of the following two operations: Choose an element from the array and remove it from the array. As a resu...
842 2 5 431 3 243 7 6 81142 2 4 225 572 4 8 1 9 3 424 10
1 0 0 1 1 2 1 1
2 seconds
256 megabytes
['implementation', 'math', 'number theory', '*800']
A. Turtle Puzzle: Rearrange and Negatetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of n integers. You must perform the following two operations on the array (the first, then the second): Arbitrarily rearrange the elements of the array or...
83-2 3 -31020 11-99410 -2 -3 75-1 -2 -3 -4 -56-41 22 -69 73 -15 -50121 2 3 4 5 6 7 8 9 10 11 12
8 0 1 99 22 15 270 78
2 seconds
256 megabytes
['greedy', 'math', 'sortings', '*800']
G. Moving Platformstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a game where you need to move through a labyrinth. The labyrinth consists of n platforms, connected by m passages. Each platform is at some level l_i, an integer number from 0 to H - 1. In a...
33 3 101 9 42 3 01 23 21 32 1 101 24 61 28 7 2522 14 5 3 10 14 11 19 5 4 10 7 16 18 182 86 33 57 52 61 44 7
6 -1 52
3 seconds
512 megabytes
['graphs', 'math', 'number theory', 'shortest paths', '*2300']
F. Feed Catstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a fun game where you need to feed cats that come and go. The level of the game consists of n steps. There are m cats; the cat i is present in steps from l_i to r_i, inclusive. In each step, you can...
315 62 103 52 47 78 1211 111000 11 10005 101 23 43 43 43 41 11 23 33 43 4
5 1 10
3 seconds
512 megabytes
['data structures', 'dp', 'sortings', '*1900']
E. Final Countdowntime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are in a nuclear laboratory that is about to explode and destroy the Earth. You must save the Earth before the final countdown reaches zero. The countdown consists of n (1 \le n \le 4 \cdot 10^5) ...
52425123452994000527456480697259671309012631002
46 13715 108 5 507200774732968121125145546
2 seconds
512 megabytes
['implementation', 'math', 'number theory', '*1600']
D. Card Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo players are playing an online card game. The game is played using a 32-card deck. Each card has a suit and a rank. There are four suits: clubs, diamonds, hearts, and spades. We will encode them with cha...
83S3C 9S 4C 6D 3S 7S2C3S 5D 9S 6H1H6C 5D1S7S 3S1H9S 9H1S9S 9H1C9D 8H2C9C 9S 6H 8C
3C 4C 6D 9S 3S 7S IMPOSSIBLE IMPOSSIBLE 3S 7S 9S 9H 9H 9S IMPOSSIBLE 6H 9C 9S 8C
2 seconds
256 megabytes
['greedy', 'implementation', '*1400']
C. LR-remainderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n, a positive integer m, and a string of commands of length n. Each command is either the character 'L' or the character 'R'.Process all n commands in the order they a...
44 63 1 4 2LRRL5 11 1 1 1 1LLLLL6 81 2 3 4 5 6RLLLRR1 1000010000R
0 2 4 1 0 0 0 0 0 0 0 0 4 4 4 0
2 seconds
256 megabytes
['brute force', 'data structures', 'implementation', 'math', 'two pointers', '*1400']
B. Chaya Calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Chaya tribe believes that there are n signs of the apocalypse. Over time, it has been found out that the i-th sign occurs every a_i years (in years a_i, 2 \cdot a_i, 3 \cdot a_i, \dots).According t...
463 2 4 5 9 1851 2 3 4 551 1 1 1 1650 30 711 200 503 1006
36 5 5 2012
2 seconds
256 megabytes
['number theory', '*1100']
A. Thorns and Coinstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputDuring your journey through computer universes, you stumbled upon a very interesting world. It is a path with n consecutive cells, each of which can either be empty, contain thorns, or a coin. In one ...
310.@@*@.**@@5.@@@@15.@@..@***..@@@*
3 4 3
1 second
512 megabytes
['dp', 'greedy', 'implementation', '*800']
G. One-Dimensional Puzzletime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a one-dimensional puzzle, all the elements of which need to be put in one row, connecting with each other. All the puzzle elements are completely white and distinguishable from each ot...
111 1 1 11 2 5 104 6 100 200900000 900000 900000 9000000 0 0 00 0 566 2391 0 0 0100 0 100 00 0 0 45 5 0 25 4 0 5
4 66 0 794100779 1 0 1 0 1 36 126
4 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*2000']
F. Chat Screenshotstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people in the programming contest chat. Chat participants are ordered by activity, but each person sees himself at the top of the list.For example, there are 4 participants in the chat, a...
105 11 2 3 4 54 41 2 3 42 3 1 43 2 1 44 2 3 16 21 3 5 2 4 66 3 5 2 1 43 31 2 32 3 13 2 110 21 2 3 4 5 6 7 8 9 1010 9 8 7 6 5 4 3 2 11 115 21 2 3 5 42 1 3 5 43 33 1 22 3 11 3 25 43 5 1 4 22 5 1 4 31 5 4 3 25 1 4 3 23 31 3 22 1 33 2 1
YES YES YES YES NO YES YES YES YES NO
2 seconds
256 megabytes
['combinatorics', 'dfs and similar', 'graphs', '*1700']
E. Anna and the Valentine's Day Gifttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha gave Anna a list a of n integers for Valentine's Day. Anna doesn't need this list, so she suggests destroying it by playing a game.Players take turns. Sasha is a gentleman, so ...
92 214 23 59 56 14 101 2007 800 15804 55000 123 30 410 106 4 6 2 3 1 10 9 10 71 161 1108 91 2 9 10 10 2 10 24 510 10 10 10
Sasha Anna Anna Sasha Sasha Anna Anna Anna Sasha
2 seconds
256 megabytes
['games', 'greedy', 'math', 'sortings', '*1400']
D. Divisible Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has two favorite integers x and y (they can be equal), and he has found an array a of length n.Polycarp considers a pair of indices \langle i, j \rangle (1 \le i < j \le n) beautiful if: a_...
76 5 21 2 7 4 9 67 9 51 10 15 3 8 12 159 4 1014 10 2 2 11 11 13 5 69 5 610 7 6 7 9 7 7 10 109 6 24 9 7 1 2 2 13 3 159 2 314 6 1 15 12 15 8 2 1510 5 713 3 3 2 12 11 3 7 13 14
2 0 1 3 5 7 0
2 seconds
256 megabytes
['combinatorics', 'math', 'number theory', '*1300']
C. Make Equal Againtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a of n integers. You can no more than once apply the following operation: select three integers i, j, x (1 \le i \le j \le n) and assign all elements of the array with indexes from ...
861 2 3 4 5 171 1 1 1 1 1 188 8 8 1 2 8 8 81121 231 2 374 3 2 7 1 1 399 9 2 9 2 5 5 5 3
4 0 2 0 1 2 6 7
2 seconds
256 megabytes
['brute force', 'greedy', 'math', '*1000']
B. Make Equaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n containers of water lined up, numbered from left to right from 1 to n. Each container can hold any amount of water; initially, the i-th container contains a_i units of water. The sum of a_i is ...
614321 354 5 2 1 331 2 374 5 5 0 6 4 476 5 5 1 3 4 4
YES NO YES NO NO YES
2 seconds
256 megabytes
['greedy', '*800']
A. Recovering a Small Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNikita had a word consisting of exactly 3 lowercase Latin letters. The letters in the Latin alphabet are numbered from 1 to 26, where the letter "a" has the index 1, and the letter "z" has th...
5247035548
aav rzz aaa czz auz
1 second
256 megabytes
['brute force', 'strings', '*800']
I. Counting Is Funtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary^\dagger pattern p of length n.A binary string q of the same length n is called good if for every i (1 \leq i \leq n), there exist indices l and r such that: 1 \leq l \leq i \l...
10
1
3 seconds
256 megabytes
['combinatorics', '*3500']
H. Interactive Mex Treetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Alice has a tree T consisting of n nodes, numbered from 1 to n. Alice will show T to Bob. After observing T, Bob needs to tell Alice two permutations p_1 and p_2 of...
1 3 1 1 2 2 3 2 3 1 0 1
1 2 3 2 1 3 ? 1 2 3 ? 2 1 3 ! 0
5 seconds
256 megabytes
['constructive algorithms', 'dfs and similar', 'interactive', 'trees', '*3300']
G. Prefix Max Set Countingtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDefine a function f such that for an array b, f(b) returns the array of prefix maxima of b. In other words, f(b) is an array containing only those elements b_i, for which b_i=\max(b_1,b_2,\ldo...
6121 231 21 331 22 351 21 31 41 5101 22 31 42 52 64 75 84 99 10
1 1 2 1 8 6
5 seconds
512 megabytes
['data structures', 'dp', 'trees', '*3100']
F. Maximize the Differencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor an array b of m non-negative integers, define f(b) as the maximum value of \max\limits_{i = 1}^{m} (b_i | x) - \min\limits_{i = 1}^{m} (b_i | x) over all possible non-negative integers x, ...
25 21 27 43 1 5 2
0 2 0 2 3 5
3 seconds
256 megabytes
['bitmasks', 'brute force', 'dfs and similar', '*2700']
E. 2..3...4.... Wonderful! Wonderful!time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStack has an array a of length n such that a_i = i for all i (1 \leq i \leq n). He will select a positive integer k (1 \leq k \leq \lfloor \frac{n-1}{2} \rfloor) and do the followin...
434510
2 4 10 2 487 162 85 10
3 seconds
256 megabytes
['combinatorics', 'dp', 'math', '*2400']
D2. Sum over all Substrings (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference between the two versions is the constraint on t and n. You can make hacks only if both versions of the problem are ...
4112105000002011110110000000111111
1 2 0 346
2 seconds
256 megabytes
['bitmasks', 'divide and conquer', 'dp', 'dsu', 'greedy', 'implementation', 'strings', '*2100']
D1. Sum over all Substrings (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the easy version of the problem. The only difference between the two versions is the constraint on t and n. You can make hacks only if both versions of the problem are ...
4112105000002011110110000000111111
1 2 0 346
2 seconds
256 megabytes
['brute force', 'dp', 'greedy', 'strings', '*1800']
C. Lexicographically Largesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStack has an array a of length n. He also has an empty set S. Note that S is not a multiset.He will do the following three-step operation exactly n times: Select an index i such that 1 \leq...
322 151 100 1000 1000000 100000000036 4 8
3 2 1000000005 1000004 1003 102 2 11 7 6
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'greedy', 'sortings', '*1700']
B. Permutation Printingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive integer n.Find a permutation^\dagger p of length n such that there do not exist two distinct indices i and j (1 \leq i, j < n; i \neq j) such that p_i divides p_j and p_{i...
243
4 1 2 3 1 2 3
1 second
256 megabytes
['brute force', 'constructive algorithms', 'math', '*1000']
A. Maximise The Scoretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are 2n positive integers written on a whiteboard. Being bored, you decided to play a one-player game with the numbers on the whiteboard.You start with a score of 0. You will increase your scor...
312 321 1 2 131 1 1 1 1 1
2 2 3
1 second
256 megabytes
['greedy', 'sortings', '*800']
F. Sasha and the Wedding Binary Search Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHaving overcome all the difficulties and hardships, Sasha finally decided to marry his girlfriend. To do this, he needs to give her an engagement ring. However, his girlfriend...
35 52 3 -1-1 -1 24 -1 3-1 5 -1-1 -1 -13 692 3 47-1 -1 13-1 -1 693 32 3 -1-1 -1 -1-1 -1 -1
4 1 10
2 seconds
256 megabytes
['brute force', 'combinatorics', 'data structures', 'dfs and similar', 'math', 'trees', '*2300']
E. Sasha and the Happy Tree Cuttingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha was given a tree^{\dagger} with n vertices as a prize for winning yet another competition. However, upon returning home after celebrating his victory, he noticed that some parts...
341 22 32 421 34 161 23 16 15 24 233 13 62 651 22 33 44 541 22 33 44 5
1 2 4
2 seconds
256 megabytes
['bitmasks', 'brute force', 'dfs and similar', 'dp', 'graphs', 'greedy', 'math', 'trees', '*2300']
D. Sasha and a Walk in the Citytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha wants to take a walk with his girlfriend in the city. The city consists of n intersections, numbered from 1 to n. Some of them are connected by roads, and from any intersection, the...
431 33 243 42 33 151 23 45 12 341 22 33 4
7 12 16 11
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'trees', '*1900']
C. Sasha and the Casinotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha decided to give his girlfriend the best handbag, but unfortunately for Sasha, it is very expensive. Therefore, Sasha wants to earn it. After looking at earning tips on the internet, he deci...
92 1 72 1 12 3 153 3 64 4 55 4 74 88 100000000025 69 23113 97 18806
YES NO YES NO NO YES NO NO NO
2 seconds
256 megabytes
['binary search', 'brute force', 'constructive algorithms', 'games', 'greedy', 'math', '*1400']
B. Sasha and the Drawingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEven in kindergarten, Sasha liked a girl. Therefore, he wanted to give her a drawing and attract her attention.As a drawing, he decided to draw a square grid of size n \times n, in which some cel...
73 43 33 103 94 77 112 3
2 2 6 5 4 6 2
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', '*800']
A. Sasha and the Beautiful Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha decided to give his girlfriend an array a_1, a_2, \ldots, a_n. He found out that his girlfriend evaluates the beauty of the array as the sum of the values (a_i - a_{i - 1}) for all ...
532 1 3369 69 695100 54 80 43 9043 4 3 322 1
2 0 57 1 1
1 second
256 megabytes
['constructive algorithms', 'greedy', 'math', 'sortings', '*800']
F. Digital Patternstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnya is engaged in needlework. Today she decided to knit a scarf from semi-transparent threads. Each thread is characterized by a single integer — the transparency coefficient.The scarf is made accor...
4 4 01 1 2 31 2 2 3
20
2 seconds
256 megabytes
['combinatorics', 'data structures', 'implementation', 'math', '*2900']
E. Modular Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers x and y. A sequence a of length n is called modular if a_1=x, and for all 1 < i \le n the value of a_{i} is either a_{i-1} + y or a_{i-1} \bmod y. Here x \bmod y denotes th...
35 8 3 283 5 3 69 1 5 79
YES 8 11 2 2 5 NO NO
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'dp', 'graphs', 'greedy', 'math', 'number theory', '*2300']
D. Lonely Mountain Dungeonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce, the people, elves, dwarves, and other inhabitants of Middle-earth gathered to reclaim the treasures stolen from them by Smaug. In the name of this great goal, they rallied around the pow...
53 1 01 2 33 5 102 5 34 3 33 2 1 24 1 04 1 4 24 1 104 1 4 2
4 40 9 13 0
1 second
256 megabytes
['brute force', 'data structures', 'greedy', 'math', 'ternary search', '*1900']
C. Physical Education Lessontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a well-known school, a physical education lesson took place. As usual, everyone was lined up and asked to settle in "the first–k-th" position.As is known, settling in "the first–k-th" posi...
510 23 176 4100 991000000000 500000000
4 1 9 0 1
1 second
256 megabytes
['brute force', 'math', 'number theory', '*1600']
B. Equalizetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has two hobbies — adding permutations^{\dagger} to arrays and finding the most frequently occurring element. Recently, he found an array a and decided to find out the maximum number of elements equal to...
721 247 1 4 13103 102 10451 101 1 100 151 10 100 1000 123 131000000000 999999997 999999999
2 2 3 2 1 1 2
1 second
256 megabytes
['binary search', 'greedy', 'sortings', 'two pointers', '*1200']
A. Rectangle Cuttingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has a rectangle of size a \times b. He tries to cut this rectangle into two rectangles with integer sides by making a cut parallel to one of the sides of the original rectangle. Then Bob tries to...
71 12 12 63 22 22 46 3
No No Yes Yes Yes Yes No
1 second
256 megabytes
['geometry', 'math', '*800']
G. Paint Chargestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA horizontal grid strip of n cells is given. In the i-th cell, there is a paint charge of size a_i. This charge can be: either used to the left — then all cells to the left at a distance less than a_i ...
131121 122 121 222 231 1 133 1 231 3 171 2 3 1 2 4 272 1 1 1 2 3 1102 2 5 1 6 1 8 2 8 262 1 2 1 1 261 1 4 1 3 2
1 2 1 1 1 3 1 2 3 4 2 3 3
4 seconds
256 megabytes
['data structures', 'dp', 'greedy', 'math', '*2300']
F. Microcycletime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an undirected weighted graph with n vertices and m edges. There is at most one edge between each pair of vertices in the graph, and the graph does not contain loops (edges from a vertex to itself). T...
56 61 2 12 3 13 1 14 5 15 6 16 4 16 61 2 102 3 83 1 54 5 1005 6 406 4 36 151 2 45 2 86 1 76 3 106 5 13 2 84 3 45 3 62 6 65 4 54 1 36 4 54 2 13 1 71 5 54 62 3 21 3 101 4 13 4 72 4 51 2 24 52 1 103 1 34 2 61 4 72 3 3
1 3 1 2 3 3 3 6 4 5 1 5 4 2 1 6 3 1 4 1 4 3 2 3 3 2 3 1
4 seconds
256 megabytes
['data structures', 'dfs and similar', 'dsu', 'graphs', 'greedy', 'implementation', 'sortings', 'trees', '*1900']
E. Klever Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k (k \le n), where k is even.A permutation of length n is an array consisting of n distinct integers from 1 to n in any order. For example, [2,3,1,5,4] is a permuta...
52 23 210 413 47 4
2 1 1 3 2 1 8 4 10 2 7 5 9 3 6 4 10 1 13 5 9 2 12 6 8 3 11 7 1 6 3 7 2 5 4
2 seconds
256 megabytes
['constructive algorithms', 'math', 'two pointers', '*1400']
D. Find the Different Ones!time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of n integers, and q queries.Each query is represented by two integers l and r (1 \le l \le r \le n). Your task is to find, for each query, two indices i and j (or de...
551 1 2 1 131 51 21 3630 20 20 10 10 2051 22 32 42 63 545 2 3 441 21 42 32 451 4 3 2 451 52 43 43 54 552 3 1 4 271 21 41 52 42 53 54 5
2 3 -1 -1 1 3 2 1 -1 -1 4 2 4 6 5 3 1 2 1 2 2 3 3 2 1 3 2 4 3 4 5 3 5 4 1 2 4 2 1 3 2 3 3 2 5 4 5 4
5 seconds
256 megabytes
['binary search', 'brute force', 'data structures', 'dp', 'dsu', 'greedy', 'two pointers', '*1300']
C. Choose the Different Ones!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array a of n integers, an array b of m integers, and an even number k.Your task is to determine whether it is possible to choose exactly \frac{k}{2} elements from both arrays in su...
66 5 62 3 8 5 6 51 3 4 10 56 5 62 3 4 5 6 51 3 8 10 33 3 41 3 52 4 62 5 41 47 3 4 4 21 4 226 4 4 21 5 232 2 1 4 3
YES NO YES YES NO NO
2 seconds
256 megabytes
['brute force', 'greedy', 'math', '*1000']
B. Following the Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp lost the string s of length n consisting of lowercase Latin letters, but he still has its trace.The trace of the string s is an array a of n integers, where a_i is the number of such ind...
5110 0 0 1 0 2 0 3 1 1 4100 0 0 0 0 1 0 1 1 01080 1 2 3 4 5 6 780 0 0 0 0 0 0 0
abracadabra codeforces a aaaaaaaa dijkstra
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'strings', '*900']
A. Make it Whitetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a horizontal strip of n cells. Each cell is either white or black.You can choose a continuous segment of cells once and paint them all white. After this action, all the black cells in this segm...
86WBBWBW1B2WB3BBW4BWWB6BWBWWB6WWBBWB9WBWBWWWBW
4 1 1 2 4 6 4 7
2 seconds
256 megabytes
['greedy', 'strings', '*800']
G. Vlad and Trouble at MITtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has a son who really wanted to go to MIT. The college dormitory at MIT (Moldova Institute of Technology) can be represented as a tree with n vertices, each vertex being a room with ex...
331 1CSP41 2 2PCSS41 2 2PPSS
1 1 2
1 second
256 megabytes
['dfs and similar', 'dp', 'flows', 'graphs', 'greedy', 'implementation', 'trees', '*1900']
F. Vlad and Avoiding Xtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has a grid of size 7 \times 7, where each cell is colored black or white. In one operation, he can choose any cell and change its color (black \leftrightarrow white).Find the minimum num...
4WWWWWWWWWWWBBBWWWWWBWWWBBBBBWWWBWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBBBBBWWBBBBBWWBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBWBBBBBBBBBBBBBBWWWWWWWBBBBBBBBBBBBBBBBBBBBB
1 2 0 5
4 seconds
256 megabytes
['bitmasks', 'brute force', 'dfs and similar', 'dp', 'implementation', '*2200']
E. Vlad and an Odd Orderingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has n cards numbered 1, 2, \dots, n. He wants to lay them down in a row as follows: First, he lays down all the odd-numbered cards from smallest to largest. Next, he lays down al...
117 17 27 37 47 57 67 71 134 1484 191000000000 1000000000
1 3 5 7 2 6 4 1 27 37 536870912
2 seconds
256 megabytes
['binary search', 'bitmasks', 'data structures', 'dp', 'implementation', 'math', 'number theory', '*1500']
D. Vlad and Divisiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has n non-negative integers, and he wants to divide all of them into several groups so that in any group, any pair of numbers does not have matching bit values among bits from 1-st to 31-s...
941 4 3 420 21474836475476319172 261956880 2136179468 1671164475 188552676731335890506 811593141 11282233624688873446 627404104 1520079543 1458610201461545621 2085938026 1269342732 143025857540 0 2147483647 214748364730 0 214748364781858058912 289424735 1858058912 2024818580 1858058912 289424735 122665067 289424735
4 1 3 2 2 3 2 2 4
2 seconds
256 megabytes
['bitmasks', 'greedy', '*1300']
C. Vlad and a Sum of Sum of Digitstime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPlease note that the time limit for this problem is only 0.5 seconds per test.Vladislav wrote the integers from 1 to n, inclusive, on the board. Then he replaced each integer with th...
71212314342024200000
51 1 3 6 18465 28170 4600002
0.5 seconds
256 megabytes
['dp', 'implementation', '*1200']
B. Vlad and Shapestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has a binary square grid of n \times n cells. A triangle or a square is drawn on the grid with symbols \texttt{1}. As he is too busy being cool, he asks you to tell him which shape is drawn o...
630000110114000000000100111021111500111000100000000000000001000000000000000000000000000000000000000000000000000111111111001111111000011111000000111000000001000003111111111
SQUARE TRIANGLE SQUARE TRIANGLE TRIANGLE SQUARE
1 second
256 megabytes
['geometry', 'implementation', '*800']
A. Vlad and the Best of Fivetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladislav has a string of length 5, whose characters are each either \texttt{A} or \texttt{B}.Which letter appears most frequently: \texttt{A} or \texttt{B}?InputThe first line of the input c...
8ABABBABABABBBABAAAAABBBBBBABAAAAAABBAAAA
B A B A B A A A
1 second
256 megabytes
['implementation', '*800']
D. Good Triptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n children in a class, m pairs among them are friends. The i-th pair who are friends have a friendship value of f_i. The teacher has to go for k excursions, and for each of the excursions she choos...
4100 0 242 1 101 2 13 1 22 1 15 2 41 2 253 2 24
0 55 777777784 40000020
1 second
256 megabytes
['combinatorics', 'dp', 'math', 'probabilities', '*1900']
B. A Balanced Problemset?time limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJay managed to create a problem of difficulty x and decided to make it the second problem for Codeforces Round #921. But Yash fears that this problem will make the contest highly unbalanced, ...
310 35 5420 69
2 1 6
1.5 seconds
256 megabytes
['brute force', 'greedy', 'math', 'number theory', '*1200']
A. We Got Everything Covered!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integers n and k. Your task is to find a string s such that all possible strings of length n that can be formed using the first k lowercase English alphabets occur...
41 22 12 22 3
ab aa baab abcbac
1 second
256 megabytes
['constructive algorithms', 'greedy', 'strings', '*800']
F. Anti-Proxy Attendancetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem!Mr. 1048576 is one of those faculty who hates wasting his time in taking class attendance. Instead of taking attendance the old-fashioned way, he decided to try ou...
2 5 3 2 1 2 0 1 0 2 0 1 6 6 2 2 0 1 1 0 0 0 1
? 1 4 ? 3 5 ? 2 2 ? 1 3 ? 3 3 ? 3 3 ! 3 ? 2 4 ? 4 4 ! 2 # ? 1 6 ? 1 3 ? 4 6 ? 1 1 ? 3 3 ? 5 5 ! 3 ? 2 2 ? 4 4 ! 4 #
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'interactive', 'ternary search', '*3500']
E. Paper Cutting Againtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a rectangular sheet of paper with initial height n and width m. Let the current height and width be h and w respectively. We introduce a xy-coordinate system so that the four corners of t...
42 4 102 4 82 4 22 4 6
0 1 833333342 250000003
3 seconds
256 megabytes
['combinatorics', 'probabilities', '*3100']
D. Balanced Subsequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, whi...
32 2 23 2 33 2 1
2 0 4
1 second
256 megabytes
['combinatorics', 'dp', 'math', '*2700']
C. Fractal Origamitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a square piece of paper with a side length equal to 1 unit. In one operation, you fold each corner of the square to the center of the paper, thus forming another square with a side length equa...
3123
0 1 714285638
1 second
256 megabytes
['geometry', 'math', 'matrices', '*2400']
B. Space Harbourtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points numbered 1 to n on a straight line. Initially, there are m harbours. The i-th harbour is at point X_i and has a value V_i. It is guaranteed that there are harbours at the points 1 and...
8 3 41 3 83 24 102 2 51 5 152 5 52 7 8
171 0 15
2 seconds
256 megabytes
['data structures', 'implementation', 'math', 'sortings', '*2100']
A. Did We Get Everything Covered?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k along with a string s.Your task is to check whether all possible strings of length n that can be formed using the first k lowercase English alphabets ...
32 2 4abba2 2 3abb3 3 10aabbccabab
YES NO aa NO ccc
2 seconds
256 megabytes
['constructive algorithms', 'dp', 'greedy', 'shortest paths', 'strings', '*1500']
F. Shrink-Reversetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary string s of length n (a string consisting of n characters, and each character is either 0 or 1).Let's look at s as at a binary representation of some integer, and name that integ...
8 210010010
7
3 seconds
256 megabytes
['binary search', 'brute force', 'greedy', 'hashing', 'implementation', 'string suffix structures', 'strings', '*2800']
E. Count Pathstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a tree, consisting of n vertices, numbered from 1 to n. Every vertex is colored in some color, denoted by an integer from 1 to n.A simple path of the tree is called beautiful if: it consis...
431 2 11 22 352 1 2 1 21 21 33 44 551 2 3 4 51 21 33 44 542 2 2 23 13 23 4
1 3 0 3
2 seconds
512 megabytes
['data structures', 'dfs and similar', 'dp', 'dsu', 'graphs', 'trees', '*2000']
D. Slimestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n slimes placed in a line. The slimes are numbered from 1 to n in order from left to right. The size of the i-th slime is a_i.Every second, the following happens: exactly one slime eats one of its ne...
443 2 4 231 2 352 2 3 1 174 2 3 6 1 1 8
2 1 2 1 1 1 -1 2 1 -1 1 2 2 1 1 3 1 1 4
2 seconds
256 megabytes
['binary search', 'constructive algorithms', 'data structures', 'greedy', 'two pointers', '*1800']
C. Find Btime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array a of length m is considered good if there exists an integer array b of length m such that the following conditions hold: \sum\limits_{i=1}^{m} a_i = \sum\limits_{i=1}^{m} b_i; a_i \neq b_i for eve...
15 41 2 1 4 51 54 43 41 3
YES NO YES NO
3 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1400']
B. Monsters Attack!time limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a computer game. The current level of this game can be modeled as a straight line. Your character is in point 0 of this line. There are n monsters trying to kill your character; the...
53 21 2 3-1 2 32 11 1-1 14 103 4 2 5-3 -2 1 35 32 1 3 2 5-3 -2 3 4 52 11 21 2
YES NO YES YES NO
2.5 seconds
256 megabytes
['dp', 'greedy', 'implementation', '*1100']
A. Moving Chipstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a ribbon divided into n cells, numbered from 1 to n from left to right. Each cell either contains a chip or is free.You can perform the following operation any number of times (possibly zero): c...
580 1 1 1 0 1 1 060 1 0 0 0 061 1 1 1 1 151 0 1 0 190 1 1 0 0 0 1 1 0
1 0 0 2 3
2 seconds
512 megabytes
['greedy', 'implementation', '*800']
F. Replace on Segmenttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n, where each element is an integer from 1 to x.You can perform the following operation with it any number of times: choose three integers l, r and k such...
33 21 2 16 31 2 3 1 2 312 33 1 3 1 2 1 1 2 3 1 1 3
1 2 2
3 seconds
256 megabytes
['dp', 'graph matchings', '*2500']
E. Increasing Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's recall that an increasing subsequence of the array a is a sequence that can be obtained from it by removing some elements without changing the order of the remaining elements, and the re...
4251337
1 0 3 0 1 0 5 2 2 3 4 2 7 -1 -1 0 0 2 3 -1
2 seconds
256 megabytes
['bitmasks', 'constructive algorithms', 'divide and conquer', 'greedy', 'math', '*1800']
D. Berserk Monsterstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMonocarp is playing a computer game (yet again). Guess what is he doing? That's right, killing monsters.There are n monsters in a row, numbered from 1 to n. The i-th monster has two parameters: attac...
353 4 7 5 104 9 1 18 122 11 341 1 2 43 3 4 2
3 1 0 0 0 0 0 1 1 1 0
2 seconds
256 megabytes
['brute force', 'data structures', 'dsu', 'implementation', 'math', '*1900']
C. Closest Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities located on the number line, the i-th city is in the point a_i. The coordinates of the cities are given in ascending order, so a_1 < a_2 < \dots < a_n.The distance between two cities ...
150 8 12 15 2051 41 53 43 25 1
3 8 1 4 14
2 seconds
256 megabytes
['greedy', 'implementation', 'math', '*1300']