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 |
|---|---|---|---|---|---|
B. Digits Sequence (Hard Edition)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 1234567891011121314... | 7
| 7 | 1 second | 256 megabytes | ['binary search', 'divide and conquer', 'implementation', '*1800'] |
A. Digits Sequence (Easy Edition)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 1234567891011121314... | 7
| 7 | 1 second | 256 megabytes | ['implementation', '*1000'] |
F. Destroy it!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.The boss battle consists of n turns. During each turn, you will get several ca... | 5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100
| 263 | 2 seconds | 256 megabytes | ['dp', 'implementation', 'sortings', '*2100'] |
E. Cover it!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your task is to choose at most... | 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
6 8
2 5
5 4
4 3
4 1
1 3
2 3
2 6
5 6
| 2 1 3 3 4 3 6 | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'shortest paths', 'trees', '*1700'] |
D. Recover it!time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAuthors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 \cdot 10^5. You don't know the array a, but you know the array b which is formed from it with th... | 3
3 5 2 3 2 4
| 3 4 2 | 4 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'greedy', 'number theory', 'sortings', '*1800'] |
C. Lose it!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers. Each a_i is one of the six following numbers: 4, 8, 15, 16, 23, 42.Your task is to remove the minimum number of elements to make this array good.An array of... | 5
4 8 15 16 23
| 5 | 2 seconds | 256 megabytes | ['dp', 'greedy', 'implementation', '*1300'] |
B. Merge it!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers a_1, a_2, \dots , a_n.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter wher... | 2
5
3 1 2 3 1
7
1 1 1 1 1 2 2
| 3 3 | 1 second | 256 megabytes | ['math', '*1100'] |
A. Divide it!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer n.You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: Replace n with \frac{n}{2} if n is divisible by 2; Replace n wit... | 7
1
10
25
30
14
27
1000000000000000000
| 0 4 6 6 -1 6 72 | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', '*800'] |
G. Yet Another Partiton Problemtime limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given array a_1, a_2, \dots, a_n. You need to split it into k subsegments (so every element is included in exactly one subsegment).The weight of a subsegment a_l, a_{l+1}, \dots, ... | 4 2
6 1 7 4
| 25 | 5 seconds | 512 megabytes | ['data structures', 'divide and conquer', 'dp', 'geometry', 'two pointers', '*3000'] |
F. The Number of Subpermutationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have an array a_1, a_2, \dots, a_n. Let's call some subarray a_l, a_{l + 1}, \dots , a_r of this array a subpermutation if it contains all integers from 1 to r-l+1 exactly once. For ... | 8
2 4 1 3 4 2 1 2
| 7 | 2 seconds | 256 megabytes | ['brute force', 'data structures', 'divide and conquer', 'hashing', 'math', '*2500'] |
E. Minimal Segment Covertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n intervals in form [l; r] on a number line.You are also given m queries in form [x; y]. What is the minimal number of intervals you have to take so that every point (not necessari... | 2 3
1 3
2 4
1 3
1 4
3 4
| 1 2 1 | 2 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'divide and conquer', 'dp', 'greedy', 'implementation', 'trees', '*2200'] |
D. Array Splittingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n and an integer k.You are asked to divide this array into k non-empty consecutive subarrays. Every element in the array should be included in exactly one sub... | 5 2
-1 -2 5 -4 8
| 15 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1900'] |
C. Electrificationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt first, there was a legend related to the name of the problem, but now it's just a formal statement.You are given n points a_1, a_2, \dots, a_n on the OX axis. Now you are asked to find such an inte... | 3
3 2
1 2 5
2 1
1 1000000000
1 0
4
| 3 500000000 4 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'greedy', '*1600'] |
B. Catch Overflow!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values ... | 9
add
for 43
end
for 10
for 15
add
end
add
end
| 161 | 1 second | 256 megabytes | ['data structures', 'expression parsing', 'implementation', '*1600'] |
A. From Hero to Zerotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer n and an integer k.In one step you can do one of the following moves: decrease n by 1; divide n by k if n is divisible by k. For example, if n = 27 and k = 3 you can do th... | 2
59 3
1000000000000000000 10
| 8 19 | 1 second | 256 megabytes | ['implementation', 'math', '*900'] |
F. Ehab and the Big Finaletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.You're given a tree consisting of n nodes, rooted at node 1. A tree is a connected graph with no cycles.We chose a hidden node x. In order to find this node, you... | 5
1 2
1 3
3 4
3 5
3
5 | d 2 s 3 ! 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'divide and conquer', 'graphs', 'implementation', 'interactive', 'trees', '*2400'] |
E. Ehab and the Expected GCD Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a function f(p) on a permutation p as follows. Let g_i be the greatest common divisor (GCD) of elements p_1, p_2, ..., p_i (in other words, it is the GCD of the prefix o... | 2
| 1 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'math', 'number theory', '*2500'] |
D. Ehab and the Expected XOR Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven two integers n and x, construct an array that satisfies the following conditions: for any element a_i in the array, 1 \le a_i<2^n; there is no non-empty subsegment with bitwi... | 3 5
| 3 6 1 3 | 1 second | 256 megabytes | ['bitmasks', 'constructive algorithms', '*1900'] |
C. Ehab and a Special Coloring Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an integer n. For every integer i from 2 to n, assign a positive integer a_i such that the following conditions hold: For any pair of integers (i,j), if i and j are co... | 4
| 1 2 1 | 1 second | 256 megabytes | ['constructive algorithms', 'number theory', '*1300'] |
B. Ehab Is an Odd Persontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an array a of length n. You can perform the following operation on it as many times as you want: Pick two integers i and j (1 \le i,j \le n) such that a_i+a_j is odd, then swap a_i ... | 3
4 1 7
| 1 4 7 | 1 second | 256 megabytes | ['sortings', '*1200'] |
A. Ehab Fails to Be Thanostime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're given an array a of length 2n. Is it possible to reorder it in such way so that the sum of the first n elements isn't equal to the sum of the last n elements?InputThe first line contains... | 3
1 2 2 1 3 1
| 2 1 3 1 1 2 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'sortings', '*1000'] |
B. Nauuo and Chesstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves playing chess.One day she invented a game by herself which needs n chess pieces to play on a m\times m chessboard. The rows and columns are numbered from 1 to m. We denote a c... | 2
| 2 1 1 1 2 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', '*1100'] |
A. Nauuo and Votestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves writing comments.One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.It's known that there were x persons who would upvote, y per... | 3 7 0
| - | 1 second | 256 megabytes | ['greedy', '*800'] |
F. Nauuo and Bugtime limit per test4 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves coding.One day she was solving a problem which requires to calculate a sum of some numbers modulo p.She wrote the following code and got the verdict "Wrong answer".She soon di... | 4 5 6
7 2 -3 17
2 3
1 3
1 2
2 4
4 4
| -1 0 3 10 11 | 4 seconds | 1024 megabytes | ['data structures', '*3300'] |
E. Nauuo and ODTtime limit per test7.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves traveling.One day she went to a tree, Old Driver Tree, literally, a tree with an old driver on it.The tree is a connected graph consisting of n nodes and n-1 edges. Each node... | 5 3
1 2 1 2 3
1 2
1 3
3 4
3 5
3 3
4 1
4 3
| 47 51 49 45 | 7.5 seconds | 512 megabytes | ['data structures', '*3300'] |
D. Nauuo and Portalstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves playing games related to portals.One day she was playing a game as follows.In an n\times n grid, the rows are numbered from 1 to n from top to bottom, the columns are numbe... | 3
1 3 2
3 1 2
| 2 1 1 1 3 2 2 3 1 | 2 seconds | 256 megabytes | ['constructive algorithms', '*2900'] |
C2. Nauuo and Pictures (hard version)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includ... | 2 1
0 1
2 1
| 332748119 332748119 | 4 seconds | 256 megabytes | ['dp', 'probabilities', '*2600'] |
C1. Nauuo and Pictures (easy version)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Nauuo is a girl who loves random picture websites.One day she made a random picture website by herself which includ... | 2 1
0 1
2 1
| 332748119 332748119 | 4 seconds | 256 megabytes | ['dp', 'probabilities', '*2300'] |
B. Nauuo and Circletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves drawing circles.One day she has drawn a circle and wanted to draw a tree on it.The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are nu... | 4
1 2
1 3
2 4
| 16 | 2 seconds | 256 megabytes | ['combinatorics', 'dfs and similar', 'dp', 'trees', '*1900'] |
A. Nauuo and Cardstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNauuo is a girl who loves playing cards.One day she was playing cards but found that the cards were mixed with some empty ones.There are n cards numbered from 1 to n, and they were mixed with anothe... | 3
0 2 0
3 0 1
| 2 | 1.5 seconds | 256 megabytes | ['greedy', 'implementation', '*1800'] |
I. Good Subsetstime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n segments on the Ox axis. The i-th segment is given as a pair l_i, r_i, where l_i is the position of the left end of the i-th segment and r_i is the position of the right end of the i-th s... | 3
1 1
2 6
1 6
| 4 | 6 seconds | 256 megabytes | ['*special problem', 'dp'] |
H. Longest Sawtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the sequence a_1, a_2, \dots, a_n. You can choose any subset of elements and then reorder them to create a "saw".The sequence b_1, b_2, \dots, b_m is called a "saw" if the elements satisfy o... | 3
10
10 9 8 7 6 5 4 3 2 1
7
1 2 2 2 3 2 2
3
100 100 100
| 10 1 6 2 7 3 8 4 9 5 10 4 2 1 3 2 1 100 | 3 seconds | 256 megabytes | ['*special problem', 'constructive algorithms'] |
G. Graph Decompositiontime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected graph consisting of n vertices and m edges.Recall that a cycle is a path that starts and ends in the same vertex. A cycle in a graph is called simple if it contains eac... | 6 9
1 2
2 3
1 3
2 4
2 5
4 5
3 5
3 6
5 6
| YES 3 4 2 5 4 2 4 3 6 5 3 4 1 3 2 1 | 6 seconds | 256 megabytes | ['*special problem', 'graphs'] |
F. Wheelstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has n wheels and a car with m slots for wheels. The initial pressure in the i-th wheel is a_i.Polycarp's goal is to take exactly m wheels among the given n wheels and equalize the pressure in them (th... | 6 6 7
6 15 16 20 1 5
| 39 | 3 seconds | 256 megabytes | ['*special problem', 'binary search', 'greedy'] |
E. Sliding Doorstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImagine that you are the CEO of a big old-fashioned company. Unlike any modern and progressive company (such as JetBrains), your company has a dress code. That's why you have already allocated a spaciou... | 3 10
2 3 2
6
1 5
2 1 10
2 2 9
2 5 6
3 1 7 8
4 1 2 3 4
| YES YES NO NO YES NO | 3 seconds | 256 megabytes | ['*special problem', 'binary search'] |
D. Decoding of Integer Sequencestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is developing a method for transmitting n integer sequences over a network. This method should support the transmission of an arbitrary number of integer sequences; sequences ca... | 12
3 2 1 1 7 2 4 -1 3 -1 4 -1
| 3 3 3 1 4 2 2 7 4 1 2 3 4 | 3 seconds | 256 megabytes | ['*special problem', 'data structures', 'implementation'] |
C. Minus and Minus Give Plustime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone knows that two consecutive (adjacent) "minus" signs can be replaced with a single "plus" sign.You are given the string s, consisting of "plus" and "minus" signs only. Zero or more o... | 5
-+--+
-+++
--------
-+--+-
-
+
--
---
+++
+++
| YES YES NO NO YES | 3 seconds | 256 megabytes | ['*special problem', 'implementation', 'strings'] |
B. Bad Daystime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery day Kotlin heroes analyze the statistics of their website. For n days, they wrote out n numbers a_1, a_2, \dots, a_n, where a_i is the number of visits on the i-th day.They believe that a day is bad if... | 8
3 1 4 1 5 9 2 6
| 2 | 3 seconds | 256 megabytes | ['*special problem', 'implementation'] |
A. Three Integers Againtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe have three positive integers a, b and c. You don't know their values, but you know some information about them. Consider all three pairwise sums, i.e. the numbers a+b, a+c and b+c. You know exa... | 3
123 13
2 2
2000000000 2000000000
| 111 1 12 1 1 1 1999999999 1 1 | 1 second | 256 megabytes | ['*special problem', 'math'] |
B. Pairstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Ivan has m pairs of integers, each integer is between 1 and n, inclusive. The pairs are (a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m). He asks you to check if there exist two integers x and y (1 \leq x < y \l... | 4 6
1 2
1 3
1 4
2 3
2 4
3 4
| NO | 2 seconds | 256 megabytes | ['graphs', 'implementation', '*1500'] |
A. Circle Metrotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe circle line of the Roflanpolis subway has n stations.There are two parallel routes in the subway. The first one visits stations in order 1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots (so the next st... | 5 1 4 3 2
| YES | 1 second | 256 megabytes | ['implementation', 'math', '*900'] |
E. Xor Permutationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Mikhail has an array of 2^k integers a_1, a_2, \ldots, a_{2^k}.Find two permutations p and q of integers 0, 1, \ldots, 2^k-1, such that a_i is equal to p_i \oplus q_i for all possible i, or deter... | 2
0 1 2 3
| Shi 2 0 1 3 2 1 3 0 | 1 second | 256 megabytes | ['constructive algorithms', 'math', '*3100'] |
D. Anagram Pathstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Ilya has a rooted binary tree with vertex 1 being the root. A tree is a connected graph without cycles. A tree is rooted if one vertex is selected and called the root. A vertex u is a child of a ve... | 3 4
1 ?
1 ?
2 ?
2 a
3 b
2 b
| Shi 351 Shi 1 Fou Shi 2 | 4 seconds | 256 megabytes | ['dp', 'implementation', 'trees', '*3000'] |
C. And Reachabilitytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Pimple has an array of integers a_1, a_2, \ldots, a_n.We say that y is reachable from x if x<y and there exists an integer array p such that x = p_1 < p_2 < \ldots < p_k=y, and a_{p_i}\, \&\, a_... | 5 3
1 3 0 2 1
1 3
2 4
1 4
| Fou Shi Shi | 3 seconds | 256 megabytes | ['bitmasks', 'dp', '*2200'] |
B. Good Tripletime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Rash has a binary string s. A binary string consists only of zeros and ones.Let n be the length of s.Rash needs to find the number of such pairs of integers l, r that 1 \leq l \leq r \leq n and there... | 010101
| 3 | 4 seconds | 256 megabytes | ['brute force', 'two pointers', '*1900'] |
A. Increasing by Modulotime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToad Zitz has an array of integers, each integer is between 0 and m-1 inclusive. The integers are a_1, a_2, \ldots, a_n.In one operation Zitz can choose an integer k and k indices i_1, i_2, \ld... | 5 3
0 0 0 1 2
| 0 | 2.5 seconds | 256 megabytes | ['binary search', 'greedy', '*1700'] |
G. Low Budget Inceptiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSo we got bored and decided to take our own guess at how would "Inception" production go if the budget for the film had been terribly low.The first scene we remembered was the one that features t... | 3 5
0 5 7
9
0 1 2 3 4 5 6 7 8
| 1.570796326794897 1.570796326794897 0.785398163397448 0.927295218001612 0.785398163397448 1.570796326794897 1.570796326794897 1.570796326794897 1.570796326794897 | 3 seconds | 256 megabytes | ['brute force', 'geometry', '*3100'] |
F. Scalar Queriestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n. All a_i are pairwise distinct.Let's define function f(l, r) as follows: let's define array b_1, b_2, \dots, b_{r - l + 1}, where b_i = a_{l - 1 + i}; sor... | 4
5 2 4 7
| 167 | 2 seconds | 256 megabytes | ['combinatorics', 'data structures', 'math', 'sortings', '*2300'] |
E. Range Deletingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array consisting of n integers a_1, a_2, \dots , a_n and an integer x. It is guaranteed that for every i, 1 \le a_i \le x.Let's denote a function f(l, r) which erases all values such t... | 3 3
2 3 1
| 4 | 2 seconds | 256 megabytes | ['binary search', 'combinatorics', 'data structures', 'two pointers', '*2100'] |
D. Bicolored RBStime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expre... | 2
()
| 11 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', '*1500'] |
C. News Distributiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn some social network, there are n users communicating with each other in m groups of friends. Let's analyze the process of distributing some news between users.Initially, some user x receives the ... | 7 5
3 2 5 4
0
2 1 2
1 1
2 6 7
| 4 4 1 4 4 2 2 | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', '*1400'] |
B. Lost Numberstime 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... | 16
64
345
672 | ? 1 1 ? 2 2 ? 3 5 ? 4 6 ! 4 8 15 16 23 42 | 1 second | 256 megabytes | ['brute force', 'divide and conquer', 'interactive', 'math', '*1400'] |
A. Telephone Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not... | 2
13
7818005553535
11
31415926535
| YES NO | 1 second | 256 megabytes | ['brute force', 'greedy', 'strings', '*800'] |
F. Vicky's Delivery Servicetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a magical land there are n cities conveniently numbered 1, 2, \dots, n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may ... | 4 3 2 4
1 2 1
2 3 1
3 4 2
? 1 4
? 4 1
+ 3 1 2
? 4 1
| Yes No Yes | 4 seconds | 256 megabytes | ['data structures', 'dsu', 'graphs', 'hashing', '*2400'] |
E. The LCMs Must be Largetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?There are n stores numbered from 1 to n in Nlogonia.... | 2 5
3 1 2 3
3 3 4 5
| possible | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'constructive algorithms', 'math', 'number theory', '*2100'] |
D. Cute Sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a positive integer m, we say that a sequence x_1, x_2, \dots, x_n of positive integers is m-cute if for every index i such that 2 \le i \le n it holds that x_i = x_{i - 1} + x_{i - 2} + \dots + x_... | 2
5 26 2
3 9 1
| 4 5 6 13 26 -1 | 1 second | 256 megabytes | ['binary search', 'brute force', 'greedy', 'math', '*2200'] |
C. A Tale of Two Landstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points |x| and |y| on the number line and conquered all the land in bet... | 3
2 5 -3
| 2 | 1 second | 256 megabytes | ['binary search', 'sortings', 'two pointers', '*1500'] |
B. All the Vowels Pleasetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k is vowelly if there are positive integers n and m such that n\cdot m = ... | 7
| -1 | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'number theory', '*1100'] |
A. Silent Classroomtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct st... | 4
jorge
jose
oscar
jerry
| 1 | 1 second | 256 megabytes | ['combinatorics', 'greedy', '*900'] |
F2. Microtransactions (hard version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his... | 5 6
1 2 0 2 0
2 4
3 3
1 5
1 2
1 5
2 3
| 8 | 3 seconds | 256 megabytes | ['binary search', 'greedy', 'implementation', '*2000'] |
F1. Microtransactions (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his... | 5 6
1 2 0 2 0
2 4
3 3
1 5
1 2
1 5
2 3
| 8 | 2 seconds | 256 megabytes | ['binary search', 'greedy', '*2000'] |
E. Two Arrays and Sum of Functionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b, both of length n.Let's define a function f(l, r) = \sum\limits_{l \le i \le r} a_i \cdot b_i.Your task is to reorder the elements (choose an arbitrary... | 5
1 8 7 2 4
9 7 2 9 3
| 646 | 2 seconds | 256 megabytes | ['greedy', 'math', 'sortings', '*1600'] |
D. Almost All Divisorstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe guessed some integer number x. You are given a list of almost all its divisors. Almost all means that there are all divisors except 1 and x in the list.Your task is to find the minimum possible... | 2
8
8 2 12 6 4 24 16 3
1
2
| 48 4 | 2 seconds | 256 megabytes | ['math', 'number theory', '*1600'] |
C. Good Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the th... | 4
good
| 0 good | 1 second | 256 megabytes | ['greedy', '*1300'] |
B. Polycarp Trainingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third d... | 4
3 1 4 1
| 3 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'sortings', '*1000'] |
A. Remaindertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.You may perform several (possibly zero) operatio... | 11 5 2
11010100101
| 1 | 1 second | 256 megabytes | ['implementation', 'math', '*1100'] |
F. Indecisive Taxi Feetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn the city of Capypaland where Kuro and Shiro resides, there are n towns numbered from 1 to n and there are m bidirectional roads numbered from 1 to m connecting them. The i-th road connects town... | 4 5 6
1 2 2
2 4 3
1 4 7
1 3 1
3 4 5
3 4
5 1
3 8
1 4
2 1
3 1
| 4 2 5 6 3 1 | 2 seconds | 512 megabytes | ['data structures', 'graphs', 'shortest paths', '*3000'] |
E. Magical Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKuro has just learned about permutations and he is really excited to create a new permutation type. He has chosen n distinct positive integers and put all of them in a set S. Now he defines a magic... | 3
1 2 3
| 2 0 1 3 2 | 1 second | 256 megabytes | ['bitmasks', 'brute force', 'constructive algorithms', 'data structures', 'graphs', 'math', '*2400'] |
D. Mysterious Codetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDuring a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string c consisting of l... | *****
katie
shiro
| 1 | 2 seconds | 256 megabytes | ['dp', 'strings', '*2100'] |
C2. Power Transmission (Hard Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the previous one, but has larger constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby powe... | 4
0 0
1 1
0 3
1 2
| 14 | 3 seconds | 256 megabytes | ['data structures', 'geometry', 'implementation', 'math', '*1900'] |
C1. Power Transmission (Easy Edition)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the next one, but has smaller constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power s... | 4
0 0
1 1
0 3
1 2
| 14 | 3 seconds | 256 megabytes | ['brute force', 'geometry', '*1900'] |
B2. Cat Party (Hard Edition)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the previous one, but has larger constraints.Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. Howeve... | 13
1 1 1 2 2 2 3 3 3 4 4 4 5
| 13 | 1 second | 256 megabytes | ['data structures', 'implementation', '*1600'] |
B1. Cat Party (Easy Edition)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is same as the next one, but has smaller constraints.Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, ... | 13
1 1 1 2 2 2 3 3 3 4 4 4 5
| 13 | 1 second | 256 megabytes | ['data structures', 'implementation', '*1500'] |
A. Eating Souptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited ... | 7 4
| 3 | 1 second | 256 megabytes | ['greedy', 'math', '*900'] |
B. Double Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two n \times m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers ... | 2 2
2 10
11 5
9 4
3 12
| Possible | 1 second | 256 megabytes | ['brute force', 'greedy', '*1400'] |
A. Zoning Restrictions Againtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, yo... | 3 3 3
1 1 1
2 2 3
3 3 2
| 14 | 1 second | 256 megabytes | ['implementation', '*800'] |
A2. Collaborationtime limit per test15 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputConsider several locations in integer points on the plane. One of the locations is the base where workers wait. Every other location contains one job.Each job has the following characteristics: work d... | Input45 15 0 0 0 02 13 30 2 200 4003 12 29 1 350 60039 21 9 4 671 757 | Outputstart 335 1arrive 340 2work 340 370 2arrive 372 3work 372 401 3arrive 406 1endstart 335 1arrive 340 2work 340 370 2arrive 375 1end | 15 seconds | 768 megabytes | ['*special problem'] |
B. Expansion coefficient of the arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call an array of non-negative integers a_1, a_2, \ldots, a_n a k-extension for some non-negative integer k if for all possible pairs of indices 1 \leq i, j \leq n the inequalit... | 4
6 4 5 5
| 1 | 1 second | 256 megabytes | ['implementation', 'math', '*1300'] |
A. A pile of stonestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one ston... | 3
---
| 0 | 1 second | 256 megabytes | ['implementation', 'math', '*800'] |
F. Density of subarraystime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet c be some positive integer. Let's call an array a_1, a_2, \ldots, a_n of positive integers c-array, if for all i condition 1 \leq a_i \leq c is satisfied. Let's call c-array b_1, b_2, \ldots,... | 4 1
1 1 1 1
| 0 4 6 4 1 | 6 seconds | 256 megabytes | ['dp', 'math', '*3500'] |
E. Strange devicetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is an interactive problem.Vasya enjoys solving quizzes. He found a strange device and wants to know how it works.This device encrypted with the tree (connected undirected graph without cycles) with n... | 5
00000
11011
11100
10010
| ? 0 0 0 0 0 ? 1 1 2 0 2 ? 0 0 0 1 0 ? 0 1 0 0 1 ! 4 2 1 5 3 4 4 1 | 1 second | 256 megabytes | ['binary search', 'interactive', 'math', 'trees', '*3400'] |
D. Winding polygonal linetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has n different points A_1, A_2, \ldots A_n on the plane. No three of them lie on the same line He wants to place them in some order A_{p_1}, A_{p_2}, \ldots, A_{p_n}, where p_1, p_2, \ldo... | 3
1 1
3 1
1 3
L
| 1 2 3 | 1 second | 256 megabytes | ['constructive algorithms', 'geometry', 'greedy', 'math', '*2600'] |
C. Permutation recoverytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has written some permutation p_1, p_2, \ldots, p_n of integers from 1 to n, so for all 1 \leq i \leq n it is true that 1 \leq p_i \leq n and all p_1, p_2, \ldots, p_n are different. After th... | 6
3
2 3 4
2
3 3
3
-1 -1 -1
3
3 4 -1
1
2
4
4 -1 4 5
| 1 2 3 2 1 2 1 3 -1 1 3 2 1 4 | 1 second | 256 megabytes | ['constructive algorithms', 'data structures', 'dfs and similar', 'graphs', 'greedy', 'math', 'sortings', '*2100'] |
B. The minimal unique substringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 \leq l \leq |s| - |t| + 1 that t = s_l s_{l+1} \ldots s_... | 4 4
| 1111 | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'strings', '*2200'] |
A. The Party and Sweetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputn boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with in... | 3 2
1 2 1
3 4
| 12 | 1 second | 256 megabytes | ['binary search', 'constructive algorithms', 'greedy', 'implementation', 'math', 'sortings', 'two pointers', '*1500'] |
G. Inverse of Rows and Columnstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a binary matrix a of size n \times m. A binary matrix is a matrix where each element is either 0 or 1.You may perform some (possibly zero) operations with this matrix. During... | 2 2
1 1
0 1
| YES 00 10 | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', '*2200'] |
F. Maximum Balanced Circletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n people in a row. The height of the i-th person is a_i. You can choose any subset of these people and try to arrange them into a balanced circle.A balanced circle is such an order o... | 7
4 3 5 1 2 2 1
| 5 2 1 1 2 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dp', 'greedy', 'two pointers', '*2000'] |
E. Minimum Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b, both of length n. All elements of both arrays are from 0 to n-1.You can reorder elements of the array b (if you want, you may leave the order of elements as it is). Aft... | 4
0 1 2 1
3 2 1 1
| 1 0 0 2 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'greedy', '*1700'] |
D. N Problems During K Daystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will star... | 26 6
| YES 1 2 4 5 6 8 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1900'] |
C2. Increasing Subsequence (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).You are given a sequence a con... | 5
1 2 4 3 2
| 4 LRRR | 2 seconds | 256 megabytes | ['greedy', '*1700'] |
C1. Increasing Subsequence (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).You are given a sequence a con... | 5
2 1 5 4 3
| 4 LRRR | 2 seconds | 256 megabytes | ['greedy', '*1300'] |
B. Long Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9.You can perform the fol... | 4
1337
1 2 5 4 6 6 3 1 9
| 1557 | 2 seconds | 256 megabytes | ['greedy', '*1300'] |
A. Reachable Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, f(599) = 6: 599 + 1 = 600 \righ... | 1098
| 20 | 1 second | 256 megabytes | ['implementation', '*1100'] |
G. Optimizertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's analyze a program written on some strange programming language. The variables in this language have names consisting of 1 to 4 characters, and each character is a lowercase or an uppercase Latin letter... | 4
c=aa#bb
d12=c
res=c^d12
tmp=aa$c
| 2 aaaa=aa#bb res=aaaa^aaaa | 1 second | 256 megabytes | ['graphs', 'greedy', 'hashing', 'implementation', '*2700'] |
F. Card Bagtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou have a bag which contains n cards. There is a number written on each card; the number on i-th card is a_i.You are playing the following game. During each turn, you choose and remove a random card from th... | 5
1 1 4 2 3
| 299473306 | 2 seconds | 512 megabytes | ['dp', 'math', 'probabilities', '*2300'] |
E. Special Segments of Permutationtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a permutation p of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once).Let's call some subsegment p[l, r] of this permu... | 5
3 4 1 5 2
| 2 | 2 seconds | 512 megabytes | ['data structures', 'divide and conquer', 'dsu', 'two pointers', '*2200'] |
D. 0-1-Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (an undirected connected acyclic graph) consisting of n vertices and n - 1 edges. A number is written on each edge, each number is either 0 (let's call such edges 0-edges) or 1 (those ar... | 7
2 1 1
3 2 0
4 2 1
5 2 0
6 7 1
7 2 1
| 34 | 2 seconds | 256 megabytes | ['dfs and similar', 'divide and conquer', 'dp', 'dsu', 'trees', '*2200'] |
C. Match Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a set of points x_1, x_2, ..., x_n on the number line.Two points i and j can be matched with each other if the following conditions hold: neither i nor j is matched with any other point; ... | 4 2
1 3 3 7
| 2 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'sortings', 'ternary search', 'two pointers', '*2000'] |
B. Ugly Pairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string, consisting of lowercase Latin letters.A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" ... | 4
abcd
gg
codeforces
abaca
| cadb gg codfoerces No answer | 1 second | 256 megabytes | ['dfs and similar', 'greedy', 'implementation', 'sortings', 'strings', '*1800'] |
A. Inscribed Figurestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the ... | 3
2 1 3
| Finite 7 | 1 second | 256 megabytes | ['geometry', '*1400'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.