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-0010/instruction.md +54 -0
- code_contests-0011/instruction.md +80 -0
- code_contests-0016/instruction.md +121 -0
- code_contests-0017/instruction.md +70 -0
- code_contests-0018/instruction.md +61 -0
- code_contests-0019/instruction.md +182 -0
- code_contests-0020/instruction.md +75 -0
- code_contests-0027/instruction.md +112 -0
- code_contests-0029/instruction.md +62 -0
- code_contests-0042/instruction.md +59 -0
- code_contests-0073/instruction.md +40 -0
- code_contests-0074/instruction.md +59 -0
- code_contests-0080/instruction.md +83 -0
- code_contests-0087/instruction.md +51 -0
- code_contests-0089/instruction.md +68 -0
- code_contests-0137/instruction.md +51 -0
- code_contests-0215/instruction.md +60 -0
- code_contests-0222/instruction.md +87 -0
- code_contests-0223/instruction.md +60 -0
- code_contests-0224/instruction.md +70 -0
- code_contests-0225/instruction.md +68 -0
- code_contests-0241/instruction.md +53 -0
- code_contests-0246/instruction.md +74 -0
- code_contests-0248/instruction.md +65 -0
- code_contests-0249/instruction.md +76 -0
- code_contests-0270/instruction.md +75 -0
- code_contests-0277/instruction.md +89 -0
- code_contests-0279/instruction.md +33 -0
- code_contests-0282/instruction.md +76 -0
- code_contests-0283/instruction.md +55 -0
- code_contests-0284/instruction.md +50 -0
- code_contests-0285/instruction.md +95 -0
- code_contests-0410/instruction.md +78 -0
- code_contests-0417/instruction.md +56 -0
- code_contests-0419/instruction.md +43 -0
- code_contests-0426/instruction.md +132 -0
- code_contests-0472/instruction.md +83 -0
- code_contests-0473/instruction.md +72 -0
- code_contests-0474/instruction.md +65 -0
- code_contests-0475/instruction.md +78 -0
- code_contests-0481/instruction.md +51 -0
- code_contests-0486/instruction.md +32 -0
- code_contests-0487/instruction.md +47 -0
- code_contests-0488/instruction.md +40 -0
- code_contests-0553/instruction.md +87 -0
- code_contests-0598/instruction.md +84 -0
- code_contests-0613/instruction.md +73 -0
- code_contests-0615/instruction.md +71 -0
- code_contests-0622/instruction.md +95 -0
- code_contests-0625/instruction.md +40 -0
code_contests-0010/instruction.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1101_A. Minimum Integer
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given q queries in the following form:
|
| 5 |
+
|
| 6 |
+
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
|
| 7 |
+
|
| 8 |
+
Can you answer all the queries?
|
| 9 |
+
|
| 10 |
+
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains one integer q (1 ≤ q ≤ 500) — the number of queries.
|
| 15 |
+
|
| 16 |
+
Then q lines follow, each containing a query given in the format l_i r_i d_i (1 ≤ l_i ≤ r_i ≤ 10^9, 1 ≤ d_i ≤ 10^9). l_i, r_i and d_i are integers.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
For each query print one integer: the answer to this query.
|
| 21 |
+
|
| 22 |
+
Example
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
5
|
| 28 |
+
2 4 2
|
| 29 |
+
5 10 4
|
| 30 |
+
3 10 1
|
| 31 |
+
1 2 3
|
| 32 |
+
4 6 5
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
6
|
| 39 |
+
4
|
| 40 |
+
1
|
| 41 |
+
3
|
| 42 |
+
10
|
| 43 |
+
|
| 44 |
+
## Contest Information
|
| 45 |
+
- **Contest ID**: 1101
|
| 46 |
+
- **Problem Index**: A
|
| 47 |
+
- **Points**: 0.0
|
| 48 |
+
- **Rating**: 1000
|
| 49 |
+
- **Tags**: math
|
| 50 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 51 |
+
- **Memory Limit**: 256000000 bytes
|
| 52 |
+
|
| 53 |
+
## Task
|
| 54 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0011/instruction.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1129_D. Isolation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Find the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once.
|
| 5 |
+
|
| 6 |
+
Since the answer can be large, find it modulo 998 244 353.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 10^5) — the number of elements in the array a and the restriction from the statement.
|
| 11 |
+
|
| 12 |
+
The following line contains n space-separated integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — elements of the array a.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
The first and only line contains the number of ways to divide an array a modulo 998 244 353.
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
3 1
|
| 24 |
+
1 1 2
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
3
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
5 2
|
| 37 |
+
1 1 2 1 3
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
14
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
5 5
|
| 50 |
+
1 2 3 4 5
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Output
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
16
|
| 57 |
+
|
| 58 |
+
Note
|
| 59 |
+
|
| 60 |
+
In the first sample, the three possible divisions are as follows.
|
| 61 |
+
|
| 62 |
+
* [[1], [1], [2]]
|
| 63 |
+
* [[1, 1], [2]]
|
| 64 |
+
* [[1, 1, 2]]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
Division [[1], [1, 2]] is not possible because two distinct integers appear exactly once in the second segment [1, 2].
|
| 69 |
+
|
| 70 |
+
## Contest Information
|
| 71 |
+
- **Contest ID**: 1129
|
| 72 |
+
- **Problem Index**: D
|
| 73 |
+
- **Points**: 2250.0
|
| 74 |
+
- **Rating**: 2900
|
| 75 |
+
- **Tags**: data structures, dp
|
| 76 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 77 |
+
- **Memory Limit**: 256000000 bytes
|
| 78 |
+
|
| 79 |
+
## Task
|
| 80 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0016/instruction.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1227_D1. Optimal Subsequences (Easy Version)
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
|
| 5 |
+
|
| 6 |
+
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:
|
| 7 |
+
|
| 8 |
+
* [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list);
|
| 9 |
+
* [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Suppose that an additional non-negative integer k (1 ≤ k ≤ n) is given, then the subsequence is called optimal if:
|
| 14 |
+
|
| 15 |
+
* it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k;
|
| 16 |
+
* and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≤ t ≤ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:
|
| 21 |
+
|
| 22 |
+
* [10, 20, 20] lexicographically less than [10, 21, 1],
|
| 23 |
+
* [7, 99, 99] is lexicographically less than [10, 21, 1],
|
| 24 |
+
* [10, 21, 0] is lexicographically less than [10, 21, 1].
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.
|
| 29 |
+
|
| 30 |
+
For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] — it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
The first line contains an integer n (1 ≤ n ≤ 100) — the length of the sequence a.
|
| 35 |
+
|
| 36 |
+
The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
|
| 37 |
+
|
| 38 |
+
The third line contains an integer m (1 ≤ m ≤ 100) — the number of requests.
|
| 39 |
+
|
| 40 |
+
The following m lines contain pairs of integers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j) — the requests.
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
Print m integers r_1, r_2, ..., r_m (1 ≤ r_j ≤ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.
|
| 45 |
+
|
| 46 |
+
Examples
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
3
|
| 52 |
+
10 20 10
|
| 53 |
+
6
|
| 54 |
+
1 1
|
| 55 |
+
2 1
|
| 56 |
+
2 2
|
| 57 |
+
3 1
|
| 58 |
+
3 2
|
| 59 |
+
3 3
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Output
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
20
|
| 66 |
+
10
|
| 67 |
+
20
|
| 68 |
+
10
|
| 69 |
+
20
|
| 70 |
+
10
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
Input
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
7
|
| 77 |
+
1 2 1 3 1 2 1
|
| 78 |
+
9
|
| 79 |
+
2 1
|
| 80 |
+
2 2
|
| 81 |
+
3 1
|
| 82 |
+
3 2
|
| 83 |
+
3 3
|
| 84 |
+
1 1
|
| 85 |
+
7 1
|
| 86 |
+
7 7
|
| 87 |
+
7 4
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Output
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
2
|
| 94 |
+
3
|
| 95 |
+
2
|
| 96 |
+
3
|
| 97 |
+
2
|
| 98 |
+
3
|
| 99 |
+
1
|
| 100 |
+
1
|
| 101 |
+
3
|
| 102 |
+
|
| 103 |
+
Note
|
| 104 |
+
|
| 105 |
+
In the first example, for a=[10,20,10] the optimal subsequences are:
|
| 106 |
+
|
| 107 |
+
* for k=1: [20],
|
| 108 |
+
* for k=2: [10,20],
|
| 109 |
+
* for k=3: [10,20,10].
|
| 110 |
+
|
| 111 |
+
## Contest Information
|
| 112 |
+
- **Contest ID**: 1227
|
| 113 |
+
- **Problem Index**: D1
|
| 114 |
+
- **Points**: 500.0
|
| 115 |
+
- **Rating**: 1600
|
| 116 |
+
- **Tags**: data structures, greedy
|
| 117 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 118 |
+
- **Memory Limit**: 256000000 bytes
|
| 119 |
+
|
| 120 |
+
## Task
|
| 121 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0017/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1250_B. The Feast and the Bus
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Employees of JebTrains are on their way to celebrate the 256-th day of the year! There are n employees and k teams in JebTrains. Each employee is a member of some (exactly one) team. All teams are numbered from 1 to k. You are given an array of numbers t_1, t_2, ..., t_n where t_i is the i-th employee's team number.
|
| 5 |
+
|
| 6 |
+
JebTrains is going to rent a single bus to get employees to the feast. The bus will take one or more rides. A bus can pick up an entire team or two entire teams. If three or more teams take a ride together they may start a new project which is considered unacceptable. It's prohibited to split a team, so all members of a team should take the same ride.
|
| 7 |
+
|
| 8 |
+
It is possible to rent a bus of any capacity s. Such a bus can take up to s people on a single ride. The total cost of the rent is equal to s ⋅ r burles where r is the number of rides. Note that it's impossible to rent two or more buses.
|
| 9 |
+
|
| 10 |
+
Help JebTrains to calculate the minimum cost of the rent, required to get all employees to the feast, fulfilling all the conditions above.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains two integers n and k (1 ≤ n ≤ 5⋅10^5, 1 ≤ k ≤ 8000) — the number of employees and the number of teams in JebTrains. The second line contains a sequence of integers t_1, t_2, ..., t_n, where t_i (1 ≤ t_i ≤ k) is the i-th employee's team number. Every team contains at least one employee.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
Print the minimum cost of the rent.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
6 3
|
| 26 |
+
3 1 2 3 2 3
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
6
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
10 1
|
| 39 |
+
1 1 1 1 1 1 1 1 1 1
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
10
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
12 4
|
| 52 |
+
1 2 3 1 2 3 4 1 2 1 2 1
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
12
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 1250
|
| 62 |
+
- **Problem Index**: B
|
| 63 |
+
- **Points**: 0.0
|
| 64 |
+
- **Rating**: 1800
|
| 65 |
+
- **Tags**: brute force, constructive algorithms, greedy, math
|
| 66 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 67 |
+
- **Memory Limit**: 512000000 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-0018/instruction.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1269_E. K Integers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given a permutation p_1, p_2, …, p_n.
|
| 5 |
+
|
| 6 |
+
In one move you can swap two adjacent values.
|
| 7 |
+
|
| 8 |
+
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k.
|
| 9 |
+
|
| 10 |
+
Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation.
|
| 11 |
+
|
| 12 |
+
You need to find f(1), f(2), …, f(n).
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of input contains one integer n (1 ≤ n ≤ 200 000): the number of elements in the permutation.
|
| 17 |
+
|
| 18 |
+
The next line of input contains n integers p_1, p_2, …, p_n: given permutation (1 ≤ p_i ≤ n).
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation, for k=1, 2, …, n.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
5
|
| 30 |
+
5 4 3 2 1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
0 1 3 6 10
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
3
|
| 43 |
+
1 2 3
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
0 0 0
|
| 50 |
+
|
| 51 |
+
## Contest Information
|
| 52 |
+
- **Contest ID**: 1269
|
| 53 |
+
- **Problem Index**: E
|
| 54 |
+
- **Points**: 1500.0
|
| 55 |
+
- **Rating**: 2300
|
| 56 |
+
- **Tags**: binary search, data structures
|
| 57 |
+
- **Time Limit**: {'seconds': 3, '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-0019/instruction.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1291_E. Prefix Enlightenment
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
|
| 5 |
+
|
| 6 |
+
You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅.
|
| 7 |
+
|
| 8 |
+
In one operation, you can choose one of these k subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.
|
| 9 |
+
|
| 10 |
+
Let m_i be the minimum number of operations you have to do in order to make the i first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1 and n), they can be either off or on.
|
| 11 |
+
|
| 12 |
+
You have to compute m_i for all 1 ≤ i ≤ n.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains two integers n and k (1 ≤ n, k ≤ 3 ⋅ 10^5).
|
| 17 |
+
|
| 18 |
+
The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if s_i = 0, on if s_i = 1).
|
| 19 |
+
|
| 20 |
+
The description of each one of the k subsets follows, in the following format:
|
| 21 |
+
|
| 22 |
+
The first line of the description contains a single integer c (1 ≤ c ≤ n) — the number of elements in the subset.
|
| 23 |
+
|
| 24 |
+
The second line of the description contains c distinct integers x_1, …, x_c (1 ≤ x_i ≤ n) — the elements of the subset.
|
| 25 |
+
|
| 26 |
+
It is guaranteed that:
|
| 27 |
+
|
| 28 |
+
* The intersection of any three subsets is empty;
|
| 29 |
+
* It's possible to make all lamps be simultaneously on using some operations.
|
| 30 |
+
|
| 31 |
+
Output
|
| 32 |
+
|
| 33 |
+
You must output n lines. The i-th line should contain a single integer m_i — the minimum number of operations required to make the lamps 1 to i be simultaneously on.
|
| 34 |
+
|
| 35 |
+
Examples
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
7 3
|
| 41 |
+
0011100
|
| 42 |
+
3
|
| 43 |
+
1 4 6
|
| 44 |
+
3
|
| 45 |
+
3 4 7
|
| 46 |
+
2
|
| 47 |
+
2 3
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
1
|
| 54 |
+
2
|
| 55 |
+
3
|
| 56 |
+
3
|
| 57 |
+
3
|
| 58 |
+
3
|
| 59 |
+
3
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
Input
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
8 6
|
| 66 |
+
00110011
|
| 67 |
+
3
|
| 68 |
+
1 3 8
|
| 69 |
+
5
|
| 70 |
+
1 2 5 6 7
|
| 71 |
+
2
|
| 72 |
+
6 8
|
| 73 |
+
2
|
| 74 |
+
3 5
|
| 75 |
+
2
|
| 76 |
+
4 7
|
| 77 |
+
1
|
| 78 |
+
2
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Output
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
1
|
| 85 |
+
1
|
| 86 |
+
1
|
| 87 |
+
1
|
| 88 |
+
1
|
| 89 |
+
1
|
| 90 |
+
4
|
| 91 |
+
4
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
Input
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
5 3
|
| 98 |
+
00011
|
| 99 |
+
3
|
| 100 |
+
1 2 3
|
| 101 |
+
1
|
| 102 |
+
4
|
| 103 |
+
3
|
| 104 |
+
3 4 5
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
Output
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
1
|
| 111 |
+
1
|
| 112 |
+
1
|
| 113 |
+
1
|
| 114 |
+
1
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
Input
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
19 5
|
| 121 |
+
1001001001100000110
|
| 122 |
+
2
|
| 123 |
+
2 3
|
| 124 |
+
2
|
| 125 |
+
5 6
|
| 126 |
+
2
|
| 127 |
+
8 9
|
| 128 |
+
5
|
| 129 |
+
12 13 14 15 16
|
| 130 |
+
1
|
| 131 |
+
19
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
Output
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
0
|
| 138 |
+
1
|
| 139 |
+
1
|
| 140 |
+
1
|
| 141 |
+
2
|
| 142 |
+
2
|
| 143 |
+
2
|
| 144 |
+
3
|
| 145 |
+
3
|
| 146 |
+
3
|
| 147 |
+
3
|
| 148 |
+
4
|
| 149 |
+
4
|
| 150 |
+
4
|
| 151 |
+
4
|
| 152 |
+
4
|
| 153 |
+
4
|
| 154 |
+
4
|
| 155 |
+
5
|
| 156 |
+
|
| 157 |
+
Note
|
| 158 |
+
|
| 159 |
+
In the first example:
|
| 160 |
+
|
| 161 |
+
* For i = 1, we can just apply one operation on A_1, the final states will be 1010110;
|
| 162 |
+
* For i = 2, we can apply operations on A_1 and A_3, the final states will be 1100110;
|
| 163 |
+
* For i ≥ 3, we can apply operations on A_1, A_2 and A_3, the final states will be 1111111.
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
In the second example:
|
| 168 |
+
|
| 169 |
+
* For i ≤ 6, we can just apply one operation on A_2, the final states will be 11111101;
|
| 170 |
+
* For i ≥ 7, we can apply operations on A_1, A_3, A_4, A_6, the final states will be 11111111.
|
| 171 |
+
|
| 172 |
+
## Contest Information
|
| 173 |
+
- **Contest ID**: 1291
|
| 174 |
+
- **Problem Index**: E
|
| 175 |
+
- **Points**: 1750.0
|
| 176 |
+
- **Rating**: 2400
|
| 177 |
+
- **Tags**: dfs and similar, dsu, graphs
|
| 178 |
+
- **Time Limit**: {'seconds': 3, 'nanos': 0} seconds
|
| 179 |
+
- **Memory Limit**: 256000000 bytes
|
| 180 |
+
|
| 181 |
+
## Task
|
| 182 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0020/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1311_F. Moving Points
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There are n points on a coordinate axis OX. The i-th point is located at the integer point x_i and has a speed v_i. It is guaranteed that no two points occupy the same coordinate. All n points move with the constant speed, the coordinate of the i-th point at the moment t (t can be non-integer) is calculated as x_i + t ⋅ v_i.
|
| 5 |
+
|
| 6 |
+
Consider two points i and j. Let d(i, j) be the minimum possible distance between these two points over any possible moments of time (even non-integer). It means that if two points i and j coincide at some moment, the value d(i, j) will be 0.
|
| 7 |
+
|
| 8 |
+
Your task is to calculate the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line of the input contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of points.
|
| 13 |
+
|
| 14 |
+
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^8), where x_i is the initial coordinate of the i-th point. It is guaranteed that all x_i are distinct.
|
| 15 |
+
|
| 16 |
+
The third line of the input contains n integers v_1, v_2, ..., v_n (-10^8 ≤ v_i ≤ 10^8), where v_i is the speed of the i-th point.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
Print one integer — the value ∑_{1 ≤ i < j ≤ n} d(i, j) (the sum of minimum distances over all pairs of points).
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
3
|
| 28 |
+
1 3 2
|
| 29 |
+
-100 2 3
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
3
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
5
|
| 42 |
+
2 1 4 3 5
|
| 43 |
+
2 2 2 3 4
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Output
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
19
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
2
|
| 56 |
+
2 1
|
| 57 |
+
-3 0
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
0
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 1311
|
| 67 |
+
- **Problem Index**: F
|
| 68 |
+
- **Points**: 0.0
|
| 69 |
+
- **Rating**: 1900
|
| 70 |
+
- **Tags**: data structures, divide and conquer, implementation, sortings
|
| 71 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 72 |
+
- **Memory Limit**: 256000000 bytes
|
| 73 |
+
|
| 74 |
+
## Task
|
| 75 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0027/instruction.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1466_F. Euclid's nightmare
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
|
| 5 |
+
|
| 6 |
+
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
|
| 7 |
+
|
| 8 |
+
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
|
| 9 |
+
|
| 10 |
+
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
|
| 11 |
+
|
| 12 |
+
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
|
| 13 |
+
|
| 14 |
+
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
In the first line of input, there are two integers n, m (1 ≤ n, m ≤ 5 ⋅ 10^5) denoting the number of vectors in S and the number of dimensions.
|
| 19 |
+
|
| 20 |
+
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 ≤ k ≤ 2) and then follow k distinct integers x_1, ... x_k (1 ≤ x_i ≤ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
|
| 21 |
+
|
| 22 |
+
Among the n vectors, no two are the same.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
3 2
|
| 34 |
+
1 1
|
| 35 |
+
1 2
|
| 36 |
+
2 2 1
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
4 2
|
| 43 |
+
1 2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
2 3
|
| 50 |
+
2 1 3
|
| 51 |
+
2 1 2
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
4 2
|
| 58 |
+
1 2
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Input
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
3 5
|
| 65 |
+
2 1 2
|
| 66 |
+
1 3
|
| 67 |
+
1 4
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Output
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
8 3
|
| 74 |
+
1 2 3
|
| 75 |
+
|
| 76 |
+
Note
|
| 77 |
+
|
| 78 |
+
In the first example we are given three vectors:
|
| 79 |
+
|
| 80 |
+
* 10
|
| 81 |
+
* 01
|
| 82 |
+
* 11
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
|
| 87 |
+
|
| 88 |
+
* 00 is a sum of the empty subset of above vectors;
|
| 89 |
+
* 01 = 11 + 10, is a sum of the first and third vector;
|
| 90 |
+
* 10 = 10, is just the first vector;
|
| 91 |
+
* 11 = 10 + 01, is a sum of the first and the second vector.
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
|
| 96 |
+
|
| 97 |
+
* 00 is a sum of the empty subset;
|
| 98 |
+
* 01 = 01 is just the second vector;
|
| 99 |
+
* 10 = 10 is just the first vector;
|
| 100 |
+
* 11 = 10 + 01 is a sum of the first and the second vector.
|
| 101 |
+
|
| 102 |
+
## Contest Information
|
| 103 |
+
- **Contest ID**: 1466
|
| 104 |
+
- **Problem Index**: F
|
| 105 |
+
- **Points**: 1750.0
|
| 106 |
+
- **Rating**: 2100
|
| 107 |
+
- **Tags**: bitmasks, dfs and similar, dsu, graphs, greedy, math, sortings
|
| 108 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 109 |
+
- **Memory Limit**: 256000000 bytes
|
| 110 |
+
|
| 111 |
+
## Task
|
| 112 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0029/instruction.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1513_C. Add One
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an integer n. You have to apply m operations to it.
|
| 5 |
+
|
| 6 |
+
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
|
| 7 |
+
|
| 8 |
+
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — the number of test cases.
|
| 13 |
+
|
| 14 |
+
The only line of each test case contains two integers n (1 ≤ n ≤ 10^9) and m (1 ≤ m ≤ 2 ⋅ 10^5) — the initial number and the number of operations.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
For each test case output the length of the resulting number modulo 10^9+7.
|
| 19 |
+
|
| 20 |
+
Example
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
5
|
| 26 |
+
1912 1
|
| 27 |
+
5 6
|
| 28 |
+
999 1
|
| 29 |
+
88 2
|
| 30 |
+
12 100
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
5
|
| 37 |
+
2
|
| 38 |
+
6
|
| 39 |
+
4
|
| 40 |
+
2115
|
| 41 |
+
|
| 42 |
+
Note
|
| 43 |
+
|
| 44 |
+
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
|
| 45 |
+
|
| 46 |
+
For the second test, 5 becomes 21 after 6 operations which is of length 2.
|
| 47 |
+
|
| 48 |
+
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
|
| 49 |
+
|
| 50 |
+
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.
|
| 51 |
+
|
| 52 |
+
## Contest Information
|
| 53 |
+
- **Contest ID**: 1513
|
| 54 |
+
- **Problem Index**: C
|
| 55 |
+
- **Points**: 1500.0
|
| 56 |
+
- **Rating**: 1600
|
| 57 |
+
- **Tags**: dp, matrices
|
| 58 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 59 |
+
- **Memory Limit**: 256000000 bytes
|
| 60 |
+
|
| 61 |
+
## Task
|
| 62 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0042/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 425_D. Sereja and Squares
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.
|
| 5 |
+
|
| 6 |
+
Input
|
| 7 |
+
|
| 8 |
+
The first line contains integer n (1 ≤ n ≤ 105). Each of the next n lines contains two integers xi, yi (0 ≤ xi, yi ≤ 105), the integers represent the coordinates of the i-th point. It is guaranteed that all the given points are distinct.
|
| 9 |
+
|
| 10 |
+
Output
|
| 11 |
+
|
| 12 |
+
In a single line print the required number of squares.
|
| 13 |
+
|
| 14 |
+
Examples
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
5
|
| 19 |
+
0 0
|
| 20 |
+
0 2
|
| 21 |
+
2 0
|
| 22 |
+
2 2
|
| 23 |
+
1 1
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
1
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
0 0
|
| 35 |
+
1 1
|
| 36 |
+
2 2
|
| 37 |
+
0 1
|
| 38 |
+
1 0
|
| 39 |
+
0 2
|
| 40 |
+
2 0
|
| 41 |
+
1 2
|
| 42 |
+
2 1
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
5
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 425
|
| 51 |
+
- **Problem Index**: D
|
| 52 |
+
- **Points**: 2000.0
|
| 53 |
+
- **Rating**: 2300
|
| 54 |
+
- **Tags**: binary search, data structures, hashing
|
| 55 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 56 |
+
- **Memory Limit**: 512000000 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-0073/instruction.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# playing-with-substrings
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Description
|
| 5 |
+
You are given two strings S and T, such that length of S is greater than the length of T.
|
| 6 |
+
Then a substring of S is defined as a sequence of characters which appear consecutively in S.
|
| 7 |
+
|
| 8 |
+
Find the total number of distinct substrings of M such that T is a substring of M
|
| 9 |
+
|
| 10 |
+
Input Format
|
| 11 |
+
One line containing strings S and T separated by a space.
|
| 12 |
+
|
| 13 |
+
Output Format
|
| 14 |
+
One line containing the number of distinct substrings of M such that T is a substring of M
|
| 15 |
+
|
| 16 |
+
Input Limits:
|
| 17 |
+
0 < Length(S), Length(T) < 100
|
| 18 |
+
|
| 19 |
+
SAMPLE INPUT
|
| 20 |
+
abcc c
|
| 21 |
+
|
| 22 |
+
SAMPLE OUTPUT
|
| 23 |
+
6
|
| 24 |
+
|
| 25 |
+
Explanation
|
| 26 |
+
|
| 27 |
+
Suppose the string S is abcc. Then the distinct substrings of S are
|
| 28 |
+
a, b, c, ab, bc, cc, abc, bcc, abcc
|
| 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-0074/instruction.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# roys-life-cycle
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Roy is going through the dark times of his life. Recently his girl friend broke up with him and to overcome the pain of acute misery he decided to restrict himself to Eat-Sleep-Code life cycle. For N days he did nothing but eat, sleep and code.
|
| 5 |
+
|
| 6 |
+
A close friend of Roy kept an eye on him for last N days. For every single minute of the day, he kept track of Roy's actions and prepared a log file.
|
| 7 |
+
|
| 8 |
+
The log file contains exactly N lines, each line contains a string of length 1440 ( i.e. number of minutes in 24 hours of the day).
|
| 9 |
+
The string is made of characters E, S, and C only; representing Eat, Sleep and Code respectively. i^th character of the string represents what Roy was doing during i^th minute of the day.
|
| 10 |
+
|
| 11 |
+
Roy's friend is now interested in finding out the maximum of longest coding streak of the day - X.
|
| 12 |
+
He also wants to find the longest coding streak of N days - Y.
|
| 13 |
+
Coding streak means number of C's without any E or S in between.
|
| 14 |
+
|
| 15 |
+
See sample test case for clarification.
|
| 16 |
+
|
| 17 |
+
Input:
|
| 18 |
+
First line of each file contains N - number of days.
|
| 19 |
+
Following N lines contains a string of exactly 1440 length representing his activity on that day.
|
| 20 |
+
|
| 21 |
+
Output:
|
| 22 |
+
Print X and Y separated by a space in a single line.
|
| 23 |
+
|
| 24 |
+
Constraints:
|
| 25 |
+
1 ≤ N ≤ 365
|
| 26 |
+
String consists of characters E, S, and C only.
|
| 27 |
+
String length is exactly 1440.
|
| 28 |
+
|
| 29 |
+
Note: The sample test case does not follow the given constraints on string length to avoid large data. It is meant only for explanation. We assure you that the hidden test files strictly follow the constraints.
|
| 30 |
+
|
| 31 |
+
SAMPLE INPUT
|
| 32 |
+
4
|
| 33 |
+
SSSSEEEECCCCEECCCC
|
| 34 |
+
CCCCCSSSSEEECCCCSS
|
| 35 |
+
SSSSSEEESSCCCCCCCS
|
| 36 |
+
EESSSSCCCCCCSSEEEESAMPLE OUTPUT
|
| 37 |
+
7 9Explanation
|
| 38 |
+
|
| 39 |
+
Longest coding streak for each day is as follows:
|
| 40 |
+
Day 1: 4
|
| 41 |
+
Day 2: 5
|
| 42 |
+
Day 3: 7
|
| 43 |
+
Day 4: 6
|
| 44 |
+
Maximum of these is 7, hence X is 7.
|
| 45 |
+
|
| 46 |
+
Now in order to find longest coding streak of the all days, we should also check if Roy continued his coding from previous days.
|
| 47 |
+
As in the sample test case, Roy was coding for 4 minutes at the end of Day 1 and he continued to code till 5 more minutes on Day 2. Hence the longest coding streak is 4+5 equals 9. There is no any other coding streak larger than this. So the longest coding streak of all days is 9.
|
| 48 |
+
|
| 49 |
+
## Contest Information
|
| 50 |
+
- **Contest ID**: 0
|
| 51 |
+
- **Problem Index**:
|
| 52 |
+
- **Points**: 0.0
|
| 53 |
+
- **Rating**: 0
|
| 54 |
+
- **Tags**: None
|
| 55 |
+
- **Time Limit**: None seconds
|
| 56 |
+
- **Memory Limit**: 0 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-0080/instruction.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p03013 AtCoder Beginner Contest 129 - Typical Stairs
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time.
|
| 5 |
+
|
| 6 |
+
However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.
|
| 7 |
+
|
| 8 |
+
How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007.
|
| 9 |
+
|
| 10 |
+
Constraints
|
| 11 |
+
|
| 12 |
+
* 1 \leq N \leq 10^5
|
| 13 |
+
* 0 \leq M \leq N-1
|
| 14 |
+
* 1 \leq a_1 < a_2 < ... < a_M \leq N-1
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
Input is given from Standard Input in the following format:
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
N M
|
| 22 |
+
a_1
|
| 23 |
+
a_2
|
| 24 |
+
.
|
| 25 |
+
.
|
| 26 |
+
.
|
| 27 |
+
a_M
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.
|
| 33 |
+
|
| 34 |
+
Examples
|
| 35 |
+
|
| 36 |
+
Input
|
| 37 |
+
|
| 38 |
+
6 1
|
| 39 |
+
3
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
4
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Input
|
| 48 |
+
|
| 49 |
+
10 2
|
| 50 |
+
4
|
| 51 |
+
5
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
0
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Input
|
| 60 |
+
|
| 61 |
+
100 5
|
| 62 |
+
1
|
| 63 |
+
23
|
| 64 |
+
45
|
| 65 |
+
67
|
| 66 |
+
89
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Output
|
| 70 |
+
|
| 71 |
+
608200469
|
| 72 |
+
|
| 73 |
+
## Contest Information
|
| 74 |
+
- **Contest ID**: 0
|
| 75 |
+
- **Problem Index**:
|
| 76 |
+
- **Points**: 0.0
|
| 77 |
+
- **Rating**: 0
|
| 78 |
+
- **Tags**:
|
| 79 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 80 |
+
- **Memory Limit**: 1073741824 bytes
|
| 81 |
+
|
| 82 |
+
## Task
|
| 83 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0087/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00035 Is it Convex?
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
4 different points on the plane Read the coordinates of $ A (x_a, y_a) $, $ B (x_b, y_b) $, $ C (x_c, y_c) $, $ D (x_d, y_d) $ and read those 4 points Create a program that outputs YES if there is no dent in the quadrangle $ ABCD $ with the coordinates as the vertices, and NO if there is a dent.
|
| 5 |
+
|
| 6 |
+
A quadrangle with a dent is a quadrangle as shown in Figure 1.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
Given multiple datasets. The format of each dataset is as follows.
|
| 15 |
+
|
| 16 |
+
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $
|
| 17 |
+
|
| 18 |
+
$ x_a $, $ y_a $, $ x_b $, $ y_b $, $ x_c $, $ y_c $, $ x_d $, $ y_d $ are -100 or more and 100 or less, respectively, and are given as real numbers.
|
| 19 |
+
|
| 20 |
+
1 No more than two points can be lined up on a straight line. Also, if you connect the points in the order of input, the coordinates of the points will be input in the order of forming a quadrangle. (That is, the points are not given in the order shown in Figure 2.)
|
| 21 |
+
|
| 22 |
+
The number of datasets does not exceed 100.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print YES or NO on one line for each dataset.
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0
|
| 33 |
+
0.0,0.0,3.0,0.0,1.0,1.0,1.0,3.0
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
YES
|
| 39 |
+
NO
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 0
|
| 43 |
+
- **Problem Index**:
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 0
|
| 46 |
+
- **Tags**:
|
| 47 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 48 |
+
- **Memory Limit**: 134217728 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-0089/instruction.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00323 Metal Recycling
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
|
| 5 |
+
|
| 6 |
+
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
|
| 7 |
+
|
| 8 |
+
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
|
| 9 |
+
|
| 10 |
+
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The input is given in the following format.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
N
|
| 20 |
+
a1 b1
|
| 21 |
+
a2 b2
|
| 22 |
+
::
|
| 23 |
+
aN bN
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
3
|
| 37 |
+
2 1
|
| 38 |
+
1 3
|
| 39 |
+
2 2
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Output
|
| 43 |
+
|
| 44 |
+
3 0
|
| 45 |
+
5 0
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Input
|
| 49 |
+
|
| 50 |
+
1
|
| 51 |
+
100000 2
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Output
|
| 55 |
+
|
| 56 |
+
100002 0
|
| 57 |
+
|
| 58 |
+
## Contest Information
|
| 59 |
+
- **Contest ID**: 0
|
| 60 |
+
- **Problem Index**:
|
| 61 |
+
- **Points**: 0.0
|
| 62 |
+
- **Rating**: 0
|
| 63 |
+
- **Tags**:
|
| 64 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 65 |
+
- **Memory Limit**: 268435456 bytes
|
| 66 |
+
|
| 67 |
+
## Task
|
| 68 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0137/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 219_A. k-String
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
|
| 5 |
+
|
| 6 |
+
You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.
|
| 15 |
+
|
| 16 |
+
If the solution doesn't exist, print "-1" (without quotes).
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
2
|
| 23 |
+
aazz
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
azaz
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Input
|
| 32 |
+
|
| 33 |
+
3
|
| 34 |
+
abcabcabz
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
-1
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 219
|
| 43 |
+
- **Problem Index**: A
|
| 44 |
+
- **Points**: 500.0
|
| 45 |
+
- **Rating**: 1000
|
| 46 |
+
- **Tags**: implementation, strings
|
| 47 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 48 |
+
- **Memory Limit**: 256000000 bytes
|
| 49 |
+
|
| 50 |
+
## Task
|
| 51 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0215/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1037_B. Reach Median
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an array a of n integers and an integer s. It is guaranteed that n is odd.
|
| 5 |
+
|
| 6 |
+
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s.
|
| 7 |
+
|
| 8 |
+
The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two integers n and s (1≤ n≤ 2⋅ 10^5-1, 1≤ s≤ 10^9) — the length of the array and the required value of median.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers a_1, a_2, …, a_n (1≤ a_i ≤ 10^9) — the elements of the array a.
|
| 15 |
+
|
| 16 |
+
It is guaranteed that n is odd.
|
| 17 |
+
|
| 18 |
+
Output
|
| 19 |
+
|
| 20 |
+
In a single line output the minimum number of operations to make the median being equal to s.
|
| 21 |
+
|
| 22 |
+
Examples
|
| 23 |
+
|
| 24 |
+
Input
|
| 25 |
+
|
| 26 |
+
3 8
|
| 27 |
+
6 5 8
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
2
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
7 20
|
| 37 |
+
21 15 12 11 20 19 12
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
6
|
| 43 |
+
|
| 44 |
+
Note
|
| 45 |
+
|
| 46 |
+
In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8.
|
| 47 |
+
|
| 48 |
+
In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20.
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 1037
|
| 52 |
+
- **Problem Index**: B
|
| 53 |
+
- **Points**: 750.0
|
| 54 |
+
- **Rating**: 1300
|
| 55 |
+
- **Tags**: greedy
|
| 56 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0222/instruction.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1189_A. Keanu Reeves
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
|
| 5 |
+
|
| 6 |
+
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good.
|
| 7 |
+
|
| 8 |
+
We are given a string s of length n consisting of only zeroes and ones. We need to cut s into minimal possible number of substrings s_1, s_2, …, s_k such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings s_1, s_2, …, s_k such that their concatenation (joining) equals s, i.e. s_1 + s_2 + ... + s_k = s.
|
| 9 |
+
|
| 10 |
+
For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all 3 strings are good.
|
| 11 |
+
|
| 12 |
+
Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line of the input contains a single integer n (1≤ n ≤ 100) — the length of the string s.
|
| 17 |
+
|
| 18 |
+
The second line contains the string s of length n consisting only from zeros and ones.
|
| 19 |
+
|
| 20 |
+
Output
|
| 21 |
+
|
| 22 |
+
In the first line, output a single integer k (1≤ k) — a minimal number of strings you have cut s into.
|
| 23 |
+
|
| 24 |
+
In the second line, output k strings s_1, s_2, …, s_k separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to s and all of them have to be good.
|
| 25 |
+
|
| 26 |
+
If there are multiple answers, print any.
|
| 27 |
+
|
| 28 |
+
Examples
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
1
|
| 34 |
+
1
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
1
|
| 41 |
+
1
|
| 42 |
+
|
| 43 |
+
Input
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
2
|
| 47 |
+
10
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
2
|
| 54 |
+
1 0
|
| 55 |
+
|
| 56 |
+
Input
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
6
|
| 60 |
+
100011
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
Output
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
2
|
| 67 |
+
100 011
|
| 68 |
+
|
| 69 |
+
Note
|
| 70 |
+
|
| 71 |
+
In the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied.
|
| 72 |
+
|
| 73 |
+
In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal.
|
| 74 |
+
|
| 75 |
+
In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal.
|
| 76 |
+
|
| 77 |
+
## Contest Information
|
| 78 |
+
- **Contest ID**: 1189
|
| 79 |
+
- **Problem Index**: A
|
| 80 |
+
- **Points**: 500.0
|
| 81 |
+
- **Rating**: 800
|
| 82 |
+
- **Tags**: strings
|
| 83 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 84 |
+
- **Memory Limit**: 256000000 bytes
|
| 85 |
+
|
| 86 |
+
## Task
|
| 87 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0223/instruction.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1208_A. XORinacci
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
|
| 5 |
+
|
| 6 |
+
* f(0) = a;
|
| 7 |
+
* f(1) = b;
|
| 8 |
+
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
You are given three integers a, b, and n, calculate f(n).
|
| 13 |
+
|
| 14 |
+
You have to answer for T independent test cases.
|
| 15 |
+
|
| 16 |
+
Input
|
| 17 |
+
|
| 18 |
+
The input contains one or more independent test cases.
|
| 19 |
+
|
| 20 |
+
The first line of input contains a single integer T (1 ≤ T ≤ 10^3), the number of test cases.
|
| 21 |
+
|
| 22 |
+
Each of the T following lines contains three space-separated integers a, b, and n (0 ≤ a, b, n ≤ 10^9) respectively.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
For each test case, output f(n).
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
3
|
| 34 |
+
3 4 2
|
| 35 |
+
4 5 0
|
| 36 |
+
325 265 1231232
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
7
|
| 43 |
+
4
|
| 44 |
+
76
|
| 45 |
+
|
| 46 |
+
Note
|
| 47 |
+
|
| 48 |
+
In the first example, f(2) = f(0) ⊕ f(1) = 3 ⊕ 4 = 7.
|
| 49 |
+
|
| 50 |
+
## Contest Information
|
| 51 |
+
- **Contest ID**: 1208
|
| 52 |
+
- **Problem Index**: A
|
| 53 |
+
- **Points**: 500.0
|
| 54 |
+
- **Rating**: 900
|
| 55 |
+
- **Tags**: math
|
| 56 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 57 |
+
- **Memory Limit**: 256000000 bytes
|
| 58 |
+
|
| 59 |
+
## Task
|
| 60 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0224/instruction.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1227_A. Math Problem
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Your math teacher gave you the following problem:
|
| 5 |
+
|
| 6 |
+
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
|
| 7 |
+
|
| 8 |
+
Two segments [a; b] and [c; d] have a common point (intersect) if there exists x that a ≤ x ≤ b and c ≤ x ≤ d. For example, [2; 5] and [3; 10] have a common point, but [5; 6] and [1; 4] don't have.
|
| 9 |
+
|
| 10 |
+
You should add one segment, which has at least one common point with each of the given segments and as short as possible (i.e. has minimal length). The required segment can degenerate to be a point (i.e a segment with length zero). The added segment may or may not be among the given n segments.
|
| 11 |
+
|
| 12 |
+
In other words, you need to find a segment [a; b], such that [a; b] and every [l_i; r_i] have a common point for each i, and b-a is minimal.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains integer number t (1 ≤ t ≤ 100) — the number of test cases in the input. Then t test cases follow.
|
| 17 |
+
|
| 18 |
+
The first line of each test case contains one integer n (1 ≤ n ≤ 10^{5}) — the number of segments. The following n lines contain segment descriptions: the i-th of them contains two integers l_i,r_i (1 ≤ l_i ≤ r_i ≤ 10^{9}).
|
| 19 |
+
|
| 20 |
+
The sum of all values n over all the test cases in the input doesn't exceed 10^5.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
For each test case, output one integer — the smallest possible length of the segment which has at least one common point with all given segments.
|
| 25 |
+
|
| 26 |
+
Example
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
4
|
| 32 |
+
3
|
| 33 |
+
4 5
|
| 34 |
+
5 9
|
| 35 |
+
7 7
|
| 36 |
+
5
|
| 37 |
+
11 19
|
| 38 |
+
4 17
|
| 39 |
+
16 16
|
| 40 |
+
3 12
|
| 41 |
+
14 17
|
| 42 |
+
1
|
| 43 |
+
1 10
|
| 44 |
+
1
|
| 45 |
+
1 1
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
2
|
| 52 |
+
4
|
| 53 |
+
0
|
| 54 |
+
0
|
| 55 |
+
|
| 56 |
+
Note
|
| 57 |
+
|
| 58 |
+
In the first test case of the example, we can choose the segment [5;7] as the answer. It is the shortest segment that has at least one common point with all given segments.
|
| 59 |
+
|
| 60 |
+
## Contest Information
|
| 61 |
+
- **Contest ID**: 1227
|
| 62 |
+
- **Problem Index**: A
|
| 63 |
+
- **Points**: 500.0
|
| 64 |
+
- **Rating**: 1100
|
| 65 |
+
- **Tags**: math
|
| 66 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 67 |
+
- **Memory Limit**: 256000000 bytes
|
| 68 |
+
|
| 69 |
+
## Task
|
| 70 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0225/instruction.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 124_D. Squares
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
|
| 5 |
+
|
| 6 |
+
A square (x; y) is considered bad, if at least one of the two conditions is fulfilled:
|
| 7 |
+
|
| 8 |
+
* |x + y| ≡ 0 (mod 2a),
|
| 9 |
+
* |x - y| ≡ 0 (mod 2b).
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).
|
| 14 |
+
|
| 15 |
+
Input
|
| 16 |
+
|
| 17 |
+
The only line contains integers a, b, x1, y1, x2 and y2 — the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 ≤ a, b ≤ 109 and |x1|,|y1|,|x2|,|y2| ≤ 109). It is guaranteed that the initial and the final square aren't bad.
|
| 18 |
+
|
| 19 |
+
Output
|
| 20 |
+
|
| 21 |
+
Print a single number — the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
|
| 25 |
+
Input
|
| 26 |
+
|
| 27 |
+
2 2 1 0 0 1
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
1
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
2 2 10 11 0 1
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Output
|
| 41 |
+
|
| 42 |
+
5
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Input
|
| 46 |
+
|
| 47 |
+
2 4 3 -1 3 7
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Output
|
| 51 |
+
|
| 52 |
+
2
|
| 53 |
+
|
| 54 |
+
Note
|
| 55 |
+
|
| 56 |
+
In the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad.
|
| 57 |
+
|
| 58 |
+
## Contest Information
|
| 59 |
+
- **Contest ID**: 124
|
| 60 |
+
- **Problem Index**: D
|
| 61 |
+
- **Points**: 1000.0
|
| 62 |
+
- **Rating**: 1800
|
| 63 |
+
- **Tags**: math
|
| 64 |
+
- **Time Limit**: {'seconds': 0, 'nanos': 500000000} seconds
|
| 65 |
+
- **Memory Limit**: 256000000 bytes
|
| 66 |
+
|
| 67 |
+
## Task
|
| 68 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0241/instruction.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 209_B. Pixels
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z ≠ x; z ≠ y). Pixels of the same color are friends, so they don't fight.
|
| 5 |
+
|
| 6 |
+
The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains three space-separated integers a, b and c (0 ≤ a, b, c ≤ 231; a + b + c > 0) — the number of red, green and blue pixels, correspondingly.
|
| 11 |
+
|
| 12 |
+
Output
|
| 13 |
+
|
| 14 |
+
Print a single number — the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.
|
| 15 |
+
|
| 16 |
+
Examples
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
1 1 1
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
1
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
3 1 0
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Output
|
| 34 |
+
|
| 35 |
+
3
|
| 36 |
+
|
| 37 |
+
Note
|
| 38 |
+
|
| 39 |
+
In the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.
|
| 40 |
+
|
| 41 |
+
In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.
|
| 42 |
+
|
| 43 |
+
## Contest Information
|
| 44 |
+
- **Contest ID**: 209
|
| 45 |
+
- **Problem Index**: B
|
| 46 |
+
- **Points**: 500.0
|
| 47 |
+
- **Rating**: 2100
|
| 48 |
+
- **Tags**: constructive algorithms, math
|
| 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-0246/instruction.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 331_D2. Escaping on Beaveractor
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Don't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a b × b square on a plane. Each point x, y (0 ≤ x, y ≤ b) belongs to BSA. To make the path quick and funny, the Beaver constructed a Beaveractor, an effective and comfortable types of transport.
|
| 5 |
+
|
| 6 |
+
The campus obeys traffic rules: there are n arrows, parallel to the coordinate axes. The arrows do not intersect and do not touch each other. When the Beaveractor reaches some arrow, it turns in the arrow's direction and moves on until it either reaches the next arrow or gets outside the campus. The Beaveractor covers exactly one unit of space per one unit of time. You can assume that there are no obstacles to the Beaveractor.
|
| 7 |
+
|
| 8 |
+
The BSA scientists want to transport the brand new Beaveractor to the "Academic Tractor" research institute and send the Smart Beaver to do his postgraduate studies and sharpen pencils. They have q plans, representing the Beaveractor's initial position (xi, yi), the initial motion vector wi and the time ti that have passed after the escape started.
|
| 9 |
+
|
| 10 |
+
Your task is for each of the q plans to determine the Smart Beaver's position after the given time.
|
| 11 |
+
|
| 12 |
+
Input
|
| 13 |
+
|
| 14 |
+
The first line contains two integers: the number of traffic rules n and the size of the campus b, 0 ≤ n, 1 ≤ b. Next n lines contain the rules. Each line of the rules contains four space-separated integers x0, y0, x1, y1 — the beginning and the end of the arrow. It is guaranteed that all arrows are parallel to the coordinate axes and have no common points. All arrows are located inside the campus, that is, 0 ≤ x0, y0, x1, y1 ≤ b holds.
|
| 15 |
+
|
| 16 |
+
Next line contains integer q — the number of plans the scientists have, 1 ≤ q ≤ 105. The i-th plan is represented by two integers, xi, yi are the Beaveractor's coordinates at the initial time, 0 ≤ xi, yi ≤ b, character wi, that takes value U, D, L, R and sets the initial direction up, down, to the left or to the right correspondingly (the Y axis is directed upwards), and ti — the time passed after the escape started, 0 ≤ ti ≤ 1015.
|
| 17 |
+
|
| 18 |
+
* to get 30 points you need to solve the problem with constraints n, b ≤ 30 (subproblem D1);
|
| 19 |
+
* to get 60 points you need to solve the problem with constraints n, b ≤ 1000 (subproblems D1+D2);
|
| 20 |
+
* to get 100 points you need to solve the problem with constraints n, b ≤ 105 (subproblems D1+D2+D3).
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
Print q lines. Each line should contain two integers — the Beaveractor's coordinates at the final moment of time for each plan. If the Smart Beaver manages to leave the campus in time ti, print the coordinates of the last point in the campus he visited.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
3 3
|
| 31 |
+
0 0 0 1
|
| 32 |
+
0 2 2 2
|
| 33 |
+
3 3 2 3
|
| 34 |
+
12
|
| 35 |
+
0 0 L 0
|
| 36 |
+
0 0 L 1
|
| 37 |
+
0 0 L 2
|
| 38 |
+
0 0 L 3
|
| 39 |
+
0 0 L 4
|
| 40 |
+
0 0 L 5
|
| 41 |
+
0 0 L 6
|
| 42 |
+
2 0 U 2
|
| 43 |
+
2 0 U 3
|
| 44 |
+
3 0 U 5
|
| 45 |
+
1 3 D 2
|
| 46 |
+
1 3 R 2
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
0 0
|
| 52 |
+
0 1
|
| 53 |
+
0 2
|
| 54 |
+
1 2
|
| 55 |
+
2 2
|
| 56 |
+
3 2
|
| 57 |
+
3 2
|
| 58 |
+
2 2
|
| 59 |
+
3 2
|
| 60 |
+
1 3
|
| 61 |
+
2 2
|
| 62 |
+
1 3
|
| 63 |
+
|
| 64 |
+
## Contest Information
|
| 65 |
+
- **Contest ID**: 331
|
| 66 |
+
- **Problem Index**: D2
|
| 67 |
+
- **Points**: 30.0
|
| 68 |
+
- **Rating**: 2600
|
| 69 |
+
- **Tags**: graphs
|
| 70 |
+
- **Time Limit**: {'seconds': 6, '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-0248/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 378_C. Maze
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
|
| 5 |
+
|
| 6 |
+
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.
|
| 11 |
+
|
| 12 |
+
Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
|
| 17 |
+
|
| 18 |
+
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3 4 2
|
| 25 |
+
#..#
|
| 26 |
+
..#.
|
| 27 |
+
#...
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
#.X#
|
| 33 |
+
X.#.
|
| 34 |
+
#...
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Input
|
| 38 |
+
|
| 39 |
+
5 4 5
|
| 40 |
+
#...
|
| 41 |
+
#.#.
|
| 42 |
+
.#..
|
| 43 |
+
...#
|
| 44 |
+
.#.#
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
#XXX
|
| 50 |
+
#X#.
|
| 51 |
+
X#..
|
| 52 |
+
...#
|
| 53 |
+
.#.#
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 378
|
| 57 |
+
- **Problem Index**: C
|
| 58 |
+
- **Points**: 500.0
|
| 59 |
+
- **Rating**: 1600
|
| 60 |
+
- **Tags**: dfs and similar
|
| 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-0249/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 39_E. What Has Dirichlet Got to Do with That?
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items.
|
| 5 |
+
|
| 6 |
+
Having heard of that principle, but having not mastered the technique of logical thinking, 8 year olds Stas and Masha invented a game. There are a different boxes and b different items, and each turn a player can either add a new box or a new item. The player, after whose turn the number of ways of putting b items into a boxes becomes no less then a certain given number n, loses. All the boxes and items are considered to be different. Boxes may remain empty.
|
| 7 |
+
|
| 8 |
+
Who loses if both players play optimally and Stas's turn is first?
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The only input line has three integers a, b, n (1 ≤ a ≤ 10000, 1 ≤ b ≤ 30, 2 ≤ n ≤ 109) — the initial number of the boxes, the number of the items and the number which constrains the number of ways, respectively. Guaranteed that the initial number of ways is strictly less than n.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
Output "Stas" if Masha wins. Output "Masha" if Stas wins. In case of a draw, output "Missing".
|
| 17 |
+
|
| 18 |
+
Examples
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
2 2 10
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Output
|
| 26 |
+
|
| 27 |
+
Masha
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
5 5 16808
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
Masha
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
Input
|
| 41 |
+
|
| 42 |
+
3 1 4
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
Stas
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
Input
|
| 51 |
+
|
| 52 |
+
1 4 10
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Output
|
| 56 |
+
|
| 57 |
+
Missing
|
| 58 |
+
|
| 59 |
+
Note
|
| 60 |
+
|
| 61 |
+
In the second example the initial number of ways is equal to 3125.
|
| 62 |
+
|
| 63 |
+
* If Stas increases the number of boxes, he will lose, as Masha may increase the number of boxes once more during her turn. After that any Stas's move will lead to defeat.
|
| 64 |
+
* But if Stas increases the number of items, then any Masha's move will be losing.
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 39
|
| 68 |
+
- **Problem Index**: E
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 2000
|
| 71 |
+
- **Tags**: dp, games
|
| 72 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 73 |
+
- **Memory Limit**: 64000000 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-0270/instruction.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 893_A. Chess For Three
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
|
| 5 |
+
|
| 6 |
+
So they play with each other according to following rules:
|
| 7 |
+
|
| 8 |
+
* Alex and Bob play the first game, and Carl is spectating;
|
| 9 |
+
* When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Alex, Bob and Carl play in such a way that there are no draws.
|
| 14 |
+
|
| 15 |
+
Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!
|
| 16 |
+
|
| 17 |
+
Input
|
| 18 |
+
|
| 19 |
+
The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played.
|
| 20 |
+
|
| 21 |
+
Then n lines follow, describing the game log. i-th line contains one integer ai (1 ≤ ai ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.
|
| 22 |
+
|
| 23 |
+
Output
|
| 24 |
+
|
| 25 |
+
Print YES if the situation described in the log was possible. Otherwise print NO.
|
| 26 |
+
|
| 27 |
+
Examples
|
| 28 |
+
|
| 29 |
+
Input
|
| 30 |
+
|
| 31 |
+
3
|
| 32 |
+
1
|
| 33 |
+
1
|
| 34 |
+
2
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
YES
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
2
|
| 45 |
+
1
|
| 46 |
+
2
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
NO
|
| 52 |
+
|
| 53 |
+
Note
|
| 54 |
+
|
| 55 |
+
In the first example the possible situation is:
|
| 56 |
+
|
| 57 |
+
1. Alex wins, Carl starts playing instead of Bob;
|
| 58 |
+
2. Alex wins, Bob replaces Carl;
|
| 59 |
+
3. Bob wins.
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.
|
| 64 |
+
|
| 65 |
+
## Contest Information
|
| 66 |
+
- **Contest ID**: 893
|
| 67 |
+
- **Problem Index**: A
|
| 68 |
+
- **Points**: 0.0
|
| 69 |
+
- **Rating**: 900
|
| 70 |
+
- **Tags**: implementation
|
| 71 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 72 |
+
- **Memory Limit**: 256000000 bytes
|
| 73 |
+
|
| 74 |
+
## Task
|
| 75 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0277/instruction.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# digital-numbers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Bosky is a very curious child who turned 13 yesterday. His parents gifted him a digital watch which he really liked. He was amazed to see how each number can be represented inside one cell only by switching different edges on and off.
|
| 5 |
+
|
| 6 |
+
Today, while he was in his home alone, getting bored looking at his watch, an idea popped up in his scientific mind. He immediately went to the garage and picked up a long rectangular cardboard, which was 2 units wide and L units long, and lots of thin LED tubes which were 1 unit long.
|
| 7 |
+
|
| 8 |
+
Bosky wanted to place LED tubes on the rectangular cardboard in such a way that he can represent as many digits as possible using the LED tubes and rectangular board similar to how digits are represented on his watch.
|
| 9 |
+
|
| 10 |
+
He realized that none of the LED tubes are working so he decided to purchase new LED tubes.
|
| 11 |
+
|
| 12 |
+
Each LED tube will cost Rs. 7
|
| 13 |
+
|
| 14 |
+
He has Rs. M with him and he now goes to market and spends all the money purchasing LED tubes.
|
| 15 |
+
|
| 16 |
+
After he brought all the LED tubes home, he wondered how many different digits he can represent on the rectangular board such that he doesn't have to repeat a number again.
|
| 17 |
+
|
| 18 |
+
But Bosky is tired now and does not want to try all the possible combinations to figure out how many digits he can represent on the board. He knows that you are a great programmer and you would surely help him. He calls you and tells you the length L and the amount of money M he has. Now, you have to tell him how many different digits he can represent on the rectangular board such that none of the digits is repeated, given:
|
| 19 |
+
|
| 20 |
+
0 requires -- 6 tubes
|
| 21 |
+
|
| 22 |
+
1 requires -- 2 tubes
|
| 23 |
+
|
| 24 |
+
2 requires -- 5 tubes
|
| 25 |
+
|
| 26 |
+
3 requires -- 5 tubes
|
| 27 |
+
|
| 28 |
+
4 requires -- 4 tubes
|
| 29 |
+
|
| 30 |
+
5 requires -- 5 tubes
|
| 31 |
+
|
| 32 |
+
6 requires -- 6 tubes
|
| 33 |
+
|
| 34 |
+
7 requires -- 3 tubes
|
| 35 |
+
|
| 36 |
+
8 requires -- 7 tubes
|
| 37 |
+
|
| 38 |
+
9 requires -- 6 tubes
|
| 39 |
+
|
| 40 |
+
[NOTE: Each digit occupies exactly 1 unit length on the board]
|
| 41 |
+
|
| 42 |
+
Input:
|
| 43 |
+
|
| 44 |
+
Input will contain a number T denoting the number of test cases.
|
| 45 |
+
|
| 46 |
+
Then T test cases follow, each one consisting of two space-separated integers L and M .
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
For each test case, output a single integer - the number of different digits Bosky can represent on the rectangular board such that none of the number is repeated and all the digits fit on the board.
|
| 51 |
+
|
| 52 |
+
Constraints
|
| 53 |
+
|
| 54 |
+
1 ≤ T ≤ 100
|
| 55 |
+
|
| 56 |
+
0 ≤ M ≤ 2000
|
| 57 |
+
|
| 58 |
+
0 ≤ L ≤ 10
|
| 59 |
+
|
| 60 |
+
SAMPLE INPUT
|
| 61 |
+
4
|
| 62 |
+
1 14
|
| 63 |
+
1 50
|
| 64 |
+
4 28
|
| 65 |
+
5 700
|
| 66 |
+
|
| 67 |
+
SAMPLE OUTPUT
|
| 68 |
+
1
|
| 69 |
+
10
|
| 70 |
+
3
|
| 71 |
+
32491
|
| 72 |
+
|
| 73 |
+
Explanation
|
| 74 |
+
|
| 75 |
+
Case 1: He has 14 rupees and he can purchase 2 LED tubes using which he can represent only '1' on the board.
|
| 76 |
+
|
| 77 |
+
Case 2: He can purchase 7 LED tubes using 50 rupees and the number of digits he can represent using 7 tubes are 10.
|
| 78 |
+
|
| 79 |
+
## Contest Information
|
| 80 |
+
- **Contest ID**: 0
|
| 81 |
+
- **Problem Index**:
|
| 82 |
+
- **Points**: 0.0
|
| 83 |
+
- **Rating**: 0
|
| 84 |
+
- **Tags**: None
|
| 85 |
+
- **Time Limit**: None seconds
|
| 86 |
+
- **Memory Limit**: 0 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-0279/instruction.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lexicographically-preceding-permutation
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given permutation is the lexicographically least permutation, then print the input permutation itself.
|
| 5 |
+
|
| 6 |
+
Input Format:
|
| 7 |
+
|
| 8 |
+
First line is the test cases and second line contains value of integer n: 1 ≤ n ≤ 1,000,000
|
| 9 |
+
third line is a space separated list of integers 1 2 ... n permuted in some random order
|
| 10 |
+
|
| 11 |
+
Output Format:
|
| 12 |
+
|
| 13 |
+
Output a single line containing a space separated list of integers which is the lexicographically preceding permutation of the input permutation.
|
| 14 |
+
|
| 15 |
+
SAMPLE INPUT
|
| 16 |
+
1
|
| 17 |
+
3
|
| 18 |
+
1 3 2
|
| 19 |
+
|
| 20 |
+
SAMPLE OUTPUT
|
| 21 |
+
1 2 3
|
| 22 |
+
|
| 23 |
+
## Contest Information
|
| 24 |
+
- **Contest ID**: 0
|
| 25 |
+
- **Problem Index**:
|
| 26 |
+
- **Points**: 0.0
|
| 27 |
+
- **Rating**: 0
|
| 28 |
+
- **Tags**: None
|
| 29 |
+
- **Time Limit**: None seconds
|
| 30 |
+
- **Memory Limit**: 0 bytes
|
| 31 |
+
|
| 32 |
+
## Task
|
| 33 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0282/instruction.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# roy-and-wobbly-numbers
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Roy is looking for Wobbly Numbers.
|
| 5 |
+
|
| 6 |
+
An N-length wobbly number is of the form "ababababab..." and so on of length N, where a != b.
|
| 7 |
+
|
| 8 |
+
A 3-length wobbly number would be of form "aba".
|
| 9 |
+
Eg: 101, 121, 131, 252, 646 etc
|
| 10 |
+
But 111, 222, 999 etc are not 3-length wobbly number, because here a != b condition is not satisfied.
|
| 11 |
+
Also 010 is not a 3-length wobbly number because it has preceding 0. So 010 equals 10 and 10 is not a 3-length wobbly number.
|
| 12 |
+
|
| 13 |
+
A 4-length wobbly number would be of form "abab".
|
| 14 |
+
Eg: 2323, 3232, 9090, 1414 etc
|
| 15 |
+
|
| 16 |
+
Similarly we can form a list of N-length wobbly numbers.
|
| 17 |
+
|
| 18 |
+
Now your task is to find K^th wobbly number from a lexicographically sorted list of N-length wobbly numbers. If the number does not exist print -1 else print the K^th wobbly number. See the sample test case and explanation for more clarity.
|
| 19 |
+
|
| 20 |
+
Input:
|
| 21 |
+
First line contains T - number of test cases
|
| 22 |
+
Each of the next T lines contains two space separated integers - N and K.
|
| 23 |
+
|
| 24 |
+
Output:
|
| 25 |
+
For each test case print the required output in a new line.
|
| 26 |
+
|
| 27 |
+
Constraints:
|
| 28 |
+
1 ≤ T ≤ 100
|
| 29 |
+
3 ≤ N ≤ 1000
|
| 30 |
+
1 ≤ K ≤ 100
|
| 31 |
+
|
| 32 |
+
SAMPLE INPUT
|
| 33 |
+
6
|
| 34 |
+
3 1
|
| 35 |
+
3 2
|
| 36 |
+
3 100
|
| 37 |
+
4 3
|
| 38 |
+
4 4
|
| 39 |
+
5 2
|
| 40 |
+
|
| 41 |
+
SAMPLE OUTPUT
|
| 42 |
+
101
|
| 43 |
+
121
|
| 44 |
+
-1
|
| 45 |
+
1313
|
| 46 |
+
1414
|
| 47 |
+
12121
|
| 48 |
+
|
| 49 |
+
Explanation
|
| 50 |
+
|
| 51 |
+
First 10 terms of 3-length wobbly numbers arranged lexicographically is as follows:
|
| 52 |
+
101, 121, 131, 141, 151, 161, 171, 181, 191, 202
|
| 53 |
+
|
| 54 |
+
1st wobbly number of length 3 is 101.
|
| 55 |
+
2nd wobbly number of length 3 is 121.
|
| 56 |
+
100th wobbly number of length 3 does not exist, so the output is -1.
|
| 57 |
+
|
| 58 |
+
First 10 terms of 4-length wobbly numbers arranged lexicographically is as follows:
|
| 59 |
+
1010, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020
|
| 60 |
+
|
| 61 |
+
3rd wobbly number of length 4 is 1313.
|
| 62 |
+
4th wobbly number of length 4 is 1414.
|
| 63 |
+
|
| 64 |
+
Similarly 2nd wobbly number of length 5 is 12121
|
| 65 |
+
|
| 66 |
+
## Contest Information
|
| 67 |
+
- **Contest ID**: 0
|
| 68 |
+
- **Problem Index**:
|
| 69 |
+
- **Points**: 0.0
|
| 70 |
+
- **Rating**: 0
|
| 71 |
+
- **Tags**: None
|
| 72 |
+
- **Time Limit**: None seconds
|
| 73 |
+
- **Memory Limit**: 0 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-0283/instruction.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# substrings-count-3
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Jack is the most intelligent student in the class.To boost his intelligence,his class teacher gave him a problem named "Substring Count".
|
| 5 |
+
|
| 6 |
+
Problem :
|
| 7 |
+
His Class teacher gave him n strings numbered from 1 to n which consists of only lowercase letters (each having length not more than 10) and then ask Q questions related to the given strings.
|
| 8 |
+
|
| 9 |
+
Each question is described by the 2 integers L,R and a string str,Now his teacher wants to know how many strings numbered from L to R contains str as a substrings.
|
| 10 |
+
|
| 11 |
+
As expected, Jack solved this problem with in a minute but he failed to solve it efficiently.Now ,its your turn to teach him.How to do it efficiently?? and save him from punishment.
|
| 12 |
+
|
| 13 |
+
INPUT
|
| 14 |
+
First line of input contains a single integer n denoting the number of strings given by class teacher to jack.Next n lines of input contains n strings (one per line).Next line fo input contains a single integer Q denoting the number of questions asked by his teacher.next Q lines of input contains Q question (one per line) as explained above.
|
| 15 |
+
|
| 16 |
+
OUTPUT
|
| 17 |
+
print the correct answer for each of the question asked by his teacher.
|
| 18 |
+
|
| 19 |
+
CONSTRAINTS
|
| 20 |
+
1 ≤ n ≤ 10000
|
| 21 |
+
1 ≤ strlen(str) ≤ 10
|
| 22 |
+
1 ≤ Q ≤ 5*10^5
|
| 23 |
+
1 ≤ L,R ≤ n
|
| 24 |
+
|
| 25 |
+
NOTE: strings consist of only lower case characters
|
| 26 |
+
|
| 27 |
+
SAMPLE INPUT
|
| 28 |
+
3
|
| 29 |
+
code
|
| 30 |
+
coder
|
| 31 |
+
coding
|
| 32 |
+
2
|
| 33 |
+
1 3 code
|
| 34 |
+
1 3 co
|
| 35 |
+
|
| 36 |
+
SAMPLE OUTPUT
|
| 37 |
+
2
|
| 38 |
+
3
|
| 39 |
+
|
| 40 |
+
Explanation
|
| 41 |
+
|
| 42 |
+
Q1:: code coder coding only two out of 3 strings contain cod as substring
|
| 43 |
+
Q2:: code coder coding all the 3 strings contain co as substring
|
| 44 |
+
|
| 45 |
+
## Contest Information
|
| 46 |
+
- **Contest ID**: 0
|
| 47 |
+
- **Problem Index**:
|
| 48 |
+
- **Points**: 0.0
|
| 49 |
+
- **Rating**: 0
|
| 50 |
+
- **Tags**: None
|
| 51 |
+
- **Time Limit**: None seconds
|
| 52 |
+
- **Memory Limit**: 0 bytes
|
| 53 |
+
|
| 54 |
+
## Task
|
| 55 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0284/instruction.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vibhu-and-his-mathematics
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
In code world all genders are considered equal ( It means their is nothing like male or female). Now their are N distinct persons living in this hypothetical world. Each person can pair up with any other person or can even remain single. One day Vbhu planned to visit code world. Being a maths guy , he always try to be mathematical. So he started counting the ways in which N persons living in code world can make pairs or remain single. A single person can make pair with at most one other person.Seeing that N can be large , Vibhu ask you for help. Now being a great programmer you need to help Vbhu count the number of ways in which N persons living in code world can make pairs or remain single.
|
| 5 |
+
|
| 6 |
+
Note : Its not necessary that everyone is required to make pair with someone. Person can remain single also.
|
| 7 |
+
|
| 8 |
+
Input Format : First line contain number of test cases T. Then next T lines contain a single integer N , denoting the number of persons living in code world.
|
| 9 |
+
|
| 10 |
+
Output Format : You need to print the number of ways in which N different persons can make their pairs or stay single. As answer can be large so print it modulo 10^9+7.
|
| 11 |
+
|
| 12 |
+
Constraints :
|
| 13 |
+
1 ≤ T ≤10^5
|
| 14 |
+
1 ≤ N ≤10^6
|
| 15 |
+
Warning: Large Input/Output data, be careful with certain languages
|
| 16 |
+
|
| 17 |
+
SAMPLE INPUT
|
| 18 |
+
2
|
| 19 |
+
2
|
| 20 |
+
3
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
SAMPLE OUTPUT
|
| 24 |
+
2
|
| 25 |
+
4
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Explanation
|
| 29 |
+
|
| 30 |
+
In first test case , For N=2 answer will be 2. Possible ways are :
|
| 31 |
+
{1},{2} (It means Person 1 and Person 2 are single)
|
| 32 |
+
{1,2} (It means Person 1 and Person 2 had formed a pair)
|
| 33 |
+
|
| 34 |
+
For second test case , For N=3 , answer will be 4. Possible ways are :
|
| 35 |
+
{1},{2},{3} (It means all three Persons are single)
|
| 36 |
+
{1,2},{3} (It means Person 1 and Person 2 had formed a pair and Person 3 is single)
|
| 37 |
+
{1},{2,3} (It means Person 2 and Person 3 had formed a pair and Person 1 is single)
|
| 38 |
+
{1,3},{2} (It means Person 1 and Person 3 had formed a pair and Person 2 is single)
|
| 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-0285/instruction.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02610 AIsing Programming Contest 2020 - Camel Train
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
We have N camels numbered 1,2,\ldots,N. Snuke has decided to make them line up in a row.
|
| 5 |
+
|
| 6 |
+
The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise.
|
| 7 |
+
|
| 8 |
+
Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel.
|
| 9 |
+
|
| 10 |
+
Solve this problem for each of the T test cases given.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
* All values in input are integers.
|
| 15 |
+
* 1 \leq T \leq 10^5
|
| 16 |
+
* 1 \leq N \leq 2 \times 10^{5}
|
| 17 |
+
* 1 \leq K_i \leq N
|
| 18 |
+
* 1 \leq L_i, R_i \leq 10^9
|
| 19 |
+
* The sum of values of N in each input file is at most 2 \times 10^5.
|
| 20 |
+
|
| 21 |
+
Input
|
| 22 |
+
|
| 23 |
+
Input is given from Standard Input in the following format:
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
T
|
| 27 |
+
\mathrm{case}_1
|
| 28 |
+
\vdots
|
| 29 |
+
\mathrm{case}_T
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Each case is given in the following format:
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
N
|
| 36 |
+
K_1 L_1 R_1
|
| 37 |
+
\vdots
|
| 38 |
+
K_N L_N R_N
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
Print T lines. The i-th line should contain the answer to the i-th test case.
|
| 44 |
+
|
| 45 |
+
Example
|
| 46 |
+
|
| 47 |
+
Input
|
| 48 |
+
|
| 49 |
+
3
|
| 50 |
+
2
|
| 51 |
+
1 5 10
|
| 52 |
+
2 15 5
|
| 53 |
+
3
|
| 54 |
+
2 93 78
|
| 55 |
+
1 71 59
|
| 56 |
+
3 57 96
|
| 57 |
+
19
|
| 58 |
+
19 23 16
|
| 59 |
+
5 90 13
|
| 60 |
+
12 85 70
|
| 61 |
+
19 67 78
|
| 62 |
+
12 16 60
|
| 63 |
+
18 48 28
|
| 64 |
+
5 4 24
|
| 65 |
+
12 97 97
|
| 66 |
+
4 57 87
|
| 67 |
+
19 91 74
|
| 68 |
+
18 100 76
|
| 69 |
+
7 86 46
|
| 70 |
+
9 100 57
|
| 71 |
+
3 76 73
|
| 72 |
+
6 84 93
|
| 73 |
+
1 6 84
|
| 74 |
+
11 75 94
|
| 75 |
+
19 15 3
|
| 76 |
+
12 11 34
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Output
|
| 80 |
+
|
| 81 |
+
25
|
| 82 |
+
221
|
| 83 |
+
1354
|
| 84 |
+
|
| 85 |
+
## Contest Information
|
| 86 |
+
- **Contest ID**: 0
|
| 87 |
+
- **Problem Index**:
|
| 88 |
+
- **Points**: 0.0
|
| 89 |
+
- **Rating**: 0
|
| 90 |
+
- **Tags**:
|
| 91 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 92 |
+
- **Memory Limit**: 1073741824 bytes
|
| 93 |
+
|
| 94 |
+
## Task
|
| 95 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0410/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01646 Dictionary
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem Statement
|
| 5 |
+
|
| 6 |
+
We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary into a computer.
|
| 7 |
+
|
| 8 |
+
How the words are ordered in the dictionary, especially whether they are ordered lexicographically, is an interesting topic to many people. As a good programmer, you are requested to write a program to judge whether we can consider the words to be sorted in a lexicographical order.
|
| 9 |
+
|
| 10 |
+
Note: In a lexicographical order, a word always precedes other words it is a prefix of. For example, `ab` precedes `abc`, `abde`, and so on.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The input consists of multiple datasets. Each dataset is formatted as follows:
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
n
|
| 20 |
+
string_1
|
| 21 |
+
...
|
| 22 |
+
string_n
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
Each dataset consists of n+1 lines. The first line of each dataset contains an integer that indicates n (1 \leq n \leq 500). The i-th line of the following n lines contains string_i, which consists of up to 10 English lowercase letters.
|
| 26 |
+
|
| 27 |
+
The end of the input is `0`, and this should not be processed.
|
| 28 |
+
|
| 29 |
+
Output
|
| 30 |
+
|
| 31 |
+
Print either `yes` or `no` in a line for each dataset, in the order of the input. If all words in the dataset can be considered to be ordered lexicographically, print `yes`. Otherwise, print `no`.
|
| 32 |
+
|
| 33 |
+
Example
|
| 34 |
+
|
| 35 |
+
Input
|
| 36 |
+
|
| 37 |
+
4
|
| 38 |
+
cba
|
| 39 |
+
cab
|
| 40 |
+
b
|
| 41 |
+
a
|
| 42 |
+
3
|
| 43 |
+
bca
|
| 44 |
+
ab
|
| 45 |
+
a
|
| 46 |
+
5
|
| 47 |
+
abc
|
| 48 |
+
acb
|
| 49 |
+
b
|
| 50 |
+
c
|
| 51 |
+
c
|
| 52 |
+
5
|
| 53 |
+
abc
|
| 54 |
+
acb
|
| 55 |
+
c
|
| 56 |
+
b
|
| 57 |
+
b
|
| 58 |
+
0
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
yes
|
| 64 |
+
no
|
| 65 |
+
yes
|
| 66 |
+
no
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 0
|
| 70 |
+
- **Problem Index**:
|
| 71 |
+
- **Points**: 0.0
|
| 72 |
+
- **Rating**: 0
|
| 73 |
+
- **Tags**:
|
| 74 |
+
- **Time Limit**: {'seconds': 8, 'nanos': 0} seconds
|
| 75 |
+
- **Memory Limit**: 268435456 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-0417/instruction.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# chefrp
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Rupsa recently started to intern under Chef. He gave her N type of ingredients of varying quantity A1, A2, ..., AN respectively to store it. But as she is lazy to arrange them she puts them all in a storage box.
|
| 5 |
+
Chef comes up with a new recipe and decides to prepare it. He asks Rupsa to get two units of each type ingredient for the dish. But when she went to retrieve the ingredients, she realizes that she can only pick one item at a time from the box and can know its type only after she has picked it out. The picked item is not put back in the bag.
|
| 6 |
+
She, being lazy, wants to know the maximum number of times she would need to pick items from the box in the worst case so that it is guaranteed that she gets at least two units of each type of ingredient. If it is impossible to pick items in such a way, print -1.
|
| 7 |
+
|
| 8 |
+
Input
|
| 9 |
+
|
| 10 |
+
The first line of the input contains an integer T denoting the number of test cases.
|
| 11 |
+
The first line of each test case contains a single integer N denoting the number of different type of ingredients.
|
| 12 |
+
The second line contains N space-separated integers A1, A2, ..., AN denoting the quantity of each ingredient.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Output
|
| 16 |
+
|
| 17 |
+
For each test case, output a single line containing an integer denoting the answer corresponding to that test case.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Constraints
|
| 21 |
+
|
| 22 |
+
1 ≤ T ≤ 10
|
| 23 |
+
1 ≤ N ≤ 10^5
|
| 24 |
+
1 ≤ Ai ≤ 10^4
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
Sub tasks
|
| 28 |
+
|
| 29 |
+
Example
|
| 30 |
+
Input:
|
| 31 |
+
2
|
| 32 |
+
2
|
| 33 |
+
2 2
|
| 34 |
+
1
|
| 35 |
+
6
|
| 36 |
+
|
| 37 |
+
Output:
|
| 38 |
+
4
|
| 39 |
+
2
|
| 40 |
+
|
| 41 |
+
Explanation
|
| 42 |
+
|
| 43 |
+
In Example 1, she need to pick up all items.
|
| 44 |
+
In Example 2, since there is only one type of ingredient, picking two items is enough.
|
| 45 |
+
|
| 46 |
+
## Contest Information
|
| 47 |
+
- **Contest ID**: 0
|
| 48 |
+
- **Problem Index**:
|
| 49 |
+
- **Points**: 0.0
|
| 50 |
+
- **Rating**: 0
|
| 51 |
+
- **Tags**: None
|
| 52 |
+
- **Time Limit**: None seconds
|
| 53 |
+
- **Memory Limit**: 0 bytes
|
| 54 |
+
|
| 55 |
+
## Task
|
| 56 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0419/instruction.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ism1
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Hackers! Hackers! Everywhere!
|
| 5 |
+
Some days back your email ID was hacked. Some one read the personal messages and Love Letters you sent to your girl friend. That's a terrible thing, well, you know how are the boys at ISM. So, you have decided that from now onwards you will write Love Letters to your girlfriend in a different way.
|
| 6 |
+
Suppose you want to write "i love you sweet heart", then you will write "I evol uoy teews traeh".
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
Input
|
| 10 |
+
First line will contain the number of test cases T, not more than 20.
|
| 11 |
+
Each test case will contain a line of not more than 100 characters and all the characters will be small alphabets only ('a'-'z'). There will be exactly one space between two words.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Output
|
| 16 |
+
For each test case output a single line in the new format.
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Example
|
| 20 |
+
|
| 21 |
+
Input:
|
| 22 |
+
3
|
| 23 |
+
can you meet me outside ccd today
|
| 24 |
+
a
|
| 25 |
+
this year hard kaur is coming to entertain us
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output:
|
| 29 |
+
nac uoy teem em edistuo dcc yadot
|
| 30 |
+
a
|
| 31 |
+
siht raey drah ruak si gnimoc ot niatretne su
|
| 32 |
+
|
| 33 |
+
## Contest Information
|
| 34 |
+
- **Contest ID**: 0
|
| 35 |
+
- **Problem Index**:
|
| 36 |
+
- **Points**: 0.0
|
| 37 |
+
- **Rating**: 0
|
| 38 |
+
- **Tags**: None
|
| 39 |
+
- **Time Limit**: None seconds
|
| 40 |
+
- **Memory Limit**: 0 bytes
|
| 41 |
+
|
| 42 |
+
## Task
|
| 43 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0426/instruction.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1091_G. New Year and the Factorisation Collaboration
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Integer factorisation is hard. The RSA Factoring Challenge offered $100 000 for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number.
|
| 5 |
+
|
| 6 |
+
Since your programming language of choice might not offer facilities for handling large integers, we will provide you with a very simple calculator.
|
| 7 |
+
|
| 8 |
+
To use this calculator, you can print queries on the standard output and retrieve the results from the standard input. The operations are as follows:
|
| 9 |
+
|
| 10 |
+
* + x y where x and y are integers between 0 and n-1. Returns (x+y) mod n.
|
| 11 |
+
* - x y where x and y are integers between 0 and n-1. Returns (x-y) mod n.
|
| 12 |
+
* * x y where x and y are integers between 0 and n-1. Returns (x ⋅ y) mod n.
|
| 13 |
+
* / x y where x and y are integers between 0 and n-1 and y is coprime with n. Returns (x ⋅ y^{-1}) mod n where y^{-1} is multiplicative inverse of y modulo n. If y is not coprime with n, then -1 is returned instead.
|
| 14 |
+
* sqrt x where x is integer between 0 and n-1 coprime with n. Returns y such that y^2 mod n = x. If there are multiple such integers, only one of them is returned. If there are none, -1 is returned instead.
|
| 15 |
+
* ^ x y where x and y are integers between 0 and n-1. Returns {x^y mod n}.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
Find the factorisation of n that is a product of between 2 and 10 distinct prime numbers, all of form 4x + 3 for some integer x.
|
| 20 |
+
|
| 21 |
+
Because of technical issues, we restrict number of requests to 100.
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
The only line contains a single integer n (21 ≤ n ≤ 2^{1024}). It is guaranteed that n is a product of between 2 and 10 distinct prime numbers, all of form 4x + 3 for some integer x.
|
| 26 |
+
|
| 27 |
+
Output
|
| 28 |
+
|
| 29 |
+
You can print as many queries as you wish, adhering to the time limit (see the Interaction section for more details).
|
| 30 |
+
|
| 31 |
+
When you think you know the answer, output a single line of form ! k p_1 p_2 ... p_k, where k is the number of prime factors of n, and p_i are the distinct prime factors. You may print the factors in any order.
|
| 32 |
+
|
| 33 |
+
Hacks input
|
| 34 |
+
|
| 35 |
+
For hacks, use the following format:.
|
| 36 |
+
|
| 37 |
+
The first should contain k (2 ≤ k ≤ 10) — the number of prime factors of n.
|
| 38 |
+
|
| 39 |
+
The second should contain k space separated integers p_1, p_2, ..., p_k (21 ≤ n ≤ 2^{1024}) — the prime factors of n. All prime factors have to be of form 4x + 3 for some integer x. They all have to be distinct.
|
| 40 |
+
|
| 41 |
+
Interaction
|
| 42 |
+
|
| 43 |
+
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
|
| 44 |
+
|
| 45 |
+
* fflush(stdout) or cout.flush() in C++;
|
| 46 |
+
* System.out.flush() in Java;
|
| 47 |
+
* flush(output) in Pascal;
|
| 48 |
+
* stdout.flush() in Python;
|
| 49 |
+
* see documentation for other languages.
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
The number of queries is not limited. However, your program must (as always) fit in the time limit. The run time of the interactor is also counted towards the time limit. The maximum runtime of each query is given below.
|
| 54 |
+
|
| 55 |
+
* + x y — up to 1 ms.
|
| 56 |
+
* - x y — up to 1 ms.
|
| 57 |
+
* * x y — up to 1 ms.
|
| 58 |
+
* / x y — up to 350 ms.
|
| 59 |
+
* sqrt x — up to 80 ms.
|
| 60 |
+
* ^ x y — up to 350 ms.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Note that the sample input contains extra empty lines so that it easier to read. The real input will not contain any empty lines and you do not need to output extra empty lines.
|
| 65 |
+
|
| 66 |
+
Example
|
| 67 |
+
|
| 68 |
+
Input
|
| 69 |
+
|
| 70 |
+
21
|
| 71 |
+
|
| 72 |
+
7
|
| 73 |
+
|
| 74 |
+
17
|
| 75 |
+
|
| 76 |
+
15
|
| 77 |
+
|
| 78 |
+
17
|
| 79 |
+
|
| 80 |
+
11
|
| 81 |
+
|
| 82 |
+
-1
|
| 83 |
+
|
| 84 |
+
15
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Output
|
| 89 |
+
|
| 90 |
+
+ 12 16
|
| 91 |
+
|
| 92 |
+
- 6 10
|
| 93 |
+
|
| 94 |
+
* 8 15
|
| 95 |
+
|
| 96 |
+
/ 5 4
|
| 97 |
+
|
| 98 |
+
sqrt 16
|
| 99 |
+
|
| 100 |
+
sqrt 5
|
| 101 |
+
|
| 102 |
+
^ 6 12
|
| 103 |
+
|
| 104 |
+
! 2 3 7
|
| 105 |
+
|
| 106 |
+
Note
|
| 107 |
+
|
| 108 |
+
We start by reading the first line containing the integer n = 21. Then, we ask for:
|
| 109 |
+
|
| 110 |
+
1. (12 + 16) mod 21 = 28 mod 21 = 7.
|
| 111 |
+
2. (6 - 10) mod 21 = -4 mod 21 = 17.
|
| 112 |
+
3. (8 ⋅ 15) mod 21 = 120 mod 21 = 15.
|
| 113 |
+
4. (5 ⋅ 4^{-1}) mod 21 = (5 ⋅ 16) mod 21 = 80 mod 21 = 17.
|
| 114 |
+
5. Square root of 16. The answer is 11, as (11 ⋅ 11) mod 21 = 121 mod 21 = 16. Note that the answer may as well be 10.
|
| 115 |
+
6. Square root of 5. There is no x such that x^2 mod 21 = 5, so the output is -1.
|
| 116 |
+
7. (6^{12}) mod 21 = 2176782336 mod 21 = 15.
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
We conclude that our calculator is working, stop fooling around and realise that 21 = 3 ⋅ 7.
|
| 121 |
+
|
| 122 |
+
## Contest Information
|
| 123 |
+
- **Contest ID**: 1091
|
| 124 |
+
- **Problem Index**: G
|
| 125 |
+
- **Points**: 3750.0
|
| 126 |
+
- **Rating**: 3200
|
| 127 |
+
- **Tags**: interactive, math, number theory
|
| 128 |
+
- **Time Limit**: {'seconds': 6, 'nanos': 0} seconds
|
| 129 |
+
- **Memory Limit**: 256000000 bytes
|
| 130 |
+
|
| 131 |
+
## Task
|
| 132 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0472/instruction.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 741_E. Arpa’s abnormal DNA and Mehrdad’s deep interest
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D
|
| 5 |
+
|
| 6 |
+
Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.
|
| 7 |
+
|
| 8 |
+
<image>
|
| 9 |
+
|
| 10 |
+
Sipa put Arpa under the DNA editor. DNA editor showed Arpa's DNA as a string S consisting of n lowercase English letters. Also Sipa has another DNA T consisting of lowercase English letters that belongs to a normal man.
|
| 11 |
+
|
| 12 |
+
Now there are (n + 1) options to change Arpa's DNA, numbered from 0 to n. i-th of them is to put T between i-th and (i + 1)-th characters of S (0 ≤ i ≤ n). If i = 0, T will be put before S, and if i = n, it will be put after S.
|
| 13 |
+
|
| 14 |
+
Mehrdad wants to choose the most interesting option for Arpa's DNA among these n + 1 options. DNA A is more interesting than B if A is lexicographically smaller than B. Mehrdad asked Sipa q questions:
|
| 15 |
+
|
| 16 |
+
Given integers l, r, k, x, y, what is the most interesting option if we only consider such options i that l ≤ i ≤ r and <image>? If there are several most interesting options, Mehrdad wants to know one with the smallest number i.
|
| 17 |
+
|
| 18 |
+
Since Sipa is a biology scientist but not a programmer, you should help him.
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
|
| 22 |
+
The first line contains strings S, T and integer q (1 ≤ |S|, |T|, q ≤ 105) — Arpa's DNA, the DNA of a normal man, and the number of Mehrdad's questions. The strings S and T consist only of small English letters.
|
| 23 |
+
|
| 24 |
+
Next q lines describe the Mehrdad's questions. Each of these lines contain five integers l, r, k, x, y (0 ≤ l ≤ r ≤ n, 1 ≤ k ≤ n, 0 ≤ x ≤ y < k).
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
Print q integers. The j-th of them should be the number i of the most interesting option among those that satisfy the conditions of the j-th question. If there is no option i satisfying the conditions in some question, print -1.
|
| 29 |
+
|
| 30 |
+
Examples
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
abc d 4
|
| 35 |
+
0 3 2 0 0
|
| 36 |
+
0 3 1 0 0
|
| 37 |
+
1 2 1 0 0
|
| 38 |
+
0 1 3 2 2
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Output
|
| 42 |
+
|
| 43 |
+
2 3 2 -1
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
Input
|
| 47 |
+
|
| 48 |
+
abbbbbbaaa baababaaab 10
|
| 49 |
+
1 2 1 0 0
|
| 50 |
+
2 7 8 4 7
|
| 51 |
+
2 3 9 2 8
|
| 52 |
+
3 4 6 1 1
|
| 53 |
+
0 8 5 2 4
|
| 54 |
+
2 8 10 4 7
|
| 55 |
+
7 10 1 0 0
|
| 56 |
+
1 4 6 0 2
|
| 57 |
+
0 9 8 0 6
|
| 58 |
+
4 8 5 0 1
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
Output
|
| 62 |
+
|
| 63 |
+
1 4 2 -1 2 4 10 1 1 5
|
| 64 |
+
|
| 65 |
+
Note
|
| 66 |
+
|
| 67 |
+
Explanation of first sample case:
|
| 68 |
+
|
| 69 |
+
In the first question Sipa has two options: dabc (i = 0) and abdc (i = 2). The latter (abcd) is better than abdc, so answer is 2.
|
| 70 |
+
|
| 71 |
+
In the last question there is no i such that 0 ≤ i ≤ 1 and <image>.
|
| 72 |
+
|
| 73 |
+
## Contest Information
|
| 74 |
+
- **Contest ID**: 741
|
| 75 |
+
- **Problem Index**: E
|
| 76 |
+
- **Points**: 2500.0
|
| 77 |
+
- **Rating**: 3400
|
| 78 |
+
- **Tags**: data structures, string suffix structures
|
| 79 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 80 |
+
- **Memory Limit**: 256000000 bytes
|
| 81 |
+
|
| 82 |
+
## Task
|
| 83 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0473/instruction.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 765_D. Artsem and Saunders
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
|
| 5 |
+
|
| 6 |
+
Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.
|
| 7 |
+
|
| 8 |
+
Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains an integer n (1 ≤ n ≤ 105).
|
| 13 |
+
|
| 14 |
+
The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
If there is no answer, print one integer -1.
|
| 19 |
+
|
| 20 |
+
Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).
|
| 21 |
+
|
| 22 |
+
If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
|
| 23 |
+
|
| 24 |
+
Examples
|
| 25 |
+
|
| 26 |
+
Input
|
| 27 |
+
|
| 28 |
+
3
|
| 29 |
+
1 2 3
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Output
|
| 33 |
+
|
| 34 |
+
3
|
| 35 |
+
1 2 3
|
| 36 |
+
1 2 3
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Input
|
| 40 |
+
|
| 41 |
+
3
|
| 42 |
+
2 2 2
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
Output
|
| 46 |
+
|
| 47 |
+
1
|
| 48 |
+
1 1 1
|
| 49 |
+
2
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
2
|
| 55 |
+
2 1
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
Output
|
| 59 |
+
|
| 60 |
+
-1
|
| 61 |
+
|
| 62 |
+
## Contest Information
|
| 63 |
+
- **Contest ID**: 765
|
| 64 |
+
- **Problem Index**: D
|
| 65 |
+
- **Points**: 2000.0
|
| 66 |
+
- **Rating**: 1700
|
| 67 |
+
- **Tags**: constructive algorithms, dsu, math
|
| 68 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 69 |
+
- **Memory Limit**: 512000000 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-0474/instruction.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 789_A. Anastasia and pebbles
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
|
| 5 |
+
|
| 6 |
+
She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
|
| 7 |
+
|
| 8 |
+
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
|
| 13 |
+
|
| 14 |
+
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
|
| 15 |
+
|
| 16 |
+
Output
|
| 17 |
+
|
| 18 |
+
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
|
| 19 |
+
|
| 20 |
+
Examples
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
3 2
|
| 25 |
+
2 3 4
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
3
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
Input
|
| 34 |
+
|
| 35 |
+
5 4
|
| 36 |
+
3 1 8 9 7
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Output
|
| 40 |
+
|
| 41 |
+
5
|
| 42 |
+
|
| 43 |
+
Note
|
| 44 |
+
|
| 45 |
+
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
|
| 46 |
+
|
| 47 |
+
Optimal sequence of actions in the second sample case:
|
| 48 |
+
|
| 49 |
+
* In the first day Anastasia collects 8 pebbles of the third type.
|
| 50 |
+
* In the second day she collects 8 pebbles of the fourth type.
|
| 51 |
+
* In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
|
| 52 |
+
* In the fourth day she collects 7 pebbles of the fifth type.
|
| 53 |
+
* In the fifth day she collects 1 pebble of the second type.
|
| 54 |
+
|
| 55 |
+
## Contest Information
|
| 56 |
+
- **Contest ID**: 789
|
| 57 |
+
- **Problem Index**: A
|
| 58 |
+
- **Points**: 500.0
|
| 59 |
+
- **Rating**: 1100
|
| 60 |
+
- **Tags**: implementation, math
|
| 61 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 62 |
+
- **Memory Limit**: 256000000 bytes
|
| 63 |
+
|
| 64 |
+
## Task
|
| 65 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0475/instruction.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 80_C. Heroes
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The year of 2012 is coming...
|
| 5 |
+
|
| 6 |
+
According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil.
|
| 7 |
+
|
| 8 |
+
The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal.
|
| 9 |
+
|
| 10 |
+
Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team.
|
| 11 |
+
|
| 12 |
+
Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum.
|
| 13 |
+
|
| 14 |
+
It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself.
|
| 15 |
+
|
| 16 |
+
The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p).
|
| 17 |
+
|
| 18 |
+
A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team.
|
| 19 |
+
|
| 20 |
+
It is guaranteed that every hero is able to destroy any megaboss alone.
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠ q). Every liking is described in the input exactly once, no hero likes himself.
|
| 25 |
+
|
| 26 |
+
In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal.
|
| 27 |
+
|
| 28 |
+
In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c.
|
| 29 |
+
|
| 30 |
+
Output
|
| 31 |
+
|
| 32 |
+
Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team).
|
| 33 |
+
|
| 34 |
+
When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking.
|
| 35 |
+
|
| 36 |
+
Examples
|
| 37 |
+
|
| 38 |
+
Input
|
| 39 |
+
|
| 40 |
+
3
|
| 41 |
+
Troll likes Dracul
|
| 42 |
+
Dracul likes Anka
|
| 43 |
+
Snowy likes Hexadecimal
|
| 44 |
+
210 200 180
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
30 3
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
2
|
| 55 |
+
Anka likes Chapay
|
| 56 |
+
Chapay likes Anka
|
| 57 |
+
10000 50 50
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Output
|
| 61 |
+
|
| 62 |
+
1950 2
|
| 63 |
+
|
| 64 |
+
Note
|
| 65 |
+
|
| 66 |
+
A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.
|
| 67 |
+
|
| 68 |
+
## Contest Information
|
| 69 |
+
- **Contest ID**: 80
|
| 70 |
+
- **Problem Index**: C
|
| 71 |
+
- **Points**: 500.0
|
| 72 |
+
- **Rating**: 1400
|
| 73 |
+
- **Tags**: brute force, implementation
|
| 74 |
+
- **Time Limit**: {'seconds': 2, '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-0481/instruction.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 954_F. Runner's Problem
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column.
|
| 5 |
+
|
| 6 |
+
You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) you may advance to:
|
| 7 |
+
|
| 8 |
+
* (i - 1, j + 1) — only if i > 1,
|
| 9 |
+
* (i, j + 1), or
|
| 10 |
+
* (i + 1, j + 1) — only if i < 3.
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
However, there are n obstacles blocking your path. k-th obstacle is denoted by three integers ak, lk and rk, and it forbids entering any cell (ak, j) such that lk ≤ j ≤ rk.
|
| 15 |
+
|
| 16 |
+
You have to calculate the number of different paths from (2, 1) to (2, m), and print it modulo 109 + 7.
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
The first line contains two integers n and m (1 ≤ n ≤ 104, 3 ≤ m ≤ 1018) — the number of obstacles and the number of columns in the matrix, respectively.
|
| 21 |
+
|
| 22 |
+
Then n lines follow, each containing three integers ak, lk and rk (1 ≤ ak ≤ 3, 2 ≤ lk ≤ rk ≤ m - 1) denoting an obstacle blocking every cell (ak, j) such that lk ≤ j ≤ rk. Some cells may be blocked by multiple obstacles.
|
| 23 |
+
|
| 24 |
+
Output
|
| 25 |
+
|
| 26 |
+
Print the number of different paths from (2, 1) to (2, m), taken modulo 109 + 7. If it is impossible to get from (2, 1) to (2, m), then the number of paths is 0.
|
| 27 |
+
|
| 28 |
+
Example
|
| 29 |
+
|
| 30 |
+
Input
|
| 31 |
+
|
| 32 |
+
2 5
|
| 33 |
+
1 3 4
|
| 34 |
+
2 2 3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
2
|
| 40 |
+
|
| 41 |
+
## Contest Information
|
| 42 |
+
- **Contest ID**: 954
|
| 43 |
+
- **Problem Index**: F
|
| 44 |
+
- **Points**: 0.0
|
| 45 |
+
- **Rating**: 2100
|
| 46 |
+
- **Tags**: dp, matrices, sortings
|
| 47 |
+
- **Time Limit**: {'seconds': 4, 'nanos': 0} seconds
|
| 48 |
+
- **Memory Limit**: 256000000 bytes
|
| 49 |
+
|
| 50 |
+
## Task
|
| 51 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0486/instruction.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# find-the-nth-prime
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Given the value of n, print the n'th prime number.
|
| 5 |
+
|
| 6 |
+
Input : A single integer n.
|
| 7 |
+
Output : A single number which is the n'th prime number.
|
| 8 |
+
Constraints :
|
| 9 |
+
1 ≤ n ≤ 1000
|
| 10 |
+
|
| 11 |
+
SAMPLE INPUT
|
| 12 |
+
2
|
| 13 |
+
|
| 14 |
+
SAMPLE OUTPUT
|
| 15 |
+
3
|
| 16 |
+
|
| 17 |
+
Explanation
|
| 18 |
+
|
| 19 |
+
The first few prime numbers are:
|
| 20 |
+
2,3,5,7. So, the answer is 3.
|
| 21 |
+
|
| 22 |
+
## Contest Information
|
| 23 |
+
- **Contest ID**: 0
|
| 24 |
+
- **Problem Index**:
|
| 25 |
+
- **Points**: 0.0
|
| 26 |
+
- **Rating**: 0
|
| 27 |
+
- **Tags**: None
|
| 28 |
+
- **Time Limit**: None seconds
|
| 29 |
+
- **Memory Limit**: 0 bytes
|
| 30 |
+
|
| 31 |
+
## Task
|
| 32 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0487/instruction.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# insect-colony-2
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Yesterday Oz heard a story about insect colony. The specialty of insects is that they splits sometimes i.e an insect of size A can split into two insects of positive integral sizes B and C such that A = B + C. Also sometimes they attack each other i.e. two insects of sizes P and Q will become R = P XOR Q .
|
| 5 |
+
You are given the sizes of the insects of insect colony, you have to determine whether it is possible for insect colony to disappear after several splits and/or attacks?
|
| 6 |
+
|
| 7 |
+
Input :
|
| 8 |
+
The first line contains an integer T, indicating the number of test cases.
|
| 9 |
+
For each test case, the first line contains an integer N, indicating the number of insects in insect colony, followed by N space separated positive integers p1,p2,...,pN denoting the sizes of insects.
|
| 10 |
+
|
| 11 |
+
Output :
|
| 12 |
+
For each test case, output "Yes" if it is possible for insect colony to disappear after several splits and/or attacks otherwise output "No" (quotes for clarity only)
|
| 13 |
+
|
| 14 |
+
Constraints :
|
| 15 |
+
1 ≤ T ≤ 100
|
| 16 |
+
1 ≤ N ≤ 100
|
| 17 |
+
1 ≤ pi ≤ 10^9 where i =1,2...,N
|
| 18 |
+
|
| 19 |
+
SAMPLE INPUT
|
| 20 |
+
2
|
| 21 |
+
2 9 17
|
| 22 |
+
1 1
|
| 23 |
+
|
| 24 |
+
SAMPLE OUTPUT
|
| 25 |
+
Yes
|
| 26 |
+
No
|
| 27 |
+
|
| 28 |
+
Explanation
|
| 29 |
+
|
| 30 |
+
For the first sample :
|
| 31 |
+
Following is one possible sequence of operations -
|
| 32 |
+
1) attack i.e 9 XOR 17 = 24
|
| 33 |
+
2) split 24 into two parts each of size 12
|
| 34 |
+
3) attack i.e 12 XOR 12 = 0
|
| 35 |
+
as the size is now 0 so it is possible for the colony to disappear.
|
| 36 |
+
|
| 37 |
+
## Contest Information
|
| 38 |
+
- **Contest ID**: 0
|
| 39 |
+
- **Problem Index**:
|
| 40 |
+
- **Points**: 0.0
|
| 41 |
+
- **Rating**: 0
|
| 42 |
+
- **Tags**: None
|
| 43 |
+
- **Time Limit**: None seconds
|
| 44 |
+
- **Memory Limit**: 0 bytes
|
| 45 |
+
|
| 46 |
+
## Task
|
| 47 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0488/instruction.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# max-min
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
you are given an array of size N. You need to select K elements from the array such that the difference between the max number among selected and the min number among selected array elements should be minimum. Print the minimum difference.
|
| 5 |
+
|
| 6 |
+
INPUT:
|
| 7 |
+
First line N number i.e., length of array
|
| 8 |
+
Second line K number
|
| 9 |
+
Next N lines contains a number for each line
|
| 10 |
+
|
| 11 |
+
OUTPUT:
|
| 12 |
+
Print the minimum possible difference
|
| 13 |
+
|
| 14 |
+
0<N<10^5
|
| 15 |
+
0<K<N
|
| 16 |
+
0<number<10^9
|
| 17 |
+
|
| 18 |
+
SAMPLE INPUT
|
| 19 |
+
5
|
| 20 |
+
3
|
| 21 |
+
1
|
| 22 |
+
2
|
| 23 |
+
3
|
| 24 |
+
4
|
| 25 |
+
5
|
| 26 |
+
|
| 27 |
+
SAMPLE OUTPUT
|
| 28 |
+
2
|
| 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-0553/instruction.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 187_B. AlgoRace
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features.
|
| 5 |
+
|
| 6 |
+
AlgoRace is a special league of car racing where different teams compete in a country of n cities. Cities are numbered 1 through n. Every two distinct cities in the country are connected with one bidirectional road. Each competing team should introduce one driver and a set of cars.
|
| 7 |
+
|
| 8 |
+
The competition is held in r rounds. In i-th round, drivers will start at city si and finish at city ti. Drivers are allowed to change their cars at most ki times. Changing cars can take place in any city in no time. One car can be used multiple times in one round, but total number of changes should not exceed ki. Drivers can freely choose their path to destination.
|
| 9 |
+
|
| 10 |
+
PMP has prepared m type of purpose-built cars. Beside for PMP’s driving skills, depending on properties of the car and the road, a car traverses each road in each direction in different times.
|
| 11 |
+
|
| 12 |
+
PMP Warriors wants to devise best strategies of choosing car and roads in each round to maximize the chance of winning the cup. For each round they want to find the minimum time required to finish it.
|
| 13 |
+
|
| 14 |
+
Input
|
| 15 |
+
|
| 16 |
+
The first line contains three space-separated integers n, m, r (2 ≤ n ≤ 60, 1 ≤ m ≤ 60, 1 ≤ r ≤ 105) — the number of cities, the number of different types of cars and the number of rounds in the competition, correspondingly.
|
| 17 |
+
|
| 18 |
+
Next m sets of n × n matrices of integers between 0 to 106 (inclusive) will follow — describing the time one car requires to traverse different roads. The k-th integer in j-th line of the i-th set is the time that i-th car requires to traverse the road from j-th city to k-th city. These matrices are not necessarily symmetric, but their diagonal is always zero.
|
| 19 |
+
|
| 20 |
+
Next r lines contain description of the rounds. The i-th of these lines contains space-separated integers si, ti, ki (1 ≤ si, ti ≤ n, si ≠ ti, 0 ≤ ki ≤ 1000) — the number of starting city, finishing city and the number of possible car changes in i-th round, correspondingly.
|
| 21 |
+
|
| 22 |
+
Output
|
| 23 |
+
|
| 24 |
+
For each round you should print the minimum required time to complete the round in a single line.
|
| 25 |
+
|
| 26 |
+
Examples
|
| 27 |
+
|
| 28 |
+
Input
|
| 29 |
+
|
| 30 |
+
4 2 3
|
| 31 |
+
0 1 5 6
|
| 32 |
+
2 0 3 6
|
| 33 |
+
1 3 0 1
|
| 34 |
+
6 6 7 0
|
| 35 |
+
0 3 5 6
|
| 36 |
+
2 0 1 6
|
| 37 |
+
1 3 0 2
|
| 38 |
+
6 6 7 0
|
| 39 |
+
1 4 2
|
| 40 |
+
1 4 1
|
| 41 |
+
1 4 3
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
|
| 46 |
+
3
|
| 47 |
+
4
|
| 48 |
+
3
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Input
|
| 52 |
+
|
| 53 |
+
4 2 3
|
| 54 |
+
0 7 3 3
|
| 55 |
+
8 0 10 5
|
| 56 |
+
1 1 0 4
|
| 57 |
+
8 9 2 0
|
| 58 |
+
0 3 3 9
|
| 59 |
+
7 0 4 9
|
| 60 |
+
3 8 0 4
|
| 61 |
+
4 8 9 0
|
| 62 |
+
2 3 3
|
| 63 |
+
2 1 3
|
| 64 |
+
1 2 2
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Output
|
| 68 |
+
|
| 69 |
+
4
|
| 70 |
+
5
|
| 71 |
+
3
|
| 72 |
+
|
| 73 |
+
Note
|
| 74 |
+
|
| 75 |
+
In the first sample, in all rounds PMP goes from city #1 to city #2, then city #3 and finally city #4. But the sequences of types of the cars he uses are (1, 2, 1) in the first round and (1, 2, 2) in the second round. In the third round, although he can change his car three times, he uses the same strategy as the first round which only needs two car changes.
|
| 76 |
+
|
| 77 |
+
## Contest Information
|
| 78 |
+
- **Contest ID**: 187
|
| 79 |
+
- **Problem Index**: B
|
| 80 |
+
- **Points**: 1000.0
|
| 81 |
+
- **Rating**: 1800
|
| 82 |
+
- **Tags**: dp, shortest paths
|
| 83 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 84 |
+
- **Memory Limit**: 256000000 bytes
|
| 85 |
+
|
| 86 |
+
## Task
|
| 87 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0598/instruction.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02603 M-SOLUTIONS Programming Contest 2020 - Road to Millionaire
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.
|
| 5 |
+
|
| 6 |
+
He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:
|
| 7 |
+
|
| 8 |
+
* A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.
|
| 13 |
+
|
| 14 |
+
* Buy stock: Pay A_i yen and receive one stock.
|
| 15 |
+
* Sell stock: Sell one stock for A_i yen.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
|
| 20 |
+
|
| 21 |
+
Constraints
|
| 22 |
+
|
| 23 |
+
* 2 \leq N \leq 80
|
| 24 |
+
* 100 \leq A_i \leq 200
|
| 25 |
+
* All values in input are integers.
|
| 26 |
+
|
| 27 |
+
Input
|
| 28 |
+
|
| 29 |
+
Input is given from Standard Input in the following format:
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
N
|
| 33 |
+
A_1 A_2 \cdots A_N
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Output
|
| 37 |
+
|
| 38 |
+
Print the maximum possible amount of money that M-kun can have in the end, as an integer.
|
| 39 |
+
|
| 40 |
+
Examples
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
7
|
| 45 |
+
100 130 130 130 115 115 150
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
Output
|
| 49 |
+
|
| 50 |
+
1685
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
Input
|
| 54 |
+
|
| 55 |
+
6
|
| 56 |
+
200 180 160 140 120 100
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
Output
|
| 60 |
+
|
| 61 |
+
1000
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Input
|
| 65 |
+
|
| 66 |
+
2
|
| 67 |
+
157 193
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
Output
|
| 71 |
+
|
| 72 |
+
1216
|
| 73 |
+
|
| 74 |
+
## Contest Information
|
| 75 |
+
- **Contest ID**: 0
|
| 76 |
+
- **Problem Index**:
|
| 77 |
+
- **Points**: 0.0
|
| 78 |
+
- **Rating**: 0
|
| 79 |
+
- **Tags**:
|
| 80 |
+
- **Time Limit**: {'seconds': 2, 'nanos': 0} seconds
|
| 81 |
+
- **Memory Limit**: 1073741824 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-0613/instruction.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p00812 Equals are Equals
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
|
| 5 |
+
|
| 6 |
+
His headache came from the ``creativity'' of his students. They provided him a variety of ways to answer each problem. He has his own answer to each problem, which is correct, of course, and the best from his aesthetic point of view.
|
| 7 |
+
|
| 8 |
+
Some of his students wrote algebraic expressions equivalent to the expected answer, but many of them look quite different from Mr. Simpson's answer in terms of their literal forms. Some wrote algebraic expressions not equivalent to his answer, but they look quite similar to it. Only a few of the students' answers were exactly the same as his.
|
| 9 |
+
|
| 10 |
+
It is his duty to check if each expression is mathematically equivalent to the answer he has prepared. This is to prevent expressions that are equivalent to his from being marked as ``incorrect'', even if they are not acceptable to his aesthetic moral.
|
| 11 |
+
|
| 12 |
+
He had now spent five days checking the expressions. Suddenly, he stood up and yelled, ``I've had enough! I must call for help.''
|
| 13 |
+
|
| 14 |
+
Your job is to write a program to help Mr. Simpson to judge if each answer is equivalent to the ``correct'' one. Algebraic expressions written on the papers are multi-variable polynomials over variable symbols a, b,..., z with integer coefficients, e.g., (a + b2)(a - b2), ax2 +2bx + c and (x2 +5x + 4)(x2 + 5x + 6) + 1.
|
| 15 |
+
|
| 16 |
+
Mr. Simpson will input every answer expression as it is written on the papers; he promises you that an algebraic expression he inputs is a sequence of terms separated by additive operators `+' and `-', representing the sum of the terms with those operators, if any; a term is a juxtaposition of multiplicands, representing their product; and a multiplicand is either (a) a non-negative integer as a digit sequence in decimal, (b) a variable symbol (one of the lowercase letters `a' to `z'), possibly followed by a symbol `^' and a non-zero digit, which represents the power of that variable, or (c) a parenthesized algebraic expression, recursively. Note that the operator `+' or `-' appears only as a binary operator and not as a unary operator to specify the sing of its operand.
|
| 17 |
+
|
| 18 |
+
He says that he will put one or more space characters before an integer if it immediately follows another integer or a digit following the symbol `^'. He also says he may put spaces here and there in an expression as an attempt to make it readable, but he will never put a space between two consecutive digits of an integer. He remarks that the expressions are not so complicated, and that any expression, having its `-'s replaced with `+'s, if any, would have no variable raised to its 10th power, nor coefficient more than a billion, even if it is fully expanded into a form of a sum of products of coefficients and powered variables.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Input
|
| 23 |
+
|
| 24 |
+
The input to your program is a sequence of blocks of lines. A block consists of lines, each containing an expression, and a terminating line. After the last block, there is another terminating line. A terminating line is a line solely consisting of a period symbol.
|
| 25 |
+
|
| 26 |
+
The first expression of a block is one prepared by Mr. Simpson; all that follow in a block are answers by the students. An expression consists of lowercase letters, digits, operators `+', `-' and `^', parentheses `(' and `)', and spaces. A line containing an expression has no more than 80 characters.
|
| 27 |
+
|
| 28 |
+
Output
|
| 29 |
+
|
| 30 |
+
Your program should produce a line solely consisting of ``yes'' or ``no'' for each answer by the students corresponding to whether or not it is mathematically equivalent to the expected answer. Your program should produce a line solely containing a period symbol after each block.
|
| 31 |
+
|
| 32 |
+
Example
|
| 33 |
+
|
| 34 |
+
Input
|
| 35 |
+
|
| 36 |
+
a+b+c
|
| 37 |
+
(a+b)+c
|
| 38 |
+
a- (b-c)+2
|
| 39 |
+
.
|
| 40 |
+
4ab
|
| 41 |
+
(a - b) (0-b+a) - 1a ^ 2 - b ^ 2
|
| 42 |
+
2 b 2 a
|
| 43 |
+
.
|
| 44 |
+
108 a
|
| 45 |
+
2 2 3 3 3 a
|
| 46 |
+
4 a^1 27
|
| 47 |
+
.
|
| 48 |
+
.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Output
|
| 52 |
+
|
| 53 |
+
yes
|
| 54 |
+
no
|
| 55 |
+
.
|
| 56 |
+
no
|
| 57 |
+
yes
|
| 58 |
+
.
|
| 59 |
+
yes
|
| 60 |
+
yes
|
| 61 |
+
.
|
| 62 |
+
|
| 63 |
+
## Contest Information
|
| 64 |
+
- **Contest ID**: 0
|
| 65 |
+
- **Problem Index**:
|
| 66 |
+
- **Points**: 0.0
|
| 67 |
+
- **Rating**: 0
|
| 68 |
+
- **Tags**:
|
| 69 |
+
- **Time Limit**: {'seconds': 8, '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-0615/instruction.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p01076 Graph Making
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem
|
| 5 |
+
|
| 6 |
+
There are n vertices that are not connected to any of the vertices.
|
| 7 |
+
An undirected side is stretched between each vertex.
|
| 8 |
+
Find out how many sides can be stretched when the diameter is set to d.
|
| 9 |
+
The diameter represents the largest of the shortest distances between two vertices.
|
| 10 |
+
Here, the shortest distance is the minimum value of the number of sides required to move between vertices.
|
| 11 |
+
Multiple edges and self-loops are not allowed.
|
| 12 |
+
|
| 13 |
+
Constraints
|
| 14 |
+
|
| 15 |
+
* 2 ≤ n ≤ 109
|
| 16 |
+
* 1 ≤ d ≤ n−1
|
| 17 |
+
|
| 18 |
+
Input
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
n d
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Two integers n and d are given on one line, separated by blanks.
|
| 25 |
+
|
| 26 |
+
Output
|
| 27 |
+
|
| 28 |
+
Output the maximum number of sides that can be stretched on one line.
|
| 29 |
+
|
| 30 |
+
Examples
|
| 31 |
+
|
| 32 |
+
Input
|
| 33 |
+
|
| 34 |
+
4 3
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Output
|
| 38 |
+
|
| 39 |
+
3
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
Input
|
| 43 |
+
|
| 44 |
+
5 1
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Output
|
| 48 |
+
|
| 49 |
+
10
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
Input
|
| 53 |
+
|
| 54 |
+
4 2
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
Output
|
| 58 |
+
|
| 59 |
+
5
|
| 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-0622/instruction.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# p02110 Settler
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
Problem
|
| 5 |
+
|
| 6 |
+
There are N vacant lots on the two-dimensional plane. Numbers from 1 to N are assigned to each vacant lot. Every vacant lot is so small that it can be considered a point. The i-th vacant lot exists at (xi, yi).
|
| 7 |
+
|
| 8 |
+
Taro chose just K from these N vacant lots and decided to build a building in those vacant lots. However, I thought it would be uninteresting to build multiple buildings too close together, so Taro decided to choose a vacant lot so that the Euclidean distance between each vacant lot would always be 2 or more.
|
| 9 |
+
|
| 10 |
+
Create a program that outputs possible combinations of vacant lots that Taro chooses. If there are multiple combinations, output the smallest one in lexicographical order. However, no matter how you choose K vacant lots, if the Euclidean distance of any two vacant lots is less than 2, output -1 instead.
|
| 11 |
+
|
| 12 |
+
Constraints
|
| 13 |
+
|
| 14 |
+
The input satisfies the following conditions.
|
| 15 |
+
|
| 16 |
+
* All inputs are integers.
|
| 17 |
+
* 2 ≤ K ≤ N ≤ 6,000
|
| 18 |
+
* 1 ≤ xi, yi ≤ 1,000,000 (1 ≤ i ≤ N)
|
| 19 |
+
* xi mod 2 = floor (yi ÷ 2) mod 2 (1 ≤ i ≤ N)
|
| 20 |
+
(Here, floor (yi ÷ 2) is the value obtained by dividing yi by 2 and rounding down to the nearest whole number.)
|
| 21 |
+
* There can be no more than one vacant lot at the same coordinates.
|
| 22 |
+
|
| 23 |
+
Input
|
| 24 |
+
|
| 25 |
+
The input is given in the following format.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
N K
|
| 29 |
+
x1 y1
|
| 30 |
+
x2 y2
|
| 31 |
+
...
|
| 32 |
+
xN yN
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Output
|
| 36 |
+
|
| 37 |
+
Output the vacant lot numbers selected by Taro line by line in ascending order.
|
| 38 |
+
|
| 39 |
+
Examples
|
| 40 |
+
|
| 41 |
+
Input
|
| 42 |
+
|
| 43 |
+
3 2
|
| 44 |
+
2 1
|
| 45 |
+
1 2
|
| 46 |
+
1 3
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Output
|
| 50 |
+
|
| 51 |
+
1
|
| 52 |
+
3
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Input
|
| 56 |
+
|
| 57 |
+
4 3
|
| 58 |
+
2 1
|
| 59 |
+
1 2
|
| 60 |
+
1 3
|
| 61 |
+
2 4
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
Output
|
| 65 |
+
|
| 66 |
+
-1
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Input
|
| 70 |
+
|
| 71 |
+
5 3
|
| 72 |
+
5 7
|
| 73 |
+
5 6
|
| 74 |
+
6 8
|
| 75 |
+
20 20
|
| 76 |
+
4 8
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Output
|
| 80 |
+
|
| 81 |
+
2
|
| 82 |
+
3
|
| 83 |
+
4
|
| 84 |
+
|
| 85 |
+
## Contest Information
|
| 86 |
+
- **Contest ID**: 0
|
| 87 |
+
- **Problem Index**:
|
| 88 |
+
- **Points**: 0.0
|
| 89 |
+
- **Rating**: 0
|
| 90 |
+
- **Tags**:
|
| 91 |
+
- **Time Limit**: {'seconds': 1, 'nanos': 0} seconds
|
| 92 |
+
- **Memory Limit**: 267386880 bytes
|
| 93 |
+
|
| 94 |
+
## Task
|
| 95 |
+
Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.
|
code_contests-0625/instruction.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# cb03
|
| 2 |
+
|
| 3 |
+
## Problem Description
|
| 4 |
+
The problem is very simple. For every string given as input, you need to tell us the number of subsequences of it that are palindromes (need not necessarily be distinct). Note that the empty string is not a palindrome.
|
| 5 |
+
|
| 6 |
+
For example, the palindromic subsequences of "aab" are:
|
| 7 |
+
"a", "a", "b", "aa", and the method returns 4.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Input
|
| 11 |
+
|
| 12 |
+
First line contains the number of test cases T (atmost 20). Each of the next T lines contains a single string whose number of palindromic subsequences are to be printed. The maximum length of any input string is 50.
|
| 13 |
+
|
| 14 |
+
Output
|
| 15 |
+
|
| 16 |
+
For each test case, print in a single line, the number of palindromic subsequences of the input string.
|
| 17 |
+
|
| 18 |
+
Example
|
| 19 |
+
|
| 20 |
+
Input:
|
| 21 |
+
3
|
| 22 |
+
aab
|
| 23 |
+
dddd
|
| 24 |
+
thisisapalindromeemordnilapasisiht
|
| 25 |
+
Output:
|
| 26 |
+
4
|
| 27 |
+
15
|
| 28 |
+
814157
|
| 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.
|