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-0000/instruction.md +51 -0
- code_contests-0007/instruction.md +124 -0
- code_contests-0025/instruction.md +89 -0
- code_contests-0030/instruction.md +79 -0
- code_contests-0031/instruction.md +69 -0
- code_contests-0036/instruction.md +53 -0
- code_contests-0038/instruction.md +88 -0
- code_contests-0047/instruction.md +75 -0
- code_contests-0053/instruction.md +60 -0
- code_contests-0054/instruction.md +67 -0
- code_contests-0062/instruction.md +70 -0
- code_contests-0065/instruction.md +66 -0
- code_contests-0078/instruction.md +90 -0
- code_contests-0098/instruction.md +100 -0
- code_contests-0203/instruction.md +133 -0
- code_contests-0210/instruction.md +57 -0
- code_contests-0217/instruction.md +79 -0
- code_contests-0226/instruction.md +81 -0
- code_contests-0228/instruction.md +74 -0
- code_contests-0235/instruction.md +72 -0
- code_contests-0257/instruction.md +75 -0
- code_contests-0261/instruction.md +69 -0
- code_contests-0266/instruction.md +65 -0
- code_contests-0268/instruction.md +59 -0
- code_contests-0281/instruction.md +45 -0
- code_contests-0292/instruction.md +83 -0
- code_contests-0401/instruction.md +78 -0
- code_contests-0406/instruction.md +119 -0
- code_contests-0408/instruction.md +127 -0
- code_contests-0423/instruction.md +75 -0
- code_contests-0430/instruction.md +107 -0
- code_contests-0437/instruction.md +56 -0
- code_contests-0439/instruction.md +54 -0
- code_contests-0441/instruction.md +107 -0
- code_contests-0448/instruction.md +79 -0
- code_contests-0455/instruction.md +89 -0
- code_contests-0463/instruction.md +47 -0
- code_contests-0464/instruction.md +71 -0
- code_contests-0470/instruction.md +84 -0
- code_contests-0479/instruction.md +79 -0
- code_contests-0499/instruction.md +67 -0
- code_contests-0602/instruction.md +109 -0
- code_contests-0605/instruction.md +97 -0
- code_contests-0611/instruction.md +56 -0
- code_contests-0642/instruction.md +80 -0
- code_contests-0651/instruction.md +57 -0
- code_contests-0656/instruction.md +65 -0
- code_contests-0658/instruction.md +65 -0
- code_contests-0660/instruction.md +61 -0
- code_contests-0666/instruction.md +32 -0
code_contests-0000/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# brcktsrm
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem description.
|
| 5 |
+
Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship.
|
| 6 |
+
|
| 7 |
+
Input
|
| 8 |
+
|
| 9 |
+
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
|
| 10 |
+
The first line of each test case contains a single string S denoting the string to be checked.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Output
|
| 14 |
+
|
| 15 |
+
For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not .
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
|
| 20 |
+
1 ≤ T ≤ 10
|
| 21 |
+
1 ≤ length of S ≤ 60
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Example
|
| 25 |
+
Input:
|
| 26 |
+
3
|
| 27 |
+
((()))
|
| 28 |
+
(())()
|
| 29 |
+
()(()
|
| 30 |
+
|
| 31 |
+
Output:
|
| 32 |
+
YES
|
| 33 |
+
YES
|
| 34 |
+
NO
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Explanation
|
| 39 |
+
Example is self-explanatory.
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 0
|
| 43 |
+
- **Problem Index**:
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 0
|
| 46 |
+
- **Tags**: None
|
| 47 |
+
- **Time Limit**: None seconds
|
| 48 |
+
- **Memory Limit**: 0 bytes
|
| 49 |
+
|
| 50 |
+
## Task
|
| 51 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0007/instruction.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1037_E. Trips
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
|
| 5 |
+
|
| 6 |
+
We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:
|
| 7 |
+
|
| 8 |
+
* Either this person does not go on the trip,
|
| 9 |
+
* Or at least k of his friends also go on the trip.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Note that the friendship is not transitive. That is, if a and b are friends and b and c are friends, it does not necessarily imply that a and c are friends.
|
| 14 |
+
|
| 15 |
+
For each day, find the maximum number of people that can go on the trip on that day.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The first line contains three integers n, m, and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5, 1 ≤ k < n) — the number of people, the number of days and the number of friends each person on the trip should have in the group.
|
| 20 |
+
|
| 21 |
+
The i-th (1 ≤ i ≤ m) of the next m lines contains two integers x and y (1≤ x, y≤ n, x≠ y), meaning that persons x and y become friends on the morning of day i. It is guaranteed that x and y were not friends before.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
Print exactly m lines, where the i-th of them (1≤ i≤ m) contains the maximum number of people that can go on the trip on the evening of the day i.
|
| 26 |
+
|
| 27 |
+
Examples
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
4 4 2
|
| 32 |
+
2 3
|
| 33 |
+
1 2
|
| 34 |
+
1 3
|
| 35 |
+
1 4
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
0
|
| 41 |
+
0
|
| 42 |
+
3
|
| 43 |
+
3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
5 8 2
|
| 49 |
+
2 1
|
| 50 |
+
4 2
|
| 51 |
+
5 4
|
| 52 |
+
5 2
|
| 53 |
+
4 3
|
| 54 |
+
5 1
|
| 55 |
+
4 1
|
| 56 |
+
3 2
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
0
|
| 62 |
+
0
|
| 63 |
+
0
|
| 64 |
+
3
|
| 65 |
+
3
|
| 66 |
+
4
|
| 67 |
+
4
|
| 68 |
+
5
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Input
|
| 72 |
+
|
| 73 |
+
5 7 2
|
| 74 |
+
1 5
|
| 75 |
+
3 2
|
| 76 |
+
2 5
|
| 77 |
+
3 4
|
| 78 |
+
1 2
|
| 79 |
+
5 3
|
| 80 |
+
1 3
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
Output
|
| 84 |
+
|
| 85 |
+
0
|
| 86 |
+
0
|
| 87 |
+
0
|
| 88 |
+
0
|
| 89 |
+
3
|
| 90 |
+
4
|
| 91 |
+
4
|
| 92 |
+
|
| 93 |
+
Note
|
| 94 |
+
|
| 95 |
+
In the first example,
|
| 96 |
+
|
| 97 |
+
* 1,2,3 can go on day 3 and 4.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
In the second example,
|
| 102 |
+
|
| 103 |
+
* 2,4,5 can go on day 4 and 5.
|
| 104 |
+
* 1,2,4,5 can go on day 6 and 7.
|
| 105 |
+
* 1,2,3,4,5 can go on day 8.
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
In the third example,
|
| 110 |
+
|
| 111 |
+
* 1,2,5 can go on day 5.
|
| 112 |
+
* 1,2,3,5 can go on day 6 and 7.
|
| 113 |
+
|
| 114 |
+
## Contest Information
|
| 115 |
+
- **Contest ID**: 1037
|
| 116 |
+
- **Problem Index**: E
|
| 117 |
+
- **Points**: 2250.0
|
| 118 |
+
- **Rating**: 2200
|
| 119 |
+
- **Tags**: graphs
|
| 120 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 121 |
+
- **Memory Limit**: 256000000 bytes
|
| 122 |
+
|
| 123 |
+
## Task
|
| 124 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0025/instruction.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1421_B. Putting Bricks in the Wall
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
|
| 5 |
+
|
| 6 |
+
Roger Waters has a square grid of size n× n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
|
| 7 |
+
|
| 8 |
+
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
|
| 9 |
+
|
| 10 |
+
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
|
| 11 |
+
|
| 12 |
+
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
|
| 13 |
+
|
| 14 |
+
We can show that there always exists a solution for the given constraints.
|
| 15 |
+
|
| 16 |
+
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 50). Description of the test cases follows.
|
| 21 |
+
|
| 22 |
+
The first line of each test case contains one integers n (3 ≤ n ≤ 200).
|
| 23 |
+
|
| 24 |
+
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
|
| 25 |
+
|
| 26 |
+
The sum of values of n doesn't exceed 200.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
For each test case output on the first line an integer c (0 ≤ c ≤ 2) — the number of inverted cells.
|
| 31 |
+
|
| 32 |
+
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
|
| 33 |
+
|
| 34 |
+
Example
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
3
|
| 40 |
+
4
|
| 41 |
+
S010
|
| 42 |
+
0001
|
| 43 |
+
1000
|
| 44 |
+
111F
|
| 45 |
+
3
|
| 46 |
+
S10
|
| 47 |
+
101
|
| 48 |
+
01F
|
| 49 |
+
5
|
| 50 |
+
S0101
|
| 51 |
+
00000
|
| 52 |
+
01111
|
| 53 |
+
11111
|
| 54 |
+
0001F
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
1
|
| 61 |
+
3 4
|
| 62 |
+
2
|
| 63 |
+
1 2
|
| 64 |
+
2 1
|
| 65 |
+
0
|
| 66 |
+
|
| 67 |
+
Note
|
| 68 |
+
|
| 69 |
+
For the first test case, after inverting the cell, we get the following grid:
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
S010
|
| 74 |
+
0001
|
| 75 |
+
1001
|
| 76 |
+
111F
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
## Contest Information
|
| 80 |
+
- **Contest ID**: 1421
|
| 81 |
+
- **Problem Index**: B
|
| 82 |
+
- **Points**: 1000.0
|
| 83 |
+
- **Rating**: 1100
|
| 84 |
+
- **Tags**: constructive algorithms, implementation
|
| 85 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 86 |
+
- **Memory Limit**: 256000000 bytes
|
| 87 |
+
|
| 88 |
+
## Task
|
| 89 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0030/instruction.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1540_C1. Converging Array (Easy Version)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
|
| 5 |
+
|
| 6 |
+
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
|
| 7 |
+
|
| 8 |
+
The process is an infinite sequence of operations. Each operation is as follows:
|
| 9 |
+
|
| 10 |
+
* First, choose a random integer i (1 ≤ i ≤ n-1).
|
| 11 |
+
* Then, simultaneously set a_i = min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right) and a_{i+1} = max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right) without any rounding (so values may become non-integer).
|
| 12 |
+
|
| 13 |
+
See notes for an example of an operation.
|
| 14 |
+
|
| 15 |
+
It can be proven that array a converges, i. e. for each i there exists a limit a_i converges to. Let function F(a, b) return the value a_1 converges to after a process on a and b.
|
| 16 |
+
|
| 17 |
+
You are given array b, but not array a. However, you are given a third array c. Array a is good if it contains only integers and satisfies 0 ≤ a_i ≤ c_i for 1 ≤ i ≤ n.
|
| 18 |
+
|
| 19 |
+
Your task is to count the number of good arrays a where F(a, b) ≥ x for q values of x. Since the number of arrays can be very large, print it modulo 10^9+7.
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
The first line contains a single integer n (2 ≤ n ≤ 100).
|
| 24 |
+
|
| 25 |
+
The second line contains n integers c_1, c_2 …, c_n (0 ≤ c_i ≤ 100).
|
| 26 |
+
|
| 27 |
+
The third line contains n-1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 100).
|
| 28 |
+
|
| 29 |
+
The fourth line contains a single integer q (q=1).
|
| 30 |
+
|
| 31 |
+
The fifth line contains q space separated integers x_1, x_2, …, x_q (-10^5 ≤ x_i ≤ 10^5).
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
Output q integers, where the i-th integer is the answer to the i-th query, i. e. the number of good arrays a where F(a, b) ≥ x_i modulo 10^9+7.
|
| 36 |
+
|
| 37 |
+
Example
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
3
|
| 43 |
+
2 3 4
|
| 44 |
+
2 1
|
| 45 |
+
1
|
| 46 |
+
-1
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
56
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
The following explanation assumes b = [2, 1] and c=[2, 3, 4] (as in the sample).
|
| 57 |
+
|
| 58 |
+
Examples of arrays a that are not good:
|
| 59 |
+
|
| 60 |
+
* a = [3, 2, 3] is not good because a_1 > c_1;
|
| 61 |
+
* a = [0, -1, 3] is not good because a_2 < 0.
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
One possible good array a is [0, 2, 4]. We can show that no operation has any effect on this array, so F(a, b) = a_1 = 0.
|
| 66 |
+
|
| 67 |
+
Another possible good array a is [0, 1, 4]. In a single operation with i = 1, we set a_1 = min((0+1-2)/(2), 0) and a_2 = max((0+1+2)/(2), 1). So, after a single operation with i = 1, a becomes equal to [-1/2, 3/2, 4]. We can show that no operation has any effect on this array, so F(a, b) = -1/2.
|
| 68 |
+
|
| 69 |
+
## Contest Information
|
| 70 |
+
- **Contest ID**: 1540
|
| 71 |
+
- **Problem Index**: C1
|
| 72 |
+
- **Points**: 1500.0
|
| 73 |
+
- **Rating**: 2700
|
| 74 |
+
- **Tags**: dp, math
|
| 75 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 76 |
+
- **Memory Limit**: 256000000 bytes
|
| 77 |
+
|
| 78 |
+
## Task
|
| 79 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0031/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 168_A. Wizards and Demonstration
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Some country is populated by wizards. They want to organize a demonstration.
|
| 5 |
+
|
| 6 |
+
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
|
| 7 |
+
|
| 8 |
+
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets.
|
| 9 |
+
|
| 10 |
+
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains three space-separated integers, n, x, y (1 ≤ n, x, y ≤ 104, x ≤ n) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
|
| 15 |
+
|
| 16 |
+
Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n).
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population).
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
10 1 14
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
1
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
20 10 50
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
0
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
1000 352 146
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
1108
|
| 52 |
+
|
| 53 |
+
Note
|
| 54 |
+
|
| 55 |
+
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
|
| 56 |
+
|
| 57 |
+
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 168
|
| 61 |
+
- **Problem Index**: A
|
| 62 |
+
- **Points**: 500.0
|
| 63 |
+
- **Rating**: 900
|
| 64 |
+
- **Tags**: implementation, math
|
| 65 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 66 |
+
- **Memory Limit**: 256000000 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-0036/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 284_B. Cows and Poker Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".
|
| 5 |
+
|
| 6 |
+
Find the number of cows that can currently show their hands without affecting any betting decisions.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains a single integer, n (2 ≤ n ≤ 2·105). The second line contains n characters, each either "A", "I", or "F". The i-th character is "A" if the i-th player's status is "ALLIN", "I" if the i-th player's status is "IN", or "F" if the i-th player's status is "FOLDED".
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
The first line should contain a single integer denoting the number of players that can currently show their hands.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
6
|
| 21 |
+
AFFAAA
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
4
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
AFI
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
1
|
| 38 |
+
|
| 39 |
+
Note
|
| 40 |
+
|
| 41 |
+
In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 284
|
| 45 |
+
- **Problem Index**: B
|
| 46 |
+
- **Points**: 1000.0
|
| 47 |
+
- **Rating**: 1000
|
| 48 |
+
- **Tags**: brute force, implementation
|
| 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-0038/instruction.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 331_E2. Deja Vu
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Everybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers.
|
| 5 |
+
|
| 6 |
+
So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he gets visions of events in some places he's been at or is going to be at. Let's examine the phenomenon in more detail.
|
| 7 |
+
|
| 8 |
+
We can say that Neo's city is represented by a directed graph, consisting of n shops and m streets that connect the shops. No two streets connect the same pair of shops (besides, there can't be one street from A to B and one street from B to A). No street connects a shop with itself. As Neo passes some streets, he gets visions. No matter how many times he passes street k, every time he will get the same visions in the same order. A vision is a sequence of shops.
|
| 9 |
+
|
| 10 |
+
We know that Neo is going to get really shocked if he passes the way from some shop a to some shop b, possible coinciding with a, such that the list of visited shops in the real life and in the visions coincide.
|
| 11 |
+
|
| 12 |
+
Suggest beaver Neo such path of non-zero length. Or maybe you can even count the number of such paths modulo 1000000007 (109 + 7)?..
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains integers n and m — the number of shops and the number of streets, correspondingly, 1 ≤ n ≤ 50, <image>. Next m lines contain the descriptions of the streets in the following format: xi yi ki v1 v2 ... vk, where xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi) are numbers of shops connected by a street, ki (0 ≤ ki ≤ n) is the number of visions on the way from xi to yi; v1, v2, ..., vk (1 ≤ vi ≤ n) describe the visions: the numbers of the shops Neo saw. Note that the order of the visions matters.
|
| 17 |
+
|
| 18 |
+
It is guaranteed that the total number of visions on all streets doesn't exceed 105.
|
| 19 |
+
|
| 20 |
+
* to get 50 points, you need to find any (not necessarily simple) path of length at most 2·n, that meets the attributes described above (subproblem E1);
|
| 21 |
+
* to get 50 more points, you need to count for each length from 1 to 2·n the number of paths that have the attribute described above (subproblem E2).
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
Subproblem E1. In the first line print an integer k (1 ≤ k ≤ 2·n) — the numbers of shops on Neo's path. In the next line print k integers — the number of shops in the order Neo passes them. If the graph doesn't have such paths or the length of the shortest path includes more than 2·n shops, print on a single line 0.
|
| 26 |
+
|
| 27 |
+
Subproblem E2. Print 2·n lines. The i-th line must contain a single integer — the number of required paths of length i modulo 1000000007 (109 + 7).
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
6 6
|
| 34 |
+
1 2 2 1 2
|
| 35 |
+
2 3 1 3
|
| 36 |
+
3 4 2 4 5
|
| 37 |
+
4 5 0
|
| 38 |
+
5 3 1 3
|
| 39 |
+
6 1 1 6
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
4
|
| 45 |
+
6 1 2 3
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
6 6
|
| 51 |
+
1 2 2 1 2
|
| 52 |
+
2 3 1 3
|
| 53 |
+
3 4 2 4 5
|
| 54 |
+
4 5 0
|
| 55 |
+
5 3 1 3
|
| 56 |
+
6 1 1 6
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
1
|
| 62 |
+
2
|
| 63 |
+
1
|
| 64 |
+
1
|
| 65 |
+
2
|
| 66 |
+
1
|
| 67 |
+
1
|
| 68 |
+
2
|
| 69 |
+
1
|
| 70 |
+
1
|
| 71 |
+
2
|
| 72 |
+
1
|
| 73 |
+
|
| 74 |
+
Note
|
| 75 |
+
|
| 76 |
+
The input in both samples are the same. The first sample contains the answer to the first subproblem, the second sample contains the answer to the second subproblem.
|
| 77 |
+
|
| 78 |
+
## Contest Information
|
| 79 |
+
- **Contest ID**: 331
|
| 80 |
+
- **Problem Index**: E2
|
| 81 |
+
- **Points**: 50.0
|
| 82 |
+
- **Rating**: 3100
|
| 83 |
+
- **Tags**: constructive algorithms, dp
|
| 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-0047/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 545_C. Woodcutters
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
|
| 5 |
+
|
| 6 |
+
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.
|
| 11 |
+
|
| 12 |
+
Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.
|
| 13 |
+
|
| 14 |
+
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print a single number — the maximum number of trees that you can cut down by the given rules.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
5
|
| 25 |
+
1 2
|
| 26 |
+
2 1
|
| 27 |
+
5 10
|
| 28 |
+
10 9
|
| 29 |
+
19 1
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
5
|
| 40 |
+
1 2
|
| 41 |
+
2 1
|
| 42 |
+
5 10
|
| 43 |
+
10 9
|
| 44 |
+
20 1
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
4
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
In the first sample you can fell the trees like that:
|
| 54 |
+
|
| 55 |
+
* fell the 1-st tree to the left — now it occupies segment [ - 1;1]
|
| 56 |
+
* fell the 2-nd tree to the right — now it occupies segment [2;3]
|
| 57 |
+
* leave the 3-rd tree — it occupies point 5
|
| 58 |
+
* leave the 4-th tree — it occupies point 10
|
| 59 |
+
* fell the 5-th tree to the right — now it occupies segment [19;20]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 545
|
| 67 |
+
- **Problem Index**: C
|
| 68 |
+
- **Points**: 1750.0
|
| 69 |
+
- **Rating**: 1500
|
| 70 |
+
- **Tags**: dp, greedy
|
| 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-0053/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 687_D. Dividing Kingdom II
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.
|
| 5 |
+
|
| 6 |
+
The great kingdom consisted of n cities numbered from 1 to n and m bidirectional roads between these cities, numbered from 1 to m. The i-th road had length equal to wi. The Great Arya and Pari The Great were discussing about destructing some prefix (all road with numbers less than some x) and suffix (all roads with numbers greater than some x) of the roads so there will remain only the roads with numbers l, l + 1, ..., r - 1 and r.
|
| 7 |
+
|
| 8 |
+
After that they will divide the great kingdom into two pieces (with each city belonging to exactly one piece) such that the hardness of the division is minimized. The hardness of a division is the maximum length of a road such that its both endpoints are in the same piece of the kingdom. In case there is no such road, the hardness of the division is considered to be equal to - 1.
|
| 9 |
+
|
| 10 |
+
Historians found the map of the great kingdom, and they have q guesses about the l and r chosen by those great rulers. Given these data, for each guess li and ri print the minimum possible hardness of the division of the kingdom.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of the input contains three integers n, m and q (1 ≤ n, q ≤ 1000, <image>) — the number of cities and roads in the great kingdom, and the number of guesses, respectively.
|
| 15 |
+
|
| 16 |
+
The i-th line of the following m lines contains three integers ui, vi and wi (1 ≤ ui, vi ≤ n, 0 ≤ wi ≤ 109), denoting the road number i connects cities ui and vi and its length is equal wi. It's guaranteed that no road connects the city to itself and no pair of cities is connected by more than one road.
|
| 17 |
+
|
| 18 |
+
Each of the next q lines contains a pair of integers li and ri (1 ≤ li ≤ ri ≤ m) — a guess from the historians about the remaining roads in the kingdom.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
For each guess print the minimum possible hardness of the division in described scenario.
|
| 23 |
+
|
| 24 |
+
Example
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
5 6 5
|
| 29 |
+
5 4 86
|
| 30 |
+
5 1 0
|
| 31 |
+
1 3 38
|
| 32 |
+
2 1 33
|
| 33 |
+
2 4 28
|
| 34 |
+
2 3 40
|
| 35 |
+
3 5
|
| 36 |
+
2 6
|
| 37 |
+
1 3
|
| 38 |
+
2 3
|
| 39 |
+
1 6
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
-1
|
| 45 |
+
33
|
| 46 |
+
-1
|
| 47 |
+
-1
|
| 48 |
+
33
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 687
|
| 52 |
+
- **Problem Index**: D
|
| 53 |
+
- **Points**: 2000.0
|
| 54 |
+
- **Rating**: 2500
|
| 55 |
+
- **Tags**: brute force, data structures, dsu, graphs, sortings
|
| 56 |
+
- **Time Limit**: {'seconds': 6, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0054/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 70_C. Lucky Tickets
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In Walrusland public transport tickets are characterized by two integers: by the number of the series and by the number of the ticket in the series. Let the series number be represented by a and the ticket number — by b, then a ticket is described by the ordered pair of numbers (a, b).
|
| 5 |
+
|
| 6 |
+
The walruses believe that a ticket is lucky if a * b = rev(a) * rev(b). The function rev(x) reverses a number written in the decimal system, at that the leading zeroes disappear. For example, rev(12343) = 34321, rev(1200) = 21.
|
| 7 |
+
|
| 8 |
+
The Public Transport Management Committee wants to release x series, each containing y tickets, so that at least w lucky tickets were released and the total number of released tickets (x * y) were minimum. The series are numbered from 1 to x inclusive. The tickets in each series are numbered from 1 to y inclusive. The Transport Committee cannot release more than maxx series and more than maxy tickets in one series.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains three integers maxx, maxy, w (1 ≤ maxx, maxy ≤ 105, 1 ≤ w ≤ 107).
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print on a single line two space-separated numbers, the x and the y. If there are several possible variants, print any of them. If such x and y do not exist, print a single number - 1.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
2 2 1
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
1 1
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
132 10 35
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
7 5
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
5 18 1000
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
-1
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
48 132 235
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
22 111
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 70
|
| 59 |
+
- **Problem Index**: C
|
| 60 |
+
- **Points**: 1500.0
|
| 61 |
+
- **Rating**: 2200
|
| 62 |
+
- **Tags**: binary search, data structures, sortings, two pointers
|
| 63 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 500000000} 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-0062/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 893_D. Credit Card
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
|
| 5 |
+
|
| 6 |
+
She starts with 0 money on her account.
|
| 7 |
+
|
| 8 |
+
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
|
| 9 |
+
|
| 10 |
+
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
|
| 11 |
+
|
| 12 |
+
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
|
| 13 |
+
|
| 14 |
+
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
|
| 19 |
+
|
| 20 |
+
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
5 10
|
| 31 |
+
-1 5 0 -5 3
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
0
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
3 4
|
| 42 |
+
-10 0 20
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
-1
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
5 10
|
| 53 |
+
-5 0 10 -11 0
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
2
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 893
|
| 62 |
+
- **Problem Index**: D
|
| 63 |
+
- **Points**: 0.0
|
| 64 |
+
- **Rating**: 1900
|
| 65 |
+
- **Tags**: data structures, dp, greedy, implementation
|
| 66 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 67 |
+
- **Memory Limit**: 256000000 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0065/instruction.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 963_B. Destruction of a Tree
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
|
| 5 |
+
|
| 6 |
+
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
|
| 7 |
+
|
| 8 |
+
Destroy all vertices in the given tree or determine that it is impossible.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes).
|
| 19 |
+
|
| 20 |
+
If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
5
|
| 27 |
+
0 1 2 1 2
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
YES
|
| 33 |
+
1
|
| 34 |
+
2
|
| 35 |
+
3
|
| 36 |
+
5
|
| 37 |
+
4
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
4
|
| 43 |
+
0 1 2 3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
NO
|
| 49 |
+
|
| 50 |
+
Note
|
| 51 |
+
|
| 52 |
+
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
|
| 53 |
+
|
| 54 |
+
<image>
|
| 55 |
+
|
| 56 |
+
## Contest Information
|
| 57 |
+
- **Contest ID**: 963
|
| 58 |
+
- **Problem Index**: B
|
| 59 |
+
- **Points**: 1000.0
|
| 60 |
+
- **Rating**: 2000
|
| 61 |
+
- **Tags**: constructive algorithms, dfs and similar, dp, greedy, trees
|
| 62 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 63 |
+
- **Memory Limit**: 256000000 bytes
|
| 64 |
+
|
| 65 |
+
## Task
|
| 66 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0078/instruction.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02744 Panasonic Programming Contest 2020 - String Equivalence
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In this problem, we only consider strings consisting of lowercase English letters.
|
| 5 |
+
|
| 6 |
+
Strings s and t are said to be isomorphic when the following conditions are satisfied:
|
| 7 |
+
|
| 8 |
+
* |s| = |t| holds.
|
| 9 |
+
* For every pair i, j, one of the following holds:
|
| 10 |
+
* s_i = s_j and t_i = t_j.
|
| 11 |
+
* s_i \neq s_j and t_i \neq t_j.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not.
|
| 16 |
+
|
| 17 |
+
A string s is said to be in normal form when the following condition is satisfied:
|
| 18 |
+
|
| 19 |
+
* For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`.
|
| 24 |
+
|
| 25 |
+
You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
|
| 26 |
+
|
| 27 |
+
Constraints
|
| 28 |
+
|
| 29 |
+
* 1 \leq N \leq 10
|
| 30 |
+
* All values in input are integers.
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
Input is given from Standard Input in the following format:
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
N
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order. Output should be in the following format:
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
w_1
|
| 46 |
+
:
|
| 47 |
+
w_K
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order. Output should be in the following format:
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
w_1
|
| 55 |
+
:
|
| 56 |
+
w_K
|
| 57 |
+
|
| 58 |
+
Examples
|
| 59 |
+
|
| 60 |
+
Input
|
| 61 |
+
|
| 62 |
+
1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Output
|
| 66 |
+
|
| 67 |
+
a
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Input
|
| 71 |
+
|
| 72 |
+
2
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
aa
|
| 78 |
+
ab
|
| 79 |
+
|
| 80 |
+
## Contest Information
|
| 81 |
+
- **Contest ID**: 0
|
| 82 |
+
- **Problem Index**:
|
| 83 |
+
- **Points**: 0.0
|
| 84 |
+
- **Rating**: 0
|
| 85 |
+
- **Tags**:
|
| 86 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 87 |
+
- **Memory Limit**: 1073741824 bytes
|
| 88 |
+
|
| 89 |
+
## Task
|
| 90 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0098/instruction.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01694 Step Aerobics
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Step up and down
|
| 5 |
+
|
| 6 |
+
Kazuki, commonly known as Kerr, who attends JAG University, was invited by your friend this summer to participate in the ICPC (International Collegiate Potchari Contest). ICPC is a sports contest and requires a high degree of athletic ability. However, Mr. Kerr was always in front of the computer, and he was so lacking in exercise that he was tired even if he moved a little. Therefore, Kerr decided to start an easy-to-start exercise, "stepping up and down," as the first step to achieve good results with ICPC.
|
| 7 |
+
|
| 8 |
+
As the name suggests, stepping up and down is a simple exercise that simply repeats going up and down between the step and the floor. However, in stepping up and down, the effect cannot be obtained unless the feet are raised and lowered correctly. Correct ascent and descent is the movement of the foot that satisfies either of the following two types.
|
| 9 |
+
|
| 10 |
+
* From the state where both feet are on the floor, the left foot and the right foot are raised on the stepping stone, and both feet are on the stepping stone. Either the left foot or the right foot may be raised first.
|
| 11 |
+
* From the state where both feet are on the platform, the left foot and the right foot are lowered to the floor, and both feet are on the floor. Either the left foot or the right foot may be lowered first.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
As can be seen from the above, raising and lowering only one leg continuously from the state of being on the floor or stepping stone does not result in correct raising and lowering. In the stepping up / down movement, when any of the above correct up / down movements is satisfied, it is counted as one time, and the larger the count number, the more effective the effect can be obtained. Note that even if you don't go back and forth between the floor and the platform, it counts as one only one way.
|
| 16 |
+
|
| 17 |
+
You want your teammate, Kerr, to be as strong as possible. So you decided to write a program and check if Kerr was skipping the step up and down. Since the information of the foot that Kerr moved by going up and down the platform is given, find the number of times that he went up and down correctly. However, it is assumed that both feet are on the floor before going up and down the platform.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The input consists of multiple data sets, and the number of data sets contained in one input is 150 or less. The format of each data set is as follows.
|
| 22 |
+
|
| 23 |
+
> $ n $
|
| 24 |
+
> $ f_1 $ $ f_2 $ ... $ f_n $
|
| 25 |
+
|
| 26 |
+
In the first line, the integer $ n $ ($ 1 \ le n \ le 100 $) representing the number of times the foot is moved is given. In the second line, $ f_i $, which is a character string representing the movement of the foot, is given in chronological order by $ n $, separated by spaces. $ f_i $ is one of the following four types of character strings.
|
| 27 |
+
|
| 28 |
+
* "lu": Raise your left foot to the platform.
|
| 29 |
+
* "ru": Raise your right foot to the platform.
|
| 30 |
+
* "ld": Lower your left foot to the floor.
|
| 31 |
+
* "rd": Lower your right foot to the floor.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
It can be assumed that no action is input that lowers the foot on the floor or raises the foot on the platform.
|
| 36 |
+
|
| 37 |
+
The line where $ n $ is 0 indicates the end of input. Do not process this data.
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
For each dataset, output the number of correct steps up and down in one line. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer.
|
| 42 |
+
|
| 43 |
+
Sample Input
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Four
|
| 47 |
+
lu ru ld rd
|
| 48 |
+
Four
|
| 49 |
+
lu ld lu ru
|
| 50 |
+
1
|
| 51 |
+
lu
|
| 52 |
+
Ten
|
| 53 |
+
ru lu ld rd ru rd ru lu lu rd ld
|
| 54 |
+
0
|
| 55 |
+
|
| 56 |
+
Output for Sample Input
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
2
|
| 60 |
+
1
|
| 61 |
+
0
|
| 62 |
+
Four
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Example
|
| 69 |
+
|
| 70 |
+
Input
|
| 71 |
+
|
| 72 |
+
4
|
| 73 |
+
lu ru ld rd
|
| 74 |
+
4
|
| 75 |
+
lu ld lu ru
|
| 76 |
+
1
|
| 77 |
+
lu
|
| 78 |
+
10
|
| 79 |
+
ru lu ld rd ru rd ru lu rd ld
|
| 80 |
+
0
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
Output
|
| 84 |
+
|
| 85 |
+
2
|
| 86 |
+
1
|
| 87 |
+
0
|
| 88 |
+
4
|
| 89 |
+
|
| 90 |
+
## Contest Information
|
| 91 |
+
- **Contest ID**: 0
|
| 92 |
+
- **Problem Index**:
|
| 93 |
+
- **Points**: 0.0
|
| 94 |
+
- **Rating**: 0
|
| 95 |
+
- **Tags**:
|
| 96 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 97 |
+
- **Memory Limit**: 134217728 bytes
|
| 98 |
+
|
| 99 |
+
## Task
|
| 100 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0203/instruction.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01878 Destiny Draw
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
G: Destiny Draw-
|
| 5 |
+
|
| 6 |
+
problem
|
| 7 |
+
|
| 8 |
+
Mr. D will play a card game. This card game uses a pile of N cards. Also, the pile cards are numbered 1, 2, 3, ..., N in order from the top.
|
| 9 |
+
|
| 10 |
+
He can't afford to be defeated, carrying everything that starts with D, but unfortunately Mr. D isn't good at card games. Therefore, I decided to win by controlling the cards I draw.
|
| 11 |
+
|
| 12 |
+
Mr. D can shuffle K types. For the i-th shuffle of the K types, pull out exactly the b_i sheets from the top a_i to the a_i + b_i − 1st sheet and stack them on top. Each shuffle i-th takes t_i seconds.
|
| 13 |
+
|
| 14 |
+
How many ways are there to make the top card a C after just a T second shuffle? Since the number can be large, output the remainder divided by 10 ^ 9 + 7.
|
| 15 |
+
|
| 16 |
+
Input format
|
| 17 |
+
|
| 18 |
+
The input is given in the following format:
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
N K C T
|
| 22 |
+
a_1 b_1 t_1
|
| 23 |
+
a_2 b_2 t_2
|
| 24 |
+
...
|
| 25 |
+
a_K b_K t_K
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
* N is an integer and satisfies 2 \ ≤ N \ ≤ 40.
|
| 29 |
+
* K is an integer and satisfies 1 \ ≤ K \ ≤ \ frac {N (N + 1)} {2}
|
| 30 |
+
* C is an integer and satisfies 1 \ ≤ C \ ≤ N
|
| 31 |
+
* T is an integer and satisfies 1 \ ≤ T \ ≤ 1,000,000
|
| 32 |
+
* a_i (i = 1, 2, ..., K) is an integer and satisfies 1 \ ≤ a_i \ ≤ N
|
| 33 |
+
* b_i (i = 1, 2, ..., K) is an integer and satisfies 1 \ ≤ b_i \ ≤ N − a_i + 1
|
| 34 |
+
* Limited to i = j when a_i = a_j and b_i = b_j are satisfied
|
| 35 |
+
* t_i is an integer and satisfies 1 \ ≤ t_i \ ≤ 5
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output format
|
| 40 |
+
|
| 41 |
+
Divide the answer by 10 ^ 9 + 7 and output the remainder in one line.
|
| 42 |
+
|
| 43 |
+
Input example 1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
4 1 1 6
|
| 47 |
+
3 2 3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output example 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
1
|
| 54 |
+
|
| 55 |
+
Input example 2
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
4 1 1 5
|
| 59 |
+
3 2 3
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output example 2
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
0
|
| 66 |
+
|
| 67 |
+
Input example 3
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
6 2 2 5
|
| 71 |
+
1 2 1
|
| 72 |
+
2 5 3
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output example 3
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
3
|
| 79 |
+
|
| 80 |
+
There are three ways to get the top card to 2 in just 5 seconds:
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
1 → 1 → 2
|
| 84 |
+
1 → 2 → 1
|
| 85 |
+
2 → 1 → 1
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Input example 4
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
6 8 3 10
|
| 92 |
+
1 4 5
|
| 93 |
+
1 3 3
|
| 94 |
+
1 6 5
|
| 95 |
+
1 2 2
|
| 96 |
+
1 1 4
|
| 97 |
+
2 5 1
|
| 98 |
+
4 3 1
|
| 99 |
+
2 1 3
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
Output example 4
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
3087
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
Example
|
| 112 |
+
|
| 113 |
+
Input
|
| 114 |
+
|
| 115 |
+
4 1 1 6
|
| 116 |
+
3 2 3
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
Output
|
| 120 |
+
|
| 121 |
+
1
|
| 122 |
+
|
| 123 |
+
## Contest Information
|
| 124 |
+
- **Contest ID**: 0
|
| 125 |
+
- **Problem Index**:
|
| 126 |
+
- **Points**: 0.0
|
| 127 |
+
- **Rating**: 0
|
| 128 |
+
- **Tags**:
|
| 129 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 130 |
+
- **Memory Limit**: 268435456 bytes
|
| 131 |
+
|
| 132 |
+
## Task
|
| 133 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0210/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# gameaam
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the smaller integer in the pair in such a way that both integers in the pair remain positive. If two numbers in some pair become equal then the pair is removed from the sequence. The player who can not make any move loses (or in another words the player who encounters an empty sequence loses). Given the sequence of positive integer pairs determine whether the first player can win or not (assuming that both players are playing optimally).
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
|
| 8 |
+
Each test starts with an integer N denoting the number of pairs. Each of the next N lines contains a pair of positive integers.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
Output
|
| 12 |
+
For each test case, output a single line containing "YES" if the first player can win and "NO" otherwise.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
1 ≤ T ≤ 100
|
| 17 |
+
1 ≤ N ≤ 100
|
| 18 |
+
All other integers are between 1 to 10^8
|
| 19 |
+
The integers in each pair will be different
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Example
|
| 24 |
+
Input:
|
| 25 |
+
3
|
| 26 |
+
1
|
| 27 |
+
2 3
|
| 28 |
+
2
|
| 29 |
+
4 5
|
| 30 |
+
5 6
|
| 31 |
+
2
|
| 32 |
+
2 3
|
| 33 |
+
3 5
|
| 34 |
+
|
| 35 |
+
Output:
|
| 36 |
+
NO
|
| 37 |
+
NO
|
| 38 |
+
YES
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Explanation
|
| 43 |
+
Example case 1. The first player don't have any choice other subtracting 2 from 3. So during the turn of the second player integer pair will be (2,1). The second player will win by subtracting 1 from 2.
|
| 44 |
+
Example case 2. If the first player choose to move (4,5) to (4,1) the second player will make it to (1,1). If the first player choose to move (5,6) to (5,1) the second player will make it to (1,1). So regardless of the move of the first player, the second will always win.
|
| 45 |
+
Example case 3. The first player will select pair (3,5) and make it to (3,2). Now both pairs are equal. So whatever the move of second player he will just mirror that move in another pair. This will ensure his win.
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 0
|
| 49 |
+
- **Problem Index**:
|
| 50 |
+
- **Points**: 0.0
|
| 51 |
+
- **Rating**: 0
|
| 52 |
+
- **Tags**: None
|
| 53 |
+
- **Time Limit**: None seconds
|
| 54 |
+
- **Memory Limit**: 0 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-0217/instruction.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1081_D. Maximum Distance
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
|
| 5 |
+
|
| 6 |
+
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, …, x_k.
|
| 7 |
+
|
| 8 |
+
Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them.
|
| 9 |
+
|
| 10 |
+
For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them.
|
| 11 |
+
|
| 12 |
+
The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains three integers n, m and k (2 ≤ k ≤ n ≤ 10^5, n-1 ≤ m ≤ 10^5) — the number of vertices, the number of edges and the number of special vertices.
|
| 17 |
+
|
| 18 |
+
The second line contains k distinct integers x_1, x_2, …, x_k (1 ≤ x_i ≤ n).
|
| 19 |
+
|
| 20 |
+
Each of the following m lines contains three integers u, v and w (1 ≤ u,v ≤ n, 1 ≤ w ≤ 10^9), denoting there is an edge between u and v of weight w. The given graph is undirected, so an edge (u, v) can be used in the both directions.
|
| 21 |
+
|
| 22 |
+
The graph may have multiple edges and self-loops.
|
| 23 |
+
|
| 24 |
+
It is guaranteed, that the graph is connected.
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
The first and only line should contain k integers. The i-th integer is the distance between x_i and the farthest special vertex from it.
|
| 29 |
+
|
| 30 |
+
Examples
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
2 3 2
|
| 35 |
+
2 1
|
| 36 |
+
1 2 3
|
| 37 |
+
1 2 2
|
| 38 |
+
2 2 1
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
2 2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
4 5 3
|
| 49 |
+
1 2 3
|
| 50 |
+
1 2 5
|
| 51 |
+
4 2 1
|
| 52 |
+
2 3 2
|
| 53 |
+
1 4 4
|
| 54 |
+
1 3 3
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
3 3 3
|
| 60 |
+
|
| 61 |
+
Note
|
| 62 |
+
|
| 63 |
+
In the first example, the distance between vertex 1 and 2 equals to 2 because one can walk through the edge of weight 2 connecting them. So the distance to the farthest node for both 1 and 2 equals to 2.
|
| 64 |
+
|
| 65 |
+
In the second example, one can find that distance between 1 and 2, distance between 1 and 3 are both 3 and the distance between 2 and 3 is 2.
|
| 66 |
+
|
| 67 |
+
The graph may have multiple edges between and self-loops, as in the first example.
|
| 68 |
+
|
| 69 |
+
## Contest Information
|
| 70 |
+
- **Contest ID**: 1081
|
| 71 |
+
- **Problem Index**: D
|
| 72 |
+
- **Points**: 2000.0
|
| 73 |
+
- **Rating**: 1800
|
| 74 |
+
- **Tags**: dsu, graphs, shortest paths, sortings
|
| 75 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 76 |
+
- **Memory Limit**: 256000000 bytes
|
| 77 |
+
|
| 78 |
+
## Task
|
| 79 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0226/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1269_B. Modulo Equality
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a positive integer m and two integer sequence: a=[a_1, a_2, …, a_n] and b=[b_1, b_2, …, b_n]. Both of these sequence have a length n.
|
| 5 |
+
|
| 6 |
+
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3].
|
| 7 |
+
|
| 8 |
+
You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x.
|
| 9 |
+
|
| 10 |
+
In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, …, p_n], such that for all 1 ≤ i ≤ n, (a_i + x) mod m = b_{p_i}, where y mod m — remainder of division of y by m.
|
| 11 |
+
|
| 12 |
+
For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains two integers n,m (1 ≤ n ≤ 2000, 1 ≤ m ≤ 10^9): number of elemens in arrays and m.
|
| 17 |
+
|
| 18 |
+
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < m).
|
| 19 |
+
|
| 20 |
+
The third line contains n integers b_1, b_2, …, b_n (0 ≤ b_i < m).
|
| 21 |
+
|
| 22 |
+
It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i}.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, …, p_n such that (a_i + x) mod m = b_{p_i} for all 1 ≤ i ≤ n.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
4 3
|
| 34 |
+
0 0 2 1
|
| 35 |
+
2 0 1 1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
1
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
3 2
|
| 48 |
+
0 0 0
|
| 49 |
+
1 1 1
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
1
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Input
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
5 10
|
| 62 |
+
0 0 0 1 2
|
| 63 |
+
2 1 0 0 0
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
0
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 1269
|
| 73 |
+
- **Problem Index**: B
|
| 74 |
+
- **Points**: 1000.0
|
| 75 |
+
- **Rating**: 1500
|
| 76 |
+
- **Tags**: brute force, sortings
|
| 77 |
+
- **Time Limit**: {'seconds': 3, '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-0228/instruction.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1311_C. Perform the Combo
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
|
| 5 |
+
|
| 6 |
+
You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after p_i-th button (1 ≤ p_i < n) (i.e. you will press first p_i buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.
|
| 7 |
+
|
| 8 |
+
I.e. if s="abca", m=2 and p = [1, 3] then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.
|
| 9 |
+
|
| 10 |
+
Your task is to calculate for each button (letter) the number of times you'll press it.
|
| 11 |
+
|
| 12 |
+
You have to answer t independent test cases.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases.
|
| 17 |
+
|
| 18 |
+
Then t test cases follow.
|
| 19 |
+
|
| 20 |
+
The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the length of s and the number of tries correspondingly.
|
| 21 |
+
|
| 22 |
+
The second line of each test case contains the string s consisting of n lowercase Latin letters.
|
| 23 |
+
|
| 24 |
+
The third line of each test case contains m integers p_1, p_2, ..., p_m (1 ≤ p_i < n) — the number of characters pressed right during the i-th try.
|
| 25 |
+
|
| 26 |
+
It is guaranteed that the sum of n and the sum of m both does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ m ≤ 2 ⋅ 10^5).
|
| 27 |
+
|
| 28 |
+
It is guaranteed that the answer for each letter does not exceed 2 ⋅ 10^9.
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
For each test case, print the answer — 26 integers: the number of times you press the button 'a', the number of times you press the button 'b', ..., the number of times you press the button 'z'.
|
| 33 |
+
|
| 34 |
+
Example
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
3
|
| 40 |
+
4 2
|
| 41 |
+
abca
|
| 42 |
+
1 3
|
| 43 |
+
10 5
|
| 44 |
+
codeforces
|
| 45 |
+
2 8 3 2 9
|
| 46 |
+
26 10
|
| 47 |
+
qwertyuioplkjhgfdsazxcvbnm
|
| 48 |
+
20 10 1 2 3 5 10 5 9 4
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
| 55 |
+
0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0
|
| 56 |
+
2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2
|
| 57 |
+
|
| 58 |
+
Note
|
| 59 |
+
|
| 60 |
+
The first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is 4, 'b' is 2 and 'c' is 2.
|
| 61 |
+
|
| 62 |
+
In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is 9, 'd' is 4, 'e' is 5, 'f' is 3, 'o' is 9, 'r' is 3 and 's' is 1.
|
| 63 |
+
|
| 64 |
+
## Contest Information
|
| 65 |
+
- **Contest ID**: 1311
|
| 66 |
+
- **Problem Index**: C
|
| 67 |
+
- **Points**: 0.0
|
| 68 |
+
- **Rating**: 1300
|
| 69 |
+
- **Tags**: brute force
|
| 70 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 71 |
+
- **Memory Limit**: 256000000 bytes
|
| 72 |
+
|
| 73 |
+
## Task
|
| 74 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0235/instruction.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1466_C. Canine poetry
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
|
| 5 |
+
|
| 6 |
+
Orpheus, a famous poet, and musician plans to calm Cerberus with his poetry and safely walk past him. He created a very peculiar poem for Cerberus. It consists only of lowercase English letters.
|
| 7 |
+
|
| 8 |
+
We call a poem's substring a palindrome if and only if it reads the same backwards and forwards. A string a is a substring of a string b if a can be obtained from b by deleting several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.
|
| 9 |
+
|
| 10 |
+
Unfortunately, Cerberus dislikes palindromes of length greater than 1. For example in the poem abaa the hound of Hades wouldn't like substrings aba and aa.
|
| 11 |
+
|
| 12 |
+
Orpheus can only calm Cerberus if the hound likes his poetry. That's why he wants to change his poem so that it does not contain any palindrome substrings of length greater than 1.
|
| 13 |
+
|
| 14 |
+
Orpheus can modify the poem by replacing a letter at any position with any lowercase English letter. He can use this operation arbitrarily many times (possibly zero). Since there can be many palindromes in his poem, he may have to make some corrections. But how many, exactly? Given the poem, determine the minimal number of letters that have to be changed so that the poem does not contain any palindromes of length greater than 1.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The first line of the input contains a single integer t (1 ≤ t ≤ 10^5) denoting the number of test cases, then t test cases follow.
|
| 19 |
+
|
| 20 |
+
The first and only line of each test case contains a non-empty string of lowercase English letters, Orpheus' poem.
|
| 21 |
+
|
| 22 |
+
The sum of the length of Orpheus' poems in all test cases will not exceed 10^5.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
You should output t lines, i-th line should contain a single integer, answer to the i-th test case.
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
7
|
| 34 |
+
babba
|
| 35 |
+
abaac
|
| 36 |
+
codeforces
|
| 37 |
+
zeroorez
|
| 38 |
+
abcdcba
|
| 39 |
+
bbbbbbb
|
| 40 |
+
a
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
1
|
| 47 |
+
1
|
| 48 |
+
0
|
| 49 |
+
1
|
| 50 |
+
1
|
| 51 |
+
4
|
| 52 |
+
0
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
In the first test case, we can replace the third character with c and obtain a palindrome-less poem bacba.
|
| 57 |
+
|
| 58 |
+
In the second test case, we can replace the third character with d and obtain a palindrome-less poem abdac.
|
| 59 |
+
|
| 60 |
+
In the third test case, the initial poem already doesn't contain any palindromes, so Orpheus doesn't need to change anything there.
|
| 61 |
+
|
| 62 |
+
## Contest Information
|
| 63 |
+
- **Contest ID**: 1466
|
| 64 |
+
- **Problem Index**: C
|
| 65 |
+
- **Points**: 1000.0
|
| 66 |
+
- **Rating**: 1300
|
| 67 |
+
- **Tags**: dp, greedy, strings
|
| 68 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 69 |
+
- **Memory Limit**: 256000000 bytes
|
| 70 |
+
|
| 71 |
+
## Task
|
| 72 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0257/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 592_E. BCPC
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
BCPC stands for Byteforces Collegiate Programming Contest, and is the most famous competition in Byteforces.
|
| 5 |
+
|
| 6 |
+
BCPC is a team competition. Each team is composed by a coach and three contestants. Blenda is the coach of the Bit State University(BSU), and she is very strict selecting the members of her team.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
In BSU there are n students numbered from 1 to n. Since all BSU students are infinitely smart, the only important parameters for Blenda are their reading and writing speed. After a careful measuring, Blenda have found that the i-th student have a reading speed equal to ri (words per minute), and a writing speed of wi (symbols per minute). Since BSU students are very smart, the measured speeds are sometimes very big and Blenda have decided to subtract some constant value c from all the values of reading speed and some value d from all the values of writing speed. Therefore she considers ri' = ri - c and wi' = wi - d.
|
| 11 |
+
|
| 12 |
+
The student i is said to overwhelm the student j if and only if ri'·wj' > rj'·wi'. Blenda doesn’t like fights in teams, so she thinks that a team consisting of three distinct students i, j and k is good if i overwhelms j, j overwhelms k, and k overwhelms i. Yes, the relation of overwhelming is not transitive as it often happens in real life.
|
| 13 |
+
|
| 14 |
+
Since Blenda is busy preparing a training camp in Codeforces, you are given a task to calculate the number of different good teams in BSU. Two teams are considered to be different if there is at least one student that is present in one team but is not present in the other. In other words, two teams are different if the sets of students that form these teams are different.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
In the first line of the input three integers n, c and d (3 ≤ n ≤ 345678, 1 ≤ c, d ≤ 109) are written. They denote the number of students Blenda can use to form teams, the value subtracted from all reading speeds and the value subtracted from all writing speeds respectively.
|
| 19 |
+
|
| 20 |
+
Each of the next n lines contains two integers ri and wi (0 < ri, wi ≤ 109, |ri - c| + |wi - d| > 0). There are no two students, such that both their reading and writing speeds coincide, i.e. for every i ≠ j condition |ri - rj| + |wi - wj| > 0 holds.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the number of different teams in BSU, that are good according to Blenda's definition.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
5 2 2
|
| 31 |
+
1 1
|
| 32 |
+
4 1
|
| 33 |
+
2 3
|
| 34 |
+
3 2
|
| 35 |
+
3 4
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
4
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
7 6 6
|
| 46 |
+
3 2
|
| 47 |
+
1 7
|
| 48 |
+
5 7
|
| 49 |
+
3 7
|
| 50 |
+
6 4
|
| 51 |
+
8 9
|
| 52 |
+
8 5
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
11
|
| 58 |
+
|
| 59 |
+
Note
|
| 60 |
+
|
| 61 |
+
In the first sample the following teams are good: (i = 1, j = 2, k = 3), (i = 2, j = 5, k = 1), (i = 1, j = 4, k = 3), (i = 5, j = 1, k = 4).
|
| 62 |
+
|
| 63 |
+
Note, that for example the team (i = 3, j = 1, k = 2) is also good, but is considered to be the same as the team (i = 1, j = 2, k = 3).
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 592
|
| 67 |
+
- **Problem Index**: E
|
| 68 |
+
- **Points**: 3000.0
|
| 69 |
+
- **Rating**: 2700
|
| 70 |
+
- **Tags**: binary search, geometry, two pointers
|
| 71 |
+
- **Time Limit**: {'seconds': 4, '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-0261/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 687_A. NP-Hard Problem
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
|
| 5 |
+
|
| 6 |
+
Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv there is at least one endpoint of it in this set, i.e. <image> or <image> (or both).
|
| 7 |
+
|
| 8 |
+
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
|
| 9 |
+
|
| 10 |
+
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices A and B, such that both A and B are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the prize graph, respectively.
|
| 15 |
+
|
| 16 |
+
Each of the next m lines contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n), denoting an undirected edge between ui and vi. It's guaranteed the graph won't contain any self-loops or multiple edges.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
|
| 21 |
+
|
| 22 |
+
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer k denoting the number of vertices in that vertex cover, and the second line contains k integers — the indices of vertices. Note that because of m ≥ 1, vertex cover cannot be empty.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
4 2
|
| 29 |
+
1 2
|
| 30 |
+
2 3
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
1
|
| 36 |
+
2
|
| 37 |
+
2
|
| 38 |
+
1 3
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
3 3
|
| 44 |
+
1 2
|
| 45 |
+
2 3
|
| 46 |
+
1 3
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
-1
|
| 52 |
+
|
| 53 |
+
Note
|
| 54 |
+
|
| 55 |
+
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
|
| 56 |
+
|
| 57 |
+
In the second sample, there is no way to satisfy both Pari and Arya.
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 687
|
| 61 |
+
- **Problem Index**: A
|
| 62 |
+
- **Points**: 500.0
|
| 63 |
+
- **Rating**: 1500
|
| 64 |
+
- **Tags**: dfs and similar, graphs
|
| 65 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 66 |
+
- **Memory Limit**: 256000000 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-0266/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 79_D. Password
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Finally Fox Ciel arrived in front of her castle!
|
| 5 |
+
|
| 6 |
+
She have to type a password to enter her castle. An input device attached to her castle is a bit unusual.
|
| 7 |
+
|
| 8 |
+
The input device is a 1 × n rectangle divided into n square panels. They are numbered 1 to n from left to right. Each panel has a state either ON or OFF. Initially all panels are in the OFF state. She can enter her castle if and only if x1-th, x2-th, ..., xk-th panels are in the ON state and other panels are in the OFF state.
|
| 9 |
+
|
| 10 |
+
She is given an array a1, ..., al. In each move, she can perform the following operation: choose an index i (1 ≤ i ≤ l), choose consecutive ai panels, and flip the states of those panels (i.e. ON → OFF, OFF → ON).
|
| 11 |
+
|
| 12 |
+
Unfortunately she forgets how to type the password with only above operations. Determine the minimal number of operations required to enter her castle.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains three integers n, k and l (1 ≤ n ≤ 10000, 1 ≤ k ≤ 10, 1 ≤ l ≤ 100), separated by single spaces.
|
| 17 |
+
|
| 18 |
+
The second line contains k integers x1, ..., xk (1 ≤ x1 < x2 < ... < xk ≤ n), separated by single spaces.
|
| 19 |
+
|
| 20 |
+
The third line contains l integers a1, ..., al (1 ≤ ai ≤ n), separated by single spaces. It is possible that some elements of the array ai are equal value.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the minimal number of moves required to type the password. If it's impossible, print -1.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
10 8 2
|
| 31 |
+
1 2 3 5 6 7 8 9
|
| 32 |
+
3 5
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
2
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
3 2 1
|
| 43 |
+
1 2
|
| 44 |
+
3
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
-1
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
One possible way to type the password in the first example is following: In the first move, choose 1st, 2nd, 3rd panels and flip those panels. In the second move, choose 5th, 6th, 7th, 8th, 9th panels and flip those panels.
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 79
|
| 57 |
+
- **Problem Index**: D
|
| 58 |
+
- **Points**: 2000.0
|
| 59 |
+
- **Rating**: 2800
|
| 60 |
+
- **Tags**: bitmasks, dp, shortest paths
|
| 61 |
+
- **Time Limit**: {'seconds': 1, '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-0268/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 846_B. Math Show
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
|
| 5 |
+
|
| 6 |
+
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
|
| 7 |
+
|
| 8 |
+
Polycarp has M minutes of time. What is the maximum number of points he can earn?
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
|
| 13 |
+
|
| 14 |
+
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print the maximum amount of points Polycarp can earn in M minutes.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3 4 11
|
| 25 |
+
1 2 3 4
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
6
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
5 5 10
|
| 36 |
+
1 2 4 8 16
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
7
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
|
| 46 |
+
|
| 47 |
+
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 846
|
| 51 |
+
- **Problem Index**: B
|
| 52 |
+
- **Points**: 0.0
|
| 53 |
+
- **Rating**: 1800
|
| 54 |
+
- **Tags**: brute force, greedy
|
| 55 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 56 |
+
- **Memory Limit**: 256000000 bytes
|
| 57 |
+
|
| 58 |
+
## Task
|
| 59 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0281/instruction.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# play-with-string
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.
|
| 5 |
+
|
| 6 |
+
(Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. |x| denotes the absolute value of an integer x)
|
| 7 |
+
|
| 8 |
+
SAMPLE INPUT
|
| 9 |
+
2
|
| 10 |
+
acxz
|
| 11 |
+
bcxz
|
| 12 |
+
|
| 13 |
+
SAMPLE OUTPUT
|
| 14 |
+
Funny
|
| 15 |
+
Not Funny
|
| 16 |
+
|
| 17 |
+
Explanation
|
| 18 |
+
|
| 19 |
+
Consider the 1st testcase acxz :
|
| 20 |
+
|
| 21 |
+
c-a
|
| 22 |
+
=
|
| 23 |
+
x-z
|
| 24 |
+
= 2
|
| 25 |
+
|
| 26 |
+
z-x
|
| 27 |
+
=
|
| 28 |
+
a-c
|
| 29 |
+
= 2
|
| 30 |
+
|
| 31 |
+
Consider the 2st testcase bcxz
|
| 32 |
+
|
| 33 |
+
|c-b| != |x-z|
|
| 34 |
+
|
| 35 |
+
## Contest Information
|
| 36 |
+
- **Contest ID**: 0
|
| 37 |
+
- **Problem Index**:
|
| 38 |
+
- **Points**: 0.0
|
| 39 |
+
- **Rating**: 0
|
| 40 |
+
- **Tags**: None
|
| 41 |
+
- **Time Limit**: None seconds
|
| 42 |
+
- **Memory Limit**: 0 bytes
|
| 43 |
+
|
| 44 |
+
## Task
|
| 45 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0292/instruction.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03612 AtCoder Beginner Contest 072 - Derangement
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero):
|
| 5 |
+
|
| 6 |
+
Operation: Swap two adjacent elements in the permutation.
|
| 7 |
+
|
| 8 |
+
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
|
| 12 |
+
* 2≤N≤10^5
|
| 13 |
+
* p_1,p_2,..,p_N is a permutation of 1,2,..,N.
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
The input is given from Standard Input in the following format:
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
N
|
| 21 |
+
p_1 p_2 .. p_N
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print the minimum required number of operations
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
5
|
| 33 |
+
1 4 3 5 2
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
2
|
| 44 |
+
1 2
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
1
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
2
|
| 55 |
+
2 1
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
0
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Input
|
| 64 |
+
|
| 65 |
+
9
|
| 66 |
+
1 2 4 9 5 8 7 3 6
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Output
|
| 70 |
+
|
| 71 |
+
3
|
| 72 |
+
|
| 73 |
+
## Contest Information
|
| 74 |
+
- **Contest ID**: 0
|
| 75 |
+
- **Problem Index**:
|
| 76 |
+
- **Points**: 0.0
|
| 77 |
+
- **Rating**: 0
|
| 78 |
+
- **Tags**:
|
| 79 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 80 |
+
- **Memory Limit**: 268435456 bytes
|
| 81 |
+
|
| 82 |
+
## Task
|
| 83 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0401/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00260 Cats Going Straight
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There was a large mansion surrounded by high walls. The owner of the mansion loved cats so much that he always prepared delicious food for the occasional cats. The hungry cats jumped over the high walls and rushed straight to the rice that was everywhere in the mansion.
|
| 5 |
+
|
| 6 |
+
One day the husband found some cats lying down in the mansion. The cats ran around the mansion in search of food, hitting and falling. The husband decided to devise a place to put the rice in consideration of the safety of the cats.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
Seen from the sky, the fence of this mansion is polygonal. The owner decided to place the rice only at the top of the polygon on the premises so that the cats could easily find it. Also, since cats are capricious, it is unpredictable from which point on the circumference of the polygon they will enter the mansion. Therefore, the husband also decided to arrange the rice so that no matter where the cat entered, he would go straight from that point and reach one of the rice.
|
| 11 |
+
|
| 12 |
+
You can meet this condition by placing rice at all vertices. However, it is difficult to replenish the rice and go around, so the master wanted to place the rice at as few vertices as possible. Now, how many places does the master need to place the rice?
|
| 13 |
+
|
| 14 |
+
Enter the polygon that represents the wall of the mansion as an input, and create a program that finds the minimum number of vertices on which rice is placed. However, the cat shall be able to go straight only inside the polygon (the sides shall be included inside the polygon).
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
input
|
| 19 |
+
|
| 20 |
+
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
n
|
| 24 |
+
x1 y1
|
| 25 |
+
x2 y2
|
| 26 |
+
...
|
| 27 |
+
xn yn
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
The number of vertices of the polygon n (3 ≤ n ≤ 16) is given in the first line. The following n lines give the coordinates of the vertices of the polygon. Each of the n lines consists of two integers separated by one space. xi (-1000 ≤ xi ≤ 1000) indicates the x coordinate of the i-th vertex, and yi (-1000 ≤ yi ≤ 1000) indicates the y coordinate of the i-th vertex. The vertices of a polygon are given in such an order that they visit adjacent vertices counterclockwise.
|
| 31 |
+
|
| 32 |
+
The number of datasets does not exceed 20.
|
| 33 |
+
|
| 34 |
+
output
|
| 35 |
+
|
| 36 |
+
For each data set, the number of vertices on which rice is placed is output on one line.
|
| 37 |
+
|
| 38 |
+
Example
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
8
|
| 43 |
+
0 0
|
| 44 |
+
3 2
|
| 45 |
+
6 2
|
| 46 |
+
8 6
|
| 47 |
+
6 5
|
| 48 |
+
7 7
|
| 49 |
+
0 4
|
| 50 |
+
3 4
|
| 51 |
+
8
|
| 52 |
+
0 0
|
| 53 |
+
5 3
|
| 54 |
+
5 2
|
| 55 |
+
4 1
|
| 56 |
+
6 1
|
| 57 |
+
8 6
|
| 58 |
+
6 4
|
| 59 |
+
2 4
|
| 60 |
+
0
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
1
|
| 66 |
+
2
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 0
|
| 70 |
+
- **Problem Index**:
|
| 71 |
+
- **Points**: 0.0
|
| 72 |
+
- **Rating**: 0
|
| 73 |
+
- **Tags**:
|
| 74 |
+
- **Time Limit**: {'seconds': 5, '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-0406/instruction.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01046 Yu-kun Likes a lot of Money
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Background
|
| 5 |
+
|
| 6 |
+
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves money as much as programming. Yu-kun visited the island where treasures sleep to make money today. Yu-kun has obtained a map of the treasure in advance. I want to make as much money as possible based on the map. How much money can Yu get up to?
|
| 7 |
+
|
| 8 |
+
Problem
|
| 9 |
+
|
| 10 |
+
You will be given a map, Yu-kun's initial location, the types of treasures and the money they will earn, and the cost of destroying the small rocks. Map information is given as a field of h squares x w squares. The characters written on each square of the map and their meanings are as follows.
|
| 11 |
+
|
| 12 |
+
*'@': Indicates the position where Yu is first. After Yu-kun moves, treat it like a road.
|
| 13 |
+
*'.': Represents the way. This square is free to pass and does not cost anything.
|
| 14 |
+
*'#': Represents a large rock. This square cannot pass.
|
| 15 |
+
*'*': Represents a small rock. It can be broken by paying a certain amount. After breaking it, it becomes a road.
|
| 16 |
+
* '0', '1', ..., '9','a','b', ...,'z','A','B', ...,'Z': Treasure Represents a square. By visiting this square, you will get the amount of money of the treasure corresponding to the letters written on it. However, you can only get money when you first visit.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Yu-kun can move to any of the adjacent squares, up, down, left, and right with one move. However, you cannot move out of the map.
|
| 21 |
+
|
| 22 |
+
You don't have to have the amount you need to break a small rock at the time, as you can pay later. Therefore, Yu needs to earn more than the sum of the amount of money it took to finally break a small rock.
|
| 23 |
+
|
| 24 |
+
Output the maximum amount you can get.
|
| 25 |
+
|
| 26 |
+
Constraints
|
| 27 |
+
|
| 28 |
+
The input meets the following constraints.
|
| 29 |
+
|
| 30 |
+
* 1 ≤ h, w ≤ 8
|
| 31 |
+
* 0 ≤ n ≤ min (h × w -1,62) where min (a, b) represents the minimum value of a, b
|
| 32 |
+
* 1 ≤ vi ≤ 105 (1 ≤ i ≤ n)
|
| 33 |
+
* 1 ≤ r ≤ 105
|
| 34 |
+
* All inputs except cj, k, ml are given as integers (1 ≤ j ≤ h, 1 ≤ k ≤ w, 1 ≤ l ≤ n)
|
| 35 |
+
* Exactly one'@' is written on the map
|
| 36 |
+
* Just n treasures are written on the map
|
| 37 |
+
* The type of treasure written on the map is one of the ml given in the input
|
| 38 |
+
* No more than one treasure of the same type will appear on the map
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
The input is given in the following format.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
h w n r
|
| 46 |
+
c1,1 c1,2… c1, w
|
| 47 |
+
c2,1 c2,2… c2, w
|
| 48 |
+
...
|
| 49 |
+
ch, 1 ch, 2… ch, w
|
| 50 |
+
m1 v1
|
| 51 |
+
m2 v2
|
| 52 |
+
...
|
| 53 |
+
mn vn
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
In the first line, the vertical length h of the map, the horizontal length w, the number of treasures contained in the map n, and the cost r for destroying a small rock are given separated by blanks.
|
| 57 |
+
|
| 58 |
+
In the following h line, w pieces of information ci and j of each cell representing the map are given. (1 ≤ i ≤ h, 1 ≤ j ≤ w)
|
| 59 |
+
|
| 60 |
+
In the next n lines, the treasure type mk and the treasure amount vk are given, separated by blanks. (1 ≤ k ≤ n)
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
Output the maximum amount of money you can get on one line.
|
| 65 |
+
|
| 66 |
+
Examples
|
| 67 |
+
|
| 68 |
+
Input
|
| 69 |
+
|
| 70 |
+
3 3 1 10
|
| 71 |
+
@0.
|
| 72 |
+
...
|
| 73 |
+
...
|
| 74 |
+
0 100
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Output
|
| 78 |
+
|
| 79 |
+
100
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Input
|
| 83 |
+
|
| 84 |
+
3 3 1 10
|
| 85 |
+
@#b
|
| 86 |
+
.#.
|
| 87 |
+
.#.
|
| 88 |
+
b 100
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
Output
|
| 92 |
+
|
| 93 |
+
0
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
Input
|
| 97 |
+
|
| 98 |
+
3 3 1 20
|
| 99 |
+
@*C
|
| 100 |
+
..*
|
| 101 |
+
...
|
| 102 |
+
C 10
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
Output
|
| 106 |
+
|
| 107 |
+
0
|
| 108 |
+
|
| 109 |
+
## Contest Information
|
| 110 |
+
- **Contest ID**: 0
|
| 111 |
+
- **Problem Index**:
|
| 112 |
+
- **Points**: 0.0
|
| 113 |
+
- **Rating**: 0
|
| 114 |
+
- **Tags**:
|
| 115 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 116 |
+
- **Memory Limit**: 268435456 bytes
|
| 117 |
+
|
| 118 |
+
## Task
|
| 119 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0408/instruction.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01316 Differential Pulse Code Modulation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals.
|
| 5 |
+
|
| 6 |
+
The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, this sequence of integers tends to have similar values before and after. Differential pulse code modulation uses this to encode the difference between the values before and after and improve the compression rate.
|
| 7 |
+
|
| 8 |
+
In this problem, we consider selecting the difference value from a predetermined set of values. We call this set of values a codebook. The decrypted audio signal yn is defined by the following equation.
|
| 9 |
+
|
| 10 |
+
> yn = yn --1 + C [kn]
|
| 11 |
+
|
| 12 |
+
Where kn is the output sequence output by the program and C [j] is the jth value in the codebook. However, yn is rounded to 0 if the value is less than 0 by addition, and to 255 if the value is greater than 255. The value of y0 is 128.
|
| 13 |
+
|
| 14 |
+
Your job is to select the output sequence so that the sum of squares of the difference between the original input signal and the decoded output signal is minimized given the input signal and the codebook, and the difference at that time. It is to write a program that outputs the sum of squares of.
|
| 15 |
+
|
| 16 |
+
For example, if you compress the columns 131, 137 using a set of values {4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 4 = When compressed into the sequence 132, y2 = 132 + 4 = 136, the sum of squares becomes the minimum (131 --132) ^ 2 + (137 --136) ^ 2 = 2.
|
| 17 |
+
|
| 18 |
+
Also, if you also compress the columns 131, 123 using the set of values {4, 2, 1, 0, -1, -2, -4} as a codebook, y0 = 128, y1 = 128 + 1 = 129, y2 = 129 --4 = 125, and unlike the previous example, it is better not to adopt +2, which is closer to 131 (131 --129) ^ 2 + (123 --125) ^ 2 = 8, which is a smaller square. The sum is obtained.
|
| 19 |
+
|
| 20 |
+
The above two examples are the first two examples of sample input.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
The input consists of multiple datasets. The format of each data set is as follows.
|
| 27 |
+
|
| 28 |
+
> N M
|
| 29 |
+
> C1
|
| 30 |
+
> C2
|
| 31 |
+
> ...
|
| 32 |
+
> CM
|
| 33 |
+
> x1
|
| 34 |
+
> x2
|
| 35 |
+
> ...
|
| 36 |
+
> xN
|
| 37 |
+
>
|
| 38 |
+
|
| 39 |
+
The first line specifies the size of the input dataset. N is the length (number of samples) of the input signal to be compressed. M is the number of values contained in the codebook. N and M satisfy 1 ≤ N ≤ 20000 and 1 ≤ M ≤ 16.
|
| 40 |
+
|
| 41 |
+
The M line that follows is the description of the codebook. Ci represents the i-th value contained in the codebook. Ci satisfies -255 ≤ Ci ≤ 255.
|
| 42 |
+
|
| 43 |
+
The N lines that follow are the description of the input signal. xi is the i-th value of a sequence of integers representing the input signal. xi satisfies 0 ≤ xi ≤ 255.
|
| 44 |
+
|
| 45 |
+
The input items in the dataset are all integers. The end of the input is represented by a line consisting of only two zeros separated by a single space character.
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
For each input data set, output the minimum value of the sum of squares of the difference between the original input signal and the decoded output signal in one line.
|
| 50 |
+
|
| 51 |
+
Example
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
2 7
|
| 56 |
+
4
|
| 57 |
+
2
|
| 58 |
+
1
|
| 59 |
+
0
|
| 60 |
+
-1
|
| 61 |
+
-2
|
| 62 |
+
-4
|
| 63 |
+
131
|
| 64 |
+
137
|
| 65 |
+
2 7
|
| 66 |
+
4
|
| 67 |
+
2
|
| 68 |
+
1
|
| 69 |
+
0
|
| 70 |
+
-1
|
| 71 |
+
-2
|
| 72 |
+
-4
|
| 73 |
+
131
|
| 74 |
+
123
|
| 75 |
+
10 7
|
| 76 |
+
-4
|
| 77 |
+
-2
|
| 78 |
+
-1
|
| 79 |
+
0
|
| 80 |
+
1
|
| 81 |
+
2
|
| 82 |
+
4
|
| 83 |
+
132
|
| 84 |
+
134
|
| 85 |
+
135
|
| 86 |
+
134
|
| 87 |
+
132
|
| 88 |
+
128
|
| 89 |
+
124
|
| 90 |
+
122
|
| 91 |
+
121
|
| 92 |
+
122
|
| 93 |
+
5 1
|
| 94 |
+
255
|
| 95 |
+
0
|
| 96 |
+
0
|
| 97 |
+
0
|
| 98 |
+
0
|
| 99 |
+
0
|
| 100 |
+
4 1
|
| 101 |
+
0
|
| 102 |
+
255
|
| 103 |
+
0
|
| 104 |
+
255
|
| 105 |
+
0
|
| 106 |
+
0 0
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
Output
|
| 110 |
+
|
| 111 |
+
2
|
| 112 |
+
8
|
| 113 |
+
0
|
| 114 |
+
325125
|
| 115 |
+
65026
|
| 116 |
+
|
| 117 |
+
## Contest Information
|
| 118 |
+
- **Contest ID**: 0
|
| 119 |
+
- **Problem Index**:
|
| 120 |
+
- **Points**: 0.0
|
| 121 |
+
- **Rating**: 0
|
| 122 |
+
- **Tags**:
|
| 123 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 124 |
+
- **Memory Limit**: 134217728 bytes
|
| 125 |
+
|
| 126 |
+
## Task
|
| 127 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0423/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1027_E. Inverse Coloring
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a square board, consisting of n rows and n columns. Each tile in it should be colored either white or black.
|
| 5 |
+
|
| 6 |
+
Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.
|
| 7 |
+
|
| 8 |
+
Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least k tiles.
|
| 9 |
+
|
| 10 |
+
Your task is to count the number of suitable colorings of the board of the given size.
|
| 11 |
+
|
| 12 |
+
Since the answer can be very large, print it modulo 998244353.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
A single line contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n^2) — the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print a single integer — the number of suitable colorings of the board of the given size modulo 998244353.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
1 1
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
0
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
2 3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
6
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
49 1808
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
359087121
|
| 52 |
+
|
| 53 |
+
Note
|
| 54 |
+
|
| 55 |
+
Board of size 1 × 1 is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of 1 tile.
|
| 56 |
+
|
| 57 |
+
Here are the beautiful colorings of a board of size 2 × 2 that don't include rectangles of a single color, consisting of at least 3 tiles:
|
| 58 |
+
|
| 59 |
+
<image>
|
| 60 |
+
|
| 61 |
+
The rest of beautiful colorings of a board of size 2 × 2 are the following:
|
| 62 |
+
|
| 63 |
+
<image>
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 1027
|
| 67 |
+
- **Problem Index**: E
|
| 68 |
+
- **Points**: 0.0
|
| 69 |
+
- **Rating**: 2100
|
| 70 |
+
- **Tags**: combinatorics, dp, math
|
| 71 |
+
- **Time Limit**: {'seconds': 2, '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-0430/instruction.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1180_E. Serge and Dining Room
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Serge came to the school dining room and discovered that there is a big queue here. There are m pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him.
|
| 5 |
+
|
| 6 |
+
Initially there are n dishes with costs a_1, a_2, …, a_n. As you already know, there are the queue of m pupils who have b_1, …, b_m togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has b_1 togrogs and the last one has b_m togrogs)
|
| 7 |
+
|
| 8 |
+
Pupils think that the most expensive dish is the most delicious one, so every pupil just buys the most expensive dish for which he has money (every dish has a single copy, so when a pupil has bought it nobody can buy it later), and if a pupil doesn't have money for any dish, he just leaves the queue (so brutal capitalism...)
|
| 9 |
+
|
| 10 |
+
But money isn't a problem at all for Serge, so Serge is buying the most expensive dish if there is at least one remaining.
|
| 11 |
+
|
| 12 |
+
Moreover, Serge's school has a very unstable economic situation and the costs of some dishes or number of togrogs of some pupils can change. More formally, you must process q queries:
|
| 13 |
+
|
| 14 |
+
* change a_i to x. It means that the price of the i-th dish becomes x togrogs.
|
| 15 |
+
* change b_i to x. It means that the i-th pupil in the queue has x togrogs now.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Nobody leaves the queue during those queries because a saleswoman is late.
|
| 20 |
+
|
| 21 |
+
After every query, you must tell Serge price of the dish which he will buy if he has waited until the queue is clear, or -1 if there are no dishes at this point, according to rules described above.
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
The first line contains integers n and m (1 ≤ n, m ≤ 300\ 000) — number of dishes and pupils respectively. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^{6}) — elements of array a. The third line contains m integers b_1, b_2, …, b_{m} (1 ≤ b_i ≤ 10^{6}) — elements of array b. The fourth line conatins integer q (1 ≤ q ≤ 300\ 000) — number of queries.
|
| 26 |
+
|
| 27 |
+
Each of the following q lines contains as follows:
|
| 28 |
+
|
| 29 |
+
* if a query changes price of some dish, it contains 1, and two integers i and x (1 ≤ i ≤ n, 1 ≤ x ≤ 10^{6}), what means a_i becomes x.
|
| 30 |
+
* if a query changes number of togrogs of some pupil, it contains 2, and two integers i and x (1 ≤ i ≤ m, 1 ≤ x ≤ 10^{6}), what means b_i becomes x.
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
For each of q queries prints the answer as the statement describes, the answer of the i-th query in the i-th line (the price of the dish which Serge will buy or -1 if nothing remains)
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
1 1
|
| 42 |
+
1
|
| 43 |
+
1
|
| 44 |
+
1
|
| 45 |
+
1 1 100
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
100
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
1 1
|
| 58 |
+
1
|
| 59 |
+
1
|
| 60 |
+
1
|
| 61 |
+
2 1 100
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Output
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
-1
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Input
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
4 6
|
| 74 |
+
1 8 2 4
|
| 75 |
+
3 3 6 1 5 2
|
| 76 |
+
3
|
| 77 |
+
1 1 1
|
| 78 |
+
2 5 10
|
| 79 |
+
1 1 6
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Output
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
8
|
| 86 |
+
-1
|
| 87 |
+
4
|
| 88 |
+
|
| 89 |
+
Note
|
| 90 |
+
|
| 91 |
+
In the first sample after the first query, there is one dish with price 100 togrogs and one pupil with one togrog, so Serge will buy the dish with price 100 togrogs.
|
| 92 |
+
|
| 93 |
+
In the second sample after the first query, there is one dish with price one togrog and one pupil with 100 togrogs, so Serge will get nothing.
|
| 94 |
+
|
| 95 |
+
In the third sample after the first query, nobody can buy the dish with price 8, so Serge will take it. After the second query, all dishes will be bought, after the third one the third and fifth pupils will by the first and the second dishes respectively and nobody will by the fourth one.
|
| 96 |
+
|
| 97 |
+
## Contest Information
|
| 98 |
+
- **Contest ID**: 1180
|
| 99 |
+
- **Problem Index**: E
|
| 100 |
+
- **Points**: 1500.0
|
| 101 |
+
- **Rating**: 2200
|
| 102 |
+
- **Tags**: binary search, data structures, graph matchings, greedy, implementation, math, trees
|
| 103 |
+
- **Time Limit**: {'seconds': 4, '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-0437/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1325_B. CopyCopyCopyCopyCopy
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
|
| 5 |
+
|
| 6 |
+
A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains an integer t — the number of test cases you need to solve. The description of the test cases follows.
|
| 11 |
+
|
| 12 |
+
The first line of each test case contains an integer n (1 ≤ n ≤ 10^5) — the number of elements in the array a.
|
| 13 |
+
|
| 14 |
+
The second line contains n space-separated integers a_1, a_2, …, a_{n} (1 ≤ a_i ≤ 10^9) — the elements of the array a.
|
| 15 |
+
|
| 16 |
+
The sum of n across the test cases doesn't exceed 10^5.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
For each testcase, output the length of the longest increasing subsequence of a if you concatenate it to itself n times.
|
| 21 |
+
|
| 22 |
+
Example
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
2
|
| 28 |
+
3
|
| 29 |
+
3 2 1
|
| 30 |
+
6
|
| 31 |
+
3 1 4 1 5 9
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
3
|
| 38 |
+
5
|
| 39 |
+
|
| 40 |
+
Note
|
| 41 |
+
|
| 42 |
+
In the first sample, the new array is [3,2,1,3,2,1,3,2,1]. The longest increasing subsequence is marked in bold.
|
| 43 |
+
|
| 44 |
+
In the second sample, the longest increasing subsequence will be [1,3,4,5,9].
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 1325
|
| 48 |
+
- **Problem Index**: B
|
| 49 |
+
- **Points**: 750.0
|
| 50 |
+
- **Rating**: 800
|
| 51 |
+
- **Tags**: greedy, implementation
|
| 52 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 53 |
+
- **Memory Limit**: 256000000 bytes
|
| 54 |
+
|
| 55 |
+
## Task
|
| 56 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0439/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1366_A. Shovels and Swords
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.
|
| 5 |
+
|
| 6 |
+
Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a sticks and b diamonds?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.
|
| 11 |
+
|
| 12 |
+
The only line of each test case contains two integers a and b (0 ≤ a, b ≤ 10^9) — the number of sticks and the number of diamonds, respectively.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
For each test case print one integer — the maximum number of emeralds Polycarp can earn.
|
| 17 |
+
|
| 18 |
+
Example
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
4
|
| 24 |
+
4 4
|
| 25 |
+
1000000000 0
|
| 26 |
+
7 15
|
| 27 |
+
8 7
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
2
|
| 34 |
+
0
|
| 35 |
+
7
|
| 36 |
+
5
|
| 37 |
+
|
| 38 |
+
Note
|
| 39 |
+
|
| 40 |
+
In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.
|
| 41 |
+
|
| 42 |
+
In the second test case Polycarp does not have any diamonds, so he cannot craft anything.
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 1366
|
| 46 |
+
- **Problem Index**: A
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 1100
|
| 49 |
+
- **Tags**: binary search, greedy, math
|
| 50 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 256000000 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-0441/instruction.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1408_A. Circle Coloring
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given three sequences: a_1, a_2, …, a_n; b_1, b_2, …, b_n; c_1, c_2, …, c_n.
|
| 5 |
+
|
| 6 |
+
For each i, a_i ≠ b_i, a_i ≠ c_i, b_i ≠ c_i.
|
| 7 |
+
|
| 8 |
+
Find a sequence p_1, p_2, …, p_n, that satisfy the following conditions:
|
| 9 |
+
|
| 10 |
+
* p_i ∈ \\{a_i, b_i, c_i\}
|
| 11 |
+
* p_i ≠ p_{(i mod n) + 1}.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements i,i+1 adjacent for i<n and also elements 1 and n) will have equal value.
|
| 16 |
+
|
| 17 |
+
It can be proved that in the given constraints solution always exists. You don't need to minimize/maximize anything, you need to find any proper sequence.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line of input contains one integer t (1 ≤ t ≤ 100): the number of test cases.
|
| 22 |
+
|
| 23 |
+
The first line of each test case contains one integer n (3 ≤ n ≤ 100): the number of elements in the given sequences.
|
| 24 |
+
|
| 25 |
+
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100).
|
| 26 |
+
|
| 27 |
+
The third line contains n integers b_1, b_2, …, b_n (1 ≤ b_i ≤ 100).
|
| 28 |
+
|
| 29 |
+
The fourth line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 100).
|
| 30 |
+
|
| 31 |
+
It is guaranteed that a_i ≠ b_i, a_i ≠ c_i, b_i ≠ c_i for all i.
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
For each test case, print n integers: p_1, p_2, …, p_n (p_i ∈ \\{a_i, b_i, c_i\}, p_i ≠ p_{i mod n + 1}).
|
| 36 |
+
|
| 37 |
+
If there are several solutions, you can print any.
|
| 38 |
+
|
| 39 |
+
Example
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
5
|
| 45 |
+
3
|
| 46 |
+
1 1 1
|
| 47 |
+
2 2 2
|
| 48 |
+
3 3 3
|
| 49 |
+
4
|
| 50 |
+
1 2 1 2
|
| 51 |
+
2 1 2 1
|
| 52 |
+
3 4 3 4
|
| 53 |
+
7
|
| 54 |
+
1 3 3 1 1 1 1
|
| 55 |
+
2 4 4 3 2 2 4
|
| 56 |
+
4 2 2 2 4 4 2
|
| 57 |
+
3
|
| 58 |
+
1 2 1
|
| 59 |
+
2 3 3
|
| 60 |
+
3 1 2
|
| 61 |
+
10
|
| 62 |
+
1 1 1 2 2 2 3 3 3 1
|
| 63 |
+
2 2 2 3 3 3 1 1 1 2
|
| 64 |
+
3 3 3 1 1 1 2 2 2 3
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
1 2 3
|
| 71 |
+
1 2 1 2
|
| 72 |
+
1 3 4 3 2 4 2
|
| 73 |
+
1 3 2
|
| 74 |
+
1 2 3 1 2 3 1 2 3 2
|
| 75 |
+
|
| 76 |
+
Note
|
| 77 |
+
|
| 78 |
+
In the first test case p = [1, 2, 3].
|
| 79 |
+
|
| 80 |
+
It is a correct answer, because:
|
| 81 |
+
|
| 82 |
+
* p_1 = 1 = a_1, p_2 = 2 = b_2, p_3 = 3 = c_3
|
| 83 |
+
* p_1 ≠ p_2 , p_2 ≠ p_3 , p_3 ≠ p_1
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
All possible correct answers to this test case are: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1].
|
| 88 |
+
|
| 89 |
+
In the second test case p = [1, 2, 1, 2].
|
| 90 |
+
|
| 91 |
+
In this sequence p_1 = a_1, p_2 = a_2, p_3 = a_3, p_4 = a_4. Also we can see, that no two adjacent elements of the sequence are equal.
|
| 92 |
+
|
| 93 |
+
In the third test case p = [1, 3, 4, 3, 2, 4, 2].
|
| 94 |
+
|
| 95 |
+
In this sequence p_1 = a_1, p_2 = a_2, p_3 = b_3, p_4 = b_4, p_5 = b_5, p_6 = c_6, p_7 = c_7. Also we can see, that no two adjacent elements of the sequence are equal.
|
| 96 |
+
|
| 97 |
+
## Contest Information
|
| 98 |
+
- **Contest ID**: 1408
|
| 99 |
+
- **Problem Index**: A
|
| 100 |
+
- **Points**: 500.0
|
| 101 |
+
- **Rating**: 800
|
| 102 |
+
- **Tags**: constructive algorithms
|
| 103 |
+
- **Time Limit**: {'seconds': 1, '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-0448/instruction.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 178_A1. Educational Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
|
| 5 |
+
|
| 6 |
+
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.
|
| 7 |
+
|
| 8 |
+
One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).
|
| 9 |
+
|
| 10 |
+
You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces.
|
| 15 |
+
|
| 16 |
+
The input limitations for getting 20 points are:
|
| 17 |
+
|
| 18 |
+
* 1 ≤ n ≤ 300
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
The input limitations for getting 50 points are:
|
| 23 |
+
|
| 24 |
+
* 1 ≤ n ≤ 2000
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
The input limitations for getting 100 points are:
|
| 29 |
+
|
| 30 |
+
* 1 ≤ n ≤ 105
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero.
|
| 35 |
+
|
| 36 |
+
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.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
4
|
| 43 |
+
1 0 1 2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
1
|
| 49 |
+
1
|
| 50 |
+
3
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
8
|
| 56 |
+
1 2 3 4 5 6 7 8
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
1
|
| 62 |
+
3
|
| 63 |
+
6
|
| 64 |
+
10
|
| 65 |
+
16
|
| 66 |
+
24
|
| 67 |
+
40
|
| 68 |
+
|
| 69 |
+
## Contest Information
|
| 70 |
+
- **Contest ID**: 178
|
| 71 |
+
- **Problem Index**: A1
|
| 72 |
+
- **Points**: 20.0
|
| 73 |
+
- **Rating**: 1000
|
| 74 |
+
- **Tags**: greedy
|
| 75 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 76 |
+
- **Memory Limit**: 256000000 bytes
|
| 77 |
+
|
| 78 |
+
## Task
|
| 79 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0455/instruction.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 343_B. Alternating Current
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
|
| 5 |
+
|
| 6 |
+
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
|
| 11 |
+
|
| 12 |
+
To understand the problem better please read the notes to the test samples.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
-++-
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Yes
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
+-
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
No
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
++
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
Yes
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
-
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
No
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
|
| 66 |
+
|
| 67 |
+
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
|
| 68 |
+
|
| 69 |
+
<image>
|
| 70 |
+
|
| 71 |
+
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
|
| 72 |
+
|
| 73 |
+
<image>
|
| 74 |
+
|
| 75 |
+
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
|
| 76 |
+
|
| 77 |
+
<image>
|
| 78 |
+
|
| 79 |
+
## Contest Information
|
| 80 |
+
- **Contest ID**: 343
|
| 81 |
+
- **Problem Index**: B
|
| 82 |
+
- **Points**: 1000.0
|
| 83 |
+
- **Rating**: 1600
|
| 84 |
+
- **Tags**: data structures, greedy, implementation
|
| 85 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 86 |
+
- **Memory Limit**: 256000000 bytes
|
| 87 |
+
|
| 88 |
+
## Task
|
| 89 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0463/instruction.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 530_C. Diophantine equation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an equation A * X + B * Y = C, A, B, C are positive integer coefficients, X and Y are variables which can have positive integer values only. Output the number of solutions of this equation and the solutions themselves.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The only line of input contains integers A, B and C (1 ≤ A, B, C ≤ 1000), separated with spaces.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
In the first line of the output print the number of the solutions N. In the next N lines print the solutions, formatted as "XY", sorted in ascending order of X, one solution per line.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
3 5 35
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
2
|
| 24 |
+
5 4
|
| 25 |
+
10 1
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
3 35 5
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
0
|
| 36 |
+
|
| 37 |
+
## Contest Information
|
| 38 |
+
- **Contest ID**: 530
|
| 39 |
+
- **Problem Index**: C
|
| 40 |
+
- **Points**: 0.0
|
| 41 |
+
- **Rating**: 1500
|
| 42 |
+
- **Tags**: *special
|
| 43 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 44 |
+
- **Memory Limit**: 256000000 bytes
|
| 45 |
+
|
| 46 |
+
## Task
|
| 47 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0464/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 556_C. Case of Matryoshkas
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
|
| 5 |
+
|
| 6 |
+
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5.
|
| 7 |
+
|
| 8 |
+
In one second, you can perform one of the two following operations:
|
| 9 |
+
|
| 10 |
+
* Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
|
| 11 |
+
* Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out of b.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration.
|
| 20 |
+
|
| 21 |
+
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbers ai1, ai2, ..., aimi — the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
|
| 22 |
+
|
| 23 |
+
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
3 2
|
| 34 |
+
2 1 2
|
| 35 |
+
1 3
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
1
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
7 3
|
| 46 |
+
3 1 3 7
|
| 47 |
+
2 2 5
|
| 48 |
+
2 4 6
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
10
|
| 54 |
+
|
| 55 |
+
Note
|
| 56 |
+
|
| 57 |
+
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3.
|
| 58 |
+
|
| 59 |
+
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 556
|
| 63 |
+
- **Problem Index**: C
|
| 64 |
+
- **Points**: 250.0
|
| 65 |
+
- **Rating**: 1500
|
| 66 |
+
- **Tags**: implementation
|
| 67 |
+
- **Time Limit**: {'seconds': 2, '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-0470/instruction.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 699_F. Limak and Shooting Points
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.
|
| 5 |
+
|
| 6 |
+
There are n monsters in Bearland. The i-th of them stands at (mxi, myi).
|
| 7 |
+
|
| 8 |
+
The given k + n points are pairwise distinct.
|
| 9 |
+
|
| 10 |
+
After each teleportation, Limak can shoot an arrow in some direction. An arrow will hit the first monster in the chosen direction. Then, both an arrow and a monster disappear. It’s dangerous to stay in one place for long, so Limak can shoot only one arrow from one place.
|
| 11 |
+
|
| 12 |
+
A monster should be afraid if it’s possible that Limak will hit it. How many monsters should be afraid of Limak?
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains two integers k and n (1 ≤ k ≤ 7, 1 ≤ n ≤ 1000) — the number of stones and the number of monsters.
|
| 17 |
+
|
| 18 |
+
The i-th of following k lines contains two integers axi and ayi ( - 109 ≤ axi, ayi ≤ 109) — coordinates to which Limak can teleport using the i-th stone.
|
| 19 |
+
|
| 20 |
+
The i-th of last n lines contains two integers mxi and myi ( - 109 ≤ mxi, myi ≤ 109) — coordinates of the i-th monster.
|
| 21 |
+
|
| 22 |
+
The given k + n points are pairwise distinct.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print the number of monsters which should be afraid of Limak.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
2 4
|
| 33 |
+
-2 -1
|
| 34 |
+
4 5
|
| 35 |
+
4 2
|
| 36 |
+
2 1
|
| 37 |
+
4 -1
|
| 38 |
+
1 -1
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
3 8
|
| 49 |
+
10 20
|
| 50 |
+
0 0
|
| 51 |
+
20 40
|
| 52 |
+
300 600
|
| 53 |
+
30 60
|
| 54 |
+
170 340
|
| 55 |
+
50 100
|
| 56 |
+
28 56
|
| 57 |
+
90 180
|
| 58 |
+
-4 -8
|
| 59 |
+
-1 -2
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
5
|
| 65 |
+
|
| 66 |
+
Note
|
| 67 |
+
|
| 68 |
+
In the first sample, there are two stones and four monsters. Stones allow to teleport to points ( - 2, - 1) and (4, 5), marked blue in the drawing below. Monsters are at (4, 2), (2, 1), (4, - 1) and (1, - 1), marked red. A monster at (4, - 1) shouldn't be afraid because it's impossible that Limak will hit it with an arrow. Other three monsters can be hit and thus the answer is 3.
|
| 69 |
+
|
| 70 |
+
<image>
|
| 71 |
+
|
| 72 |
+
In the second sample, five monsters should be afraid. Safe monsters are those at (300, 600), (170, 340) and (90, 180).
|
| 73 |
+
|
| 74 |
+
## Contest Information
|
| 75 |
+
- **Contest ID**: 699
|
| 76 |
+
- **Problem Index**: F
|
| 77 |
+
- **Points**: 2000.0
|
| 78 |
+
- **Rating**: 2600
|
| 79 |
+
- **Tags**: brute force, geometry, math
|
| 80 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 81 |
+
- **Memory Limit**: 256000000 bytes
|
| 82 |
+
|
| 83 |
+
## Task
|
| 84 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0479/instruction.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 903_D. Almost Difference
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let's denote a function
|
| 5 |
+
|
| 6 |
+
<image>
|
| 7 |
+
|
| 8 |
+
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of the array.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print one integer — the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
5
|
| 25 |
+
1 2 3 1 3
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
4
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4
|
| 36 |
+
6 6 5 5
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
0
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
4
|
| 47 |
+
6 6 4 4
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
-8
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
In the first example:
|
| 57 |
+
|
| 58 |
+
1. d(a1, a2) = 0;
|
| 59 |
+
2. d(a1, a3) = 2;
|
| 60 |
+
3. d(a1, a4) = 0;
|
| 61 |
+
4. d(a1, a5) = 2;
|
| 62 |
+
5. d(a2, a3) = 0;
|
| 63 |
+
6. d(a2, a4) = 0;
|
| 64 |
+
7. d(a2, a5) = 0;
|
| 65 |
+
8. d(a3, a4) = - 2;
|
| 66 |
+
9. d(a3, a5) = 0;
|
| 67 |
+
10. d(a4, a5) = 2.
|
| 68 |
+
|
| 69 |
+
## Contest Information
|
| 70 |
+
- **Contest ID**: 903
|
| 71 |
+
- **Problem Index**: D
|
| 72 |
+
- **Points**: 0.0
|
| 73 |
+
- **Rating**: 2200
|
| 74 |
+
- **Tags**: data structures, math
|
| 75 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 76 |
+
- **Memory Limit**: 256000000 bytes
|
| 77 |
+
|
| 78 |
+
## Task
|
| 79 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0499/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03371 AtCoder Beginner Contest 095 - Half and Half
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.
|
| 5 |
+
|
| 6 |
+
Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* 1 ≤ A, B, C ≤ 5000
|
| 11 |
+
* 1 ≤ X, Y ≤ 10^5
|
| 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 |
+
A B C X Y
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
1500 2000 1600 3 2
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
7900
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
1500 2000 1900 3 2
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
8500
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
1500 2000 500 90000 100000
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
100000000
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 0
|
| 59 |
+
- **Problem Index**:
|
| 60 |
+
- **Points**: 0.0
|
| 61 |
+
- **Rating**: 0
|
| 62 |
+
- **Tags**:
|
| 63 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 64 |
+
- **Memory Limit**: 268435456 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-0602/instruction.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
|
| 5 |
+
|
| 6 |
+
We would like to remove zero or more edges so that the following condition is satisfied:
|
| 7 |
+
|
| 8 |
+
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Find the minimum number of edges that need to be removed.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* 1 \leq N \leq 10^5
|
| 17 |
+
* N-1 \leq M \leq 10^5
|
| 18 |
+
* 1 \leq X_i \leq 10^9
|
| 19 |
+
* 1 \leq A_i < B_i \leq N
|
| 20 |
+
* 1 \leq Y_i \leq 10^9
|
| 21 |
+
* (A_i,B_i) \neq (A_j,B_j) (i \neq j)
|
| 22 |
+
* The given graph is connected.
|
| 23 |
+
* All values in input are integers.
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
Input is given from Standard Input in the following format:
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
N M
|
| 31 |
+
X_1 X_2 ... X_N
|
| 32 |
+
A_1 B_1 Y_1
|
| 33 |
+
A_2 B_2 Y_2
|
| 34 |
+
:
|
| 35 |
+
A_M B_M Y_M
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
Find the minimum number of edges that need to be removed.
|
| 41 |
+
|
| 42 |
+
Examples
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
4 4
|
| 47 |
+
2 3 5 7
|
| 48 |
+
1 2 7
|
| 49 |
+
1 3 9
|
| 50 |
+
2 3 12
|
| 51 |
+
3 4 18
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
2
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
6 10
|
| 62 |
+
4 4 1 1 1 7
|
| 63 |
+
3 5 19
|
| 64 |
+
2 5 20
|
| 65 |
+
4 5 8
|
| 66 |
+
1 6 16
|
| 67 |
+
2 3 9
|
| 68 |
+
3 6 16
|
| 69 |
+
3 4 1
|
| 70 |
+
2 6 20
|
| 71 |
+
2 4 19
|
| 72 |
+
1 2 9
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
4
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Input
|
| 81 |
+
|
| 82 |
+
10 9
|
| 83 |
+
81 16 73 7 2 61 86 38 90 28
|
| 84 |
+
6 8 725
|
| 85 |
+
3 10 12
|
| 86 |
+
1 4 558
|
| 87 |
+
4 9 615
|
| 88 |
+
5 6 942
|
| 89 |
+
8 9 918
|
| 90 |
+
2 7 720
|
| 91 |
+
4 7 292
|
| 92 |
+
7 10 414
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
Output
|
| 96 |
+
|
| 97 |
+
8
|
| 98 |
+
|
| 99 |
+
## Contest Information
|
| 100 |
+
- **Contest ID**: 0
|
| 101 |
+
- **Problem Index**:
|
| 102 |
+
- **Points**: 0.0
|
| 103 |
+
- **Rating**: 0
|
| 104 |
+
- **Tags**:
|
| 105 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 106 |
+
- **Memory Limit**: 1073741824 bytes
|
| 107 |
+
|
| 108 |
+
## Task
|
| 109 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0605/instruction.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03603 AtCoder Regular Contest 083 - Bichrome Tree
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
|
| 5 |
+
|
| 6 |
+
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
|
| 7 |
+
|
| 8 |
+
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to allocate colors and weights so that the following condition is satisfied for all v.
|
| 9 |
+
|
| 10 |
+
* The total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is X_v.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Here, the subtree whose root is v is the tree consisting of Vertex v and all of its descendants.
|
| 15 |
+
|
| 16 |
+
Determine whether it is possible to allocate colors and weights in this way.
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
|
| 20 |
+
* 1 \leq N \leq 1 000
|
| 21 |
+
* 1 \leq P_i \leq i - 1
|
| 22 |
+
* 0 \leq X_i \leq 5 000
|
| 23 |
+
|
| 24 |
+
Inputs
|
| 25 |
+
|
| 26 |
+
Input is given from Standard Input in the following format:
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
N
|
| 30 |
+
P_2 P_3 ... P_N
|
| 31 |
+
X_1 X_2 ... X_N
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Outputs
|
| 35 |
+
|
| 36 |
+
If it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
3
|
| 43 |
+
1 1
|
| 44 |
+
4 3 2
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
POSSIBLE
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
3
|
| 55 |
+
1 2
|
| 56 |
+
1 2 3
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
IMPOSSIBLE
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Input
|
| 65 |
+
|
| 66 |
+
8
|
| 67 |
+
1 1 1 3 4 5 5
|
| 68 |
+
4 1 6 2 2 1 3 3
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Output
|
| 72 |
+
|
| 73 |
+
POSSIBLE
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Input
|
| 77 |
+
|
| 78 |
+
1
|
| 79 |
+
|
| 80 |
+
0
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
Output
|
| 84 |
+
|
| 85 |
+
POSSIBLE
|
| 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**: 268435456 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-0611/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00483 Planetary Exploration
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. The planned place of residence has a rectangular shape of M km north-south and N km east-west, and is divided into square sections of 1 km square. There are MN compartments in total, and the compartments in the p-th row from the north and the q-th column from the west are represented by (p, q). The northwest corner section is (1, 1) and the southeast corner section is (M, N). The terrain of each section is one of "jungle", "sea", and "ice". "Jungle" is represented by J, "sea" is represented by O, and "ice" is represented by one letter I.
|
| 5 |
+
|
| 6 |
+
Now, in making a detailed migration plan, I decided to investigate how many sections of "jungle," "sea," and "ice" are included in the rectangular area at K.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
input
|
| 11 |
+
|
| 12 |
+
Read the following input from standard input.
|
| 13 |
+
|
| 14 |
+
* The integers M and N are written on the first line, separated by blanks, indicating that the planned residence is M km north-south and N km east-west.
|
| 15 |
+
* The integer K is written on the second line, which indicates the number of regions to be investigated.
|
| 16 |
+
* The following M line contains information on the planned residence. The second line of i + (1 ≤ i ≤ M) contains an N-character string consisting of J, O, and I that represents the information of the N section located on the i-th line from the north of the planned residence. ..
|
| 17 |
+
* The following K line describes the area to be investigated. On the second line of j + M + (1 ≤ j ≤ K), the positive integers aj, bj, cj, and dj representing the jth region are written with blanks as delimiters. (aj, bj) represents the northwest corner section of the survey area, and (cj, dj) represents the southeast corner section of the survey area. However, aj, bj, cj, and dj satisfy 1 ≤ aj ≤ cj ≤ M, 1 ≤ bj ≤ dj ≤ N.
|
| 18 |
+
|
| 19 |
+
output
|
| 20 |
+
|
| 21 |
+
Output K lines representing the results of the survey to standard output. Line j of the output contains three integers representing the number of "jungle" (J) compartments, the "sea" (O) compartment, and the "ice" (I) compartment in the jth survey area. , In this order, separated by blanks.
|
| 22 |
+
|
| 23 |
+
Example
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
4 7
|
| 28 |
+
4
|
| 29 |
+
JIOJOIJ
|
| 30 |
+
IOJOIJO
|
| 31 |
+
JOIJOOI
|
| 32 |
+
OOJJIJO
|
| 33 |
+
3 5 4 7
|
| 34 |
+
2 2 3 6
|
| 35 |
+
2 2 2 2
|
| 36 |
+
1 1 4 7
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
1 3 2
|
| 42 |
+
3 5 2
|
| 43 |
+
0 1 0
|
| 44 |
+
10 11 7
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 0
|
| 48 |
+
- **Problem Index**:
|
| 49 |
+
- **Points**: 0.0
|
| 50 |
+
- **Rating**: 0
|
| 51 |
+
- **Tags**:
|
| 52 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 53 |
+
- **Memory Limit**: 134217728 bytes
|
| 54 |
+
|
| 55 |
+
## Task
|
| 56 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0642/instruction.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1251_E1. Voting (Easy Version)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The only difference between easy and hard versions is constraints.
|
| 5 |
+
|
| 6 |
+
Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.
|
| 7 |
+
|
| 8 |
+
There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins. The second way is to make m_i other voters vote for you, and the i-th voter will vote for free.
|
| 9 |
+
|
| 10 |
+
Moreover, the process of such voting takes place in several steps. For example, if there are five voters with m_1 = 1, m_2 = 2, m_3 = 2, m_4 = 4, m_5 = 5, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: {5} → {1, 5} → {1, 2, 3, 5} → {1, 2, 3, 4, 5}.
|
| 11 |
+
|
| 12 |
+
Calculate the minimum number of coins you have to spend so that everyone votes for you.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains one integer t (1 ≤ t ≤ 5000) — the number of test cases.
|
| 17 |
+
|
| 18 |
+
The first line of each test case contains one integer n (1 ≤ n ≤ 5000) — the number of voters.
|
| 19 |
+
|
| 20 |
+
The next n lines contains the description of voters. i-th line contains two integers m_i and p_i (1 ≤ p_i ≤ 10^9, 0 ≤ m_i < n).
|
| 21 |
+
|
| 22 |
+
It is guaranteed that the sum of all n over all test cases does not exceed 5000.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
For each test case print one integer — the minimum number of coins you have to spend so that everyone votes for you.
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
3
|
| 34 |
+
3
|
| 35 |
+
1 5
|
| 36 |
+
2 10
|
| 37 |
+
2 8
|
| 38 |
+
7
|
| 39 |
+
0 1
|
| 40 |
+
3 1
|
| 41 |
+
1 1
|
| 42 |
+
6 1
|
| 43 |
+
1 1
|
| 44 |
+
4 1
|
| 45 |
+
4 1
|
| 46 |
+
6
|
| 47 |
+
2 6
|
| 48 |
+
2 3
|
| 49 |
+
2 8
|
| 50 |
+
2 7
|
| 51 |
+
4 4
|
| 52 |
+
5 5
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
8
|
| 59 |
+
0
|
| 60 |
+
7
|
| 61 |
+
|
| 62 |
+
Note
|
| 63 |
+
|
| 64 |
+
In the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: {3} → {1, 3} → {1, 2, 3}.
|
| 65 |
+
|
| 66 |
+
In the second example you don't need to buy votes. The set of people voting for you will change as follows: {1} → {1, 3, 5} → {1, 2, 3, 5} → {1, 2, 3, 5, 6, 7} → {1, 2, 3, 4, 5, 6, 7}.
|
| 67 |
+
|
| 68 |
+
In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: {2, 5} → {1, 2, 3, 4, 5} → {1, 2, 3, 4, 5, 6}.
|
| 69 |
+
|
| 70 |
+
## Contest Information
|
| 71 |
+
- **Contest ID**: 1251
|
| 72 |
+
- **Problem Index**: E1
|
| 73 |
+
- **Points**: 0.0
|
| 74 |
+
- **Rating**: 2300
|
| 75 |
+
- **Tags**: data structures, dp, greedy
|
| 76 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 77 |
+
- **Memory Limit**: 512000000 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-0651/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1443_A. Kids Seating
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if:
|
| 5 |
+
|
| 6 |
+
1. gcd(a, b) = 1 or,
|
| 7 |
+
2. a divides b or b divides a.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
gcd(a, b) — the maximum number x such that a is divisible by x and b is divisible by x.
|
| 12 |
+
|
| 13 |
+
For example, if n=3 and the kids sit on chairs with numbers 2, 3, 4, then they will indulge since 4 is divided by 2 and gcd(2, 3) = 1. If kids sit on chairs with numbers 4, 6, 10, then they will not indulge.
|
| 14 |
+
|
| 15 |
+
The teacher really doesn't want the mess at the table, so she wants to seat the kids so there are no 2 of the kid that can indulge. More formally, she wants no pair of chairs a and b that the kids occupy to fulfill the condition above.
|
| 16 |
+
|
| 17 |
+
Since the teacher is very busy with the entertainment of the kids, she asked you to solve this problem.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then t test cases follow.
|
| 22 |
+
|
| 23 |
+
Each test case consists of one line containing an integer n (1 ≤ n ≤ 100) — the number of kids.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Output t lines, which contain n distinct integers from 1 to 4n — the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print n numbers in any order.
|
| 28 |
+
|
| 29 |
+
Example
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
2
|
| 36 |
+
3
|
| 37 |
+
4
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
6 4
|
| 44 |
+
4 6 10
|
| 45 |
+
14 10 12 8
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 1443
|
| 49 |
+
- **Problem Index**: A
|
| 50 |
+
- **Points**: 500.0
|
| 51 |
+
- **Rating**: 800
|
| 52 |
+
- **Tags**: constructive algorithms, math
|
| 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-0656/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 171_C. A Piece of Cake
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
How to make a cake you'll never eat.
|
| 5 |
+
|
| 6 |
+
Ingredients.
|
| 7 |
+
|
| 8 |
+
* 2 carrots
|
| 9 |
+
* 0 calories
|
| 10 |
+
* 100 g chocolate spread
|
| 11 |
+
* 1 pack of flour
|
| 12 |
+
* 1 egg
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Method.
|
| 17 |
+
|
| 18 |
+
1. Put calories into the mixing bowl.
|
| 19 |
+
2. Take carrots from refrigerator.
|
| 20 |
+
3. Chop carrots.
|
| 21 |
+
4. Take chocolate spread from refrigerator.
|
| 22 |
+
5. Put chocolate spread into the mixing bowl.
|
| 23 |
+
6. Combine pack of flour into the mixing bowl.
|
| 24 |
+
7. Fold chocolate spread into the mixing bowl.
|
| 25 |
+
8. Add chocolate spread into the mixing bowl.
|
| 26 |
+
9. Put pack of flour into the mixing bowl.
|
| 27 |
+
10. Add egg into the mixing bowl.
|
| 28 |
+
11. Fold pack of flour into the mixing bowl.
|
| 29 |
+
12. Chop carrots until choped.
|
| 30 |
+
13. Pour contents of the mixing bowl into the baking dish.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Serves 1.
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
The only line of input contains a sequence of integers a0, a1, ... (1 ≤ a0 ≤ 100, 0 ≤ ai ≤ 1000 for i ≥ 1).
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
Output a single integer.
|
| 43 |
+
|
| 44 |
+
Examples
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
4 1 2 3 4
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
30
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 171
|
| 57 |
+
- **Problem Index**: C
|
| 58 |
+
- **Points**: 0.0
|
| 59 |
+
- **Rating**: 2000
|
| 60 |
+
- **Tags**: *special, implementation
|
| 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-0658/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 215_A. Bicycle Chain
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
|
| 5 |
+
|
| 6 |
+
We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value <image>.
|
| 7 |
+
|
| 8 |
+
Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.
|
| 9 |
+
|
| 10 |
+
In the problem, fraction <image> denotes division in real numbers, that is, no rounding is performed.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing.
|
| 15 |
+
|
| 16 |
+
The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing.
|
| 17 |
+
|
| 18 |
+
It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print the number of "integer" gears with the maximum ratio among all "integer" gears.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
2
|
| 29 |
+
4 5
|
| 30 |
+
3
|
| 31 |
+
12 13 15
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
2
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
4
|
| 42 |
+
1 2 3 4
|
| 43 |
+
5
|
| 44 |
+
10 11 12 13 14
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
1
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 215
|
| 57 |
+
- **Problem Index**: A
|
| 58 |
+
- **Points**: 500.0
|
| 59 |
+
- **Rating**: 900
|
| 60 |
+
- **Tags**: brute force, implementation
|
| 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-0660/instruction.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 263_D. Cycle in Graph
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1.
|
| 5 |
+
|
| 6 |
+
A simple cycle of length d (d > 1) in graph G is a sequence of distinct graph nodes v1, v2, ..., vd such, that nodes v1 and vd are connected by an edge of the graph, also for any integer i (1 ≤ i < d) nodes vi and vi + 1 are connected by an edge of the graph.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains three integers n, m, k (3 ≤ n, m ≤ 105; 2 ≤ k ≤ n - 1) — the number of the nodes of the graph, the number of the graph's edges and the lower limit on the degree of the graph node. Next m lines contain pairs of integers. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the indexes of the graph nodes that are connected by the i-th edge.
|
| 11 |
+
|
| 12 |
+
It is guaranteed that the given graph doesn't contain any multiple edges or self-loops. It is guaranteed that each node of the graph is connected by the edges with at least k other nodes of the graph.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
In the first line print integer r (r ≥ k + 1) — the length of the found cycle. In the next line print r distinct integers v1, v2, ..., vr (1 ≤ vi ≤ n) — the found simple cycle.
|
| 17 |
+
|
| 18 |
+
It is guaranteed that the answer exists. If there are multiple correct answers, you are allowed to print any of them.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3 3 2
|
| 25 |
+
1 2
|
| 26 |
+
2 3
|
| 27 |
+
3 1
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
3
|
| 33 |
+
1 2 3
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
4 6 3
|
| 38 |
+
4 3
|
| 39 |
+
1 2
|
| 40 |
+
1 3
|
| 41 |
+
1 4
|
| 42 |
+
2 3
|
| 43 |
+
2 4
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
4
|
| 49 |
+
3 4 1 2
|
| 50 |
+
|
| 51 |
+
## Contest Information
|
| 52 |
+
- **Contest ID**: 263
|
| 53 |
+
- **Problem Index**: D
|
| 54 |
+
- **Points**: 2000.0
|
| 55 |
+
- **Rating**: 1800
|
| 56 |
+
- **Tags**: dfs and similar, graphs
|
| 57 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 58 |
+
- **Memory Limit**: 256000000 bytes
|
| 59 |
+
|
| 60 |
+
## Task
|
| 61 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0666/instruction.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 401_E. Olympic Games
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
This problem was deleted from the contest, because it was used previously at another competition.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
Output
|
| 9 |
+
|
| 10 |
+
Examples
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
1 1
|
| 15 |
+
1 2 100
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
6
|
| 21 |
+
|
| 22 |
+
## Contest Information
|
| 23 |
+
- **Contest ID**: 401
|
| 24 |
+
- **Problem Index**: E
|
| 25 |
+
- **Points**: 2500.0
|
| 26 |
+
- **Rating**: 2500
|
| 27 |
+
- **Tags**: math
|
| 28 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 29 |
+
- **Memory Limit**: 256000000 bytes
|
| 30 |
+
|
| 31 |
+
## Task
|
| 32 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|