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-0002/instruction.md +54 -0
- code_contests-0005/instruction.md +40 -0
- code_contests-0033/instruction.md +41 -0
- code_contests-0034/instruction.md +100 -0
- code_contests-0051/instruction.md +85 -0
- code_contests-0056/instruction.md +128 -0
- code_contests-0060/instruction.md +65 -0
- code_contests-0067/instruction.md +36 -0
- code_contests-0093/instruction.md +26 -0
- code_contests-0094/instruction.md +164 -0
- code_contests-0112/instruction.md +72 -0
- code_contests-0147/instruction.md +59 -0
- code_contests-0148/instruction.md +56 -0
- code_contests-0170/instruction.md +78 -0
- code_contests-0177/instruction.md +51 -0
- code_contests-0183/instruction.md +88 -0
- code_contests-0184/instruction.md +112 -0
- code_contests-0206/instruction.md +73 -0
- code_contests-0208/instruction.md +42 -0
- code_contests-0230/instruction.md +50 -0
- code_contests-0237/instruction.md +69 -0
- code_contests-0239/instruction.md +67 -0
- code_contests-0255/instruction.md +89 -0
- code_contests-0263/instruction.md +74 -0
- code_contests-0264/instruction.md +91 -0
- code_contests-0297/instruction.md +70 -0
- code_contests-0299/instruction.md +71 -0
- code_contests-0320/instruction.md +84 -0
- code_contests-0327/instruction.md +76 -0
- code_contests-0345/instruction.md +82 -0
- code_contests-0373/instruction.md +91 -0
- code_contests-0375/instruction.md +57 -0
- code_contests-0381/instruction.md +50 -0
- code_contests-0389/instruction.md +76 -0
- code_contests-0403/instruction.md +58 -0
- code_contests-0404/instruction.md +72 -0
- code_contests-0432/instruction.md +93 -0
- code_contests-0459/instruction.md +96 -0
- code_contests-0466/instruction.md +61 -0
- code_contests-0495/instruction.md +70 -0
- code_contests-0514/instruction.md +87 -0
- code_contests-0525/instruction.md +46 -0
- code_contests-0576/instruction.md +71 -0
- code_contests-0582/instruction.md +53 -0
- code_contests-0600/instruction.md +91 -0
- code_contests-0607/instruction.md +138 -0
- code_contests-0609/instruction.md +142 -0
- code_contests-0631/instruction.md +67 -0
- code_contests-0653/instruction.md +71 -0
- code_contests-0662/instruction.md +54 -0
code_contests-0002/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# gcd2
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD
|
| 5 |
+
of two numbers. Then Felman implements it algorithm
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
int gcd(int a, int b)
|
| 9 |
+
{
|
| 10 |
+
if (b==0)
|
| 11 |
+
return a;
|
| 12 |
+
else
|
| 13 |
+
return gcd(b,a%b);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
and it proposes to Frank that makes it
|
| 17 |
+
but with a little integer and another integer that has up to 250 digits.
|
| 18 |
+
Your task is to help Frank programming an efficient code for the challenge of Felman.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
The first line of the input file contains a number representing the number of lines to follow.
|
| 24 |
+
Each line consists of two number A and B (0 ≤ A ≤ 40000 and A ≤ B < 10^250).
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
Print for each pair (A,B) in the input one integer representing the GCD of A and B.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Example
|
| 33 |
+
|
| 34 |
+
Input:
|
| 35 |
+
2
|
| 36 |
+
2 6
|
| 37 |
+
10 11
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output:
|
| 41 |
+
2
|
| 42 |
+
1
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 0
|
| 46 |
+
- **Problem Index**:
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 0
|
| 49 |
+
- **Tags**: None
|
| 50 |
+
- **Time Limit**: None seconds
|
| 51 |
+
- **Memory Limit**: 0 bytes
|
| 52 |
+
|
| 53 |
+
## Task
|
| 54 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0005/instruction.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tf01
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K.
|
| 5 |
+
You are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K.
|
| 6 |
+
|
| 7 |
+
Input
|
| 8 |
+
First line of input contains T, the number of test cases. T test cases follow.
|
| 9 |
+
Each test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000).
|
| 10 |
+
0 < T < 1000
|
| 11 |
+
0 < N < 1000
|
| 12 |
+
0 < K < 1000
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
Output T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not.
|
| 16 |
+
|
| 17 |
+
Example
|
| 18 |
+
|
| 19 |
+
Input:
|
| 20 |
+
2
|
| 21 |
+
5 10
|
| 22 |
+
3 4 6 1 9
|
| 23 |
+
3 2
|
| 24 |
+
1 3 4
|
| 25 |
+
|
| 26 |
+
Output:
|
| 27 |
+
1
|
| 28 |
+
0
|
| 29 |
+
|
| 30 |
+
## Contest Information
|
| 31 |
+
- **Contest ID**: 0
|
| 32 |
+
- **Problem Index**:
|
| 33 |
+
- **Points**: 0.0
|
| 34 |
+
- **Rating**: 0
|
| 35 |
+
- **Tags**: None
|
| 36 |
+
- **Time Limit**: None seconds
|
| 37 |
+
- **Memory Limit**: 0 bytes
|
| 38 |
+
|
| 39 |
+
## Task
|
| 40 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0033/instruction.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 20_B. Equation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an equation:
|
| 5 |
+
|
| 6 |
+
Ax2 + Bx + C = 0.
|
| 7 |
+
|
| 8 |
+
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
1 -5 6
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
2
|
| 28 |
+
2.0000000000
|
| 29 |
+
3.0000000000
|
| 30 |
+
|
| 31 |
+
## Contest Information
|
| 32 |
+
- **Contest ID**: 20
|
| 33 |
+
- **Problem Index**: B
|
| 34 |
+
- **Points**: 1000.0
|
| 35 |
+
- **Rating**: 2000
|
| 36 |
+
- **Tags**: math
|
| 37 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 38 |
+
- **Memory Limit**: 256000000 bytes
|
| 39 |
+
|
| 40 |
+
## Task
|
| 41 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0034/instruction.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 235_D. Graph Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In computer science, there is a method called "Divide And Conquer By Node" to solve some hard problems about paths on a tree. Let's desribe how this method works by function:
|
| 5 |
+
|
| 6 |
+
solve(t) (t is a tree):
|
| 7 |
+
|
| 8 |
+
1. Chose a node x (it's common to chose weight-center) in tree t. Let's call this step "Line A".
|
| 9 |
+
2. Deal with all paths that pass x.
|
| 10 |
+
3. Then delete x from tree t.
|
| 11 |
+
4. After that t becomes some subtrees.
|
| 12 |
+
5. Apply solve on each subtree.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
This ends when t has only one node because after deleting it, there's nothing.
|
| 17 |
+
|
| 18 |
+
Now, WJMZBMR has mistakenly believed that it's ok to chose any node in "Line A". So he'll chose a node at random. To make the situation worse, he thinks a "tree" should have the same number of edges and nodes! So this procedure becomes like that.
|
| 19 |
+
|
| 20 |
+
Let's define the variable totalCost. Initially the value of totalCost equal to 0. So, solve(t) (now t is a graph):
|
| 21 |
+
|
| 22 |
+
1. totalCost = totalCost + (size of t). The operation "=" means assignment. (Size of t) means the number of nodes in t.
|
| 23 |
+
2. Choose a node x in graph t at random (uniformly among all nodes of t).
|
| 24 |
+
3. Then delete x from graph t.
|
| 25 |
+
4. After that t becomes some connected components.
|
| 26 |
+
5. Apply solve on each component.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
He'll apply solve on a connected graph with n nodes and n edges. He thinks it will work quickly, but it's very slow. So he wants to know the expectation of totalCost of this procedure. Can you help him?
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
The first line contains an integer n (3 ≤ n ≤ 3000) — the number of nodes and edges in the graph. Each of the next n lines contains two space-separated integers ai, bi (0 ≤ ai, bi ≤ n - 1) indicating an edge between nodes ai and bi.
|
| 35 |
+
|
| 36 |
+
Consider that the graph nodes are numbered from 0 to (n - 1). It's guaranteed that there are no self-loops, no multiple edges in that graph. It's guaranteed that the graph is connected.
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
Print a single real number — the expectation of totalCost. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
|
| 41 |
+
|
| 42 |
+
Examples
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
5
|
| 47 |
+
3 4
|
| 48 |
+
2 3
|
| 49 |
+
2 4
|
| 50 |
+
0 4
|
| 51 |
+
1 2
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
13.166666666666666
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
3
|
| 62 |
+
0 1
|
| 63 |
+
1 2
|
| 64 |
+
0 2
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
6.000000000000000
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Input
|
| 73 |
+
|
| 74 |
+
5
|
| 75 |
+
0 1
|
| 76 |
+
1 2
|
| 77 |
+
2 0
|
| 78 |
+
3 0
|
| 79 |
+
4 1
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Output
|
| 83 |
+
|
| 84 |
+
13.166666666666666
|
| 85 |
+
|
| 86 |
+
Note
|
| 87 |
+
|
| 88 |
+
Consider the second example. No matter what we choose first, the totalCost will always be 3 + 2 + 1 = 6.
|
| 89 |
+
|
| 90 |
+
## Contest Information
|
| 91 |
+
- **Contest ID**: 235
|
| 92 |
+
- **Problem Index**: D
|
| 93 |
+
- **Points**: 2000.0
|
| 94 |
+
- **Rating**: 3000
|
| 95 |
+
- **Tags**: graphs
|
| 96 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 97 |
+
- **Memory Limit**: 256000000 bytes
|
| 98 |
+
|
| 99 |
+
## Task
|
| 100 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0051/instruction.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 634_C. Factory Repairs
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.
|
| 5 |
+
|
| 6 |
+
Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
|
| 7 |
+
|
| 8 |
+
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
|
| 13 |
+
|
| 14 |
+
The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:
|
| 15 |
+
|
| 16 |
+
* 1 di ai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or
|
| 17 |
+
* 2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
It's guaranteed that the input will contain at least one query of the second type.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days.
|
| 26 |
+
|
| 27 |
+
Examples
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
5 2 2 1 8
|
| 32 |
+
1 1 2
|
| 33 |
+
1 5 3
|
| 34 |
+
1 2 1
|
| 35 |
+
2 2
|
| 36 |
+
1 4 2
|
| 37 |
+
1 3 2
|
| 38 |
+
2 1
|
| 39 |
+
2 3
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
3
|
| 45 |
+
6
|
| 46 |
+
4
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Input
|
| 50 |
+
|
| 51 |
+
5 4 10 1 6
|
| 52 |
+
1 1 5
|
| 53 |
+
1 5 5
|
| 54 |
+
1 3 2
|
| 55 |
+
1 5 2
|
| 56 |
+
2 1
|
| 57 |
+
2 2
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
7
|
| 63 |
+
1
|
| 64 |
+
|
| 65 |
+
Note
|
| 66 |
+
|
| 67 |
+
Consider the first sample.
|
| 68 |
+
|
| 69 |
+
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
|
| 70 |
+
|
| 71 |
+
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.
|
| 72 |
+
|
| 73 |
+
For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
|
| 74 |
+
|
| 75 |
+
## Contest Information
|
| 76 |
+
- **Contest ID**: 634
|
| 77 |
+
- **Problem Index**: C
|
| 78 |
+
- **Points**: 1000.0
|
| 79 |
+
- **Rating**: 1700
|
| 80 |
+
- **Tags**: data structures
|
| 81 |
+
- **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
|
| 82 |
+
- **Memory Limit**: 256000000 bytes
|
| 83 |
+
|
| 84 |
+
## Task
|
| 85 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0056/instruction.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 754_E. Dasha and cyclic table
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Dasha is fond of challenging puzzles: Rubik's Cube 3 × 3 × 3, 4 × 4 × 4, 5 × 5 × 5 and so on. This time she has a cyclic table of size n × m, and each cell of the table contains a lowercase English letter. Each cell has coordinates (i, j) (0 ≤ i < n, 0 ≤ j < m). The table is cyclic means that to the right of cell (i, j) there is the cell <image>, and to the down there is the cell <image>.
|
| 5 |
+
|
| 6 |
+
Dasha has a pattern as well. A pattern is a non-cyclic table of size r × c. Each cell is either a lowercase English letter or a question mark. Each cell has coordinates (i, j) (0 ≤ i < r, 0 ≤ j < c).
|
| 7 |
+
|
| 8 |
+
The goal of the puzzle is to find all the appearance positions of the pattern in the cyclic table.
|
| 9 |
+
|
| 10 |
+
We say that the cell (i, j) of cyclic table is an appearance position, if for every pair (x, y) such that 0 ≤ x < r and 0 ≤ y < c one of the following conditions holds:
|
| 11 |
+
|
| 12 |
+
* There is a question mark in the cell (x, y) of the pattern, or
|
| 13 |
+
* The cell <image> of the cyclic table equals to the cell (x, y) of the pattern.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Dasha solved this puzzle in no time, as well as all the others she ever tried. Can you solve it?.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line contains two integers n and m (1 ≤ n, m ≤ 400) — the cyclic table sizes.
|
| 22 |
+
|
| 23 |
+
Each of the next n lines contains a string of m lowercase English characters — the description of the cyclic table.
|
| 24 |
+
|
| 25 |
+
The next line contains two integers r and c (1 ≤ r, c ≤ 400) — the sizes of the pattern.
|
| 26 |
+
|
| 27 |
+
Each of the next r lines contains a string of c lowercase English letter and/or characters '?' — the description of the pattern.
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Print n lines. Each of the n lines should contain m characters. Each of the characters should equal '0' or '1'.
|
| 32 |
+
|
| 33 |
+
The j-th character of the i-th (0-indexed) line should be equal to '1', in case the cell (i, j) is an appearance position, otherwise it should be equal to '0'.
|
| 34 |
+
|
| 35 |
+
Examples
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
5 7
|
| 40 |
+
qcezchs
|
| 41 |
+
hhedywq
|
| 42 |
+
wikywqy
|
| 43 |
+
qckrqzt
|
| 44 |
+
bqexcxz
|
| 45 |
+
3 2
|
| 46 |
+
??
|
| 47 |
+
yw
|
| 48 |
+
?q
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
0000100
|
| 54 |
+
0001001
|
| 55 |
+
0000000
|
| 56 |
+
0000000
|
| 57 |
+
0000000
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Input
|
| 61 |
+
|
| 62 |
+
10 10
|
| 63 |
+
fwtoayylhw
|
| 64 |
+
yyaryyjawr
|
| 65 |
+
ywrdzwhscy
|
| 66 |
+
hnsyyxiphn
|
| 67 |
+
bnjwzyyjvo
|
| 68 |
+
kkjgseenwn
|
| 69 |
+
gvmiflpcsy
|
| 70 |
+
lxvkwrobwu
|
| 71 |
+
wyybbcocyy
|
| 72 |
+
yysijsvqry
|
| 73 |
+
2 2
|
| 74 |
+
??
|
| 75 |
+
yy
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
Output
|
| 79 |
+
|
| 80 |
+
1000100000
|
| 81 |
+
0000000001
|
| 82 |
+
0001000000
|
| 83 |
+
0000010000
|
| 84 |
+
0000000000
|
| 85 |
+
0000000000
|
| 86 |
+
0000000000
|
| 87 |
+
0100000010
|
| 88 |
+
1000000001
|
| 89 |
+
0000010000
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
Input
|
| 93 |
+
|
| 94 |
+
8 6
|
| 95 |
+
ibrgxl
|
| 96 |
+
xqdcsg
|
| 97 |
+
okbcgi
|
| 98 |
+
tvpetc
|
| 99 |
+
xgxxig
|
| 100 |
+
igghzo
|
| 101 |
+
lmlaza
|
| 102 |
+
gpswzv
|
| 103 |
+
1 4
|
| 104 |
+
gx??
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
Output
|
| 108 |
+
|
| 109 |
+
000100
|
| 110 |
+
000001
|
| 111 |
+
000000
|
| 112 |
+
000000
|
| 113 |
+
010001
|
| 114 |
+
000000
|
| 115 |
+
000000
|
| 116 |
+
000000
|
| 117 |
+
|
| 118 |
+
## Contest Information
|
| 119 |
+
- **Contest ID**: 754
|
| 120 |
+
- **Problem Index**: E
|
| 121 |
+
- **Points**: 2500.0
|
| 122 |
+
- **Rating**: 2600
|
| 123 |
+
- **Tags**: bitmasks, brute force, fft, strings, trees
|
| 124 |
+
- **Time Limit**: {'seconds': 6, 'nanos': 0} seconds
|
| 125 |
+
- **Memory Limit**: 512000000 bytes
|
| 126 |
+
|
| 127 |
+
## Task
|
| 128 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0060/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 846_E. Chemistry in Berland
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
|
| 5 |
+
|
| 6 |
+
Fortunately, chemical laws allow material transformations (yes, chemistry in Berland differs from ours). But the rules of transformation are a bit strange.
|
| 7 |
+
|
| 8 |
+
Berland chemists are aware of n materials, numbered in the order they were discovered. Each material can be transformed into some other material (or vice versa). Formally, for each i (2 ≤ i ≤ n) there exist two numbers xi and ki that denote a possible transformation: ki kilograms of material xi can be transformed into 1 kilogram of material i, and 1 kilogram of material i can be transformed into 1 kilogram of material xi. Chemical processing equipment in BerSU allows only such transformation that the amount of resulting material is always an integer number of kilograms.
|
| 9 |
+
|
| 10 |
+
For each i (1 ≤ i ≤ n) Igor knows that the experiment requires ai kilograms of material i, and the laboratory contains bi kilograms of this material. Is it possible to conduct an experiment after transforming some materials (or none)?
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains one integer number n (1 ≤ n ≤ 105) — the number of materials discovered by Berland chemists.
|
| 15 |
+
|
| 16 |
+
The second line contains n integer numbers b1, b2... bn (1 ≤ bi ≤ 1012) — supplies of BerSU laboratory.
|
| 17 |
+
|
| 18 |
+
The third line contains n integer numbers a1, a2... an (1 ≤ ai ≤ 1012) — the amounts required for the experiment.
|
| 19 |
+
|
| 20 |
+
Then n - 1 lines follow. j-th of them contains two numbers xj + 1 and kj + 1 that denote transformation of (j + 1)-th material (1 ≤ xj + 1 ≤ j, 1 ≤ kj + 1 ≤ 109).
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print YES if it is possible to conduct an experiment. Otherwise print NO.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
3
|
| 31 |
+
1 2 3
|
| 32 |
+
3 2 1
|
| 33 |
+
1 1
|
| 34 |
+
1 1
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
YES
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
3
|
| 45 |
+
3 2 1
|
| 46 |
+
1 2 3
|
| 47 |
+
1 1
|
| 48 |
+
1 2
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
NO
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 846
|
| 57 |
+
- **Problem Index**: E
|
| 58 |
+
- **Points**: 0.0
|
| 59 |
+
- **Rating**: 2300
|
| 60 |
+
- **Tags**: dfs and similar, greedy, trees
|
| 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-0067/instruction.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# appu-and-sugarcane-farm
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
As you know Appu created aversion to Maths after that maths problem given by his teacher.So he stopped studying and began to do farming. He has some land where he starts growing sugarcane. At the end of the season he grew N sugarcanes. Is Appu satisfied??. No,
|
| 5 |
+
He wants all his sugar canes to be of the same height. He goes to the nearby market .He finds a powder which when applied to one of his sugarcanes will double the height of that sugar cane. Now he needs to find out whether is it possible to make all the sugarcanes of the same height . Oh No!! Again maths.
|
| 6 |
+
Please help him to find whether is it possible make all the sugar cane of the same height?
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
First line contains N - the number of sugarcanes.Next N lines contains heights of sugarcanes seperated by space
|
| 10 |
+
|
| 11 |
+
Output
|
| 12 |
+
Print "YES" if it is possible make all the sugar cane of the same height or
|
| 13 |
+
"NO" otherwise (quotes only for clarity)
|
| 14 |
+
|
| 15 |
+
Constraints
|
| 16 |
+
1 ≤ N ≤ 50
|
| 17 |
+
Initial Height of all sugarcanes will be between 1 and 1,000,000,000, inclusive.
|
| 18 |
+
|
| 19 |
+
SAMPLE INPUT
|
| 20 |
+
2
|
| 21 |
+
1 23
|
| 22 |
+
|
| 23 |
+
SAMPLE OUTPUT
|
| 24 |
+
NO
|
| 25 |
+
|
| 26 |
+
## Contest Information
|
| 27 |
+
- **Contest ID**: 0
|
| 28 |
+
- **Problem Index**:
|
| 29 |
+
- **Points**: 0.0
|
| 30 |
+
- **Rating**: 0
|
| 31 |
+
- **Tags**: None
|
| 32 |
+
- **Time Limit**: None seconds
|
| 33 |
+
- **Memory Limit**: 0 bytes
|
| 34 |
+
|
| 35 |
+
## Task
|
| 36 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0093/instruction.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00953 Animal Companion in Maze
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Example
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
2 1
|
| 9 |
+
1 2 2
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
1
|
| 15 |
+
|
| 16 |
+
## Contest Information
|
| 17 |
+
- **Contest ID**: 0
|
| 18 |
+
- **Problem Index**:
|
| 19 |
+
- **Points**: 0.0
|
| 20 |
+
- **Rating**: 0
|
| 21 |
+
- **Tags**:
|
| 22 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 23 |
+
- **Memory Limit**: 268435456 bytes
|
| 24 |
+
|
| 25 |
+
## Task
|
| 26 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0094/instruction.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01086 Short Phrase
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Short Phrase
|
| 5 |
+
|
| 6 |
+
A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition:
|
| 7 |
+
|
| 8 |
+
> (The Condition for a Short Phrase)
|
| 9 |
+
> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively.
|
| 10 |
+
|
| 11 |
+
The following is an example of a Short Phrase.
|
| 12 |
+
|
| 13 |
+
>
|
| 14 |
+
> do the best
|
| 15 |
+
> and enjoy today
|
| 16 |
+
> at acm icpc
|
| 17 |
+
>
|
| 18 |
+
|
| 19 |
+
In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase.
|
| 20 |
+
|
| 21 |
+
Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix.
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
The input consists of multiple datasets, each in the following format.
|
| 26 |
+
|
| 27 |
+
> n
|
| 28 |
+
> w1
|
| 29 |
+
> ...
|
| 30 |
+
> wn
|
| 31 |
+
>
|
| 32 |
+
|
| 33 |
+
Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase.
|
| 34 |
+
|
| 35 |
+
The end of the input is indicated by a line with a single zero.
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one.
|
| 40 |
+
|
| 41 |
+
Sample Input
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
9
|
| 45 |
+
do
|
| 46 |
+
the
|
| 47 |
+
best
|
| 48 |
+
and
|
| 49 |
+
enjoy
|
| 50 |
+
today
|
| 51 |
+
at
|
| 52 |
+
acm
|
| 53 |
+
icpc
|
| 54 |
+
14
|
| 55 |
+
oh
|
| 56 |
+
yes
|
| 57 |
+
by
|
| 58 |
+
far
|
| 59 |
+
it
|
| 60 |
+
is
|
| 61 |
+
wow
|
| 62 |
+
so
|
| 63 |
+
bad
|
| 64 |
+
to
|
| 65 |
+
me
|
| 66 |
+
you
|
| 67 |
+
know
|
| 68 |
+
hey
|
| 69 |
+
15
|
| 70 |
+
abcde
|
| 71 |
+
fghijkl
|
| 72 |
+
mnopq
|
| 73 |
+
rstuvwx
|
| 74 |
+
yzz
|
| 75 |
+
abcde
|
| 76 |
+
fghijkl
|
| 77 |
+
mnopq
|
| 78 |
+
rstuvwx
|
| 79 |
+
yz
|
| 80 |
+
abcde
|
| 81 |
+
fghijkl
|
| 82 |
+
mnopq
|
| 83 |
+
rstuvwx
|
| 84 |
+
yz
|
| 85 |
+
0
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Output for the Sample Input
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
1
|
| 92 |
+
2
|
| 93 |
+
6
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
Example
|
| 101 |
+
|
| 102 |
+
Input
|
| 103 |
+
|
| 104 |
+
9
|
| 105 |
+
do
|
| 106 |
+
the
|
| 107 |
+
best
|
| 108 |
+
and
|
| 109 |
+
enjoy
|
| 110 |
+
today
|
| 111 |
+
at
|
| 112 |
+
acm
|
| 113 |
+
icpc
|
| 114 |
+
14
|
| 115 |
+
oh
|
| 116 |
+
yes
|
| 117 |
+
by
|
| 118 |
+
far
|
| 119 |
+
it
|
| 120 |
+
is
|
| 121 |
+
wow
|
| 122 |
+
so
|
| 123 |
+
bad
|
| 124 |
+
to
|
| 125 |
+
me
|
| 126 |
+
you
|
| 127 |
+
know
|
| 128 |
+
hey
|
| 129 |
+
15
|
| 130 |
+
abcde
|
| 131 |
+
fghijkl
|
| 132 |
+
mnopq
|
| 133 |
+
rstuvwx
|
| 134 |
+
yzz
|
| 135 |
+
abcde
|
| 136 |
+
fghijkl
|
| 137 |
+
mnopq
|
| 138 |
+
rstuvwx
|
| 139 |
+
yz
|
| 140 |
+
abcde
|
| 141 |
+
fghijkl
|
| 142 |
+
mnopq
|
| 143 |
+
rstuvwx
|
| 144 |
+
yz
|
| 145 |
+
0
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
Output
|
| 149 |
+
|
| 150 |
+
1
|
| 151 |
+
2
|
| 152 |
+
6
|
| 153 |
+
|
| 154 |
+
## Contest Information
|
| 155 |
+
- **Contest ID**: 0
|
| 156 |
+
- **Problem Index**:
|
| 157 |
+
- **Points**: 0.0
|
| 158 |
+
- **Rating**: 0
|
| 159 |
+
- **Tags**:
|
| 160 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 161 |
+
- **Memory Limit**: 268435456 bytes
|
| 162 |
+
|
| 163 |
+
## Task
|
| 164 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0112/instruction.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1065_F. Up and Down the Tree
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a tree with n vertices; its root is vertex 1. Also there is a token, initially placed in the root. You can move the token to other vertices. Let's assume current vertex of token is v, then you make any of the following two possible moves:
|
| 5 |
+
|
| 6 |
+
* move down to any leaf in subtree of v;
|
| 7 |
+
* if vertex v is a leaf, then move up to the parent no more than k times. In other words, if h(v) is the depth of vertex v (the depth of the root is 0), then you can move to vertex to such that to is an ancestor of v and h(v) - k ≤ h(to).
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
Consider that root is not a leaf (even if its degree is 1). Calculate the maximum number of different leaves you can visit during one sequence of moves.
|
| 12 |
+
|
| 13 |
+
Input
|
| 14 |
+
|
| 15 |
+
The first line contains two integers n and k (1 ≤ k < n ≤ 10^6) — the number of vertices in the tree and the restriction on moving up, respectively.
|
| 16 |
+
|
| 17 |
+
The second line contains n - 1 integers p_2, p_3, ..., p_n, where p_i is the parent of vertex i.
|
| 18 |
+
|
| 19 |
+
It is guaranteed that the input represents a valid tree, rooted at 1.
|
| 20 |
+
|
| 21 |
+
Output
|
| 22 |
+
|
| 23 |
+
Print one integer — the maximum possible number of different leaves you can visit.
|
| 24 |
+
|
| 25 |
+
Examples
|
| 26 |
+
|
| 27 |
+
Input
|
| 28 |
+
|
| 29 |
+
7 1
|
| 30 |
+
1 1 3 3 4 4
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
4
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
8 2
|
| 41 |
+
1 1 2 3 4 5 5
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
2
|
| 47 |
+
|
| 48 |
+
Note
|
| 49 |
+
|
| 50 |
+
The graph from the first example:
|
| 51 |
+
|
| 52 |
+
<image>
|
| 53 |
+
|
| 54 |
+
One of the optimal ways is the next one: 1 → 2 → 1 → 5 → 3 → 7 → 4 → 6.
|
| 55 |
+
|
| 56 |
+
The graph from the second example:
|
| 57 |
+
|
| 58 |
+
<image>
|
| 59 |
+
|
| 60 |
+
One of the optimal ways is the next one: 1 → 7 → 5 → 8. Note that there is no way to move from 6 to 7 or 8 and vice versa.
|
| 61 |
+
|
| 62 |
+
## Contest Information
|
| 63 |
+
- **Contest ID**: 1065
|
| 64 |
+
- **Problem Index**: F
|
| 65 |
+
- **Points**: 0.0
|
| 66 |
+
- **Rating**: 2500
|
| 67 |
+
- **Tags**: dfs and similar, dp, trees
|
| 68 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 69 |
+
- **Memory Limit**: 256000000 bytes
|
| 70 |
+
|
| 71 |
+
## Task
|
| 72 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0147/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 455_C. Civilization
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Andrew plays a game called "Civilization". Dima helps him.
|
| 5 |
+
|
| 6 |
+
The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.
|
| 7 |
+
|
| 8 |
+
During the game events of two types take place:
|
| 9 |
+
|
| 10 |
+
1. Andrew asks Dima about the length of the longest path in the region where city x lies.
|
| 11 |
+
2. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m < n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.
|
| 20 |
+
|
| 21 |
+
Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities.
|
| 22 |
+
|
| 23 |
+
Each of the following q lines contains one of the two events in the following format:
|
| 24 |
+
|
| 25 |
+
* 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n).
|
| 26 |
+
* 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
For each event of the first type print the answer on a separate line.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
6 0 6
|
| 37 |
+
2 1 2
|
| 38 |
+
2 3 4
|
| 39 |
+
2 5 6
|
| 40 |
+
2 3 2
|
| 41 |
+
2 5 3
|
| 42 |
+
1 1
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
4
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 455
|
| 51 |
+
- **Problem Index**: C
|
| 52 |
+
- **Points**: 1500.0
|
| 53 |
+
- **Rating**: 2100
|
| 54 |
+
- **Tags**: dfs and similar, dp, dsu, ternary search, trees
|
| 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-0148/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 478_A. Initial Bet
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
|
| 5 |
+
|
| 6 |
+
Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value of b, then print the only value "-1" (quotes for clarity).
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
2 5 4 0 4
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
3
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
4 5 9 2 1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
-1
|
| 36 |
+
|
| 37 |
+
Note
|
| 38 |
+
|
| 39 |
+
In the first sample the following sequence of operations is possible:
|
| 40 |
+
|
| 41 |
+
1. One coin is passed from the fourth player to the second player;
|
| 42 |
+
2. One coin is passed from the fourth player to the fifth player;
|
| 43 |
+
3. One coin is passed from the first player to the third player;
|
| 44 |
+
4. One coin is passed from the fourth player to the second player.
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 478
|
| 48 |
+
- **Problem Index**: A
|
| 49 |
+
- **Points**: 500.0
|
| 50 |
+
- **Rating**: 1100
|
| 51 |
+
- **Tags**: implementation
|
| 52 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 53 |
+
- **Memory Limit**: 256000000 bytes
|
| 54 |
+
|
| 55 |
+
## Task
|
| 56 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0170/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 996_F. Game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a move. A move consists of picking an i such that x_i = -1 and either setting x_i → 0 or x_i → 1.
|
| 5 |
+
|
| 6 |
+
After n rounds all variables are set, and the game value resolves to f(x_1, x_2, ..., x_n). Allen wants to maximize the game value, and Bessie wants to minimize it.
|
| 7 |
+
|
| 8 |
+
Your goal is to help Allen and Bessie find the expected game value! They will play r+1 times though, so between each game, exactly one value of f changes. In other words, between rounds i and i+1 for 1 ≤ i ≤ r, f(z_1, ..., z_n) → g_i for some (z_1, ..., z_n) ∈ \{0, 1\}^n. You are to find the expected game value in the beginning and after each change.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two integers n and r (1 ≤ n ≤ 18, 0 ≤ r ≤ 2^{18}).
|
| 13 |
+
|
| 14 |
+
The next line contains 2^n integers c_0, c_1, ..., c_{2^n-1} (0 ≤ c_i ≤ 10^9), denoting the initial values of f. More specifically, f(x_0, x_1, ..., x_{n-1}) = c_x, if x = \overline{x_{n-1} … x_0} in binary.
|
| 15 |
+
|
| 16 |
+
Each of the next r lines contains two integers z and g (0 ≤ z ≤ 2^n - 1, 0 ≤ g ≤ 10^9). If z = \overline{z_{n-1} ... z_0} in binary, then this means to set f(z_0, ..., z_{n-1}) → g.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print r+1 lines, the i-th of which denotes the value of the game f during the i-th round. Your answer must have absolute or relative error within 10^{-6}.
|
| 21 |
+
|
| 22 |
+
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
2 2
|
| 29 |
+
0 1 2 3
|
| 30 |
+
2 5
|
| 31 |
+
0 4
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
1.500000
|
| 37 |
+
2.250000
|
| 38 |
+
3.250000
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
1 0
|
| 44 |
+
2 3
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
2.500000
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
2 0
|
| 55 |
+
1 1 1 1
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
1.000000
|
| 61 |
+
|
| 62 |
+
Note
|
| 63 |
+
|
| 64 |
+
Consider the second test case. If Allen goes first, he will set x_1 → 1, so the final value will be 3. If Bessie goes first, then she will set x_1 → 0 so the final value will be 2. Thus the answer is 2.5.
|
| 65 |
+
|
| 66 |
+
In the third test case, the game value will always be 1 regardless of Allen and Bessie's play.
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 996
|
| 70 |
+
- **Problem Index**: F
|
| 71 |
+
- **Points**: 1750.0
|
| 72 |
+
- **Rating**: 2500
|
| 73 |
+
- **Tags**: math
|
| 74 |
+
- **Time Limit**: {'seconds': 3, '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-0177/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# professor-sharma
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Professor Sharma gives the following problem to his students: given two integers X( ≥ 2) and Y( ≥ 2)
|
| 5 |
+
and tells them to find the smallest positive integral exponent E such that the decimal expansion of X^E begins with Y.
|
| 6 |
+
For example, if X = 8 and Y= 51, then X^3 = 512 begins with Y= 51, so E= 3.
|
| 7 |
+
Professor Sharma has also announced that he is only interested in values of X such that
|
| 8 |
+
X is not a power of 10. The professor has a proof that in this case, at least one value of E exists for any Y.
|
| 9 |
+
now your task is to perform professor's theory and check his theory for different values of X and Y .
|
| 10 |
+
|
| 11 |
+
Input :
|
| 12 |
+
The first line contains the number of test cases N(0<N ≤ 9).
|
| 13 |
+
For each test case, there is a single line containing the integers X and Y.
|
| 14 |
+
|
| 15 |
+
Output :
|
| 16 |
+
For each test case, print the case number, followed by a space and a colon, followed by a single space, followed by a single integer showing the value of the smallest exponent E.
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
1<T<10
|
| 20 |
+
2<X,Y ≤ 10^5
|
| 21 |
+
|
| 22 |
+
SAMPLE INPUT
|
| 23 |
+
2
|
| 24 |
+
5 156
|
| 25 |
+
16 40
|
| 26 |
+
|
| 27 |
+
SAMPLE OUTPUT
|
| 28 |
+
Case 1: 6
|
| 29 |
+
Case 2: 3
|
| 30 |
+
|
| 31 |
+
Explanation
|
| 32 |
+
|
| 33 |
+
Case 1:
|
| 34 |
+
55 = 255 =1255 = 6255 = 3125*5 = 15625 = 6
|
| 35 |
+
so after 6 turns we gets our answer cos 156 is present in 15625.
|
| 36 |
+
|
| 37 |
+
Case 2:
|
| 38 |
+
1616 = 25616 = 4096 = 3
|
| 39 |
+
so after 3 turns we gets our answer cos 40 which is present in 4096
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 0
|
| 43 |
+
- **Problem Index**:
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 0
|
| 46 |
+
- **Tags**: None
|
| 47 |
+
- **Time Limit**: None seconds
|
| 48 |
+
- **Memory Limit**: 0 bytes
|
| 49 |
+
|
| 50 |
+
## Task
|
| 51 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0183/instruction.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02916 AtCoder Beginner Contest 140 - Buffet
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
|
| 5 |
+
|
| 6 |
+
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
|
| 7 |
+
|
| 8 |
+
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
|
| 9 |
+
|
| 10 |
+
Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.
|
| 11 |
+
|
| 12 |
+
Find the sum of the satisfaction points he gained.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* All values in input are integers.
|
| 17 |
+
* 2 \leq N \leq 20
|
| 18 |
+
* 1 \leq A_i \leq N
|
| 19 |
+
* A_1, A_2, ..., A_N are all different.
|
| 20 |
+
* 1 \leq B_i \leq 50
|
| 21 |
+
* 1 \leq C_i \leq 50
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
Input is given from Standard Input in the following format:
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
N
|
| 29 |
+
A_1 A_2 ... A_N
|
| 30 |
+
B_1 B_2 ... B_N
|
| 31 |
+
C_1 C_2 ... C_{N-1}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
Print the sum of the satisfaction points Takahashi gained, as an integer.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
3
|
| 43 |
+
3 1 2
|
| 44 |
+
2 5 4
|
| 45 |
+
3 6
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
14
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
4
|
| 56 |
+
2 3 4 1
|
| 57 |
+
13 5 8 24
|
| 58 |
+
45 9 15
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
74
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Input
|
| 67 |
+
|
| 68 |
+
2
|
| 69 |
+
1 2
|
| 70 |
+
50 50
|
| 71 |
+
50
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Output
|
| 75 |
+
|
| 76 |
+
150
|
| 77 |
+
|
| 78 |
+
## Contest Information
|
| 79 |
+
- **Contest ID**: 0
|
| 80 |
+
- **Problem Index**:
|
| 81 |
+
- **Points**: 0.0
|
| 82 |
+
- **Rating**: 0
|
| 83 |
+
- **Tags**:
|
| 84 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 85 |
+
- **Memory Limit**: 1073741824 bytes
|
| 86 |
+
|
| 87 |
+
## Task
|
| 88 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0184/instruction.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03052 diverta 2019 Programming Contest - Edge Ordering
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M.
|
| 5 |
+
|
| 6 |
+
Edge i connects Vertex a_i and b_i bidirectionally. It is guaranteed that the subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning tree of G.
|
| 7 |
+
|
| 8 |
+
An allocation of weights to the edges is called a good allocation when the tree consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a minimum spanning tree of G.
|
| 9 |
+
|
| 10 |
+
There are M! ways to allocate the edges distinct integer weights between 1 and M. For each good allocation among those, find the total weight of the edges in the minimum spanning tree, and print the sum of those total weights modulo 10^{9}+7.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* All values in input are integers.
|
| 15 |
+
* 2 \leq N \leq 20
|
| 16 |
+
* N-1 \leq M \leq N(N-1)/2
|
| 17 |
+
* 1 \leq a_i, b_i \leq N
|
| 18 |
+
* G does not have self-loops or multiple edges.
|
| 19 |
+
* The subgraph consisting of Vertex 1,2,\ldots,N and Edge 1,2,\ldots,N-1 is a spanning tree of G.
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
Input is given from Standard Input in the following format:
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
N M
|
| 27 |
+
a_1 b_1
|
| 28 |
+
\vdots
|
| 29 |
+
a_M b_M
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
Print the answer.
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
3 3
|
| 41 |
+
1 2
|
| 42 |
+
2 3
|
| 43 |
+
1 3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
6
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
4 4
|
| 54 |
+
1 2
|
| 55 |
+
3 2
|
| 56 |
+
3 4
|
| 57 |
+
1 3
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
50
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Input
|
| 66 |
+
|
| 67 |
+
15 28
|
| 68 |
+
10 7
|
| 69 |
+
5 9
|
| 70 |
+
2 13
|
| 71 |
+
2 14
|
| 72 |
+
6 1
|
| 73 |
+
5 12
|
| 74 |
+
2 10
|
| 75 |
+
3 9
|
| 76 |
+
10 15
|
| 77 |
+
11 12
|
| 78 |
+
12 6
|
| 79 |
+
2 12
|
| 80 |
+
12 8
|
| 81 |
+
4 10
|
| 82 |
+
15 3
|
| 83 |
+
13 14
|
| 84 |
+
1 15
|
| 85 |
+
15 12
|
| 86 |
+
4 14
|
| 87 |
+
1 7
|
| 88 |
+
5 11
|
| 89 |
+
7 13
|
| 90 |
+
9 10
|
| 91 |
+
2 7
|
| 92 |
+
1 9
|
| 93 |
+
5 6
|
| 94 |
+
12 14
|
| 95 |
+
5 2
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
Output
|
| 99 |
+
|
| 100 |
+
657573092
|
| 101 |
+
|
| 102 |
+
## Contest Information
|
| 103 |
+
- **Contest ID**: 0
|
| 104 |
+
- **Problem Index**:
|
| 105 |
+
- **Points**: 0.0
|
| 106 |
+
- **Rating**: 0
|
| 107 |
+
- **Tags**:
|
| 108 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 109 |
+
- **Memory Limit**: 1073741824 bytes
|
| 110 |
+
|
| 111 |
+
## Task
|
| 112 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0206/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02298 Is-Convex
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
For a given polygon g, print "1" if g is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.
|
| 5 |
+
|
| 6 |
+
g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the polygon. The line segment connecting pn and p1 is also a side of the polygon.
|
| 7 |
+
|
| 8 |
+
Constraints
|
| 9 |
+
|
| 10 |
+
* 3 ≤ n ≤ 100
|
| 11 |
+
* -10000 ≤ xi, yi ≤ 10000
|
| 12 |
+
* No point of the polygon will occur more than once.
|
| 13 |
+
* Two sides of the polygon can intersect only at a common endpoint.
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
g is given by coordinates of the points p1,..., pn in the following format:
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
n
|
| 21 |
+
x1 y1
|
| 22 |
+
x2 y2
|
| 23 |
+
:
|
| 24 |
+
xn yn
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Print "1" or "0" in a line.
|
| 32 |
+
|
| 33 |
+
Examples
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
4
|
| 38 |
+
0 0
|
| 39 |
+
3 1
|
| 40 |
+
2 3
|
| 41 |
+
0 3
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
1
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Input
|
| 50 |
+
|
| 51 |
+
5
|
| 52 |
+
0 0
|
| 53 |
+
2 0
|
| 54 |
+
1 1
|
| 55 |
+
2 2
|
| 56 |
+
0 2
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
0
|
| 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-0208/instruction.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# bogosort
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Recently Johnny have learned bogosort sorting algorithm. He thought that it is too ineffective. So he decided to improve it. As you may know this algorithm shuffles the sequence randomly until it is sorted. Johnny decided that we don't need to shuffle the whole sequence every time. If after the last shuffle several first elements end up in the right places we will fix them and don't shuffle those elements furthermore. We will do the same for the last elements if they are in the right places. For example, if the initial sequence is (3, 5, 1, 6, 4, 2) and after one shuffle Johnny gets (1, 2, 5, 4, 3, 6) he will fix 1, 2 and 6 and proceed with sorting (5, 4, 3) using the same algorithm. Johnny hopes that this optimization will significantly improve the algorithm. Help him calculate the expected amount of shuffles for the improved algorithm to sort the sequence of the first n natural numbers given that no elements are in the right places initially.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
The first line of input file is number t - the number of test cases. Each of the following t lines hold single number n - the number of elements in the sequence.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
1 <= t <= 150
|
| 12 |
+
2 <= n <= 150
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Output
|
| 16 |
+
For each test case output the expected amount of shuffles needed for the improved algorithm to sort the sequence of first n natural numbers in the form of irreducible fractions.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Example
|
| 20 |
+
|
| 21 |
+
Input:
|
| 22 |
+
3
|
| 23 |
+
2
|
| 24 |
+
6
|
| 25 |
+
10
|
| 26 |
+
|
| 27 |
+
Output:
|
| 28 |
+
2
|
| 29 |
+
1826/189
|
| 30 |
+
877318/35343
|
| 31 |
+
|
| 32 |
+
## Contest Information
|
| 33 |
+
- **Contest ID**: 0
|
| 34 |
+
- **Problem Index**:
|
| 35 |
+
- **Points**: 0.0
|
| 36 |
+
- **Rating**: 0
|
| 37 |
+
- **Tags**: None
|
| 38 |
+
- **Time Limit**: None seconds
|
| 39 |
+
- **Memory Limit**: 0 bytes
|
| 40 |
+
|
| 41 |
+
## Task
|
| 42 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0230/instruction.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1354_C2. Not So Simple Polygon Embedding
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
|
| 5 |
+
|
| 6 |
+
You are given a regular polygon with 2 ⋅ n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n-gon.
|
| 7 |
+
|
| 8 |
+
Your task is to find the square of the minimum size such that you can embed 2n-gon in the square. Embedding 2n-gon in the square means that you need to place 2n-gon in the square in such way that each point which lies inside or on a border of 2n-gon should also lie inside or on a border of the square.
|
| 9 |
+
|
| 10 |
+
You can rotate 2n-gon and/or the square.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains a single integer T (1 ≤ T ≤ 200) — the number of test cases.
|
| 15 |
+
|
| 16 |
+
Next T lines contain descriptions of test cases — one per line. Each line contains single odd integer n (3 ≤ n ≤ 199). Don't forget you need to embed 2n-gon, not an n-gon.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print T real numbers — one per test case. For each test case, print the minimum length of a side of the square 2n-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}.
|
| 21 |
+
|
| 22 |
+
Example
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
3
|
| 28 |
+
3
|
| 29 |
+
5
|
| 30 |
+
199
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
1.931851653
|
| 37 |
+
3.196226611
|
| 38 |
+
126.687663595
|
| 39 |
+
|
| 40 |
+
## Contest Information
|
| 41 |
+
- **Contest ID**: 1354
|
| 42 |
+
- **Problem Index**: C2
|
| 43 |
+
- **Points**: 0.0
|
| 44 |
+
- **Rating**: 2000
|
| 45 |
+
- **Tags**: binary search, brute force, geometry, math
|
| 46 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 47 |
+
- **Memory Limit**: 256000000 bytes
|
| 48 |
+
|
| 49 |
+
## Task
|
| 50 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0237/instruction.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1512_G. Short Task
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = ∑_{k | n} k.
|
| 5 |
+
|
| 6 |
+
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
|
| 7 |
+
|
| 8 |
+
For a given number c, find the minimum n such that d(n) = c.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
|
| 13 |
+
|
| 14 |
+
Each test case is characterized by one integer c (1 ≤ c ≤ 10^7).
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
For each test case, output:
|
| 19 |
+
|
| 20 |
+
* "-1" if there is no such n that d(n) = c;
|
| 21 |
+
* n, otherwise.
|
| 22 |
+
|
| 23 |
+
Example
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
12
|
| 29 |
+
1
|
| 30 |
+
2
|
| 31 |
+
3
|
| 32 |
+
4
|
| 33 |
+
5
|
| 34 |
+
6
|
| 35 |
+
7
|
| 36 |
+
8
|
| 37 |
+
9
|
| 38 |
+
10
|
| 39 |
+
39
|
| 40 |
+
691
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
1
|
| 47 |
+
-1
|
| 48 |
+
2
|
| 49 |
+
3
|
| 50 |
+
-1
|
| 51 |
+
5
|
| 52 |
+
4
|
| 53 |
+
7
|
| 54 |
+
-1
|
| 55 |
+
-1
|
| 56 |
+
18
|
| 57 |
+
-1
|
| 58 |
+
|
| 59 |
+
## Contest Information
|
| 60 |
+
- **Contest ID**: 1512
|
| 61 |
+
- **Problem Index**: G
|
| 62 |
+
- **Points**: 0.0
|
| 63 |
+
- **Rating**: 1700
|
| 64 |
+
- **Tags**: brute force, dp, math, number theory
|
| 65 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 66 |
+
- **Memory Limit**: 512000000 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-0239/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 167_C. Wizards and Numbers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In some country live wizards. They love playing with numbers.
|
| 5 |
+
|
| 6 |
+
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
|
| 7 |
+
|
| 8 |
+
* Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak ≥ 0. Number k is chosen independently each time an active player casts a spell.
|
| 9 |
+
* Replace b with b mod a.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
If a > b, similar moves are possible.
|
| 14 |
+
|
| 15 |
+
If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.
|
| 16 |
+
|
| 17 |
+
To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line contains a single integer t — the number of input data sets (1 ≤ t ≤ 104). Each of the next t lines contains two integers a, b (0 ≤ a, b ≤ 1018). The numbers are separated by a space.
|
| 22 |
+
|
| 23 |
+
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
4
|
| 34 |
+
10 21
|
| 35 |
+
31 10
|
| 36 |
+
0 1
|
| 37 |
+
10 30
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
First
|
| 43 |
+
Second
|
| 44 |
+
Second
|
| 45 |
+
First
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.
|
| 50 |
+
|
| 51 |
+
In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.
|
| 52 |
+
|
| 53 |
+
In the third sample, the first player has no moves.
|
| 54 |
+
|
| 55 |
+
In the fourth sample, the first player wins in one move, taking 30 modulo 10.
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 167
|
| 59 |
+
- **Problem Index**: C
|
| 60 |
+
- **Points**: 1500.0
|
| 61 |
+
- **Rating**: 2300
|
| 62 |
+
- **Tags**: games, math
|
| 63 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 64 |
+
- **Memory Limit**: 256000000 bytes
|
| 65 |
+
|
| 66 |
+
## Task
|
| 67 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0255/instruction.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 544_E. Remembering Strings
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i.
|
| 5 |
+
|
| 6 |
+
For example, a multiset of strings {"abc", "aba", "adc", "ada"} are not easy to remember. And multiset {"abc", "ada", "ssa"} is easy to remember because:
|
| 7 |
+
|
| 8 |
+
* the first string is the only string that has character c in position 3;
|
| 9 |
+
* the second string is the only string that has character d in position 2;
|
| 10 |
+
* the third string is the only string that has character s in position 2.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
You want to change your multiset a little so that it is easy to remember. For aij coins, you can change character in the j-th position of the i-th string into any other lowercase letter of the English alphabet. Find what is the minimum sum you should pay in order to make the multiset of strings easy to remember.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The first line contains two integers n, m (1 ≤ n, m ≤ 20) — the number of strings in the multiset and the length of the strings respectively. Next n lines contain the strings of the multiset, consisting only of lowercase English letters, each string's length is m.
|
| 19 |
+
|
| 20 |
+
Next n lines contain m integers each, the i-th of them contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 106).
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print a single number — the answer to the problem.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
4 5
|
| 31 |
+
abcde
|
| 32 |
+
abcde
|
| 33 |
+
abcde
|
| 34 |
+
abcde
|
| 35 |
+
1 1 1 1 1
|
| 36 |
+
1 1 1 1 1
|
| 37 |
+
1 1 1 1 1
|
| 38 |
+
1 1 1 1 1
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
4 3
|
| 49 |
+
abc
|
| 50 |
+
aba
|
| 51 |
+
adc
|
| 52 |
+
ada
|
| 53 |
+
10 10 10
|
| 54 |
+
10 1 10
|
| 55 |
+
10 10 10
|
| 56 |
+
10 1 10
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
2
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Input
|
| 65 |
+
|
| 66 |
+
3 3
|
| 67 |
+
abc
|
| 68 |
+
ada
|
| 69 |
+
ssa
|
| 70 |
+
1 1 1
|
| 71 |
+
1 1 1
|
| 72 |
+
1 1 1
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
0
|
| 78 |
+
|
| 79 |
+
## Contest Information
|
| 80 |
+
- **Contest ID**: 544
|
| 81 |
+
- **Problem Index**: E
|
| 82 |
+
- **Points**: 1750.0
|
| 83 |
+
- **Rating**: 2500
|
| 84 |
+
- **Tags**: bitmasks, dp
|
| 85 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 86 |
+
- **Memory Limit**: 256000000 bytes
|
| 87 |
+
|
| 88 |
+
## Task
|
| 89 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0263/instruction.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 730_G. Car Repair Shop
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
|
| 5 |
+
|
| 6 |
+
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order they came.
|
| 7 |
+
|
| 8 |
+
The i-th request is characterized by two values: si — the day when a client wants to start the repair of his car, di — duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.
|
| 9 |
+
|
| 10 |
+
Polycarp is making schedule by processing requests in the order from the first to the n-th request. He schedules the i-th request as follows:
|
| 11 |
+
|
| 12 |
+
* If the car repair shop is idle for di days starting from si (si, si + 1, ..., si + di - 1), then these days are used to repair a car of the i-th client.
|
| 13 |
+
* Otherwise, Polycarp finds the first day x (from 1 and further) that there are di subsequent days when no repair is scheduled starting from x. In other words he chooses the smallest positive x that all days x, x + 1, ..., x + di - 1 are not scheduled for repair of any car. So, the car of the i-th client will be repaired in the range [x, x + di - 1]. It is possible that the day x when repair is scheduled to start will be less than si.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Given n requests, you are asked to help Polycarp schedule all of them according to the rules above.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
|
| 22 |
+
|
| 23 |
+
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number of days to repair the i-th car.
|
| 24 |
+
|
| 25 |
+
The requests should be processed in the order they are given in the input.
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.
|
| 30 |
+
|
| 31 |
+
Examples
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
3
|
| 36 |
+
9 2
|
| 37 |
+
7 3
|
| 38 |
+
2 4
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
9 10
|
| 44 |
+
1 3
|
| 45 |
+
4 7
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
4
|
| 51 |
+
1000000000 1000000
|
| 52 |
+
1000000000 1000000
|
| 53 |
+
100000000 1000000
|
| 54 |
+
1000000000 1000000
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
1000000000 1000999999
|
| 60 |
+
1 1000000
|
| 61 |
+
100000000 100999999
|
| 62 |
+
1000001 2000000
|
| 63 |
+
|
| 64 |
+
## Contest Information
|
| 65 |
+
- **Contest ID**: 730
|
| 66 |
+
- **Problem Index**: G
|
| 67 |
+
- **Points**: 0.0
|
| 68 |
+
- **Rating**: 1600
|
| 69 |
+
- **Tags**: implementation
|
| 70 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 71 |
+
- **Memory Limit**: 512000000 bytes
|
| 72 |
+
|
| 73 |
+
## Task
|
| 74 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0264/instruction.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 754_B. Ilya and tic-tac-toe game
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
|
| 5 |
+
|
| 6 |
+
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The tic-tac-toe position is given in four lines.
|
| 11 |
+
|
| 12 |
+
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
xx..
|
| 23 |
+
.oo.
|
| 24 |
+
x...
|
| 25 |
+
oox.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
YES
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
x.ox
|
| 36 |
+
ox..
|
| 37 |
+
x.o.
|
| 38 |
+
oo.x
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
NO
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
x..x
|
| 49 |
+
..oo
|
| 50 |
+
o...
|
| 51 |
+
x.xo
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
YES
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
o.x.
|
| 62 |
+
o...
|
| 63 |
+
.x..
|
| 64 |
+
ooxx
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
NO
|
| 70 |
+
|
| 71 |
+
Note
|
| 72 |
+
|
| 73 |
+
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
|
| 74 |
+
|
| 75 |
+
In the second example it wasn't possible to win by making single turn.
|
| 76 |
+
|
| 77 |
+
In the third example Ilya could have won by placing X in the last row between two existing Xs.
|
| 78 |
+
|
| 79 |
+
In the fourth example it wasn't possible to win by making single turn.
|
| 80 |
+
|
| 81 |
+
## Contest Information
|
| 82 |
+
- **Contest ID**: 754
|
| 83 |
+
- **Problem Index**: B
|
| 84 |
+
- **Points**: 1000.0
|
| 85 |
+
- **Rating**: 1100
|
| 86 |
+
- **Tags**: brute force, implementation
|
| 87 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 88 |
+
- **Memory Limit**: 256000000 bytes
|
| 89 |
+
|
| 90 |
+
## Task
|
| 91 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0297/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00320 Cuboid
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The educational program (AHK Education) of the Aiz Broadcasting Corporation broadcasts a program called "Play with Tsukuro" for children. Today is the time to make a box with drawing paper, but I would like to see if the rectangular drawing paper I prepared can make a rectangular parallelepiped. However, do not cut or fold the drawing paper.
|
| 5 |
+
|
| 6 |
+
Given six rectangles, write a program to determine if you can make a rectangular parallelepiped using them.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The input is given in the following format.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
h1 w1
|
| 16 |
+
h2 w2
|
| 17 |
+
h3 w3
|
| 18 |
+
h4 w4
|
| 19 |
+
h5 w5
|
| 20 |
+
h6 w6
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
The input consists of 6 lines, each line given the integer hi (1 ≤ hi ≤ 1000) for the vertical length of each rectangle and the integer wi (1 ≤ wi ≤ 1000) for the horizontal length.
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
If a rectangular parallelepiped can be created, "yes" is output, and if it cannot be created, "no" is output. However, since a cube is a kind of rectangular parallelepiped, "yes" is output even if it is a cube.
|
| 28 |
+
|
| 29 |
+
Examples
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
2 2
|
| 34 |
+
2 3
|
| 35 |
+
2 3
|
| 36 |
+
2 3
|
| 37 |
+
2 2
|
| 38 |
+
3 2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
yes
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
2 2
|
| 49 |
+
2 3
|
| 50 |
+
2 3
|
| 51 |
+
2 3
|
| 52 |
+
2 2
|
| 53 |
+
2 2
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
no
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 0
|
| 62 |
+
- **Problem Index**:
|
| 63 |
+
- **Points**: 0.0
|
| 64 |
+
- **Rating**: 0
|
| 65 |
+
- **Tags**:
|
| 66 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 67 |
+
- **Memory Limit**: 268435456 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0299/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00676 KND is So Sexy
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem
|
| 5 |
+
|
| 6 |
+
KND is a student programmer at the University of Aizu. His chest is known to be very sexy.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
For simplicity, the part of the skin that can be seen from the chest is represented by the isosceles triangle ABC in the figure. However, due to the slack in the clothes, the two sides AC and BC (where these lengths are l), which have the same length, actually have an additional length x minutes. In order to increase the area of the open part, let's make two new triangular ADCs and BECs by pulling the slack part. Points D and E exist outside the triangle ABC. These two new triangles are caused by slack, and the sum of the lengths of side BE and side EC and the sum of the lengths of side AD and side DC must be l + x. You determine the points D and E so that the sum M of the areas of these three triangles is maximized. As KND's neighbor, you decide to write a program to calculate the maximum area of skin (M) to look out of your clothes, using a, l, x as inputs to find out how sexy his chest is. did.
|
| 12 |
+
|
| 13 |
+
Constraints
|
| 14 |
+
|
| 15 |
+
The input satisfies the following conditions.
|
| 16 |
+
|
| 17 |
+
* All inputs are integers.
|
| 18 |
+
* 1 ≤ a ≤ 1000
|
| 19 |
+
* 1 ≤ l ≤ 1000
|
| 20 |
+
* 1 ≤ x ≤ 1000
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
The input consists of multiple test cases. One test case is given in the following format. The end of input is indicated by EOF.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
a l x
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
here,
|
| 31 |
+
|
| 32 |
+
* a: Length of side AB of triangle ABC
|
| 33 |
+
* l: Length of two sides AC and BC of triangle ABC
|
| 34 |
+
* x: Slack on two sides AC, BC
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Is.
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
Output the maximum area for each test case on one line. This value should not differ more than 10-5 from the value of the judge output.
|
| 43 |
+
|
| 44 |
+
Example
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
2 2 1
|
| 49 |
+
2 3 1
|
| 50 |
+
3 2 3
|
| 51 |
+
2 3 5
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
3.9681187851
|
| 57 |
+
6.7970540913
|
| 58 |
+
6.5668891783
|
| 59 |
+
13.9527248554
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 0
|
| 63 |
+
- **Problem Index**:
|
| 64 |
+
- **Points**: 0.0
|
| 65 |
+
- **Rating**: 0
|
| 66 |
+
- **Tags**:
|
| 67 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 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-0320/instruction.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1053_C. Putting Boxes Together
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There is an infinite line consisting of cells. There are n boxes in some cells of this line. The i-th box stands in the cell a_i and has weight w_i. All a_i are distinct, moreover, a_{i - 1} < a_i holds for all valid i.
|
| 5 |
+
|
| 6 |
+
You would like to put together some boxes. Putting together boxes with indices in the segment [l, r] means that you will move some of them in such a way that their positions will form some segment [x, x + (r - l)].
|
| 7 |
+
|
| 8 |
+
In one step you can move any box to a neighboring cell if it isn't occupied by another box (i.e. you can choose i and change a_i by 1, all positions should remain distinct). You spend w_i units of energy moving the box i by one cell. You can move any box any number of times, in arbitrary order.
|
| 9 |
+
|
| 10 |
+
Sometimes weights of some boxes change, so you have queries of two types:
|
| 11 |
+
|
| 12 |
+
1. id nw — weight w_{id} of the box id becomes nw.
|
| 13 |
+
2. l r — you should compute the minimum total energy needed to put together boxes with indices in [l, r]. Since the answer can be rather big, print the remainder it gives when divided by 1000 000 007 = 10^9 + 7. Note that the boxes are not moved during the query, you only should compute the answer.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Note that you should minimize the answer, not its remainder modulo 10^9 + 7. So if you have two possible answers 2 ⋅ 10^9 + 13 and 2 ⋅ 10^9 + 14, you should choose the first one and print 10^9 + 6, even though the remainder of the second answer is 0.
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
The first line contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the number of boxes and the number of queries.
|
| 22 |
+
|
| 23 |
+
The second line contains n integers a_1, a_2, ... a_n (1 ≤ a_i ≤ 10^9) — the positions of the boxes. All a_i are distinct, a_{i - 1} < a_i holds for all valid i.
|
| 24 |
+
|
| 25 |
+
The third line contains n integers w_1, w_2, ... w_n (1 ≤ w_i ≤ 10^9) — the initial weights of the boxes.
|
| 26 |
+
|
| 27 |
+
Next q lines describe queries, one query per line.
|
| 28 |
+
|
| 29 |
+
Each query is described in a single line, containing two integers x and y. If x < 0, then this query is of the first type, where id = -x, nw = y (1 ≤ id ≤ n, 1 ≤ nw ≤ 10^9). If x > 0, then the query is of the second type, where l = x and r = y (1 ≤ l_j ≤ r_j ≤ n). x can not be equal to 0.
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
For each query of the second type print the answer on a separate line. Since answer can be large, print the remainder it gives when divided by 1000 000 007 = 10^9 + 7.
|
| 34 |
+
|
| 35 |
+
Example
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
5 8
|
| 40 |
+
1 2 6 7 10
|
| 41 |
+
1 1 1 1 2
|
| 42 |
+
1 1
|
| 43 |
+
1 5
|
| 44 |
+
1 3
|
| 45 |
+
3 5
|
| 46 |
+
-3 5
|
| 47 |
+
-1 10
|
| 48 |
+
1 4
|
| 49 |
+
2 5
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Output
|
| 53 |
+
|
| 54 |
+
0
|
| 55 |
+
10
|
| 56 |
+
3
|
| 57 |
+
4
|
| 58 |
+
18
|
| 59 |
+
7
|
| 60 |
+
|
| 61 |
+
Note
|
| 62 |
+
|
| 63 |
+
Let's go through queries of the example:
|
| 64 |
+
|
| 65 |
+
1. 1\ 1 — there is only one box so we don't need to move anything.
|
| 66 |
+
2. 1\ 5 — we can move boxes to segment [4, 8]: 1 ⋅ |1 - 4| + 1 ⋅ |2 - 5| + 1 ⋅ |6 - 6| + 1 ⋅ |7 - 7| + 2 ⋅ |10 - 8| = 10.
|
| 67 |
+
3. 1\ 3 — we can move boxes to segment [1, 3].
|
| 68 |
+
4. 3\ 5 — we can move boxes to segment [7, 9].
|
| 69 |
+
5. -3\ 5 — w_3 is changed from 1 to 5.
|
| 70 |
+
6. -1\ 10 — w_1 is changed from 1 to 10. The weights are now equal to w = [10, 1, 5, 1, 2].
|
| 71 |
+
7. 1\ 4 — we can move boxes to segment [1, 4].
|
| 72 |
+
8. 2\ 5 — we can move boxes to segment [5, 8].
|
| 73 |
+
|
| 74 |
+
## Contest Information
|
| 75 |
+
- **Contest ID**: 1053
|
| 76 |
+
- **Problem Index**: C
|
| 77 |
+
- **Points**: 2500.0
|
| 78 |
+
- **Rating**: 2500
|
| 79 |
+
- **Tags**: data structures
|
| 80 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 500000000} seconds
|
| 81 |
+
- **Memory Limit**: 256000000 bytes
|
| 82 |
+
|
| 83 |
+
## Task
|
| 84 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0327/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1202_C. You Are Given a WASD-string...
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands:
|
| 5 |
+
|
| 6 |
+
* 'W' — move one cell up;
|
| 7 |
+
* 'S' — move one cell down;
|
| 8 |
+
* 'A' — move one cell left;
|
| 9 |
+
* 'D' — move one cell right.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Let Grid(s) be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands s. For example, if s = DSAWWAW then Grid(s) is the 4 × 3 grid:
|
| 14 |
+
|
| 15 |
+
1. you can place the robot in the cell (3, 2);
|
| 16 |
+
2. the robot performs the command 'D' and moves to (3, 3);
|
| 17 |
+
3. the robot performs the command 'S' and moves to (4, 3);
|
| 18 |
+
4. the robot performs the command 'A' and moves to (4, 2);
|
| 19 |
+
5. the robot performs the command 'W' and moves to (3, 2);
|
| 20 |
+
6. the robot performs the command 'W' and moves to (2, 2);
|
| 21 |
+
7. the robot performs the command 'A' and moves to (2, 1);
|
| 22 |
+
8. the robot performs the command 'W' and moves to (1, 1).
|
| 23 |
+
|
| 24 |
+
<image>
|
| 25 |
+
|
| 26 |
+
You have 4 extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence s to minimize the area of Grid(s).
|
| 27 |
+
|
| 28 |
+
What is the minimum area of Grid(s) you can achieve?
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
The first line contains one integer T (1 ≤ T ≤ 1000) — the number of queries.
|
| 33 |
+
|
| 34 |
+
Next T lines contain queries: one per line. This line contains single string s (1 ≤ |s| ≤ 2 ⋅ 10^5, s_i ∈ \{W, A, S, D\}) — the sequence of commands.
|
| 35 |
+
|
| 36 |
+
It's guaranteed that the total length of s over all queries doesn't exceed 2 ⋅ 10^5.
|
| 37 |
+
|
| 38 |
+
Output
|
| 39 |
+
|
| 40 |
+
Print T integers: one per query. For each query print the minimum area of Grid(s) you can achieve.
|
| 41 |
+
|
| 42 |
+
Example
|
| 43 |
+
|
| 44 |
+
Input
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
3
|
| 48 |
+
DSAWWAW
|
| 49 |
+
D
|
| 50 |
+
WA
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
8
|
| 57 |
+
2
|
| 58 |
+
4
|
| 59 |
+
|
| 60 |
+
Note
|
| 61 |
+
|
| 62 |
+
In the first query you have to get string DSAWW\underline{D}AW.
|
| 63 |
+
|
| 64 |
+
In second and third queries you can not decrease the area of Grid(s).
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 1202
|
| 68 |
+
- **Problem Index**: C
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 2100
|
| 71 |
+
- **Tags**: brute force, data structures, dp, greedy, implementation, math, strings
|
| 72 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 73 |
+
- **Memory Limit**: 256000000 bytes
|
| 74 |
+
|
| 75 |
+
## Task
|
| 76 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0345/instruction.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 203_E. Transportation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment.
|
| 5 |
+
|
| 6 |
+
The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other robots. More precisely, for the i-th robot we know value ci — the number of robots it can carry. In this case, each of ci transported robots can additionally carry other robots.
|
| 7 |
+
|
| 8 |
+
However, the robots need to be filled with fuel to go, so Valera spent all his last money and bought S liters of fuel. He learned that each robot has a restriction on travel distances. Thus, in addition to features ci, the i-th robot has two features fi and li — the amount of fuel (in liters) needed to move the i-th robot, and the maximum distance that the robot can go.
|
| 9 |
+
|
| 10 |
+
Due to the limited amount of time and fuel, Valera wants to move the maximum number of robots to the luggage compartment. He operates as follows.
|
| 11 |
+
|
| 12 |
+
* First Valera selects some robots that will travel to the luggage compartment on their own. In this case the total amount of fuel required to move all these robots must not exceed S.
|
| 13 |
+
* Then Valera seats the robots into the compartments, so as to transport as many robots as possible. Note that if a robot doesn't move by itself, you can put it in another not moving robot that is moved directly or indirectly by a moving robot.
|
| 14 |
+
* After that all selected and seated robots along with Valera go to the luggage compartment and the rest robots will be lost.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
There are d meters to the luggage compartment. Therefore, the robots that will carry the rest, must have feature li of not less than d. During the moving Valera cannot stop or change the location of the robots in any way.
|
| 19 |
+
|
| 20 |
+
Help Valera calculate the maximum number of robots that he will be able to take home, and the minimum amount of fuel he will have to spend, because the remaining fuel will come in handy in Valera's research.
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
The first line contains three space-separated integers n, d, S (1 ≤ n ≤ 105, 1 ≤ d, S ≤ 109). The first number represents the number of robots, the second one — the distance to the luggage compartment and the third one — the amount of available fuel.
|
| 25 |
+
|
| 26 |
+
Next n lines specify the robots. The i-th line contains three space-separated integers ci, fi, li (0 ≤ ci, fi, li ≤ 109) — the i-th robot's features. The first number is the number of robots the i-th robot can carry, the second number is the amount of fuel needed for the i-th robot to move and the third one shows the maximum distance the i-th robot can go.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
Print two space-separated integers — the maximum number of robots Valera can transport to the luggage compartment and the minimum amount of fuel he will need for that. If Valera won't manage to get any robots to the luggage compartment, print two zeroes.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
3 10 10
|
| 37 |
+
0 12 10
|
| 38 |
+
1 6 10
|
| 39 |
+
0 1 1
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
2 6
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Input
|
| 48 |
+
|
| 49 |
+
2 7 10
|
| 50 |
+
3 12 10
|
| 51 |
+
5 16 8
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
0 0
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
4 8 10
|
| 62 |
+
0 12 3
|
| 63 |
+
1 1 0
|
| 64 |
+
0 3 11
|
| 65 |
+
1 6 9
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Output
|
| 69 |
+
|
| 70 |
+
4 9
|
| 71 |
+
|
| 72 |
+
## Contest Information
|
| 73 |
+
- **Contest ID**: 203
|
| 74 |
+
- **Problem Index**: E
|
| 75 |
+
- **Points**: 2500.0
|
| 76 |
+
- **Rating**: 2300
|
| 77 |
+
- **Tags**: greedy, sortings, two pointers
|
| 78 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 79 |
+
- **Memory Limit**: 256000000 bytes
|
| 80 |
+
|
| 81 |
+
## Task
|
| 82 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0373/instruction.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 85_D. Sum of Medians
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is called the middle element of a sorted array (it's the third largest element for a group of five). To increase the algorithm's performance speed on a modern video card, you should be able to find a sum of medians in each five of the array.
|
| 5 |
+
|
| 6 |
+
A sum of medians of a sorted k-element set S = {a1, a2, ..., ak}, where a1 < a2 < a3 < ... < ak, will be understood by as
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
The <image> operator stands for taking the remainder, that is <image> stands for the remainder of dividing x by y.
|
| 11 |
+
|
| 12 |
+
To organize exercise testing quickly calculating the sum of medians for a changing set was needed.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains number n (1 ≤ n ≤ 105), the number of operations performed.
|
| 17 |
+
|
| 18 |
+
Then each of n lines contains the description of one of the three operations:
|
| 19 |
+
|
| 20 |
+
* add x — add the element x to the set;
|
| 21 |
+
* del x — delete the element x from the set;
|
| 22 |
+
* sum — find the sum of medians of the set.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
For any add x operation it is true that the element x is not included in the set directly before the operation.
|
| 27 |
+
|
| 28 |
+
For any del x operation it is true that the element x is included in the set directly before the operation.
|
| 29 |
+
|
| 30 |
+
All the numbers in the input are positive integers, not exceeding 109.
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
For each operation sum print on the single line the sum of medians of the current set. If the set is empty, print 0.
|
| 35 |
+
|
| 36 |
+
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams (also you may use the %I64d specificator).
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
6
|
| 43 |
+
add 4
|
| 44 |
+
add 5
|
| 45 |
+
add 1
|
| 46 |
+
add 2
|
| 47 |
+
add 3
|
| 48 |
+
sum
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
3
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
14
|
| 59 |
+
add 1
|
| 60 |
+
add 7
|
| 61 |
+
add 2
|
| 62 |
+
add 5
|
| 63 |
+
sum
|
| 64 |
+
add 6
|
| 65 |
+
add 8
|
| 66 |
+
add 9
|
| 67 |
+
add 3
|
| 68 |
+
add 4
|
| 69 |
+
add 10
|
| 70 |
+
sum
|
| 71 |
+
del 1
|
| 72 |
+
sum
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
Output
|
| 76 |
+
|
| 77 |
+
5
|
| 78 |
+
11
|
| 79 |
+
13
|
| 80 |
+
|
| 81 |
+
## Contest Information
|
| 82 |
+
- **Contest ID**: 85
|
| 83 |
+
- **Problem Index**: D
|
| 84 |
+
- **Points**: 2000.0
|
| 85 |
+
- **Rating**: 2300
|
| 86 |
+
- **Tags**: binary search, brute force, data structures, implementation
|
| 87 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 88 |
+
- **Memory Limit**: 256000000 bytes
|
| 89 |
+
|
| 90 |
+
## Task
|
| 91 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0375/instruction.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 909_D. Colorful Points
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.
|
| 5 |
+
|
| 6 |
+
You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.
|
| 7 |
+
|
| 8 |
+
How many operations will you need to perform until the next operation does not have any points to delete?
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
|
| 13 |
+
|
| 14 |
+
The number of the points is between 1 and 106.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
aabb
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
2
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
aabcaa
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
1
|
| 40 |
+
|
| 41 |
+
Note
|
| 42 |
+
|
| 43 |
+
In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
|
| 44 |
+
|
| 45 |
+
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.
|
| 46 |
+
|
| 47 |
+
## Contest Information
|
| 48 |
+
- **Contest ID**: 909
|
| 49 |
+
- **Problem Index**: D
|
| 50 |
+
- **Points**: 1750.0
|
| 51 |
+
- **Rating**: 2100
|
| 52 |
+
- **Tags**: data structures, greedy, implementation
|
| 53 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 54 |
+
- **Memory Limit**: 256000000 bytes
|
| 55 |
+
|
| 56 |
+
## Task
|
| 57 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0381/instruction.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# cube-change-qualifier2
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Chandan gave his son a cube with side N. The N X N X N cube is made up of small 1 X 1 X 1 cubes.
|
| 5 |
+
|
| 6 |
+
Chandan's son is extremely notorious just like him. So he dropped the cube inside a tank filled with Coke. The cube got totally immersed in that tank. His son was somehow able to take out the cube from the tank. But sooner his son realized that the cube had gone all dirty because of the coke. Since Chandan did not like dirty stuffs so his son decided to scrap off all the smaller cubes that got dirty in the process. A cube that had coke on any one of its six faces was considered to be dirty and scrapped off. After completing this cumbersome part his son decided to calculate volume of the scrapped off material.
|
| 7 |
+
Since Chandan's son is weak in maths he is unable to do it alone.
|
| 8 |
+
|
| 9 |
+
Help him in calculating the required volume.
|
| 10 |
+
|
| 11 |
+
Input:
|
| 12 |
+
|
| 13 |
+
The first line contains T denoting the number of test cases. Then T lines follow each line contains N that is the side of cube.
|
| 14 |
+
|
| 15 |
+
Output:
|
| 16 |
+
|
| 17 |
+
For each case output the required volume.
|
| 18 |
+
|
| 19 |
+
Constraints:
|
| 20 |
+
|
| 21 |
+
1 ≤ T ≤ 100
|
| 22 |
+
1 ≤ N ≤ 10^9
|
| 23 |
+
Note:
|
| 24 |
+
|
| 25 |
+
There is no hole or space between 2 smaller cubes.
|
| 26 |
+
|
| 27 |
+
SAMPLE INPUT
|
| 28 |
+
2
|
| 29 |
+
1
|
| 30 |
+
3
|
| 31 |
+
|
| 32 |
+
SAMPLE OUTPUT
|
| 33 |
+
1
|
| 34 |
+
26
|
| 35 |
+
|
| 36 |
+
Explanation
|
| 37 |
+
|
| 38 |
+
For the first test case : There is only 1 small cube in a 1 x 1 x 1 cube. This cube gets coke on all of its 6 faces so it needs to be scrapped off. Volume of material that gets scrapped is 1 x 1 x 1 = 1.
|
| 39 |
+
|
| 40 |
+
## Contest Information
|
| 41 |
+
- **Contest ID**: 0
|
| 42 |
+
- **Problem Index**:
|
| 43 |
+
- **Points**: 0.0
|
| 44 |
+
- **Rating**: 0
|
| 45 |
+
- **Tags**: None
|
| 46 |
+
- **Time Limit**: None seconds
|
| 47 |
+
- **Memory Limit**: 0 bytes
|
| 48 |
+
|
| 49 |
+
## Task
|
| 50 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0389/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02574 AtCoder Beginner Contest 177 - Coprime
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have N integers. The i-th number is A_i.
|
| 5 |
+
|
| 6 |
+
\\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.
|
| 7 |
+
|
| 8 |
+
\\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.
|
| 9 |
+
|
| 10 |
+
Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.
|
| 11 |
+
|
| 12 |
+
Here, GCD(\ldots) denotes greatest common divisor.
|
| 13 |
+
|
| 14 |
+
Constraints
|
| 15 |
+
|
| 16 |
+
* 2 \leq N \leq 10^6
|
| 17 |
+
* 1 \leq A_i\leq 10^6
|
| 18 |
+
|
| 19 |
+
Input
|
| 20 |
+
|
| 21 |
+
Input is given from Standard Input in the following format:
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
N
|
| 25 |
+
A_1 \ldots A_N
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
If \\{A_i\\} is pairwise coprime, print `pairwise coprime`; if \\{A_i\\} is setwise coprime, print `setwise coprime`; if neither, print `not coprime`.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
3
|
| 37 |
+
3 4 5
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
pairwise coprime
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
3
|
| 48 |
+
6 10 15
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
setwise coprime
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
3
|
| 59 |
+
6 10 16
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
not coprime
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 0
|
| 68 |
+
- **Problem Index**:
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 0
|
| 71 |
+
- **Tags**:
|
| 72 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 73 |
+
- **Memory Limit**: 1073741824 bytes
|
| 74 |
+
|
| 75 |
+
## Task
|
| 76 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0403/instruction.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00638 Old Bridges
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
|
| 5 |
+
|
| 6 |
+
Finally he found n islands that had treasures and one island that had nothing. Most of islands had seashore and he can land only on an island which had nothing. He walked around the island and found that there was an old bridge between this island and each of all other n islands.
|
| 7 |
+
|
| 8 |
+
He tries to visit all islands one by one and pick all the treasures up. Since he is afraid to be stolen, he visits with bringing all treasures that he has picked up. He is a strong man and can bring all the treasures at a time, but the old bridges will break if he cross it with taking certain or more amount of treasures.
|
| 9 |
+
|
| 10 |
+
Please write a program that judges if he can collect all the treasures and can be back to the island where he land on by properly selecting an order of his visit.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* 1 ≤ n ≤ 25
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
Input consists of several datasets.
|
| 19 |
+
|
| 20 |
+
The first line of each dataset contains an integer n. Next n lines represents information of the islands. Each line has two integers, which means the amount of treasures of the island and the maximal amount that he can take when he crosses the bridge to the islands, respectively.
|
| 21 |
+
|
| 22 |
+
The end of input is represented by a case with n = 0.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
For each dataset, if he can collect all the treasures and can be back, print "Yes" Otherwise print "No"
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
3
|
| 33 |
+
2 3
|
| 34 |
+
3 6
|
| 35 |
+
1 2
|
| 36 |
+
3
|
| 37 |
+
2 3
|
| 38 |
+
3 5
|
| 39 |
+
1 2
|
| 40 |
+
0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
Yes
|
| 46 |
+
No
|
| 47 |
+
|
| 48 |
+
## Contest Information
|
| 49 |
+
- **Contest ID**: 0
|
| 50 |
+
- **Problem Index**:
|
| 51 |
+
- **Points**: 0.0
|
| 52 |
+
- **Rating**: 0
|
| 53 |
+
- **Tags**:
|
| 54 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 55 |
+
- **Memory Limit**: 134217728 bytes
|
| 56 |
+
|
| 57 |
+
## Task
|
| 58 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0404/instruction.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00781 Lattice Practices
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 × 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows:
|
| 5 |
+
|
| 6 |
+
<image>
|
| 7 |
+
|
| 8 |
+
The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits:
|
| 9 |
+
|
| 10 |
+
<image>
|
| 11 |
+
|
| 12 |
+
Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following:
|
| 13 |
+
|
| 14 |
+
<image>
|
| 15 |
+
|
| 16 |
+
Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit.
|
| 17 |
+
|
| 18 |
+
Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore you should not count mirror image configurations and rotated configurations separately as different configurations.
|
| 19 |
+
|
| 20 |
+
The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards separately, where shallow and deep slits are denoted by '1' and '0' respectively.
|
| 21 |
+
|
| 22 |
+
<image>
|
| 23 |
+
|
| 24 |
+
Notice that a rotation may exchange position of a vertical board and a horizontal board.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
The input consists of multiple data sets, each in a line. A data set gives the patterns of slits of 10 boards used to construct the lattice. The format of a data set is as follows:
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Each x is either '0' or '1'. '0' means a deep slit, and '1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space.
|
| 37 |
+
|
| 38 |
+
For example, the first data set in the Sample Input means the set of the following 10 boards:
|
| 39 |
+
|
| 40 |
+
<image>
|
| 41 |
+
|
| 42 |
+
The end of the input is indicated by a line consisting solely of three characters "END".
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
For each data set, the number of possible configurations to make the lattice from the given 10 boards should be output, each in a separate line.
|
| 47 |
+
|
| 48 |
+
Example
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
10000 01000 00100 11000 01100 11111 01110 11100 10110 11110
|
| 53 |
+
10101 01000 00000 11001 01100 11101 01110 11100 10110 11010
|
| 54 |
+
END
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
40
|
| 60 |
+
6
|
| 61 |
+
|
| 62 |
+
## Contest Information
|
| 63 |
+
- **Contest ID**: 0
|
| 64 |
+
- **Problem Index**:
|
| 65 |
+
- **Points**: 0.0
|
| 66 |
+
- **Rating**: 0
|
| 67 |
+
- **Tags**:
|
| 68 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 69 |
+
- **Memory Limit**: 134217728 bytes
|
| 70 |
+
|
| 71 |
+
## Task
|
| 72 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0432/instruction.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1216_D. Swords
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swords. Note that the values x, y and z are unknown for you.
|
| 5 |
+
|
| 6 |
+
The next morning the director of the theater discovers the loss. He counts all swords — exactly a_i swords of the i-th type are left untouched.
|
| 7 |
+
|
| 8 |
+
The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.
|
| 9 |
+
|
| 10 |
+
For example, if n=3, a = [3, 12, 6] then one of the possible situations is x=12, y=5 and z=3. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values x, y and z beforehand but know values of n and a.
|
| 11 |
+
|
| 12 |
+
Thus he seeks for your help. Determine the minimum number of people y, which could have broken into the theater basement, and the number of swords z each of them has taken.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains one integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of types of swords.
|
| 17 |
+
|
| 18 |
+
The second line of the input contains the sequence a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{9}), where a_i equals to the number of swords of the i-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices (j, k) that a_j ≠ a_k.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print two integers y and z — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
3
|
| 30 |
+
3 12 6
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
5 3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
2
|
| 43 |
+
2 9
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
1 7
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
7
|
| 56 |
+
2 1000000000 4 6 8 4 2
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
2999999987 2
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Input
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
6
|
| 69 |
+
13 52 0 13 26 52
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Output
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
12 13
|
| 76 |
+
|
| 77 |
+
Note
|
| 78 |
+
|
| 79 |
+
In the first example the minimum value of y equals to 5, i.e. the minimum number of people who could have broken into the basement, is 5. Each of them has taken 3 swords: three of them have taken 3 swords of the first type, and two others have taken 3 swords of the third type.
|
| 80 |
+
|
| 81 |
+
In the second example the minimum value of y is 1, i.e. the minimum number of people who could have broken into the basement, equals to 1. He has taken 7 swords of the first type.
|
| 82 |
+
|
| 83 |
+
## Contest Information
|
| 84 |
+
- **Contest ID**: 1216
|
| 85 |
+
- **Problem Index**: D
|
| 86 |
+
- **Points**: 0.0
|
| 87 |
+
- **Rating**: 1300
|
| 88 |
+
- **Tags**: math
|
| 89 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 90 |
+
- **Memory Limit**: 256000000 bytes
|
| 91 |
+
|
| 92 |
+
## Task
|
| 93 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0459/instruction.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 438_A. The Child and Toy
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
|
| 5 |
+
|
| 6 |
+
The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.
|
| 7 |
+
|
| 8 |
+
Help the child to find out, what is the minimum total energy he should spend to remove all n parts.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi).
|
| 13 |
+
|
| 14 |
+
Consider all the parts are numbered from 1 to n.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Output the minimum total energy the child should spend to remove all n parts of the toy.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
4 3
|
| 25 |
+
10 20 30 40
|
| 26 |
+
1 4
|
| 27 |
+
1 2
|
| 28 |
+
2 3
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
40
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
4 4
|
| 39 |
+
100 100 100 100
|
| 40 |
+
1 2
|
| 41 |
+
2 3
|
| 42 |
+
2 4
|
| 43 |
+
3 4
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
400
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
7 10
|
| 54 |
+
40 10 20 10 20 80 40
|
| 55 |
+
1 5
|
| 56 |
+
4 7
|
| 57 |
+
4 5
|
| 58 |
+
5 2
|
| 59 |
+
5 7
|
| 60 |
+
6 4
|
| 61 |
+
1 6
|
| 62 |
+
1 3
|
| 63 |
+
4 3
|
| 64 |
+
1 4
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
160
|
| 70 |
+
|
| 71 |
+
Note
|
| 72 |
+
|
| 73 |
+
One of the optimal sequence of actions in the first sample is:
|
| 74 |
+
|
| 75 |
+
* First, remove part 3, cost of the action is 20.
|
| 76 |
+
* Then, remove part 2, cost of the action is 10.
|
| 77 |
+
* Next, remove part 4, cost of the action is 10.
|
| 78 |
+
* At last, remove part 1, cost of the action is 0.
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.
|
| 83 |
+
|
| 84 |
+
In the second sample, the child will spend 400 no matter in what order he will remove the parts.
|
| 85 |
+
|
| 86 |
+
## Contest Information
|
| 87 |
+
- **Contest ID**: 438
|
| 88 |
+
- **Problem Index**: A
|
| 89 |
+
- **Points**: 1500.0
|
| 90 |
+
- **Rating**: 1400
|
| 91 |
+
- **Tags**: graphs, greedy, sortings
|
| 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-0466/instruction.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 604_A. Uncowed Forces
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
|
| 5 |
+
|
| 6 |
+
Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is <image>. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
|
| 7 |
+
|
| 8 |
+
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted.
|
| 13 |
+
|
| 14 |
+
The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i.
|
| 15 |
+
|
| 16 |
+
The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print a single integer, the value of Kevin's final score.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
20 40 60 80 100
|
| 27 |
+
0 1 2 3 4
|
| 28 |
+
1 0
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
4900
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
119 119 119 119 119
|
| 39 |
+
0 0 0 0 0
|
| 40 |
+
10 0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
4930
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <image> of the points on each problem. So his score from solving problems is <image>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
|
| 50 |
+
|
| 51 |
+
## Contest Information
|
| 52 |
+
- **Contest ID**: 604
|
| 53 |
+
- **Problem Index**: A
|
| 54 |
+
- **Points**: 500.0
|
| 55 |
+
- **Rating**: 1000
|
| 56 |
+
- **Tags**: implementation
|
| 57 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 58 |
+
- **Memory Limit**: 256000000 bytes
|
| 59 |
+
|
| 60 |
+
## Task
|
| 61 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0495/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02807 Dwango Programming Contest 6th - Fusing Slimes
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are N slimes standing on a number line. The i-th slime from the left is at position x_i.
|
| 5 |
+
|
| 6 |
+
It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.
|
| 7 |
+
|
| 8 |
+
Niwango will perform N-1 operations. The i-th operation consists of the following procedures:
|
| 9 |
+
|
| 10 |
+
* Choose an integer k between 1 and N-i (inclusive) with equal probability.
|
| 11 |
+
* Move the k-th slime from the left, to the position of the neighboring slime to the right.
|
| 12 |
+
* Fuse the two slimes at the same position into one slime.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
|
| 17 |
+
|
| 18 |
+
Constraints
|
| 19 |
+
|
| 20 |
+
* 2 \leq N \leq 10^{5}
|
| 21 |
+
* 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}
|
| 22 |
+
* x_i is an integer.
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
Input is given from Standard Input in the following format:
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
N
|
| 30 |
+
x_1 x_2 \ldots x_N
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
Print the answer.
|
| 36 |
+
|
| 37 |
+
Examples
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
3
|
| 42 |
+
1 2 3
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
5
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
12
|
| 53 |
+
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
Output
|
| 57 |
+
|
| 58 |
+
750927044
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 0
|
| 62 |
+
- **Problem Index**:
|
| 63 |
+
- **Points**: 0.0
|
| 64 |
+
- **Rating**: 0
|
| 65 |
+
- **Tags**:
|
| 66 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 525000000} seconds
|
| 67 |
+
- **Memory Limit**: 1073741824 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0514/instruction.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01609 One
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
One
|
| 5 |
+
|
| 6 |
+
Problem Statement
|
| 7 |
+
|
| 8 |
+
A beautiful mountain range can be seen from the train window.
|
| 9 |
+
The window is a rectangle with the coordinates of the lower left corner (0, 0) and the coordinates of the upper right corner (W, H).
|
| 10 |
+
N peaks can be seen from the window, and the i-th peak has the shape of an upwardly convex parabola y = a_i (x-p_i) ^ 2 + q_i.
|
| 11 |
+
Find the length of the boundary between the mountain and the sky.
|
| 12 |
+
|
| 13 |
+
The following three figures correspond to Sample Input. The part shown by the thick line is the boundary between the mountain and the sky.
|
| 14 |
+
|
| 15 |
+
<image> <image> <image>
|
| 16 |
+
|
| 17 |
+
Constraints
|
| 18 |
+
|
| 19 |
+
* 1 ≤ W, H ≤ 100
|
| 20 |
+
* 1 ≤ N ≤ 50
|
| 21 |
+
* -100 ≤ a_i ≤ -1
|
| 22 |
+
* 0 ≤ p_i ≤ W
|
| 23 |
+
* 1 ≤ q_i ≤ H
|
| 24 |
+
* If i \ neq j, then (a_i, p_i, q_i) \ neq (a_j, p_j, q_j)
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
Input follows the following format. All given numbers are integers.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
W H N
|
| 32 |
+
a_1 p_1 q_1
|
| 33 |
+
...
|
| 34 |
+
a_N p_N q_N
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
Output the length of the boundary between the mountain and the sky on one line.
|
| 39 |
+
The output value must have an absolute or relative error of less than 10 ^ {-6} with the true value.
|
| 40 |
+
|
| 41 |
+
Examples
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
20 20 1
|
| 46 |
+
-1 10 10
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
21.520346288593280
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Input
|
| 55 |
+
|
| 56 |
+
20 20 2
|
| 57 |
+
-1 10 10
|
| 58 |
+
-2 10 5
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
21.520346288593280
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Input
|
| 67 |
+
|
| 68 |
+
15 100 2
|
| 69 |
+
-2 5 100
|
| 70 |
+
-2 10 100
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Output
|
| 74 |
+
|
| 75 |
+
126.921542730127873
|
| 76 |
+
|
| 77 |
+
## Contest Information
|
| 78 |
+
- **Contest ID**: 0
|
| 79 |
+
- **Problem Index**:
|
| 80 |
+
- **Points**: 0.0
|
| 81 |
+
- **Rating**: 0
|
| 82 |
+
- **Tags**:
|
| 83 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 84 |
+
- **Memory Limit**: 134217728 bytes
|
| 85 |
+
|
| 86 |
+
## Task
|
| 87 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0525/instruction.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# prime1
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Shridhar wants to generate some prime numbers for his cryptosystem. Help him!
|
| 5 |
+
Your task is to generate all prime numbers between two given numbers.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains t, the number of test cases (less then or equal to 10).
|
| 11 |
+
|
| 12 |
+
Followed by t lines which contain two numbers m and n (1 ≤ m ≤ n ≤ 1000000000, n-m ≤ 100000) separated by a space.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Output
|
| 16 |
+
For every test case print all prime numbers p such that m ≤ p ≤ n,
|
| 17 |
+
one number per line. Separate the answers for each test case by an empty line.
|
| 18 |
+
|
| 19 |
+
Example
|
| 20 |
+
Input:
|
| 21 |
+
2
|
| 22 |
+
1 10
|
| 23 |
+
3 5
|
| 24 |
+
|
| 25 |
+
Output:
|
| 26 |
+
2
|
| 27 |
+
3
|
| 28 |
+
5
|
| 29 |
+
7
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
5
|
| 33 |
+
|
| 34 |
+
Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)
|
| 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-0576/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 72_I. Goofy Numbers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The non-negative integer a is a divisor of the non-negative integer b if and only if there exists a positive integer c such that a × c = b.
|
| 5 |
+
|
| 6 |
+
Some numbers are really interesting. Commander Surena defines some interesting properties for non-negative integers:
|
| 7 |
+
|
| 8 |
+
* An integer is happy if it is divisible by at least one of its digits and not by all of them.
|
| 9 |
+
* An integer is happier if it is divisible by all of its digits.
|
| 10 |
+
* An integer is upset if it's divisible by none of its digits.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Surena asks you to find out if a given number is happy, happier or upset.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
Input contains a single non-negative integer n (1 ≤ n ≤ 108).
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Write on a single line the type of the integer: happy, happier or upset. Print the type in lowercase letters.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
99
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
happier
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
29994
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
happy
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
23
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
upset
|
| 54 |
+
|
| 55 |
+
Note
|
| 56 |
+
|
| 57 |
+
In the second test 29994 is only divisible by 2.
|
| 58 |
+
|
| 59 |
+
In the third test 23 is a prime number.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 72
|
| 63 |
+
- **Problem Index**: I
|
| 64 |
+
- **Points**: 0.0
|
| 65 |
+
- **Rating**: 1500
|
| 66 |
+
- **Tags**: *special, implementation
|
| 67 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 256000000 bytes
|
| 69 |
+
|
| 70 |
+
## Task
|
| 71 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0582/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 865_D. Buy Low Sell High
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the N days you would like to again own zero shares, but want to have as much money as possible.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days.
|
| 9 |
+
|
| 10 |
+
Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print the maximum amount of money you can end up with at the end of N days.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
9
|
| 21 |
+
10 5 4 7 9 12 6 2 10
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
20
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
20
|
| 32 |
+
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
41
|
| 38 |
+
|
| 39 |
+
Note
|
| 40 |
+
|
| 41 |
+
In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20.
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 865
|
| 45 |
+
- **Problem Index**: D
|
| 46 |
+
- **Points**: 2000.0
|
| 47 |
+
- **Rating**: 2400
|
| 48 |
+
- **Tags**: constructive algorithms, data structures, greedy
|
| 49 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 50 |
+
- **Memory Limit**: 256000000 bytes
|
| 51 |
+
|
| 52 |
+
## Task
|
| 53 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0600/instruction.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02868 NIKKEI Programming Contest 2019-2 - Shortest Path on a Line
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have N points numbered 1 to N arranged in a line in this order.
|
| 5 |
+
|
| 6 |
+
Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows:
|
| 7 |
+
|
| 8 |
+
* The operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \leq s < t \leq R_i, add an edge of length C_i between Vertex s and Vertex t.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
The integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.
|
| 13 |
+
|
| 14 |
+
Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.
|
| 15 |
+
|
| 16 |
+
Constraints
|
| 17 |
+
|
| 18 |
+
* 2 \leq N \leq 10^5
|
| 19 |
+
* 1 \leq M \leq 10^5
|
| 20 |
+
* 1 \leq L_i < R_i \leq N
|
| 21 |
+
* 1 \leq C_i \leq 10^9
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
Input is given from Standard Input in the following format:
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
N M
|
| 29 |
+
L_1 R_1 C_1
|
| 30 |
+
:
|
| 31 |
+
L_M R_M C_M
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Output
|
| 35 |
+
|
| 36 |
+
Print the length of the shortest path from Vertex 1 to Vertex N in the final graph. If there is no shortest path, print `-1` instead.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
4 3
|
| 43 |
+
1 3 2
|
| 44 |
+
2 4 3
|
| 45 |
+
1 4 6
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
5
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
4 2
|
| 56 |
+
1 2 1
|
| 57 |
+
3 4 2
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
-1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Input
|
| 66 |
+
|
| 67 |
+
10 7
|
| 68 |
+
1 5 18
|
| 69 |
+
3 4 8
|
| 70 |
+
1 3 5
|
| 71 |
+
4 7 10
|
| 72 |
+
5 9 8
|
| 73 |
+
6 10 5
|
| 74 |
+
8 10 3
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Output
|
| 78 |
+
|
| 79 |
+
28
|
| 80 |
+
|
| 81 |
+
## Contest Information
|
| 82 |
+
- **Contest ID**: 0
|
| 83 |
+
- **Problem Index**:
|
| 84 |
+
- **Points**: 0.0
|
| 85 |
+
- **Rating**: 0
|
| 86 |
+
- **Tags**:
|
| 87 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 88 |
+
- **Memory Limit**: 1073741824 bytes
|
| 89 |
+
|
| 90 |
+
## Task
|
| 91 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0607/instruction.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03932 square869120Contest #3 - Souvenirs
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Input
|
| 5 |
+
|
| 6 |
+
The input is given from standard input in the following format.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
|
| 10 |
+
|
| 11 |
+
Output
|
| 12 |
+
|
| 13 |
+
* Print the maximum number of souvenirs they can get.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Constraints
|
| 18 |
+
|
| 19 |
+
* $1 \le H, W \le 200$
|
| 20 |
+
* $0 \le a_{i, j} \le 10^5$
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Subtasks
|
| 25 |
+
|
| 26 |
+
Subtask 1 [ 50 points ]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
* The testcase in the subtask satisfies $1 \le H \le 2$.
|
| 30 |
+
|
| 31 |
+
Subtask 2 [ 80 points ]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
* The testcase in the subtask satisfies $1 \le H \le 3$.
|
| 35 |
+
|
| 36 |
+
Subtask 3 [ 120 points ]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
* The testcase in the subtask satisfies $1 \le H, W \le 7$.
|
| 40 |
+
|
| 41 |
+
Subtask 4 [ 150 points ]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
* The testcase in the subtask satisfies $1 \le H, W \le 30$.
|
| 45 |
+
|
| 46 |
+
Subtask 5 [ 200 points ]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
* There are no additional constraints.
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
* Print the maximum number of souvenirs they can get.
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Constraints
|
| 58 |
+
|
| 59 |
+
* $1 \le H, W \le 200$
|
| 60 |
+
* $0 \le a_{i, j} \le 10^5$
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Subtasks
|
| 65 |
+
|
| 66 |
+
Subtask 1 [ 50 points ]
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
* The testcase in the subtask satisfies $1 \le H \le 2$.
|
| 70 |
+
|
| 71 |
+
Subtask 2 [ 80 points ]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
* The testcase in the subtask satisfies $1 \le H \le 3$.
|
| 75 |
+
|
| 76 |
+
Subtask 3 [ 120 points ]
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
* The testcase in the subtask satisfies $1 \le H, W \le 7$.
|
| 80 |
+
|
| 81 |
+
Subtask 4 [ 150 points ]
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
* The testcase in the subtask satisfies $1 \le H, W \le 30$.
|
| 85 |
+
|
| 86 |
+
Subtask 5 [ 200 points ]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
* There are no additional constraints.
|
| 90 |
+
|
| 91 |
+
Input
|
| 92 |
+
|
| 93 |
+
The input is given from standard input in the following format.
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
|
| 97 |
+
|
| 98 |
+
Examples
|
| 99 |
+
|
| 100 |
+
Input
|
| 101 |
+
|
| 102 |
+
3 3
|
| 103 |
+
1 0 5
|
| 104 |
+
2 2 3
|
| 105 |
+
4 2 4
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
Output
|
| 109 |
+
|
| 110 |
+
21
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
Input
|
| 114 |
+
|
| 115 |
+
6 6
|
| 116 |
+
1 2 3 4 5 6
|
| 117 |
+
8 6 9 1 2 0
|
| 118 |
+
3 1 4 1 5 9
|
| 119 |
+
2 6 5 3 5 8
|
| 120 |
+
1 4 1 4 2 1
|
| 121 |
+
2 7 1 8 2 8
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
Output
|
| 125 |
+
|
| 126 |
+
97
|
| 127 |
+
|
| 128 |
+
## Contest Information
|
| 129 |
+
- **Contest ID**: 0
|
| 130 |
+
- **Problem Index**:
|
| 131 |
+
- **Points**: 0.0
|
| 132 |
+
- **Rating**: 0
|
| 133 |
+
- **Tags**:
|
| 134 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 135 |
+
- **Memory Limit**: 268435456 bytes
|
| 136 |
+
|
| 137 |
+
## Task
|
| 138 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0609/instruction.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00156 Moats around the Castle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible.
|
| 5 |
+
|
| 6 |
+
Create a program that takes a sketch of the castle as input and outputs the minimum number of times you have to crawl up from the moat from outside the castle to the castle tower. The sketch of the castle is given as a two-dimensional grid. The symbols drawn on the sketch show the positions of "&" indicating the position of the castle tower and "#" indicating the position of the moat, and "." (Half-width period) at other points. In addition, it is assumed that there is only one castle tower in the castle, and the ninja moves one square at a time in the north, south, east, and west directions when running or swimming, and does not move diagonally.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
n m
|
| 16 |
+
c1,1 c1,2 ... c1, n
|
| 17 |
+
c2,1c2,2 ... c2, n
|
| 18 |
+
::
|
| 19 |
+
cm, 1cm, 2 ... cm, n
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
The first line gives the east-west width n and the north-south width m (1 ≤ n, m ≤ 100) of the sketch. The following m lines give the information on the i-th line of the sketch. Each piece of information is a character string of length n consisting of the symbols "&", "#", and ".".
|
| 23 |
+
|
| 24 |
+
The number of datasets does not exceed 50.
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
Outputs the minimum number of times (integer) that must be climbed from the moat for each dataset on one line.
|
| 29 |
+
|
| 30 |
+
Examples
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
5 5
|
| 35 |
+
.###.
|
| 36 |
+
#...#
|
| 37 |
+
#.&.#
|
| 38 |
+
#...#
|
| 39 |
+
.###.
|
| 40 |
+
18 15
|
| 41 |
+
..####....####....
|
| 42 |
+
####..####....####
|
| 43 |
+
#...............##
|
| 44 |
+
.#.############.##
|
| 45 |
+
#..#..........#.##
|
| 46 |
+
.#.#.########.#.##
|
| 47 |
+
#..#.#......#.#.##
|
| 48 |
+
.#.#....&...#.#.##
|
| 49 |
+
#..#........#.#.##
|
| 50 |
+
.#.#.########.#.##
|
| 51 |
+
#..#..........#.##
|
| 52 |
+
.#.############.##
|
| 53 |
+
#...............##
|
| 54 |
+
.#################
|
| 55 |
+
##################
|
| 56 |
+
9 10
|
| 57 |
+
#########
|
| 58 |
+
........#
|
| 59 |
+
#######.#
|
| 60 |
+
#.....#.#
|
| 61 |
+
#.###.#.#
|
| 62 |
+
#.#&#.#.#
|
| 63 |
+
#.#...#.#
|
| 64 |
+
#.#####.#
|
| 65 |
+
#.......#
|
| 66 |
+
#########
|
| 67 |
+
9 3
|
| 68 |
+
###...###
|
| 69 |
+
#.#.&.#.#
|
| 70 |
+
###...###
|
| 71 |
+
0 0
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Output
|
| 75 |
+
|
| 76 |
+
1
|
| 77 |
+
2
|
| 78 |
+
0
|
| 79 |
+
0
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
Input
|
| 83 |
+
|
| 84 |
+
5 5
|
| 85 |
+
.###.
|
| 86 |
+
...#
|
| 87 |
+
.&.#
|
| 88 |
+
...#
|
| 89 |
+
.###.
|
| 90 |
+
18 15
|
| 91 |
+
..####....####....
|
| 92 |
+
..####....####
|
| 93 |
+
...............##
|
| 94 |
+
.#.############.##
|
| 95 |
+
..#..........#.##
|
| 96 |
+
.#.#.########.#.##
|
| 97 |
+
..#.#......#.#.##
|
| 98 |
+
.#.#....&...#.#.##
|
| 99 |
+
..#........#.#.##
|
| 100 |
+
.#.#.########.#.##
|
| 101 |
+
..#..........#.##
|
| 102 |
+
.#.############.##
|
| 103 |
+
...............##
|
| 104 |
+
.#################
|
| 105 |
+
|
| 106 |
+
9 10
|
| 107 |
+
|
| 108 |
+
........#
|
| 109 |
+
.#
|
| 110 |
+
.....#.#
|
| 111 |
+
.###.#.#
|
| 112 |
+
.#&#.#.#
|
| 113 |
+
.#...#.#
|
| 114 |
+
.#####.#
|
| 115 |
+
.......#
|
| 116 |
+
|
| 117 |
+
9 3
|
| 118 |
+
...###
|
| 119 |
+
.#.&.#.#
|
| 120 |
+
...###
|
| 121 |
+
0 0
|
| 122 |
+
</pre>
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
Output
|
| 126 |
+
|
| 127 |
+
1
|
| 128 |
+
2
|
| 129 |
+
0
|
| 130 |
+
0
|
| 131 |
+
|
| 132 |
+
## Contest Information
|
| 133 |
+
- **Contest ID**: 0
|
| 134 |
+
- **Problem Index**:
|
| 135 |
+
- **Points**: 0.0
|
| 136 |
+
- **Rating**: 0
|
| 137 |
+
- **Tags**:
|
| 138 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 139 |
+
- **Memory Limit**: 134217728 bytes
|
| 140 |
+
|
| 141 |
+
## Task
|
| 142 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0631/instruction.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1016_C. Vasya And The Mushrooms
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends exactly one minute to move to some adjacent cell. Vasya cannot leave the glade. Two cells are considered adjacent if they share a common side. When Vasya enters some cell, he instantly collects all the mushrooms growing there.
|
| 5 |
+
|
| 6 |
+
Vasya begins his journey in the left upper cell. Every minute Vasya must move to some adjacent cell, he cannot wait for the mushrooms to grow. He wants to visit all the cells exactly once and maximize the total weight of the collected mushrooms. Initially, all mushrooms have a weight of 0. Note that Vasya doesn't need to return to the starting cell.
|
| 7 |
+
|
| 8 |
+
Help Vasya! Calculate the maximum total weight of mushrooms he can collect.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains the number n (1 ≤ n ≤ 3·105) — the length of the glade.
|
| 13 |
+
|
| 14 |
+
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the growth rate of mushrooms in the first row of the glade.
|
| 15 |
+
|
| 16 |
+
The third line contains n numbers b1, b2, ..., bn (1 ≤ bi ≤ 106) is the growth rate of mushrooms in the second row of the glade.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Output one number — the maximum total weight of mushrooms that Vasya can collect by choosing the optimal route. Pay attention that Vasya must visit every cell of the glade exactly once.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
3
|
| 27 |
+
1 2 3
|
| 28 |
+
6 5 4
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
70
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
3
|
| 39 |
+
1 1000 10000
|
| 40 |
+
10 100 100000
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
543210
|
| 46 |
+
|
| 47 |
+
Note
|
| 48 |
+
|
| 49 |
+
In the first test case, the optimal route is as follows:
|
| 50 |
+
|
| 51 |
+
<image> Thus, the collected weight of mushrooms will be 0·1 + 1·2 + 2·3 + 3·4 + 4·5 + 5·6 = 70.
|
| 52 |
+
|
| 53 |
+
In the second test case, the optimal route is as follows:
|
| 54 |
+
|
| 55 |
+
<image> Thus, the collected weight of mushrooms will be 0·1 + 1·10 + 2·100 + 3·1000 + 4·10000 + 5·100000 = 543210.
|
| 56 |
+
|
| 57 |
+
## Contest Information
|
| 58 |
+
- **Contest ID**: 1016
|
| 59 |
+
- **Problem Index**: C
|
| 60 |
+
- **Points**: 0.0
|
| 61 |
+
- **Rating**: 1800
|
| 62 |
+
- **Tags**: dp, implementation
|
| 63 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 64 |
+
- **Memory Limit**: 256000000 bytes
|
| 65 |
+
|
| 66 |
+
## Task
|
| 67 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0653/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1493_C. K-beautiful Strings
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is lexicographically greater or equal to string s. If such a string does not exist, output -1.
|
| 5 |
+
|
| 6 |
+
A string a is lexicographically smaller than a string b if and only if one of the following holds:
|
| 7 |
+
|
| 8 |
+
* a is a prefix of b, but a ≠ b;
|
| 9 |
+
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
|
| 10 |
+
|
| 11 |
+
Input
|
| 12 |
+
|
| 13 |
+
The first line contains a single integer T (1 ≤ T ≤ 10 000) — the number of test cases.
|
| 14 |
+
|
| 15 |
+
The next 2 ⋅ T lines contain the description of test cases. The description of each test case consists of two lines.
|
| 16 |
+
|
| 17 |
+
The first line of the description contains two integers n and k (1 ≤ k ≤ n ≤ 10^5) — the length of string s and number k respectively.
|
| 18 |
+
|
| 19 |
+
The second line contains string s consisting of lowercase English letters.
|
| 20 |
+
|
| 21 |
+
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
For each test case output in a separate line lexicographically smallest beautiful string of length n, which is greater or equal to string s, or -1 if such a string does not exist.
|
| 26 |
+
|
| 27 |
+
Example
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
4
|
| 33 |
+
4 2
|
| 34 |
+
abcd
|
| 35 |
+
3 1
|
| 36 |
+
abc
|
| 37 |
+
4 3
|
| 38 |
+
aaaa
|
| 39 |
+
9 3
|
| 40 |
+
abaabaaaa
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Output
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
acac
|
| 47 |
+
abc
|
| 48 |
+
-1
|
| 49 |
+
abaabaaab
|
| 50 |
+
|
| 51 |
+
Note
|
| 52 |
+
|
| 53 |
+
In the first test case "acac" is greater than or equal to s, and each letter appears 2 or 0 times in it, so it is beautiful.
|
| 54 |
+
|
| 55 |
+
In the second test case each letter appears 0 or 1 times in s, so s itself is the answer.
|
| 56 |
+
|
| 57 |
+
We can show that there is no suitable string in the third test case.
|
| 58 |
+
|
| 59 |
+
In the fourth test case each letter appears 0, 3, or 6 times in "abaabaaab". All these integers are divisible by 3.
|
| 60 |
+
|
| 61 |
+
## Contest Information
|
| 62 |
+
- **Contest ID**: 1493
|
| 63 |
+
- **Problem Index**: C
|
| 64 |
+
- **Points**: 1750.0
|
| 65 |
+
- **Rating**: 2000
|
| 66 |
+
- **Tags**: binary search, brute force, constructive algorithms, greedy, strings
|
| 67 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 68 |
+
- **Memory Limit**: 256000000 bytes
|
| 69 |
+
|
| 70 |
+
## Task
|
| 71 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0662/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 312_D. Cats Transport
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1.
|
| 5 |
+
|
| 6 |
+
One day, the cats went out to play. Cat i went on a trip to hill hi, finished its trip at time ti, and then waited at hill hi for a feeder. The feeders must take all the cats. Each feeder goes straightly from hill 1 to n without waiting at a hill and takes all the waiting cats at each hill away. Feeders walk at a speed of 1 meter per unit time and are strong enough to take as many cats as they want.
|
| 7 |
+
|
| 8 |
+
For example, suppose we have two hills (d2 = 1) and one cat that finished its trip at time 3 at hill 2 (h1 = 2). Then if the feeder leaves hill 1 at time 2 or at time 3, he can take this cat, but if he leaves hill 1 at time 1 he can't take it. If the feeder leaves hill 1 at time 2, the cat waits him for 0 time units, if the feeder leaves hill 1 at time 3, the cat waits him for 1 time units.
|
| 9 |
+
|
| 10 |
+
Your task is to schedule the time leaving from hill 1 for each feeder so that the sum of the waiting time of all cats is minimized.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line of the input contains three integers n, m, p (2 ≤ n ≤ 105, 1 ≤ m ≤ 105, 1 ≤ p ≤ 100).
|
| 15 |
+
|
| 16 |
+
The second line contains n - 1 positive integers d2, d3, ..., dn (1 ≤ di < 104).
|
| 17 |
+
|
| 18 |
+
Each of the next m lines contains two integers hi and ti (1 ≤ hi ≤ n, 0 ≤ ti ≤ 109).
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Output an integer, the minimum sum of waiting time of all cats.
|
| 23 |
+
|
| 24 |
+
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
4 6 2
|
| 31 |
+
1 3 5
|
| 32 |
+
1 0
|
| 33 |
+
2 1
|
| 34 |
+
4 9
|
| 35 |
+
1 10
|
| 36 |
+
2 10
|
| 37 |
+
3 12
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
3
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 312
|
| 46 |
+
- **Problem Index**: D
|
| 47 |
+
- **Points**: 1000.0
|
| 48 |
+
- **Rating**: 2400
|
| 49 |
+
- **Tags**: data structures, dp
|
| 50 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 256000000 bytes
|
| 52 |
+
|
| 53 |
+
## Task
|
| 54 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|