Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ M の整数列 A=(A_1,A_2,\dots,A_M) が与えられます。
A の各要素は 1 以上 N 以下で、全ての要素は相異なります。
A の要素として含まれない 1 以上 N 以下の整数を、昇順に全て列挙してください。
制約
- 入力は全て整数
- 1 \le M \le N \le 1000
- 1 \le A_i \le N
- A の要素は相異なる
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_M
出力
A の要素として含まれない 1 以上 N 以下の整数を昇順に全て挙げた列が (X_1,X_2,\dots,X_C) であるとき、以下の形式で出力せよ。
C X_1 X_2 \dots X_C
入力例 1
10 3 3 9 2
出力例 1
7 1 4 5 6 7 8 10
A=(3,9,2) です。
A の要素として含まれない 1 以上 10 以下の整数を昇順に全て挙げると、 1,4,5,6,7,8,10 となります。
入力例 2
6 6 1 3 5 2 4 6
出力例 2
0
A の要素として含まれない 1 以上 6 以下の整数がひとつもありません。
この場合、 1 行目に 0 と出力し、 2 行目は空行としてください。
入力例 3
9 1 9
出力例 3
8 1 2 3 4 5 6 7 8
Score : 200 points
Problem Statement
You are given a sequence of M integers A = (A_1, A_2, \dots, A_M).
Each element of A is an integer between 1 and N, inclusive, and all elements are distinct.
List all integers between 1 and N that do not appear in A in ascending order.
Constraints
- All input values are integers.
- 1 \le M \le N \le 1000
- 1 \le A_i \le N
- The elements of A are distinct.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_M
Output
Let (X_1, X_2, \dots, X_C) be the sequence of all integers between 1 and N, inclusive, that do not appear in A, listed in ascending order. The output should be in the following format:
C X_1 X_2 \dots X_C
Sample Input 1
10 3 3 9 2
Sample Output 1
7 1 4 5 6 7 8 10
Here, A=(3,9,2).
The integers between 1 and 10 that do not appear in A, listed in ascending order, are 1,4,5,6,7,8,10.
Sample Input 2
6 6 1 3 5 2 4 6
Sample Output 2
0
No integer between 1 and 6 is missing from A.
In this case, print 0 on the first line and leave the second line empty.
Sample Input 3
9 1 9
Sample Output 3
8 1 2 3 4 5 6 7 8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
縦 N マス、横 N マスのグリッドが 2 個与えられます。それぞれグリッド A, グリッド B と呼びます。
グリッドの各マスには英小文字が書かれています。
グリッド A の上から i 行目、左から j 列目に書かれている文字は A_{i, j} です。
グリッド B の上から i 行目、左から j 列目に書かれている文字は B_{i, j} です。
2 つのグリッドは 1 ヵ所だけ書かれている文字が異なります。すなわち、A_{i, j} \neq B_{i, j} である N 以下の正整数の組 (i, j) はちょうど 1 個存在します。この (i, j) を求めてください。
制約
- 1 \leq N \leq 100
- A_{i, j}, B_{i, j} は全て英小文字
- A_{i, j} \neq B_{i, j} である (i, j) がちょうど 1 個存在する
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
B_{1,1}B_{1,2}\dots B_{1,N}
B_{2,1}B_{2,2}\dots B_{2,N}
\vdots
B_{N,1}B_{N,2}\dots B_{N,N}
出力
A_{i, j} \neq B_{i, j} である N 以下の正整数の組を (i, j) とする。この時、(i, j) を以下の形式で出力せよ。
i j
入力例 1
3 abc def ghi abc bef ghi
出力例 1
2 1
A_{2, 1} = d、B_{2, 1} = b なので A_{2, 1} \neq B_{2, 1} が成り立つため、(i, j) = (2, 1) は問題文の条件を満たします。
入力例 2
1 f q
出力例 2
1 1
入力例 3
10 eixfumagit vtophbepfe pxbfgsqcug ugpugtsxzq bvfhxyehfk uqyfwtmglr jaitenfqiq acwvufpfvv jhaddglpva aacxsyqvoj eixfumagit vtophbepfe pxbfgsqcug ugpugtsxzq bvfhxyehok uqyfwtmglr jaitenfqiq acwvufpfvv jhaddglpva aacxsyqvoj
出力例 3
5 9
Score: 150 points
Problem Statement
You are given two grids, each with N rows and N columns, referred to as grid A and grid B.
Each cell in the grids contains a lowercase English letter.
The character at the i-th row and j-th column of grid A is A_{i, j}.
The character at the i-th row and j-th column of grid B is B_{i, j}.
The two grids differ in exactly one cell. That is, there exists exactly one pair (i, j) of positive integers not greater than N such that A_{i, j} \neq B_{i, j}. Find this (i, j).
Constraints
- 1 \leq N \leq 100
- A_{i, j} and B_{i, j} are all lowercase English letters.
- There exists exactly one pair (i, j) such that A_{i, j} \neq B_{i, j}.
Input
The input is given from Standard Input in the following format:
N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}
B_{1,1}B_{1,2}\dots B_{1,N}
B_{2,1}B_{2,2}\dots B_{2,N}
\vdots
B_{N,1}B_{N,2}\dots B_{N,N}
Output
Let (i, j) be the pair of positive integers not greater than N such that A_{i, j} \neq B_{i, j}. Print (i, j) in the following format:
i j
Sample Input 1
3 abc def ghi abc bef ghi
Sample Output 1
2 1
From A_{2, 1} = d and B_{2, 1} = b, we have A_{2, 1} \neq B_{2, 1}, so (i, j) = (2, 1) satisfies the condition in the problem statement.
Sample Input 2
1 f q
Sample Output 2
1 1
Sample Input 3
10 eixfumagit vtophbepfe pxbfgsqcug ugpugtsxzq bvfhxyehfk uqyfwtmglr jaitenfqiq acwvufpfvv jhaddglpva aacxsyqvoj eixfumagit vtophbepfe pxbfgsqcug ugpugtsxzq bvfhxyehok uqyfwtmglr jaitenfqiq acwvufpfvv jhaddglpva aacxsyqvoj
Sample Output 3
5 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字からなる長さ N の文字列 S が与えられます。 S の各文字は色 1 、色 2 、\ldots 、色 M の M 色のうちのいずれかで塗られており、 i = 1, 2, \ldots, N について、S の i 文字目は色 C_i で塗られています。
各 i = 1, 2, \ldots, M について、この順番に下記の操作を行います。
- S の色 i で塗られた文字からなる部分を、右に 1 つ巡回シフトする。 すなわち、S の 色 i で塗られた文字の位置が先頭のものから順に p_1, p_2, p_3, \ldots, p_k 文字目であるとき、 S の p_1, p_2, p_3, \ldots, p_k 文字目を、それぞれ、S の p_k, p_1,p_2, \ldots, p_{k-1} 文字目で同時に置き換える。
上記の操作をすべて行った後の、最終的な S を出力してください。
なお、M 色あるどの色についても、その色で塗られた S の文字が必ず 1 つ以上存在することが、制約として保証されます。
制約
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq C_i \leq M
- N, M, C_i はすべて整数
- S は英小文字からなる長さ N の文字列
- 任意の整数 1 \leq i \leq M に対して、ある整数 1 \leq j \leq N が存在して C_j = i が成り立つ
入力
入力は以下の形式で標準入力から与えられる。
N M S C_1 C_2 \ldots C_N
出力
答えを出力せよ。
入力例 1
8 3 apzbqrcs 1 2 3 1 2 2 1 2
出力例 1
cszapqbr
はじめ、S = apzbqrcs です。
- i = 1 に対する操作では、S の 1, 4, 7 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S =
cpzaqrbsとなります。 - i = 2 に対する操作では、S の 2, 5, 6, 8 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S =
cszapqbrとなります。 - i = 3 に対する操作では、S の 3 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S =
cszapqbrとなります(操作の前後で S は変わりません)。
よって、最終的な S である cszapqbr を出力します。
入力例 2
2 1 aa 1 1
出力例 2
aa
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters. Each character of S is painted in one of the M colors: color 1, color 2, ..., color M; for each i = 1, 2, \ldots, N, the i-th character of S is painted in color C_i.
For each i = 1, 2, \ldots, M in this order, let us perform the following operation.
- Perform a right circular shift by 1 on the part of S painted in color i. That is, if the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters are painted in color i from left to right, then simultaneously replace the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters of S with the p_k-th, p_1-th, p_2-th, \ldots, p_{k-1}-th characters of S, respectively.
Print the final S after the above operations.
The constraints guarantee that at least one character of S is painted in each of the M colors.
Constraints
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq C_i \leq M
- N, M, and C_i are all integers.
- S is a string of length N consisting of lowercase English letters.
- For each integer 1 \leq i \leq M, there is an integer 1 \leq j \leq N such that C_j = i.
Input
The input is given from Standard Input in the following format:
N M S C_1 C_2 \ldots C_N
Output
Print the answer.
Sample Input 1
8 3 apzbqrcs 1 2 3 1 2 2 1 2
Sample Output 1
cszapqbr
Initially, S = apzbqrcs.
- For i = 1, perform a right circular shift by 1 on the part of S formed by the 1-st, 4-th, 7-th characters, resulting in S =
cpzaqrbs. - For i = 2, perform a right circular shift by 1 on the part of S formed by the 2-nd, 5-th, 6-th, 8-th characters, resulting in S =
cszapqbr. - For i = 3, perform a right circular shift by 1 on the part of S formed by the 3-rd character, resulting in S =
cszapqbr(here, S is not changed).
Thus, you should print cszapqbr, the final S.
Sample Input 2
2 1 aa 1 1
Sample Output 2
aa
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋くんは、文字をいくつか持っています。
高橋くんが持っている文字は A, B, C のいずれかです。
はじめ、高橋くんは A を n _ A 個、B を n _ B 個、C を n _ C 個持っています。
高橋くんは、A を 1 つ、C を 1 つ、さらに追加で任意の 1 つの文字の合計 3 文字を使うことで、コンテストを 1 つ開催することができます。
具体的には、A を 2 つ、C を 1 つ使うと AAC を、A, B, C を 1 つずつ使うと ABC を、A を 1 つ、C を 2 つ使うと ACC を開催することができます。
高橋くんは、現在持っている文字を使ってコンテストをなるべく多く開催したいです。 高橋くんが最大でいくつのコンテストを開催することができるか求めてください。
T 個のテストケースが与えられるので、それぞれについて答えてください。
制約
- 1\le T\le2\times10 ^ 5
- それぞれのテストケースについて、
- 0\le n _ A\le10 ^ 9
- 0\le n _ B\le10 ^ 9
- 0\le n _ C\le10 ^ 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{testcase} _ 1
\mathrm{testcase} _ 2
\vdots
\mathrm{testcase} _ T
\mathrm{testcase} _ i\ (1\le i\le T) は i 番目のテストケースを表しており、次の形式で与えられる。
n _ A n _ B n _ C
出力
T 行にわたって出力せよ。 i 行目 (1\le i\le T) には、i 番目のテストケースの答えを出力せよ。
入力例 1
5 3 1 2 100 0 0 1000000 1000000 1000000 31 41 59 1000000000 10000 1
出力例 1
2 0 1000000 31 1
1 つめのテストケースでは、AAC を 1 回、ABC を 1 回の計 2 回のコンテストを開催することができます。
よって、1 行目には 2 を出力してください。
Score : 300 points
Problem Statement
Takahashi has some letters.
Each letter he has is A, B, or C.
Initially, he has n _ A letters A, n _ B letters B, and n _ C letters C.
He can hold one contest by using one letter A, one letter C, and additionally any one letter, for a total of three letters.
Specifically, he can hold AAC by using two letters A and one letter C, ABC by using one letter each of A, B, and C, and ACC by using one letter A and two letters C.
He wants to hold as many contests as possible using the letters he currently has. Find the maximum number of contests he can hold.
T test cases are given, so report the answer for each of them.
Constraints
- 1\le T\le2\times10 ^ 5
- For each test case,
- 0\le n _ A\le10 ^ 9
- 0\le n _ B\le10 ^ 9
- 0\le n _ C\le10 ^ 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\mathrm{testcase} _ 1
\mathrm{testcase} _ 2
\vdots
\mathrm{testcase} _ T
\mathrm{testcase} _ i\ (1\le i\le T) represents the i-th test case and is given in the following format:
n _ A n _ B n _ C
Output
Output over T lines. On the i-th line (1\le i\le T), output the answer to the i-th test case.
Sample Input 1
5 3 1 2 100 0 0 1000000 1000000 1000000 31 41 59 1000000000 10000 1
Sample Output 1
2 0 1000000 31 1
In the first test case, he can hold AAC once and ABC once, for a total of two contests.
Therefore, output 2 on the first line.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
長さ N の整数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。 ここで、どの i\ (1\le i\le N) についても A _ i が 0 でないことが保証されます。
A を適切に並べ替えた数列 B=(B _ 1,B _ 2,\ldots,B _ N) が等比数列になることがあるか判定してください。
ただし、数列 S=(S _ 1,S _ 2,\ldots,S _ N) が等比数列であるとは、ある実数 r が存在してすべての整数 1\le i\lt N に対して S _ {i+1}=rS _ i が成り立つことをいいます。
1 つの入力ファイルにつき、T 個のテストケースを解いてください。
制約
- 1\le T\le10 ^ 5
- 2\le N\le2\times10 ^ 5
- -10 ^ 9\le A _ i\le10 ^ 9\ (1\le i\le N)
- A _ i\ne0\ (1\le i\le N)
- 1 つの入力ファイルにおける N の総和は 2\times10 ^ 5 以下
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{testcase} _ 1
\mathrm{testcase} _ 2
\vdots
\mathrm{testcase} _ T
ここで、\mathrm{testcase} _ i は i 番目 (1\le i\le T) のテストケースであり、各テストケースは以下の形式で与えられる。
N A _ 1 A _ 2 \ldots A _ N
出力
T 行にわたって出力せよ。
i 行目 (1\le i\le T) には、i 番目のテストケースにおいて A を並べ替えて等比数列にできる場合は Yes を、そうでない場合は No を出力せよ。
入力例 1
3 5 1 8 2 4 16 5 -16 24 54 81 -36 7 90000 8100 -27000 729 -300000 -2430 1000000
出力例 1
Yes No Yes
1 つめのテストケースでは、A を並べ替えた (16,8,4,2,1) は、公比 r=\dfrac12 の等比数列になります。
よって、1 行目には Yes と出力してください。
2 つめのテストケースでは、A をどのように並べ替えても条件を満たしません。
よって、2 行目には No と出力してください。
Score : 425 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N. It is guaranteed that for any i\ (1\le i\le N), A_i is not 0.
Determine whether there exists a permutation B=(B_1,B_2,\ldots,B_N) of A such that B forms a geometric sequence.
A sequence S=(S_1,S_2,\ldots,S_N) is a geometric sequence if there exists a real number r such that S_{i+1}=rS_i for all integers 1\le i\lt N.
Solve T test cases per input file.
Constraints
- 1\le T\le10^5
- 2\le N\le2\times10^5
- -10^9\le A_i\le10^9\ (1\le i\le N)
- A_i\ne0\ (1\le i\le N)
- The sum of N over all test cases in a single input file is at most 2\times10^5.
- All input values are integers.
Input
The input is given from standard input in the following format:
T
\mathrm{testcase}_1
\mathrm{testcase}_2
\vdots
\mathrm{testcase}_T
where \mathrm{testcase}_i is the i-th test case (1\le i\le T), and each test case is given in the following format:
N A_1 A_2 \ldots A_N
Output
Output T lines.
The i-th line (1\le i\le T) should contain Yes if A can be rearranged to form a geometric sequence in the i-th test case, and No otherwise.
Sample Input 1
3 5 1 8 2 4 16 5 -16 24 54 81 -36 7 90000 8100 -27000 729 -300000 -2430 1000000
Sample Output 1
Yes No Yes
In the first test case, the rearrangement (16,8,4,2,1) of A forms a geometric sequence with common ratio r=\frac{1}{2}.
Thus, print Yes on the first line.
In the second test case, no rearrangement of A satisfies the condition.
Thus, print No on the second line.