Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- code_contests-0003/instruction.md +66 -0
- code_contests-0021/instruction.md +60 -0
- code_contests-0026/instruction.md +93 -0
- code_contests-0032/instruction.md +60 -0
- code_contests-0043/instruction.md +49 -0
- code_contests-0044/instruction.md +44 -0
- code_contests-0050/instruction.md +59 -0
- code_contests-0057/instruction.md +74 -0
- code_contests-0059/instruction.md +81 -0
- code_contests-0061/instruction.md +81 -0
- code_contests-0066/instruction.md +85 -0
- code_contests-0068/instruction.md +39 -0
- code_contests-0069/instruction.md +53 -0
- code_contests-0072/instruction.md +45 -0
- code_contests-0075/instruction.md +73 -0
- code_contests-0081/instruction.md +83 -0
- code_contests-0086/instruction.md +69 -0
- code_contests-0088/instruction.md +103 -0
- code_contests-0200/instruction.md +76 -0
- code_contests-0207/instruction.md +61 -0
- code_contests-0209/instruction.md +70 -0
- code_contests-0213/instruction.md +36 -0
- code_contests-0238/instruction.md +61 -0
- code_contests-0253/instruction.md +77 -0
- code_contests-0262/instruction.md +57 -0
- code_contests-0276/instruction.md +51 -0
- code_contests-0278/instruction.md +47 -0
- code_contests-0298/instruction.md +96 -0
- code_contests-0405/instruction.md +64 -0
- code_contests-0418/instruction.md +54 -0
- code_contests-0429/instruction.md +70 -0
- code_contests-0433/instruction.md +88 -0
- code_contests-0434/instruction.md +63 -0
- code_contests-0442/instruction.md +99 -0
- code_contests-0445/instruction.md +85 -0
- code_contests-0451/instruction.md +50 -0
- code_contests-0460/instruction.md +60 -0
- code_contests-0467/instruction.md +59 -0
- code_contests-0469/instruction.md +72 -0
- code_contests-0493/instruction.md +64 -0
- code_contests-0494/instruction.md +77 -0
- code_contests-0601/instruction.md +107 -0
- code_contests-0606/instruction.md +66 -0
- code_contests-0608/instruction.md +71 -0
- code_contests-0612/instruction.md +75 -0
- code_contests-0624/instruction.md +42 -0
- code_contests-0630/instruction.md +106 -0
- code_contests-0637/instruction.md +87 -0
- code_contests-0639/instruction.md +73 -0
- code_contests-0648/instruction.md +81 -0
code_contests-0003/instruction.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# luckybal
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.
|
| 5 |
+
The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the number of digits 7 in the substring T[X, M]. For example, the string S = 7477447 is balanced since S[1, 4] = 7477 has 1 digit 4 and S[5, 7] = 447 has 1 digit 7. On the other hand, one can verify that the string S = 7 is not balanced.
|
| 6 |
+
The Little Elephant has the string S of the length N. He wants to know the number of such pairs of integers (L; R) that 1 ≤ L ≤ R ≤ N and the substring S[L, R] is balanced. Help him to find this number.
|
| 7 |
+
Notes.
|
| 8 |
+
|
| 9 |
+
Let S be some lucky string. Then
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|S| denotes the length of the string S;
|
| 13 |
+
|
| 14 |
+
S[i] (1 ≤ i ≤ |S|) denotes the i^th character of S (the numeration of characters starts from 1);
|
| 15 |
+
|
| 16 |
+
S[L, R] (1 ≤ L ≤ R ≤ |S|) denotes the string with the following sequence of characters: S[L], S[L + 1], ..., S[R], and is called a substring of S. For L > R we mean by S[L, R] an empty string.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
The first line of the input file contains a single integer T, the number of test cases. Each of the following T lines contains one string, the string S for the corresponding test case. The input file does not contain any whitespaces.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
For each test case output a single line containing the answer for this test case.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Constraints
|
| 28 |
+
1 ≤ T ≤ 10
|
| 29 |
+
1 ≤ |S| ≤ 100000
|
| 30 |
+
S consists only of the lucky digits 4 and 7.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Example
|
| 35 |
+
|
| 36 |
+
Input:
|
| 37 |
+
4
|
| 38 |
+
47
|
| 39 |
+
74
|
| 40 |
+
477
|
| 41 |
+
4747477
|
| 42 |
+
|
| 43 |
+
Output:
|
| 44 |
+
2
|
| 45 |
+
2
|
| 46 |
+
3
|
| 47 |
+
23
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Explanation
|
| 52 |
+
In the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47.
|
| 53 |
+
In the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74.
|
| 54 |
+
Unfortunately, we can't provide you with the explanations of the third and the fourth test cases. You should figure it out by yourself. Please, don't ask about this in comments.
|
| 55 |
+
|
| 56 |
+
## Contest Information
|
| 57 |
+
- **Contest ID**: 0
|
| 58 |
+
- **Problem Index**:
|
| 59 |
+
- **Points**: 0.0
|
| 60 |
+
- **Rating**: 0
|
| 61 |
+
- **Tags**: None
|
| 62 |
+
- **Time Limit**: None seconds
|
| 63 |
+
- **Memory Limit**: 0 bytes
|
| 64 |
+
|
| 65 |
+
## Task
|
| 66 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0021/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1334_D. Minimum Euler Cycle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
|
| 5 |
+
|
| 6 |
+
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
|
| 7 |
+
|
| 8 |
+
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 — a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
|
| 9 |
+
|
| 10 |
+
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
|
| 11 |
+
|
| 12 |
+
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains the single integer T (1 ≤ T ≤ 100) — the number of test cases.
|
| 17 |
+
|
| 18 |
+
Next T lines contain test cases — one per line. The first and only line of each test case contains three integers n, l and r (2 ≤ n ≤ 10^5, 1 ≤ l ≤ r ≤ n(n - 1) + 1, r - l + 1 ≤ 10^5) — the number of vertices in K_n, and segment of the cycle to print.
|
| 19 |
+
|
| 20 |
+
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
|
| 25 |
+
|
| 26 |
+
Example
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
2 1 3
|
| 33 |
+
3 3 6
|
| 34 |
+
99995 9998900031 9998900031
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
1 2 1
|
| 41 |
+
1 3 2 3
|
| 42 |
+
1
|
| 43 |
+
|
| 44 |
+
Note
|
| 45 |
+
|
| 46 |
+
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
|
| 47 |
+
|
| 48 |
+
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 1334
|
| 52 |
+
- **Problem Index**: D
|
| 53 |
+
- **Points**: 0.0
|
| 54 |
+
- **Rating**: 1800
|
| 55 |
+
- **Tags**: constructive algorithms, graphs, greedy, implementation
|
| 56 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0026/instruction.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 143_A. Help Vasilisa the Wise 2
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
|
| 5 |
+
|
| 6 |
+
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
|
| 11 |
+
|
| 12 |
+
<image>
|
| 13 |
+
|
| 14 |
+
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
|
| 19 |
+
|
| 20 |
+
<image>
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
|
| 25 |
+
|
| 26 |
+
If there are several solutions, output any.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
3 7
|
| 33 |
+
4 6
|
| 34 |
+
5 5
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
1 2
|
| 40 |
+
3 4
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
11 10
|
| 46 |
+
13 8
|
| 47 |
+
5 16
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
4 7
|
| 53 |
+
9 1
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
1 2
|
| 59 |
+
3 4
|
| 60 |
+
5 6
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
-1
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Input
|
| 69 |
+
|
| 70 |
+
10 10
|
| 71 |
+
10 10
|
| 72 |
+
10 10
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
-1
|
| 78 |
+
|
| 79 |
+
Note
|
| 80 |
+
|
| 81 |
+
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
|
| 82 |
+
|
| 83 |
+
## Contest Information
|
| 84 |
+
- **Contest ID**: 143
|
| 85 |
+
- **Problem Index**: A
|
| 86 |
+
- **Points**: 500.0
|
| 87 |
+
- **Rating**: 1000
|
| 88 |
+
- **Tags**: brute force, math
|
| 89 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 90 |
+
- **Memory Limit**: 256000000 bytes
|
| 91 |
+
|
| 92 |
+
## Task
|
| 93 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0032/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 188_G. Array Sorting
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Sorting arrays is traditionally associated with high-level languages. How hard can it be in Roco? Sort the given array in non-descending order.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first line of input contains an integer n (1 ≤ n ≤ 100) — the size of the array. The following n lines contain the elements of the array, one per line. Each element of the array is an integer between 1 and 100, inclusive. The array might contain duplicate elements.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output space-separated elements of the sorted array.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
5
|
| 19 |
+
7
|
| 20 |
+
1
|
| 21 |
+
9
|
| 22 |
+
7
|
| 23 |
+
3
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
1 3 7 7 9
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
10
|
| 34 |
+
100
|
| 35 |
+
1
|
| 36 |
+
100
|
| 37 |
+
1
|
| 38 |
+
100
|
| 39 |
+
1
|
| 40 |
+
100
|
| 41 |
+
1
|
| 42 |
+
100
|
| 43 |
+
1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
1 1 1 1 1 100 100 100 100 100
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 188
|
| 52 |
+
- **Problem Index**: G
|
| 53 |
+
- **Points**: 0.0
|
| 54 |
+
- **Rating**: 1600
|
| 55 |
+
- **Tags**: *special, implementation
|
| 56 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0043/instruction.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 44_B. Cola
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
|
| 5 |
+
|
| 6 |
+
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
|
| 7 |
+
|
| 8 |
+
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
10 5 5 5
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
9
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
3 0 0 2
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
0
|
| 38 |
+
|
| 39 |
+
## Contest Information
|
| 40 |
+
- **Contest ID**: 44
|
| 41 |
+
- **Problem Index**: B
|
| 42 |
+
- **Points**: 0.0
|
| 43 |
+
- **Rating**: 1500
|
| 44 |
+
- **Tags**: implementation
|
| 45 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 46 |
+
- **Memory Limit**: 256000000 bytes
|
| 47 |
+
|
| 48 |
+
## Task
|
| 49 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0044/instruction.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 470_F. Pairwise Sums
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an array of n integers. For each element output the sum of itself and the previous element. For the first element, output the sum of the first and the last elements of the array.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The input consists of a single line of space-separated integers. The first number is n (2 ≤ n ≤ 50) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 1000).
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output the sums a1 + an, a2 + a1, ..., an + an - 1, separated with spaces.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
4 1 2 3 4
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
5 3 5 7
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
5 5 46 372 81 9
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
14 51 418 453 90
|
| 33 |
+
|
| 34 |
+
## Contest Information
|
| 35 |
+
- **Contest ID**: 470
|
| 36 |
+
- **Problem Index**: F
|
| 37 |
+
- **Points**: 0.0
|
| 38 |
+
- **Rating**: 2300
|
| 39 |
+
- **Tags**: *special
|
| 40 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 41 |
+
- **Memory Limit**: 256000000 bytes
|
| 42 |
+
|
| 43 |
+
## Task
|
| 44 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0050/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 615_A. Bulbs
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
|
| 5 |
+
|
| 6 |
+
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.
|
| 11 |
+
|
| 12 |
+
Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 ≤ yij ≤ m) — the numbers of these bulbs.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
If it's possible to turn on all m bulbs print "YES", otherwise print "NO".
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
3 4
|
| 23 |
+
2 1 4
|
| 24 |
+
3 1 3 1
|
| 25 |
+
1 2
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
YES
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
3 3
|
| 36 |
+
1 1
|
| 37 |
+
1 2
|
| 38 |
+
1 1
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
NO
|
| 44 |
+
|
| 45 |
+
Note
|
| 46 |
+
|
| 47 |
+
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 615
|
| 51 |
+
- **Problem Index**: A
|
| 52 |
+
- **Points**: 500.0
|
| 53 |
+
- **Rating**: 800
|
| 54 |
+
- **Tags**: implementation
|
| 55 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 56 |
+
- **Memory Limit**: 256000000 bytes
|
| 57 |
+
|
| 58 |
+
## Task
|
| 59 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0057/instruction.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 776_A. A Serial Killer
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
|
| 5 |
+
|
| 6 |
+
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
|
| 7 |
+
|
| 8 |
+
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days.
|
| 13 |
+
|
| 14 |
+
Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
|
| 15 |
+
|
| 16 |
+
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
ross rachel
|
| 27 |
+
4
|
| 28 |
+
ross joey
|
| 29 |
+
rachel phoebe
|
| 30 |
+
phoebe monica
|
| 31 |
+
monica chandler
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
ross rachel
|
| 37 |
+
joey rachel
|
| 38 |
+
joey phoebe
|
| 39 |
+
joey monica
|
| 40 |
+
joey chandler
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
icm codeforces
|
| 46 |
+
1
|
| 47 |
+
codeforces technex
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
icm codeforces
|
| 53 |
+
icm technex
|
| 54 |
+
|
| 55 |
+
Note
|
| 56 |
+
|
| 57 |
+
In first example, the killer starts with ross and rachel.
|
| 58 |
+
|
| 59 |
+
* After day 1, ross is killed and joey appears.
|
| 60 |
+
* After day 2, rachel is killed and phoebe appears.
|
| 61 |
+
* After day 3, phoebe is killed and monica appears.
|
| 62 |
+
* After day 4, monica is killed and chandler appears.
|
| 63 |
+
|
| 64 |
+
## Contest Information
|
| 65 |
+
- **Contest ID**: 776
|
| 66 |
+
- **Problem Index**: A
|
| 67 |
+
- **Points**: 500.0
|
| 68 |
+
- **Rating**: 900
|
| 69 |
+
- **Tags**: brute force, implementation, strings
|
| 70 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 71 |
+
- **Memory Limit**: 256000000 bytes
|
| 72 |
+
|
| 73 |
+
## Task
|
| 74 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0059/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 820_D. Mister B and PR Shifts
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Some time ago Mister B detected a strange signal from the space, which he started to study.
|
| 5 |
+
|
| 6 |
+
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation.
|
| 7 |
+
|
| 8 |
+
Let's define the deviation of a permutation p as <image>.
|
| 9 |
+
|
| 10 |
+
Find a cyclic shift of permutation p with minimum possible deviation. If there are multiple solutions, print any of them.
|
| 11 |
+
|
| 12 |
+
Let's denote id k (0 ≤ k < n) of a cyclic shift of permutation p as the number of right shifts needed to reach this shift, for example:
|
| 13 |
+
|
| 14 |
+
* k = 0: shift p1, p2, ... pn,
|
| 15 |
+
* k = 1: shift pn, p1, ... pn - 1,
|
| 16 |
+
* ...,
|
| 17 |
+
* k = n - 1: shift p2, p3, ... pn, p1.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
First line contains single integer n (2 ≤ n ≤ 106) — the length of the permutation.
|
| 22 |
+
|
| 23 |
+
The second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of the permutation. It is guaranteed that all elements are distinct.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Print two integers: the minimum deviation of cyclic shifts of permutation p and the id of such shift. If there are multiple solutions, print any of them.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
3
|
| 34 |
+
1 2 3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
0 0
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
3
|
| 45 |
+
2 3 1
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
0 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
3
|
| 56 |
+
3 2 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
2 1
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
In the first sample test the given permutation p is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
|
| 66 |
+
|
| 67 |
+
In the second sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift.
|
| 68 |
+
|
| 69 |
+
In the third sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts.
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 820
|
| 73 |
+
- **Problem Index**: D
|
| 74 |
+
- **Points**: 1000.0
|
| 75 |
+
- **Rating**: 1900
|
| 76 |
+
- **Tags**: data structures, implementation, math
|
| 77 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 78 |
+
- **Memory Limit**: 256000000 bytes
|
| 79 |
+
|
| 80 |
+
## Task
|
| 81 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0061/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 868_A. Bark to Unlock
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
|
| 5 |
+
|
| 6 |
+
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains two lowercase English letters — the password on the phone.
|
| 11 |
+
|
| 12 |
+
The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows.
|
| 13 |
+
|
| 14 |
+
The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
|
| 19 |
+
|
| 20 |
+
You can print each letter in arbitrary case (upper or lower).
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
ya
|
| 27 |
+
4
|
| 28 |
+
ah
|
| 29 |
+
oy
|
| 30 |
+
to
|
| 31 |
+
ha
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
YES
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
hp
|
| 42 |
+
2
|
| 43 |
+
ht
|
| 44 |
+
tp
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
NO
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
ah
|
| 55 |
+
1
|
| 56 |
+
ha
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
YES
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
|
| 66 |
+
|
| 67 |
+
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
|
| 68 |
+
|
| 69 |
+
In the third example the string "hahahaha" contains "ah" as a substring.
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 868
|
| 73 |
+
- **Problem Index**: A
|
| 74 |
+
- **Points**: 250.0
|
| 75 |
+
- **Rating**: 900
|
| 76 |
+
- **Tags**: brute force, implementation, strings
|
| 77 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 78 |
+
- **Memory Limit**: 256000000 bytes
|
| 79 |
+
|
| 80 |
+
## Task
|
| 81 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0066/instruction.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 990_E. Post Lamps
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there.
|
| 5 |
+
|
| 6 |
+
There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number.
|
| 7 |
+
|
| 8 |
+
The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each.
|
| 9 |
+
|
| 10 |
+
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]).
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 10^6, 0 ≤ m ≤ n) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
|
| 15 |
+
|
| 16 |
+
The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≤ s_1 < s_2 < ... s_m < n) — the blocked positions.
|
| 17 |
+
|
| 18 |
+
The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≤ a_i ≤ 10^6) — the costs of the post lamps.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street.
|
| 23 |
+
|
| 24 |
+
If illumintaing the entire segment [0; n] is impossible, print -1.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
6 2 3
|
| 31 |
+
1 3
|
| 32 |
+
1 2 3
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
6
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
4 3 4
|
| 43 |
+
1 2 3
|
| 44 |
+
1 10 100 1000
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
1000
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
5 1 5
|
| 55 |
+
0
|
| 56 |
+
3 3 3 3 3
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
-1
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Input
|
| 65 |
+
|
| 66 |
+
7 4 3
|
| 67 |
+
2 4 5 6
|
| 68 |
+
3 14 15
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Output
|
| 72 |
+
|
| 73 |
+
-1
|
| 74 |
+
|
| 75 |
+
## Contest Information
|
| 76 |
+
- **Contest ID**: 990
|
| 77 |
+
- **Problem Index**: E
|
| 78 |
+
- **Points**: 0.0
|
| 79 |
+
- **Rating**: 2100
|
| 80 |
+
- **Tags**: brute force, greedy
|
| 81 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 82 |
+
- **Memory Limit**: 256000000 bytes
|
| 83 |
+
|
| 84 |
+
## Task
|
| 85 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0068/instruction.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chandu-and-his-girlfriend-returns
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In the previous problem Chandu bought some unsorted arrays and sorted them (in non-increasing order). Now, he has many sorted arrays to give to his girlfriend. But, the number of sorted arrays are very large so Chandu decided to merge two sorted arrays into one sorted array. But he is too lazy to do that. So, he asked your help to merge the two sorted arrays into one sorted array (in non-increasing order).
|
| 5 |
+
|
| 6 |
+
Input:
|
| 7 |
+
First line contains an integer T, denoting the number of test cases.
|
| 8 |
+
First line of each test case contains two space separated integers N and M, denoting the size of the two sorted arrays.
|
| 9 |
+
Second line of each test case contains N space separated integers, denoting the first sorted array A.
|
| 10 |
+
Third line of each test case contains M space separated integers, denoting the second array B.
|
| 11 |
+
|
| 12 |
+
Output:
|
| 13 |
+
For each test case, print (N + M) space separated integer representing the merged array.
|
| 14 |
+
|
| 15 |
+
Constraints:
|
| 16 |
+
1 ≤ T ≤ 100
|
| 17 |
+
1 ≤ N, M ≤ 5*10^4
|
| 18 |
+
0 ≤ Ai, Bi ≤ 10^9
|
| 19 |
+
|
| 20 |
+
SAMPLE INPUT
|
| 21 |
+
1
|
| 22 |
+
4 5
|
| 23 |
+
9 7 5 3
|
| 24 |
+
8 6 4 2 0
|
| 25 |
+
|
| 26 |
+
SAMPLE OUTPUT
|
| 27 |
+
9 8 7 6 5 4 3 2 0
|
| 28 |
+
|
| 29 |
+
## Contest Information
|
| 30 |
+
- **Contest ID**: 0
|
| 31 |
+
- **Problem Index**:
|
| 32 |
+
- **Points**: 0.0
|
| 33 |
+
- **Rating**: 0
|
| 34 |
+
- **Tags**: None
|
| 35 |
+
- **Time Limit**: None seconds
|
| 36 |
+
- **Memory Limit**: 0 bytes
|
| 37 |
+
|
| 38 |
+
## Task
|
| 39 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0069/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# discover-the-monk
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an array A of size N, and Q queries to deal with. For each query, you are given an integer X, and you're supposed to find out if X is present in the array A or not.
|
| 5 |
+
|
| 6 |
+
Input:
|
| 7 |
+
The first line contains two integers, N and Q, denoting the size of array A and number of queries. The second line contains N space separated integers, denoting the array of elements Ai. The next Q lines contain a single integer X per line.
|
| 8 |
+
|
| 9 |
+
Output:
|
| 10 |
+
For each query, print YES if the X is in the array, otherwise print NO.
|
| 11 |
+
|
| 12 |
+
Constraints:
|
| 13 |
+
1 ≤ N, Q ≤ 10^5
|
| 14 |
+
1 ≤ Ai ≤ 10^9
|
| 15 |
+
1 ≤ X ≤ 10^9
|
| 16 |
+
|
| 17 |
+
SAMPLE INPUT
|
| 18 |
+
5 10
|
| 19 |
+
50 40 30 20 10
|
| 20 |
+
10
|
| 21 |
+
20
|
| 22 |
+
30
|
| 23 |
+
40
|
| 24 |
+
50
|
| 25 |
+
60
|
| 26 |
+
70
|
| 27 |
+
80
|
| 28 |
+
90
|
| 29 |
+
100
|
| 30 |
+
|
| 31 |
+
SAMPLE OUTPUT
|
| 32 |
+
YES
|
| 33 |
+
YES
|
| 34 |
+
YES
|
| 35 |
+
YES
|
| 36 |
+
YES
|
| 37 |
+
NO
|
| 38 |
+
NO
|
| 39 |
+
NO
|
| 40 |
+
NO
|
| 41 |
+
NO
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 0
|
| 45 |
+
- **Problem Index**:
|
| 46 |
+
- **Points**: 0.0
|
| 47 |
+
- **Rating**: 0
|
| 48 |
+
- **Tags**: None
|
| 49 |
+
- **Time Limit**: None seconds
|
| 50 |
+
- **Memory Limit**: 0 bytes
|
| 51 |
+
|
| 52 |
+
## Task
|
| 53 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0072/instruction.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# monks-choice-of-numbers-1
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Monk loves cakes! He visits the Binary Bakery to buy some of his favorite cheesecakes.
|
| 5 |
+
The owner of the bakery, Bob, is a clever man. He does not want Monk to finish all his cheesecakes. Hence, he plays a game.
|
| 6 |
+
The Monk is given N numbers and has to select K of these numbers. For each number that Monk chooses, he will get as many cheesecakes as the number of 1's in the Binary representation of the number i.e. the number of bits that are set.
|
| 7 |
+
Help Monk find the maximum number of cakes that he can have.
|
| 8 |
+
|
| 9 |
+
Input:
|
| 10 |
+
The first line of input contains T. T test cases follow.
|
| 11 |
+
First line of each test cases contains 2 space-separated integers N and K.
|
| 12 |
+
The next line contains N space-separated integers.
|
| 13 |
+
|
| 14 |
+
Output:
|
| 15 |
+
For each test cases, print the answer in a new line.
|
| 16 |
+
|
| 17 |
+
Constraints:
|
| 18 |
+
1 ≤ T ≤ 10
|
| 19 |
+
1 ≤ N ≤ 10^3
|
| 20 |
+
0 ≤ K ≤ N
|
| 21 |
+
0 ≤ Numbers ≤ 10^5
|
| 22 |
+
|
| 23 |
+
SAMPLE INPUT
|
| 24 |
+
1
|
| 25 |
+
4 2
|
| 26 |
+
6 1 2 0
|
| 27 |
+
|
| 28 |
+
SAMPLE OUTPUT
|
| 29 |
+
3
|
| 30 |
+
|
| 31 |
+
Explanation
|
| 32 |
+
|
| 33 |
+
He chooses numbers 6 (110) and 1 (001) with 2 and 1 set bits respectively.
|
| 34 |
+
|
| 35 |
+
## Contest Information
|
| 36 |
+
- **Contest ID**: 0
|
| 37 |
+
- **Problem Index**:
|
| 38 |
+
- **Points**: 0.0
|
| 39 |
+
- **Rating**: 0
|
| 40 |
+
- **Tags**: None
|
| 41 |
+
- **Time Limit**: None seconds
|
| 42 |
+
- **Memory Limit**: 0 bytes
|
| 43 |
+
|
| 44 |
+
## Task
|
| 45 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0075/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# subtraction-game-theory-1
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem:
|
| 5 |
+
|
| 6 |
+
Rani and Nandu decide to play a number game. Both play alternately, Rani playing the first move.
|
| 7 |
+
|
| 8 |
+
In each of their moves, they can subtract a maximum of k and a minimun of 1 from n ( ie.each of them must subtract from n, any natural number less than or equal to k) , and the new value of n will be the result of this subtraction.
|
| 9 |
+
|
| 10 |
+
They continue playing this game until the value of n becomes zero or negative. The person to play the last move loses the game.
|
| 11 |
+
|
| 12 |
+
Both are super-intelligent and hence both play optimally. Given the values of n and k, find out the winner of the game.
|
| 13 |
+
|
| 14 |
+
Note : Large Input/Output Data. Use fast I/O.
|
| 15 |
+
|
| 16 |
+
Input:
|
| 17 |
+
|
| 18 |
+
First line consists of t, the number of test case. The next t lines are such that each line consists of two space separated integers n and k.
|
| 19 |
+
|
| 20 |
+
Output:
|
| 21 |
+
|
| 22 |
+
Print the answer to each test case on a new line, 'Rani' if the winner of the game is Rani and 'Nandu' if the winner of the game is Nandu.
|
| 23 |
+
|
| 24 |
+
Constraints:
|
| 25 |
+
|
| 26 |
+
1 ≤ t ≤ 1000000
|
| 27 |
+
|
| 28 |
+
1 ≤ n ≤ 1000000.
|
| 29 |
+
|
| 30 |
+
1 ≤ k ≤ n.
|
| 31 |
+
|
| 32 |
+
Problem Setter : Shreyans
|
| 33 |
+
|
| 34 |
+
Problem Tester : Sandeep
|
| 35 |
+
|
| 36 |
+
(By IIT Kgp HackerEarth Programming Club)
|
| 37 |
+
|
| 38 |
+
SAMPLE INPUT
|
| 39 |
+
2
|
| 40 |
+
2 1
|
| 41 |
+
3 2
|
| 42 |
+
|
| 43 |
+
SAMPLE OUTPUT
|
| 44 |
+
Rani
|
| 45 |
+
Rani
|
| 46 |
+
|
| 47 |
+
Explanation
|
| 48 |
+
|
| 49 |
+
For n=2 and k=1
|
| 50 |
+
1st move Rani : n = 2 - 1 = 1
|
| 51 |
+
2nd move Nandu : n = 1 - 1 = 0.
|
| 52 |
+
Now, n has become zero. So, the game is over. Since Nandu palyed the last move, he loses the game. So,
|
| 53 |
+
|
| 54 |
+
the winner of the game is Rani.
|
| 55 |
+
|
| 56 |
+
For n=3 and k=2
|
| 57 |
+
1st move Rani : n = 3 - 2 = 1
|
| 58 |
+
2nd move Nandu : n = 1 - 1 = 0 or n = 1 - 2 = -1.
|
| 59 |
+
Now, n has become zero/negative. So, the game is over. Since Nandu palyed the last move, he loses the
|
| 60 |
+
|
| 61 |
+
game. So, the winner of the game is Rani.
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 0
|
| 65 |
+
- **Problem Index**:
|
| 66 |
+
- **Points**: 0.0
|
| 67 |
+
- **Rating**: 0
|
| 68 |
+
- **Tags**: None
|
| 69 |
+
- **Time Limit**: None seconds
|
| 70 |
+
- **Memory Limit**: 0 bytes
|
| 71 |
+
|
| 72 |
+
## Task
|
| 73 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0081/instruction.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03153 KEYENCE Programming Contest 2019 - Connecting Cities
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.
|
| 5 |
+
|
| 6 |
+
Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* 1 \leq N \leq 2 \times 10^5
|
| 11 |
+
* 1 \leq D \leq 10^9
|
| 12 |
+
* 1 \leq A_{i} \leq 10^9
|
| 13 |
+
* A_{i} and D are integers.
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
Input is given from Standard Input in the following format:
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
N D
|
| 21 |
+
A_1 A_2 ... A_N
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print the minimum possible total cost.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
3 1
|
| 33 |
+
1 100 1
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
106
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
3 1000
|
| 44 |
+
1 100 1
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
2202
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
6 14
|
| 55 |
+
25 171 7 1 17 162
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
497
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Input
|
| 64 |
+
|
| 65 |
+
12 5
|
| 66 |
+
43 94 27 3 69 99 56 25 8 15 46 8
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Output
|
| 70 |
+
|
| 71 |
+
658
|
| 72 |
+
|
| 73 |
+
## Contest Information
|
| 74 |
+
- **Contest ID**: 0
|
| 75 |
+
- **Problem Index**:
|
| 76 |
+
- **Points**: 0.0
|
| 77 |
+
- **Rating**: 0
|
| 78 |
+
- **Tags**:
|
| 79 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 80 |
+
- **Memory Limit**: 1073741824 bytes
|
| 81 |
+
|
| 82 |
+
## Task
|
| 83 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0086/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03943 AtCoder Beginner Contest 047 - Fighting over Candies
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Two students of AtCoder Kindergarten are fighting over candy packs.
|
| 5 |
+
|
| 6 |
+
There are three candy packs, each of which contains a, b, and c candies, respectively.
|
| 7 |
+
|
| 8 |
+
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
|
| 9 |
+
|
| 10 |
+
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 ≦ a, b, c ≦ 100
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The input is given from Standard Input in the following format:
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
a b c
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
If it is possible to distribute the packs so that each student gets the same number of candies, print `Yes`. Otherwise, print `No`.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
10 30 20
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
Yes
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
30 30 100
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
No
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
56 25 31
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
Yes
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 0
|
| 61 |
+
- **Problem Index**:
|
| 62 |
+
- **Points**: 0.0
|
| 63 |
+
- **Rating**: 0
|
| 64 |
+
- **Tags**:
|
| 65 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 66 |
+
- **Memory Limit**: 268435456 bytes
|
| 67 |
+
|
| 68 |
+
## Task
|
| 69 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0088/instruction.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00167 Bubble Sort
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Sorting algorithms for sorting data are basic algorithms indispensable in computer science. For example, as shown in the figure below, the operation of "sorting the elements of an array of integer values in ascending order" is alignment.
|
| 5 |
+
|
| 6 |
+
<image>
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Many alignment algorithms have been devised, but one of the basic algorithms is bubble sort. As an example, let's arrange an array of given integer values in ascending order by bubble sort.
|
| 10 |
+
|
| 11 |
+
<image>
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
In bubble sort, each calculation step divides the array into "sorted parts" and "unsorted parts". Initially, the entire array will be the unsorted part.
|
| 16 |
+
|
| 17 |
+
From the beginning of the unsorted part, compare the adjacent elements (green element in the figure) and swap them so that the larger value is to the right. If the two values are equal, they will not be exchanged.
|
| 18 |
+
|
| 19 |
+
<image>
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Repeat this process until the end of the unsorted part (white element in the figure). Finally, add the end to the sorted part (blue element in the figure) to complete one step.
|
| 24 |
+
|
| 25 |
+
Repeat this step until the unsorted part has a length of 1.
|
| 26 |
+
|
| 27 |
+
<image>
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
<image>
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
<image>
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
When the length of the unsorted part becomes 1, the sorting process ends.
|
| 38 |
+
|
| 39 |
+
Now, let's create a program that takes an array of n numbers as input, sorts the numbers in ascending order from the beginning of the array by the above bubble sort procedure, and outputs the number of exchanges of the required array elements. Please give me.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
n
|
| 49 |
+
a1
|
| 50 |
+
a2
|
| 51 |
+
::
|
| 52 |
+
an
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
The first line gives the number n (1 ≤ n ≤ 100), and the following n lines give the i-th number ai (1 ≤ ai ≤ 1000000).
|
| 56 |
+
|
| 57 |
+
The number of datasets does not exceed 20.
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
Outputs the number of data element exchanges (integer) for each data set on one line.
|
| 62 |
+
|
| 63 |
+
Example
|
| 64 |
+
|
| 65 |
+
Input
|
| 66 |
+
|
| 67 |
+
5
|
| 68 |
+
5
|
| 69 |
+
3
|
| 70 |
+
2
|
| 71 |
+
1
|
| 72 |
+
4
|
| 73 |
+
6
|
| 74 |
+
1
|
| 75 |
+
2
|
| 76 |
+
3
|
| 77 |
+
4
|
| 78 |
+
5
|
| 79 |
+
6
|
| 80 |
+
3
|
| 81 |
+
3
|
| 82 |
+
2
|
| 83 |
+
1
|
| 84 |
+
0
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
Output
|
| 88 |
+
|
| 89 |
+
7
|
| 90 |
+
0
|
| 91 |
+
3
|
| 92 |
+
|
| 93 |
+
## Contest Information
|
| 94 |
+
- **Contest ID**: 0
|
| 95 |
+
- **Problem Index**:
|
| 96 |
+
- **Points**: 0.0
|
| 97 |
+
- **Rating**: 0
|
| 98 |
+
- **Tags**:
|
| 99 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 100 |
+
- **Memory Limit**: 134217728 bytes
|
| 101 |
+
|
| 102 |
+
## Task
|
| 103 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0200/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01422 Beautiful Currency
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
KM country has N kinds of coins and each coin has its value a_i.
|
| 5 |
+
|
| 6 |
+
The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins.
|
| 7 |
+
|
| 8 |
+
A currency system is called beautiful if each coin has an integer value and the (i+1)-th smallest value is divisible by the i-th smallest value for all i (1 \leq i \leq N-1).
|
| 9 |
+
|
| 10 |
+
For example, the set {1, 5, 10, 50, 100, 500} is considered as a beautiful system, while the set {1, 5, 10, 25, 50, 100} is NOT, because 25 is not divisible by 10.
|
| 11 |
+
|
| 12 |
+
Since changing the currency system may confuse citizens, the king, Kita_masa, wants to minimize the maximum value of the confusion ratios. Here, the confusion ratio for the change in the i-th coin is defined as |a_i - b_i| / a_i, where a_i and b_i is the value of i-th coin before and after the structure changes, respectively.
|
| 13 |
+
|
| 14 |
+
Note that Kita_masa can change the value of each existing coin, but he cannot introduce new coins nor eliminate existing coins. After the modification, the values of two or more coins may coincide.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
Each dataset contains two lines. The first line contains a single integer, N, and the second line contains N integers, {a_i}.
|
| 21 |
+
|
| 22 |
+
You may assume the following constraints:
|
| 23 |
+
|
| 24 |
+
1 \leq N \leq 20
|
| 25 |
+
|
| 26 |
+
1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
Output one number that represents the minimum of the maximum value of the confusion ratios. The value may be printed with an arbitrary number of decimal digits, but may not contain an absolute error greater than or equal to 10^{-8}.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
3
|
| 37 |
+
6 11 12
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
0.090909090909
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
3
|
| 48 |
+
6 11 24
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
0.090909090909
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
3
|
| 59 |
+
6 11 30
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
0.166666666667
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 0
|
| 68 |
+
- **Problem Index**:
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 0
|
| 71 |
+
- **Tags**:
|
| 72 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 73 |
+
- **Memory Limit**: 134217728 bytes
|
| 74 |
+
|
| 75 |
+
## Task
|
| 76 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0207/instruction.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02445 Swap
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and swap specified elements by a list of the following operation:
|
| 5 |
+
|
| 6 |
+
* swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* $1 \leq n \leq 1,000$
|
| 11 |
+
* $-1,000,000,000 \leq a_i \leq 1,000,000,000$
|
| 12 |
+
* $1 \leq q \leq 1,000$
|
| 13 |
+
* $0 \leq b_i < e_i \leq n$
|
| 14 |
+
* $0 \leq t_i < t_i + (e_i - b_i) \leq n$
|
| 15 |
+
* Given swap ranges do not overlap each other
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The input is given in the following format.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
$n$
|
| 23 |
+
$a_0 \; a_1 \; ...,\; a_{n-1}$
|
| 24 |
+
$q$
|
| 25 |
+
$b_1 \; e_1 \; t_1$
|
| 26 |
+
$b_2 \; e_2 \; t_2$
|
| 27 |
+
:
|
| 28 |
+
$b_{q} \; e_{q} \; t_{q}$
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
|
| 36 |
+
|
| 37 |
+
Example
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
1 2 3 4 5 6 7 8 9 10 11
|
| 43 |
+
1
|
| 44 |
+
1 4 7
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
1 8 9 10 5 6 7 2 3 4 11
|
| 50 |
+
|
| 51 |
+
## Contest Information
|
| 52 |
+
- **Contest ID**: 0
|
| 53 |
+
- **Problem Index**:
|
| 54 |
+
- **Points**: 0.0
|
| 55 |
+
- **Rating**: 0
|
| 56 |
+
- **Tags**:
|
| 57 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 58 |
+
- **Memory Limit**: 268435456 bytes
|
| 59 |
+
|
| 60 |
+
## Task
|
| 61 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0209/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# colarr
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Chef had a hard time arguing with his friend, and after getting a great old kick Chef saw a colored array with N cells, numbered from 1 to N.
|
| 5 |
+
The kick was so strong that Chef suddenly understood the rules of the game.
|
| 6 |
+
|
| 7 |
+
Each cell is painted with a color. Here the colors are numbered from 1 to M.
|
| 8 |
+
For any cell i, Chef can repaint it with any color q, and the cost of such operation is Ci,q points.
|
| 9 |
+
However Chef can do at most K repaintings (0 repaintings is possible).
|
| 10 |
+
After performing all repaintings, each cell will have some color. For each cell i, if cell i has color q then Chef will receive Bi,q points.
|
| 11 |
+
|
| 12 |
+
Now Chef is wondering how many points can he receive in total when he repaints optimally.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows.
|
| 16 |
+
The first line of each test case contains three space-separated integers N, M and K, denoting the number of cells and the number of colors, the maximal possible number of repaintings respectively. The next line contains N space-separated integers A1, A2, ..., AN, denoting the initial colors of the cells. Then N lines follow. The i^th line of them contains M integers Bi1, Bi2, ..., BiM, where Bij denotes how many points Chef will receive if the cell i will be painted with j-th color after all operations. Then N lines follow. The i^th line of them contains M integers Ci1, Ci2, ..., CiM, where Cij denotes how many points Chef will lose if he repaints the cell i with color j.
|
| 17 |
+
|
| 18 |
+
Note: Be careful that the size of input files can be large.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
For each test case, output a single line containing the maximal possible points.
|
| 23 |
+
|
| 24 |
+
Constraints
|
| 25 |
+
|
| 26 |
+
1 ≤ T ≤ 5
|
| 27 |
+
0 ≤ K ≤ 1000
|
| 28 |
+
1 ≤ N, M ≤ 1000
|
| 29 |
+
1 ≤ Ai ≤ M
|
| 30 |
+
0 ≤ Bi,j ≤ 1000
|
| 31 |
+
0 ≤ Ci,j ≤ 1000
|
| 32 |
+
If j = Ai, then Ci,j = 0
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Example
|
| 36 |
+
Input:
|
| 37 |
+
1
|
| 38 |
+
4 2 1
|
| 39 |
+
1 1 2 2
|
| 40 |
+
1 1
|
| 41 |
+
1 1
|
| 42 |
+
1 1
|
| 43 |
+
3 1
|
| 44 |
+
0 1
|
| 45 |
+
0 1
|
| 46 |
+
1 0
|
| 47 |
+
1 0
|
| 48 |
+
|
| 49 |
+
Output:
|
| 50 |
+
5
|
| 51 |
+
|
| 52 |
+
Explanation:
|
| 53 |
+
For this sample, we can repaint only once, since K = 1. We should repaint 4^th cell with color 1. We will pay 1 for this, and receive:
|
| 54 |
+
1 (1^st cell - 1^st color) +
|
| 55 |
+
1 (2^nd cell -1^st color) +
|
| 56 |
+
1 (3^rd cell - 2^nd color) +
|
| 57 |
+
3 (4^th cell - 1^st color) = 6.
|
| 58 |
+
Hence we get 6 − 1 = 5 points in total, and it is the optimal answer.
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 0
|
| 62 |
+
- **Problem Index**:
|
| 63 |
+
- **Points**: 0.0
|
| 64 |
+
- **Rating**: 0
|
| 65 |
+
- **Tags**: None
|
| 66 |
+
- **Time Limit**: None seconds
|
| 67 |
+
- **Memory Limit**: 0 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0213/instruction.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tech07
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a square with 'n' points on each side of the square. None of these points co-incide with the corners of this square. You have to compute the total number of triangles that can be formed using these '4n' points (n points on each side of the square) as vertices of the triangle.
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
Input
|
| 8 |
+
|
| 9 |
+
First line contains the integer 'T', the number of test cases. This is followed by 'T' lines with a single integer 'n' on each line n ≤ 100.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
The total number of triangles that can be formed.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Example
|
| 18 |
+
|
| 19 |
+
Input:
|
| 20 |
+
1
|
| 21 |
+
1
|
| 22 |
+
|
| 23 |
+
Output:
|
| 24 |
+
4
|
| 25 |
+
|
| 26 |
+
## Contest Information
|
| 27 |
+
- **Contest ID**: 0
|
| 28 |
+
- **Problem Index**:
|
| 29 |
+
- **Points**: 0.0
|
| 30 |
+
- **Rating**: 0
|
| 31 |
+
- **Tags**: None
|
| 32 |
+
- **Time Limit**: None seconds
|
| 33 |
+
- **Memory Limit**: 0 bytes
|
| 34 |
+
|
| 35 |
+
## Task
|
| 36 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0238/instruction.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 153_E. Euclidean Distance
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a multiset of points on the plane with integer coordinates. Find the maximum distance between two points from this multiset.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first line of input contains the number of points n (2 ≤ n ≤ 50). Next, n pairs of lines follow, each describing a single point: the first line contains x-coordinate, the second one — the y-coordinate ( - 50 ≤ x, y ≤ 50). Some of the points can have identical coordinates.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output the maximum distance between two points from this multiset. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
3
|
| 19 |
+
0
|
| 20 |
+
1
|
| 21 |
+
2
|
| 22 |
+
3
|
| 23 |
+
4
|
| 24 |
+
5
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
5.656854249
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
10
|
| 36 |
+
12
|
| 37 |
+
-5
|
| 38 |
+
8
|
| 39 |
+
10
|
| 40 |
+
12
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
15.5241747
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first case the maximum distance is between points (0, 1) and (4, 5). In the second case two of the points are the same, so the maximum distance is between one of them and the third point.
|
| 50 |
+
|
| 51 |
+
## Contest Information
|
| 52 |
+
- **Contest ID**: 153
|
| 53 |
+
- **Problem Index**: E
|
| 54 |
+
- **Points**: 0.0
|
| 55 |
+
- **Rating**: 2100
|
| 56 |
+
- **Tags**: *special
|
| 57 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 58 |
+
- **Memory Limit**: 256000000 bytes
|
| 59 |
+
|
| 60 |
+
## Task
|
| 61 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0253/instruction.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 494_A. Treasure
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
|
| 5 |
+
|
| 6 |
+
Below there was also written that a string is called beautiful if for each i (1 ≤ i ≤ |s|) there are no more ')' characters than '(' characters among the first i characters of s and also the total number of '(' characters is equal to the total number of ')' characters.
|
| 7 |
+
|
| 8 |
+
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of the input contains a string s (1 ≤ |s| ≤ 105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that s contains at least one '#' character.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
If there is no way of replacing '#' characters which leads to a beautiful string print - 1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
|
| 17 |
+
|
| 18 |
+
If there are several possible answers, you may output any of them.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
(((#)((#)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
1
|
| 30 |
+
2
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
()((#((#(#()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
2
|
| 41 |
+
2
|
| 42 |
+
1
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
#
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
-1
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
(#)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
-1
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
|s| denotes the length of the string s.
|
| 66 |
+
|
| 67 |
+
## Contest Information
|
| 68 |
+
- **Contest ID**: 494
|
| 69 |
+
- **Problem Index**: A
|
| 70 |
+
- **Points**: 500.0
|
| 71 |
+
- **Rating**: 1500
|
| 72 |
+
- **Tags**: greedy
|
| 73 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 74 |
+
- **Memory Limit**: 256000000 bytes
|
| 75 |
+
|
| 76 |
+
## Task
|
| 77 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0262/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 709_E. Centroids
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed <image>.
|
| 5 |
+
|
| 6 |
+
You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
3
|
| 21 |
+
1 2
|
| 22 |
+
2 3
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
1 1 1
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
5
|
| 33 |
+
1 2
|
| 34 |
+
1 3
|
| 35 |
+
1 4
|
| 36 |
+
1 5
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
1 0 0 0 0
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 709
|
| 49 |
+
- **Problem Index**: E
|
| 50 |
+
- **Points**: 1500.0
|
| 51 |
+
- **Rating**: 2300
|
| 52 |
+
- **Tags**: data structures, dfs and similar, dp, graphs, greedy, trees
|
| 53 |
+
- **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 512000000 bytes
|
| 55 |
+
|
| 56 |
+
## Task
|
| 57 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0276/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chandu-and-daspal-2
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Continuing from previous version of codeXplod series i.e. CodeXplod 1.0,Chandu and daspal are still fighting over a matter of MOMO's(they are very fond of Mo Mos of sector 3..:P).This time the fight became so savior that they want to kill each other.As we all know that during a fight it is most probable outcome that both will be injured.As their friend we don`t want that to happen so we devise a method.
|
| 5 |
+
|
| 6 |
+
We gave them two integers (x,y) as they have to play a game on these values.
|
| 7 |
+
Game is defined as follows:-
|
| 8 |
+
Players play alternative.
|
| 9 |
+
1-During a move they are allowed to subtract gcd(x,y) from both x and y .
|
| 10 |
+
|
| 11 |
+
2-The player which makes either one of the values to zero or both to zero will win the game and will eat all the MOMO's.
|
| 12 |
+
|
| 13 |
+
3-If neither of values after 1st step does not equal to zero then the second player gets a chance and play as described by rule 1,2,3.
|
| 14 |
+
Now,You are given two integers and you have to find out who will eat all the MOMOs.
|
| 15 |
+
|
| 16 |
+
Input Format:-
|
| 17 |
+
|
| 18 |
+
First Line of input will contain an integer T denoting number of test cases.
|
| 19 |
+
Each test cases contains 2 integers(x,y) with a strings.
|
| 20 |
+
Two integers x,y specify the integers given to them by us and string will specify who will play first i.e. String will be either of values "Chandu" and "Daspal"(Quotes only for clarity).
|
| 21 |
+
Output Format:-
|
| 22 |
+
|
| 23 |
+
Output a string either "Chandu" or "Daspal"(Qoutes for clarity) determinging who will win the game.
|
| 24 |
+
Constraints:-
|
| 25 |
+
|
| 26 |
+
1 ≤ T ≤ 50
|
| 27 |
+
|
| 28 |
+
1 ≤ x,y ≤ 3000
|
| 29 |
+
|
| 30 |
+
SAMPLE INPUT
|
| 31 |
+
1
|
| 32 |
+
2 3 Chandu
|
| 33 |
+
|
| 34 |
+
SAMPLE OUTPUT
|
| 35 |
+
Daspal
|
| 36 |
+
|
| 37 |
+
Explanation
|
| 38 |
+
|
| 39 |
+
First gcd(2,3)=1 so Chandu subtract 1 from each so new pair now (1,2) now its Daspal's Turn he has gcd(1,2)=1 so after subtracting (0,1) now daspal have one zero so he is declared as winner of the game.Phew!!!
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 0
|
| 43 |
+
- **Problem Index**:
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 0
|
| 46 |
+
- **Tags**: None
|
| 47 |
+
- **Time Limit**: None seconds
|
| 48 |
+
- **Memory Limit**: 0 bytes
|
| 49 |
+
|
| 50 |
+
## Task
|
| 51 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0278/instruction.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# give-me-my-test-monk
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Professor just has checked all the N students tests. Everything was fine but then he realised that none of the students had signed their papers, so he doesn't know which test belongs to which student.
|
| 5 |
+
|
| 6 |
+
But it's definitely not professors's job to catch every student and asked him to find his paper! So he will hand out these papers in a random way.
|
| 7 |
+
|
| 8 |
+
Now he is interested in the following question: what is the probability that X students will receive someone other's test, not their where L ≤ X ≤ R.
|
| 9 |
+
|
| 10 |
+
Input:
|
| 11 |
+
|
| 12 |
+
The first line contains 3 space-separated integers: N, L, R.
|
| 13 |
+
|
| 14 |
+
Output:
|
| 15 |
+
|
| 16 |
+
Let's suppose the answer is a fraction P / Q where P and Q are coprime. Output P * Q^-1 modulo 10^9 + 7.
|
| 17 |
+
|
| 18 |
+
Constraints:
|
| 19 |
+
|
| 20 |
+
1 ≤ N ≤ 100
|
| 21 |
+
0 ≤ L ≤ R ≤ N
|
| 22 |
+
|
| 23 |
+
SAMPLE INPUT
|
| 24 |
+
3 1 3
|
| 25 |
+
|
| 26 |
+
SAMPLE OUTPUT
|
| 27 |
+
833333340
|
| 28 |
+
|
| 29 |
+
Explanation
|
| 30 |
+
|
| 31 |
+
It's not possible that exactly 1 students doesn't receive his paper.
|
| 32 |
+
There are 3 variants when 2 students doesn't receive their tests: {1, 3, 2}, {3, 2, 1}, {2, 1, 3}
|
| 33 |
+
There are 2 variants when 3 students doesn't receive their tests: {3, 1, 2}, {2, 3, 1}
|
| 34 |
+
|
| 35 |
+
There are 5 variants total and 6 overall possible situations. So the answer is (5 / 6) modulo 10^9 + 7 = 833333340
|
| 36 |
+
|
| 37 |
+
## Contest Information
|
| 38 |
+
- **Contest ID**: 0
|
| 39 |
+
- **Problem Index**:
|
| 40 |
+
- **Points**: 0.0
|
| 41 |
+
- **Rating**: 0
|
| 42 |
+
- **Tags**: None
|
| 43 |
+
- **Time Limit**: None seconds
|
| 44 |
+
- **Memory Limit**: 0 bytes
|
| 45 |
+
|
| 46 |
+
## Task
|
| 47 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0298/instruction.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00490 Best Pizza
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
problem
|
| 5 |
+
|
| 6 |
+
Chairman K is a regular customer of the JOI pizza shop in the center of JOI city. For some reason, he decided to start a life-saving life this month. So he wanted to order the pizza with the highest calories per dollar among the pizzas he could order at the JOI pizza store. Let's call such a pizza the "best pizza". The "best pizza" is not limited to one type.
|
| 7 |
+
|
| 8 |
+
At JOI Pizza, you can freely choose from N types of toppings and order the ones placed on the basic dough. You cannot put more than one topping of the same type. You can also order a pizza that doesn't have any toppings on the dough. The price of the dough is $ A and the price of the toppings is $ B. The price of pizza is the sum of the price of the dough and the price of the toppings. That is, the price of a pizza with k types of toppings (0 ≤ k ≤ N) is A + k x B dollars. The total calorie of the pizza is the sum of the calories of the dough and the calories of the toppings placed.
|
| 9 |
+
|
| 10 |
+
Create a program to find the number of calories per dollar for the "best pizza" given the price of the dough and the price of the toppings, and the calorie value of the dough and each topping.
|
| 11 |
+
|
| 12 |
+
input
|
| 13 |
+
|
| 14 |
+
The input consists of N + 3 lines.
|
| 15 |
+
|
| 16 |
+
On the first line, one integer N (1 ≤ N ≤ 100) representing the number of topping types is written. On the second line, two integers A and B (1 ≤ A ≤ 1000, 1 ≤ B ≤ 1000) are written with a blank as a delimiter. A is the price of the dough and B is the price of the toppings. On the third line, one integer C (1 ≤ C ≤ 10000) representing the number of calories in the dough is written.
|
| 17 |
+
|
| 18 |
+
On the 3 + i line (1 ≤ i ≤ N), one integer Di (1 ≤ Di ≤ 10000) representing the number of calories in the i-th topping is written.
|
| 19 |
+
|
| 20 |
+
output
|
| 21 |
+
|
| 22 |
+
Print the number of calories per dollar for the "best pizza" in one line. However, round down the numbers after the decimal point and output as an integer value.
|
| 23 |
+
|
| 24 |
+
Input / output example
|
| 25 |
+
|
| 26 |
+
Input example 1
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
3
|
| 30 |
+
12 2
|
| 31 |
+
200
|
| 32 |
+
50
|
| 33 |
+
300
|
| 34 |
+
100
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output example 1
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
37
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
In I / O Example 1, with the second and third toppings, 200 + 300 + 100 = 600 calories gives a pizza of $ 12 + 2 x 2 = $ 16.
|
| 44 |
+
This pizza has 600/16 = 37.5 calories per dollar. Since this is the "best pizza", we output 37, rounded down to the nearest whole number of 37.5.
|
| 45 |
+
|
| 46 |
+
Input example 2
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Four
|
| 50 |
+
20 3
|
| 51 |
+
900
|
| 52 |
+
300
|
| 53 |
+
100
|
| 54 |
+
400
|
| 55 |
+
1300
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output example 2
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
100
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Example
|
| 71 |
+
|
| 72 |
+
Input
|
| 73 |
+
|
| 74 |
+
3
|
| 75 |
+
12 2
|
| 76 |
+
200
|
| 77 |
+
50
|
| 78 |
+
300
|
| 79 |
+
100
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Output
|
| 83 |
+
|
| 84 |
+
37
|
| 85 |
+
|
| 86 |
+
## Contest Information
|
| 87 |
+
- **Contest ID**: 0
|
| 88 |
+
- **Problem Index**:
|
| 89 |
+
- **Points**: 0.0
|
| 90 |
+
- **Rating**: 0
|
| 91 |
+
- **Tags**:
|
| 92 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 93 |
+
- **Memory Limit**: 134217728 bytes
|
| 94 |
+
|
| 95 |
+
## Task
|
| 96 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0405/instruction.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00914 Equal Sum Sets
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.
|
| 5 |
+
|
| 6 |
+
Specifying the number of set elements and their sum to be k and s, respectively, sets satisfying the conditions are limited. When n = 9, k = 3 and s = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When n = 9, k = 3 and s = 22, both {5, 8, 9} and {6, 7, 9} are possible.
|
| 7 |
+
|
| 8 |
+
You have to write a program that calculates the number of the sets that satisfy the given conditions.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The input consists of multiple datasets. The number of datasets does not exceed 100.
|
| 15 |
+
|
| 16 |
+
Each of the datasets has three integers n, k and s in one line, separated by a space. You may assume 1 ≤ n ≤ 20, 1 ≤ k ≤ 10 and 1 ≤ s ≤ 155.
|
| 17 |
+
|
| 18 |
+
The end of the input is indicated by a line containing three zeros.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output.
|
| 23 |
+
|
| 24 |
+
You can assume that the number of sets does not exceed 231 - 1.
|
| 25 |
+
|
| 26 |
+
Example
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
9 3 23
|
| 31 |
+
9 3 22
|
| 32 |
+
10 3 28
|
| 33 |
+
16 10 107
|
| 34 |
+
20 8 102
|
| 35 |
+
20 10 105
|
| 36 |
+
20 10 155
|
| 37 |
+
3 4 3
|
| 38 |
+
4 2 11
|
| 39 |
+
0 0 0
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
1
|
| 45 |
+
2
|
| 46 |
+
0
|
| 47 |
+
20
|
| 48 |
+
1542
|
| 49 |
+
5448
|
| 50 |
+
1
|
| 51 |
+
0
|
| 52 |
+
0
|
| 53 |
+
|
| 54 |
+
## Contest Information
|
| 55 |
+
- **Contest ID**: 0
|
| 56 |
+
- **Problem Index**:
|
| 57 |
+
- **Points**: 0.0
|
| 58 |
+
- **Rating**: 0
|
| 59 |
+
- **Tags**:
|
| 60 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 61 |
+
- **Memory Limit**: 134217728 bytes
|
| 62 |
+
|
| 63 |
+
## Task
|
| 64 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0418/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# donuts
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There is new delicious item in Chef's menu - a doughnut chain. Doughnuts connected successively in line forming a chain.
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
Chain of 3 doughnuts
|
| 8 |
+
|
| 9 |
+
Chef has received an urgent order for making a chain of N doughnuts. He noticed that there are exactly N cooked doughnuts in the kitchen, some of which are already connected in chains. The only thing he needs to do is connect them in one chain.
|
| 10 |
+
He can cut one doughnut (from any position in a chain) into two halves and then use this cut doughnut to link two different chains.
|
| 11 |
+
Help Chef determine the minimum number of cuts needed to complete the order.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains an integer T denoting the number of test cases.
|
| 17 |
+
The first line of each test case contains two integer N and M denoting the size of order and number of cooked chains respectively.
|
| 18 |
+
The second line contains M space-separated integers A1, A2, ..., AM denoting the size of the chains.
|
| 19 |
+
|
| 20 |
+
It is guaranteed that N is equal to the sum of all Ai's over 1<=i<=M.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
For each test case, output a single line containing an integer corresponding to the number of cuts needed Chef to make the order.
|
| 24 |
+
|
| 25 |
+
Constraints and Example
|
| 26 |
+
Input:
|
| 27 |
+
2
|
| 28 |
+
11 3
|
| 29 |
+
4 3 4
|
| 30 |
+
6 3
|
| 31 |
+
3 2 1
|
| 32 |
+
|
| 33 |
+
Output:
|
| 34 |
+
2
|
| 35 |
+
1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Explanation
|
| 39 |
+
Example 1: We could cut 2 doughnut from any "chain" and use them to connect chains to the one. For example, let's cut it from the first chain. After this we will have chains of sizes 2, 3, 4 and two doughnuts that have been cut. So we could connect the first chain with second and second with third using these two doughnuts.
|
| 40 |
+
Example 2: We cut doughnut from the last "chain" and connect the first two chains.
|
| 41 |
+
|
| 42 |
+
Image for second example. Yellow doughnut has been cut.
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 0
|
| 46 |
+
- **Problem Index**:
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 0
|
| 49 |
+
- **Tags**: None
|
| 50 |
+
- **Time Limit**: None seconds
|
| 51 |
+
- **Memory Limit**: 0 bytes
|
| 52 |
+
|
| 53 |
+
## Task
|
| 54 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0429/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1158_F. Density of subarrays
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let c be some positive integer. Let's call an array a_1, a_2, …, a_n of positive integers c-array, if for all i condition 1 ≤ a_i ≤ c is satisfied. Let's call c-array b_1, b_2, …, b_k a subarray of c-array a_1, a_2, …, a_n, if there exists such set of k indices 1 ≤ i_1 < i_2 < … < i_k ≤ n that b_j = a_{i_j} for all 1 ≤ j ≤ k. Let's define density of c-array a_1, a_2, …, a_n as maximal non-negative integer p, such that any c-array, that contains p numbers is a subarray of a_1, a_2, …, a_n.
|
| 5 |
+
|
| 6 |
+
You are given a number c and some c-array a_1, a_2, …, a_n. For all 0 ≤ p ≤ n find the number of sequences of indices 1 ≤ i_1 < i_2 < … < i_k ≤ n for all 1 ≤ k ≤ n, such that density of array a_{i_1}, a_{i_2}, …, a_{i_k} is equal to p. Find these numbers by modulo 998 244 353, because they can be too large.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains two integers n and c, separated by spaces (1 ≤ n, c ≤ 3 000). The second line contains n integers a_1, a_2, …, a_n, separated by spaces (1 ≤ a_i ≤ c).
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print n + 1 numbers s_0, s_1, …, s_n. s_p should be equal to the number of sequences of indices 1 ≤ i_1 < i_2 < … < i_k ≤ n for all 1 ≤ k ≤ n by modulo 998 244 353, such that the density of array a_{i_1}, a_{i_2}, …, a_{i_k} is equal to p.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
4 1
|
| 22 |
+
1 1 1 1
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
0 4 6 4 1
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
3 3
|
| 34 |
+
1 2 3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
6 1 0 0
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
5 2
|
| 46 |
+
1 2 1 2 1
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
10 17 4 0 0 0
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
In the first example, it's easy to see that the density of array will always be equal to its length. There exists 4 sequences with one index, 6 with two indices, 4 with three and 1 with four.
|
| 57 |
+
|
| 58 |
+
In the second example, the only sequence of indices, such that the array will have non-zero density is all indices because in other cases there won't be at least one number from 1 to 3 in the array, so it won't satisfy the condition of density for p ≥ 1.
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 1158
|
| 62 |
+
- **Problem Index**: F
|
| 63 |
+
- **Points**: 2750.0
|
| 64 |
+
- **Rating**: 3500
|
| 65 |
+
- **Tags**: dp, math
|
| 66 |
+
- **Time Limit**: {'seconds': 6, 'nanos': 0} seconds
|
| 67 |
+
- **Memory Limit**: 256000000 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0433/instruction.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1239_E. Turtle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Kolya has a turtle and a field of size 2 × n. The field rows are numbered from 1 to 2 from top to bottom, while the columns are numbered from 1 to n from left to right.
|
| 5 |
+
|
| 6 |
+
Suppose in each cell of the field there is a lettuce leaf. The energy value of lettuce leaf in row i and column j is equal to a_{i,j}. The turtle is initially in the top left cell and wants to reach the bottom right cell. The turtle can only move right and down and among all possible ways it will choose a way, maximizing the total energy value of lettuce leaves (in case there are several such paths, it will choose any of them).
|
| 7 |
+
|
| 8 |
+
Kolya is afraid, that if turtle will eat too much lettuce, it can be bad for its health. So he wants to reorder lettuce leaves in the field, so that the energetic cost of leaves eaten by turtle will be minimized.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains an integer n (2 ≤ n ≤ 25) — the length of the field.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers a_{1, i} (0 ≤ a_{1, i} ≤ 50 000), the energetic cost of lettuce leaves in the first row of the field.
|
| 15 |
+
|
| 16 |
+
The third line contains n integers a_{2, i} (0 ≤ a_{2, i} ≤ 50 000), the energetic cost of lettuce leaves in the second row of the field.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print two lines with n integers in each — the optimal reordering of lettuce from the input data.
|
| 21 |
+
|
| 22 |
+
In case there are several optimal ways to reorder lettuce, print any of them.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
2
|
| 30 |
+
1 4
|
| 31 |
+
2 3
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
1 3
|
| 38 |
+
4 2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
3
|
| 45 |
+
0 0 0
|
| 46 |
+
0 0 0
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
0 0 0
|
| 53 |
+
0 0 0
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
3
|
| 60 |
+
1 0 1
|
| 61 |
+
0 0 0
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Output
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
0 0 1
|
| 68 |
+
0 1 0
|
| 69 |
+
|
| 70 |
+
Note
|
| 71 |
+
|
| 72 |
+
In the first example, after reordering, the turtle will eat lettuce with total energetic cost 1+4+2 = 7.
|
| 73 |
+
|
| 74 |
+
In the second example, the turtle will eat lettuce with energetic cost equal 0.
|
| 75 |
+
|
| 76 |
+
In the third example, after reordering, the turtle will eat lettuce with total energetic cost equal 1.
|
| 77 |
+
|
| 78 |
+
## Contest Information
|
| 79 |
+
- **Contest ID**: 1239
|
| 80 |
+
- **Problem Index**: E
|
| 81 |
+
- **Points**: 2500.0
|
| 82 |
+
- **Rating**: 3100
|
| 83 |
+
- **Tags**: dp, implementation
|
| 84 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 85 |
+
- **Memory Limit**: 512000000 bytes
|
| 86 |
+
|
| 87 |
+
## Task
|
| 88 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0434/instruction.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1257_G. Divisor Set
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an integer x represented as a product of n its prime divisors p_1 ⋅ p_2, ⋅ … ⋅ p_n. Let S be the set of all positive integer divisors of x (including 1 and x itself).
|
| 5 |
+
|
| 6 |
+
We call a set of integers D good if (and only if) there is no pair a ∈ D, b ∈ D such that a ≠ b and a divides b.
|
| 7 |
+
|
| 8 |
+
Find a good subset of S with maximum possible size. Since the answer can be large, print the size of the subset modulo 998244353.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains the single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of prime divisors in representation of x.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers p_1, p_2, ..., p_n (2 ≤ p_i ≤ 3 ⋅ 10^6) — the prime factorization of x.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print the maximum possible size of a good subset modulo 998244353.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
3
|
| 26 |
+
2999999 43 2999957
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
3
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
6
|
| 39 |
+
2 3 2 3 2 2
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
3
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first sample, x = 2999999 ⋅ 43 ⋅ 2999957 and one of the maximum good subsets is \{ 43, 2999957, 2999999 \}.
|
| 50 |
+
|
| 51 |
+
In the second sample, x = 2 ⋅ 3 ⋅ 2 ⋅ 3 ⋅ 2 ⋅ 2 = 144 and one of the maximum good subsets is \{ 9, 12, 16 \}.
|
| 52 |
+
|
| 53 |
+
## Contest Information
|
| 54 |
+
- **Contest ID**: 1257
|
| 55 |
+
- **Problem Index**: G
|
| 56 |
+
- **Points**: 0.0
|
| 57 |
+
- **Rating**: 2600
|
| 58 |
+
- **Tags**: divide and conquer, fft, greedy, math, number theory
|
| 59 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 60 |
+
- **Memory Limit**: 512000000 bytes
|
| 61 |
+
|
| 62 |
+
## Task
|
| 63 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0442/instruction.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1428_D. Bouncing Boomerangs
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
To improve the boomerang throwing skills of the animals, Zookeeper has set up an n × n grid with some targets, where each row and each column has at most 2 targets each. The rows are numbered from 1 to n from top to bottom, and the columns are numbered from 1 to n from left to right.
|
| 5 |
+
|
| 6 |
+
For each column, Zookeeper will throw a boomerang from the bottom of the column (below the grid) upwards. When the boomerang hits any target, it will bounce off, make a 90 degree turn to the right and fly off in a straight line in its new direction. The boomerang can hit multiple targets and does not stop until it leaves the grid.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
In the above example, n=6 and the black crosses are the targets. The boomerang in column 1 (blue arrows) bounces 2 times while the boomerang in column 3 (red arrows) bounces 3 times.
|
| 11 |
+
|
| 12 |
+
The boomerang in column i hits exactly a_i targets before flying out of the grid. It is known that a_i ≤ 3.
|
| 13 |
+
|
| 14 |
+
However, Zookeeper has lost the original positions of the targets. Thus, he asks you to construct a valid configuration of targets that matches the number of hits for each column, or tell him that no such configuration exists. If multiple valid configurations exist, you may print any of them.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The first line contains a single integer n (1 ≤ n ≤ 10^5).
|
| 19 |
+
|
| 20 |
+
The next line contains n integers a_1,a_2,…,a_n (0 ≤ a_i ≤ 3).
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
If no configuration of targets exist, print -1.
|
| 25 |
+
|
| 26 |
+
Otherwise, on the first line print a single integer t (0 ≤ t ≤ 2n): the number of targets in your configuration.
|
| 27 |
+
|
| 28 |
+
Then print t lines with two spaced integers each per line. Each line should contain two integers r and c (1 ≤ r,c ≤ n), where r is the target's row and c is the target's column. All targets should be different.
|
| 29 |
+
|
| 30 |
+
Every row and every column in your configuration should have at most two targets each.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
6
|
| 38 |
+
2 0 3 0 1 1
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
5
|
| 45 |
+
2 1
|
| 46 |
+
2 5
|
| 47 |
+
3 3
|
| 48 |
+
3 6
|
| 49 |
+
5 6
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
1
|
| 56 |
+
0
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
0
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Input
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
6
|
| 69 |
+
3 2 2 2 1 1
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Output
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
-1
|
| 76 |
+
|
| 77 |
+
Note
|
| 78 |
+
|
| 79 |
+
For the first test, the answer configuration is the same as in the picture from the statement.
|
| 80 |
+
|
| 81 |
+
For the second test, the boomerang is not supposed to hit anything, so we can place 0 targets.
|
| 82 |
+
|
| 83 |
+
For the third test, the following configuration of targets matches the number of hits, but is not allowed as row 3 has 4 targets.
|
| 84 |
+
|
| 85 |
+
<image>
|
| 86 |
+
|
| 87 |
+
It can be shown for this test case that no valid configuration of targets will result in the given number of target hits.
|
| 88 |
+
|
| 89 |
+
## Contest Information
|
| 90 |
+
- **Contest ID**: 1428
|
| 91 |
+
- **Problem Index**: D
|
| 92 |
+
- **Points**: 1500.0
|
| 93 |
+
- **Rating**: 1900
|
| 94 |
+
- **Tags**: constructive algorithms, greedy, implementation
|
| 95 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 96 |
+
- **Memory Limit**: 256000000 bytes
|
| 97 |
+
|
| 98 |
+
## Task
|
| 99 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0445/instruction.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1500_B. Two chandeliers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered both chandeliers that can change its color cyclically. For example: red – brown – yellow – red – brown – yellow and so on.
|
| 5 |
+
|
| 6 |
+
There are many chandeliers that differs in color set or order of colors. And the person responsible for the light made a critical mistake — they bought two different chandeliers.
|
| 7 |
+
|
| 8 |
+
Since chandeliers are different, some days they will have the same color, but some days — different. Of course, it looks poor and only annoys Vasya. As a result, at the k-th time when chandeliers will light with different colors, Vasya will become very angry and, most probably, will fire the person who bought chandeliers.
|
| 9 |
+
|
| 10 |
+
Your task is to calculate the day, when it happens (counting from the day chandeliers were installed). You can think that Vasya works every day without weekends and days off.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500 000; 1 ≤ k ≤ 10^{12}) — the number of colors in the first and the second chandeliers and how many times colors should differ to anger Vasya.
|
| 15 |
+
|
| 16 |
+
The second line contains n different integers a_i (1 ≤ a_i ≤ 2 ⋅ max(n, m)) that describe the first chandelier's sequence of colors.
|
| 17 |
+
|
| 18 |
+
The third line contains m different integers b_j (1 ≤ b_i ≤ 2 ⋅ max(n, m)) that describe the second chandelier's sequence of colors.
|
| 19 |
+
|
| 20 |
+
At the i-th day, the first chandelier has a color a_x, where x = ((i - 1) mod n) + 1) and the second one has a color b_y, where y = ((i - 1) mod m) + 1).
|
| 21 |
+
|
| 22 |
+
It's guaranteed that sequence a differs from sequence b, so there are will be days when colors of chandeliers differs.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print the single integer — the index of day when Vasya will become angry.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
4 2 4
|
| 34 |
+
4 2 3 1
|
| 35 |
+
2 1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
5
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
3 8 41
|
| 48 |
+
1 3 2
|
| 49 |
+
1 6 4 3 5 7 2 8
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
47
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Input
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
1 2 31
|
| 62 |
+
1
|
| 63 |
+
1 2
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
62
|
| 70 |
+
|
| 71 |
+
Note
|
| 72 |
+
|
| 73 |
+
In the first example, the chandeliers will have different colors at days 1, 2, 3 and 5. That's why the answer is 5.
|
| 74 |
+
|
| 75 |
+
## Contest Information
|
| 76 |
+
- **Contest ID**: 1500
|
| 77 |
+
- **Problem Index**: B
|
| 78 |
+
- **Points**: 750.0
|
| 79 |
+
- **Rating**: 2200
|
| 80 |
+
- **Tags**: binary search, brute force, chinese remainder theorem, math, number theory
|
| 81 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 82 |
+
- **Memory Limit**: 256000000 bytes
|
| 83 |
+
|
| 84 |
+
## Task
|
| 85 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0451/instruction.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 248_A. Cupboards
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
|
| 5 |
+
|
| 6 |
+
Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.
|
| 7 |
+
|
| 8 |
+
And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.
|
| 9 |
+
|
| 10 |
+
Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.
|
| 11 |
+
|
| 12 |
+
Your task is to write a program that will determine the required number of seconds t.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero.
|
| 17 |
+
|
| 18 |
+
The numbers in the lines are separated by single spaces.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
5
|
| 29 |
+
0 1
|
| 30 |
+
1 0
|
| 31 |
+
0 1
|
| 32 |
+
1 1
|
| 33 |
+
0 1
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
3
|
| 39 |
+
|
| 40 |
+
## Contest Information
|
| 41 |
+
- **Contest ID**: 248
|
| 42 |
+
- **Problem Index**: A
|
| 43 |
+
- **Points**: 500.0
|
| 44 |
+
- **Rating**: 800
|
| 45 |
+
- **Tags**: implementation
|
| 46 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 47 |
+
- **Memory Limit**: 256000000 bytes
|
| 48 |
+
|
| 49 |
+
## Task
|
| 50 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0460/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 45_H. Road Problem
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.
|
| 5 |
+
|
| 6 |
+
The city administration noticed that in the cities of all the developed countries between any two roads one can drive along at least two paths so that the paths don't share any roads (but they may share the same junction). The administration decided to add the minimal number of roads so that this rules was fulfilled in the Berland capital as well. In the city road network should exist no more than one road between every pair of junctions before or after the reform.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first input line contains a pair of integers n, m (2 ≤ n ≤ 900, 1 ≤ m ≤ 100000), where n is the number of junctions and m is the number of roads. Each of the following m lines contains a description of a road that is given by the numbers of the connected junctions ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). The junctions are numbered from 1 to n. It is possible to reach any junction of the city from any other one moving along roads.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
On the first line print t — the number of added roads. Then on t lines print the descriptions of the added roads in the format of the input data. You can use any order of printing the roads themselves as well as the junctions linked by every road. If there are several solutions to that problem, print any of them.
|
| 15 |
+
|
| 16 |
+
If the capital doesn't need the reform, print the single number 0.
|
| 17 |
+
|
| 18 |
+
If there's no solution, print the single number -1.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
4 3
|
| 25 |
+
1 2
|
| 26 |
+
2 3
|
| 27 |
+
3 4
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
1
|
| 33 |
+
1 4
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
4 4
|
| 39 |
+
1 2
|
| 40 |
+
2 3
|
| 41 |
+
2 4
|
| 42 |
+
3 4
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
1
|
| 48 |
+
1 3
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 45
|
| 52 |
+
- **Problem Index**: H
|
| 53 |
+
- **Points**: 0.0
|
| 54 |
+
- **Rating**: 2100
|
| 55 |
+
- **Tags**: graphs
|
| 56 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0467/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 626_D. Jerry's Protest
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.
|
| 5 |
+
|
| 6 |
+
Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar.
|
| 11 |
+
|
| 12 |
+
The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
|
| 17 |
+
|
| 18 |
+
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
2
|
| 25 |
+
1 2
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
0.0000000000
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
3
|
| 36 |
+
1 2 10
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
0.0740740741
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.
|
| 46 |
+
|
| 47 |
+
In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 626
|
| 51 |
+
- **Problem Index**: D
|
| 52 |
+
- **Points**: 1500.0
|
| 53 |
+
- **Rating**: 1800
|
| 54 |
+
- **Tags**: brute force, combinatorics, dp, probabilities
|
| 55 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 56 |
+
- **Memory Limit**: 256000000 bytes
|
| 57 |
+
|
| 58 |
+
## Task
|
| 59 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0469/instruction.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 675_E. Trains and Statistic
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.
|
| 5 |
+
|
| 6 |
+
Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j. As Vasya is fond of different useless statistic he asks you to compute the sum of all values ρi, j among all pairs 1 ≤ i < j ≤ n.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of stations.
|
| 11 |
+
|
| 12 |
+
The second line contains n - 1 integer ai (i + 1 ≤ ai ≤ n), the i-th of them means that at the i-th station one may buy tickets to each station from i + 1 to ai inclusive.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print the sum of ρi, j among all pairs of 1 ≤ i < j ≤ n.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
4
|
| 23 |
+
4 4 4
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
6
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
5
|
| 34 |
+
2 3 5 5
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
17
|
| 40 |
+
|
| 41 |
+
Note
|
| 42 |
+
|
| 43 |
+
In the first sample it's possible to get from any station to any other (with greater index) using only one ticket. The total number of pairs is 6, so the answer is also 6.
|
| 44 |
+
|
| 45 |
+
Consider the second sample:
|
| 46 |
+
|
| 47 |
+
* ρ1, 2 = 1
|
| 48 |
+
* ρ1, 3 = 2
|
| 49 |
+
* ρ1, 4 = 3
|
| 50 |
+
* ρ1, 5 = 3
|
| 51 |
+
* ρ2, 3 = 1
|
| 52 |
+
* ρ2, 4 = 2
|
| 53 |
+
* ρ2, 5 = 2
|
| 54 |
+
* ρ3, 4 = 1
|
| 55 |
+
* ρ3, 5 = 1
|
| 56 |
+
* ρ4, 5 = 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Thus the answer equals 1 + 2 + 3 + 3 + 1 + 2 + 2 + 1 + 1 + 1 = 17.
|
| 61 |
+
|
| 62 |
+
## Contest Information
|
| 63 |
+
- **Contest ID**: 675
|
| 64 |
+
- **Problem Index**: E
|
| 65 |
+
- **Points**: 2500.0
|
| 66 |
+
- **Rating**: 2300
|
| 67 |
+
- **Tags**: data structures, dp, greedy
|
| 68 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 69 |
+
- **Memory Limit**: 256000000 bytes
|
| 70 |
+
|
| 71 |
+
## Task
|
| 72 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0493/instruction.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02548 AtCoder Beginner Contest 179 - A x B + C
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?
|
| 5 |
+
|
| 6 |
+
Constraints
|
| 7 |
+
|
| 8 |
+
* 2 \leq N \leq 10^6
|
| 9 |
+
* All values in input are integers.
|
| 10 |
+
|
| 11 |
+
Input
|
| 12 |
+
|
| 13 |
+
Input is given from Standard Input in the following format:
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
N
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Output
|
| 20 |
+
|
| 21 |
+
Print the answer.
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
3
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
3
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
100
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
473
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
1000000
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
13969985
|
| 53 |
+
|
| 54 |
+
## Contest Information
|
| 55 |
+
- **Contest ID**: 0
|
| 56 |
+
- **Problem Index**:
|
| 57 |
+
- **Points**: 0.0
|
| 58 |
+
- **Rating**: 0
|
| 59 |
+
- **Tags**:
|
| 60 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 61 |
+
- **Memory Limit**: 1073741824 bytes
|
| 62 |
+
|
| 63 |
+
## Task
|
| 64 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0494/instruction.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02679 AtCoder Beginner Contest 168 - ∙ (Bullet)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
|
| 5 |
+
|
| 6 |
+
We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
|
| 7 |
+
|
| 8 |
+
The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.
|
| 9 |
+
|
| 10 |
+
In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* All values in input are integers.
|
| 15 |
+
* 1 \leq N \leq 2 \times 10^5
|
| 16 |
+
* -10^{18} \leq A_i, B_i \leq 10^{18}
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
Input is given from Standard Input in the following format:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
N
|
| 24 |
+
A_1 B_1
|
| 25 |
+
:
|
| 26 |
+
A_N B_N
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Print the count modulo 1000000007.
|
| 32 |
+
|
| 33 |
+
Examples
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
3
|
| 38 |
+
1 2
|
| 39 |
+
-1 1
|
| 40 |
+
2 -1
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
5
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
10
|
| 51 |
+
3 2
|
| 52 |
+
3 2
|
| 53 |
+
-1 1
|
| 54 |
+
2 -1
|
| 55 |
+
-3 -9
|
| 56 |
+
-8 12
|
| 57 |
+
7 7
|
| 58 |
+
8 1
|
| 59 |
+
8 2
|
| 60 |
+
8 4
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
479
|
| 66 |
+
|
| 67 |
+
## Contest Information
|
| 68 |
+
- **Contest ID**: 0
|
| 69 |
+
- **Problem Index**:
|
| 70 |
+
- **Points**: 0.0
|
| 71 |
+
- **Rating**: 0
|
| 72 |
+
- **Tags**:
|
| 73 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 74 |
+
- **Memory Limit**: 1073741824 bytes
|
| 75 |
+
|
| 76 |
+
## Task
|
| 77 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0601/instruction.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03003 AtCoder Beginner Contest 130 - Common Subsequence
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).
|
| 5 |
+
|
| 6 |
+
In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?
|
| 7 |
+
|
| 8 |
+
Here the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.
|
| 9 |
+
|
| 10 |
+
For both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.
|
| 11 |
+
|
| 12 |
+
Since the answer can be tremendous, print the number modulo 10^9+7.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* 1 \leq N, M \leq 2 \times 10^3
|
| 17 |
+
* The length of S is N.
|
| 18 |
+
* The length of T is M.
|
| 19 |
+
* 1 \leq S_i, T_i \leq 10^5
|
| 20 |
+
* All values in input are integers.
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
Input is given from Standard Input in the following format:
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
N M
|
| 28 |
+
S_1 S_2 ... S_{N-1} S_{N}
|
| 29 |
+
T_1 T_2 ... T_{M-1} T_{M}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
2 2
|
| 41 |
+
1 3
|
| 42 |
+
3 1
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
2 2
|
| 53 |
+
1 1
|
| 54 |
+
1 1
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
6
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Input
|
| 63 |
+
|
| 64 |
+
4 4
|
| 65 |
+
3 4 5 6
|
| 66 |
+
3 4 5 6
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Output
|
| 70 |
+
|
| 71 |
+
16
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Input
|
| 75 |
+
|
| 76 |
+
10 9
|
| 77 |
+
9 6 5 7 5 9 8 5 6 7
|
| 78 |
+
8 6 8 5 5 7 9 9 7
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Output
|
| 82 |
+
|
| 83 |
+
191
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
Input
|
| 87 |
+
|
| 88 |
+
20 20
|
| 89 |
+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
| 90 |
+
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
Output
|
| 94 |
+
|
| 95 |
+
846527861
|
| 96 |
+
|
| 97 |
+
## Contest Information
|
| 98 |
+
- **Contest ID**: 0
|
| 99 |
+
- **Problem Index**:
|
| 100 |
+
- **Points**: 0.0
|
| 101 |
+
- **Rating**: 0
|
| 102 |
+
- **Tags**:
|
| 103 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 104 |
+
- **Memory Limit**: 1073741824 bytes
|
| 105 |
+
|
| 106 |
+
## Task
|
| 107 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0606/instruction.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03762 AtCoder Beginner Contest 058 - ###
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
|
| 5 |
+
|
| 6 |
+
For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.
|
| 7 |
+
|
| 8 |
+
That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
|
| 12 |
+
* 2 \leq n,m \leq 10^5
|
| 13 |
+
* -10^9 \leq x_1 < ... < x_n \leq 10^9
|
| 14 |
+
* -10^9 \leq y_1 < ... < y_m \leq 10^9
|
| 15 |
+
* x_i and y_i are integers.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
Input is given from Standard Input in the following format:
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
n m
|
| 23 |
+
x_1 x_2 ... x_n
|
| 24 |
+
y_1 y_2 ... y_m
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
Print the total area of the rectangles, modulo 10^9+7.
|
| 30 |
+
|
| 31 |
+
Examples
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
3 3
|
| 36 |
+
1 3 4
|
| 37 |
+
1 3 6
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
60
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
6 5
|
| 48 |
+
-790013317 -192321079 95834122 418379342 586260100 802780784
|
| 49 |
+
-253230108 193944314 363756450 712662868 735867677
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
835067060
|
| 55 |
+
|
| 56 |
+
## Contest Information
|
| 57 |
+
- **Contest ID**: 0
|
| 58 |
+
- **Problem Index**:
|
| 59 |
+
- **Points**: 0.0
|
| 60 |
+
- **Rating**: 0
|
| 61 |
+
- **Tags**:
|
| 62 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 63 |
+
- **Memory Limit**: 268435456 bytes
|
| 64 |
+
|
| 65 |
+
## Task
|
| 66 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0608/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00025 Hit and Blow
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
|
| 5 |
+
|
| 6 |
+
* The number of numbers which have the same place with numbers A imagined (Hit)
|
| 7 |
+
* The number of numbers included (but different place) in the numbers A imagined (Blow)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
For example, if A imagined numbers:
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
9 1 8 2
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
and B chose:
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
4 1 5 9
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
A should say 1 Hit and 1 Blow.
|
| 24 |
+
|
| 25 |
+
Write a program which reads four numbers A imagined and four numbers B chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
The input consists of multiple datasets. Each dataset set consists of:
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
a1 a2 a3 a4
|
| 35 |
+
b1 b2 b3 b4
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
, where ai (0 ≤ ai ≤ 9) is i-th number A imagined and bi (0 ≤ bi ≤ 9) is i-th number B chose.
|
| 39 |
+
|
| 40 |
+
The input ends with EOF. The number of datasets is less than or equal to 50.
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
For each dataset, print the number of Hit and Blow in a line. These two numbers should be separated by a space.
|
| 45 |
+
|
| 46 |
+
Example
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
9 1 8 2
|
| 51 |
+
4 1 5 9
|
| 52 |
+
4 6 8 2
|
| 53 |
+
4 6 3 2
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
1 1
|
| 59 |
+
3 0
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 0
|
| 63 |
+
- **Problem Index**:
|
| 64 |
+
- **Points**: 0.0
|
| 65 |
+
- **Rating**: 0
|
| 66 |
+
- **Tags**:
|
| 67 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 134217728 bytes
|
| 69 |
+
|
| 70 |
+
## Task
|
| 71 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0612/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00669 K Cards
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
One day, the teacher came up with the following game.
|
| 5 |
+
The game uses n cards with one number from 1 to 10 and proceeds as follows.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal row, let Ck be the maximum product of k consecutive cards. Also, let Ck'when the teachers line up.
|
| 9 |
+
2. Students consider increasing Ck by looking at the row of cards affixed in 1. If the Ck can be increased by swapping two cards, the student's grade will increase by Ck --Ck'points. End the game when someone gets a grade.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Your job is to write a program that fills in a row of cards arranged by the teacher and outputs the maximum grades the student can get. However, if you can only lower Ck by selecting any two of them and exchanging them (Ck --Ck'<0), output the string "NO GAME" (without quotation marks).
|
| 14 |
+
<image>
|
| 15 |
+
When the cards arranged by the teacher are 7, 2, 3, 5. By exchanging 7 and 3 at this time, the student gets a maximum of 35 -15 = 20 grade points.
|
| 16 |
+
|
| 17 |
+
Hint
|
| 18 |
+
|
| 19 |
+
In the sample, C2'= 35, and no matter which two sheets are rearranged from here, the maximum value of C2 does not exceed 35. Therefore, students can get a maximum of 0 grades.
|
| 20 |
+
|
| 21 |
+
Constraints
|
| 22 |
+
|
| 23 |
+
* All inputs are integers
|
| 24 |
+
* 2 ≤ n ≤ 100
|
| 25 |
+
* 1 ≤ k ≤ 5
|
| 26 |
+
* k ≤ n
|
| 27 |
+
* 1 ≤ ci ≤ 10 (1 ≤ i ≤ n)
|
| 28 |
+
* The number of test cases does not exceed 100.
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
The input consists of multiple test cases. One test case follows the format below.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
n k
|
| 36 |
+
c1
|
| 37 |
+
c2
|
| 38 |
+
c3
|
| 39 |
+
...
|
| 40 |
+
cn
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
n is the number of cards the teacher arranges, and k is the integer to declare. Also, ci (1 ≤ i ≤ n) indicates the number written on the card. Also, suppose that the teacher pastes it on the blackboard sideways in this order. The end of the input is indicated by a line where two 0s are separated by a single space.
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
Print the maximum grade or string "NO GAME" (without quotation marks) that students will get on one line for each test case.
|
| 48 |
+
|
| 49 |
+
Example
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
4 2
|
| 54 |
+
2
|
| 55 |
+
3
|
| 56 |
+
7
|
| 57 |
+
5
|
| 58 |
+
0 0
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
0
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 0
|
| 67 |
+
- **Problem Index**:
|
| 68 |
+
- **Points**: 0.0
|
| 69 |
+
- **Rating**: 0
|
| 70 |
+
- **Tags**:
|
| 71 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 72 |
+
- **Memory Limit**: 134217728 bytes
|
| 73 |
+
|
| 74 |
+
## Task
|
| 75 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0624/instruction.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02398 How Many Divisors?
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
How Many Divisors?
|
| 5 |
+
|
| 6 |
+
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* 1 ≤ a, b, c ≤ 10000
|
| 11 |
+
* a ≤ b
|
| 12 |
+
|
| 13 |
+
Input
|
| 14 |
+
|
| 15 |
+
Three integers a, b and c are given in a line separated by a single space.
|
| 16 |
+
|
| 17 |
+
Output
|
| 18 |
+
|
| 19 |
+
Print the number of divisors in a line.
|
| 20 |
+
|
| 21 |
+
Example
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
5 14 80
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
3
|
| 31 |
+
|
| 32 |
+
## Contest Information
|
| 33 |
+
- **Contest ID**: 0
|
| 34 |
+
- **Problem Index**:
|
| 35 |
+
- **Points**: 0.0
|
| 36 |
+
- **Rating**: 0
|
| 37 |
+
- **Tags**:
|
| 38 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 39 |
+
- **Memory Limit**: 134217728 bytes
|
| 40 |
+
|
| 41 |
+
## Task
|
| 42 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0630/instruction.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# traveler
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Chef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be no road between some two consecutive cities in the route. Also note that Chef hates to visit the same city twice during his travel. Even the last city should differ from the first. Two consecutive cities in the route should also be different. So you need to check these conditions for the given routes too.
|
| 5 |
+
|
| 6 |
+
You will be given the list of all cities and all roads between them with their lengths. All roads are one-way. Also you will be given the list of all travel routes that Chef plans. For each route you should check whether it is correct and find its length in this case.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Input
|
| 10 |
+
|
| 11 |
+
The first line contains positive integer N, the number of cities. The second line contains space separated list of N strings, city names. All city names are distinct.
|
| 12 |
+
|
| 13 |
+
The third line contains non-negative integer M, the number of available roads. Each of the next M lines describes one road and contains names C1 and C2 of two cities followed by the positive integer D, the length of the one-way road that connects C1 with C2. It is guaranteed that C1 and C2 will be correct names of two different cities from the list of N cities given in the second line of the input file. For each pair of different cities there is at most one road in each direction and each road will be described exactly once in the input file.
|
| 14 |
+
|
| 15 |
+
Next line contains positive integer T, the number of travel routes planned by the Chef. Each of the next T lines contains positive integer K followed by K strings, names of cities of the current route. Cities are given in order in which Chef will visit them during his travel.
|
| 16 |
+
|
| 17 |
+
All strings in the input file composed only of lowercase, uppercase letters of the English alphabet and hyphens. Each string is non-empty and has length at most 20. If some line of the input file contains more then one element than consecutive elements of this line are separated by exactly one space. Each line of the input file has no leading or trailing spaces.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
For each travel route from the input file output a single line containing word ERROR if the route is incorrect and its length otherwise.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Constraints
|
| 25 |
+
|
| 26 |
+
1 <= N <= 50
|
| 27 |
+
|
| 28 |
+
0 <= M <= N * (N - 1)
|
| 29 |
+
|
| 30 |
+
1 <= D <= 20000
|
| 31 |
+
|
| 32 |
+
1 <= T <= 50
|
| 33 |
+
|
| 34 |
+
1 <= K <= 50
|
| 35 |
+
|
| 36 |
+
1 <= length of each string <= 20
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Example
|
| 40 |
+
|
| 41 |
+
Input:
|
| 42 |
+
5
|
| 43 |
+
Donetsk Kiev New-York Miami Hollywood
|
| 44 |
+
9
|
| 45 |
+
Donetsk Kiev 560
|
| 46 |
+
Kiev New-York 7507
|
| 47 |
+
New-York Miami 1764
|
| 48 |
+
Miami Hollywood 28
|
| 49 |
+
Hollywood Miami 30
|
| 50 |
+
Miami New-York 1764
|
| 51 |
+
Kiev Donetsk 550
|
| 52 |
+
Hollywood New-York 1736
|
| 53 |
+
New-York Hollywood 1738
|
| 54 |
+
13
|
| 55 |
+
5 Donetsk Kiev New-York Miami Hollywood
|
| 56 |
+
5 Hollywood Miami New-York Kiev Donetsk
|
| 57 |
+
3 Donetsk Kiev Donetsk
|
| 58 |
+
2 Kyiv New-York
|
| 59 |
+
3 New-York Hollywood Miami
|
| 60 |
+
2 New-York Miami
|
| 61 |
+
3 Hollywood New-York Miami
|
| 62 |
+
4 Donetsk Kiev Miami Hollywood
|
| 63 |
+
2 Donetsk Hollywood
|
| 64 |
+
1 Donetsk
|
| 65 |
+
2 Mumbai Deli
|
| 66 |
+
6 Donetsk Kiev New-York Miami Hollywood New-York
|
| 67 |
+
2 Miami Miami
|
| 68 |
+
|
| 69 |
+
Output:
|
| 70 |
+
9859
|
| 71 |
+
ERROR
|
| 72 |
+
ERROR
|
| 73 |
+
ERROR
|
| 74 |
+
1768
|
| 75 |
+
1764
|
| 76 |
+
3500
|
| 77 |
+
ERROR
|
| 78 |
+
ERROR
|
| 79 |
+
0
|
| 80 |
+
ERROR
|
| 81 |
+
ERROR
|
| 82 |
+
ERROR
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Explanation
|
| 86 |
+
The 2^nd route is incorrect since there is no road from New-York to Kiev. Note however that inverse road from Kiev to New-York exists.
|
| 87 |
+
The 3^rd route is incorrect since the first city coincides with the last one.
|
| 88 |
+
The 4^th route is incorrect since there is no city with name Kyiv (Probably Chef means Kiev but he misspells this word).
|
| 89 |
+
The 8^th route is incorrect since there is no road from Miami to Kiev.
|
| 90 |
+
The 9^th route is incorrect since there is no road from Donetsk to Hollywood.
|
| 91 |
+
The 10^th route is correct. Note that a route composed of exactly one city is always correct provided that city name is written correctly.
|
| 92 |
+
The 11^th route is incorrect since there is no cities with names Mumbai and Deli. (Probably Chef is not so good in geography :))
|
| 93 |
+
The 12^th route is incorrect since city New-York is visited twice.
|
| 94 |
+
Finally the 13^th route is incorrect since we have equal consecutive cities.
|
| 95 |
+
|
| 96 |
+
## Contest Information
|
| 97 |
+
- **Contest ID**: 0
|
| 98 |
+
- **Problem Index**:
|
| 99 |
+
- **Points**: 0.0
|
| 100 |
+
- **Rating**: 0
|
| 101 |
+
- **Tags**: None
|
| 102 |
+
- **Time Limit**: None seconds
|
| 103 |
+
- **Memory Limit**: 0 bytes
|
| 104 |
+
|
| 105 |
+
## Task
|
| 106 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0637/instruction.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1152_A. Neko Finds Grapes
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.
|
| 5 |
+
|
| 6 |
+
The j-th key can be used to unlock the i-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, a_i + b_j ≡ 1 \pmod{2}. One key can be used to open at most one chest, and one chest can be opened at most once.
|
| 7 |
+
|
| 8 |
+
Find the maximum number of chests Neko can open.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains integers n and m (1 ≤ n, m ≤ 10^5) — the number of chests and the number of keys.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the numbers written on the treasure chests.
|
| 15 |
+
|
| 16 |
+
The third line contains m integers b_1, b_2, …, b_m (1 ≤ b_i ≤ 10^9) — the numbers written on the keys.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print the maximum number of chests you can open.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
5 4
|
| 28 |
+
9 14 6 2 11
|
| 29 |
+
8 4 7 20
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
3
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
5 1
|
| 41 |
+
2 4 6 8 10
|
| 42 |
+
5
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
1
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
1 4
|
| 54 |
+
10
|
| 55 |
+
20 30 40 50
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
0
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
In the first example, one possible way to unlock 3 chests is as follows:
|
| 66 |
+
|
| 67 |
+
* Use first key to unlock the fifth chest,
|
| 68 |
+
* Use third key to unlock the second chest,
|
| 69 |
+
* Use fourth key to unlock the first chest.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
In the second example, you can use the only key to unlock any single chest (note that one key can't be used twice).
|
| 74 |
+
|
| 75 |
+
In the third example, no key can unlock the given chest.
|
| 76 |
+
|
| 77 |
+
## Contest Information
|
| 78 |
+
- **Contest ID**: 1152
|
| 79 |
+
- **Problem Index**: A
|
| 80 |
+
- **Points**: 500.0
|
| 81 |
+
- **Rating**: 800
|
| 82 |
+
- **Tags**: greedy, implementation, math
|
| 83 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 84 |
+
- **Memory Limit**: 256000000 bytes
|
| 85 |
+
|
| 86 |
+
## Task
|
| 87 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0639/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1191_C. Tokitsukaze and Discard Items
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
|
| 5 |
+
|
| 6 |
+
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty.
|
| 7 |
+
|
| 8 |
+
Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.
|
| 9 |
+
|
| 10 |
+
<image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10.
|
| 11 |
+
|
| 12 |
+
Tokitsukaze wants to know the number of operations she would do in total.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains three integers n, m and k (1 ≤ n ≤ 10^{18}, 1 ≤ m ≤ 10^5, 1 ≤ m, k ≤ n) — the number of items, the number of special items to be discarded and the number of positions in each page.
|
| 17 |
+
|
| 18 |
+
The second line contains m distinct integers p_1, p_2, …, p_m (1 ≤ p_1 < p_2 < … < p_m ≤ n) — the indices of special items which should be discarded.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print a single integer — the number of operations that Tokitsukaze would do in total.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
10 4 5
|
| 30 |
+
3 5 7 10
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
13 4 5
|
| 43 |
+
7 8 9 10
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
1
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
For the first example:
|
| 54 |
+
|
| 55 |
+
* In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5;
|
| 56 |
+
* In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7;
|
| 57 |
+
* In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 1191
|
| 65 |
+
- **Problem Index**: C
|
| 66 |
+
- **Points**: 500.0
|
| 67 |
+
- **Rating**: 1400
|
| 68 |
+
- **Tags**: implementation, two pointers
|
| 69 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 70 |
+
- **Memory Limit**: 256000000 bytes
|
| 71 |
+
|
| 72 |
+
## Task
|
| 73 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0648/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1379_F1. Chess Strikes Back (easy version)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Note that the difference between easy and hard versions is that in hard version unavailable cells can become available again and in easy version can't. You can make hacks only if all versions are solved.
|
| 5 |
+
|
| 6 |
+
Ildar and Ivan are tired of chess, but they really like the chessboard, so they invented a new game. The field is a chessboard 2n × 2m: it has 2n rows, 2m columns, and the cell in row i and column j is colored white if i+j is even, and is colored black otherwise.
|
| 7 |
+
|
| 8 |
+
The game proceeds as follows: Ildar marks some of the white cells of the chessboard as unavailable, and asks Ivan to place n × m kings on the remaining white cells in such way, so that there are no kings attacking each other. A king can attack another king if they are located in the adjacent cells, sharing an edge or a corner.
|
| 9 |
+
|
| 10 |
+
Ildar would like to explore different combinations of cells. Initially all cells are marked as available, and then he has q queries. In each query he marks a cell as unavailable. After each query he would like to know whether it is possible to place the kings on the available cells in a desired way. Please help him!
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of input contains three integers n, m, q (1 ≤ n, m, q ≤ 200 000) — the size of the board and the number of queries.
|
| 15 |
+
|
| 16 |
+
q lines follow, each of them contains a description of a query: two integers i and j, denoting a white cell (i, j) on the board (1 ≤ i ≤ 2n, 1 ≤ j ≤ 2m, i + j is even) that becomes unavailable. It's guaranteed, that each cell (i, j) appears in input at most once.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Output q lines, i-th line should contain answer for a board after i queries of Ildar. This line should contain "YES" if it is possible to place the kings on the available cells in the desired way, or "NO" otherwise.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
1 3 3
|
| 28 |
+
1 1
|
| 29 |
+
1 5
|
| 30 |
+
2 4
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
YES
|
| 37 |
+
YES
|
| 38 |
+
NO
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
3 2 7
|
| 45 |
+
4 2
|
| 46 |
+
6 4
|
| 47 |
+
1 3
|
| 48 |
+
2 2
|
| 49 |
+
2 4
|
| 50 |
+
4 4
|
| 51 |
+
3 1
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
YES
|
| 58 |
+
YES
|
| 59 |
+
NO
|
| 60 |
+
NO
|
| 61 |
+
NO
|
| 62 |
+
NO
|
| 63 |
+
NO
|
| 64 |
+
|
| 65 |
+
Note
|
| 66 |
+
|
| 67 |
+
In the first example case after the second query only cells (1, 1) and (1, 5) are unavailable. Then Ivan can place three kings on cells (2, 2), (2, 4) and (2, 6).
|
| 68 |
+
|
| 69 |
+
After the third query three cells (1, 1), (1, 5) and (2, 4) are unavailable, so there remain only 3 available cells: (2, 2), (1, 3) and (2, 6). Ivan can not put 3 kings on those cells, because kings on cells (2, 2) and (1, 3) attack each other, since these cells share a corner.
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 1379
|
| 73 |
+
- **Problem Index**: F1
|
| 74 |
+
- **Points**: 1500.0
|
| 75 |
+
- **Rating**: 2700
|
| 76 |
+
- **Tags**: binary search, data structures
|
| 77 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 78 |
+
- **Memory Limit**: 512000000 bytes
|
| 79 |
+
|
| 80 |
+
## Task
|
| 81 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|