Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君の住む AtCoder 国には「飴を A 個以上所持している人はクッキーを B 個以上所持していなければならない」という奇妙な法律があります。
高橋君は飴を C 個、クッキーを D 個所持しています。高橋君がこの法律に違反しているかどうか判定してください。
制約
- 1\leq A,B,C,D \leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
高橋君が法律に違反しているとき Yes、違反していないとき No と出力せよ。
入力例 1
10 20 30 40
出力例 1
No
AtCoder国には「飴を 10 個以上所持している人はクッキーを 20 個以上所持していなければならない」という法律があります。
高橋君は飴を 30 個、クッキーを 40 個所持しているため、この法律に違反していません。
入力例 2
10 20 30 4
出力例 2
Yes
入力例 3
100 100 1 1
出力例 3
No
Score : 100 points
Problem Statement
In AtCoder Country where Takahashi lives, there is a strange law that "a person who possesses A or more candies must possess B or more cookies."
Takahashi possesses C candies and D cookies. Determine whether Takahashi is violating this law.
Constraints
- 1\leq A,B,C,D \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B C D
Output
Print Yes if Takahashi is violating the law, and No otherwise.
Sample Input 1
10 20 30 40
Sample Output 1
No
In AtCoder Country, there is a law that "a person who possesses 10 or more candies must possess 20 or more cookies."
Takahashi possesses 30 candies and 40 cookies, so he is not violating this law.
Sample Input 2
10 20 30 4
Sample Output 2
Yes
Sample Input 3
100 100 1 1
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字からなる N 文字の文字列 S が与えられます。
S の先頭から A 文字、末尾から B 文字取り除いた N-A-B 文字の文字列を出力してください。
制約
- 1\le N\le20
- 0\le A
- 0\le B
- A+B\lt N
- S は英小文字からなる N 文字の文字列
- N,A,B はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A B S
出力
S の先頭から A 文字、末尾から B 文字取り除いた文字列を出力せよ。
入力例 1
7 1 3 atcoder
出力例 1
tco
atcoder の先頭から 1 文字、末尾から 3 文字取り除くと tco になります。
入力例 2
1 0 0 a
出力例 2
a
出力すべき文字列が S と等しい場合もあります。
入力例 3
20 4 8 abcdefghijklmnopqrst
出力例 3
efghijkl
Score : 100 points
Problem Statement
You are given an N-character string S consisting of lowercase English letters.
Output the string of N-A-B characters obtained by removing the first A characters and the last B characters from S.
Constraints
- 1\le N\le20
- 0\le A
- 0\le B
- A+B\lt N
- S is a string of N characters consisting of lowercase English letters.
- N, A, and B are all integers.
Input
The input is given from Standard Input in the following format:
N A B S
Output
Output the string obtained by removing the first A characters and the last B characters from S.
Sample Input 1
7 1 3 atcoder
Sample Output 1
tco
Removing the first one character and the last three characters from atcoder gives tco.
Sample Input 2
1 0 0 a
Sample Output 2
a
The string to be output may be equal to S.
Sample Input 3
20 4 8 abcdefghijklmnopqrst
Sample Output 3
efghijkl
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder 市では、N 種類のゴミを定期的に収集しています。i\;(=1,2,\dots,N) 種類目のゴミは、日付を q_i で割ったあまりが r_i の日に収集されます。
Q 個の質問に答えてください。j\;(=1,2,\dots,Q) 番目の質問では、d_j 日に t_j 種類目のゴミが出たときに、次にそれが収集される日を答えてください。
ただし、i 種類目のゴミが出た日が、 i 種類目のゴミが回収される日であった場合、そのゴミは同じ日に収集されるとします。
制約
- 1 \leq N \leq 100
- 0 \leq r_i < q_i \leq 10^9
- 1 \leq Q \leq 100
- 1 \leq t_j \leq N
- 1 \leq d_j \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N q_1 r_1 q_2 r_2 \vdots q_N r_N Q t_1 d_1 t_2 d_2 \vdots t_Q d_Q
出力
Q 行出力せよ。j\;(1\leq j \leq Q) 行目には、j 番目の質問に対する答えを出力せよ。
入力例 1
2 7 3 4 2 5 1 1 1 3 1 4 1 15 2 7
出力例 1
3 3 10 17 10
- 1 番目の質問:1 種類目のゴミが 1 日以降に初めて回収されるのは 3 日です。
- 2 番目の質問:1 種類目のゴミが 3 日以降に初めて回収されるのは 3 日です。
- 3 番目の質問:1 種類目のゴミが 4 日以降に初めて回収されるのは 10 日です。
Score : 200 points
Problem Statement
In AtCoder City, N types of garbage are collected regularly. The i-th type of garbage (i=1,2,\dots,N) is collected on days when the date modulo q_i equals r_i.
Answer Q queries. In the j-th query (j=1,2,\dots,Q), given that the t_j-th type of garbage is put out on day d_j, answer the next day on which it will be collected.
Here, if the i-th type of garbage is put out on a day when that type of garbage is collected, then the garbage will be collected on the same day.
Constraints
- 1 \leq N \leq 100
- 0 \leq r_i < q_i \leq 10^9
- 1 \leq Q \leq 100
- 1 \leq t_j \leq N
- 1 \leq d_j \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N q_1 r_1 q_2 r_2 \vdots q_N r_N Q t_1 d_1 t_2 d_2 \vdots t_Q d_Q
Output
Print Q lines. The j-th line (1\leq j \leq Q) should contain the answer to the j-th query.
Sample Input 1
2 7 3 4 2 5 1 1 1 3 1 4 1 15 2 7
Sample Output 1
3 3 10 17 10
- 1st query: The 1st type of garbage is collected on day 3 for the first time after day 1.
- 2nd query: The 1st type of garbage is collected on day 3 for the first time after day 3.
- 3rd query: The 1st type of garbage is collected on day 10 for the first time after day 4.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
xy 平面を考えます。x 軸の正の向きを東向き、y 軸の正の向きを北向きとします。
高橋君ははじめ、点 (x, y) = (0, 0) にいて東( x 軸の正の向き)を向いています。
S と R のみからなる長さ N の文字列 T = t_1t_2\ldots t_N が与えられます。
高橋君は i = 1, 2, \ldots, N の順番で下記を行います。
- t_i =
Sならば、高橋君はいま向いている方向に距離 1 だけ進む。 - t_i =
Rならば、高橋君はその場で右に 90 度回転する。その結果、高橋君の向いている方向が下記の通りに変わる。- 回転前の向きが東向き( x 軸の正の向き)ならば、回転後の向きは南向き( y 軸の負の向き)になる。
- 回転前の向きが南向き( y 軸の負の向き)ならば、回転後の向きは西向き( x 軸の負の向き)になる。
- 回転前の向きが西向き( x 軸の負の向き)ならば、回転後の向きは北向き( y 軸の正の向き)になる。
- 回転前の向きが北向き( y 軸の正の向き)ならば、回転後の向きは東向き( x 軸の正の向き)になる。
上記の手順を終えた後に高橋君がいる点の座標を出力してください。
制約
- 1 \leq N \leq 10^5
- N は整数
- T は
SとRのみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N T
出力
問題文中の手順を終えた後に高橋君がいる点の座標 (x, y) を、下記の形式にしたがって空白区切りで出力せよ。
x y
入力例 1
4 SSRS
出力例 1
2 -1
高橋君ははじめ (0, 0) にいて東を向いています。その後、高橋君は下記の通りに行動します。
- t_1 =
Sであるので、高橋君は東に距離 1 だけ進んだ (1, 0) に移動します。 - t_2 =
Sであるので、高橋君は東に距離 1 だけ進んだ (2, 0) に移動します。 - t_3 =
Rであるので、高橋君は右に 90 度回転し、高橋君は南を向きます。 - t_4 =
Sであるので、高橋君は南に距離 1 だけ進んだ (2, -1) に移動します。
よって、高橋君の最終的な位置である (x, y) = (2, -1) を出力します。
入力例 2
20 SRSRSSRSSSRSRRRRRSRR
出力例 2
0 1
Score : 200 points
Problem Statement
Consider an xy-plane. The positive direction of the x-axis is in the direction of east, and the positive direction of the y-axis is in the direction of north.
Takahashi is initially at point (x, y) = (0, 0) and facing east (in the positive direction of the x-axis).
You are given a string T = t_1t_2\ldots t_N of length N consisting of S and R.
Takahashi will do the following move for each i = 1, 2, \ldots, N in this order.
- If t_i =
S, Takahashi advances in the current direction by distance 1. - If t_i =
R, Takahashi turns 90 degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.- If he is facing east (in the positive direction of the x-axis) before he turns, he will face south (in the negative direction of the y-axis) after he turns.
- If he is facing south (in the negative direction of the y-axis) before he turns, he will face west (in the negative direction of the x-axis) after he turns.
- If he is facing west (in the negative direction of the x-axis) before he turns, he will face north (in the positive direction of the y-axis) after he turns.
- If he is facing north (in the positive direction of the y-axis) before he turns, he will face east (in the positive direction of the x-axis) after he turns.
Print the coordinates Takahashi is at after all the steps above have been done.
Constraints
- 1 \leq N \leq 10^5
- N is an integer.
- T is a string of length N consisting of
SandR.
Input
Input is given from Standard Input in the following format:
N T
Output
Print the coordinates (x, y) Takahashi is at after all the steps described in the Problem Statement have been completed, in the following format, with a space in between:
x y
Sample Input 1
4 SSRS
Sample Output 1
2 -1
Takahashi is initially at (0, 0) facing east. Then, he moves as follows.
- t_1 =
S, so he advances in the direction of east by distance 1, arriving at (1, 0). - t_2 =
S, so he advances in the direction of east by distance 1, arriving at (2, 0). - t_3 =
R, so he turns 90 degrees clockwise, resulting in facing south. - t_4 =
S, so he advances in the direction of south by distance 1, arriving at (2, -1).
Thus, Takahashi's final position, (x, y) = (2, -1), should be printed.
Sample Input 2
20 SRSRSSRSSSRSRRRRRSRR
Sample Output 2
0 1
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