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 |
|---|---|---|---|---|---|
F2. Marek and Matching (hard version)time limit per test15 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version, n \le 7.Marek is working hard on creating strong test cases to his new algorithmic problem. Do you want to know what it is... | 2
50 50
50 50
| 937500007 | 15 seconds | 256 megabytes | ['brute force', 'probabilities', '*3200'] |
F1. Marek and Matching (easy version)time limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easier version of the problem. In this version, n \le 6.Marek is working hard on creating strong testcases to his new algorithmic problem. You want to know what it is? Na... | 2
50 50
50 50
| 937500007 | 7 seconds | 256 megabytes | ['brute force', 'probabilities', '*3100'] |
E. Wojtek and Card Trickstime limit per test3.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWojtek has just won a maths competition in Byteland! The prize is admirable — a great book called 'Card Tricks for Everyone.' 'Great!' he thought, 'I can finally use this old, dusted deck of ... | 3 3
2 1 3
3 1 2
1 3 2
| 25 | 3.5 seconds | 256 megabytes | ['math', '*2700'] |
D. Konrad and Company Evaluationtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKonrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company.Ther... | 4 5
1 2
2 4
1 3
3 4
2 3
2
2
3
| 4 3 2 | 4 seconds | 256 megabytes | ['graphs', '*2400'] |
C. Kamil and Making a Streamtime limit per test4 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputKamil likes streaming the competitive programming videos. His MeTube channel has recently reached 100 million subscribers. In order to celebrate this, he posted a video with an interesting p... | 5
4 5 6 0 8
1 2
1 3
1 4
4 5
| 42 | 4 seconds | 768 megabytes | ['math', 'number theory', 'trees', '*2000'] |
B. Marcin and Training Camptime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMarcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each oth... | 4
3 2 3 6
2 8 5 10
| 15 | 3 seconds | 256 megabytes | ['brute force', 'greedy', '*1700'] |
A. Anadi and Dominotime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 \leq a \leq b \leq 6, there is exactly one domino with a dots on one half and ... | 4 4
1 2
2 3
3 4
4 1
| 4 | 2 seconds | 256 megabytes | ['brute force', 'graphs', '*1700'] |
H. Moving Walkwaystime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAirports often use moving walkways to help you walking big distances faster. Each such walkway has some speed that effectively increases your speed. You can stand on such a walkway and let it move y... | 1 5
0 2 2.0
| 3.000000000000 | 2.5 seconds | 256 megabytes | ['data structures', 'greedy', 'math', '*3300'] |
G2. Into Blocks (hard version)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. In this version q \le 200\,000.A sequence of integers is called nice if its elements are arranged in blocks like in [3, 3, 3, 4, 1, 1]. Formally, i... | 5 6
1 2 1 2 1
2 1
4 1
5 3
2 3
4 2
2 1
| 2 1 0 0 2 3 0 | 5 seconds | 256 megabytes | ['data structures', '*3200'] |
G1. Into Blocks (easy version)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easier version of the next problem. In this version, q = 0.A sequence of integers is called nice if its elements are arranged in blocks like in [3, 3, 3, 4, 1, 1]. Formally, if ... | 5 0
3 7 3 7 3
| 2 | 5 seconds | 256 megabytes | ['data structures', 'dsu', 'greedy', 'implementation', 'two pointers', '*2000'] |
F. Koala and Notebooktime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputKoala Land consists of m bidirectional roads connecting n cities. The roads are numbered from 1 to m by order in input. It is guaranteed, that one can reach any city from every other city.Koala sta... | 11 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
| 1 12 123 1234 12345 123456 1234567 12345678 123456789 345678826 | 2 seconds | 512 megabytes | ['data structures', 'dfs and similar', 'graphs', 'shortest paths', 'strings', 'trees', '*2600'] |
E2. Rotate Columns (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a harder version of the problem. The difference is only in constraints.You are given a rectangular n \times m matrix a. In one move you can choose any column and cyclically shif... | 3
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
3 3
9 9 9
1 1 1
1 1 1
| 12 29 27 | 3 seconds | 256 megabytes | ['bitmasks', 'dp', 'greedy', 'sortings', '*2500'] |
E1. Rotate Columns (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an easier version of the next problem. The difference is only in constraints.You are given a rectangular n \times m matrix a. In one move you can choose any column and cyclicall... | 2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
| 12 29 | 3 seconds | 256 megabytes | ['bitmasks', 'brute force', 'dp', 'greedy', 'sortings', '*2000'] |
D. Cow and Snackstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!... | 5 4
1 2
4 3
1 4
3 4
| 1 | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', '*1700'] |
C. Paint the Digitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n digits d_1d_2 \dots d_{n}. You need to paint all the digits in two colors so that: each digit is painted either in the color 1 or in the color 2; if you write in a row... | 5
12
040425524644
1
0
9
123456789
2
98
3
987
| 121212211211 1 222222222 21 - | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1500'] |
B. Koala and Lightstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.After taking a quick glance at them, Koala realizes that each of his light... | 3
101
3 3
3 2
3 1
| 2 | 1 second | 256 megabytes | ['implementation', 'math', 'number theory', '*1300'] |
A. Paint the Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of integers a_1, a_2, \dots, a_n. You need to paint elements in colors, so that: If we consider any color, all elements of this color must be divisible by the minimal eleme... | 6
10 2 3 5 4 2
| 3 | 1 second | 256 megabytes | ['greedy', 'implementation', 'math', '*800'] |
H. Red Blue Treetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree of n nodes. The tree is rooted at node 1, which is not considered as a leaf regardless of its degree.Each leaf of the tree has one of the two colors: red or blue. Leaf node v initia... | 5 2
1 2
1 3
2 4
2 5
-1 -1 0 1 0
9
1 1
1 2
3 -2
1 1
1 2
3 1
2 5 1
1 1
1 2
| 0 0 1 1 0 1 | 5 seconds | 256 megabytes | ['data structures', 'implementation', 'trees', '*3500'] |
G. Polygonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers n and k.You need to construct k regular polygons having same circumcircle, with distinct number of sides l between 3 and n. Illustration for the first example. You can rotate them... | 6 2
| 6 | 1 second | 256 megabytes | ['greedy', 'math', 'number theory', '*2800'] |
F. Bits And Piecestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of n integers.You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.Here \& denotes the bitwise AND operation, and | d... | 3
2 4 6
| 6 | 2 seconds | 256 megabytes | ['bitmasks', 'dfs and similar', 'dp', 'greedy', '*2600'] |
E. Let Them Slidetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n arrays that can have different sizes. You also have a table with w columns and n rows. The i-th array is placed horizontally in the i-th row. You can slide each array within its row as ... | 3 3
3 2 4 8
2 2 5
2 6 3
| 10 15 16 | 4 seconds | 256 megabytes | ['data structures', 'implementation', '*2200'] |
D. Restore Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array of integers p_{1},p_{2}, \ldots,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3... | 3
0 0 0
| 3 2 1 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', 'implementation', '*1900'] |
C. Magic Gridtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet us define a magic grid to be a square matrix of integers of size n \times n, satisfying the following conditions. All integers from 0 to (n^2 - 1) inclusive appear in the matrix exactly once. Bitwise... | 4
| 8 9 1 13 3 12 7 5 0 2 4 11 6 10 15 14 | 1 second | 256 megabytes | ['constructive algorithms', '*1800'] |
B. Uniquenesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_{1}, a_{2}, \ldots, a_{n}. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.In other words, at most one time you can choose two int... | 3
1 2 3
| 0 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'implementation', 'two pointers', '*1500'] |
A. XORinaccitime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbe... | 3
3 4 2
4 5 0
325 265 1231232
| 7 4 76 | 1 second | 256 megabytes | ['math', '*900'] |
G. Indie Albumtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMishka's favourite experimental indie band has recently dropped a new album! Songs of that album share one gimmick. Each name s_i is one of the following types: 1~c — a single lowercase Latin letter; 2~... | 20
1 d
2 1 a
2 2 d
2 3 a
2 4 d
2 5 a
2 6 d
2 7 a
1 d
2 9 o
2 10 k
2 11 i
2 12 d
2 13 o
2 14 k
2 15 i
2 1 o
2 17 k
2 18 i
2 15 i
12
8 da
8 dada
8 ada
6 dada
3 dada
19 doki
19 ok
16 doki
15 doki
9 d
1 a
20 doki
| 4 3 3 2 0 1 1 2 1 1 0 2 | 3 seconds | 512 megabytes | ['data structures', 'dfs and similar', 'hashing', 'string suffix structures', 'strings', 'trees', '*2700'] |
F. Remainder Problemtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.You have to process two types of queries to this array: 1 x y — increase a_x... | 5
1 3 4
2 3 0
2 4 3
1 4 -4
2 1 0
| 4 4 0 | 4 seconds | 512 megabytes | ['brute force', 'data structures', 'implementation', '*2100'] |
E. XOR Guessingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush... | 0
32 | ? 3 5 6 ? 32 24 37 ! 5 | 1 second | 256 megabytes | ['bitmasks', 'interactive', 'math', '*1900'] |
D. Number Of Permutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n pairs of integers: (a_1, b_1), (a_2, b_2), \dots , (a_n, b_n). This sequence is called bad if it is sorted in non-descending order by first elements or if it is so... | 3
1 1
2 2
3 1
| 3 | 2 seconds | 256 megabytes | ['combinatorics', '*1800'] |
C. Gas Pipelinetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment [0, n] on OX axis. The road can have several crossroads, but for simplicity, we'll de... | 4
8 2 5
00110010
8 1 1
00110010
9 100000000 100000000
010101010
2 5 1
00
| 94 25 2900000000 13 | 2 seconds | 256 megabytes | ['dp', 'greedy', '*1500'] |
B. Square Fillingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two matrices A and B. Each matrix contains exactly n rows and m columns. Each element of A is either 0 or 1; each element of B is initially 0.You may perform some operations with matrix B.... | 3 3
1 1 1
1 1 1
0 1 1
| 3 1 1 1 2 2 2 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1200'] |
A. There Are Two Types Of Burgerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two ... | 3
15 2 3
5 10
7 5 2
10 12
1 100 100
100 100
| 40 34 0 | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', 'math', '*800'] |
B. Make Product Equal Onetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n numbers a_1, a_2, \dots, a_n. With a cost of one coin you can perform the following operation:Choose one of these numbers and add or subtract 1 from it.In particular, we can appl... | 2
-1 1
| 2 | 1 second | 256 megabytes | ['dp', 'implementation', '*900'] |
A. Choose Two Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array A, consisting of n positive integers a_1, a_2, \dots, a_n, and an array B, consisting of m positive integers b_1, b_2, \dots, b_m. Choose some element a of A and some element ... | 1
20
2
10 20
| 20 20 | 1 second | 256 megabytes | ['math', 'sortings', '*800'] |
F. Beauty of a Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDefine the beauty of a permutation of numbers from 1 to n (p_1, p_2, \dots, p_n) as number of pairs (L, R) such that 1 \le L \le R \le n and numbers p_L, p_{L+1}, \dots, p_R are consecutive R-... | 4
1 1
5 6
5 8
5 10
| YES 1 YES 2 4 1 5 3 NO YES 2 3 1 4 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'math', '*3400'] |
E. Expected Value Againtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given integers n, k. Let's consider the alphabet consisting of k different elements.Let beauty f(s) of the string s be the number of indexes i, 1\le i<|s|, for which prefix of s of length... | 2 3
| 333333336 | 4 seconds | 256 megabytes | ['combinatorics', 'strings', '*3100'] |
D. Almost Alltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:For every two nodes i, j, look at the path between them and count t... | 3
2 3
2 1
| 3 2 1 1 2 2 | 1 second | 256 megabytes | ['constructive algorithms', 'trees', '*2700'] |
C. Palindromic Pathstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problemYou are given a grid n\times n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on... | 3
0
1
0
1
1
1
1 | ? 1 1 1 3 ? 1 1 2 3 ? 2 1 2 3 ? 3 1 3 3 ? 2 2 3 3 ? 1 2 3 2 ? 1 2 3 3 ! 100 001 000 | 1 second | 256 megabytes | ['implementation', 'interactive', '*2400'] |
B. Shortest Cycletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n integer numbers a_1, a_2, \dots, a_n. Consider graph on n nodes, in which nodes i, j (i\neq j) are connected if and only if, a_i AND a_j\neq 0, where AND denotes the bitwise AND operatio... | 4
3 6 28 9
| 4 | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'graphs', 'shortest paths', '*1900'] |
A. Almost Equaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:For every n consecutive numbers on the... | 3
| YES 1 4 5 2 3 6 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1200'] |
E. Natasha, Sasha and the Prefix Sumstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNatasha's favourite numbers are n and 1, and Sasha's favourite numbers are m and -1. One day Natasha and Sasha met and wrote down every possible array of length n+m such that some n... | Input0 2 | Output0 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'math', 'number theory', '*2300'] |
D2. Kirk and a Binary String (hard version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you sol... | 110
| 010 | 1 second | 256 megabytes | ['data structures', 'greedy', 'math', 'strings', '*2100'] |
D1. Kirk and a Binary String (easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.Kirk has a binary string s (a string w... | 110
| 010 | 1 second | 256 megabytes | ['brute force', 'greedy', 'strings', '*2000'] |
C. Anna, Svyatoslav and Mapstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe main characters have been omitted to be short.You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequ... | 4
0110
0010
0001
1000
4
1 2 3 4
| 3 1 2 4 | 2 seconds | 256 megabytes | ['dp', 'graphs', 'greedy', 'shortest paths', '*1700'] |
B. Mislove Has Lost an Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMislove had an array a_1, a_2, \cdots, a_n of n positive integers, but he has lost it. He only remembers the following facts about it: The number of different numbers in the array is not less... | 4 2 2
| 5 7 | 1 second | 256 megabytes | ['greedy', 'math', '*900'] |
A. BowWow and the Timetabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, t... | 100000000
| 4 | 1 second | 256 megabytes | ['math', '*1000'] |
F2. Complete the Projects (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.Polycarp is a very famou... | 3 4
4 6
10 -2
8 -1
| 3 | 2 seconds | 256 megabytes | ['dp', 'greedy', '*2300'] |
F1. Complete the Projects (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.Polycarp is a very famou... | 3 4
4 6
10 -2
8 -1
| YES | 2 seconds | 256 megabytes | ['greedy', '*2100'] |
E. Boxerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). ... | Input43 2 4 1 | Output4 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1500'] |
D2. Remove the Substring (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the length of the string.You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guar... | bbaba
bb
| 3 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'implementation', 'two pointers', '*1700'] |
D1. Remove the Substring (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the length of the string.You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guar... | bbaba
bb
| 3 | 2 seconds | 256 megabytes | ['greedy', 'implementation', '*1600'] |
C. Common Divisorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers.Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number... | 5
1 2 3 4 5
| 1 | 2 seconds | 256 megabytes | ['implementation', 'math', '*1300'] |
B. Equal Rectanglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given 4n sticks, the length of the i-th stick is a_i.You have to create n rectangles, each rectangle will consist of exactly 4 sticks from the given set. The rectangle consists of four sides,... | 5
1
1 1 10 10
2
10 5 2 10 1 1 2 5
2
10 5 1 10 5 1 1 1
2
1 1 1 1 1 1 1 1
1
10000 10000 10000 10000
| YES YES NO YES YES | 2 seconds | 256 megabytes | ['greedy', 'math', '*1200'] |
A. Circle of Studentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students standing in a circle in some order. The index of the i-th student is p_i. It is guaranteed that all indices of students are distinct integers from 1 to n (i. e. they form a per... | 5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
| YES YES NO YES YES | 2 seconds | 256 megabytes | ['implementation', '*1000'] |
F. You Are Given Some Letters...time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a uppercase Latin letters 'A' and b letters 'B'.The period of the string is the smallest such positive integer k that s_i = s_{i~mod~k} (0-indexed) for each i. Note that thi... | 2 4
| 4 | 1 second | 256 megabytes | ['binary search', 'implementation', 'math', '*2700'] |
E. You Are Given Some Strings...time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string t and n strings s_1, s_2, \dots, s_n. All strings consist of lowercase Latin letters.Let f(t, s) be the number of occurences of string s in string t. For example, ... | aaabacaa
2
a
aa
| 5 | 3 seconds | 256 megabytes | ['brute force', 'string suffix structures', 'strings', '*2400'] |
D. Print a 1337-string...time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.You are given an integer n. You have to fin... | 2
6
1
| 113337 1337 | 1 second | 256 megabytes | ['combinatorics', 'constructive algorithms', 'math', 'strings', '*1900'] |
C. You Are Given a WASD-string...time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: 'W' — move one cell up; 'S' — mo... | 3
DSAWWAW
D
WA
| 8 2 4 | 2 seconds | 256 megabytes | ['brute force', 'data structures', 'dp', 'greedy', 'implementation', 'math', 'strings', '*2100'] |
B. You Are Given a Decimal String...time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you have a special x-y-counter. This counter can store some value as a decimal number; at first, the counter has value 0. The counter performs the following algorithm: it pri... | 0840
| -1 17 7 7 7 -1 2 17 2 7 17 17 7 5 5 5 2 7 2 7 7 7 7 4 3 7 1 7 2 5 7 5 4 7 3 3 2 5 2 3 7 5 3 3 7 7 1 7 2 7 -1 5 7 3 7 -1 2 9 2 7 2 2 1 2 1 2 2 2 0 1 17 7 7 5 7 9 2 17 2 3 2 2 2 2 2 2 0 2 2 2 7 7 5 3 7 7 1 3 2 7 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'shortest paths', '*1700'] |
A. You Are Given Two Binary Strings...time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two binary strings x and y, which are binary representations of some two integers (let's denote these integers as f(x) and f(y)). You can choose any integer k \ge 0, ... | 4
1010
11
10001
110
1
1
1010101010101
11110000
| 1 3 0 0 | 2 seconds | 256 megabytes | ['bitmasks', 'greedy', '*1100'] |
E2. Knightmare (hard)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Alice and Bob are playing a game on the chessboard of size n \times m where n and m are even. The rows are numbered from 1 to n and the columns are numbered from 1 to... | 8 8
2 3 1 8
| WHITE 4 4 | 3 seconds | 256 megabytes | ['graphs', 'interactive', 'shortest paths', '*3000'] |
E1. Knightmare (easy)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem only differs from the next problem in constraints.This is an interactive problem.Alice and Bob are playing a game on the chessboard of size n \times m where n and m are even. The rows ... | 8 8
2 3 1 8
| WHITE 4 4 | 3 seconds | 256 megabytes | ['graphs', 'interactive', 'shortest paths', '*2900'] |
D. Treasure Huntingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are on the island which can be represented as a n \times m table. The rows are numbered from 1 to n and the columns are numbered from 1 to m. There are k treasures on the island, the i-th of them... | 3 3 3 2
1 1
2 1
3 1
2 3
| 6 | 3 seconds | 256 megabytes | ['binary search', 'dp', 'greedy', 'implementation', '*2100'] |
C. Maximum Mediantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of n integers, where n is odd. You can make the following operation with it: Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace i... | 3 2
1 3 5
| 5 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'math', 'sortings', '*1400'] |
B. Zero Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \ldots, a_n.In one operation you can choose two elements a_i and a_j (i \ne j) and decrease each of them by one.You need to check whether it is possible to make all the elem... | 4
1 1 2 2
| YES | 1 second | 256 megabytes | ['greedy', 'math', '*1500'] |
A. Important Examtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA class of students wrote a multiple-choice test.There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer f... | 2 4
ABCD
ABCE
1 2 3 4
| 16 | 1 second | 256 megabytes | ['implementation', 'strings', '*900'] |
F. Graph Travelertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputGildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges t... | 4
0 0 0 0
2
2 3
1
2
3
2 4 1
4
3 1 2 1
6
1 0
2 0
3 -1
4 -2
1 1
1 5
| 1 1 2 1 3 2 | 2 seconds | 512 megabytes | ['brute force', 'data structures', 'dfs and similar', 'dp', 'graphs', 'implementation', 'math', 'number theory', '*2300'] |
E. Compress Wordstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmugae has a sentence consisting of n words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of... | 5
I want to order pizza
| Iwantorderpizza | 1 second | 256 megabytes | ['brute force', 'hashing', 'implementation', 'string suffix structures', 'strings', '*2000'] |
D. White Linestime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of n rows and n columns of square cells. The rows are numbered from 1 to n, from top to b... | 4 2
BWWW
WBBW
WBBW
WWWB
| 4 | 1.5 seconds | 256 megabytes | ['brute force', 'data structures', 'dp', 'implementation', 'two pointers', '*1900'] |
C. Round Corridortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by n sectors, and the outer area is equally divided by m sectors. A wall exists between ea... | 4 6 3
1 1 2 3
2 6 1 2
2 6 2 4
| YES NO YES | 1 second | 256 megabytes | ['math', 'number theory', '*1400'] |
B. Block Adventuretime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGildong is playing a video game called Block Adventure. In Block Adventure, there are n columns of blocks in a row, and the columns are numbered from 1 to n. All blocks have equal heights. The height o... | Input53 0 14 3 53 1 21 4 74 10 010 20 10 202 5 50 111 9 999 | OutputYESNOYESNOYES | 1 second | 256 megabytes | ['dp', 'greedy', '*1200'] |
A. Hoteliertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAmugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to... | 8
LLRL1RL1
| 1010000011 | 1 second | 256 megabytes | ['brute force', 'data structures', 'implementation', '*800'] |
B. Water Lilytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grab... | 1 2
| 1.5000000000000 | 1 second | 256 megabytes | ['geometry', 'math', '*1000'] |
A. City Daytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the... | 10 2 2
10 9 6 7 8 3 2 1 4 5
| 3 | 1 second | 256 megabytes | ['implementation', '*1000'] |
F. GCD Groups 2time limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group i... | 4
2 3 6 7
| YES 2 2 1 1 | 0.5 seconds | 256 megabytes | ['greedy', 'number theory', 'probabilities', '*2900'] |
E. Rectangle Painting 2time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a square grid of size n \times n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It cos... | 10 2
4 1 5 10
1 4 10 5
| 4 | 1 second | 256 megabytes | ['flows', 'graph matchings', 'graphs', '*2500'] |
D. Rectangle Painting 1time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a square grid of size n \times n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It cos... | 3
###
#.#
###
| 3 | 1 second | 256 megabytes | ['dp', '*2300'] |
C. Matching vs Independent Settime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a graph with 3 \cdot n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.A set of edges is called a matching if no two edges sha... | 4
1 2
1 3
1 2
1 2
1 3
1 2
2 5
1 2
3 1
1 4
5 1
1 6
2 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
| Matching 2 IndSet 1 IndSet 2 4 Matching 1 15 | 1 second | 256 megabytes | ['constructive algorithms', 'graphs', 'greedy', 'sortings', '*2000'] |
B. Welfare Statetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they... | 4
1 2 3 4
3
2 3
1 2 2
2 1
| 3 2 3 4 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'data structures', 'sortings', '*1600'] |
A. MP3time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of... | 6 1
2 1 2 3 4 3
| 2 | 1 second | 256 megabytes | ['sortings', 'two pointers', '*1600'] |
F. Coloring Gametime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputAlice and Bob want to play a game. They have n colored paper strips; the i-th strip is divided into a_i cells numbered from 1 to a_i. Each cell can have one of 3 colors.In the beginning of the game, Ali... | 3
3 4 5
2
1 1 1
2 2 2
1 1 1
1 0 0
0 1 1
| 14346 | 5 seconds | 512 megabytes | ['dp', 'games', 'matrices', '*2700'] |
E. Culture Codetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figur... | 7
4 1
4 2
4 2
2 1
5 4
6 4
3 2
| 6 | 2 seconds | 256 megabytes | ['binary search', 'combinatorics', 'data structures', 'dp', 'shortest paths', 'sortings', '*2300'] |
D. Yet Another Subarray Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots , a_n and two integers m and k.You can choose some subarray a_l, a_{l+1}, \dots, a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, \dots, a_{r-1}, a_... | 7 3 10
2 -4 15 -3 4 8 3
| 7 | 2 seconds | 256 megabytes | ['dp', 'greedy', 'math', '*1900'] |
C. Array Splittingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sorted array a_1, a_2, \dots, a_n (for each index i > 1 condition a_i \ge a_{i-1} holds) and an integer k.You are asked to divide this array into k non-empty consecutive subarrays. Eve... | 6 3
4 8 15 16 23 42
| 12 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1400'] |
B. Pillarstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n pillars aligned in a row and numbered from 1 to n.Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius a_i.You can move these disks from one pillar to a... | 4
1 3 4 2
| YES | 1.5 seconds | 256 megabytes | ['greedy', 'implementation', '*1000'] |
A. DIY Wooden Laddertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote a k-step ladder as the following structure: exactly k + 2 wooden planks, of which two planks of length at least k+1 — the base of the ladder; k planks of length at least 1 — the steps... | 4
4
1 3 1 3
3
3 3 2
5
2 3 3 4 2
3
1 1 2
| 2 1 2 0 | 2 seconds | 256 megabytes | ['greedy', 'math', 'sortings', '*900'] |
F. K-th Pathtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a connected undirected weighted graph consisting of n vertices and m edges.You need to print the k-th smallest shortest path in this graph (paths from the vertex to itself are not counted, p... | 6 10 5
2 5 1
5 3 9
6 2 2
1 3 1
5 1 8
6 5 10
1 6 5
6 4 6
3 6 2
3 4 5
| 3 | 2.5 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'shortest paths', 'sortings', '*2200'] |
E. Connected Component on a Chessboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two integers b and w. You have a chessboard of size 10^9 \times 10^9 with the top left cell at (1; 1), the cell (1; 1) is painted white.Your task is to find a connect... | 3
1 1
1 4
2 5
| YES 2 2 1 2 YES 2 3 1 3 3 3 2 2 2 4 YES 2 3 2 4 2 5 1 3 1 5 3 3 3 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1800'] |
D2. RGB Substring (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the size of the input.You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'.You are also given an i... | 3
5 2
BGGGG
5 3
RBRGR
5 5
BBBRR
| 1 0 3 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'implementation', 'two pointers', '*1600'] |
D1. RGB Substring (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the size of the input.You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'.You are also given an i... | 3
5 2
BGGGG
5 3
RBRGR
5 5
BBBRR
| 1 0 3 | 2 seconds | 256 megabytes | ['implementation', '*1500'] |
C. Robot Breakouttime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous!Fortu... | 4
2
-1 -2 0 0 0 0
-1 -2 0 0 0 0
3
1 5 1 1 1 1
2 5 0 1 0 1
3 5 1 0 0 0
2
1337 1337 0 1 1 1
1336 1337 1 1 0 1
1
3 5 1 1 1 1
| 1 -1 -2 1 2 5 0 1 -100000 -100000 | 3 seconds | 256 megabytes | ['implementation', '*1500'] |
B. Odd Sum Segmentstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers a_1, a_2, \dots, a_n. You want to split it into exactly k non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for eac... | 3
5 3
7 18 3 14 1
5 4
1 2 3 4 5
6 2
1 2 8 4 10 2
| YES 1 3 5 NO NO | 3 seconds | 256 megabytes | ['constructive algorithms', 'math', '*1200'] |
A. Three Piles of Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of th... | 4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
| 4 55 15000000000000000 51 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'math', '*800'] |
F. Geometers Anonymous Clubtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDenis holds a Geometers Anonymous Club meeting in SIS. He has prepared n convex polygons numbered from 1 to n for the club. He plans to offer members of the club to calculate Minkowski sums o... | 3
3
0 0
1 0
0 1
4
1 1
1 2
0 2
0 1
3
2 2
1 2
2 1
3
1 2
2 3
1 3
| 5 5 6 | 2 seconds | 256 megabytes | ['data structures', 'geometry', 'math', 'sortings', '*2500'] |
E. OpenStreetMaptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSeryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size n \times m cells on a map (rows of grid are numbered from 1 to n from n... | 3 4 2 1
1 2 3 59
| 111 | 2 seconds | 256 megabytes | ['data structures', 'two pointers', '*2100'] |
D2. Submarine in the Rybinsk Sea (hard edition)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, \dots, a_n.A team of SIS students is going to... | 3
12 3 45
| 12330 | 2 seconds | 256 megabytes | ['combinatorics', 'math', 'number theory', '*1800'] |
D1. Submarine in the Rybinsk Sea (easy edition)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem differs from the next one only in the presence of the constraint on the equal length of all numbers a_1, a_2, \dots, a_n. Actually, this problem is a subtask ... | 3
12 33 45
| 26730 | 2 seconds | 256 megabytes | ['combinatorics', 'math', 'number theory', '*1500'] |
C. Basketball Exercisetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFinally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 \cdot n students have come to Demid's exercise session, and he lined up them into ... | 5
9 3 5 7 3
5 8 1 4 5
| 29 | 2 seconds | 256 megabytes | ['dp', '*1400'] |
B. Sport Mafiatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEach evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, ... | 1 1
| 0 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'math', '*1000'] |
A. Drinks Choosingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOld timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?... | 5 3
1
3
1
1
2
| 4 | 2 seconds | 256 megabytes | ['greedy', 'math', '*1000'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.