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-0048/instruction.md +57 -0
- code_contests-0070/instruction.md +46 -0
- code_contests-0083/instruction.md +54 -0
- code_contests-0084/instruction.md +118 -0
- code_contests-0102/instruction.md +73 -0
- code_contests-0103/instruction.md +99 -0
- code_contests-0105/instruction.md +48 -0
- code_contests-0132/instruction.md +98 -0
- code_contests-0156/instruction.md +59 -0
- code_contests-0158/instruction.md +92 -0
- code_contests-0159/instruction.md +68 -0
- code_contests-0161/instruction.md +75 -0
- code_contests-0166/instruction.md +71 -0
- code_contests-0169/instruction.md +57 -0
- code_contests-0192/instruction.md +78 -0
- code_contests-0193/instruction.md +67 -0
- code_contests-0194/instruction.md +223 -0
- code_contests-0195/instruction.md +135 -0
- code_contests-0300/instruction.md +89 -0
- code_contests-0308/instruction.md +125 -0
- code_contests-0330/instruction.md +79 -0
- code_contests-0331/instruction.md +77 -0
- code_contests-0337/instruction.md +73 -0
- code_contests-0338/instruction.md +110 -0
- code_contests-0352/instruction.md +57 -0
- code_contests-0354/instruction.md +81 -0
- code_contests-0355/instruction.md +60 -0
- code_contests-0363/instruction.md +37 -0
- code_contests-0390/instruction.md +54 -0
- code_contests-0396/instruction.md +80 -0
- code_contests-0399/instruction.md +57 -0
- code_contests-0414/instruction.md +165 -0
- code_contests-0551/instruction.md +96 -0
- code_contests-0560/instruction.md +59 -0
- code_contests-0566/instruction.md +65 -0
- code_contests-0569/instruction.md +56 -0
- code_contests-0592/instruction.md +71 -0
- code_contests-0595/instruction.md +56 -0
- code_contests-0621/instruction.md +115 -0
- code_contests-0700/instruction.md +39 -0
- code_contests-0707/instruction.md +57 -0
- code_contests-0708/instruction.md +71 -0
- code_contests-0709/instruction.md +99 -0
- code_contests-0730/instruction.md +90 -0
- code_contests-0736/instruction.md +78 -0
- code_contests-0737/instruction.md +83 -0
- code_contests-0738/instruction.md +63 -0
- code_contests-0752/instruction.md +69 -0
- code_contests-0754/instruction.md +69 -0
- code_contests-0755/instruction.md +92 -0
code_contests-0048/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 571_E. Geometric Progressions
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....
|
| 5 |
+
|
| 6 |
+
You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains integer (1 ≤ n ≤ 100) — the number of geometric progressions.
|
| 11 |
+
|
| 12 |
+
Next n lines contain pairs of integers a, b (1 ≤ a, b ≤ 109), that are the first element and the common ratio of the corresponding geometric progression.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
If the intersection of all progressions is empty, then print - 1, otherwise print the remainder of the minimal positive integer number belonging to all progressions modulo 1000000007 (109 + 7).
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
2
|
| 23 |
+
2 2
|
| 24 |
+
4 1
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
4
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
2
|
| 35 |
+
2 2
|
| 36 |
+
3 3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
-1
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the second sample test one of the progressions contains only powers of two, the other one contains only powers of three.
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 571
|
| 49 |
+
- **Problem Index**: E
|
| 50 |
+
- **Points**: 2750.0
|
| 51 |
+
- **Rating**: 3200
|
| 52 |
+
- **Tags**: math
|
| 53 |
+
- **Time Limit**: {'seconds': 1, '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-0070/instruction.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# golu-and-coins-1
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Golu is given a task of clearing coins fallen down on floor. Naughty being his modus operandi, he thought of playing a game while clearing coins. He arranges the coins like an M X N matrix with random heads (1) and tails (0).
|
| 5 |
+
|
| 6 |
+
In every move, he chooses a sub-matrix of size L X B [such that max(L,B) >1] and interchanges all heads to tails and vice-versa present in the chosen sub-matrix. Then if he finds a 2X2 sub-matrix exclusively of heads anywhere in the M X N matrix, he removes those coins.
|
| 7 |
+
|
| 8 |
+
Your task is simple. You have to report the minimum no. of moves taken by him before he clears his first 2X2 sub-matrix.
|
| 9 |
+
|
| 10 |
+
Input:
|
| 11 |
+
|
| 12 |
+
Your first line of input consists of two numbers M, N. Each of the next M lines consists of N space-separated integers which are either 0 or 1.
|
| 13 |
+
|
| 14 |
+
Output:
|
| 15 |
+
|
| 16 |
+
Output a single line answer giving the minimum no. of steps taken before his first clearance. If it is impossible for him to do so, print "-1" (quotes for clarity).
|
| 17 |
+
|
| 18 |
+
Constraints :
|
| 19 |
+
|
| 20 |
+
2 ≤ M,N ≤ 10
|
| 21 |
+
|
| 22 |
+
Author : Srinivas
|
| 23 |
+
|
| 24 |
+
Testers : Shubham Parekh , Shreyans
|
| 25 |
+
|
| 26 |
+
(By IIT Kgp HackerEarth Programming Club)
|
| 27 |
+
|
| 28 |
+
SAMPLE INPUT
|
| 29 |
+
2 4
|
| 30 |
+
0 0 1 1
|
| 31 |
+
0 0 1 1
|
| 32 |
+
|
| 33 |
+
SAMPLE OUTPUT
|
| 34 |
+
0
|
| 35 |
+
|
| 36 |
+
## Contest Information
|
| 37 |
+
- **Contest ID**: 0
|
| 38 |
+
- **Problem Index**:
|
| 39 |
+
- **Points**: 0.0
|
| 40 |
+
- **Rating**: 0
|
| 41 |
+
- **Tags**: None
|
| 42 |
+
- **Time Limit**: None seconds
|
| 43 |
+
- **Memory Limit**: 0 bytes
|
| 44 |
+
|
| 45 |
+
## Task
|
| 46 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0083/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03455 AtCoder Beginner Contest 086 - Product
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
| 5 |
+
|
| 6 |
+
Constraints
|
| 7 |
+
|
| 8 |
+
* 1 ≤ a,b ≤ 10000
|
| 9 |
+
* a and b are integers.
|
| 10 |
+
|
| 11 |
+
Input
|
| 12 |
+
|
| 13 |
+
Input is given from Standard Input in the following format:
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
a b
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Output
|
| 20 |
+
|
| 21 |
+
If the product is odd, print `Odd`; if it is even, print `Even`.
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
3 4
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
Even
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
1 21
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
Odd
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 0
|
| 46 |
+
- **Problem Index**:
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 0
|
| 49 |
+
- **Tags**:
|
| 50 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 268435456 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-0084/instruction.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03616 AtCoder Regular Contest 082 - Sandglass
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
|
| 5 |
+
|
| 6 |
+
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
|
| 7 |
+
|
| 8 |
+
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
|
| 9 |
+
|
| 10 |
+
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
|
| 11 |
+
|
| 12 |
+
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* 1≤X≤10^9
|
| 17 |
+
* 1≤K≤10^5
|
| 18 |
+
* 1≤r_1<r_2< .. <r_K≤10^9
|
| 19 |
+
* 1≤Q≤10^5
|
| 20 |
+
* 0≤t_1<t_2< .. <t_Q≤10^9
|
| 21 |
+
* 0≤a_i≤X (1≤i≤Q)
|
| 22 |
+
* All input values are integers.
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
The input is given from Standard Input in the following format:
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
X
|
| 30 |
+
K
|
| 31 |
+
r_1 r_2 .. r_K
|
| 32 |
+
Q
|
| 33 |
+
t_1 a_1
|
| 34 |
+
t_2 a_2
|
| 35 |
+
:
|
| 36 |
+
t_Q a_Q
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
For each query, print the answer in its own line.
|
| 42 |
+
|
| 43 |
+
Examples
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
180
|
| 48 |
+
3
|
| 49 |
+
60 120 180
|
| 50 |
+
3
|
| 51 |
+
30 90
|
| 52 |
+
61 1
|
| 53 |
+
180 180
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
60
|
| 59 |
+
1
|
| 60 |
+
120
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Input
|
| 64 |
+
|
| 65 |
+
100
|
| 66 |
+
1
|
| 67 |
+
100000
|
| 68 |
+
4
|
| 69 |
+
0 100
|
| 70 |
+
90 100
|
| 71 |
+
100 100
|
| 72 |
+
101 100
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
100
|
| 78 |
+
10
|
| 79 |
+
0
|
| 80 |
+
0
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
Input
|
| 84 |
+
|
| 85 |
+
100
|
| 86 |
+
5
|
| 87 |
+
48 141 231 314 425
|
| 88 |
+
7
|
| 89 |
+
0 19
|
| 90 |
+
50 98
|
| 91 |
+
143 30
|
| 92 |
+
231 55
|
| 93 |
+
342 0
|
| 94 |
+
365 100
|
| 95 |
+
600 10
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
Output
|
| 99 |
+
|
| 100 |
+
19
|
| 101 |
+
52
|
| 102 |
+
91
|
| 103 |
+
10
|
| 104 |
+
58
|
| 105 |
+
42
|
| 106 |
+
100
|
| 107 |
+
|
| 108 |
+
## Contest Information
|
| 109 |
+
- **Contest ID**: 0
|
| 110 |
+
- **Problem Index**:
|
| 111 |
+
- **Points**: 0.0
|
| 112 |
+
- **Rating**: 0
|
| 113 |
+
- **Tags**:
|
| 114 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 115 |
+
- **Memory Limit**: 268435456 bytes
|
| 116 |
+
|
| 117 |
+
## Task
|
| 118 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0102/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02260 Selection Sort
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
SelectionSort(A)
|
| 8 |
+
1 for i = 0 to A.length-1
|
| 9 |
+
2 mini = i
|
| 10 |
+
3 for j = i to A.length-1
|
| 11 |
+
4 if A[j] < A[mini]
|
| 12 |
+
5 mini = j
|
| 13 |
+
6 swap A[i] and A[mini]
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Note that, indices for array elements are based on 0-origin.
|
| 17 |
+
|
| 18 |
+
Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
|
| 19 |
+
|
| 20 |
+
Constraints
|
| 21 |
+
|
| 22 |
+
1 ≤ N ≤ 100
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
The first line of the input includes an integer N, the number of elements in the sequence.
|
| 27 |
+
|
| 28 |
+
In the second line, N elements of the sequence are given separated by space characters.
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
The output consists of 2 lines.
|
| 33 |
+
|
| 34 |
+
In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
|
| 35 |
+
|
| 36 |
+
In the second line, please print the number of swap operations.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
6
|
| 43 |
+
5 6 4 2 1 3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
1 2 3 4 5 6
|
| 49 |
+
4
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
6
|
| 55 |
+
5 2 4 6 1 3
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
1 2 3 4 5 6
|
| 61 |
+
3
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 0
|
| 65 |
+
- **Problem Index**:
|
| 66 |
+
- **Points**: 0.0
|
| 67 |
+
- **Rating**: 0
|
| 68 |
+
- **Tags**:
|
| 69 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 70 |
+
- **Memory Limit**: 134217728 bytes
|
| 71 |
+
|
| 72 |
+
## Task
|
| 73 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0103/instruction.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02408 Finding Missing Cards
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
|
| 5 |
+
|
| 6 |
+
The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
|
| 7 |
+
|
| 8 |
+
Note
|
| 9 |
+
|
| 10 |
+
解説
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
In the first line, the number of cards n (n ≤ 52) is given.
|
| 17 |
+
|
| 18 |
+
In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities:
|
| 23 |
+
|
| 24 |
+
* Print cards of spades, hearts, clubs and diamonds in this order.
|
| 25 |
+
* If the suits are equal, print cards with lower ranks first.
|
| 26 |
+
|
| 27 |
+
Example
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
47
|
| 32 |
+
S 10
|
| 33 |
+
S 11
|
| 34 |
+
S 12
|
| 35 |
+
S 13
|
| 36 |
+
H 1
|
| 37 |
+
H 2
|
| 38 |
+
S 6
|
| 39 |
+
S 7
|
| 40 |
+
S 8
|
| 41 |
+
S 9
|
| 42 |
+
H 6
|
| 43 |
+
H 8
|
| 44 |
+
H 9
|
| 45 |
+
H 10
|
| 46 |
+
H 11
|
| 47 |
+
H 4
|
| 48 |
+
H 5
|
| 49 |
+
S 2
|
| 50 |
+
S 3
|
| 51 |
+
S 4
|
| 52 |
+
S 5
|
| 53 |
+
H 12
|
| 54 |
+
H 13
|
| 55 |
+
C 1
|
| 56 |
+
C 2
|
| 57 |
+
D 1
|
| 58 |
+
D 2
|
| 59 |
+
D 3
|
| 60 |
+
D 4
|
| 61 |
+
D 5
|
| 62 |
+
D 6
|
| 63 |
+
D 7
|
| 64 |
+
C 3
|
| 65 |
+
C 4
|
| 66 |
+
C 5
|
| 67 |
+
C 6
|
| 68 |
+
C 7
|
| 69 |
+
C 8
|
| 70 |
+
C 9
|
| 71 |
+
C 10
|
| 72 |
+
C 11
|
| 73 |
+
C 13
|
| 74 |
+
D 9
|
| 75 |
+
D 10
|
| 76 |
+
D 11
|
| 77 |
+
D 12
|
| 78 |
+
D 13
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Output
|
| 82 |
+
|
| 83 |
+
S 1
|
| 84 |
+
H 3
|
| 85 |
+
H 7
|
| 86 |
+
C 12
|
| 87 |
+
D 8
|
| 88 |
+
|
| 89 |
+
## Contest Information
|
| 90 |
+
- **Contest ID**: 0
|
| 91 |
+
- **Problem Index**:
|
| 92 |
+
- **Points**: 0.0
|
| 93 |
+
- **Rating**: 0
|
| 94 |
+
- **Tags**:
|
| 95 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 96 |
+
- **Memory Limit**: 134217728 bytes
|
| 97 |
+
|
| 98 |
+
## Task
|
| 99 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0105/instruction.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# dbyz15t
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem Desrcription
|
| 5 |
+
Shil likes to play with trees a lot.He is playing with an undirected tree containing N nodes.He wants to find out total number of unordered triplets (A,B,C) such that A is not connected to B, B is not connected to C and A is not connected to C by a direct edge (No two of A, B, C are mutually connected). Since he doesn't like to play with this alone , he asks for your help.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
The first line of each test case contains a single integer N denoting the number of nodes.
|
| 10 |
+
Next N - 1 lines consists of two integers u and v describing an edge from u to v
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
Output a single line containing total number of triplets.
|
| 14 |
+
|
| 15 |
+
Constraints
|
| 16 |
+
|
| 17 |
+
1 ≤ N ≤ 10^5
|
| 18 |
+
1 ≤ u, v ≤ N
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Example
|
| 23 |
+
Input:
|
| 24 |
+
5
|
| 25 |
+
1 2
|
| 26 |
+
1 3
|
| 27 |
+
3 4
|
| 28 |
+
2 5
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output:
|
| 32 |
+
1
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Explanation
|
| 36 |
+
The only possible triplet is (1,4,5)
|
| 37 |
+
|
| 38 |
+
## Contest Information
|
| 39 |
+
- **Contest ID**: 0
|
| 40 |
+
- **Problem Index**:
|
| 41 |
+
- **Points**: 0.0
|
| 42 |
+
- **Rating**: 0
|
| 43 |
+
- **Tags**: None
|
| 44 |
+
- **Time Limit**: None seconds
|
| 45 |
+
- **Memory Limit**: 0 bytes
|
| 46 |
+
|
| 47 |
+
## Task
|
| 48 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0132/instruction.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1497_D. Genius
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Please note the non-standard memory limit.
|
| 5 |
+
|
| 6 |
+
There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i.
|
| 7 |
+
|
| 8 |
+
After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and becomes IQ = |c_i - c_j| and you gain |s_i - s_j| points.
|
| 9 |
+
|
| 10 |
+
Any problem can be the first. You can solve problems in any order and as many times as you want.
|
| 11 |
+
|
| 12 |
+
Initially your IQ = 0. Find the maximum number of points that can be earned.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.
|
| 17 |
+
|
| 18 |
+
The first line of each test case contains an integer n (1 ≤ n ≤ 5000) — the number of problems.
|
| 19 |
+
|
| 20 |
+
The second line of each test case contains n integers tag_1, tag_2, …, tag_n (1 ≤ tag_i ≤ n) — tags of the problems.
|
| 21 |
+
|
| 22 |
+
The third line of each test case contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — scores of the problems.
|
| 23 |
+
|
| 24 |
+
It's guaranteed that sum of n over all test cases does not exceed 5000.
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
For each test case print a single integer — the maximum number of points that can be earned.
|
| 29 |
+
|
| 30 |
+
Example
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
5
|
| 36 |
+
4
|
| 37 |
+
1 2 3 4
|
| 38 |
+
5 10 15 20
|
| 39 |
+
4
|
| 40 |
+
1 2 1 2
|
| 41 |
+
5 10 15 20
|
| 42 |
+
4
|
| 43 |
+
2 2 4 1
|
| 44 |
+
2 8 19 1
|
| 45 |
+
2
|
| 46 |
+
1 1
|
| 47 |
+
6 9
|
| 48 |
+
1
|
| 49 |
+
1
|
| 50 |
+
666
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
35
|
| 57 |
+
30
|
| 58 |
+
42
|
| 59 |
+
0
|
| 60 |
+
0
|
| 61 |
+
|
| 62 |
+
Note
|
| 63 |
+
|
| 64 |
+
In the first test case optimal sequence of solving problems is as follows:
|
| 65 |
+
|
| 66 |
+
1. 1 → 2, after that total score is 5 and IQ = 2
|
| 67 |
+
2. 2 → 3, after that total score is 10 and IQ = 4
|
| 68 |
+
3. 3 → 1, after that total score is 20 and IQ = 6
|
| 69 |
+
4. 1 → 4, after that total score is 35 and IQ = 14
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
In the second test case optimal sequence of solving problems is as follows:
|
| 74 |
+
|
| 75 |
+
1. 1 → 2, after that total score is 5 and IQ = 2
|
| 76 |
+
2. 2 → 3, after that total score is 10 and IQ = 4
|
| 77 |
+
3. 3 → 4, after that total score is 15 and IQ = 8
|
| 78 |
+
4. 4 → 1, after that total score is 35 and IQ = 14
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
In the third test case optimal sequence of solving problems is as follows:
|
| 83 |
+
|
| 84 |
+
1. 1 → 3, after that total score is 17 and IQ = 6
|
| 85 |
+
2. 3 → 4, after that total score is 35 and IQ = 8
|
| 86 |
+
3. 4 → 2, after that total score is 42 and IQ = 12
|
| 87 |
+
|
| 88 |
+
## Contest Information
|
| 89 |
+
- **Contest ID**: 1497
|
| 90 |
+
- **Problem Index**: D
|
| 91 |
+
- **Points**: 1750.0
|
| 92 |
+
- **Rating**: 2500
|
| 93 |
+
- **Tags**: bitmasks, dp, graphs, number theory
|
| 94 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 95 |
+
- **Memory Limit**: 32000000 bytes
|
| 96 |
+
|
| 97 |
+
## Task
|
| 98 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0156/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 670_B. Game of Robots
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
|
| 5 |
+
|
| 6 |
+
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
|
| 7 |
+
|
| 8 |
+
Your task is to determine the k-th identifier to be pronounced.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2).
|
| 13 |
+
|
| 14 |
+
The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print the k-th pronounced identifier (assume that the numeration starts from 1).
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
2 2
|
| 25 |
+
1 2
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4 5
|
| 36 |
+
10 4 18 3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
4
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
|
| 46 |
+
|
| 47 |
+
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 670
|
| 51 |
+
- **Problem Index**: B
|
| 52 |
+
- **Points**: 750.0
|
| 53 |
+
- **Rating**: 1000
|
| 54 |
+
- **Tags**: implementation
|
| 55 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 56 |
+
- **Memory Limit**: 256000000 bytes
|
| 57 |
+
|
| 58 |
+
## Task
|
| 59 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0158/instruction.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 716_D. Complete The Graph
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
|
| 5 |
+
|
| 6 |
+
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices s and t in the resulting graph is exactly L. Can you help him?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains five integers n, m, L, s, t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 10 000, 1 ≤ L ≤ 109, 0 ≤ s, t ≤ n - 1, s ≠ t) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
|
| 11 |
+
|
| 12 |
+
Then, m lines describing the edges of the graph follow. i-th of them contains three integers, ui, vi, wi (0 ≤ ui, vi ≤ n - 1, ui ≠ vi, 0 ≤ wi ≤ 109). ui and vi denote the endpoints of the edge and wi denotes its weight. If wi is equal to 0 then the weight of the corresponding edge was erased.
|
| 13 |
+
|
| 14 |
+
It is guaranteed that there is at most one edge between any pair of vertices.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
|
| 19 |
+
|
| 20 |
+
Otherwise, print "YES" in the first line. Next m lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. i-th of them should contain three integers ui, vi and wi, denoting an edge between vertices ui and vi of weight wi. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018.
|
| 21 |
+
|
| 22 |
+
The order of the edges in the output doesn't matter. The length of the shortest path between s and t must be equal to L.
|
| 23 |
+
|
| 24 |
+
If there are multiple solutions, print any of them.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
5 5 13 0 4
|
| 31 |
+
0 1 5
|
| 32 |
+
2 1 2
|
| 33 |
+
3 2 3
|
| 34 |
+
1 4 0
|
| 35 |
+
4 3 4
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
YES
|
| 41 |
+
0 1 5
|
| 42 |
+
2 1 2
|
| 43 |
+
3 2 3
|
| 44 |
+
1 4 8
|
| 45 |
+
4 3 4
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
2 1 123456789 0 1
|
| 51 |
+
0 1 0
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
YES
|
| 57 |
+
0 1 123456789
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Input
|
| 61 |
+
|
| 62 |
+
2 1 999999999 1 0
|
| 63 |
+
0 1 1000000000
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
NO
|
| 69 |
+
|
| 70 |
+
Note
|
| 71 |
+
|
| 72 |
+
Here's how the graph in the first sample case looks like :
|
| 73 |
+
|
| 74 |
+
<image>
|
| 75 |
+
|
| 76 |
+
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
|
| 77 |
+
|
| 78 |
+
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789.
|
| 79 |
+
|
| 80 |
+
In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO".
|
| 81 |
+
|
| 82 |
+
## Contest Information
|
| 83 |
+
- **Contest ID**: 716
|
| 84 |
+
- **Problem Index**: D
|
| 85 |
+
- **Points**: 1000.0
|
| 86 |
+
- **Rating**: 2300
|
| 87 |
+
- **Tags**: binary search, constructive algorithms, graphs, shortest paths
|
| 88 |
+
- **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
|
| 89 |
+
- **Memory Limit**: 256000000 bytes
|
| 90 |
+
|
| 91 |
+
## Task
|
| 92 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0159/instruction.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 737_A. Road to Cinema
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
|
| 5 |
+
|
| 6 |
+
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
|
| 7 |
+
|
| 8 |
+
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
|
| 9 |
+
|
| 10 |
+
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
|
| 11 |
+
|
| 12 |
+
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
|
| 17 |
+
|
| 18 |
+
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
|
| 19 |
+
|
| 20 |
+
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
3 1 8 10
|
| 31 |
+
10 8
|
| 32 |
+
5 7
|
| 33 |
+
11 9
|
| 34 |
+
3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
10
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
2 2 10 18
|
| 45 |
+
10 4
|
| 46 |
+
20 6
|
| 47 |
+
5 3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
20
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
|
| 57 |
+
|
| 58 |
+
## Contest Information
|
| 59 |
+
- **Contest ID**: 737
|
| 60 |
+
- **Problem Index**: A
|
| 61 |
+
- **Points**: 1750.0
|
| 62 |
+
- **Rating**: 1700
|
| 63 |
+
- **Tags**: binary search, greedy, sortings
|
| 64 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 65 |
+
- **Memory Limit**: 256000000 bytes
|
| 66 |
+
|
| 67 |
+
## Task
|
| 68 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0161/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 784_B. Kids' Riddle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The input contains a single integer n (0 ≤ n ≤ 2000000000).
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
Output a single integer.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
11
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
2
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
14
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
0
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
61441
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
571576
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
10
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
2128506
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
3
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 784
|
| 67 |
+
- **Problem Index**: B
|
| 68 |
+
- **Points**: 0.0
|
| 69 |
+
- **Rating**: 2000
|
| 70 |
+
- **Tags**: *special
|
| 71 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 72 |
+
- **Memory Limit**: 64000000 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-0166/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 89_C. Chip Play
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.
|
| 5 |
+
|
| 6 |
+
Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.
|
| 7 |
+
|
| 8 |
+
The player may choose a chip and make a move with it.
|
| 9 |
+
|
| 10 |
+
The move is the following sequence of actions. The chosen chip is marked as the current one. After that the player checks whether there are more chips in the same row (or in the same column) with the current one that are pointed by the arrow on the current chip. If there is at least one chip then the closest of them is marked as the new current chip and the former current chip is removed from the field. After that the check is repeated. This process can be repeated several times. If a new chip is not found, then the current chip is removed from the field and the player's move ends.
|
| 11 |
+
|
| 12 |
+
By the end of a move the player receives several points equal to the number of the deleted chips.
|
| 13 |
+
|
| 14 |
+
By the given initial chip arrangement determine the maximum number of points that a player can receive during one move. Also determine the number of such moves.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The first line contains two integers n and m (1 ≤ n, m, n × m ≤ 5000). Then follow n lines containing m characters each — that is the game field description. "." means that this square is empty. "L", "R", "U", "D" mean that this square contains a chip and an arrow on it says left, right, up or down correspondingly.
|
| 19 |
+
|
| 20 |
+
It is guaranteed that a field has at least one chip.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print two numbers — the maximal number of points a player can get after a move and the number of moves that allow receiving this maximum number of points.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
4 4
|
| 31 |
+
DRLD
|
| 32 |
+
U.UL
|
| 33 |
+
.UUR
|
| 34 |
+
RDDL
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
10 1
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
3 5
|
| 44 |
+
.D...
|
| 45 |
+
RRRLL
|
| 46 |
+
.U...
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
6 2
|
| 52 |
+
|
| 53 |
+
Note
|
| 54 |
+
|
| 55 |
+
In the first sample the maximum number of points is earned by the chip in the position (3, 3). You can see its progress at the following picture:
|
| 56 |
+
|
| 57 |
+
<image>
|
| 58 |
+
|
| 59 |
+
All other chips earn fewer points.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 89
|
| 63 |
+
- **Problem Index**: C
|
| 64 |
+
- **Points**: 1000.0
|
| 65 |
+
- **Rating**: 2300
|
| 66 |
+
- **Tags**: brute force, data structures, implementation
|
| 67 |
+
- **Time Limit**: {'seconds': 4, '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-0169/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 977_B. Two-gram
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
|
| 5 |
+
|
| 6 |
+
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string s = "BBAABBBA" the answer is two-gram "BB", which contained in s three times. In other words, find any most frequent two-gram.
|
| 7 |
+
|
| 8 |
+
Note that occurrences of the two-gram can overlap with each other.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of the input contains integer number n (2 ≤ n ≤ 100) — the length of string s. The second line of the input contains the string s consisting of n capital Latin letters.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string s as a substring (i.e. two consecutive characters of the string) maximal number of times.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
7
|
| 23 |
+
ABACABA
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
AB
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
5
|
| 34 |
+
ZZZAA
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
ZZ
|
| 40 |
+
|
| 41 |
+
Note
|
| 42 |
+
|
| 43 |
+
In the first example "BA" is also valid answer.
|
| 44 |
+
|
| 45 |
+
In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 977
|
| 49 |
+
- **Problem Index**: B
|
| 50 |
+
- **Points**: 0.0
|
| 51 |
+
- **Rating**: 900
|
| 52 |
+
- **Tags**: implementation, strings
|
| 53 |
+
- **Time Limit**: {'seconds': 1, '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-0192/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00206 Next Trip
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned manner.
|
| 5 |
+
|
| 6 |
+
If you have a friend's pocket money of M yen and the money you spend in that month is N yen, you will save (M --N) yen in that month. Create a program that inputs the monthly income and expenditure information M and N and outputs the number of months it takes for the savings amount to reach the travel cost L. However, if your savings do not reach your travel expenses after 12 months, print NA.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
L
|
| 16 |
+
M1 N1
|
| 17 |
+
M2 N2
|
| 18 |
+
::
|
| 19 |
+
M12 N12
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
The first line gives the travel cost L (1 ≤ L ≤ 1000000, integer). The next 12 lines are given the balance information for the i month, Mi, Ni (0 ≤ Mi, Ni ≤ 100000, Ni ≤ Mi, integer).
|
| 23 |
+
|
| 24 |
+
The number of datasets does not exceed 1000.
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
For each input dataset, print the number of months it takes for your savings to reach your travel costs on a single line.
|
| 29 |
+
|
| 30 |
+
Example
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
10000
|
| 35 |
+
5000 3150
|
| 36 |
+
5000 5000
|
| 37 |
+
0 0
|
| 38 |
+
5000 1050
|
| 39 |
+
5000 3980
|
| 40 |
+
5000 210
|
| 41 |
+
5000 5000
|
| 42 |
+
5000 5000
|
| 43 |
+
0 0
|
| 44 |
+
5000 2100
|
| 45 |
+
5000 2100
|
| 46 |
+
5000 2100
|
| 47 |
+
29170
|
| 48 |
+
100000 100000
|
| 49 |
+
100000 100000
|
| 50 |
+
100000 100000
|
| 51 |
+
100000 100000
|
| 52 |
+
100000 100000
|
| 53 |
+
100000 100000
|
| 54 |
+
100000 100000
|
| 55 |
+
100000 100000
|
| 56 |
+
100000 100000
|
| 57 |
+
100000 100000
|
| 58 |
+
100000 100000
|
| 59 |
+
100000 70831
|
| 60 |
+
0
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
6
|
| 66 |
+
NA
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 0
|
| 70 |
+
- **Problem Index**:
|
| 71 |
+
- **Points**: 0.0
|
| 72 |
+
- **Rating**: 0
|
| 73 |
+
- **Tags**:
|
| 74 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 75 |
+
- **Memory Limit**: 134217728 bytes
|
| 76 |
+
|
| 77 |
+
## Task
|
| 78 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0193/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00365 Age Difference
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages will hit a maximum value even though the months move on forever.
|
| 5 |
+
|
| 6 |
+
Given the birthdays for the two, make a program to report the maximum difference between their ages. The age increases by one at the moment the birthday begins. If the birthday coincides with the 29th of February in a leap year, the age increases at the moment the 1st of March arrives in non-leap years.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The input is given in the following format.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
y_1 m_1 d_1
|
| 16 |
+
y_2 m_2 d_2
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
The first and second lines provide Hatsumi’s and Taku’s birthdays respectively in year y_i (1 ≤ y_i ≤ 3000), month m_i (1 ≤ m_i ≤ 12), and day d_i (1 ≤ d_i ≤ Dmax) format. Where Dmax is given as follows:
|
| 20 |
+
|
| 21 |
+
* 28 when February in a non-leap year
|
| 22 |
+
* 29 when February in a leap-year
|
| 23 |
+
* 30 in April, June, September, and November
|
| 24 |
+
* 31 otherwise.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
It is a leap year if the year represented as a four-digit number is divisible by 4. Note, however, that it is a non-leap year if divisible by 100, and a leap year if divisible by 400.
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
Output the maximum difference between their ages.
|
| 33 |
+
|
| 34 |
+
Examples
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
1999 9 9
|
| 39 |
+
2001 11 3
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
3
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Input
|
| 48 |
+
|
| 49 |
+
2008 2 29
|
| 50 |
+
2015 3 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
8
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 0
|
| 59 |
+
- **Problem Index**:
|
| 60 |
+
- **Points**: 0.0
|
| 61 |
+
- **Rating**: 0
|
| 62 |
+
- **Tags**:
|
| 63 |
+
- **Time Limit**: {'seconds': 1, '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-0194/instruction.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00573 Commuter Pass
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are N stations in the city where JOI lives, and they are numbered 1, 2, ..., and N, respectively. In addition, there are M railway lines, numbered 1, 2, ..., and M, respectively. The railway line i (1 \ leq i \ leq M) connects station A_i and station B_i in both directions, and the fare is C_i yen.
|
| 5 |
+
|
| 6 |
+
JOI lives near station S and attends IOI high school near station T. Therefore, I decided to purchase a commuter pass that connects the two. When purchasing a commuter pass, you must specify one route between station S and station T at the lowest fare. With this commuter pass, you can freely get on and off the railway lines included in the specified route in both directions.
|
| 7 |
+
|
| 8 |
+
JOI also often uses bookstores near Station U and Station V. Therefore, I wanted to purchase a commuter pass so that the fare for traveling from station U to station V would be as small as possible.
|
| 9 |
+
|
| 10 |
+
When moving from station U to station V, first select one route from station U to station V. The fare to be paid on the railway line i included in this route is
|
| 11 |
+
|
| 12 |
+
* If railway line i is included in the route specified when purchasing the commuter pass, 0 yen
|
| 13 |
+
* If railway line i is not included in the route specified when purchasing the commuter pass, C_i yen
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
It becomes. The total of these fares is the fare for traveling from station U to station V.
|
| 18 |
+
|
| 19 |
+
I would like to find the minimum fare for traveling from station U to station V when the route specified when purchasing a commuter pass is selected successfully.
|
| 20 |
+
|
| 21 |
+
Task
|
| 22 |
+
|
| 23 |
+
Create a program to find the minimum fare for traveling from station U to station V when you have successfully selected the route you specify when purchasing a commuter pass.
|
| 24 |
+
|
| 25 |
+
input
|
| 26 |
+
|
| 27 |
+
Read the following input from standard input.
|
| 28 |
+
|
| 29 |
+
* Two integers N and M are written on the first line. These indicate that there are N stations and M railroad lines in the city where JOI lives.
|
| 30 |
+
* Two integers S and T are written on the second line. These indicate that JOI purchases a commuter pass from station S to station T.
|
| 31 |
+
* Two integers U and V are written on the third line. These indicate that JOI wants to minimize the fare for traveling from station U to station V.
|
| 32 |
+
* Three integers A_i, B_i, and C_i are written in the i-th line (1 \ leq i \ leq M) of the following M lines. These indicate that the railway line i connects station A_i and station B_i in both directions, and the fare is C_i yen.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
output
|
| 37 |
+
|
| 38 |
+
Output the minimum fare for traveling from station U to station V on one line to the standard output when the route from station S to station T is properly specified when purchasing a commuter pass.
|
| 39 |
+
|
| 40 |
+
Limits
|
| 41 |
+
|
| 42 |
+
All input data satisfy the following conditions.
|
| 43 |
+
|
| 44 |
+
* 2 \ leq N \ leq 100 000.
|
| 45 |
+
* 1 \ leq M \ leq 200 000.
|
| 46 |
+
* 1 \ leq S \ leq N.
|
| 47 |
+
* 1 \ leq T \ leq N.
|
| 48 |
+
* 1 \ leq U \ leq N.
|
| 49 |
+
* 1 \ leq V \ leq N.
|
| 50 |
+
* S ≠ T.
|
| 51 |
+
* U ≠ V.
|
| 52 |
+
* S ≠ U or T ≠ V.
|
| 53 |
+
* You can reach any other station from any station using one or more railway lines.
|
| 54 |
+
* 1 \ leq A_i <B_i \ leq N (1 \ leq i l \ leq M).
|
| 55 |
+
* 1 For \ leq i <j \ leq M, A_i ≠ A_j or B_i ≠ B_j.
|
| 56 |
+
* 1 \ leq C_i \ leq 1 000 000 000 (1 \ leq i \ leq M).
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Input / output example
|
| 61 |
+
|
| 62 |
+
Input example 1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
6 6
|
| 66 |
+
1 6
|
| 67 |
+
14
|
| 68 |
+
1 2 1
|
| 69 |
+
2 3 1
|
| 70 |
+
3 5 1
|
| 71 |
+
2 4 3
|
| 72 |
+
4 5 2
|
| 73 |
+
5 6 1
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Output example 1
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
2
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
In this input example, the route that can be specified when buying a commuter pass is limited to the route of station 1-> station 2-> station 3-> station 5-> station 6.
|
| 83 |
+
|
| 84 |
+
To minimize the fare for traveling from station 1 to station 4, choose the route station 1-> station 2-> station 3-> station 5-> station 4. If you choose this route, the fare to be paid on each railway line is
|
| 85 |
+
|
| 86 |
+
* 2 yen for railway line 5 connecting station 4 and station 5.
|
| 87 |
+
* 0 yen for other railway lines.
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
Therefore, the total fare is 2 yen.
|
| 92 |
+
|
| 93 |
+
Input example 2
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
6 5
|
| 97 |
+
1 2
|
| 98 |
+
3 6
|
| 99 |
+
1 2 1000000000
|
| 100 |
+
2 3 1000000000
|
| 101 |
+
3 4 1000000000
|
| 102 |
+
4 5 1000000000
|
| 103 |
+
5 6 1000000000
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
Output example 2
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
3000000000
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
In this input example, the commuter pass is not used to move from station 3 to station 6.
|
| 113 |
+
|
| 114 |
+
Input example 3
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
8 8
|
| 118 |
+
5 7
|
| 119 |
+
6 8
|
| 120 |
+
1 2 2
|
| 121 |
+
2 3 3
|
| 122 |
+
3 4 4
|
| 123 |
+
1 4 1
|
| 124 |
+
1 5 5
|
| 125 |
+
2 6 6
|
| 126 |
+
3 7 7
|
| 127 |
+
4 8 8
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
Output example 3
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
15
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
Input example 4
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
5 5
|
| 140 |
+
1 5
|
| 141 |
+
twenty three
|
| 142 |
+
1 2 1
|
| 143 |
+
2 3 10
|
| 144 |
+
2 4 10
|
| 145 |
+
3 5 10
|
| 146 |
+
4 5 10
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
Output example 4
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
0
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
Input example 5
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
10 15
|
| 159 |
+
6 8
|
| 160 |
+
7 9
|
| 161 |
+
2 7 12
|
| 162 |
+
8 10 17
|
| 163 |
+
1 3 1
|
| 164 |
+
3 8 14
|
| 165 |
+
5 7 15
|
| 166 |
+
2 3 7
|
| 167 |
+
1 10 14
|
| 168 |
+
3 6 12
|
| 169 |
+
1 5 10
|
| 170 |
+
8 9 1
|
| 171 |
+
2 9 7
|
| 172 |
+
1 4 1
|
| 173 |
+
1 8 1
|
| 174 |
+
2 4 7
|
| 175 |
+
5 6 16
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
Output example 5
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
19
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
Creative Commons License
|
| 188 |
+
Information Olympics Japan Committee work "17th Japan Information Olympics (JOI 2017/2018) Final Selection"
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
Example
|
| 195 |
+
|
| 196 |
+
Input
|
| 197 |
+
|
| 198 |
+
6 6
|
| 199 |
+
1 6
|
| 200 |
+
1 4
|
| 201 |
+
1 2 1
|
| 202 |
+
2 3 1
|
| 203 |
+
3 5 1
|
| 204 |
+
2 4 3
|
| 205 |
+
4 5 2
|
| 206 |
+
5 6 1
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
Output
|
| 210 |
+
|
| 211 |
+
2
|
| 212 |
+
|
| 213 |
+
## Contest Information
|
| 214 |
+
- **Contest ID**: 0
|
| 215 |
+
- **Problem Index**:
|
| 216 |
+
- **Points**: 0.0
|
| 217 |
+
- **Rating**: 0
|
| 218 |
+
- **Tags**:
|
| 219 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 220 |
+
- **Memory Limit**: 268435456 bytes
|
| 221 |
+
|
| 222 |
+
## Task
|
| 223 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0195/instruction.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00720 Earth Observation with a Mobile Robot Team
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones nearby. They also have large capacity memory units, on which they record data observed by themselves and those received from others.
|
| 5 |
+
|
| 6 |
+
Figure 1 illustrates the current positions of three robots A, B, and C and the geographic coverage of their wireless devices. Each circle represents the wireless coverage of a robot, with its center representing the position of the robot. In this figure, two robots A and B are in the positions where A can transmit data to B, and vice versa. In contrast, C cannot communicate with A or B, since it is too remote from them. Still, however, once B moves towards C as in Figure 2, B and C can start communicating with each other. In this manner, B can relay observational data from A to C. Figure 3 shows another example, in which data propagate among several robots instantaneously.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
---
|
| 10 |
+
Figure 1: The initial configuration of three robots
|
| 11 |
+
<image>
|
| 12 |
+
---
|
| 13 |
+
Figure 2: Mobile relaying
|
| 14 |
+
<image>
|
| 15 |
+
---
|
| 16 |
+
Figure 3: Instantaneous relaying among multiple robots
|
| 17 |
+
|
| 18 |
+
As you may notice from these examples, if a team of robots move properly, observational data quickly spread over a large number of them. Your mission is to write a program that simulates how information spreads among robots. Suppose that, regardless of data size, the time necessary for communication is negligible.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
The input consists of multiple datasets, each in the following format.
|
| 25 |
+
|
| 26 |
+
> N T R
|
| 27 |
+
> nickname and travel route of the first robot
|
| 28 |
+
> nickname and travel route of the second robot
|
| 29 |
+
> ...
|
| 30 |
+
> nickname and travel route of the N-th robot
|
| 31 |
+
>
|
| 32 |
+
|
| 33 |
+
The first line contains three integers N, T, and R that are the number of robots, the length of the simulation period, and the maximum distance wireless signals can reach, respectively, and satisfy that 1 <=N <= 100, 1 <= T <= 1000, and 1 <= R <= 10.
|
| 34 |
+
|
| 35 |
+
The nickname and travel route of each robot are given in the following format.
|
| 36 |
+
|
| 37 |
+
> nickname
|
| 38 |
+
> t0 x0 y0
|
| 39 |
+
> t1 vx1 vy1
|
| 40 |
+
> t2 vx2 vy2
|
| 41 |
+
> ...
|
| 42 |
+
> tk vxk vyk
|
| 43 |
+
>
|
| 44 |
+
|
| 45 |
+
Nickname is a character string of length between one and eight that only contains lowercase letters. No two robots in a dataset may have the same nickname. Each of the lines following nickname contains three integers, satisfying the following conditions.
|
| 46 |
+
|
| 47 |
+
> 0 = t0 < t1 < ... < tk = T
|
| 48 |
+
> -10 <= vx1, vy1, ..., vxk, vyk<= 10
|
| 49 |
+
>
|
| 50 |
+
|
| 51 |
+
A robot moves around on a two dimensional plane. (x0, y0) is the location of the robot at time 0. From time ti-1 to ti (0 < i <= k), the velocities in the x and y directions are vxi and vyi, respectively. Therefore, the travel route of a robot is piecewise linear. Note that it may self-overlap or self-intersect.
|
| 52 |
+
|
| 53 |
+
You may assume that each dataset satisfies the following conditions.
|
| 54 |
+
|
| 55 |
+
* The distance between any two robots at time 0 is not exactly R.
|
| 56 |
+
* The x- and y-coordinates of each robot are always between -500 and 500, inclusive.
|
| 57 |
+
* Once any robot approaches within R + 10-6 of any other, the distance between them will become smaller than R - 10-6 while maintaining the velocities.
|
| 58 |
+
* Once any robot moves away up to R - 10-6 of any other, the distance between them will become larger than R + 10-6 while maintaining the velocities.
|
| 59 |
+
* If any pair of robots mutually enter the wireless area of the opposite ones at time t and any pair, which may share one or two members with the aforementioned pair, mutually leave the wireless area of the opposite ones at time t', the difference between t and t' is no smaller than 10-6 time unit, that is, |t - t' | >= 10-6.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
A dataset may include two or more robots that share the same location at the same time. However, you should still consider that they can move with the designated velocities.
|
| 63 |
+
|
| 64 |
+
The end of the input is indicated by a line containing three zeros.
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
For each dataset in the input, your program should print the nickname of each robot that have got until time T the observational data originally acquired by the first robot at time 0. Each nickname should be written in a separate line in dictionary order without any superfluous characters such as leading or trailing spaces.
|
| 69 |
+
|
| 70 |
+
Example
|
| 71 |
+
|
| 72 |
+
Input
|
| 73 |
+
|
| 74 |
+
3 5 10
|
| 75 |
+
red
|
| 76 |
+
0 0 0
|
| 77 |
+
5 0 0
|
| 78 |
+
green
|
| 79 |
+
0 5 5
|
| 80 |
+
5 6 1
|
| 81 |
+
blue
|
| 82 |
+
0 40 5
|
| 83 |
+
5 0 0
|
| 84 |
+
3 10 5
|
| 85 |
+
atom
|
| 86 |
+
0 47 32
|
| 87 |
+
5 -10 -7
|
| 88 |
+
10 1 0
|
| 89 |
+
pluto
|
| 90 |
+
0 0 0
|
| 91 |
+
7 0 0
|
| 92 |
+
10 3 3
|
| 93 |
+
gesicht
|
| 94 |
+
0 25 7
|
| 95 |
+
5 -7 -2
|
| 96 |
+
10 -1 10
|
| 97 |
+
4 100 7
|
| 98 |
+
impulse
|
| 99 |
+
0 -500 0
|
| 100 |
+
100 10 1
|
| 101 |
+
freedom
|
| 102 |
+
0 -491 0
|
| 103 |
+
100 9 2
|
| 104 |
+
destiny
|
| 105 |
+
0 -472 0
|
| 106 |
+
100 7 4
|
| 107 |
+
strike
|
| 108 |
+
0 -482 0
|
| 109 |
+
100 8 3
|
| 110 |
+
0 0 0
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
Output
|
| 114 |
+
|
| 115 |
+
blue
|
| 116 |
+
green
|
| 117 |
+
red
|
| 118 |
+
atom
|
| 119 |
+
gesicht
|
| 120 |
+
pluto
|
| 121 |
+
freedom
|
| 122 |
+
impulse
|
| 123 |
+
strike
|
| 124 |
+
|
| 125 |
+
## Contest Information
|
| 126 |
+
- **Contest ID**: 0
|
| 127 |
+
- **Problem Index**:
|
| 128 |
+
- **Points**: 0.0
|
| 129 |
+
- **Rating**: 0
|
| 130 |
+
- **Tags**:
|
| 131 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 132 |
+
- **Memory Limit**: 134217728 bytes
|
| 133 |
+
|
| 134 |
+
## Task
|
| 135 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0300/instruction.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00819 Unreliable Message
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, “You shall make use of a message relaying game when you inform me of something.” In response to the King’s statement, six servants were selected as messengers whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message to the next messenger until the message got to the King.
|
| 5 |
+
|
| 6 |
+
Messages addressed to the King consist of digits (‘0’-‘9’) and alphabet characters (‘a’-‘z’, ‘A’-‘Z’). Capital and small letters are distinguished in messages. For example, “ke3E9Aa” is a message.
|
| 7 |
+
|
| 8 |
+
Contrary to King’s expectations, he always received wrong messages, because each messenger changed messages a bit before passing them to the next messenger. Since it irritated the King, he told you who are the Minister of the Science and Technology Agency of the Kingdom, “We don’t want such a wrong message any more. You shall develop software to correct it!” In response to the King’s new statement, you analyzed the messengers’ mistakes with all technologies in the Kingdom, and acquired the following features of mistakes of each messenger. A surprising point was that each messenger made the same mistake whenever relaying a message. The following facts were observed.
|
| 9 |
+
|
| 10 |
+
Mr. J rotates all characters of the message to the left by one. For example, he transforms “aB23d” to “B23da”.
|
| 11 |
+
|
| 12 |
+
Miss C rotates all characters of the message to the right by one. For example, she transforms “aB23d” to “daB23”.
|
| 13 |
+
|
| 14 |
+
Mr. E swaps the left half of the message with the right half. If the message has an odd number of characters, the middle one does not move. For example, he transforms “e3ac” to “ace3”, and “aB23d” to “3d2aB”.
|
| 15 |
+
|
| 16 |
+
Mr. A reverses the message. For example, he transforms “aB23d” to “d32Ba”.
|
| 17 |
+
|
| 18 |
+
Dr. P increments by one all the digits in the message. If a digit is ‘9’, it becomes ‘0’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB34d”, and “e9ac” to “e0ac”.
|
| 19 |
+
|
| 20 |
+
Mr. M decrements by one all the digits in the message. If a digit is ‘0’, it becomes ‘9’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB12d”, and “e0ac” to “e9ac”.
|
| 21 |
+
|
| 22 |
+
The software you must develop is to infer the original message from the final message, given the order of the messengers. For example, if the order of the messengers is A -> J -> M -> P and the message given to the King is “aB23d”, what is the original message? According to the features of the messengers’ mistakes, the sequence leading to the final message is
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
A J M P
|
| 26 |
+
“32Bad” --> “daB23” --> “aB23d” --> “aB12d” --> “aB23d”.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
As a result, the original message should be “32Bad”.
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
The input format is as follows.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
n
|
| 39 |
+
The order of messengers
|
| 40 |
+
The message given to the King
|
| 41 |
+
.
|
| 42 |
+
.
|
| 43 |
+
.
|
| 44 |
+
The order of messengers
|
| 45 |
+
The message given to the King
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
The first line of the input contains a positive integer n, which denotes the number of data sets. Each data set is a pair of the order of messengers and the message given to the King. The number of messengers relaying a message is between 1 and 6 inclusive. The same person may not appear more than once in the order of messengers. The length of a message is between 1 and 25 inclusive.
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
The inferred messages are printed each on a separate line.
|
| 53 |
+
|
| 54 |
+
Example
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
5
|
| 59 |
+
AJMP
|
| 60 |
+
aB23d
|
| 61 |
+
E
|
| 62 |
+
86AE
|
| 63 |
+
AM
|
| 64 |
+
6
|
| 65 |
+
JPEM
|
| 66 |
+
WaEaETC302Q
|
| 67 |
+
CP
|
| 68 |
+
rTurnAGundam1isdefferentf
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
Output
|
| 72 |
+
|
| 73 |
+
32Bad
|
| 74 |
+
AE86
|
| 75 |
+
7
|
| 76 |
+
EC302QTWaEa
|
| 77 |
+
TurnAGundam0isdefferentfr
|
| 78 |
+
|
| 79 |
+
## Contest Information
|
| 80 |
+
- **Contest ID**: 0
|
| 81 |
+
- **Problem Index**:
|
| 82 |
+
- **Points**: 0.0
|
| 83 |
+
- **Rating**: 0
|
| 84 |
+
- **Tags**:
|
| 85 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 86 |
+
- **Memory Limit**: 134217728 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-0308/instruction.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01970 The Diversity of Prime Factorization
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
D: The Diversity of Prime Factorization
|
| 5 |
+
|
| 6 |
+
Problem
|
| 7 |
+
|
| 8 |
+
Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O ($ \ log $ M) time! But unfortunately, the machine could display only digits and white spaces.
|
| 9 |
+
|
| 10 |
+
In general, we consider the factorization of M as p_1 ^ {e_1} \ times p_2 ^ {e_2} \ times ... \ times p_K ^ {e_K} where (1) i <j implies p_i <p_j and (2) p_i is prime. Now, she gives M to the machine, and the machine displays according to the following rules in ascending order with respect to i:
|
| 11 |
+
|
| 12 |
+
* If e_i = 1, then displays p_i,
|
| 13 |
+
* otherwise, displays p_i e_i.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
For example, if she gives either `22` or` 2048`, then `2 11` is displayed. If either` 24` or `54`, then` 2 3 3`.
|
| 18 |
+
|
| 19 |
+
Okay, Ebi-chan has written down the output of the machine, but she notices that she has forgotten to write down the input! Now, your task is to count how many natural numbers result in a noted output. Note that Ebi-chan has mistaken writing and no input could result in the output.
|
| 20 |
+
|
| 21 |
+
The answer could be too large, so, you must output it modulo 10 ^ 9 + 7 (prime number).
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
N
|
| 27 |
+
q_1 q_2 $ \ cdots $ q_N
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
In the first line, the number of the output of the machine is given. In the second line, the output of the machine is given.
|
| 31 |
+
|
| 32 |
+
Constraints
|
| 33 |
+
|
| 34 |
+
* 1 \ leq N \ leq 10 ^ 5
|
| 35 |
+
* 2 \ leq q_i \ leq 10 ^ 6 (1 \ leq i \ leq N)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
Print the number of the natural numbers that result in the given output of the machine.
|
| 42 |
+
|
| 43 |
+
Sample Input 1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
3
|
| 47 |
+
2 3 3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Sample Output for Input 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
2
|
| 54 |
+
|
| 55 |
+
24 = 2 ^ 3 \ times 3 and 54 = 2 \ times 3 ^ 3 satisfy the condition.
|
| 56 |
+
|
| 57 |
+
Sample Input 2
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
3
|
| 61 |
+
2 3 4
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Sample Output 2 for Input 2
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
1
|
| 68 |
+
|
| 69 |
+
Only 162 = 2 \ times 3 ^ 4 satisfies the condition. Note that 4 is not prime.
|
| 70 |
+
|
| 71 |
+
Sample Input 3
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
3
|
| 75 |
+
3 5 2
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Sample Output for Input 3
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
1
|
| 82 |
+
|
| 83 |
+
Since 2 <3 <5, only 75 = 3 \ times 5 ^ 2 satisfies the condition.
|
| 84 |
+
|
| 85 |
+
Sample Input 4
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
1
|
| 89 |
+
Four
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
Sample Output for Input 4
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
0
|
| 96 |
+
|
| 97 |
+
Ebi-chan should have written down it more carefully.
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
Example
|
| 104 |
+
|
| 105 |
+
Input
|
| 106 |
+
|
| 107 |
+
3
|
| 108 |
+
2 3 3
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
Output
|
| 112 |
+
|
| 113 |
+
2
|
| 114 |
+
|
| 115 |
+
## Contest Information
|
| 116 |
+
- **Contest ID**: 0
|
| 117 |
+
- **Problem Index**:
|
| 118 |
+
- **Points**: 0.0
|
| 119 |
+
- **Rating**: 0
|
| 120 |
+
- **Tags**:
|
| 121 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 122 |
+
- **Memory Limit**: 268435456 bytes
|
| 123 |
+
|
| 124 |
+
## Task
|
| 125 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0330/instruction.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1264_A. Beautiful Regional Contest
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n.
|
| 5 |
+
|
| 6 |
+
Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied:
|
| 7 |
+
|
| 8 |
+
* for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0);
|
| 9 |
+
* the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b);
|
| 10 |
+
* each gold medalist must solve strictly more problems than any awarded with a silver medal;
|
| 11 |
+
* each silver medalist must solve strictly more problems than any awarded a bronze medal;
|
| 12 |
+
* each bronze medalist must solve strictly more problems than any participant not awarded a medal;
|
| 13 |
+
* the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants).
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line of the input contains an integer t (1 ≤ t ≤ 10000) — the number of test cases in the input. Then t test cases follow.
|
| 22 |
+
|
| 23 |
+
The first line of a test case contains an integer n (1 ≤ n ≤ 4⋅10^5) — the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≤ p_i ≤ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 ≥ p_2 ≥ ... ≥ p_n.
|
| 24 |
+
|
| 25 |
+
The sum of n over all test cases in the input does not exceed 4⋅10^5.
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
Print t lines, the j-th line should contain the answer to the j-th test case.
|
| 30 |
+
|
| 31 |
+
The answer consists of three non-negative integers g, s, b.
|
| 32 |
+
|
| 33 |
+
* Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time.
|
| 34 |
+
* Otherwise, print three positive numbers g, s, b — the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them.
|
| 35 |
+
|
| 36 |
+
Example
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
5
|
| 42 |
+
12
|
| 43 |
+
5 4 4 3 2 2 1 1 1 1 1 1
|
| 44 |
+
4
|
| 45 |
+
4 3 2 1
|
| 46 |
+
1
|
| 47 |
+
1000000
|
| 48 |
+
20
|
| 49 |
+
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
|
| 50 |
+
32
|
| 51 |
+
64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
1 2 3
|
| 58 |
+
0 0 0
|
| 59 |
+
0 0 0
|
| 60 |
+
2 5 3
|
| 61 |
+
2 6 6
|
| 62 |
+
|
| 63 |
+
Note
|
| 64 |
+
|
| 65 |
+
In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case.
|
| 66 |
+
|
| 67 |
+
In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
|
| 68 |
+
|
| 69 |
+
## Contest Information
|
| 70 |
+
- **Contest ID**: 1264
|
| 71 |
+
- **Problem Index**: A
|
| 72 |
+
- **Points**: 500.0
|
| 73 |
+
- **Rating**: 1500
|
| 74 |
+
- **Tags**: greedy, implementation
|
| 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-0331/instruction.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1285_C. Fadi and LCM
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers.
|
| 5 |
+
|
| 6 |
+
LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6.
|
| 7 |
+
|
| 8 |
+
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first and only line contains an integer X (1 ≤ X ≤ 10^{12}).
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print two positive integers, a and b, such that the value of max(a, b) is minimum possible and LCM(a, b) equals X. If there are several possible such pairs, you can print any.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
2
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
1 2
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
6
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
2 3
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
4
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
1 4
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
1
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
1 1
|
| 66 |
+
|
| 67 |
+
## Contest Information
|
| 68 |
+
- **Contest ID**: 1285
|
| 69 |
+
- **Problem Index**: C
|
| 70 |
+
- **Points**: 1250.0
|
| 71 |
+
- **Rating**: 1400
|
| 72 |
+
- **Tags**: brute force, math, number theory
|
| 73 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 74 |
+
- **Memory Limit**: 256000000 bytes
|
| 75 |
+
|
| 76 |
+
## Task
|
| 77 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0337/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1413_F. Roads and Ramen
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a stone road if it was a sand road and vice versa). Also everyone here loves ramen, that's why every morning a ramen pavilion is set in the middle of every stone road, and at the end of each day all the pavilions are removed.
|
| 5 |
+
|
| 6 |
+
For each of the following m days, after another road is flipped, Naruto and Jiraiya choose a simple path — that is, a route which starts in a village and ends in a (possibly, the same) village, and doesn't contain any road twice. Since Naruto and Jiraiya also love ramen very much, they buy a single cup of ramen on each stone road and one of them eats it. Since they don't want to offend each other, they only choose routes where they can eat equal number of ramen cups. Since they both like traveling, they choose any longest possible path. After every renovation find the maximal possible length of a path (that is, the number of roads in it) they can follow.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains the only positive integer n (2 ≤ n ≤ 500 000) standing for the number of villages in the Land of Fire.
|
| 11 |
+
|
| 12 |
+
Each of the following (n-1) lines contains a description of another road, represented as three positive integers u, v and t (1 ≤ u, v ≤ n, t ∈ \{0,1\}). The first two numbers denote the villages connected by the road, and the third denotes the initial type of the road: 0 for the sand one and 1 for the stone one. Roads are numbered from 1 to (n-1) in the order from the input.
|
| 13 |
+
|
| 14 |
+
The following line contains a positive integer m (1 ≤ m ≤ 500 000) standing for the number of days Naruto and Jiraiya travel for.
|
| 15 |
+
|
| 16 |
+
Each of the following m lines contains the single integer id (1 ≤ id ≤ n-1) standing for the index of the road whose type is flipped on the morning of corresponding day.
|
| 17 |
+
|
| 18 |
+
It is guaranteed that there is a road path between any pair of villages.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Output m lines. In the i-th of them print the only integer denoting the maximal possible length of any valid path on the i-th day.
|
| 23 |
+
|
| 24 |
+
Example
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
5
|
| 30 |
+
1 2 0
|
| 31 |
+
1 3 0
|
| 32 |
+
3 5 0
|
| 33 |
+
3 4 0
|
| 34 |
+
5
|
| 35 |
+
3
|
| 36 |
+
4
|
| 37 |
+
1
|
| 38 |
+
3
|
| 39 |
+
4
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
3
|
| 46 |
+
2
|
| 47 |
+
3
|
| 48 |
+
3
|
| 49 |
+
2
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.
|
| 54 |
+
|
| 55 |
+
After the renovation of the 4-th road one of the longest paths consists of the roads 1 and 2.
|
| 56 |
+
|
| 57 |
+
After the renovation of the 1-st road one of the longest paths consists of the roads 1, 2 and 3.
|
| 58 |
+
|
| 59 |
+
After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.
|
| 60 |
+
|
| 61 |
+
After the renovation of the 4-rd road one of the longest paths consists of the roads 2 and 4.
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 1413
|
| 65 |
+
- **Problem Index**: F
|
| 66 |
+
- **Points**: 3000.0
|
| 67 |
+
- **Rating**: 2800
|
| 68 |
+
- **Tags**: data structures, trees
|
| 69 |
+
- **Time Limit**: {'seconds': 5, 'nanos': 0} seconds
|
| 70 |
+
- **Memory Limit**: 512000000 bytes
|
| 71 |
+
|
| 72 |
+
## Task
|
| 73 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0338/instruction.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1431_I. Cyclic Shifts
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a matrix consisting of n rows and m columns. The matrix contains lowercase letters of the Latin alphabet.
|
| 5 |
+
|
| 6 |
+
You can perform the following operation any number of times you want to: choose two integers i (1 ≤ i ≤ m) and k (0 < k < n), and shift every column j such that i ≤ j ≤ m cyclically by k. The shift is performed upwards.
|
| 7 |
+
|
| 8 |
+
For example, if you have a matrix
|
| 9 |
+
|
| 10 |
+
\left( \begin{array} \\\ a & b & c \\\ d & e & f \\\ g & h & i \end{array}\right) and perform an operation with i = 2, k = 1, then it becomes: \left( \begin{array} \\\ a & e & f \\\ d & h & i \\\ g & b & c \end{array}\right)
|
| 11 |
+
|
| 12 |
+
You have to process q queries. Each of the queries is a string of length m consisting of lowercase letters of the Latin alphabet. For each query, you have to calculate the minimum number of operations described above you have to perform so that at least one row of the matrix is equal to the string from the query. Note that all queries are independent, that is, the operations you perform in a query don't affect the initial matrix in other queries.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains three integers n, m, q (2 ≤ n, m, q ≤ 2.5 ⋅ 10^5; n ⋅ m ≤ 5 ⋅ 10^5; q ⋅ m ≤ 5 ⋅ 10^5) — the number of rows and columns in the matrix and the number of queries, respectively.
|
| 17 |
+
|
| 18 |
+
The next n lines contains m lowercase Latin letters each — elements of the matrix.
|
| 19 |
+
|
| 20 |
+
The following q lines contains a description of queries — strings of length m consisting of lowercase letters of the Latin alphabet.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print q integers. The i-th integer should be equal to the minimum number of operations you have to perform so that the matrix contains a string from the i-th query or -1 if the specified string cannot be obtained.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
3 5 4
|
| 32 |
+
abacc
|
| 33 |
+
ccbba
|
| 34 |
+
ccabc
|
| 35 |
+
abacc
|
| 36 |
+
acbbc
|
| 37 |
+
ababa
|
| 38 |
+
acbbc
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
0
|
| 45 |
+
2
|
| 46 |
+
1
|
| 47 |
+
2
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
6 4 4
|
| 54 |
+
daac
|
| 55 |
+
bcba
|
| 56 |
+
acad
|
| 57 |
+
cbdc
|
| 58 |
+
aaaa
|
| 59 |
+
bcbb
|
| 60 |
+
dcdd
|
| 61 |
+
acba
|
| 62 |
+
bbbb
|
| 63 |
+
dbcd
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
3
|
| 70 |
+
1
|
| 71 |
+
2
|
| 72 |
+
-1
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Input
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
5 10 5
|
| 79 |
+
ltjksdyfgg
|
| 80 |
+
cbhpsereqn
|
| 81 |
+
ijndtzbzcf
|
| 82 |
+
ghgcgeadep
|
| 83 |
+
bfzdgxqmqe
|
| 84 |
+
ibgcgzyfep
|
| 85 |
+
bbhdgxqmqg
|
| 86 |
+
ltgcgxrzep
|
| 87 |
+
ljnpseldgn
|
| 88 |
+
ghhpseyzcf
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
Output
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
5
|
| 95 |
+
3
|
| 96 |
+
5
|
| 97 |
+
-1
|
| 98 |
+
3
|
| 99 |
+
|
| 100 |
+
## Contest Information
|
| 101 |
+
- **Contest ID**: 1431
|
| 102 |
+
- **Problem Index**: I
|
| 103 |
+
- **Points**: 0.0
|
| 104 |
+
- **Rating**: 2900
|
| 105 |
+
- **Tags**: *special, strings
|
| 106 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 107 |
+
- **Memory Limit**: 512000000 bytes
|
| 108 |
+
|
| 109 |
+
## Task
|
| 110 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0352/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 371_B. Fox Dividing Cheese
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".
|
| 5 |
+
|
| 6 |
+
The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109).
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
15 20
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
3
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
14 8
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
-1
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
6 6
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
0
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 371
|
| 49 |
+
- **Problem Index**: B
|
| 50 |
+
- **Points**: 1000.0
|
| 51 |
+
- **Rating**: 1300
|
| 52 |
+
- **Tags**: math, number theory
|
| 53 |
+
- **Time Limit**: {'seconds': 1, '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-0354/instruction.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 415_E. Mashmokh and Reverse Operation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.
|
| 5 |
+
|
| 6 |
+
You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must:
|
| 7 |
+
|
| 8 |
+
* split the array into 2n - qi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1 ≤ j ≤ 2n - qi) should contain the elements a[(j - 1)·2qi + 1], a[(j - 1)·2qi + 2], ..., a[(j - 1)·2qi + 2qi];
|
| 9 |
+
* reverse each of the subarrays;
|
| 10 |
+
* join them into a single array in the same order (this array becomes new array a);
|
| 11 |
+
* output the number of inversions in the new a.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The first line of input contains a single integer n (0 ≤ n ≤ 20).
|
| 20 |
+
|
| 21 |
+
The second line of input contains 2n space-separated integers a[1], a[2], ..., a[2n] (1 ≤ a[i] ≤ 109), the initial array.
|
| 22 |
+
|
| 23 |
+
The third line of input contains a single integer m (1 ≤ m ≤ 106).
|
| 24 |
+
|
| 25 |
+
The fourth line of input contains m space-separated integers q1, q2, ..., qm (0 ≤ qi ≤ n), the queries.
|
| 26 |
+
|
| 27 |
+
Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query.
|
| 32 |
+
|
| 33 |
+
Examples
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
2
|
| 38 |
+
2 1 4 3
|
| 39 |
+
4
|
| 40 |
+
1 2 0 2
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
0
|
| 46 |
+
6
|
| 47 |
+
6
|
| 48 |
+
0
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
1
|
| 54 |
+
1 2
|
| 55 |
+
3
|
| 56 |
+
0 1 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
0
|
| 62 |
+
1
|
| 63 |
+
0
|
| 64 |
+
|
| 65 |
+
Note
|
| 66 |
+
|
| 67 |
+
If we reverse an array x[1], x[2], ..., x[n] it becomes new array y[1], y[2], ..., y[n], where y[i] = x[n - i + 1] for each i.
|
| 68 |
+
|
| 69 |
+
The number of inversions of an array x[1], x[2], ..., x[n] is the number of pairs of indices i, j such that: i < j and x[i] > x[j].
|
| 70 |
+
|
| 71 |
+
## Contest Information
|
| 72 |
+
- **Contest ID**: 415
|
| 73 |
+
- **Problem Index**: E
|
| 74 |
+
- **Points**: 1500.0
|
| 75 |
+
- **Rating**: 2100
|
| 76 |
+
- **Tags**: combinatorics, divide and conquer
|
| 77 |
+
- **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
|
| 78 |
+
- **Memory Limit**: 512000000 bytes
|
| 79 |
+
|
| 80 |
+
## Task
|
| 81 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0355/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 442_C. Artem and Array
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points.
|
| 5 |
+
|
| 6 |
+
After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
In a single line print a single integer — the maximum number of points Artem can get.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
5
|
| 21 |
+
3 1 5 2 6
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
11
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
5
|
| 32 |
+
1 2 3 4 5
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
6
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
5
|
| 43 |
+
1 100 101 100 1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
102
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 442
|
| 52 |
+
- **Problem Index**: C
|
| 53 |
+
- **Points**: 1500.0
|
| 54 |
+
- **Rating**: 2500
|
| 55 |
+
- **Tags**: data structures, greedy
|
| 56 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0363/instruction.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 630_A. Again Twenty Five!
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."
|
| 5 |
+
|
| 6 |
+
Could you pass the interview in the machine vision company in IT City?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Output the last two digits of 5n without spaces between them.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
2
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
25
|
| 26 |
+
|
| 27 |
+
## Contest Information
|
| 28 |
+
- **Contest ID**: 630
|
| 29 |
+
- **Problem Index**: A
|
| 30 |
+
- **Points**: 0.0
|
| 31 |
+
- **Rating**: 800
|
| 32 |
+
- **Tags**: number theory
|
| 33 |
+
- **Time Limit**: {'seconds': 0, 'nanos': 500000000} seconds
|
| 34 |
+
- **Memory Limit**: 64000000 bytes
|
| 35 |
+
|
| 36 |
+
## Task
|
| 37 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0390/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02705 AtCoder Beginner Contest 163 - Circle Pond
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Print the circumference of a circle of radius R.
|
| 5 |
+
|
| 6 |
+
Constraints
|
| 7 |
+
|
| 8 |
+
* 1 \leq R \leq 100
|
| 9 |
+
* All values in input are integers.
|
| 10 |
+
|
| 11 |
+
Input
|
| 12 |
+
|
| 13 |
+
Input is given from Standard Input in the following format:
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
R
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Output
|
| 20 |
+
|
| 21 |
+
Print the circumference of the circle. Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
1
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
6.28318530717958623200
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
73
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
458.67252742410977361942
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 0
|
| 46 |
+
- **Problem Index**:
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 0
|
| 49 |
+
- **Tags**:
|
| 50 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 1073741824 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-0396/instruction.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03570 CODE FESTIVAL 2017 qual C - Yet Another Palindrome Partitioning
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to satisfy the following condition:
|
| 5 |
+
|
| 6 |
+
* For each i (1 \leq i \leq N), it is possible to permute the characters in s_i and obtain a palindrome.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Find the minimum possible value of N when the partition satisfies the condition.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 \leq |s| \leq 2 \times 10^5
|
| 15 |
+
* s consists of lowercase English letters.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
Input is given from Standard Input in the following format:
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
s
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Print the minimum possible value of N when the partition satisfies the condition.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
aabxyyzz
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
byebye
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
1
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
abcdefghijklmnopqrstuvwxyz
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
26
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Input
|
| 62 |
+
|
| 63 |
+
abcabcxabcx
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Output
|
| 67 |
+
|
| 68 |
+
3
|
| 69 |
+
|
| 70 |
+
## Contest Information
|
| 71 |
+
- **Contest ID**: 0
|
| 72 |
+
- **Problem Index**:
|
| 73 |
+
- **Points**: 0.0
|
| 74 |
+
- **Rating**: 0
|
| 75 |
+
- **Tags**:
|
| 76 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 77 |
+
- **Memory Limit**: 536870912 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-0399/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p04048 AtCoder Grand Contest 001 - Mysterious Light
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of Mysterious Light.
|
| 5 |
+
|
| 6 |
+
Three mirrors of length N are set so that they form an equilateral triangle. Let the vertices of the triangle be a, b and c.
|
| 7 |
+
|
| 8 |
+
Inside the triangle, the rifle is placed at the point p on segment ab such that ap = X. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of bc.
|
| 9 |
+
|
| 10 |
+
The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.
|
| 11 |
+
|
| 12 |
+
The following image shows the ray's trajectory where N = 5 and X = 2.
|
| 13 |
+
|
| 14 |
+
btriangle.png
|
| 15 |
+
|
| 16 |
+
It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of N and X. Find the total length of the ray's trajectory.
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
|
| 20 |
+
* 2≦N≦10^{12}
|
| 21 |
+
* 1≦X≦N-1
|
| 22 |
+
* N and X are integers.
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
The input is given from Standard Input in the following format:
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
N X
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print the total length of the ray's trajectory.
|
| 35 |
+
|
| 36 |
+
Example
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
5 2
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 0
|
| 49 |
+
- **Problem Index**:
|
| 50 |
+
- **Points**: 0.0
|
| 51 |
+
- **Rating**: 0
|
| 52 |
+
- **Tags**:
|
| 53 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 268435456 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-0414/instruction.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02211 Apple Adventure
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Apple adventure
|
| 5 |
+
|
| 6 |
+
square1001 and E869120 got lost in the grid world of $ H $ rows and $ W $ rows!
|
| 7 |
+
|
| 8 |
+
Said the god of this world.
|
| 9 |
+
|
| 10 |
+
"When you collect $ K $ apples and they meet, you'll be back in the original world."
|
| 11 |
+
|
| 12 |
+
Upon hearing this word, square1001 decided to collect more than $ K $ of apples and head to the square where E869120 is.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Here, each cell in the grid is represented as follows.
|
| 18 |
+
|
| 19 |
+
's': square1001 This is the square where you are.
|
| 20 |
+
|
| 21 |
+
'e': E869120 This is the square where you are.
|
| 22 |
+
|
| 23 |
+
'a': A square with one apple on it. You can get an apple the first time you visit this trout. There are no more than 20 squares on this grid.
|
| 24 |
+
|
| 25 |
+
'#': It's a wall. You cannot visit this square.
|
| 26 |
+
|
| 27 |
+
'.': A square with nothing. You can visit this square.
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
square1001 You try to achieve your goal by repeatedly moving from the square you are in to the squares that are adjacent to each other up, down, left, and right. However, you cannot get out of the grid.
|
| 33 |
+
|
| 34 |
+
square1001 Find the minimum number of moves you need to achieve your goal.
|
| 35 |
+
|
| 36 |
+
However, it is assumed that E869120 will not move. Also, square1001 shall be capable of carrying $ K $ or more of apples.
|
| 37 |
+
|
| 38 |
+
If the goal cannot be achieved, output "-1".
|
| 39 |
+
|
| 40 |
+
input
|
| 41 |
+
|
| 42 |
+
Input is given from standard input in the following format.
|
| 43 |
+
|
| 44 |
+
Let $ A_ {i, j} $ be the characters in the $ i $ square from the top of the grid and the $ j $ square from the left.
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
$ H $ $ W $ $ K $
|
| 48 |
+
$ A_ {1,1} A_ {1,2} A_ {1,3} \ cdots A_ {1, W} $
|
| 49 |
+
$ A_ {2,1} A_ {2,2} A_ {2,3} \ cdots A_ {2, W} $
|
| 50 |
+
$ A_ {3,1} A_ {3,2} A_ {3,3} \ cdots A_ {3, W} $
|
| 51 |
+
$ \ ldots $
|
| 52 |
+
$ A_ {H, 1} A_ {H, 2} A_ {H, 3} \ cdots A_ {H, W} $
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
output
|
| 56 |
+
|
| 57 |
+
square1001 Find the minimum number of moves you need to reach your goal. However, if this is not possible, output "-1".
|
| 58 |
+
|
| 59 |
+
However, insert a line break at the end.
|
| 60 |
+
|
| 61 |
+
Constraint
|
| 62 |
+
|
| 63 |
+
* $ 1 \ leq H \ leq 1000 $
|
| 64 |
+
* $ 1 \ leq W \ leq 1000 $
|
| 65 |
+
* $ 1 \ leq K \ leq 20 $
|
| 66 |
+
* $ H, W, K $ are integers.
|
| 67 |
+
* $ A_ {i, j} $ is one of's','e','a','#','.'.
|
| 68 |
+
* The grid contains only one's' and one'e'.
|
| 69 |
+
* The number of'a'in the grid is greater than or equal to $ K $ and less than or equal to $ 20 $.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Input example 1
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
5 5 2
|
| 77 |
+
s .. # a
|
| 78 |
+
. # ...
|
| 79 |
+
a # e. #
|
| 80 |
+
... # a
|
| 81 |
+
. # ...
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
Output example 1
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
14
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Input example 2
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
7 7 3
|
| 94 |
+
.......
|
| 95 |
+
.s ... a.
|
| 96 |
+
a ## ... a
|
| 97 |
+
.. ### ..
|
| 98 |
+
.a # e # .a
|
| 99 |
+
. ### ..
|
| 100 |
+
a .. # .. a
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
Output example 2
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
-1
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
If the purpose cannot be achieved, output "-1".
|
| 110 |
+
|
| 111 |
+
Input example 3
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
12 12 10
|
| 115 |
+
. ##### ......
|
| 116 |
+
.## ..... # ...
|
| 117 |
+
.... a.a # a .. #
|
| 118 |
+
. # .. # a ......
|
| 119 |
+
..... a # s ..
|
| 120 |
+
..a ###. ##. #
|
| 121 |
+
.e #. #. #. # A ..
|
| 122 |
+
.. # a # ..... #.
|
| 123 |
+
.. ## a ......
|
| 124 |
+
.a ... a.a .. #.
|
| 125 |
+
a .... # a.aa ..
|
| 126 |
+
... a. # ... # a.
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
Output example 3
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
30
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
Example
|
| 140 |
+
|
| 141 |
+
Input
|
| 142 |
+
|
| 143 |
+
5 5 2
|
| 144 |
+
s..#a
|
| 145 |
+
.#...
|
| 146 |
+
a#e.#
|
| 147 |
+
...#a
|
| 148 |
+
.#...
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
Output
|
| 152 |
+
|
| 153 |
+
14
|
| 154 |
+
|
| 155 |
+
## Contest Information
|
| 156 |
+
- **Contest ID**: 0
|
| 157 |
+
- **Problem Index**:
|
| 158 |
+
- **Points**: 0.0
|
| 159 |
+
- **Rating**: 0
|
| 160 |
+
- **Tags**:
|
| 161 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 162 |
+
- **Memory Limit**: 536870912 bytes
|
| 163 |
+
|
| 164 |
+
## Task
|
| 165 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0551/instruction.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1539_D. PriceFixed
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
|
| 5 |
+
|
| 6 |
+
* The store has an infinite number of items of every product.
|
| 7 |
+
* All products have the same price: 2 rubles per item.
|
| 8 |
+
* For every product i there is a discount for experienced buyers: if you buy b_i items of products (of any type, not necessarily type i), then for all future purchases of the i-th product there is a 50\% discount (so you can buy an item of the i-th product for 1 ruble!).
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Lena needs to buy n products: she must purchase at least a_i items of the i-th product. Help Lena to calculate the minimum amount of money she needs to spend if she optimally chooses the order of purchasing. Note that if she wants, she can buy more items of some product than needed.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of products.
|
| 17 |
+
|
| 18 |
+
Each of next n lines contains a product description. Each description consists of two integers a_i and b_i (1 ≤ a_i ≤ 10^{14}, 1 ≤ b_i ≤ 10^{14}) — the required number of the i-th product and how many products you need to buy to get the discount on the i-th product.
|
| 19 |
+
|
| 20 |
+
The sum of all a_i does not exceed 10^{14}.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Output the minimum sum that Lena needs to make all purchases.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
3 4
|
| 33 |
+
1 3
|
| 34 |
+
1 5
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
8
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
5
|
| 47 |
+
2 7
|
| 48 |
+
2 8
|
| 49 |
+
1 2
|
| 50 |
+
2 4
|
| 51 |
+
1 8
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
12
|
| 58 |
+
|
| 59 |
+
Note
|
| 60 |
+
|
| 61 |
+
In the first example, Lena can purchase the products in the following way:
|
| 62 |
+
|
| 63 |
+
1. one item of product 3 for 2 rubles,
|
| 64 |
+
2. one item of product 1 for 2 rubles,
|
| 65 |
+
3. one item of product 1 for 2 rubles,
|
| 66 |
+
4. one item of product 2 for 1 ruble (she can use the discount because 3 items are already purchased),
|
| 67 |
+
5. one item of product 1 for 1 ruble (she can use the discount because 4 items are already purchased).
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
In total, she spends 8 rubles. It can be proved that it is impossible to spend less.
|
| 72 |
+
|
| 73 |
+
In the second example Lena can purchase the products in the following way:
|
| 74 |
+
|
| 75 |
+
1. one item of product 1 for 2 rubles,
|
| 76 |
+
2. two items of product 2 for 2 rubles for each,
|
| 77 |
+
3. one item of product 5 for 2 rubles,
|
| 78 |
+
4. one item of product 3 for 1 ruble,
|
| 79 |
+
5. two items of product 4 for 1 ruble for each,
|
| 80 |
+
6. one item of product 1 for 1 ruble.
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
In total, she spends 12 rubles.
|
| 85 |
+
|
| 86 |
+
## Contest Information
|
| 87 |
+
- **Contest ID**: 1539
|
| 88 |
+
- **Problem Index**: D
|
| 89 |
+
- **Points**: 1500.0
|
| 90 |
+
- **Rating**: 1600
|
| 91 |
+
- **Tags**: binary search, greedy, implementation, sortings, two pointers
|
| 92 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 93 |
+
- **Memory Limit**: 256000000 bytes
|
| 94 |
+
|
| 95 |
+
## Task
|
| 96 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0560/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 352_E. Jeff and Brackets
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Jeff loves regular bracket sequences.
|
| 5 |
+
|
| 6 |
+
Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows that he is going to spend ai mod n liters of ink on the i-th bracket of the sequence if he paints it opened and bi mod n liters if he paints it closed.
|
| 7 |
+
|
| 8 |
+
You've got sequences a, b and numbers n, m. What minimum amount of ink will Jeff need to paint a regular bracket sequence of length nm?
|
| 9 |
+
|
| 10 |
+
Operation x mod y means taking the remainder after dividing number x by number y.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains two integers n and m (1 ≤ n ≤ 20; 1 ≤ m ≤ 107; m is even). The next line contains n integers: a0, a1, ..., an - 1 (1 ≤ ai ≤ 10). The next line contains n integers: b0, b1, ..., bn - 1 (1 ≤ bi ≤ 10). The numbers are separated by spaces.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
In a single line print the answer to the problem — the minimum required amount of ink in liters.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
2 6
|
| 25 |
+
1 2
|
| 26 |
+
2 1
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
12
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
1 10000000
|
| 37 |
+
2
|
| 38 |
+
3
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
25000000
|
| 44 |
+
|
| 45 |
+
Note
|
| 46 |
+
|
| 47 |
+
In the first test the optimal sequence is: ()()()()()(), the required number of ink liters is 12.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 352
|
| 51 |
+
- **Problem Index**: E
|
| 52 |
+
- **Points**: 1500.0
|
| 53 |
+
- **Rating**: 2500
|
| 54 |
+
- **Tags**: dp, matrices
|
| 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-0566/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 492_D. Vanya and Computer Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.
|
| 5 |
+
|
| 6 |
+
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
|
| 11 |
+
|
| 12 |
+
Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
4 3 2
|
| 23 |
+
1
|
| 24 |
+
2
|
| 25 |
+
3
|
| 26 |
+
4
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Vanya
|
| 32 |
+
Vova
|
| 33 |
+
Vanya
|
| 34 |
+
Both
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
2 1 1
|
| 40 |
+
1
|
| 41 |
+
2
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
Both
|
| 47 |
+
Both
|
| 48 |
+
|
| 49 |
+
Note
|
| 50 |
+
|
| 51 |
+
In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.
|
| 52 |
+
|
| 53 |
+
In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 492
|
| 57 |
+
- **Problem Index**: D
|
| 58 |
+
- **Points**: 2000.0
|
| 59 |
+
- **Rating**: 1800
|
| 60 |
+
- **Tags**: binary search, implementation, math, sortings
|
| 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-0569/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 56_E. Domino Principle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put n dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The i-th domino has the coordinate xi and the height hi. Now Vasya wants to learn for every domino, how many dominoes will fall if he pushes it to the right. Help him do that.
|
| 5 |
+
|
| 6 |
+
Consider that a domino falls if it is touched strictly above the base. In other words, the fall of the domino with the initial coordinate x and height h leads to the fall of all dominoes on the segment [x + 1, x + h - 1].
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains integer n (1 ≤ n ≤ 105) which is the number of dominoes. Then follow n lines containing two integers xi and hi ( - 108 ≤ xi ≤ 108, 2 ≤ hi ≤ 108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print n space-separated numbers zi — the number of dominoes that will fall if Vasya pushes the i-th domino to the right (including the domino itself).
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
4
|
| 23 |
+
16 5
|
| 24 |
+
20 5
|
| 25 |
+
10 10
|
| 26 |
+
18 2
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
3 1 4 1
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4
|
| 36 |
+
0 10
|
| 37 |
+
1 5
|
| 38 |
+
9 10
|
| 39 |
+
15 10
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
4 1 2 1
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 56
|
| 48 |
+
- **Problem Index**: E
|
| 49 |
+
- **Points**: 2500.0
|
| 50 |
+
- **Rating**: 2200
|
| 51 |
+
- **Tags**: binary search, data structures, sortings
|
| 52 |
+
- **Time Limit**: {'seconds': 2, '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-0592/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lazy-boy-off-to-class-i
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
All the students in NIT are very lazy. They want to have maximum time for rest. But due to college rules, they must maintain 75% attendance at the end of every week.
|
| 5 |
+
|
| 6 |
+
Given the schedule of a week, tell them what is the maximum amount of time they might have for resting.
|
| 7 |
+
|
| 8 |
+
NOTE:
|
| 9 |
+
|
| 10 |
+
Each day has 24 hrs. i.e. 24x60x60 seconds.
|
| 11 |
+
|
| 12 |
+
Classes can of any duration from 1 sec to 24 hrs.
|
| 13 |
+
|
| 14 |
+
Time of any 2 classes on same day will never intersect.
|
| 15 |
+
|
| 16 |
+
Constraints:
|
| 17 |
+
|
| 18 |
+
1 ≤ t ≤ 10
|
| 19 |
+
|
| 20 |
+
1 ≤ n ≤ 2000
|
| 21 |
+
|
| 22 |
+
Where n is the total number of classes in the week and t is number of test cases.
|
| 23 |
+
|
| 24 |
+
Input:
|
| 25 |
+
|
| 26 |
+
First line of input will be an integer t, the number of test cases.
|
| 27 |
+
|
| 28 |
+
Each test case will contain 7 lines i.e. the schedule of each day.
|
| 29 |
+
|
| 30 |
+
First integer in each line will denote the number of classes on that day , say ni , followed by 2xni integers denoting start and end time of each class in seconds ( where 0 represents 12:00 at night and 60 represents 12:01 at night).
|
| 31 |
+
|
| 32 |
+
Output:
|
| 33 |
+
|
| 34 |
+
For each test case output the Maximum amount of time in seconds students have for resting.
|
| 35 |
+
|
| 36 |
+
SAMPLE INPUT
|
| 37 |
+
1
|
| 38 |
+
3 60 70 80 90 100 200
|
| 39 |
+
3 50 70 100 120 150 200
|
| 40 |
+
3 50 80 90 100 200 220
|
| 41 |
+
3 80 100 110 115 200 210
|
| 42 |
+
3 10 20 40 50 60 100
|
| 43 |
+
3 10 50 60 80 90 100
|
| 44 |
+
3 50 80 90 100 200 300
|
| 45 |
+
|
| 46 |
+
SAMPLE OUTPUT
|
| 47 |
+
604555
|
| 48 |
+
|
| 49 |
+
Explanation
|
| 50 |
+
|
| 51 |
+
Resting time will be maximum when students attend:
|
| 52 |
+
Day 1 – first 2 classes
|
| 53 |
+
Day 2 – first 2 classes
|
| 54 |
+
Day 3 – all 3 classes
|
| 55 |
+
Day 4 – all 3 classes
|
| 56 |
+
Day 5 – first 2 classes
|
| 57 |
+
Day 6 – last 2 classes
|
| 58 |
+
Day 7 – first 2 classes.
|
| 59 |
+
Total classes the attended is 16 = 75% of 21.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 0
|
| 63 |
+
- **Problem Index**:
|
| 64 |
+
- **Points**: 0.0
|
| 65 |
+
- **Rating**: 0
|
| 66 |
+
- **Tags**: None
|
| 67 |
+
- **Time Limit**: None seconds
|
| 68 |
+
- **Memory Limit**: 0 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-0595/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# roy-and-profile-picture
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload.
|
| 5 |
+
Minimum dimension of the picture can be L x L, where L is the length of the side of square.
|
| 6 |
+
|
| 7 |
+
Now Roy has N photos of various dimensions.
|
| 8 |
+
Dimension of a photo is denoted as W x H
|
| 9 |
+
where W - width of the photo and H - Height of the photo
|
| 10 |
+
|
| 11 |
+
When any photo is uploaded following events may occur:
|
| 12 |
+
|
| 13 |
+
[1] If any of the width or height is less than L, user is prompted to upload another one. Print "UPLOAD ANOTHER" in this case.
|
| 14 |
+
[2] If width and height, both are large enough and
|
| 15 |
+
(a) if the photo is already square then it is accepted. Print "ACCEPTED" in this case.
|
| 16 |
+
(b) else user is prompted to crop it. Print "CROP IT" in this case.
|
| 17 |
+
|
| 18 |
+
(quotes are only for clarification)
|
| 19 |
+
|
| 20 |
+
Given L, N, W and H as input, print appropriate text as output.
|
| 21 |
+
|
| 22 |
+
Input:
|
| 23 |
+
First line contains L.
|
| 24 |
+
Second line contains N, number of photos.
|
| 25 |
+
Following N lines each contains two space separated integers W and H.
|
| 26 |
+
|
| 27 |
+
Output:
|
| 28 |
+
Print appropriate text for each photo in a new line.
|
| 29 |
+
|
| 30 |
+
Constraints:
|
| 31 |
+
1 ≤ L,W,H ≤ 10000
|
| 32 |
+
1 ≤ N ≤ 1000
|
| 33 |
+
|
| 34 |
+
SAMPLE INPUT
|
| 35 |
+
180
|
| 36 |
+
3
|
| 37 |
+
640 480
|
| 38 |
+
120 300
|
| 39 |
+
180 180
|
| 40 |
+
|
| 41 |
+
SAMPLE OUTPUT
|
| 42 |
+
CROP IT
|
| 43 |
+
UPLOAD ANOTHER
|
| 44 |
+
ACCEPTED
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 0
|
| 48 |
+
- **Problem Index**:
|
| 49 |
+
- **Points**: 0.0
|
| 50 |
+
- **Rating**: 0
|
| 51 |
+
- **Tags**: None
|
| 52 |
+
- **Time Limit**: None seconds
|
| 53 |
+
- **Memory Limit**: 0 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-0621/instruction.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01963 Separate String
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
|
| 5 |
+
|
| 6 |
+
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$.
|
| 7 |
+
|
| 8 |
+
* $a,b,a,b$
|
| 9 |
+
* $a,b,ab$
|
| 10 |
+
* $ab,a,b$
|
| 11 |
+
* $ab,ab$
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Your task is to count the number of ways to separate $t$. Because the result can be large, you should output the remainder divided by $1,000,000,007$.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The input consists of a single test case formatted as follows.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
$N$
|
| 25 |
+
$s_1$
|
| 26 |
+
:
|
| 27 |
+
$s_N$
|
| 28 |
+
$t$
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
The first line consists of an integer $N$ ($1 \leq N \leq 100,000$) which is the number of the elements of $S$. The following $N$ lines consist of $N$ distinct strings separated by line breaks. The $i$-th string $s_i$ represents the $i$-th element of $S$. $s_i$ consists of lowercase letters and the length is between $1$ and $100,000$, inclusive. The summation of length of $s_i$ ($1 \leq i \leq N$) is at most $200,000$. The next line consists of a string $t$ which consists of lowercase letters and represents the string to be separated and the length is between $1$ and $100,000$, inclusive.
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
Calculate the number of ways to separate $t$ and print the remainder divided by $1,000,000,007$.
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
3
|
| 42 |
+
a
|
| 43 |
+
b
|
| 44 |
+
ab
|
| 45 |
+
abab
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
4
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
3
|
| 56 |
+
a
|
| 57 |
+
b
|
| 58 |
+
c
|
| 59 |
+
xyz
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
0
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Input
|
| 68 |
+
|
| 69 |
+
7
|
| 70 |
+
abc
|
| 71 |
+
ab
|
| 72 |
+
bc
|
| 73 |
+
a
|
| 74 |
+
b
|
| 75 |
+
c
|
| 76 |
+
aa
|
| 77 |
+
aaabcbccababbc
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Output
|
| 81 |
+
|
| 82 |
+
160
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Input
|
| 86 |
+
|
| 87 |
+
10
|
| 88 |
+
a
|
| 89 |
+
aa
|
| 90 |
+
aaa
|
| 91 |
+
aaaa
|
| 92 |
+
aaaaa
|
| 93 |
+
aaaaaa
|
| 94 |
+
aaaaaaa
|
| 95 |
+
aaaaaaaa
|
| 96 |
+
aaaaaaaaa
|
| 97 |
+
aaaaaaaaaa
|
| 98 |
+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
Output
|
| 102 |
+
|
| 103 |
+
461695029
|
| 104 |
+
|
| 105 |
+
## Contest Information
|
| 106 |
+
- **Contest ID**: 0
|
| 107 |
+
- **Problem Index**:
|
| 108 |
+
- **Points**: 0.0
|
| 109 |
+
- **Rating**: 0
|
| 110 |
+
- **Tags**:
|
| 111 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 112 |
+
- **Memory Limit**: 536870912 bytes
|
| 113 |
+
|
| 114 |
+
## Task
|
| 115 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0700/instruction.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tablets
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Therasa is a Nurse. She wants to give some tablets to the patients in her practice. All the patients sit in a line and each of them has a rating score according to his or her health score. Therasa wants to give at least 1 tablet for each patient. Patients get jealous of their immediate neighbors, so if two patients sit next to each other then the one with the higher rating must get more tablets. Therasa wants to save money, so she wants to minimize the total number of tablets.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
The first line of the input is an integer N, the number of patients in Therasa’s practice. Each of the following N lines contains an integer indicates the health score of each patient.
|
| 8 |
+
|
| 9 |
+
Output
|
| 10 |
+
Output a single line containing the minimum number of tablets Therasa must give.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
1 ≤ N ≤ 100000
|
| 14 |
+
1 ≤ health score ≤ 100000
|
| 15 |
+
|
| 16 |
+
SAMPLE INPUT
|
| 17 |
+
3
|
| 18 |
+
1
|
| 19 |
+
2
|
| 20 |
+
2
|
| 21 |
+
|
| 22 |
+
SAMPLE OUTPUT
|
| 23 |
+
4
|
| 24 |
+
|
| 25 |
+
Explanation
|
| 26 |
+
|
| 27 |
+
Here 1, 2, 2 is the health score. Note that when two patients have equal health score they are allowed to have different number of tablets. Hence optimal distribution will be 1, 2, 1.
|
| 28 |
+
|
| 29 |
+
## Contest Information
|
| 30 |
+
- **Contest ID**: 0
|
| 31 |
+
- **Problem Index**:
|
| 32 |
+
- **Points**: 0.0
|
| 33 |
+
- **Rating**: 0
|
| 34 |
+
- **Tags**: None
|
| 35 |
+
- **Time Limit**: None seconds
|
| 36 |
+
- **Memory Limit**: 0 bytes
|
| 37 |
+
|
| 38 |
+
## Task
|
| 39 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0707/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03318 AtCoder Beginner Contest 101 - Snuke Numbers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6.
|
| 5 |
+
|
| 6 |
+
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
|
| 7 |
+
|
| 8 |
+
Given an integer K, list the K smallest Snuke numbers.
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
|
| 12 |
+
* 1 \leq K
|
| 13 |
+
* The K-th smallest Snuke number is not greater than 10^{15}.
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
Input is given from Standard Input in the following format:
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
K
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
Print K lines. The i-th line should contain the i-th smallest Snuke number.
|
| 26 |
+
|
| 27 |
+
Example
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
10
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
1
|
| 37 |
+
2
|
| 38 |
+
3
|
| 39 |
+
4
|
| 40 |
+
5
|
| 41 |
+
6
|
| 42 |
+
7
|
| 43 |
+
8
|
| 44 |
+
9
|
| 45 |
+
19
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 0
|
| 49 |
+
- **Problem Index**:
|
| 50 |
+
- **Points**: 0.0
|
| 51 |
+
- **Rating**: 0
|
| 52 |
+
- **Tags**:
|
| 53 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 1073741824 bytes
|
| 55 |
+
|
| 56 |
+
## Task
|
| 57 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0708/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03474 AtCoder Beginner Contest 084 - Postal Code
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`.
|
| 5 |
+
|
| 6 |
+
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* 1≤A,B≤5
|
| 11 |
+
* |S|=A+B+1
|
| 12 |
+
* S consists of `-` and digits from `0` through `9`.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
Input is given from Standard Input in the following format:
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
A B
|
| 20 |
+
S
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise.
|
| 26 |
+
|
| 27 |
+
Examples
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
3 4
|
| 32 |
+
269-6650
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
Yes
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
1 1
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
No
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
1 2
|
| 54 |
+
7444
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
No
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 0
|
| 63 |
+
- **Problem Index**:
|
| 64 |
+
- **Points**: 0.0
|
| 65 |
+
- **Rating**: 0
|
| 66 |
+
- **Tags**:
|
| 67 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 268435456 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-0709/instruction.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03637 AtCoder Beginner Contest 069 - 4-adjacent
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer.
|
| 5 |
+
|
| 6 |
+
Snuke's objective is to permute the element in a so that the following condition is satisfied:
|
| 7 |
+
|
| 8 |
+
* For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Determine whether Snuke can achieve his objective.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* 2 ≤ N ≤ 10^5
|
| 17 |
+
* a_i is an integer.
|
| 18 |
+
* 1 ≤ a_i ≤ 10^9
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
Input is given from Standard Input in the following format:
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
N
|
| 26 |
+
a_1 a_2 ... a_N
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
If Snuke can achieve his objective, print `Yes`; otherwise, print `No`.
|
| 32 |
+
|
| 33 |
+
Examples
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
3
|
| 38 |
+
1 10 100
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
Yes
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
4
|
| 49 |
+
1 2 3 4
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
No
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Input
|
| 58 |
+
|
| 59 |
+
3
|
| 60 |
+
1 4 1
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
Yes
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Input
|
| 69 |
+
|
| 70 |
+
2
|
| 71 |
+
1 1
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Output
|
| 75 |
+
|
| 76 |
+
No
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Input
|
| 80 |
+
|
| 81 |
+
6
|
| 82 |
+
2 7 1 8 2 8
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Output
|
| 86 |
+
|
| 87 |
+
Yes
|
| 88 |
+
|
| 89 |
+
## Contest Information
|
| 90 |
+
- **Contest ID**: 0
|
| 91 |
+
- **Problem Index**:
|
| 92 |
+
- **Points**: 0.0
|
| 93 |
+
- **Rating**: 0
|
| 94 |
+
- **Tags**:
|
| 95 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 96 |
+
- **Memory Limit**: 268435456 bytes
|
| 97 |
+
|
| 98 |
+
## Task
|
| 99 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0730/instruction.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# cielrcpt
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Tomya is a girl. She loves Chef Ciel very much.
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p.
|
| 8 |
+
The current menus of Ciel's restaurant are shown the following table.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
Name of Menuprice
|
| 12 |
+
eel flavored water1
|
| 13 |
+
deep-fried eel bones2
|
| 14 |
+
clear soup made with eel livers4
|
| 15 |
+
grilled eel livers served with grated radish8
|
| 16 |
+
savory egg custard with eel16
|
| 17 |
+
eel fried rice (S)32
|
| 18 |
+
eel fried rice (L)64
|
| 19 |
+
grilled eel wrapped in cooked egg128
|
| 20 |
+
eel curry rice256
|
| 21 |
+
grilled eel over rice512
|
| 22 |
+
deluxe grilled eel over rice1024
|
| 23 |
+
eel full-course2048
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Note that the i-th menu has the price 2^i-1 (1 ≤ i ≤ 12).
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Since Tomya is a pretty girl, she cannot eat a lot.
|
| 30 |
+
So please find the minimum number of menus whose total price is exactly p.
|
| 31 |
+
Note that if she orders the same menu twice, then it is considered as two menus are ordered. (See Explanations for details)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
The first line contains an integer T, the number of test cases.
|
| 37 |
+
Then T test cases follow.
|
| 38 |
+
Each test case contains an integer p.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
For each test case, print the minimum number of menus whose total price is exactly p.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Constraints
|
| 47 |
+
|
| 48 |
+
1 ≤ T ≤ 5
|
| 49 |
+
1 ≤ p ≤ 100000 (10^5)
|
| 50 |
+
There exists combinations of menus whose total price is exactly p.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Sample Input
|
| 54 |
+
4
|
| 55 |
+
10
|
| 56 |
+
256
|
| 57 |
+
255
|
| 58 |
+
4096
|
| 59 |
+
|
| 60 |
+
Sample Output
|
| 61 |
+
2
|
| 62 |
+
1
|
| 63 |
+
8
|
| 64 |
+
2
|
| 65 |
+
|
| 66 |
+
Explanations
|
| 67 |
+
|
| 68 |
+
In the first sample, examples of the menus whose total price is 10 are the following:
|
| 69 |
+
1+1+1+1+1+1+1+1+1+1 = 10 (10 menus)
|
| 70 |
+
1+1+1+1+1+1+1+1+2 = 10 (9 menus)
|
| 71 |
+
2+2+2+2+2 = 10 (5 menus)
|
| 72 |
+
2+4+4 = 10 (3 menus)
|
| 73 |
+
2+8 = 10 (2 menus)
|
| 74 |
+
Here the minimum number of menus is 2.
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
In the last sample, the optimal way is 2048+2048=4096 (2 menus).
|
| 78 |
+
Note that there is no menu whose price is 4096.
|
| 79 |
+
|
| 80 |
+
## Contest Information
|
| 81 |
+
- **Contest ID**: 0
|
| 82 |
+
- **Problem Index**:
|
| 83 |
+
- **Points**: 0.0
|
| 84 |
+
- **Rating**: 0
|
| 85 |
+
- **Tags**: None
|
| 86 |
+
- **Time Limit**: None seconds
|
| 87 |
+
- **Memory Limit**: 0 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-0736/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1031_B. Curiosity Has No Limits
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
When Masha came to math classes today, she saw two integer sequences of length n - 1 on the blackboard. Let's denote the elements of the first sequence as a_i (0 ≤ a_i ≤ 3), and the elements of the second sequence as b_i (0 ≤ b_i ≤ 3).
|
| 5 |
+
|
| 6 |
+
Masha became interested if or not there is an integer sequence of length n, which elements we will denote as t_i (0 ≤ t_i ≤ 3), so that for every i (1 ≤ i ≤ n - 1) the following is true:
|
| 7 |
+
|
| 8 |
+
* a_i = t_i | t_{i + 1} (where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and
|
| 9 |
+
* b_i = t_i \& t_{i + 1} (where \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND)).
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence t_i of length n exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
The first line contains a single integer n (2 ≤ n ≤ 10^5) — the length of the sequence t_i.
|
| 18 |
+
|
| 19 |
+
The second line contains n - 1 integers a_1, a_2, …, a_{n-1} (0 ≤ a_i ≤ 3) — the first sequence on the blackboard.
|
| 20 |
+
|
| 21 |
+
The third line contains n - 1 integers b_1, b_2, …, b_{n-1} (0 ≤ b_i ≤ 3) — the second sequence on the blackboard.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
In the first line print "YES" (without quotes), if there is a sequence t_i that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.
|
| 26 |
+
|
| 27 |
+
If there is such a sequence, on the second line print n integers t_1, t_2, …, t_n (0 ≤ t_i ≤ 3) — the sequence that satisfies the statements conditions.
|
| 28 |
+
|
| 29 |
+
If there are multiple answers, print any of them.
|
| 30 |
+
|
| 31 |
+
Examples
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
4
|
| 36 |
+
3 3 2
|
| 37 |
+
1 2 0
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
YES
|
| 43 |
+
1 3 2 0
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
3
|
| 48 |
+
1 3
|
| 49 |
+
3 2
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
NO
|
| 55 |
+
|
| 56 |
+
Note
|
| 57 |
+
|
| 58 |
+
In the first example it's easy to see that the sequence from output satisfies the given conditions:
|
| 59 |
+
|
| 60 |
+
* t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
|
| 61 |
+
* t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
|
| 62 |
+
* t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
In the second example there is no such sequence.
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 1031
|
| 70 |
+
- **Problem Index**: B
|
| 71 |
+
- **Points**: 1000.0
|
| 72 |
+
- **Rating**: 1500
|
| 73 |
+
- **Tags**: None
|
| 74 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 75 |
+
- **Memory Limit**: 256000000 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-0737/instruction.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1054_B. Appending Mex
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Initially Ildar has an empty array. He performs n steps. On each step he takes a subset of integers already added to the array and appends the mex of this subset to the array.
|
| 5 |
+
|
| 6 |
+
The mex of an multiset of integers is the smallest non-negative integer not presented in the multiset. For example, the mex of the multiset [0, 2, 3] is 1, while the mex of the multiset [1, 2, 1] is 0.
|
| 7 |
+
|
| 8 |
+
More formally, on the step m, when Ildar already has an array a_1, a_2, …, a_{m-1}, he chooses some subset of indices 1 ≤ i_1 < i_2 < … < i_k < m (possibly, empty), where 0 ≤ k < m, and appends the mex(a_{i_1}, a_{i_2}, … a_{i_k}) to the end of the array.
|
| 9 |
+
|
| 10 |
+
After performing all the steps Ildar thinks that he might have made a mistake somewhere. He asks you to determine for a given array a_1, a_2, …, a_n the minimum step t such that he has definitely made a mistake on at least one of the steps 1, 2, …, t, or determine that he could have obtained this array without mistakes.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the number of steps Ildar made.
|
| 15 |
+
|
| 16 |
+
The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — the array Ildar obtained.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
If Ildar could have chosen the subsets on each step in such a way that the resulting array is a_1, a_2, …, a_n, print -1.
|
| 21 |
+
|
| 22 |
+
Otherwise print a single integer t — the smallest index of a step such that a mistake was made on at least one step among steps 1, 2, …, t.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
4
|
| 29 |
+
0 1 2 1
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
-1
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
3
|
| 39 |
+
1 0 1
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
1
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
4
|
| 49 |
+
0 1 2 239
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
4
|
| 55 |
+
|
| 56 |
+
Note
|
| 57 |
+
|
| 58 |
+
In the first example it is possible that Ildar made no mistakes. Here is the process he could have followed.
|
| 59 |
+
|
| 60 |
+
* 1-st step. The initial array is empty. He can choose an empty subset and obtain 0, because the mex of an empty set is 0. Appending this value to the end he gets the array [0].
|
| 61 |
+
* 2-nd step. The current array is [0]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1].
|
| 62 |
+
* 3-rd step. The current array is [0,1]. He can choose a subset [0,1] and obtain an integer 2, because mex(0,1) = 2. Appending this value to the end he gets the array [0,1,2].
|
| 63 |
+
* 4-th step. The current array is [0,1,2]. He can choose a subset [0] and obtain an integer 1, because mex(0) = 1. Appending this value to the end he gets the array [0,1,2,1].
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Thus, he can get the array without mistakes, so the answer is -1.
|
| 68 |
+
|
| 69 |
+
In the second example he has definitely made a mistake on the very first step, because he could not have obtained anything different from 0.
|
| 70 |
+
|
| 71 |
+
In the third example he could have obtained [0, 1, 2] without mistakes, but 239 is definitely wrong.
|
| 72 |
+
|
| 73 |
+
## Contest Information
|
| 74 |
+
- **Contest ID**: 1054
|
| 75 |
+
- **Problem Index**: B
|
| 76 |
+
- **Points**: 750.0
|
| 77 |
+
- **Rating**: 1000
|
| 78 |
+
- **Tags**: implementation
|
| 79 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 80 |
+
- **Memory Limit**: 256000000 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-0738/instruction.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1076_B. Divisor Subtraction
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an integer number n. The following algorithm is applied to it:
|
| 5 |
+
|
| 6 |
+
1. if n = 0, then end algorithm;
|
| 7 |
+
2. find the smallest prime divisor d of n;
|
| 8 |
+
3. subtract d from n and go to step 1.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Determine the number of subtrations the algorithm will make.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The only line contains a single integer n (2 ≤ n ≤ 10^{10}).
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print a single integer — the number of subtractions the algorithm will make.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
5
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
1
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
4
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
2
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.
|
| 50 |
+
|
| 51 |
+
In the second example 2 is the smallest prime divisor at both steps.
|
| 52 |
+
|
| 53 |
+
## Contest Information
|
| 54 |
+
- **Contest ID**: 1076
|
| 55 |
+
- **Problem Index**: B
|
| 56 |
+
- **Points**: 0.0
|
| 57 |
+
- **Rating**: 1200
|
| 58 |
+
- **Tags**: implementation, math, number theory
|
| 59 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 60 |
+
- **Memory Limit**: 256000000 bytes
|
| 61 |
+
|
| 62 |
+
## Task
|
| 63 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0752/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 136_B. Ternary Logic
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).
|
| 5 |
+
|
| 6 |
+
It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010 = 01123 tor 12123 = 10213 = 3410.
|
| 7 |
+
|
| 8 |
+
Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b = c. If there are several such numbers, print the smallest one.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two integers a and c (0 ≤ a, c ≤ 109). Both numbers are written in decimal notation.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print the single integer b, such that a tor b = c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
14 34
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
50
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
50 34
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
14
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
387420489 225159023
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
1000000001
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
5 5
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
0
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 136
|
| 61 |
+
- **Problem Index**: B
|
| 62 |
+
- **Points**: 1000.0
|
| 63 |
+
- **Rating**: 1100
|
| 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-0754/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1416_D. Graph and Queries
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an undirected graph consisting of n vertices and m edges. Initially there is a single integer written on every vertex: the vertex i has p_i written on it. All p_i are distinct integers from 1 to n.
|
| 5 |
+
|
| 6 |
+
You have to process q queries of two types:
|
| 7 |
+
|
| 8 |
+
* 1 v — among all vertices reachable from the vertex v using the edges of the graph (including the vertex v itself), find a vertex u with the largest number p_u written on it, print p_u and replace p_u with 0;
|
| 9 |
+
* 2 i — delete the i-th edge from the graph.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Note that, in a query of the first type, it is possible that all vertices reachable from v have 0 written on them. In this case, u is not explicitly defined, but since the selection of u does not affect anything, you can choose any vertex reachable from v and print its value (which is 0).
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
The first line contains three integers n, m and q (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ m ≤ 3 ⋅ 10^5; 1 ≤ q ≤ 5 ⋅ 10^5).
|
| 18 |
+
|
| 19 |
+
The second line contains n distinct integers p_1, p_2, ..., p_n, where p_i is the number initially written on vertex i (1 ≤ p_i ≤ n).
|
| 20 |
+
|
| 21 |
+
Then m lines follow, the i-th of them contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) and means that the i-th edge connects vertices a_i and b_i. It is guaranteed that the graph does not contain multi-edges.
|
| 22 |
+
|
| 23 |
+
Then q lines follow, which describe the queries. Each line is given by one of the following formats:
|
| 24 |
+
|
| 25 |
+
* 1 v — denotes a query of the first type with a vertex v (1 ≤ v ≤ n).
|
| 26 |
+
* 2 i — denotes a query of the second type with an edge i (1 ≤ i ≤ m). For each query of the second type, it is guaranteed that the corresponding edge is not deleted from the graph yet.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
For every query of the first type, print the value of p_u written on the chosen vertex u.
|
| 31 |
+
|
| 32 |
+
Example
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
5 4 6
|
| 38 |
+
1 2 5 4 3
|
| 39 |
+
1 2
|
| 40 |
+
2 3
|
| 41 |
+
1 3
|
| 42 |
+
4 5
|
| 43 |
+
1 1
|
| 44 |
+
2 1
|
| 45 |
+
2 3
|
| 46 |
+
1 1
|
| 47 |
+
1 2
|
| 48 |
+
1 2
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
5
|
| 55 |
+
1
|
| 56 |
+
2
|
| 57 |
+
0
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 1416
|
| 61 |
+
- **Problem Index**: D
|
| 62 |
+
- **Points**: 2000.0
|
| 63 |
+
- **Rating**: 2600
|
| 64 |
+
- **Tags**: data structures, dsu, graphs, implementation, trees
|
| 65 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 500000000} 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-0755/instruction.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1433_C. Dominant Piranha
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.
|
| 5 |
+
|
| 6 |
+
Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.
|
| 7 |
+
|
| 8 |
+
Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:
|
| 9 |
+
|
| 10 |
+
* The piranha i can eat the piranha i-1 if the piranha i-1 exists and a_{i - 1} < a_i.
|
| 11 |
+
* The piranha i can eat the piranha i+1 if the piranha i+1 exists and a_{i + 1} < a_i.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
When the piranha i eats some piranha, its size increases by one (a_i becomes a_i + 1).
|
| 16 |
+
|
| 17 |
+
Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.
|
| 18 |
+
|
| 19 |
+
Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.
|
| 20 |
+
|
| 21 |
+
For example, if a = [5, 3, 4, 4, 5], then the third piranha can be dominant. Consider the sequence of its moves:
|
| 22 |
+
|
| 23 |
+
* The piranha eats the second piranha and a becomes [5, \underline{5}, 4, 5] (the underlined piranha is our candidate).
|
| 24 |
+
* The piranha eats the third piranha and a becomes [5, \underline{6}, 5].
|
| 25 |
+
* The piranha eats the first piranha and a becomes [\underline{7}, 5].
|
| 26 |
+
* The piranha eats the second piranha and a becomes [\underline{8}].
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
You have to answer t independent test cases.
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
|
| 35 |
+
|
| 36 |
+
The first line of the test case contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of piranhas in the aquarium. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9), where a_i is the size of the i-th piranha.
|
| 37 |
+
|
| 38 |
+
It is guaranteed that the sum of n does not exceed 3 ⋅ 10^5 (∑ n ≤ 3 ⋅ 10^5).
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.
|
| 43 |
+
|
| 44 |
+
Example
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
6
|
| 50 |
+
5
|
| 51 |
+
5 3 4 4 5
|
| 52 |
+
3
|
| 53 |
+
1 1 1
|
| 54 |
+
5
|
| 55 |
+
4 4 3 4 4
|
| 56 |
+
5
|
| 57 |
+
5 5 4 3 2
|
| 58 |
+
3
|
| 59 |
+
1 1 2
|
| 60 |
+
5
|
| 61 |
+
5 4 3 5 5
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Output
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
3
|
| 68 |
+
-1
|
| 69 |
+
4
|
| 70 |
+
3
|
| 71 |
+
3
|
| 72 |
+
1
|
| 73 |
+
|
| 74 |
+
Note
|
| 75 |
+
|
| 76 |
+
The first test case of the example is described in the problem statement.
|
| 77 |
+
|
| 78 |
+
In the second test case of the example, there are no dominant piranhas in the aquarium.
|
| 79 |
+
|
| 80 |
+
In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes [4, 4, 5, 4], then it can eat any other piranha in the aquarium.
|
| 81 |
+
|
| 82 |
+
## Contest Information
|
| 83 |
+
- **Contest ID**: 1433
|
| 84 |
+
- **Problem Index**: C
|
| 85 |
+
- **Points**: 0.0
|
| 86 |
+
- **Rating**: 900
|
| 87 |
+
- **Tags**: constructive algorithms, greedy
|
| 88 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 89 |
+
- **Memory Limit**: 256000000 bytes
|
| 90 |
+
|
| 91 |
+
## Task
|
| 92 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|