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-0012/instruction.md +112 -0
- code_contests-0015/instruction.md +82 -0
- code_contests-0023/instruction.md +94 -0
- code_contests-0024/instruction.md +63 -0
- code_contests-0040/instruction.md +53 -0
- code_contests-0041/instruction.md +54 -0
- code_contests-0046/instruction.md +73 -0
- code_contests-0071/instruction.md +44 -0
- code_contests-0076/instruction.md +67 -0
- code_contests-0077/instruction.md +101 -0
- code_contests-0079/instruction.md +69 -0
- code_contests-0082/instruction.md +141 -0
- code_contests-0085/instruction.md +106 -0
- code_contests-0133/instruction.md +65 -0
- code_contests-0211/instruction.md +53 -0
- code_contests-0216/instruction.md +121 -0
- code_contests-0218/instruction.md +107 -0
- code_contests-0219/instruction.md +93 -0
- code_contests-0220/instruction.md +104 -0
- code_contests-0229/instruction.md +105 -0
- code_contests-0242/instruction.md +55 -0
- code_contests-0243/instruction.md +53 -0
- code_contests-0244/instruction.md +57 -0
- code_contests-0245/instruction.md +67 -0
- code_contests-0272/instruction.md +101 -0
- code_contests-0273/instruction.md +81 -0
- code_contests-0275/instruction.md +48 -0
- code_contests-0280/instruction.md +48 -0
- code_contests-0286/instruction.md +57 -0
- code_contests-0287/instruction.md +110 -0
- code_contests-0288/instruction.md +86 -0
- code_contests-0289/instruction.md +76 -0
- code_contests-0339/instruction.md +81 -0
- code_contests-0412/instruction.md +51 -0
- code_contests-0413/instruction.md +97 -0
- code_contests-0415/instruction.md +78 -0
- code_contests-0422/instruction.md +51 -0
- code_contests-0425/instruction.md +80 -0
- code_contests-0440/instruction.md +105 -0
- code_contests-0449/instruction.md +52 -0
- code_contests-0471/instruction.md +64 -0
- code_contests-0476/instruction.md +75 -0
- code_contests-0477/instruction.md +88 -0
- code_contests-0478/instruction.md +112 -0
- code_contests-0482/instruction.md +71 -0
- code_contests-0483/instruction.md +41 -0
- code_contests-0484/instruction.md +65 -0
- code_contests-0485/instruction.md +92 -0
- code_contests-0550/instruction.md +105 -0
- code_contests-0610/instruction.md +74 -0
code_contests-0012/instruction.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1149_E. Election Promises
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes.
|
| 5 |
+
|
| 6 |
+
There are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles — it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax.
|
| 7 |
+
|
| 8 |
+
Parties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles.
|
| 9 |
+
|
| 10 |
+
The first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves?
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of the input contains two integers n, m (1 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000) — the number of cities and roads in Byteland.
|
| 15 |
+
|
| 16 |
+
The next line contains n space-separated integers h_1, h_2, ..., h_n (0 ≤ h_i ≤ 10^9); h_i denotes the amount of taxes paid in the i-th city.
|
| 17 |
+
|
| 18 |
+
Each of the following m lines contains two integers (1 ≤ u, v ≤ n, u ≠ v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities.
|
| 19 |
+
|
| 20 |
+
We can show that the conventions cannot be held indefinitely for any correct test case.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
If Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 ≤ h'_i ≤ 2 ⋅ 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 ⋅ 10^{18} bourles.
|
| 25 |
+
|
| 26 |
+
If the party cannot assure their victory, output LOSE in the first and only line of the output.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
4 2
|
| 34 |
+
2 1 1 5
|
| 35 |
+
1 2
|
| 36 |
+
3 4
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
WIN
|
| 43 |
+
1 5 1 5
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
4 2
|
| 50 |
+
1 5 1 5
|
| 51 |
+
1 2
|
| 52 |
+
3 4
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
LOSE
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Input
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
3 3
|
| 65 |
+
314 159 265
|
| 66 |
+
1 2
|
| 67 |
+
1 3
|
| 68 |
+
3 2
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Output
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
WIN
|
| 75 |
+
0 0 0
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Input
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
6 4
|
| 82 |
+
2 2 5 5 6 6
|
| 83 |
+
1 3
|
| 84 |
+
2 4
|
| 85 |
+
3 5
|
| 86 |
+
4 6
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
Output
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
LOSE
|
| 93 |
+
|
| 94 |
+
Note
|
| 95 |
+
|
| 96 |
+
In the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally.
|
| 97 |
+
|
| 98 |
+
The second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win.
|
| 99 |
+
|
| 100 |
+
In the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.
|
| 101 |
+
|
| 102 |
+
## Contest Information
|
| 103 |
+
- **Contest ID**: 1149
|
| 104 |
+
- **Problem Index**: E
|
| 105 |
+
- **Points**: 2750.0
|
| 106 |
+
- **Rating**: 3200
|
| 107 |
+
- **Tags**: games, graphs
|
| 108 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 109 |
+
- **Memory Limit**: 256000000 bytes
|
| 110 |
+
|
| 111 |
+
## Task
|
| 112 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0015/instruction.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1208_D. Restore Permutation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4].
|
| 5 |
+
|
| 6 |
+
There is a hidden permutation of length n.
|
| 7 |
+
|
| 8 |
+
For each index i, you are given s_{i}, which equals to the sum of all p_{j} such that j < i and p_{j} < p_{i}. In other words, s_i is the sum of elements before the i-th element that are smaller than the i-th element.
|
| 9 |
+
|
| 10 |
+
Your task is to restore the permutation.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the size of the permutation.
|
| 15 |
+
|
| 16 |
+
The second line contains n integers s_{1}, s_{2}, …, s_{n} (0 ≤ s_{i} ≤ (n(n-1))/(2)).
|
| 17 |
+
|
| 18 |
+
It is guaranteed that the array s corresponds to a valid permutation of length n.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print n integers p_{1}, p_{2}, …, p_{n} — the elements of the restored permutation. We can show that the answer is always unique.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
3
|
| 30 |
+
0 0 0
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
3 2 1
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
2
|
| 43 |
+
0 1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
1 2
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
5
|
| 56 |
+
0 1 1 1 10
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
1 4 3 2 5
|
| 63 |
+
|
| 64 |
+
Note
|
| 65 |
+
|
| 66 |
+
In the first example for each i there is no index j satisfying both conditions, hence s_i are always 0.
|
| 67 |
+
|
| 68 |
+
In the second example for i = 2 it happens that j = 1 satisfies the conditions, so s_2 = p_1.
|
| 69 |
+
|
| 70 |
+
In the third example for i = 2, 3, 4 only j = 1 satisfies the conditions, so s_2 = s_3 = s_4 = 1. For i = 5 all j = 1, 2, 3, 4 are possible, so s_5 = p_1 + p_2 + p_3 + p_4 = 10.
|
| 71 |
+
|
| 72 |
+
## Contest Information
|
| 73 |
+
- **Contest ID**: 1208
|
| 74 |
+
- **Problem Index**: D
|
| 75 |
+
- **Points**: 2000.0
|
| 76 |
+
- **Rating**: 1900
|
| 77 |
+
- **Tags**: binary search, data structures, greedy, implementation
|
| 78 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 79 |
+
- **Memory Limit**: 256000000 bytes
|
| 80 |
+
|
| 81 |
+
## Task
|
| 82 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0023/instruction.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1374_E1. Reading Books (easy version)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
|
| 5 |
+
|
| 6 |
+
Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster.
|
| 7 |
+
|
| 8 |
+
There are n books in the family library. The i-th book is described by three integers: t_i — the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not).
|
| 9 |
+
|
| 10 |
+
So they need to choose some books from the given n books in such a way that:
|
| 11 |
+
|
| 12 |
+
* Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set;
|
| 13 |
+
* the total reading time of these books is minimized (they are children and want to play and joy as soon a possible).
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set.
|
| 18 |
+
|
| 19 |
+
Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set.
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5).
|
| 24 |
+
|
| 25 |
+
The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≤ t_i ≤ 10^4, 0 ≤ a_i, b_i ≤ 1), where:
|
| 26 |
+
|
| 27 |
+
* t_i — the amount of time required for reading the i-th book;
|
| 28 |
+
* a_i equals 1 if Alice likes the i-th book and 0 otherwise;
|
| 29 |
+
* b_i equals 1 if Bob likes the i-th book and 0 otherwise.
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
If there is no solution, print only one integer -1. Otherwise print one integer T — the minimum total reading time of the suitable set of books.
|
| 34 |
+
|
| 35 |
+
Examples
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
8 4
|
| 40 |
+
7 1 1
|
| 41 |
+
2 1 1
|
| 42 |
+
4 0 1
|
| 43 |
+
8 1 1
|
| 44 |
+
1 0 1
|
| 45 |
+
1 1 1
|
| 46 |
+
1 0 1
|
| 47 |
+
3 0 0
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
18
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Input
|
| 56 |
+
|
| 57 |
+
5 2
|
| 58 |
+
6 0 0
|
| 59 |
+
9 0 0
|
| 60 |
+
1 0 1
|
| 61 |
+
2 1 1
|
| 62 |
+
5 1 0
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Output
|
| 66 |
+
|
| 67 |
+
8
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Input
|
| 71 |
+
|
| 72 |
+
5 3
|
| 73 |
+
3 0 0
|
| 74 |
+
2 1 0
|
| 75 |
+
3 1 0
|
| 76 |
+
5 0 1
|
| 77 |
+
3 0 1
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Output
|
| 81 |
+
|
| 82 |
+
-1
|
| 83 |
+
|
| 84 |
+
## Contest Information
|
| 85 |
+
- **Contest ID**: 1374
|
| 86 |
+
- **Problem Index**: E1
|
| 87 |
+
- **Points**: 0.0
|
| 88 |
+
- **Rating**: 1600
|
| 89 |
+
- **Tags**: data structures, greedy, sortings
|
| 90 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 91 |
+
- **Memory Limit**: 256000000 bytes
|
| 92 |
+
|
| 93 |
+
## Task
|
| 94 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0024/instruction.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1398_A. Bad Triangle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≤ a_{i + 1}).
|
| 5 |
+
|
| 6 |
+
Find three indices i, j, k such that 1 ≤ i < j < k ≤ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
|
| 11 |
+
|
| 12 |
+
The first line of each test case contains one integer n (3 ≤ n ≤ 5 ⋅ 10^4) — the length of the array a.
|
| 13 |
+
|
| 14 |
+
The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 10^9; a_{i - 1} ≤ a_i) — the array a.
|
| 15 |
+
|
| 16 |
+
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
For each test case print the answer to it in one line.
|
| 21 |
+
|
| 22 |
+
If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them.
|
| 23 |
+
|
| 24 |
+
Otherwise, print -1.
|
| 25 |
+
|
| 26 |
+
Example
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
7
|
| 33 |
+
4 6 11 11 15 18 20
|
| 34 |
+
4
|
| 35 |
+
10 10 10 11
|
| 36 |
+
3
|
| 37 |
+
1 1 1000000000
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
2 3 6
|
| 44 |
+
-1
|
| 45 |
+
1 2 3
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer.
|
| 50 |
+
|
| 51 |
+
In the second test case you always can construct a non-degenerate triangle.
|
| 52 |
+
|
| 53 |
+
## Contest Information
|
| 54 |
+
- **Contest ID**: 1398
|
| 55 |
+
- **Problem Index**: A
|
| 56 |
+
- **Points**: 0.0
|
| 57 |
+
- **Rating**: 800
|
| 58 |
+
- **Tags**: geometry, math
|
| 59 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 60 |
+
- **Memory Limit**: 256000000 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-0040/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 379_A. New Year Candles
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
|
| 5 |
+
|
| 6 |
+
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.
|
| 7 |
+
|
| 8 |
+
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print a single integer — the number of hours Vasily can light up the room for.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
4 2
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
7
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
6 3
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
8
|
| 38 |
+
|
| 39 |
+
Note
|
| 40 |
+
|
| 41 |
+
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 379
|
| 45 |
+
- **Problem Index**: A
|
| 46 |
+
- **Points**: 500.0
|
| 47 |
+
- **Rating**: 1000
|
| 48 |
+
- **Tags**: implementation
|
| 49 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 50 |
+
- **Memory Limit**: 256000000 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-0041/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 39_H. Multiplication Table
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix k.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first line contains a single integer k (2 ≤ k ≤ 10) — the radix of the system.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output the multiplication table for the system of notations with the radix k. The table must contain k - 1 rows and k - 1 columns. The element on the crossing of the i-th row and the j-th column is equal to the product of i and j in the system of notations with the radix k. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity).
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
10
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
1 2 3 4 5 6 7 8 9
|
| 24 |
+
2 4 6 8 10 12 14 16 18
|
| 25 |
+
3 6 9 12 15 18 21 24 27
|
| 26 |
+
4 8 12 16 20 24 28 32 36
|
| 27 |
+
5 10 15 20 25 30 35 40 45
|
| 28 |
+
6 12 18 24 30 36 42 48 54
|
| 29 |
+
7 14 21 28 35 42 49 56 63
|
| 30 |
+
8 16 24 32 40 48 56 64 72
|
| 31 |
+
9 18 27 36 45 54 63 72 81
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
1 2
|
| 42 |
+
2 11
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 39
|
| 46 |
+
- **Problem Index**: H
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 1300
|
| 49 |
+
- **Tags**: implementation
|
| 50 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 64000000 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-0046/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 519_B. A and B and Compilation Errors
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A and B are preparing themselves for programming contests.
|
| 5 |
+
|
| 6 |
+
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
|
| 7 |
+
|
| 8 |
+
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
|
| 9 |
+
|
| 10 |
+
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
|
| 11 |
+
|
| 12 |
+
Can you help B find out exactly what two errors he corrected?
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.
|
| 17 |
+
|
| 18 |
+
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.
|
| 19 |
+
|
| 20 |
+
The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
|
| 21 |
+
|
| 22 |
+
The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
5
|
| 33 |
+
1 5 8 123 7
|
| 34 |
+
123 7 5 1
|
| 35 |
+
5 1 7
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
8
|
| 41 |
+
123
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
6
|
| 47 |
+
1 4 3 3 5 7
|
| 48 |
+
3 7 5 4 3
|
| 49 |
+
4 3 7 5
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
1
|
| 55 |
+
3
|
| 56 |
+
|
| 57 |
+
Note
|
| 58 |
+
|
| 59 |
+
In the first test sample B first corrects the error number 8, then the error number 123.
|
| 60 |
+
|
| 61 |
+
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 519
|
| 65 |
+
- **Problem Index**: B
|
| 66 |
+
- **Points**: 1000.0
|
| 67 |
+
- **Rating**: 1100
|
| 68 |
+
- **Tags**: data structures, implementation, sortings
|
| 69 |
+
- **Time Limit**: {'seconds': 2, '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-0071/instruction.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# list-sort
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A certain business maintains a list of all its customers' names. The list is arranged in order of importance, with the last customer in the list being the most important. Now, he want to create a new list sorted alphabetically according to customers' last names, but among customers with the same last name he want the more important ones to appear earlier in the new list. Alphabetical order (and equality of last names) should not be case sensitive.
|
| 5 |
+
|
| 6 |
+
Input:-
|
| 7 |
+
First line contains no. of test cases and first line of each test case contains n i.e. no. of elements and next n lines contains contains a name.
|
| 8 |
+
|
| 9 |
+
Output:- Print the new list with each element in a new line.
|
| 10 |
+
|
| 11 |
+
SAMPLE INPUT
|
| 12 |
+
2
|
| 13 |
+
5
|
| 14 |
+
Tom Jones
|
| 15 |
+
ADAMS
|
| 16 |
+
BOB ADAMS
|
| 17 |
+
Tom Jones
|
| 18 |
+
STEVE jONeS
|
| 19 |
+
3
|
| 20 |
+
Trudy
|
| 21 |
+
Trudy
|
| 22 |
+
TRUDY
|
| 23 |
+
|
| 24 |
+
SAMPLE OUTPUT
|
| 25 |
+
BOB ADAMS
|
| 26 |
+
ADAMS
|
| 27 |
+
STEVE jONeS
|
| 28 |
+
Tom Jones
|
| 29 |
+
Tom Jones
|
| 30 |
+
TRUDY
|
| 31 |
+
Trudy
|
| 32 |
+
Trudy
|
| 33 |
+
|
| 34 |
+
## Contest Information
|
| 35 |
+
- **Contest ID**: 0
|
| 36 |
+
- **Problem Index**:
|
| 37 |
+
- **Points**: 0.0
|
| 38 |
+
- **Rating**: 0
|
| 39 |
+
- **Tags**: None
|
| 40 |
+
- **Time Limit**: None seconds
|
| 41 |
+
- **Memory Limit**: 0 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-0076/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vowel
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Rakesh have learn about vowel in school and is given an assignment by his teacher in which he has to list all vowel together from the word's given to him,but he is busy in watching cricket match and want your help to solve the assignment.
|
| 5 |
+
|
| 6 |
+
5 vowel (a,e,i,o,u) and you should also take care of uppercase vowel (A,E,I,O,U)
|
| 7 |
+
INPUT
|
| 8 |
+
|
| 9 |
+
T testcase ( 1< t <10 )
|
| 10 |
+
|
| 11 |
+
then there will be T words
|
| 12 |
+
|
| 13 |
+
OUTPUT
|
| 14 |
+
|
| 15 |
+
List of all vowel present in the word
|
| 16 |
+
|
| 17 |
+
All vowel should be listed as they are found in the word
|
| 18 |
+
|
| 19 |
+
In case if there is no vowel you have to print "No"
|
| 20 |
+
|
| 21 |
+
SAMPLE INPUT
|
| 22 |
+
3
|
| 23 |
+
SdfgAe
|
| 24 |
+
Out
|
| 25 |
+
Get
|
| 26 |
+
|
| 27 |
+
SAMPLE OUTPUT
|
| 28 |
+
Ae
|
| 29 |
+
Ou
|
| 30 |
+
e
|
| 31 |
+
|
| 32 |
+
Explanation
|
| 33 |
+
|
| 34 |
+
Here Testcase T value is 3
|
| 35 |
+
(T=3) which mean there will be three word to check for.
|
| 36 |
+
|
| 37 |
+
INPUT
|
| 38 |
+
|
| 39 |
+
3
|
| 40 |
+
|
| 41 |
+
SdfgAe
|
| 42 |
+
|
| 43 |
+
Out
|
| 44 |
+
|
| 45 |
+
Get
|
| 46 |
+
|
| 47 |
+
OUTPUT
|
| 48 |
+
|
| 49 |
+
Ae
|
| 50 |
+
|
| 51 |
+
Ou
|
| 52 |
+
|
| 53 |
+
e
|
| 54 |
+
|
| 55 |
+
Here in output order of vowels is same as they occur in word
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 0
|
| 59 |
+
- **Problem Index**:
|
| 60 |
+
- **Points**: 0.0
|
| 61 |
+
- **Rating**: 0
|
| 62 |
+
- **Tags**: None
|
| 63 |
+
- **Time Limit**: None seconds
|
| 64 |
+
- **Memory Limit**: 0 bytes
|
| 65 |
+
|
| 66 |
+
## Task
|
| 67 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0077/instruction.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02613 AtCoder Beginner Contest 173 - Judge Status Summary
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.
|
| 5 |
+
|
| 6 |
+
The problem has N test cases.
|
| 7 |
+
|
| 8 |
+
For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
|
| 9 |
+
|
| 10 |
+
See the Output section for the output format.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 \leq N \leq 10^5
|
| 15 |
+
* S_i is `AC`, `WA`, `TLE`, or `RE`.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
Input is given from Standard Input in the following format:
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
N
|
| 23 |
+
S_1
|
| 24 |
+
\vdots
|
| 25 |
+
S_N
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
AC x C_0
|
| 34 |
+
WA x C_1
|
| 35 |
+
TLE x C_2
|
| 36 |
+
RE x C_3
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
AC x C_0
|
| 44 |
+
WA x C_1
|
| 45 |
+
TLE x C_2
|
| 46 |
+
RE x C_3
|
| 47 |
+
|
| 48 |
+
Examples
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
6
|
| 53 |
+
AC
|
| 54 |
+
TLE
|
| 55 |
+
AC
|
| 56 |
+
AC
|
| 57 |
+
WA
|
| 58 |
+
TLE
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
AC x 3
|
| 64 |
+
WA x 1
|
| 65 |
+
TLE x 2
|
| 66 |
+
RE x 0
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Input
|
| 70 |
+
|
| 71 |
+
10
|
| 72 |
+
AC
|
| 73 |
+
AC
|
| 74 |
+
AC
|
| 75 |
+
AC
|
| 76 |
+
AC
|
| 77 |
+
AC
|
| 78 |
+
AC
|
| 79 |
+
AC
|
| 80 |
+
AC
|
| 81 |
+
AC
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
Output
|
| 85 |
+
|
| 86 |
+
AC x 10
|
| 87 |
+
WA x 0
|
| 88 |
+
TLE x 0
|
| 89 |
+
RE x 0
|
| 90 |
+
|
| 91 |
+
## Contest Information
|
| 92 |
+
- **Contest ID**: 0
|
| 93 |
+
- **Problem Index**:
|
| 94 |
+
- **Points**: 0.0
|
| 95 |
+
- **Rating**: 0
|
| 96 |
+
- **Tags**:
|
| 97 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 98 |
+
- **Memory Limit**: 1073741824 bytes
|
| 99 |
+
|
| 100 |
+
## Task
|
| 101 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0079/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02879 AtCoder Beginner Contest 144 - 9x9
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.
|
| 5 |
+
|
| 6 |
+
Given are two integers A and B.
|
| 7 |
+
|
| 8 |
+
If Takahashi can calculate A \times B, print the result; if he cannot, print `-1` instead.
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
|
| 12 |
+
* 1 \leq A \leq 20
|
| 13 |
+
* 1 \leq B \leq 20
|
| 14 |
+
* All values in input are integers.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
Input is given from Standard Input in the following format:
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
A B
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
If Takahashi can calculate A \times B, print the result; if he cannot, print `-1`.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
2 5
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
5 10
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
-1
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
9 9
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
81
|
| 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**: 1073741824 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-0082/instruction.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03297 AtCoder Grand Contest 026 - rng_10s
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Ringo Mart, a convenience store, sells apple juice.
|
| 5 |
+
|
| 6 |
+
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
|
| 7 |
+
|
| 8 |
+
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
|
| 9 |
+
|
| 10 |
+
Note that each test case in this problem consists of T queries.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 \leq T \leq 300
|
| 15 |
+
* 1 \leq A, B, C, D \leq 10^{18}
|
| 16 |
+
* All values in input are integers.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
Input is given from Standard Input in the following format:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
T
|
| 24 |
+
A_1 B_1 C_1 D_1
|
| 25 |
+
A_2 B_2 C_2 D_2
|
| 26 |
+
:
|
| 27 |
+
A_T B_T C_T D_T
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
14
|
| 41 |
+
9 7 5 9
|
| 42 |
+
9 7 6 9
|
| 43 |
+
14 10 7 12
|
| 44 |
+
14 10 8 12
|
| 45 |
+
14 10 9 12
|
| 46 |
+
14 10 7 11
|
| 47 |
+
14 10 8 11
|
| 48 |
+
14 10 9 11
|
| 49 |
+
9 10 5 10
|
| 50 |
+
10 10 5 10
|
| 51 |
+
11 10 5 10
|
| 52 |
+
16 10 5 10
|
| 53 |
+
1000000000000000000 17 14 999999999999999985
|
| 54 |
+
1000000000000000000 17 15 999999999999999985
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
No
|
| 60 |
+
Yes
|
| 61 |
+
No
|
| 62 |
+
Yes
|
| 63 |
+
Yes
|
| 64 |
+
No
|
| 65 |
+
No
|
| 66 |
+
Yes
|
| 67 |
+
No
|
| 68 |
+
Yes
|
| 69 |
+
Yes
|
| 70 |
+
No
|
| 71 |
+
No
|
| 72 |
+
Yes
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Input
|
| 76 |
+
|
| 77 |
+
24
|
| 78 |
+
1 2 3 4
|
| 79 |
+
1 2 4 3
|
| 80 |
+
1 3 2 4
|
| 81 |
+
1 3 4 2
|
| 82 |
+
1 4 2 3
|
| 83 |
+
1 4 3 2
|
| 84 |
+
2 1 3 4
|
| 85 |
+
2 1 4 3
|
| 86 |
+
2 3 1 4
|
| 87 |
+
2 3 4 1
|
| 88 |
+
2 4 1 3
|
| 89 |
+
2 4 3 1
|
| 90 |
+
3 1 2 4
|
| 91 |
+
3 1 4 2
|
| 92 |
+
3 2 1 4
|
| 93 |
+
3 2 4 1
|
| 94 |
+
3 4 1 2
|
| 95 |
+
3 4 2 1
|
| 96 |
+
4 1 2 3
|
| 97 |
+
4 1 3 2
|
| 98 |
+
4 2 1 3
|
| 99 |
+
4 2 3 1
|
| 100 |
+
4 3 1 2
|
| 101 |
+
4 3 2 1
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
Output
|
| 105 |
+
|
| 106 |
+
No
|
| 107 |
+
No
|
| 108 |
+
No
|
| 109 |
+
No
|
| 110 |
+
No
|
| 111 |
+
No
|
| 112 |
+
Yes
|
| 113 |
+
Yes
|
| 114 |
+
No
|
| 115 |
+
No
|
| 116 |
+
No
|
| 117 |
+
No
|
| 118 |
+
Yes
|
| 119 |
+
Yes
|
| 120 |
+
Yes
|
| 121 |
+
No
|
| 122 |
+
No
|
| 123 |
+
No
|
| 124 |
+
Yes
|
| 125 |
+
Yes
|
| 126 |
+
Yes
|
| 127 |
+
No
|
| 128 |
+
No
|
| 129 |
+
No
|
| 130 |
+
|
| 131 |
+
## Contest Information
|
| 132 |
+
- **Contest ID**: 0
|
| 133 |
+
- **Problem Index**:
|
| 134 |
+
- **Points**: 0.0
|
| 135 |
+
- **Rating**: 0
|
| 136 |
+
- **Tags**:
|
| 137 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 138 |
+
- **Memory Limit**: 1073741824 bytes
|
| 139 |
+
|
| 140 |
+
## Task
|
| 141 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0085/instruction.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03774 AtCoder Beginner Contest 057 - Checkpoints
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are N students and M checkpoints on the xy-plane.
|
| 5 |
+
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
|
| 6 |
+
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
|
| 7 |
+
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
|
| 8 |
+
Here, |x| denotes the absolute value of x.
|
| 9 |
+
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
|
| 10 |
+
Which checkpoint will each student go to?
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 \leq N,M \leq 50
|
| 15 |
+
* -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
|
| 16 |
+
* All input values are integers.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
The input is given from Standard Input in the following format:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
N M
|
| 24 |
+
a_1 b_1
|
| 25 |
+
:
|
| 26 |
+
a_N b_N
|
| 27 |
+
c_1 d_1
|
| 28 |
+
:
|
| 29 |
+
c_M d_M
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print N lines.
|
| 35 |
+
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
2 2
|
| 42 |
+
2 0
|
| 43 |
+
0 0
|
| 44 |
+
-1 0
|
| 45 |
+
1 0
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
2
|
| 51 |
+
1
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
3 4
|
| 57 |
+
10 10
|
| 58 |
+
-10 -10
|
| 59 |
+
3 3
|
| 60 |
+
1 2
|
| 61 |
+
2 3
|
| 62 |
+
3 5
|
| 63 |
+
3 5
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
3
|
| 69 |
+
1
|
| 70 |
+
2
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Input
|
| 74 |
+
|
| 75 |
+
5 5
|
| 76 |
+
-100000000 -100000000
|
| 77 |
+
-100000000 100000000
|
| 78 |
+
100000000 -100000000
|
| 79 |
+
100000000 100000000
|
| 80 |
+
0 0
|
| 81 |
+
0 0
|
| 82 |
+
100000000 100000000
|
| 83 |
+
100000000 -100000000
|
| 84 |
+
-100000000 100000000
|
| 85 |
+
-100000000 -100000000
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Output
|
| 89 |
+
|
| 90 |
+
5
|
| 91 |
+
4
|
| 92 |
+
3
|
| 93 |
+
2
|
| 94 |
+
1
|
| 95 |
+
|
| 96 |
+
## Contest Information
|
| 97 |
+
- **Contest ID**: 0
|
| 98 |
+
- **Problem Index**:
|
| 99 |
+
- **Points**: 0.0
|
| 100 |
+
- **Rating**: 0
|
| 101 |
+
- **Tags**:
|
| 102 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 103 |
+
- **Memory Limit**: 268435456 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-0133/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 151_C. Win or Freeze
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.
|
| 5 |
+
|
| 6 |
+
The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains the only integer q (1 ≤ q ≤ 1013).
|
| 11 |
+
|
| 12 |
+
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
6
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
2
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
30
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
1
|
| 38 |
+
6
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
1
|
| 49 |
+
0
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 151
|
| 57 |
+
- **Problem Index**: C
|
| 58 |
+
- **Points**: 500.0
|
| 59 |
+
- **Rating**: 1400
|
| 60 |
+
- **Tags**: games, math, number theory
|
| 61 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 62 |
+
- **Memory Limit**: 256000000 bytes
|
| 63 |
+
|
| 64 |
+
## Task
|
| 65 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0211/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lucky5
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
|
| 5 |
+
|
| 6 |
+
Chef has a positive integer N. He can apply any of the following operations as many times as he want in any order:
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Add 1 to the number N.
|
| 10 |
+
Take some digit of N and replace it by any non-zero digit.
|
| 11 |
+
Add any non-zero leading digit to N.
|
| 12 |
+
|
| 13 |
+
Find the minimum number of operations that is needed for changing N to the lucky number.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
The first line contains a single positive integer T, the number of test cases. T test cases follow. The only line of each test case contains a positive integer N without leading zeros.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
For each T test cases print one integer, the minimum number of operations that is needed for changing N to the lucky number.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Constraints
|
| 25 |
+
|
| 26 |
+
1 ≤ T ≤ 10
|
| 27 |
+
|
| 28 |
+
1 ≤ N < 10^100000
|
| 29 |
+
|
| 30 |
+
Example
|
| 31 |
+
|
| 32 |
+
Input:
|
| 33 |
+
3
|
| 34 |
+
25
|
| 35 |
+
46
|
| 36 |
+
99
|
| 37 |
+
|
| 38 |
+
Output:
|
| 39 |
+
2
|
| 40 |
+
1
|
| 41 |
+
2
|
| 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-0216/instruction.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 105_C. Item World
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
|
| 5 |
+
|
| 6 |
+
Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.
|
| 7 |
+
|
| 8 |
+
Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item World
|
| 9 |
+
|
| 10 |
+
Residents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).
|
| 11 |
+
|
| 12 |
+
Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside — any of them should be inside of some item at any moment of time.
|
| 13 |
+
|
| 14 |
+
Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armor’s def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.
|
| 15 |
+
|
| 16 |
+
Find the optimal equipment pattern Laharl can get.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
The first line contains number n (3 ≤ n ≤ 100) — representing how many items Laharl has.
|
| 21 |
+
|
| 22 |
+
Then follow n lines. Each line contains description of an item. The description has the following form: "name class atk def res size" — the item's name, class, basic attack, defense and resistance parameters and its size correspondingly.
|
| 23 |
+
|
| 24 |
+
* name and class are strings and atk, def, res and size are integers.
|
| 25 |
+
* name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.
|
| 26 |
+
* class can be "weapon", "armor" or "orb".
|
| 27 |
+
* 0 ≤ atk, def, res ≤ 1000.
|
| 28 |
+
* 1 ≤ size ≤ 10.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
It is guaranteed that Laharl has at least one item of each class.
|
| 33 |
+
|
| 34 |
+
The next line contains an integer k (1 ≤ k ≤ 1000) — the number of residents.
|
| 35 |
+
|
| 36 |
+
Then k lines follow. Each of them describes a resident. A resident description looks like: "name type bonus home" — the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident.
|
| 37 |
+
|
| 38 |
+
* name, type and home are strings and bonus is an integer.
|
| 39 |
+
* name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.
|
| 40 |
+
* type may be "gladiator", "sentry" or "physician".
|
| 41 |
+
* 1 ≤ bonus ≤ 100.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
It is guaranteed that the number of residents in each item does not exceed the item's size.
|
| 46 |
+
|
| 47 |
+
The names of all items and residents are pairwise different.
|
| 48 |
+
|
| 49 |
+
All words and numbers in the input are separated by single spaces.
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.
|
| 54 |
+
|
| 55 |
+
Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.
|
| 56 |
+
|
| 57 |
+
Use single spaces for separation.
|
| 58 |
+
|
| 59 |
+
If there are several possible solutions, print any of them.
|
| 60 |
+
|
| 61 |
+
Examples
|
| 62 |
+
|
| 63 |
+
Input
|
| 64 |
+
|
| 65 |
+
4
|
| 66 |
+
sword weapon 10 2 3 2
|
| 67 |
+
pagstarmor armor 0 15 3 1
|
| 68 |
+
iceorb orb 3 2 13 2
|
| 69 |
+
longbow weapon 9 1 2 1
|
| 70 |
+
5
|
| 71 |
+
mike gladiator 5 longbow
|
| 72 |
+
bobby sentry 6 pagstarmor
|
| 73 |
+
petr gladiator 7 iceorb
|
| 74 |
+
teddy physician 6 sword
|
| 75 |
+
blackjack sentry 8 sword
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Output
|
| 79 |
+
|
| 80 |
+
sword 2 petr mike
|
| 81 |
+
pagstarmor 1 blackjack
|
| 82 |
+
iceorb 2 teddy bobby
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Input
|
| 86 |
+
|
| 87 |
+
4
|
| 88 |
+
sword weapon 10 2 3 2
|
| 89 |
+
pagstarmor armor 0 15 3 1
|
| 90 |
+
iceorb orb 3 2 13 2
|
| 91 |
+
longbow weapon 9 1 2 1
|
| 92 |
+
6
|
| 93 |
+
mike gladiator 5 longbow
|
| 94 |
+
bobby sentry 6 pagstarmor
|
| 95 |
+
petr gladiator 7 iceorb
|
| 96 |
+
teddy physician 6 sword
|
| 97 |
+
blackjack sentry 8 sword
|
| 98 |
+
joe physician 6 iceorb
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
Output
|
| 102 |
+
|
| 103 |
+
longbow 1 mike
|
| 104 |
+
pagstarmor 1 bobby
|
| 105 |
+
iceorb 2 petr joe
|
| 106 |
+
|
| 107 |
+
Note
|
| 108 |
+
|
| 109 |
+
In the second sample we have no free space inside the items, therefore we cannot move the residents between them.
|
| 110 |
+
|
| 111 |
+
## Contest Information
|
| 112 |
+
- **Contest ID**: 105
|
| 113 |
+
- **Problem Index**: C
|
| 114 |
+
- **Points**: 1500.0
|
| 115 |
+
- **Rating**: 2200
|
| 116 |
+
- **Tags**: brute force, implementation, sortings
|
| 117 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 118 |
+
- **Memory Limit**: 256000000 bytes
|
| 119 |
+
|
| 120 |
+
## Task
|
| 121 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0218/instruction.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1100_D. Dasha and Chess
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
This is an interactive task.
|
| 5 |
+
|
| 6 |
+
Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.
|
| 7 |
+
|
| 8 |
+
There are 666 black rooks and 1 white king on the chess board of size 999 × 999. The white king wins if he gets checked by rook, or, in other words, if he moves onto the square which shares either a row or column with a black rook.
|
| 9 |
+
|
| 10 |
+
The sides take turns, starting with white. NN plays as a white king and on each of his turns he moves a king to one of the squares that are adjacent to his current position either by side or diagonally, or, formally, if the king was on the square (x, y), it can move to the square (nx, ny) if and only max (|nx - x|, |ny - y|) = 1 , 1 ≤ nx, ny ≤ 999. NN is also forbidden from moving onto the squares occupied with black rooks, however, he can move onto the same row or column as a black rook.
|
| 11 |
+
|
| 12 |
+
Dasha, however, neglects playing by the chess rules, and instead of moving rooks normally she moves one of her rooks on any space devoid of other chess pieces. It is also possible that the rook would move onto the same square it was before and the position wouldn't change. However, she can't move the rook on the same row or column with the king.
|
| 13 |
+
|
| 14 |
+
Each player makes 2000 turns, if the white king wasn't checked by a black rook during those turns, black wins.
|
| 15 |
+
|
| 16 |
+
NN doesn't like losing, but thinks the task is too difficult for him, so he asks you to write a program that will always win playing for the white king. Note that Dasha can see your king and play depending on its position.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
In the beginning your program will receive 667 lines from input. Each line contains two integers x and y (1 ≤ x, y ≤ 999) — the piece's coordinates. The first line contains the coordinates of the king and the next 666 contain the coordinates of the rooks. The first coordinate denotes the number of the row where the piece is located, the second denotes the column. It is guaranteed that initially the king isn't in check and that all pieces occupy different squares.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
After getting king checked, you program should terminate immediately without printing anything extra.
|
| 25 |
+
|
| 26 |
+
Interaction
|
| 27 |
+
|
| 28 |
+
To make a move with the king, output two integers x and y (1 ≤ x, y ≤ 999) — the square to which the king would be moved. The king cannot move onto the square already occupied by a rook. It is guaranteed that the king would always have a valid move.
|
| 29 |
+
|
| 30 |
+
After each of your turns read the rook's turn in the following format: a single line containing three integers k, x and y (1 ≤ k ≤ 666, 1 ≤ x_i, y_i ≤ 999) — the number of the rook that would move and the square it would move to. It is guaranteed that the rook wouldn't move to a square already occupied by another chess piece, but it can move onto the square where it was before the turn so that its position wouldn't change. It is guaranteed that the move does not put your king into a check. If your king got in check, all three integers would be equal to -1 and in that case your program should terminate immediately.
|
| 31 |
+
|
| 32 |
+
After printing your turn do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
|
| 33 |
+
|
| 34 |
+
* fflush(stdout) or cout.flush() in C++;
|
| 35 |
+
* System.out.flush() in Java;
|
| 36 |
+
* flush(output) in Pascal;
|
| 37 |
+
* stdout.flush() in Python;
|
| 38 |
+
* see documentation for other languages.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Answer "0 0 0" instead of a correct answer means that you made an invalid query. Exit immediately after receiving "0 0 0" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
|
| 43 |
+
|
| 44 |
+
Hacks are not allowed for this problem.
|
| 45 |
+
|
| 46 |
+
Example
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
999 999
|
| 51 |
+
1 1
|
| 52 |
+
1 2
|
| 53 |
+
2 1
|
| 54 |
+
2 2
|
| 55 |
+
1 3
|
| 56 |
+
2 3
|
| 57 |
+
<...>
|
| 58 |
+
26 13
|
| 59 |
+
26 14
|
| 60 |
+
26 15
|
| 61 |
+
26 16
|
| 62 |
+
|
| 63 |
+
1 700 800
|
| 64 |
+
|
| 65 |
+
2 1 2
|
| 66 |
+
|
| 67 |
+
<...>
|
| 68 |
+
|
| 69 |
+
-1 -1 -1
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Output
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
999 998
|
| 86 |
+
|
| 87 |
+
999 997
|
| 88 |
+
|
| 89 |
+
<...>
|
| 90 |
+
|
| 91 |
+
999 26
|
| 92 |
+
|
| 93 |
+
Note
|
| 94 |
+
|
| 95 |
+
The example is trimmed. The full initial positions of the rooks in the first test are available at <https://pastebin.com/qQCTXgKP>. It is not guaranteed that they will behave as in the example.
|
| 96 |
+
|
| 97 |
+
## Contest Information
|
| 98 |
+
- **Contest ID**: 1100
|
| 99 |
+
- **Problem Index**: D
|
| 100 |
+
- **Points**: 2000.0
|
| 101 |
+
- **Rating**: 2500
|
| 102 |
+
- **Tags**: constructive algorithms, games, interactive
|
| 103 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 104 |
+
- **Memory Limit**: 256000000 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-0219/instruction.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1129_A2. Toy Train
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station i is station i+1 if 1 ≤ i < n or station 1 if i = n. It takes the train 1 second to travel to its next station as described.
|
| 5 |
+
|
| 6 |
+
Bob gave Alice a fun task before he left: to deliver m candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from 1 through m. Candy i (1 ≤ i ≤ m), now at station a_i, should be delivered to station b_i (a_i ≠ b_i).
|
| 7 |
+
|
| 8 |
+
<image> The blue numbers on the candies correspond to b_i values. The image corresponds to the 1-st example.
|
| 9 |
+
|
| 10 |
+
The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.
|
| 11 |
+
|
| 12 |
+
Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains two space-separated integers n and m (2 ≤ n ≤ 5 000; 1 ≤ m ≤ 20 000) — the number of stations and the number of candies, respectively.
|
| 17 |
+
|
| 18 |
+
The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i) — the station that initially contains candy i and the destination station of the candy, respectively.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
In the first and only line, print n space-separated integers, the i-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station i.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
5 7
|
| 30 |
+
2 4
|
| 31 |
+
5 1
|
| 32 |
+
2 3
|
| 33 |
+
3 4
|
| 34 |
+
4 1
|
| 35 |
+
5 3
|
| 36 |
+
3 5
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
10 9 10 10 9
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
2 3
|
| 49 |
+
1 2
|
| 50 |
+
1 2
|
| 51 |
+
1 2
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
5 6
|
| 58 |
+
|
| 59 |
+
Note
|
| 60 |
+
|
| 61 |
+
Consider the second sample.
|
| 62 |
+
|
| 63 |
+
If the train started at station 1, the optimal strategy is as follows.
|
| 64 |
+
|
| 65 |
+
1. Load the first candy onto the train.
|
| 66 |
+
2. Proceed to station 2. This step takes 1 second.
|
| 67 |
+
3. Deliver the first candy.
|
| 68 |
+
4. Proceed to station 1. This step takes 1 second.
|
| 69 |
+
5. Load the second candy onto the train.
|
| 70 |
+
6. Proceed to station 2. This step takes 1 second.
|
| 71 |
+
7. Deliver the second candy.
|
| 72 |
+
8. Proceed to station 1. This step takes 1 second.
|
| 73 |
+
9. Load the third candy onto the train.
|
| 74 |
+
10. Proceed to station 2. This step takes 1 second.
|
| 75 |
+
11. Deliver the third candy.
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Hence, the train needs 5 seconds to complete the tasks.
|
| 80 |
+
|
| 81 |
+
If the train were to start at station 2, however, it would need to move to station 1 before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is 5+1 = 6 seconds.
|
| 82 |
+
|
| 83 |
+
## Contest Information
|
| 84 |
+
- **Contest ID**: 1129
|
| 85 |
+
- **Problem Index**: A2
|
| 86 |
+
- **Points**: 250.0
|
| 87 |
+
- **Rating**: 1800
|
| 88 |
+
- **Tags**: brute force, greedy
|
| 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-0220/instruction.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1149_B. Three Religions
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
|
| 5 |
+
|
| 6 |
+
The Word of Universe is a long word containing the lowercase English characters only. At each moment of time, each of the religion beliefs could be described by a word consisting of lowercase English characters.
|
| 7 |
+
|
| 8 |
+
The three religions can coexist in peace if their descriptions form disjoint subsequences of the Word of Universe. More formally, one can paint some of the characters of the Word of Universe in three colors: 1, 2, 3, so that each character is painted in at most one color, and the description of the i-th religion can be constructed from the Word of Universe by removing all characters that aren't painted in color i.
|
| 9 |
+
|
| 10 |
+
The religions however evolve. In the beginning, each religion description is empty. Every once in a while, either a character is appended to the end of the description of a single religion, or the last character is dropped from the description. After each change, determine if the religions could coexist in peace.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of the input contains two integers n, q (1 ≤ n ≤ 100 000, 1 ≤ q ≤ 1000) — the length of the Word of Universe and the number of religion evolutions, respectively. The following line contains the Word of Universe — a string of length n consisting of lowercase English characters.
|
| 15 |
+
|
| 16 |
+
Each of the following line describes a single evolution and is in one of the following formats:
|
| 17 |
+
|
| 18 |
+
* + i c (i ∈ \{1, 2, 3\}, c ∈ \{a, b, ..., z\}: append the character c to the end of i-th religion description.
|
| 19 |
+
* - i (i ∈ \{1, 2, 3\}) – remove the last character from the i-th religion description. You can assume that the pattern is non-empty.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
You can assume that no religion will have description longer than 250 characters.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Write q lines. The i-th of them should be YES if the religions could coexist in peace after the i-th evolution, or NO otherwise.
|
| 28 |
+
|
| 29 |
+
You can print each character in any case (either upper or lower).
|
| 30 |
+
|
| 31 |
+
Examples
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
6 8
|
| 37 |
+
abdabc
|
| 38 |
+
+ 1 a
|
| 39 |
+
+ 1 d
|
| 40 |
+
+ 2 b
|
| 41 |
+
+ 2 c
|
| 42 |
+
+ 3 a
|
| 43 |
+
+ 3 b
|
| 44 |
+
+ 1 c
|
| 45 |
+
- 2
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
YES
|
| 52 |
+
YES
|
| 53 |
+
YES
|
| 54 |
+
YES
|
| 55 |
+
YES
|
| 56 |
+
YES
|
| 57 |
+
NO
|
| 58 |
+
YES
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Input
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
6 8
|
| 65 |
+
abbaab
|
| 66 |
+
+ 1 a
|
| 67 |
+
+ 2 a
|
| 68 |
+
+ 3 a
|
| 69 |
+
+ 1 b
|
| 70 |
+
+ 2 b
|
| 71 |
+
+ 3 b
|
| 72 |
+
- 1
|
| 73 |
+
+ 2 z
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Output
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
YES
|
| 80 |
+
YES
|
| 81 |
+
YES
|
| 82 |
+
YES
|
| 83 |
+
YES
|
| 84 |
+
NO
|
| 85 |
+
YES
|
| 86 |
+
NO
|
| 87 |
+
|
| 88 |
+
Note
|
| 89 |
+
|
| 90 |
+
In the first example, after the 6th evolution the religion descriptions are: ad, bc, and ab. The following figure shows how these descriptions form three disjoint subsequences of the Word of Universe:
|
| 91 |
+
|
| 92 |
+
<image>
|
| 93 |
+
|
| 94 |
+
## Contest Information
|
| 95 |
+
- **Contest ID**: 1149
|
| 96 |
+
- **Problem Index**: B
|
| 97 |
+
- **Points**: 1250.0
|
| 98 |
+
- **Rating**: 2200
|
| 99 |
+
- **Tags**: dp, implementation, strings
|
| 100 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 101 |
+
- **Memory Limit**: 256000000 bytes
|
| 102 |
+
|
| 103 |
+
## Task
|
| 104 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0229/instruction.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1334_A. Level Statistics
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
|
| 5 |
+
|
| 6 |
+
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 1. If he manages to finish the level successfully then the number of clears increases by 1 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).
|
| 7 |
+
|
| 8 |
+
Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.
|
| 9 |
+
|
| 10 |
+
So he peeked at the stats n times and wrote down n pairs of integers — (p_1, c_1), (p_2, c_2), ..., (p_n, c_n), where p_i is the number of plays at the i-th moment of time and c_i is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).
|
| 11 |
+
|
| 12 |
+
Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.
|
| 13 |
+
|
| 14 |
+
Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.
|
| 15 |
+
|
| 16 |
+
Help him to check the correctness of his records.
|
| 17 |
+
|
| 18 |
+
For your convenience you have to answer multiple independent test cases.
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
The first line contains a single integer T (1 ≤ T ≤ 500) — the number of test cases.
|
| 23 |
+
|
| 24 |
+
The first line of each test case contains a single integer n (1 ≤ n ≤ 100) — the number of moments of time Polycarp peeked at the stats.
|
| 25 |
+
|
| 26 |
+
Each of the next n lines contains two integers p_i and c_i (0 ≤ p_i, c_i ≤ 1000) — the number of plays and the number of clears of the level at the i-th moment of time.
|
| 27 |
+
|
| 28 |
+
Note that the stats are given in chronological order.
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
For each test case print a single line.
|
| 33 |
+
|
| 34 |
+
If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES".
|
| 35 |
+
|
| 36 |
+
Otherwise, print "NO".
|
| 37 |
+
|
| 38 |
+
You can print each letter in any case (upper or lower).
|
| 39 |
+
|
| 40 |
+
Example
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
6
|
| 46 |
+
3
|
| 47 |
+
0 0
|
| 48 |
+
1 1
|
| 49 |
+
1 2
|
| 50 |
+
2
|
| 51 |
+
1 0
|
| 52 |
+
1000 3
|
| 53 |
+
4
|
| 54 |
+
10 1
|
| 55 |
+
15 2
|
| 56 |
+
10 2
|
| 57 |
+
15 2
|
| 58 |
+
1
|
| 59 |
+
765 432
|
| 60 |
+
2
|
| 61 |
+
4 4
|
| 62 |
+
4 3
|
| 63 |
+
5
|
| 64 |
+
0 0
|
| 65 |
+
1 0
|
| 66 |
+
1 0
|
| 67 |
+
1 0
|
| 68 |
+
1 0
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Output
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
NO
|
| 75 |
+
YES
|
| 76 |
+
NO
|
| 77 |
+
YES
|
| 78 |
+
NO
|
| 79 |
+
YES
|
| 80 |
+
|
| 81 |
+
Note
|
| 82 |
+
|
| 83 |
+
In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.
|
| 84 |
+
|
| 85 |
+
The second test case is a nice example of a Super Expert level.
|
| 86 |
+
|
| 87 |
+
In the third test case the number of plays decreased, which is impossible.
|
| 88 |
+
|
| 89 |
+
The fourth test case is probably an auto level with a single jump over the spike.
|
| 90 |
+
|
| 91 |
+
In the fifth test case the number of clears decreased, which is also impossible.
|
| 92 |
+
|
| 93 |
+
Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.
|
| 94 |
+
|
| 95 |
+
## Contest Information
|
| 96 |
+
- **Contest ID**: 1334
|
| 97 |
+
- **Problem Index**: A
|
| 98 |
+
- **Points**: 0.0
|
| 99 |
+
- **Rating**: 1200
|
| 100 |
+
- **Tags**: implementation, math
|
| 101 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 102 |
+
- **Memory Limit**: 256000000 bytes
|
| 103 |
+
|
| 104 |
+
## Task
|
| 105 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0242/instruction.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 235_A. LCM Challenge
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
|
| 5 |
+
|
| 6 |
+
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains an integer n (1 ≤ n ≤ 106) — the n mentioned in the statement.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
9
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
504
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
7
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
210
|
| 36 |
+
|
| 37 |
+
Note
|
| 38 |
+
|
| 39 |
+
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
|
| 40 |
+
|
| 41 |
+
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
|
| 42 |
+
|
| 43 |
+
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.
|
| 44 |
+
|
| 45 |
+
## Contest Information
|
| 46 |
+
- **Contest ID**: 235
|
| 47 |
+
- **Problem Index**: A
|
| 48 |
+
- **Points**: 500.0
|
| 49 |
+
- **Rating**: 1600
|
| 50 |
+
- **Tags**: number theory
|
| 51 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 52 |
+
- **Memory Limit**: 256000000 bytes
|
| 53 |
+
|
| 54 |
+
## Task
|
| 55 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0243/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 25_D. Roads not only in Berland
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
2
|
| 19 |
+
1 2
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
0
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Input
|
| 28 |
+
|
| 29 |
+
7
|
| 30 |
+
1 2
|
| 31 |
+
2 3
|
| 32 |
+
3 1
|
| 33 |
+
4 5
|
| 34 |
+
5 6
|
| 35 |
+
6 7
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
1
|
| 41 |
+
3 1 3 7
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 25
|
| 45 |
+
- **Problem Index**: D
|
| 46 |
+
- **Points**: 0.0
|
| 47 |
+
- **Rating**: 1900
|
| 48 |
+
- **Tags**: dsu, graphs, trees
|
| 49 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 50 |
+
- **Memory Limit**: 256000000 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-0244/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 283_D. Cows and Cool Sequences
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Bessie and the cows have recently been playing with "cool" sequences and are trying to construct some. Unfortunately they are bad at arithmetic, so they need your help!
|
| 5 |
+
|
| 6 |
+
A pair (x, y) of positive integers is "cool" if x can be expressed as the sum of y consecutive integers (not necessarily positive). A sequence (a1, a2, ..., an) is "cool" if the pairs (a1, a2), (a2, a3), ..., (an - 1, an) are all cool.
|
| 7 |
+
|
| 8 |
+
The cows have a sequence of n positive integers, a1, a2, ..., an. In one move, they may replace some ai with any other positive integer (there are no other limits on the new value of ai). Determine the smallest number of moves needed to make the resulting sequence cool.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains a single integer, n (2 ≤ n ≤ 5000). The next line contains n space-separated integers, a1, a2, ..., an (1 ≤ ai ≤ 1015).
|
| 13 |
+
|
| 14 |
+
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
A single integer, the minimum number of ai that must be changed to make the sequence cool.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3
|
| 25 |
+
6 4 1
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
0
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4
|
| 36 |
+
20 6 3 4
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
2
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first sample, the sequence is already cool, so we don't need to change any elements. In the second sample, we can change a2 to 5 and a3 to 10 to make (20, 5, 10, 4) which is cool. This changes 2 elements.
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 283
|
| 49 |
+
- **Problem Index**: D
|
| 50 |
+
- **Points**: 2000.0
|
| 51 |
+
- **Rating**: 2400
|
| 52 |
+
- **Tags**: dp, math, number theory
|
| 53 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 256000000 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-0245/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 306_C. White, Black and White Again
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to take place during each day. As each day is unequivocally characterizes as a part of a white or a black stripe, then each day is going to have events of the same type only (ether good or not-so-good).
|
| 5 |
+
|
| 6 |
+
What is the number of distinct ways this scenario can develop over the next n days if Polycarpus is in for a white stripe (a stripe that has good events only, the stripe's length is at least 1 day), the a black stripe (a stripe that has not-so-good events only, the stripe's length is at least 1 day) and a white stripe again (a stripe that has good events only, the stripe's length is at least 1 day). Each of n days will belong to one of the three stripes only.
|
| 7 |
+
|
| 8 |
+
Note that even the events of the same type are distinct from each other. Even if some events occur on the same day, they go in some order (there are no simultaneous events).
|
| 9 |
+
|
| 10 |
+
Write a code that prints the number of possible configurations to sort the events into days. See the samples for clarifications on which scenarios should be considered distinct. Print the answer modulo 1000000009 (109 + 9).
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The single line of the input contains integers n, w and b (3 ≤ n ≤ 4000, 2 ≤ w ≤ 4000, 1 ≤ b ≤ 4000) — the number of days, the number of good events and the number of not-so-good events. It is guaranteed that w + b ≥ n.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print the required number of ways modulo 1000000009 (109 + 9).
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3 2 1
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
2
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
4 2 2
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
4
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
3 2 2
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
4
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
We'll represent the good events by numbers starting from 1 and the not-so-good events — by letters starting from 'a'. Vertical lines separate days.
|
| 54 |
+
|
| 55 |
+
In the first sample the possible ways are: "1|a|2" and "2|a|1". In the second sample the possible ways are: "1|a|b|2", "2|a|b|1", "1|b|a|2" and "2|b|a|1". In the third sample the possible ways are: "1|ab|2", "2|ab|1", "1|ba|2" and "2|ba|1".
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 306
|
| 59 |
+
- **Problem Index**: C
|
| 60 |
+
- **Points**: 1500.0
|
| 61 |
+
- **Rating**: 2100
|
| 62 |
+
- **Tags**: combinatorics, number theory
|
| 63 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 64 |
+
- **Memory Limit**: 256000000 bytes
|
| 65 |
+
|
| 66 |
+
## Task
|
| 67 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0272/instruction.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 937_D. Sleepy Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.
|
| 5 |
+
|
| 6 |
+
Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.
|
| 7 |
+
|
| 8 |
+
Your task is to help Petya find out if he can win the game or at least draw a tie.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).
|
| 13 |
+
|
| 14 |
+
The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).
|
| 15 |
+
|
| 16 |
+
It is guaranteed that the total sum of ci equals to m.
|
| 17 |
+
|
| 18 |
+
The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.
|
| 23 |
+
|
| 24 |
+
If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
5 6
|
| 31 |
+
2 2 3
|
| 32 |
+
2 4 5
|
| 33 |
+
1 4
|
| 34 |
+
1 5
|
| 35 |
+
0
|
| 36 |
+
1
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
Win
|
| 42 |
+
1 2 4 5
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
3 2
|
| 48 |
+
1 3
|
| 49 |
+
1 1
|
| 50 |
+
0
|
| 51 |
+
2
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
Lose
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
2 2
|
| 62 |
+
1 2
|
| 63 |
+
1 1
|
| 64 |
+
1
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
Draw
|
| 70 |
+
|
| 71 |
+
Note
|
| 72 |
+
|
| 73 |
+
In the first example the graph is the following:
|
| 74 |
+
|
| 75 |
+
<image>
|
| 76 |
+
|
| 77 |
+
Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.
|
| 78 |
+
|
| 79 |
+
In the second example the graph is the following:
|
| 80 |
+
|
| 81 |
+
<image>
|
| 82 |
+
|
| 83 |
+
Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.
|
| 84 |
+
|
| 85 |
+
In the third example the graph is the following:
|
| 86 |
+
|
| 87 |
+
<image>
|
| 88 |
+
|
| 89 |
+
Petya can't win, but he can move along the cycle, so the players will draw a tie.
|
| 90 |
+
|
| 91 |
+
## Contest Information
|
| 92 |
+
- **Contest ID**: 937
|
| 93 |
+
- **Problem Index**: D
|
| 94 |
+
- **Points**: 1000.0
|
| 95 |
+
- **Rating**: 2100
|
| 96 |
+
- **Tags**: dfs and similar, dp, games, graphs
|
| 97 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 98 |
+
- **Memory Limit**: 256000000 bytes
|
| 99 |
+
|
| 100 |
+
## Task
|
| 101 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0273/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 962_F. Simple Cycles Edges
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an undirected graph, consisting of n vertices and m edges. The graph does not necessarily connected. Guaranteed, that the graph does not contain multiple edges (more than one edges between a pair of vertices) or loops (edges from a vertex to itself).
|
| 5 |
+
|
| 6 |
+
A cycle in a graph is called a simple, if it contains each own vertex exactly once. So simple cycle doesn't allow to visit a vertex more than once in a cycle.
|
| 7 |
+
|
| 8 |
+
Determine the edges, which belong to exactly on one simple cycle.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contain two integers n and m (1 ≤ n ≤ 100 000, 0 ≤ m ≤ min(n ⋅ (n - 1) / 2, 100 000)) — the number of vertices and the number of edges.
|
| 13 |
+
|
| 14 |
+
Each of the following m lines contain two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
In the first line print the number of edges, which belong to exactly one simple cycle.
|
| 19 |
+
|
| 20 |
+
In the second line print the indices of edges, which belong to exactly one simple cycle, in increasing order. The edges are numbered from one in the same order as they are given in the input.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
3 3
|
| 27 |
+
1 2
|
| 28 |
+
2 3
|
| 29 |
+
3 1
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
1 2 3
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
6 7
|
| 41 |
+
2 3
|
| 42 |
+
3 4
|
| 43 |
+
4 2
|
| 44 |
+
1 2
|
| 45 |
+
1 5
|
| 46 |
+
5 6
|
| 47 |
+
6 1
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
6
|
| 53 |
+
1 2 3 5 6 7
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
5 6
|
| 59 |
+
1 2
|
| 60 |
+
2 3
|
| 61 |
+
2 4
|
| 62 |
+
4 3
|
| 63 |
+
2 5
|
| 64 |
+
5 3
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
0
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 962
|
| 73 |
+
- **Problem Index**: F
|
| 74 |
+
- **Points**: 0.0
|
| 75 |
+
- **Rating**: 2400
|
| 76 |
+
- **Tags**: dfs and similar, graphs, trees
|
| 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-0275/instruction.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ankit-and-race-team-10
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Coach Ankit is forming a team for the Annual Inter Galactic Relay Race. He has N students that train under him and he knows their strengths. The strength of a student is represented by a positive integer.
|
| 5 |
+
|
| 6 |
+
The coach has to form a team of K students. The strength of a team is defined by the strength of the weakest student in the team. Now he wants to know the sum of strengths of all the teams of size K that can be formed modulo 1000000007. Please help him.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
The first line contains the number of test cases T.
|
| 10 |
+
Each case begins with a line containing integers N and K. The next line contains N space-separated numbers which describe the strengths of the students.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
For test case output a single integer, the answer as described in the problem statement.
|
| 14 |
+
|
| 15 |
+
Constraints:
|
| 16 |
+
1 ≤ T ≤ 100
|
| 17 |
+
1 ≤ N ≤ 100000
|
| 18 |
+
1 ≤ K ≤ N
|
| 19 |
+
0 ≤ Strength of each student ≤ 2000000000
|
| 20 |
+
Strength of all the students are different.
|
| 21 |
+
|
| 22 |
+
SAMPLE INPUT
|
| 23 |
+
2
|
| 24 |
+
2 1
|
| 25 |
+
5 4
|
| 26 |
+
3 2
|
| 27 |
+
1 0 2
|
| 28 |
+
|
| 29 |
+
SAMPLE OUTPUT
|
| 30 |
+
9
|
| 31 |
+
1
|
| 32 |
+
|
| 33 |
+
Explanation
|
| 34 |
+
|
| 35 |
+
For first test case: 5+4=9, as team can only consist of 1 student.
|
| 36 |
+
For second test case: min(1,0) + min(1,2) + min(0,2) = 0+1+0 =1
|
| 37 |
+
|
| 38 |
+
## Contest Information
|
| 39 |
+
- **Contest ID**: 0
|
| 40 |
+
- **Problem Index**:
|
| 41 |
+
- **Points**: 0.0
|
| 42 |
+
- **Rating**: 0
|
| 43 |
+
- **Tags**: None
|
| 44 |
+
- **Time Limit**: None seconds
|
| 45 |
+
- **Memory Limit**: 0 bytes
|
| 46 |
+
|
| 47 |
+
## Task
|
| 48 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0280/instruction.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# monks-birthday-party
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Monk's birthday is coming this weekend! He wants to plan a Birthday party and is preparing an invite list with his friend Puchi. He asks Puchi to tell him names to add to the list.
|
| 5 |
+
Puchi is a random guy and keeps coming up with names of people randomly to add to the invite list, even if the name is already on the list! Monk hates redundancy and hence, enlists the names only once.
|
| 6 |
+
Find the final invite-list, that contain names without any repetition.
|
| 7 |
+
|
| 8 |
+
Input:
|
| 9 |
+
First line contains an integer T. T test cases follow.
|
| 10 |
+
First line of each test contains an integer N, the number of names that Puchi pops up with.
|
| 11 |
+
|
| 12 |
+
Output:
|
| 13 |
+
For each testcase,Output the final invite-list with each name in a new line. The names in the final invite-list are sorted lexicographically.
|
| 14 |
+
|
| 15 |
+
Constraints:
|
| 16 |
+
1 ≤ T ≤ 10
|
| 17 |
+
1 ≤ N ≤ 10^5
|
| 18 |
+
1 ≤ Length of each name ≤ 10^5
|
| 19 |
+
|
| 20 |
+
SAMPLE INPUT
|
| 21 |
+
1
|
| 22 |
+
7
|
| 23 |
+
chandu
|
| 24 |
+
paro
|
| 25 |
+
rahul
|
| 26 |
+
mohi
|
| 27 |
+
paro
|
| 28 |
+
arindam
|
| 29 |
+
rahul
|
| 30 |
+
|
| 31 |
+
SAMPLE OUTPUT
|
| 32 |
+
arindam
|
| 33 |
+
chandu
|
| 34 |
+
mohi
|
| 35 |
+
paro
|
| 36 |
+
rahul
|
| 37 |
+
|
| 38 |
+
## Contest Information
|
| 39 |
+
- **Contest ID**: 0
|
| 40 |
+
- **Problem Index**:
|
| 41 |
+
- **Points**: 0.0
|
| 42 |
+
- **Rating**: 0
|
| 43 |
+
- **Tags**: None
|
| 44 |
+
- **Time Limit**: None seconds
|
| 45 |
+
- **Memory Limit**: 0 bytes
|
| 46 |
+
|
| 47 |
+
## Task
|
| 48 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0286/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02741 Panasonic Programming Contest 2020 - Kth Term
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Print the K-th element of the following sequence of length 32:
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
|
| 8 |
+
|
| 9 |
+
Constraints
|
| 10 |
+
|
| 11 |
+
* 1 \leq K \leq 32
|
| 12 |
+
* All values in input are integers.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
Input is given from Standard Input in the following format:
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
K
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the K-th element.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
6
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
2
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
27
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
5
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 0
|
| 49 |
+
- **Problem Index**:
|
| 50 |
+
- **Points**: 0.0
|
| 51 |
+
- **Rating**: 0
|
| 52 |
+
- **Tags**:
|
| 53 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 1073741824 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-0287/instruction.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02876 AtCoder Grand Contest 040 - Balance Beam
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have N balance beams numbered 1 to N. The length of each beam is 1 meters. Snuke walks on Beam i at a speed of 1/A_i meters per second, and Ringo walks on Beam i at a speed of 1/B_i meters per second.
|
| 5 |
+
|
| 6 |
+
Snuke and Ringo will play the following game:
|
| 7 |
+
|
| 8 |
+
* First, Snuke connects the N beams in any order of his choice and makes a long beam of length N meters.
|
| 9 |
+
* Then, Snuke starts at the left end of the long beam. At the same time, Ringo starts at a point chosen uniformly at random on the long beam. Both of them walk to the right end of the long beam.
|
| 10 |
+
* Snuke wins if and only if he catches up to Ringo before Ringo reaches the right end of the long beam. That is, Snuke wins if there is a moment when Snuke and Ringo stand at the same position, and Ringo wins otherwise.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Find the probability that Snuke wins when Snuke arranges the N beams so that the probability of his winning is maximized.
|
| 15 |
+
|
| 16 |
+
This probability is a rational number, so we ask you to represent it as an irreducible fraction P/Q (to represent 0, use P=0, Q=1).
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
|
| 20 |
+
* 1 \leq N \leq 10^5
|
| 21 |
+
* 1 \leq A_i,B_i \leq 10^9
|
| 22 |
+
* All values in input are integers.
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
Input is given from Standard Input in the following format:
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
N
|
| 30 |
+
A_1 B_1
|
| 31 |
+
A_2 B_2
|
| 32 |
+
\vdots
|
| 33 |
+
A_N B_N
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
Print the numerator and denominator of the irreducible fraction that represents the maximum probability of Snuke's winning.
|
| 39 |
+
|
| 40 |
+
Examples
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
2
|
| 45 |
+
3 2
|
| 46 |
+
1 2
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
1 4
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
4
|
| 57 |
+
1 5
|
| 58 |
+
4 7
|
| 59 |
+
2 1
|
| 60 |
+
8 4
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
1 2
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Input
|
| 69 |
+
|
| 70 |
+
3
|
| 71 |
+
4 1
|
| 72 |
+
5 2
|
| 73 |
+
6 3
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Output
|
| 77 |
+
|
| 78 |
+
0 1
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Input
|
| 82 |
+
|
| 83 |
+
10
|
| 84 |
+
866111664 178537096
|
| 85 |
+
705445072 318106937
|
| 86 |
+
472381277 579910117
|
| 87 |
+
353498483 865935868
|
| 88 |
+
383133839 231371336
|
| 89 |
+
378371075 681212831
|
| 90 |
+
304570952 16537461
|
| 91 |
+
955719384 267238505
|
| 92 |
+
844917655 218662351
|
| 93 |
+
550309930 62731178
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
Output
|
| 97 |
+
|
| 98 |
+
697461712 2899550585
|
| 99 |
+
|
| 100 |
+
## Contest Information
|
| 101 |
+
- **Contest ID**: 0
|
| 102 |
+
- **Problem Index**:
|
| 103 |
+
- **Points**: 0.0
|
| 104 |
+
- **Rating**: 0
|
| 105 |
+
- **Tags**:
|
| 106 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 107 |
+
- **Memory Limit**: 1073741824 bytes
|
| 108 |
+
|
| 109 |
+
## Task
|
| 110 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0288/instruction.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03010 diverta 2019 Programming Contest 2 - Diverta City
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Diverta City is a new city consisting of N towns numbered 1, 2, ..., N.
|
| 5 |
+
|
| 6 |
+
The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided.
|
| 7 |
+
|
| 8 |
+
A Hamiltonian path is a path that starts at one of the towns and visits each of the other towns exactly once. The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path.
|
| 9 |
+
|
| 10 |
+
There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse.
|
| 11 |
+
|
| 12 |
+
Find one such set of the lengths of the roads, under the following conditions:
|
| 13 |
+
|
| 14 |
+
* The length of each road must be a positive integer.
|
| 15 |
+
* The maximum total length of a Hamiltonian path must be at most 10^{11}.
|
| 16 |
+
|
| 17 |
+
Constraints
|
| 18 |
+
|
| 19 |
+
* N is a integer between 2 and 10 (inclusive).
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
Input is given from Standard Input in the following format:
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
N
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Print a set of the lengths of the roads that meets the objective, in the following format:
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}
|
| 35 |
+
w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}
|
| 36 |
+
: : :
|
| 37 |
+
w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
where w_{i, j} is the length of the road connecting Town i and Town j, which must satisfy the following conditions:
|
| 41 |
+
|
| 42 |
+
* w_{i, i} = 0
|
| 43 |
+
* w_{i, j} = w_{j, i} \ (i \neq j)
|
| 44 |
+
* 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted.
|
| 49 |
+
|
| 50 |
+
Examples
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
3
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
0 6 15
|
| 60 |
+
6 0 21
|
| 61 |
+
15 21 0
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Input
|
| 65 |
+
|
| 66 |
+
4
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Output
|
| 70 |
+
|
| 71 |
+
0 111 157 193
|
| 72 |
+
111 0 224 239
|
| 73 |
+
157 224 0 258
|
| 74 |
+
193 239 258 0
|
| 75 |
+
|
| 76 |
+
## Contest Information
|
| 77 |
+
- **Contest ID**: 0
|
| 78 |
+
- **Problem Index**:
|
| 79 |
+
- **Points**: 0.0
|
| 80 |
+
- **Rating**: 0
|
| 81 |
+
- **Tags**:
|
| 82 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 83 |
+
- **Memory Limit**: 1073741824 bytes
|
| 84 |
+
|
| 85 |
+
## Task
|
| 86 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0289/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03150 KEYENCE Programming Contest 2019 - KEYENCE String
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once.
|
| 5 |
+
|
| 6 |
+
Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* The length of S is between 7 and 100 (inclusive).
|
| 11 |
+
* S consists of lowercase English letters.
|
| 12 |
+
|
| 13 |
+
Input
|
| 14 |
+
|
| 15 |
+
Input is given from Standard Input in the following format:
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
S
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
If S is a KEYENCE string, print `YES`; otherwise, print `NO`.
|
| 24 |
+
|
| 25 |
+
Examples
|
| 26 |
+
|
| 27 |
+
Input
|
| 28 |
+
|
| 29 |
+
keyofscience
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
YES
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
mpyszsbznf
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
NO
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Input
|
| 48 |
+
|
| 49 |
+
ashlfyha
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
NO
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Input
|
| 58 |
+
|
| 59 |
+
keyence
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
YES
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 0
|
| 68 |
+
- **Problem Index**:
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 0
|
| 71 |
+
- **Tags**:
|
| 72 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 73 |
+
- **Memory Limit**: 1073741824 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-0339/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1455_F. String and Operations
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a string s consisting of n characters. These characters are among the first k lowercase letters of the Latin alphabet. You have to perform n operations with the string.
|
| 5 |
+
|
| 6 |
+
During the i-th operation, you take the character that initially occupied the i-th position, and perform one of the following actions with it:
|
| 7 |
+
|
| 8 |
+
* swap it with the previous character in the string (if it exists). This operation is represented as L;
|
| 9 |
+
* swap it with the next character in the string (if it exists). This operation is represented as R;
|
| 10 |
+
* cyclically change it to the previous character in the alphabet (b becomes a, c becomes b, and so on; a becomes the k-th letter of the Latin alphabet). This operation is represented as D;
|
| 11 |
+
* cyclically change it to the next character in the alphabet (a becomes b, b becomes c, and so on; the k-th letter of the Latin alphabet becomes a). This operation is represented as U;
|
| 12 |
+
* do nothing. This operation is represented as 0.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
For example, suppose the initial string is test, k = 20, and the sequence of operations is URLD. Then the string is transformed as follows:
|
| 17 |
+
|
| 18 |
+
1. the first operation is U, so we change the underlined letter in test to the next one in the first 20 Latin letters, which is a. The string is now aest;
|
| 19 |
+
2. the second operation is R, so we swap the underlined letter with the next one in the string aest. The string is now aset;
|
| 20 |
+
3. the third operation is L, so we swap the underlined letter with the previous one in the string aset (note that this is now the 2-nd character of the string, but it was initially the 3-rd one, so the 3-rd operation is performed to it). The resulting string is saet;
|
| 21 |
+
4. the fourth operation is D, so we change the underlined letter in saet to the previous one in the first 20 Latin letters, which is s. The string is now saes.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
The result of performing the sequence of operations is saes.
|
| 26 |
+
|
| 27 |
+
Given the string s and the value of k, find the lexicographically smallest string that can be obtained after applying a sequence of operations to s.
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
|
| 32 |
+
|
| 33 |
+
Each test case consists of two lines. The first line contains two integers n and k (1 ≤ n ≤ 500; 2 ≤ k ≤ 26).
|
| 34 |
+
|
| 35 |
+
The second line contains a string s consisting of n characters. Each character is one of the k first letters of the Latin alphabet (in lower case).
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
For each test case, print one line containing the lexicographically smallest string that can be obtained from s using one sequence of operations.
|
| 40 |
+
|
| 41 |
+
Example
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
6
|
| 47 |
+
4 2
|
| 48 |
+
bbab
|
| 49 |
+
7 5
|
| 50 |
+
cceddda
|
| 51 |
+
6 5
|
| 52 |
+
ecdaed
|
| 53 |
+
7 4
|
| 54 |
+
dcdbdaa
|
| 55 |
+
8 3
|
| 56 |
+
ccabbaca
|
| 57 |
+
5 7
|
| 58 |
+
eabba
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
aaaa
|
| 65 |
+
baccacd
|
| 66 |
+
aabdac
|
| 67 |
+
aabacad
|
| 68 |
+
aaaaaaaa
|
| 69 |
+
abadb
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 1455
|
| 73 |
+
- **Problem Index**: F
|
| 74 |
+
- **Points**: 0.0
|
| 75 |
+
- **Rating**: 2800
|
| 76 |
+
- **Tags**: dp, greedy
|
| 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-0412/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01931 Check answers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
problem
|
| 5 |
+
|
| 6 |
+
AOR Ika is studying to pass the test.
|
| 7 |
+
|
| 8 |
+
AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure.
|
| 9 |
+
|
| 10 |
+
1. Check the correctness of the answer.
|
| 11 |
+
2. If the answer is correct, write a circle mark, and if it is incorrect, write a cross mark on the answer sheet.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
AOR Ika faints because of the fear of failing the test the moment she finds that the answer is wrong for $ 2 $ in a row. And no further rounding is possible.
|
| 16 |
+
|
| 17 |
+
Syncope occurs between steps $ 1 $ and $ 2 $.
|
| 18 |
+
|
| 19 |
+
You will be given an integer $ N $, which represents the number of questions AOR Ika has solved, and a string $ S $, which is a length $ N $ and represents the correctness of the answer. The string consists of'o'and'x', with'o' indicating the correct answer and'x' indicating the incorrect answer. The $ i $ letter indicates the correctness of the $ i $ question, and AOR Ika-chan rounds the $ 1 $ question in order.
|
| 20 |
+
|
| 21 |
+
Please output the number of questions that AOR Ika-chan can write the correctness.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
output
|
| 26 |
+
|
| 27 |
+
Output the number of questions that AOR Ika-chan could write in the $ 1 $ line. Also, output a line break at the end.
|
| 28 |
+
|
| 29 |
+
Example
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
3
|
| 34 |
+
oxx
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
2
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 0
|
| 43 |
+
- **Problem Index**:
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 0
|
| 46 |
+
- **Tags**:
|
| 47 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 48 |
+
- **Memory Limit**: 268435456 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-0413/instruction.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02069 Universal and Existential Quantifiers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem Statement
|
| 5 |
+
|
| 6 |
+
You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers:
|
| 7 |
+
|
| 8 |
+
* The minimum integer $x$ such that you can select $x$ intervals from the given $N$ intervals so that the union of the selected intervals is $[0, L)$.
|
| 9 |
+
* The minimum integer $y$ such that for all possible combinations of $y$ intervals from the given $N$ interval, it does cover $[0, L)$.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
We ask you to write a program to compute these two numbers.
|
| 14 |
+
|
| 15 |
+
* * *
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The input consists of a single test case formatted as follows.
|
| 20 |
+
|
| 21 |
+
> $N$ $L$ $l_1$ $r_1$ $l_2$ $r_2$ $\vdots$ $l_N$ $r_N$
|
| 22 |
+
|
| 23 |
+
The first line contains two integers $N$ ($1 \leq N \leq 2 \times 10^5$) and $L$ ($1 \leq L \leq 10^{12}$), where $N$ is the number of intervals and $L$ is the length of range to be covered, respectively. The $i$-th of the following $N$ lines contains two integers $l_i$ and $r_i$ ($0 \leq l_i < r_i \leq L$), representing the range of the $i$-th interval $[l_i, r_i)$. You can assume that the union of all the $N$ intervals is $[0, L)$
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Output two integers $x$ and $y$ mentioned in the problem statement, separated by a single space, in a line.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input| Output
|
| 32 |
+
---|---
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
3 3
|
| 36 |
+
0 2
|
| 37 |
+
1 3
|
| 38 |
+
1 2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
2 3
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
2 4
|
| 49 |
+
0 4
|
| 50 |
+
0 4
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
1 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
5 4
|
| 61 |
+
0 2
|
| 62 |
+
2 4
|
| 63 |
+
0 3
|
| 64 |
+
1 3
|
| 65 |
+
3 4
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
2 4
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Example
|
| 79 |
+
|
| 80 |
+
Input
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Output
|
| 86 |
+
|
| 87 |
+
## Contest Information
|
| 88 |
+
- **Contest ID**: 0
|
| 89 |
+
- **Problem Index**:
|
| 90 |
+
- **Points**: 0.0
|
| 91 |
+
- **Rating**: 0
|
| 92 |
+
- **Tags**:
|
| 93 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 94 |
+
- **Memory Limit**: 536870912 bytes
|
| 95 |
+
|
| 96 |
+
## Task
|
| 97 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0415/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02365 Minimum-Cost Arborescence
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).
|
| 5 |
+
|
| 6 |
+
Constraints
|
| 7 |
+
|
| 8 |
+
* 1 ≤ |V| ≤ 100
|
| 9 |
+
* 0 ≤ |E| ≤ 1,000
|
| 10 |
+
* 0 ≤ wi ≤ 10,000
|
| 11 |
+
* G has arborescence(s) with the root r
|
| 12 |
+
|
| 13 |
+
Input
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|V| |E| r
|
| 17 |
+
s0 t0 w0
|
| 18 |
+
s1 t1 w1
|
| 19 |
+
:
|
| 20 |
+
s|E|-1 t|E|-1 w|E|-1
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence.
|
| 24 |
+
|
| 25 |
+
si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
Print the sum of the weights the Minimum-Cost Arborescence.
|
| 30 |
+
|
| 31 |
+
Examples
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4 6 0
|
| 36 |
+
0 1 3
|
| 37 |
+
0 2 2
|
| 38 |
+
2 0 1
|
| 39 |
+
2 3 1
|
| 40 |
+
3 0 1
|
| 41 |
+
3 1 5
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
6
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Input
|
| 50 |
+
|
| 51 |
+
6 10 0
|
| 52 |
+
0 2 7
|
| 53 |
+
0 1 1
|
| 54 |
+
0 3 5
|
| 55 |
+
1 4 9
|
| 56 |
+
2 1 6
|
| 57 |
+
1 3 2
|
| 58 |
+
3 4 3
|
| 59 |
+
4 2 2
|
| 60 |
+
2 5 8
|
| 61 |
+
3 5 3
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Output
|
| 65 |
+
|
| 66 |
+
11
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 0
|
| 70 |
+
- **Problem Index**:
|
| 71 |
+
- **Points**: 0.0
|
| 72 |
+
- **Rating**: 0
|
| 73 |
+
- **Tags**:
|
| 74 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 75 |
+
- **Memory Limit**: 134217728 bytes
|
| 76 |
+
|
| 77 |
+
## Task
|
| 78 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0422/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1003_D. Coins and Queries
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d).
|
| 5 |
+
|
| 6 |
+
Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of coins that is necessary to obtain the value b_j using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value b_j, the answer to the j-th query is -1.
|
| 7 |
+
|
| 8 |
+
The queries are independent (the answer on the query doesn't affect Polycarp's coins).
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of the input contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the number of coins and the number of queries.
|
| 13 |
+
|
| 14 |
+
The second line of the input contains n integers a_1, a_2, ..., a_n — values of coins (1 ≤ a_i ≤ 2 ⋅ 10^9). It is guaranteed that all a_i are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d).
|
| 15 |
+
|
| 16 |
+
The next q lines contain one integer each. The j-th line contains one integer b_j — the value of the j-th query (1 ≤ b_j ≤ 10^9).
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print q integers ans_j. The j-th integer must be equal to the answer on the j-th query. If Polycarp can't obtain the value b_j the answer to the j-th query is -1.
|
| 21 |
+
|
| 22 |
+
Example
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
5 4
|
| 27 |
+
2 4 8 2 4
|
| 28 |
+
8
|
| 29 |
+
5
|
| 30 |
+
14
|
| 31 |
+
10
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
1
|
| 37 |
+
-1
|
| 38 |
+
3
|
| 39 |
+
2
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 1003
|
| 43 |
+
- **Problem Index**: D
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 1600
|
| 46 |
+
- **Tags**: greedy
|
| 47 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 48 |
+
- **Memory Limit**: 256000000 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-0425/instruction.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1070_C. Cloud Computing
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day.
|
| 5 |
+
|
| 6 |
+
The cloud provider offers m tariff plans, the i-th tariff plan is characterized by the following parameters:
|
| 7 |
+
|
| 8 |
+
* l_i and r_i — the i-th tariff plan is available only on days from l_i to r_i, inclusive,
|
| 9 |
+
* c_i — the number of cores per day available for rent on the i-th tariff plan,
|
| 10 |
+
* p_i — the price of renting one core per day on the i-th tariff plan.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to c_i) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.
|
| 15 |
+
|
| 16 |
+
Find the minimum amount of money that Buber will pay for its work for n days from 1 to n. If on a day the total number of cores for all available tariff plans is strictly less than k, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly k cores this day.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
The first line of the input contains three integers n, k and m (1 ≤ n,k ≤ 10^6, 1 ≤ m ≤ 2⋅10^5) — the number of days to analyze, the desired daily number of cores, the number of tariff plans.
|
| 21 |
+
|
| 22 |
+
The following m lines contain descriptions of tariff plans, one description per line. Each line contains four integers l_i, r_i, c_i, p_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ c_i, p_i ≤ 10^6), where l_i and r_i are starting and finishing days of the i-th tariff plan, c_i — number of cores, p_i — price of a single core for daily rent on the i-th tariff plan.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print a single integer number — the minimal amount of money that Buber will pay.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
5 7 3
|
| 33 |
+
1 4 5 3
|
| 34 |
+
1 3 5 2
|
| 35 |
+
2 5 10 1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
44
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
7 13 5
|
| 46 |
+
2 3 10 7
|
| 47 |
+
3 5 10 10
|
| 48 |
+
1 2 10 6
|
| 49 |
+
4 5 10 9
|
| 50 |
+
3 4 10 8
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
462
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Input
|
| 59 |
+
|
| 60 |
+
4 100 3
|
| 61 |
+
3 3 2 5
|
| 62 |
+
1 1 3 2
|
| 63 |
+
2 4 4 4
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
64
|
| 69 |
+
|
| 70 |
+
## Contest Information
|
| 71 |
+
- **Contest ID**: 1070
|
| 72 |
+
- **Problem Index**: C
|
| 73 |
+
- **Points**: 0.0
|
| 74 |
+
- **Rating**: 2000
|
| 75 |
+
- **Tags**: data structures, greedy
|
| 76 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 77 |
+
- **Memory Limit**: 256000000 bytes
|
| 78 |
+
|
| 79 |
+
## Task
|
| 80 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0440/instruction.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1386_A. Colors
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a difference — so Linda always knows whether Archie has spotted the difference or not.
|
| 5 |
+
|
| 6 |
+
There is a new hair dye series in the market where all available colors are numbered by integers from 1 to N such that a smaller difference of the numerical values also means less visual difference.
|
| 7 |
+
|
| 8 |
+
Linda assumes that for these series there should be some critical color difference C (1 ≤ C ≤ N) for which Archie will notice color difference between the current color color_{new} and the previous color color_{prev} if \left|color_{new} - color_{prev}\right| ≥ C and will not if \left|color_{new} - color_{prev}\right| < C.
|
| 9 |
+
|
| 10 |
+
Now she has bought N sets of hair dye from the new series — one for each of the colors from 1 to N, and is ready to set up an experiment. Linda will change her hair color on a regular basis and will observe Archie's reaction — whether he will notice the color change or not. Since for the proper dye each set should be used completely, each hair color can be obtained no more than once.
|
| 11 |
+
|
| 12 |
+
Before the experiment, Linda was using a dye from a different series which is not compatible with the new one, so for the clearness of the experiment Archie's reaction to the first used color is meaningless.
|
| 13 |
+
|
| 14 |
+
Her aim is to find the precise value of C in a limited number of dyes. Write a program which finds the value of C by experimenting with the given N colors and observing Archie's reactions to color changes.
|
| 15 |
+
|
| 16 |
+
Interaction
|
| 17 |
+
|
| 18 |
+
This is an interactive task. In the beginning you are given a single integer T (1 ≤ T ≤ 100), the number of cases in the test.
|
| 19 |
+
|
| 20 |
+
For each test case, the input first contains a single integer — the value of N (1 < N ≤ 10^{18}). The value of C is kept secret by the grading system.
|
| 21 |
+
|
| 22 |
+
Then your program should make queries writing output in the following format: "? P", where P is an integer (1 ≤ P ≤ N) denoting the next color used. For each query the grading system gives an answer in the next line of the input. The answer is 1 if Archie notices the color difference between the last two colors and 0 otherwise. No two queries should have the same P value.
|
| 23 |
+
|
| 24 |
+
When your program determines C, it should output its value in the following format: "= C". The grading system will not respond to this output and will proceed with the next test case.
|
| 25 |
+
|
| 26 |
+
Your program may use at most 64 queries "?" for each test case to find the correct value of C.
|
| 27 |
+
|
| 28 |
+
To establish proper communication between your program and the grading system, you should flush the output stream after each query.
|
| 29 |
+
|
| 30 |
+
$$$\begin{array}{ll} Language & Command \\\ \hline C++ & std::cout << std::endl; \\\ Java & System.out.flush(); \\\ Python & sys.stdout.flush() \end{array}$$$ Flush commands
|
| 31 |
+
|
| 32 |
+
Note that std::endl writes a newline and flushes the stream.
|
| 33 |
+
|
| 34 |
+
It is possible to receive an "Output isn't correct" outcome even after printing a correct answer, if task constraints were violated during the communication. Violating the communication protocol itself may result in an "Execution killed" outcome.
|
| 35 |
+
|
| 36 |
+
Submitting user tests requires specifying an input file with the testcase parameters. The format of the input file is "T" in the first line, and then "N C" on a single line for each of the T cases.
|
| 37 |
+
|
| 38 |
+
Scoring
|
| 39 |
+
|
| 40 |
+
Subtasks:
|
| 41 |
+
|
| 42 |
+
1. (9 points) N ≤ 64
|
| 43 |
+
2. (13 points) N ≤ 125
|
| 44 |
+
3. (21 points) N ≤ 1000
|
| 45 |
+
4. (24 points) N ≤ 10^9
|
| 46 |
+
5. (33 points) No further constraints.
|
| 47 |
+
|
| 48 |
+
Example
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
1
|
| 54 |
+
|
| 55 |
+
7
|
| 56 |
+
|
| 57 |
+
1
|
| 58 |
+
|
| 59 |
+
1
|
| 60 |
+
|
| 61 |
+
0
|
| 62 |
+
|
| 63 |
+
0
|
| 64 |
+
|
| 65 |
+
1
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Output
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
? 2
|
| 73 |
+
|
| 74 |
+
? 7
|
| 75 |
+
|
| 76 |
+
? 4
|
| 77 |
+
|
| 78 |
+
? 1
|
| 79 |
+
|
| 80 |
+
? 5
|
| 81 |
+
|
| 82 |
+
= 4
|
| 83 |
+
|
| 84 |
+
Note
|
| 85 |
+
|
| 86 |
+
Comments to the example input line by line:
|
| 87 |
+
|
| 88 |
+
1. N = 7.
|
| 89 |
+
2. Answer to the first query is meaningless (can also be 0).
|
| 90 |
+
3. C ≤ 5.
|
| 91 |
+
4. 3 < C ≤ 5. It would be wise to check difference 4. However, this can not be done in the next query since 4 + 4 = 8 and 4 - 4 = 0 both are outside the allowed interval 1 ≤ P ≤ 7.
|
| 92 |
+
5. 3 < C ≤ 5.
|
| 93 |
+
6. 3 < C ≤ 4. Therefore, C = 4.
|
| 94 |
+
|
| 95 |
+
## Contest Information
|
| 96 |
+
- **Contest ID**: 1386
|
| 97 |
+
- **Problem Index**: A
|
| 98 |
+
- **Points**: 0.0
|
| 99 |
+
- **Rating**: 2700
|
| 100 |
+
- **Tags**: *special, binary search, constructive algorithms, interactive
|
| 101 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 102 |
+
- **Memory Limit**: 256000000 bytes
|
| 103 |
+
|
| 104 |
+
## Task
|
| 105 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0449/instruction.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 19_B. Checkout Assistant
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
4
|
| 19 |
+
2 10
|
| 20 |
+
0 20
|
| 21 |
+
1 5
|
| 22 |
+
1 3
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
8
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
3
|
| 33 |
+
0 1
|
| 34 |
+
0 10
|
| 35 |
+
0 100
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
111
|
| 41 |
+
|
| 42 |
+
## Contest Information
|
| 43 |
+
- **Contest ID**: 19
|
| 44 |
+
- **Problem Index**: B
|
| 45 |
+
- **Points**: 0.0
|
| 46 |
+
- **Rating**: 1900
|
| 47 |
+
- **Tags**: dp
|
| 48 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 49 |
+
- **Memory Limit**: 256000000 bytes
|
| 50 |
+
|
| 51 |
+
## Task
|
| 52 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0471/instruction.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 720_C. Homework
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Today Peter has got an additional homework for tomorrow. The teacher has given three integers to him: n, m and k, and asked him to mark one or more squares on a square grid of size n × m.
|
| 5 |
+
|
| 6 |
+
The marked squares must form a connected figure, and there must be exactly k triples of marked squares that form an L-shaped tromino — all three squares are inside a 2 × 2 square.
|
| 7 |
+
|
| 8 |
+
The set of squares forms a connected figure if it is possible to get from any square to any other one if you are allowed to move from a square to any adjacent by a common side square.
|
| 9 |
+
|
| 10 |
+
Peter cannot fulfill the task, so he asks you for help. Help him to create such figure.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
Input data contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100).
|
| 15 |
+
|
| 16 |
+
Each of the following t test cases is described by a line that contains three integers: n, m and k (3 ≤ n, m, n × m ≤ 105, 0 ≤ k ≤ 109).
|
| 17 |
+
|
| 18 |
+
The sum of values of n × m for all tests in one input data doesn't exceed 105.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
For each test case print the answer.
|
| 23 |
+
|
| 24 |
+
If it is possible to create such figure, print n lines, m characters each, use asterisk '*' to denote the marked square, and dot '.' to denote the unmarked one.
|
| 25 |
+
|
| 26 |
+
If there is no solution, print -1.
|
| 27 |
+
|
| 28 |
+
Print empty line between test cases.
|
| 29 |
+
|
| 30 |
+
Example
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
3 3 4
|
| 36 |
+
3 3 5
|
| 37 |
+
3 3 3
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
.*.
|
| 43 |
+
***
|
| 44 |
+
.*.
|
| 45 |
+
|
| 46 |
+
**.
|
| 47 |
+
**.
|
| 48 |
+
*..
|
| 49 |
+
|
| 50 |
+
.*.
|
| 51 |
+
***
|
| 52 |
+
*..
|
| 53 |
+
|
| 54 |
+
## Contest Information
|
| 55 |
+
- **Contest ID**: 720
|
| 56 |
+
- **Problem Index**: C
|
| 57 |
+
- **Points**: 0.0
|
| 58 |
+
- **Rating**: 3100
|
| 59 |
+
- **Tags**: constructive algorithms
|
| 60 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 61 |
+
- **Memory Limit**: 256000000 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-0476/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 835_A. Key races
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.
|
| 5 |
+
|
| 6 |
+
If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:
|
| 7 |
+
|
| 8 |
+
1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
|
| 9 |
+
2. Right after that he starts to type it.
|
| 10 |
+
3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.
|
| 15 |
+
|
| 16 |
+
Given the length of the text and the information about participants, determine the result of the game.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
5 1 2 1 2
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
First
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
3 3 1 1 1
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
Second
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
4 5 3 1 5
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
Friendship
|
| 56 |
+
|
| 57 |
+
Note
|
| 58 |
+
|
| 59 |
+
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
|
| 60 |
+
|
| 61 |
+
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.
|
| 62 |
+
|
| 63 |
+
In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw.
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 835
|
| 67 |
+
- **Problem Index**: A
|
| 68 |
+
- **Points**: 500.0
|
| 69 |
+
- **Rating**: 800
|
| 70 |
+
- **Tags**: math
|
| 71 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 72 |
+
- **Memory Limit**: 256000000 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-0477/instruction.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 855_D. Rowena Ravenclaw's Diadem
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.
|
| 5 |
+
|
| 6 |
+
Harry thought that Riddle would have assumed that he was the only one to discover the Room of Requirement and thus, would have hidden it there. So Harry is trying to get inside the Room of Requirement to destroy the diadem as he knows that it is a horcrux.
|
| 7 |
+
|
| 8 |
+
But he has to answer a puzzle in order to enter the room. He is given n objects, numbered from 1 to n. Some of the objects have a parent object, that has a lesser number. Formally, object i may have a parent object parenti such that parenti < i.
|
| 9 |
+
|
| 10 |
+
There is also a type associated with each parent relation, it can be either of type 1 or type 2. Type 1 relation means that the child object is like a special case of the parent object. Type 2 relation means that the second object is always a part of the first object and all its special cases.
|
| 11 |
+
|
| 12 |
+
Note that if an object b is a special case of object a, and c is a special case of object b, then c is considered to be a special case of object a as well. The same holds for parts: if object b is a part of a, and object c is a part of b, then we say that object c is a part of a. Also note, that if object b is a part of a, and object c is a special case of a, then b is a part of c as well.
|
| 13 |
+
|
| 14 |
+
An object is considered to be neither a part of itself nor a special case of itself.
|
| 15 |
+
|
| 16 |
+
Now, Harry has to answer two type of queries:
|
| 17 |
+
|
| 18 |
+
* 1 u v: he needs to tell if object v is a special case of object u.
|
| 19 |
+
* 2 u v: he needs to tell if object v is a part of object u.
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
First line of input contains the number n (1 ≤ n ≤ 105), the number of objects.
|
| 24 |
+
|
| 25 |
+
Next n lines contain two integer parenti and typei ( - 1 ≤ parenti < i parenti ≠ 0, - 1 ≤ typei ≤ 1), implying that the i-th object has the parent parenti. (If typei = 0, this implies that the object i is a special case of object parenti. If typei = 1, this implies that the object i is a part of object parenti). In case the i-th object has no parent, both parenti and typei are -1.
|
| 26 |
+
|
| 27 |
+
Next line contains an integer q (1 ≤ q ≤ 105), the number of queries.
|
| 28 |
+
|
| 29 |
+
Next q lines each represent a query having three space separated integers typei, ui, vi (1 ≤ typei ≤ 2, 1 ≤ u, v ≤ n).
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
Output will contain q lines, each containing the answer for the corresponding query as "YES" (affirmative) or "NO" (without quotes).
|
| 34 |
+
|
| 35 |
+
You can output each letter in any case (upper or lower).
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
3
|
| 42 |
+
-1 -1
|
| 43 |
+
1 0
|
| 44 |
+
2 0
|
| 45 |
+
2
|
| 46 |
+
1 1 3
|
| 47 |
+
2 1 3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
YES
|
| 53 |
+
NO
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
3
|
| 59 |
+
-1 -1
|
| 60 |
+
1 0
|
| 61 |
+
1 1
|
| 62 |
+
2
|
| 63 |
+
2 2 3
|
| 64 |
+
2 3 2
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
YES
|
| 70 |
+
NO
|
| 71 |
+
|
| 72 |
+
Note
|
| 73 |
+
|
| 74 |
+
In test case 1, as object 2 is a special case of object 1 and object 3 is a special case of object 2, this makes object 3 a special case of object 1.
|
| 75 |
+
|
| 76 |
+
In test case 2, as object 2 is a special case of object 1 and object 1 has object 3, this will mean that object 2 will also have object 3. This is because when a general case (object 1) has object 3, its special case (object 2) will definitely have object 3.
|
| 77 |
+
|
| 78 |
+
## Contest Information
|
| 79 |
+
- **Contest ID**: 855
|
| 80 |
+
- **Problem Index**: D
|
| 81 |
+
- **Points**: 2000.0
|
| 82 |
+
- **Rating**: 2500
|
| 83 |
+
- **Tags**: trees
|
| 84 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 85 |
+
- **Memory Limit**: 256000000 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-0478/instruction.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 87_B. Vasya and Types
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully understand the statement, please read the language's description below carefully and follow it and not the similar rules in real programming languages.
|
| 5 |
+
|
| 6 |
+
There is a very powerful system of pointers on &K* — you can add an asterisk to the right of the existing type X — that will result in new type X * . That is called pointer-definition operation. Also, there is the operation that does the opposite — to any type of X, which is a pointer, you can add an ampersand — that will result in a type &X, to which refers X. That is called a dereference operation.
|
| 7 |
+
|
| 8 |
+
The &K* language has only two basic data types — void and errtype. Also, the language has operators typedef and typeof.
|
| 9 |
+
|
| 10 |
+
* The operator "typedef A B" defines a new data type B, which is equivalent to A. A can have asterisks and ampersands, and B cannot have them. For example, the operator typedef void** ptptvoid will create a new type ptptvoid, that can be used as void**.
|
| 11 |
+
* The operator "typeof A" returns type of A, brought to void, that is, returns the type void**...*, equivalent to it with the necessary number of asterisks (the number can possibly be zero). That is, having defined the ptptvoid type, as shown above, the typeof ptptvoid operator will return void**.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
An attempt of dereferencing of the void type will lead to an error: to a special data type errtype. For errtype the following equation holds true: errtype* = &errtype = errtype. An attempt to use the data type that hasn't been defined before that will also lead to the errtype.
|
| 16 |
+
|
| 17 |
+
Using typedef, we can define one type several times. Of all the definitions only the last one is valid. However, all the types that have been defined earlier using this type do not change.
|
| 18 |
+
|
| 19 |
+
Let us also note that the dereference operation has the lower priority that the pointer operation, in other words &T * is always equal to T.
|
| 20 |
+
|
| 21 |
+
Note, that the operators are executed consecutively one by one. If we have two operators "typedef &void a" and "typedef a* b", then at first a becomes errtype, and after that b becomes errtype* = errtype, but not &void* = void (see sample 2).
|
| 22 |
+
|
| 23 |
+
Vasya does not yet fully understand this powerful technology, that's why he asked you to help him. Write a program that analyzes these operators.
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
The first line contains an integer n (1 ≤ n ≤ 100) — the number of operators. Then follow n lines with operators. Each operator is of one of two types: either "typedef A B", or "typeof A". In the first case the B type differs from void and errtype types, and besides, doesn't have any asterisks and ampersands.
|
| 28 |
+
|
| 29 |
+
All the data type names are non-empty lines of no more than 20 lowercase Latin letters. The number of asterisks and ampersands separately in one type in any operator does not exceed 10, however if we bring some types to void with several asterisks, their number may exceed 10.
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
For every typeof operator print on the single line the answer to that operator — the type that the given operator returned.
|
| 34 |
+
|
| 35 |
+
Examples
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
5
|
| 40 |
+
typedef void* ptv
|
| 41 |
+
typeof ptv
|
| 42 |
+
typedef &&ptv node
|
| 43 |
+
typeof node
|
| 44 |
+
typeof &ptv
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
void*
|
| 50 |
+
errtype
|
| 51 |
+
void
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
17
|
| 57 |
+
typedef void* b
|
| 58 |
+
typedef b* c
|
| 59 |
+
typeof b
|
| 60 |
+
typeof c
|
| 61 |
+
typedef &b b
|
| 62 |
+
typeof b
|
| 63 |
+
typeof c
|
| 64 |
+
typedef &&b* c
|
| 65 |
+
typeof c
|
| 66 |
+
typedef &b* c
|
| 67 |
+
typeof c
|
| 68 |
+
typedef &void b
|
| 69 |
+
typeof b
|
| 70 |
+
typedef b******* c
|
| 71 |
+
typeof c
|
| 72 |
+
typedef &&b* c
|
| 73 |
+
typeof c
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Output
|
| 77 |
+
|
| 78 |
+
void*
|
| 79 |
+
void**
|
| 80 |
+
void
|
| 81 |
+
void**
|
| 82 |
+
errtype
|
| 83 |
+
void
|
| 84 |
+
errtype
|
| 85 |
+
errtype
|
| 86 |
+
errtype
|
| 87 |
+
|
| 88 |
+
Note
|
| 89 |
+
|
| 90 |
+
Let's look at the second sample.
|
| 91 |
+
|
| 92 |
+
After the first two queries typedef the b type is equivalent to void*, and с — to void**.
|
| 93 |
+
|
| 94 |
+
The next query typedef redefines b — it is now equal to &b = &void* = void. At that, the с type doesn't change.
|
| 95 |
+
|
| 96 |
+
After that the с type is defined as &&b* = &&void* = &void = errtype. It doesn't influence the b type, that's why the next typedef defines c as &void* = void.
|
| 97 |
+
|
| 98 |
+
Then the b type is again redefined as &void = errtype.
|
| 99 |
+
|
| 100 |
+
Please note that the c type in the next query is defined exactly as errtype******* = errtype, and not &void******* = void******. The same happens in the last typedef.
|
| 101 |
+
|
| 102 |
+
## Contest Information
|
| 103 |
+
- **Contest ID**: 87
|
| 104 |
+
- **Problem Index**: B
|
| 105 |
+
- **Points**: 1000.0
|
| 106 |
+
- **Rating**: 1800
|
| 107 |
+
- **Tags**: implementation, strings
|
| 108 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 109 |
+
- **Memory Limit**: 256000000 bytes
|
| 110 |
+
|
| 111 |
+
## Task
|
| 112 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0482/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 980_E. The Number Games
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
|
| 5 |
+
|
| 6 |
+
The nation has n districts numbered from 1 to n, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district i is equal to 2^i.
|
| 7 |
+
|
| 8 |
+
This year, the president decided to reduce the costs. He wants to remove k contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
|
| 9 |
+
|
| 10 |
+
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
|
| 11 |
+
|
| 12 |
+
Which contestants should the president remove?
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of input contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
|
| 17 |
+
|
| 18 |
+
The next n-1 lines each contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b), that describe a road that connects two different districts a and b in the nation. It is guaranteed that there is exactly one path between every two districts.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print k space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
6 3
|
| 29 |
+
2 1
|
| 30 |
+
2 6
|
| 31 |
+
4 2
|
| 32 |
+
5 6
|
| 33 |
+
2 3
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
1 3 4
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
8 4
|
| 44 |
+
2 6
|
| 45 |
+
2 7
|
| 46 |
+
7 8
|
| 47 |
+
1 2
|
| 48 |
+
3 1
|
| 49 |
+
2 4
|
| 50 |
+
7 5
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
1 3 4 5
|
| 56 |
+
|
| 57 |
+
Note
|
| 58 |
+
|
| 59 |
+
In the first sample, the maximum possible total number of fans is 2^2 + 2^5 + 2^6 = 100. We can achieve it by removing the contestants of the districts 1, 3, and 4.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 980
|
| 63 |
+
- **Problem Index**: E
|
| 64 |
+
- **Points**: 2500.0
|
| 65 |
+
- **Rating**: 2200
|
| 66 |
+
- **Tags**: data structures, greedy, trees
|
| 67 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 256000000 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-0483/instruction.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 9_E. Interesting Graph and Apples
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A funny ring is a cycle that goes through all the vertices just once. Moreover, loops are funny rings too.
|
| 5 |
+
|
| 6 |
+
She has already drawn the apples and some of the graph edges. But now it is not clear, how to connect the rest of the vertices to get an interesting graph as a result. The answer should contain the minimal amount of added edges. And furthermore, the answer should be the lexicographically smallest one. The set of edges (x1, y1), (x2, y2), ..., (xn, yn), where xi ≤ yi, is lexicographically smaller than the set (u1, v1), (u2, v2), ..., (un, vn), where ui ≤ vi, provided that the sequence of integers x1, y1, x2, y2, ..., xn, yn is lexicographically smaller than the sequence u1, v1, u2, v2, ..., un, vn. If you do not cope, Hexadecimal will eat you. ...eat you alive.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of the input data contains a pair of integers n and m (1 ≤ n ≤ 50, 0 ≤ m ≤ 2500) — the amount of vertices and edges respectively. The following lines contain pairs of numbers xi and yi (1 ≤ xi, yi ≤ n) — the vertices that are already connected by edges. The initial graph may contain multiple edges and loops.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
In the first line output «YES» or «NO»: if it is possible or not to construct an interesting graph. If the answer is «YES», in the second line output k — the amount of edges that should be added to the initial graph. Finally, output k lines: pairs of vertices xj and yj, between which edges should be drawn. The result may contain multiple edges and loops. k can be equal to zero.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
3 2
|
| 21 |
+
1 2
|
| 22 |
+
2 3
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
YES
|
| 28 |
+
1
|
| 29 |
+
1 3
|
| 30 |
+
|
| 31 |
+
## Contest Information
|
| 32 |
+
- **Contest ID**: 9
|
| 33 |
+
- **Problem Index**: E
|
| 34 |
+
- **Points**: 0.0
|
| 35 |
+
- **Rating**: 2300
|
| 36 |
+
- **Tags**: dfs and similar, dsu, graphs
|
| 37 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 38 |
+
- **Memory Limit**: 64000000 bytes
|
| 39 |
+
|
| 40 |
+
## Task
|
| 41 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0484/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# bhavanas-and-bhuvanas-bet
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Bhavana and Bhuvana place bet every time they see something interesting that can occur with a probability 0.5.
|
| 5 |
+
Both of them place a bet for a higher amount which they don’t posses at that time. But when one wins she demands other for the bet amount. For example if Bhuvana wins she asks bhavana for the bet amount.
|
| 6 |
+
But Bhavana is unable to pay the amount on that day, so she comes up with this ingenious idea to give a small unit of milky bar worth Rs.1 to Bhuvana on day 1. Another unit on day 2 (worth Rs 1 again). So on till ‘N’ days.
|
| 7 |
+
On Nth day she pays the whole of the bet amount (i.e Rs N) and takes back all her chocolate pieces. As Bhavana is a possessive girl, she doesn’t want to make N pieces of her chocolate bar, so help Bhavana to make the minimum number of cuts in the chocolate bar that she can mortgage for the bet amount.
|
| 8 |
+
|
| 9 |
+
Input
|
| 10 |
+
First line contains T number of bets that are placed.
|
| 11 |
+
Next T lines contain the amount to be paid which is equal to the length of the chocolate.
|
| 12 |
+
|
| 13 |
+
Output
|
| 14 |
+
An integer indicating the minimum number of cuts to be made in the chocolate for each test case in a new line
|
| 15 |
+
|
| 16 |
+
Constraints
|
| 17 |
+
1 ≤ T ≤ 10^5
|
| 18 |
+
1 ≤ N<2^64
|
| 19 |
+
|
| 20 |
+
Sample Input
|
| 21 |
+
2
|
| 22 |
+
3
|
| 23 |
+
10
|
| 24 |
+
|
| 25 |
+
Sample Output
|
| 26 |
+
1
|
| 27 |
+
3
|
| 28 |
+
Explanation:-
|
| 29 |
+
Test case: 1
|
| 30 |
+
She needs to make only one cut to divide the chocolate into two parts one of 1 unit (rs 1) another of 2units(rs 2).
|
| 31 |
+
On day one she gives one piece of rs1. On day 2 she takes the piece which is of rs 1 and gives the piece which is of Rs 2. So at the end of day 2 bhuvana has rs2 worth chocolate. On day3 bhavana repays the money and takes the chocolate back.
|
| 32 |
+
Test case: 2
|
| 33 |
+
Bhavana needs to make 3 cuts so that the chocolate bar is divided into pieces worth rs1, rs2, rs3, rs4.
|
| 34 |
+
|
| 35 |
+
Day1- give rs1 worth chocolate.
|
| 36 |
+
Day2- take back rs1 worth chocolate, give rs2 worth chocolate.
|
| 37 |
+
Day3- take back rs2 worth chocolate, give rs3 worth chocolate.
|
| 38 |
+
Day4- take back rs3 worth chocolate, give rs4 worth chocolate.
|
| 39 |
+
Day5-give rs1 worth chocolate (which u took back on day1)(so now bhuvana has 4+1=5).
|
| 40 |
+
Day6-now take back rs1 worth chocolate. Give rs2 worth chocolate (4+2=6)
|
| 41 |
+
Day7-take back rs2 worth chocolate. Give rs3 worth chocolate (4+3=7)
|
| 42 |
+
Day8-give rs1 worth chocolate (took back on day 6)(4+3+1=8)
|
| 43 |
+
Day9-take back rs1 worth chocolate. Give rs2 worth chocolate (4+3+2=9)
|
| 44 |
+
Day10-repay the money and take chocolate pieces back
|
| 45 |
+
|
| 46 |
+
SAMPLE INPUT
|
| 47 |
+
2
|
| 48 |
+
3
|
| 49 |
+
10
|
| 50 |
+
|
| 51 |
+
SAMPLE OUTPUT
|
| 52 |
+
1
|
| 53 |
+
3
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 0
|
| 57 |
+
- **Problem Index**:
|
| 58 |
+
- **Points**: 0.0
|
| 59 |
+
- **Rating**: 0
|
| 60 |
+
- **Tags**: None
|
| 61 |
+
- **Time Limit**: None seconds
|
| 62 |
+
- **Memory Limit**: 0 bytes
|
| 63 |
+
|
| 64 |
+
## Task
|
| 65 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0485/instruction.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# cost-of-data-11
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Strings can be efficiently stored as a data structure, to have efficient searching methods.
|
| 5 |
+
A new startup is going to use this method, but they don't have much space. So they want to check beforehand how much memory will be required for their data.
|
| 6 |
+
Following method describes the way in which this startup's engineers save the data in the structure.
|
| 7 |
+
|
| 8 |
+
Suppose they have 5 strings/words: et,eq,bd,be,bdp
|
| 9 |
+
A empty node is kept NULL, and strings are inserted into the structure one by one.
|
| 10 |
+
Initially the structure is this:
|
| 11 |
+
|
| 12 |
+
NULL
|
| 13 |
+
|
| 14 |
+
After inserting "et", the structure is this:
|
| 15 |
+
|
| 16 |
+
NULL
|
| 17 |
+
|
|
| 18 |
+
e
|
| 19 |
+
|
|
| 20 |
+
t
|
| 21 |
+
|
| 22 |
+
After inserting "eq", the structure is this:
|
| 23 |
+
|
| 24 |
+
NULL
|
| 25 |
+
/
|
| 26 |
+
e
|
| 27 |
+
/ \
|
| 28 |
+
t q
|
| 29 |
+
|
| 30 |
+
After inserting "bd", the structure is this:
|
| 31 |
+
|
| 32 |
+
NULL
|
| 33 |
+
/ \
|
| 34 |
+
e b
|
| 35 |
+
/ \ \
|
| 36 |
+
t q d
|
| 37 |
+
|
| 38 |
+
After inserting "be", the structure is this:
|
| 39 |
+
|
| 40 |
+
NULL
|
| 41 |
+
/ \
|
| 42 |
+
e b
|
| 43 |
+
/ \ / \
|
| 44 |
+
t q e d
|
| 45 |
+
|
| 46 |
+
After inserting "bdp", the structure is this:
|
| 47 |
+
|
| 48 |
+
NULL
|
| 49 |
+
/ \
|
| 50 |
+
e b
|
| 51 |
+
/ \ / \
|
| 52 |
+
t q e d
|
| 53 |
+
\
|
| 54 |
+
p
|
| 55 |
+
|
| 56 |
+
Therefore a total of 8 nodes are used here.
|
| 57 |
+
|
| 58 |
+
Input:
|
| 59 |
+
First line contains N, the number of strings they have.
|
| 60 |
+
Each of the next N lines contain one string. Each string consists only of lowercase letters.
|
| 61 |
+
|
| 62 |
+
Output:
|
| 63 |
+
Print the required number of nodes.
|
| 64 |
+
|
| 65 |
+
**Constraints:
|
| 66 |
+
1 ≤ N ≤ 10^5
|
| 67 |
+
Length of each string ≤ 30
|
| 68 |
+
|
| 69 |
+
Note: No two strings are same, though one string could be prefix of another.
|
| 70 |
+
|
| 71 |
+
SAMPLE INPUT
|
| 72 |
+
5
|
| 73 |
+
et
|
| 74 |
+
eq
|
| 75 |
+
bd
|
| 76 |
+
be
|
| 77 |
+
bdp
|
| 78 |
+
|
| 79 |
+
SAMPLE OUTPUT
|
| 80 |
+
8
|
| 81 |
+
|
| 82 |
+
## Contest Information
|
| 83 |
+
- **Contest ID**: 0
|
| 84 |
+
- **Problem Index**:
|
| 85 |
+
- **Points**: 0.0
|
| 86 |
+
- **Rating**: 0
|
| 87 |
+
- **Tags**: None
|
| 88 |
+
- **Time Limit**: None seconds
|
| 89 |
+
- **Memory Limit**: 0 bytes
|
| 90 |
+
|
| 91 |
+
## Task
|
| 92 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0550/instruction.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1511_F. Chainword
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A chainword is a special type of crossword. As most of the crosswords do, it has cells that you put the letters in and some sort of hints to what these letters should be.
|
| 5 |
+
|
| 6 |
+
The letter cells in a chainword are put in a single row. We will consider chainwords of length m in this task.
|
| 7 |
+
|
| 8 |
+
A hint to a chainword is a sequence of segments such that the segments don't intersect with each other and cover all m letter cells. Each segment contains a description of the word in the corresponding cells.
|
| 9 |
+
|
| 10 |
+
The twist is that there are actually two hints: one sequence is the row above the letter cells and the other sequence is the row below the letter cells. When the sequences are different, they provide a way to resolve the ambiguity in the answers.
|
| 11 |
+
|
| 12 |
+
You are provided with a dictionary of n words, each word consists of lowercase Latin letters. All words are pairwise distinct.
|
| 13 |
+
|
| 14 |
+
An instance of a chainword is the following triple:
|
| 15 |
+
|
| 16 |
+
* a string of m lowercase Latin letters;
|
| 17 |
+
* the first hint: a sequence of segments such that the letters that correspond to each segment spell a word from the dictionary;
|
| 18 |
+
* the second hint: another sequence of segments such that the letters that correspond to each segment spell a word from the dictionary.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Note that the sequences of segments don't necessarily have to be distinct.
|
| 23 |
+
|
| 24 |
+
Two instances of chainwords are considered different if they have different strings, different first hints or different second hints.
|
| 25 |
+
|
| 26 |
+
Count the number of different instances of chainwords. Since the number might be pretty large, output it modulo 998 244 353.
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
The first line contains two integers n and m (1 ≤ n ≤ 8, 1 ≤ m ≤ 10^9) — the number of words in the dictionary and the number of letter cells.
|
| 31 |
+
|
| 32 |
+
Each of the next n lines contains a word — a non-empty string of no more than 5 lowercase Latin letters. All words are pairwise distinct.
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
Print a single integer — the number of different instances of chainwords of length m for the given dictionary modulo 998 244 353.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
3 5
|
| 44 |
+
ababa
|
| 45 |
+
ab
|
| 46 |
+
a
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
11
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Input
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
2 4
|
| 59 |
+
ab
|
| 60 |
+
cd
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
4
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Input
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
5 100
|
| 73 |
+
a
|
| 74 |
+
aa
|
| 75 |
+
aaa
|
| 76 |
+
aaaa
|
| 77 |
+
aaaaa
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Output
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
142528942
|
| 84 |
+
|
| 85 |
+
Note
|
| 86 |
+
|
| 87 |
+
Here are all the instances of the valid chainwords for the first example:
|
| 88 |
+
|
| 89 |
+
<image>
|
| 90 |
+
|
| 91 |
+
The red lines above the letters denote the segments of the first hint, the blue lines below the letters denote the segments of the second hint.
|
| 92 |
+
|
| 93 |
+
In the second example the possible strings are: "abab", "abcd", "cdab" and "cdcd". All the hints are segments that cover the first two letters and the last two letters.
|
| 94 |
+
|
| 95 |
+
## Contest Information
|
| 96 |
+
- **Contest ID**: 1511
|
| 97 |
+
- **Problem Index**: F
|
| 98 |
+
- **Points**: 0.0
|
| 99 |
+
- **Rating**: 2700
|
| 100 |
+
- **Tags**: brute force, data structures, dp, matrices, string suffix structures, strings
|
| 101 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 102 |
+
- **Memory Limit**: 256000000 bytes
|
| 103 |
+
|
| 104 |
+
## Task
|
| 105 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0610/instruction.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00313 Secret Investigation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
|
| 5 |
+
|
| 6 |
+
* Those who do not belong to the organization $ A $ and who own the product $ C $.
|
| 7 |
+
* A person who belongs to the organization $ B $ and owns the product $ C $.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
A program that calculates the number of people who meet the conditions when the identification number of the person who belongs to the organization $ A $, the person who belongs to the organization $ B $, and the person who owns the product $ C $ is given as input. Create. However, be careful not to count duplicate people who meet both conditions.
|
| 12 |
+
|
| 13 |
+
(Supplement: Regarding the above conditions)
|
| 14 |
+
Let $ A $, $ B $, and $ C $ be the sets of some elements selected from the set of natural numbers from 1 to $ N $. The number of people who satisfy the condition is the number of elements that satisfy $ (\ bar {A} \ cap C) \ cup (B \ cap C) $ (painted part in the figure). However, $ \ bar {A} $ is a complement of the set $ A $.
|
| 15 |
+
|
| 16 |
+
<image>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
The input is given in the following format.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
N
|
| 26 |
+
X a1 a2 ... aX
|
| 27 |
+
Y b1 b2 ... bY
|
| 28 |
+
Z c1 c2 ... cZ
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
The input is 4 lines, and the number of people to be surveyed N (1 ≤ N ≤ 100) is given in the first line. On the second line, the number X (0 ≤ X ≤ N) of those who belong to the organization $ A $, followed by the identification number ai (1 ≤ ai ≤ N) of those who belong to the organization $ A $. Given. On the third line, the number Y (0 ≤ Y ≤ N) of those who belong to the organization $ B $, followed by the identification number bi (1 ≤ bi ≤ N) of those who belong to the organization $ B $. Given. On the fourth line, the number Z (0 ≤ Z ≤ N) of the person who owns the product $ C $, followed by the identification number ci (1 ≤ ci ≤ N) of the person who owns the product $ C $. ) Is given.
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
Output the number of people who meet the conditions on one line.
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
5
|
| 42 |
+
3 1 2 3
|
| 43 |
+
2 4 5
|
| 44 |
+
2 3 4
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
1
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
100
|
| 55 |
+
3 1 100 4
|
| 56 |
+
0
|
| 57 |
+
2 2 3
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
2
|
| 63 |
+
|
| 64 |
+
## Contest Information
|
| 65 |
+
- **Contest ID**: 0
|
| 66 |
+
- **Problem Index**:
|
| 67 |
+
- **Points**: 0.0
|
| 68 |
+
- **Rating**: 0
|
| 69 |
+
- **Tags**:
|
| 70 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 71 |
+
- **Memory Limit**: 268435456 bytes
|
| 72 |
+
|
| 73 |
+
## Task
|
| 74 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|