Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
0 以上 9 以下の整数 A, B が与えられます。
0 以上 9 以下の整数であって A + B と等しくないものをいずれかひとつ出力してください。
制約
- 0 \leq A \leq 9
- 0 \leq B \leq 9
- A + B \leq 9
- A, B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
0 以上 9 以下の整数であって A + B と等しくないものをいずれかひとつ出力せよ。
入力例 1
2 5
出力例 1
2
A = 2, B = 5 のとき A + B = 7 です。したがって、0, 1, 2, 3, 4, 5, 6, 8, 9 のいずれかを出力すると正解となります。
入力例 2
0 0
出力例 2
9
入力例 3
7 1
出力例 3
4
Score: 100 points
Problem Statement
You are given two integers A and B, each between 0 and 9, inclusive.
Print any integer between 0 and 9, inclusive, that is not equal to A + B.
Constraints
- 0 \leq A \leq 9
- 0 \leq B \leq 9
- A + B \leq 9
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print any integer between 0 and 9, inclusive, that is not equal to A + B.
Sample Input 1
2 5
Sample Output 1
2
When A = 2, B = 5, we have A + B = 7. Thus, printing any of 0, 1, 2, 3, 4, 5, 6, 8, 9 is correct.
Sample Input 2
0 0
Sample Output 2
9
Sample Input 3
7 1
Sample Output 3
4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 A,B が与えられます。
A+B の二乗を出力してください。
制約
- 1\leq A,B \leq 2025
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
入力例 1
20 25
出力例 1
2025
(20+25)^2=2025 です。
入力例 2
30 25
出力例 2
3025
入力例 3
45 11
出力例 3
3136
入力例 4
2025 1111
出力例 4
9834496
Score : 100 points
Problem Statement
You are given two positive integers A and B.
Output the square of A + B.
Constraints
- 1 \leq A,B \leq 2025
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Sample Input 1
20 25
Sample Output 1
2025
(20+25)^2=2025.
Sample Input 2
30 25
Sample Output 2
3025
Sample Input 3
45 11
Sample Output 3
3136
Sample Input 4
2025 1111
Sample Output 4
9834496
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
高橋君は改札機の利用履歴を集計しました。 しかし、高橋君はうっかりいくつかの入退場記録を消してしまいました。 高橋君は消してしまった記録の復元を試みようとしています。
i, o のみからなる文字列 S が与えられます。
S の任意の位置に文字を 0 文字以上挿入することで、変更後の文字列が以下の条件を満たすようにしたいです。
- 長さが偶数であり、奇数文字目が
iで偶数文字目がoである。
挿入する必要のある文字数の最小値を求めて下さい。なお、問題の制約下で、有限個の文字を適切に挿入することで、S が条件をみたすようにできることが証明できます。
制約
- S は
i,oからなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
ioi
出力例 1
1
3 文字目のあとに o を挿入して ioio とすることで、条件を満たすことができます。0 文字以下の挿入で条件を満たすことはできません。
入力例 2
iioo
出力例 2
2
1 文字目のあとに o を、3 文字目のあとに i を挿入することで、条件を満たすことができます。1 文字以下の挿入で条件を満たすことはできません。
入力例 3
io
出力例 3
0
S がすでに条件を満たします。
Score : 250 points
Problem Statement
Takahashi aggregated usage records from ticket gates. However, he accidentally erased some records of entering and exiting stations. He is trying to restore the erased records.
You are given a string S consisting of i and o. We want to insert zero or more characters at arbitrary positions in S so that the resulting string satisfies the following conditions:
- Its length is even, and every odd-numbered (1st, 3rd, ...) character is
iwhile every even-numbered (2nd, 4th, ...) character iso.
Find the minimum number of characters that need to be inserted. It can be proved under the constraints of this problem that by inserting an appropriate finite number of characters, S can be made to satisfy the conditions.
Constraints
- S is a string of length between 1 and 100, consisting of
iando.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
ioi
Sample Output 1
1
We can insert o after the 3rd character to form ioio to satisfy the conditions. The conditions cannot be satisfied by inserting zero or fewer characters.
Sample Input 2
iioo
Sample Output 2
2
We can insert o after the 1st character and i after the 3rd character to satisfy the conditions. The conditions cannot be satisfied by inserting one or fewer characters.
Sample Input 3
io
Sample Output 3
0
S already satisfies the conditions.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 N, M が与えられます。
X = \displaystyle\sum_{i = 0}^{M} N^i とします。X \leq 10^9 のときは X の値を、X > 10^9 のときは文字列 inf を出力してください。
制約
- 1 \leq N \leq 10^9
- 1 \leq M \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
問題文の指示に従って X の値あるいは inf を出力せよ。
入力例 1
7 3
出力例 1
400
X = 1 + 7 + 49 + 343 = 400 です。400 \leq 10^9 であるため 400 を出力します。
入力例 2
1000000 2
出力例 2
inf
X = 1000001000001 > 10^9 であるため、inf を出力します。
入力例 3
999999999 1
出力例 3
1000000000
入力例 4
998244353 99
出力例 4
inf
Score : 200 points
Problem Statement
You are given two positive integers N and M.
Let X = \displaystyle\sum_{i = 0}^{M} N^i. If X \leq 10^9, print the value of X. If X > 10^9, print inf.
Constraints
- 1 \leq N \leq 10^9
- 1 \leq M \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the value of X or inf as specified by the problem statement.
Sample Input 1
7 3
Sample Output 1
400
X = 1 + 7 + 49 + 343 = 400. Since 400 \leq 10^9, print 400.
Sample Input 2
1000000 2
Sample Output 2
inf
X = 1000001000001 > 10^9, so print inf.
Sample Input 3
999999999 1
Sample Output 3
1000000000
Sample Input 4
998244353 99
Sample Output 4
inf
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君と青木君は 2 人で次の対戦ゲームをします。
高橋君が先手でゲームを始め、ゲームが終了するまでの間、 2 人は交互に 1 以上 2N+1 以下の整数を 1 つずつ宣言します。 どちらかが一度でも宣言した整数は、それ以降どちらも二度と宣言することが出来ません。 先に整数を宣言することが出来なくなった方のプレイヤーの負けとなり、負けなかった方のプレイヤーの勝ちとなります。
このゲームでは必ず高橋君が勝ちます。 高橋君の立場で実際にゲームを行い、ゲームに勝ってください。
制約
- 1 \leq N \leq 1000
- N は整数
入出力
この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジプログラムが入出力を介して対話を行う形式の問題)です。
あなたのプログラムが高橋君の立場で、ジャッジプログラムが青木君の立場でゲームを行います。
まず、あなたのプログラムに標準入力から正の整数 N が与えられます。 その後、ゲームが終了するまで下記の手順を繰り返します。
- あなたのプログラムが、高橋君が宣言する整数として、1 以上 2N+1 以下の整数を標準出力に出力します。(どちらかのプレイヤーによってすでに宣言されている整数を出力することは出来ません。)
- ジャッジプログラムによって、青木君が宣言する整数があなたのプログラムに標準入力から与えられます。(どちらかのプレイヤーによってすでに宣言されている整数が入力されることはありません。) ただし、青木君が宣言できる整数が残っていない場合は、代わりに 0 が与えられ高橋君の勝ちでゲームが終了します。
注意点
- 出力を行うたびに標準出力をflushしてください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 高橋君の勝ちでゲームが終了したあと、あなたのプログラムは直ちに終了しなければなりません。そうしなかった場合、ジャッジ結果が AC とならない可能性があります。
- ゲームの途中で不正な出力を行った場合(例えば、すでにどちらかのプレイヤーによって宣言されている整数を出力した場合)は不正解となりますが、そのときのジャッジ結果は不定です。WA になるとは限りません。
入出力例
| 入力 | 出力 | 説明 |
|---|---|---|
| 2 | まず整数 N が与えられます。 | |
| 1 | 高橋君が 1 を宣言します。 | |
| 3 | 青木君が 3 を宣言します。 | |
| 2 | 高橋君が 2 を宣言します。 | |
| 4 | 青木君が 4 を宣言します。 | |
| 5 | 高橋君が 5 を宣言します。 | |
| 0 | 青木君が宣言できる整数が残っていないため、高橋君の勝ちでゲームが終了します。 |
Score : 300 points
Problem Statement
Takahashi and Aoki will play the following game against each other.
Starting from Takahashi, the two alternatingly declare an integer between 1 and 2N+1 (inclusive) until the game ends. Any integer declared by either player cannot be declared by either player again. The player who is no longer able to declare an integer loses; the player who didn't lose wins.
In this game, Takahashi will always win. Your task is to actually play the game on behalf of Takahashi and win the game.
Constraints
- 1 \leq N \leq 1000
- N is an integer.
Input and Output
This task is an interactive task (in which your program and the judge program interact with each other via inputs and outputs).
Your program plays the game on behalf of Takahashi, and the judge program plays the game on behalf of Aoki.
First, your program is given a positive integer N from Standard Input. Then, the following procedures are repeated until the game ends.
- Your program outputs an integer between 1 and 2N+1 (inclusive) to Standard Output, which defines the integer that Takahashi declares. (You cannot output an integer that is already declared by either player.)
- The integer that Aoki declares is given by the judge program to your program from Standard Input. (No integer that is already declared by either player will be given.) If Aoki has no more integer to declare, 0 is given instead, which means that the game ended and Takahashi won.
Notes
- After each output, you must flush Standard Output. Otherwise, you may get TLE.
- After the game ended and Takahashi won, the program must be terminated immediately. Otherwise, the judge does not necessarily give AC.
- If your program outputs something that violates the rules of the game (such as an integer that has already been declared by either player), your answer is considered incorrect. In such case, the verdict is indeterminate. It does not necessarily give WA.
Sample Input and Output
| Input | Output | Description |
|---|---|---|
| 2 | First, an integer N is given. | |
| 1 | Takahashi declares an integer 1. | |
| 3 | Aoki declares an integer 3. | |
| 2 | Takahashi declares an integer 2. | |
| 4 | Aoki declares an integer 4. | |
| 5 | Takahashi declares an integer 5. | |
| 0 | Aoki has no more integer to declare, so Takahashi wins, and the game ends. |
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
頂点 1, 頂点 2,\ldots, 頂点 N の N 個の頂点からなる単純無向グラフ G,H が与えられます。 G には M _ G 本の辺があり、i 本目 (1\leq i\leq M _ G) の辺は頂点 u _ i と頂点 v _ i を結んでいます。 H には M _ H 本の辺があり、i 本目 (1\leq i\leq M _ H) の辺は頂点 a _ i と頂点 b _ i を結んでいます。
あなたは、グラフ H に対して次の操作を 0 回以上の好きな回数繰り返すことができます。
- 1\leq i\lt j\leq N を満たす整数の組 (i,j) をひとつ選ぶ。A _ {i,j} 円を支払って、頂点 i と頂点 j を結ぶ辺がなければ追加し、あれば取り除く。
G と H を同型にするために少なくとも何円支払う必要があるか求めてください。
単純無向グラフとは?
単純無向グラフとは、自己ループや多重辺を含まず、辺に向きの無いグラフのことをいいます。
グラフの同型とは?
N 頂点のグラフ G と H が同型であるとは、ある (1,2,\ldots,N) の並べ替え (P _ 1,P _ 2,\ldots,P _ N) が存在して、どの 1\leq i\lt j\leq N に対しても
- G に頂点 i, 頂点 j を結ぶ辺が存在するとき、かつそのときに限り H に頂点 P _ i, 頂点 P _ j を結ぶ辺が存在する
制約
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
出力
答えを出力せよ。
入力例 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
出力例 1
9
与えられたグラフはそれぞれ以下のようになります。

たとえば、H に対して次のような 4 つの操作を順に行うことで、9 円を支払ってG と H を同型にすることができます。
- (i,j)=(1,3) として操作を行う。H には頂点 1 と頂点 3 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(2,5) として操作を行う。H には頂点 2 と頂点 5 を結ぶ辺はないので、2 円を支払ってこれを追加する。
- (i,j)=(1,5) として操作を行う。H には頂点 1 と頂点 5 を結ぶ辺があるので、1 円を支払ってこれを取り除く。
- (i,j)=(3,5) として操作を行う。H には頂点 3 と頂点 5 を結ぶ辺はないので、5 円を支払ってこれを追加する。
操作の結果、H は以下のようになります。

支払う金額を 8 円以下にして G と H を同型にすることはできないため、9 を出力してください。
入力例 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
出力例 2
3
たとえば、(i,j)=(2,3),(2,4),(3,4) とした 3 回の操作を行うことで G と H を同型にすることができます。
入力例 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
出力例 3
5
たとえば、(i,j)=(4,5) とした 1 回の操作を行うことで G と H を同型にすることができます。
入力例 4
2 0 0 371
出力例 4
0
G や H には辺が含まれていないこともあります。 また、一度も操作をする必要がないこともあります。
入力例 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
出力例 5
21214
Score : 300 points
Problem Statement
You are given simple undirected graphs G and H, each with N vertices: vertices 1, 2, \ldots, N. Graph G has M_G edges, and its i-th edge (1\leq i\leq M_G) connects vertices u_i and v_i. Graph H has M_H edges, and its i-th edge (1\leq i\leq M_H) connects vertices a_i and b_i.
You can perform the following operation on graph H any number of times, possibly zero.
- Choose a pair of integers (i,j) satisfying 1\leq i<j\leq N. Pay A_{i,j} yen, and if there is no edge between vertices i and j in H, add one; if there is, remove it.
Find the minimum total cost required to make G and H isomorphic.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges, where edges have no direction.
What does it mean for graphs to be isomorphic?
Two graphs G and H with N vertices are isomorphic if and only if there exists a permutation (P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) such that for all 1\leq i\lt j\leq N:
- an edge exists between vertices i and j in G if and only if an edge exists between vertices P_i and P_j in H.
Constraints
- 1\leq N\leq8
- 0\leq M _ G\leq\dfrac{N(N-1)}2
- 0\leq M _ H\leq\dfrac{N(N-1)}2
- 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M _ G)
- (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)
- 1\leq a _ i\lt b _ i\leq N\ (1\leq i\leq M _ H)
- (a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)
- 1\leq A _ {i,j}\leq 10 ^ 6\ (1\leq i\lt j\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
M _ G
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ {M _ G} v _ {M _ G}
M _ H
a _ 1 b _ 1
a _ 2 b _ 2
\vdots
a _ {M _ H} b _ {M _ H}
A _ {1,2} A _ {1,3} \ldots A _ {1,N}
A _ {2,3} \ldots A _ {2,N}
\vdots
A _ {N-1,N}
Output
Print the answer.
Sample Input 1
5 4 1 2 2 3 3 4 4 5 4 1 2 1 3 1 4 1 5 3 1 4 1 5 9 2 6 5 3
Sample Output 1
9
The given graphs are as follows:

For example, you can perform the following four operations on H to make it isomorphic to G at a cost of 9 yen.
- Choose (i,j)=(1,3). There is an edge between vertices 1 and 3 in H, so pay 1 yen to remove it.
- Choose (i,j)=(2,5). There is no edge between vertices 2 and 5 in H, so pay 2 yen to add it.
- Choose (i,j)=(1,5). There is an edge between vertices 1 and 5 in H, so pay 1 yen to remove it.
- Choose (i,j)=(3,5). There is no edge between vertices 3 and 5 in H, so pay 5 yen to add it.
After these operations, H becomes:

You cannot make G and H isomorphic at a cost less than 9 yen, so print 9.
Sample Input 2
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 9 1 1 1 1 1 1 1 1 9
Sample Output 2
3
For example, performing the operations (i,j)=(2,3),(2,4),(3,4) on H will make it isomorphic to G.
Sample Input 3
5 3 1 2 2 3 3 4 4 1 2 2 3 3 4 4 5 5 4 4 4 4 4 4 4 4 5
Sample Output 3
5
For example, performing the operation (i,j)=(4,5) once will make G and H isomorphic.
Sample Input 4
2 0 0 371
Sample Output 4
0
Note that G and H may have no edges.
Also, it is possible that no operations are needed.
Sample Input 5
8 13 1 8 5 7 4 6 1 5 7 8 1 6 1 2 5 8 2 6 5 6 6 7 3 7 4 8 15 3 5 1 7 4 6 3 8 7 8 1 2 5 6 1 6 1 5 1 4 2 8 2 6 2 4 4 7 1 3 7483 1694 5868 3296 9723 5299 4326 5195 4088 5871 1384 2491 6562 1149 6326 2996 9845 7557 4041 7720 1554 5060 8329 8541 3530 4652 3874 3748
Sample Output 5
21214
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
AtCoder 国には動物園が N 園あり、1 から N の番号がついています。動物園 i の入園料は C_i 円です。
鈴木さんは M 種類の動物、動物 1,\ldots,M が好きです。
動物 i は K_i 園の動物園 A_{i,1},\dots, A_{i,K_i} で見ることができます。
M 種類の動物全てを 2 度以上ずつ見るために必要な入園料の合計の最小値を求めてください。
なお、同じ動物園を複数回訪れた場合、その動物園の動物は訪れた回数だけ見たとみなします。
制約
- 1\leq N \leq 10
- 1\leq M \leq 100
- 0\leq C_i \leq 10^9
- 1\leq K_i \leq N
- 1 \leq A_{i,j} \leq N
- j \neq j' \Longrightarrow A_{i,j}\neq A_{i,j'}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
C_1 \dots C_N
K_1 A_{1,1} \dots A_{1,K_1}
\vdots
K_M A_{M,1} \dots A_{M,K_M}
出力
答えを出力せよ。
入力例 1
4 3 1000 300 700 200 3 1 3 4 3 1 2 4 2 1 3
出力例 1
1800
以下のようにすることで、1800 円で動物 1,2,3 を 2 度以上ずつ見ることができます。
- 動物園 3 に行く。入園料 700 円を払い、動物 1,3 を見る。
- 動物園 3 に行く。入園料 700 円を払い、動物 1,3 を見る。
- 動物園 4 に行く。入園料 200 円を払い、動物 1,2 を見る。
- 動物園 4 に行く。入園料 200 円を払い、動物 1,2 を見る。
入力例 2
7 6 500 500 500 500 500 500 1000 3 1 2 7 3 2 3 7 3 3 4 7 3 4 5 7 3 5 6 7 3 6 1 7
出力例 2
2000
動物園 7 に 2 度行くことで、合計 2000 円で動物 1,2,3,4,5,6 を 2 度ずつ見ることができます。
Score : 400 points
Problem Statement
In the country of AtCoder there are N zoos, numbered 1 to N. The admission fee for zoo i is C_i yen.
Mr. Suzuki likes M kinds of animals, animals 1,\dots,M.
Animal i can be seen at K_i zoos, namely zoos A_{i,1},\dots,A_{i,K_i}.
Find the minimum total admission fee required to see all M kinds of animals at least twice each.
If you visit the same zoo multiple times, the animals there are considered seen once per every visit.
Constraints
- 1 \le N \le 10
- 1 \le M \le 100
- 0 \le C_i \le 10^9
- 1 \le K_i \le N
- 1 \le A_{i,j} \le N
- j \neq j' \Longrightarrow A_{i,j} \neq A_{i,j'}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
C_1 \dots C_N
K_1 A_{1,1} \dots A_{1,K_1}
\vdots
K_M A_{M,1} \dots A_{M,K_M}
Output
Output the minimum total admission fee.
Sample Input 1
4 3 1000 300 700 200 3 1 3 4 3 1 2 4 2 1 3
Sample Output 1
1800
For example, the following schedule achieves seeing animals 1,2,3 at least twice each for a total of 1800 yen:
- Go to zoo 3. Pay 700 yen and see animals 1 and 3.
- Go to zoo 3. Pay 700 yen and see animals 1 and 3.
- Go to zoo 4. Pay 200 yen and see animals 1 and 2.
- Go to zoo 4. Pay 200 yen and see animals 1 and 2.
Sample Input 2
7 6 500 500 500 500 500 500 1000 3 1 2 7 3 2 3 7 3 3 4 7 3 4 5 7 3 5 6 7 3 6 1 7
Sample Output 2
2000
By visiting zoo 7 twice, you can see animals 1,2,3,4,5,6 twice each for a total of 2000 yen.
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
高橋君は N 枚のチョコレートを持っています。i 枚目のチョコレートは縦 A_i cm 横 B_i cm の長方形の形をしています。
また、高橋君は M 個の箱を持っています。i 個目の箱は縦 C_i cm 横 D_i cm の長方形の形をしています。
以下の条件を全て満たすように N 枚のチョコレートを全て箱に入れることは可能か判定してください。
- 1 個の箱に入れることのできるチョコレートの数は、高々 1 個である
- i 枚目のチョコレートを j 個目の箱に入れるとき、A_i \leq C_j かつ B_i \leq D_j を満たす必要がある(回転は不可)
制約
- 1 \leq N \leq M \leq 2\times 10^5
- 1 \leq A_i,B_i,C_i,D_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 \ldots A_N B_1 \ldots B_N C_1 \ldots C_M D_1 \ldots D_M
出力
N 枚のチョコレートを全て箱に入れることが可能ならば Yes と、不可能ならば No と出力せよ。
入力例 1
2 3 2 4 3 2 8 1 5 2 10 5
出力例 1
Yes
1 枚目のチョコレートを 3 個目の箱に入れて、2 枚目のチョコレートを 1 個目の箱に入れればよいです。
入力例 2
2 2 1 1 2 2 100 1 100 1
出力例 2
No
1 個の箱に入れることのできるチョコレートの数は、高々 1 個です。
入力例 3
1 1 10 100 100 10
出力例 3
No
入力例 4
1 1 10 100 10 100
出力例 4
Yes
Score : 500 points
Problem Statement
Takahashi has N pieces of chocolate. The i-th piece has a rectangular shape with a width of A_i centimeters and a length of B_i centimeters.
He also has M boxes. The i-th box has a rectangular shape with a width of C_i centimeters and a length of D_i centimeters.
Determine whether it is possible to put the N pieces of chocolate in the boxes under the conditions below.
- A box can contain at most one piece of chocolate.
- A_i \leq C_j and B_i \leq D_j must hold when putting the i-th piece of chocolate in the j-th box (they cannot be rotated).
Constraints
- 1 \leq N \leq M \leq 2\times 10^5
- 1 \leq A_i,B_i,C_i,D_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 \ldots A_N B_1 \ldots B_N C_1 \ldots C_M D_1 \ldots D_M
Output
If it is possible to put the N pieces of chocolate in the boxes, print Yes; otherwise, print No.
Sample Input 1
2 3 2 4 3 2 8 1 5 2 10 5
Sample Output 1
Yes
We can put the first piece of chocolate in the third box and the second piece in the first box.
Sample Input 2
2 2 1 1 2 2 100 1 100 1
Sample Output 2
No
A box can contain at most one piece of chocolate.
Sample Input 3
1 1 10 100 100 10
Sample Output 3
No
Sample Input 4
1 1 10 100 10 100
Sample Output 4
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
長さ N の整数列 A が与えられます。
t = 1, 2, \dots ,N について、 A_t が A の最長増加部分列に含まれることがあるか判定してください。
A_t が A の最長増加部分列に含まれることがあるとは、以下のことをいいます。
-
最長増加部分列の長さを L とする。各要素が 1 以上 N 以下の単調増加な整数列 i = (i_1, i_2, \dots ,i_L) \ (i_1 < i_2 < \dots < i_L) であって以下をすべて満たすものが存在する。
- A_{i_1} < A_{i_2} < \dots < A_{i_L}
- ある k \ (1 \leq k \leq L) が存在して i_k = t である
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
最長増加部分列とは?
列 A の部分列とは A の要素をいくつか抜き出して元の順に並べてできる列を指します。
列 A の最長増加部分列とは、 A の狭義単調増加な部分列のうち列の長さが最大のものを指します。
制約
- 1 \leq T \leq 2 \times 10^5
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 全てのテストケースにおける N の総和は 2 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
ここで \mathrm{case_i} は i 番目のケースの入力を意味する。各ケースは以下の形式で与えられる。
N A_1 A_2 \cdots A_N
出力
以下の形式で出力せよ。
\mathrm{answer}_1
\mathrm{answer}_2
\vdots
\mathrm{answer}_T
ここで \mathrm{answer}_i は i 番目のケースの出力を意味する。各ケースについては、次の通りである。
A_t が A の最長増加部分列に含まれることがある t が m 個存在し、昇順に i_1, i_2, \dots ,i_m であったとする。このとき、以下の形式で出力せよ。
m i_1 i_2 \cdots i_m
入力例 1
1 5 2 1 4 5 3
出力例 1
4 1 2 3 4
最長増加部分列の 1 つは (2, 4, 5) で、長さは 3 です。(1, 4, 5) も最長増加部分列の 1 つです。しかし、 A_5 を含む最長増加部分列はありません。
よって、 1, 2, 3, 4 を出力します。
入力例 2
2 6 2 5 3 4 3 4 5 10000 1000 100 1 10
出力例 2
5 1 3 4 5 6 2 4 5
Score : 525 points
Problem Statement
You are given an integer sequence A of length N.
For each t = 1, 2, \dots, N, determine whether A_t is included in a longest increasing subsequence of A.
Here, A_t is included in a longest increasing subsequence of A if and only if the following holds:
-
Let L be the length of a longest increasing subsequence of A. There exists a strictly increasing integer sequence i = (i_1, i_2, \dots, i_L) \ (i_1 < i_2 < \dots < i_L), where each element is between 1 and N, inclusive, that satisfies all of the following conditions:
- A_{i_1} < A_{i_2} < \dots < A_{i_L}.
- i_k = t for some k \ (1 \leq k \leq L).
You are given T test cases; solve each of them.
What is a longest increasing subsequence?
A subsequence of a sequence A is a sequence that can be derived by extracting some elements from A without changing the order.
A longest increasing subsequence of a sequence A is a subsequence of A that is strictly increasing with the greatest possible length.
Constraints
- 1 \leq T \leq 2 \times 10^5
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- The sum of N across all test cases is at most 2 \times 10^5.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Here, \mathrm{case_i} represents the input for the i-th case. Each case is given in the following format:
N A_1 A_2 \cdots A_N
Output
Print the answers in the following format:
\mathrm{answer}_1
\mathrm{answer}_2
\vdots
\mathrm{answer}_T
Here, \mathrm{answer}_i represents the output for the i-th case. For each case, let there be m indices t such that A_t is included in a longest increasing subsequence of A, which are i_1, i_2, \dots, i_m in ascending order. Print these in the following format:
m i_1 i_2 \cdots i_m
Sample Input 1
1 5 2 1 4 5 3
Sample Output 1
4 1 2 3 4
One of the longest increasing subsequences is (2, 4, 5), with a length of 3. Another longest increasing subsequence is (1, 4, 5). However, no longest increasing subsequence includes A_5.
Therefore, print 1, 2, 3, 4.
Sample Input 2
2 6 2 5 3 4 3 4 5 10000 1000 100 1 10
Sample Output 2
5 1 3 4 5 6 2 4 5