Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
ある長さ 6 の英小文字からなる文字列がcoffeeに似ているとは、3 文字目と 4 文字目が等しく、5 文字目と 6 文字目も等しいことを言います。
与えられる文字列 S がcoffeeに似ているか判定してください。
制約
- S は長さ 6 の英小文字からなる文字列である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S がcoffeeに似ている場合 Yes
を、そうでない場合 No
を出力せよ。
入力例 1
sippuu
出力例 1
Yes
sippuu
は 3 文字目と 4 文字目が等しく、5 文字目と 6 文字目も等しいです。
入力例 2
iphone
出力例 2
No
入力例 3
coffee
出力例 3
Yes
Score : 100 points
Problem Statement
A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like.
Constraints
- S is a string of length 6 consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
If S is coffee-like, print Yes
; otherwise, print No
.
Sample Input 1
sippuu
Sample Output 1
Yes
In sippuu
, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.
Sample Input 2
iphone
Sample Output 2
No
Sample Input 3
coffee
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
高橋君は金色の硬貨が好きです。自分が持っている 500 円硬貨 1 枚につき 1000、5 円硬貨 1 枚につき 5 の 嬉しさ を得ます。
高橋君は X 円を持っています。これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか?
(なお、利用できる硬貨は 500 円玉、100 円玉、50 円玉、10 円玉、5 円玉、1 円玉の 6 種類とします。)
制約
- 0 \leq X \leq 10^9
- X は整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
嬉しさの最大値を出力せよ。
入力例 1
1024
出力例 1
2020
500 円硬貨 2 枚、5 円硬貨 4 枚を含むように両替することで 2020 の嬉しさを得ます。これが嬉しさの最大です。
入力例 2
0
出力例 2
0
高橋君は一文無しです。
入力例 3
1000000000
出力例 3
2000000000
高橋君は大富豪です。
Score : 200 points
Problem Statement
Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)
Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?
(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)
Constraints
- 0 \leq X \leq 10^9
- X is an integer.
Input
Input is given from Standard Input in the following format:
X
Output
Print the maximum number of happiness points that can be earned.
Sample Input 1
1024
Sample Output 1
2020
By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.
Sample Input 2
0
Sample Output 2
0
He is penniless - or yenless.
Sample Input 3
1000000000
Sample Output 3
2000000000
He is a billionaire - in yen.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
1 周 K メートルの円形の湖があり、その周りに N 軒の家があります。
i 番目の家は、湖の北端から時計回りに A_i メートルの位置にあります。
家の間の移動は、湖の周りに沿ってのみ行えます。
いずれかの家から出発して N 軒すべての家を訪ねるための最短移動距離を求めてください。
制約
- 2 \leq K \leq 10^6
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_1 < ... < A_N < K
- 入力中のすべての値は整数である。
入力
入力は以下の形式で標準入力から与えられる。
K N A_1 A_2 ... A_N
出力
いずれかの家から出発して N 軒すべての家を訪ねるための最短移動距離を出力せよ。
入力例 1
20 3 5 10 15
出力例 1
10
1 番目の家から出発し、2 番目、3 番目の家へ順に移動すると移動距離が 10 になります。
入力例 2
20 3 0 5 15
出力例 2
10
2 番目の家から出発し、1 番目、3 番目の家へ順に移動すると移動距離が 10 になります。
Score : 300 points
Problem Statement
There is a circular pond with a perimeter of K meters, and N houses around them.
The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.
When traveling between these houses, you can only go around the pond.
Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
Constraints
- 2 \leq K \leq 10^6
- 2 \leq N \leq 2 \times 10^5
- 0 \leq A_1 < ... < A_N < K
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
K N A_1 A_2 ... A_N
Output
Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
Sample Input 1
20 3 5 10 15
Sample Output 1
10
If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.
Sample Input 2
20 3 0 5 15
Sample Output 2
10
If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
1 から N までの番号がつけられた N 個の頂点を持つ無向グラフ G があります。 G には、以下のように合計 N 本の辺があります。
- i=1,2,...,N-1 について、頂点 i と頂点 i+1 の間に辺があります
- 頂点 X と頂点 Y の間に辺があります
k=1,2,...,N-1 について、以下の問題を解いてください。
- 整数の組 (i,j) (1 \leq i < j \leq N) であって、 G において頂点 i と頂点 j の最短距離が k であるようなものの数を求めてください
制約
- 3 \leq N \leq 2 \times 10^3
- 1 \leq X,Y \leq N
- X+1 < Y
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X Y
出力
k=1,2,...,N-1 に対する問題の答えを、順番に一行に出力せよ。
入力例 1
5 2 4
出力例 1
5 4 1 0
この入力中のグラフは以下のようなものです。
頂点 i と 頂点 j の距離が 1 になるような整数の組 (i,j) (1 \leq i < j \leq N) は、
(1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5) の 5 つです。
頂点 i と 頂点 j の距離が 2 になるような整数の組 (i,j) (1 \leq i < j \leq N) は、
(1,3)\,,(1,4)\,,(2,5)\,,(3,5) の 4 つです。
頂点 i と 頂点 j の距離が 3 になるような整数の組 (i,j) (1 \leq i < j \leq N) は、
(1,5) の 1 つだけです。
頂点 i と 頂点 j の距離が 4 になるような整数の組 (i,j) (1 \leq i < j \leq N) はありません。
入力例 2
3 1 3
出力例 2
3 0
この入力中のグラフは以下のようなものです。
入力例 3
7 3 7
出力例 3
7 8 4 2 0 0
入力例 4
10 4 8
出力例 4
10 12 10 8 4 1 0 0 0
Score : 400 points
Problem Statement
We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:
- For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.
- There is an edge between Vertex X and Vertex Y.
For each k=1,2,...,N-1, solve the problem below:
- Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.
Constraints
- 3 \leq N \leq 2 \times 10^3
- 1 \leq X,Y \leq N
- X+1 < Y
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y
Output
For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.
Sample Input 1
5 2 4
Sample Output 1
5 4 1 0
The graph in this input is as follows:
There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).
There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).
There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).
There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.
Sample Input 2
3 1 3
Sample Output 2
3 0
The graph in this input is as follows:
Sample Input 3
7 3 7
Sample Output 3
7 8 4 2 0 0
Sample Input 4
10 4 8
Sample Output 4
10 12 10 8 4 1 0 0 0
Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 500 点
問題文
あなたは、X 個の赤色のリンゴと Y 個の緑色のリンゴを食べようとしています。
あなたは A 個の赤色のリンゴを持っており、美味しさはそれぞれ p_1,p_2, \dots ,p_A です。
あなたは B 個の緑色のリンゴを持っており、美味しさはそれぞれ q_1,q_2, \dots ,q_B です。
あなたは C 個の無色のリンゴを持っており、美味しさはそれぞれ r_1,r_2, \dots ,r_C です。
無色のリンゴは食べる前に着色することで、赤色のリンゴもしくは緑色のリンゴと見なすことができます。
以上のリンゴの中から、できるだけ美味しさの総和が大きくなるように食べるリンゴを選びます。
0 個以上の無色のリンゴに適切に着色したとき、食べる X+Y 個のリンゴの美味しさの総和が最大でいくつになるか求めてください。
制約
- 1 \leq X \leq A \leq 10^5
- 1 \leq Y \leq B \leq 10^5
- 1 \leq C \leq 10^5
- 1 \leq p_i \leq 10^9
- 1 \leq q_i \leq 10^9
- 1 \leq r_i \leq 10^9
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
X Y A B C p_1 p_2 ... p_A q_1 q_2 ... q_B r_1 r_2 ... r_C
出力
リンゴの美味しさの総和の最大値を出力せよ。
入力例 1
1 2 2 2 1 2 4 5 1 3
出力例 1
12
以下のようにすることで、食べるリンゴの美味しさの総和を最大にすることができます。
- 2 番目の赤色のリンゴを食べる。
- 1 番目の緑色のリンゴを食べる。
- 1 番目の無色のリンゴを緑色に着色し、食べる。
入力例 2
2 2 2 2 2 8 6 9 1 2 1
出力例 2
25
入力例 3
2 2 4 4 4 11 12 13 14 21 22 23 24 1 2 3 4
出力例 3
74
Score : 500 points
Problem Statement
You are going to eat X red apples and Y green apples.
You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.
Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.
From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.
Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.
Constraints
- 1 \leq X \leq A \leq 10^5
- 1 \leq Y \leq B \leq 10^5
- 1 \leq C \leq 10^5
- 1 \leq p_i \leq 10^9
- 1 \leq q_i \leq 10^9
- 1 \leq r_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y A B C p_1 p_2 ... p_A q_1 q_2 ... q_B r_1 r_2 ... r_C
Output
Print the maximum possible sum of the deliciousness of the eaten apples.
Sample Input 1
1 2 2 2 1 2 4 5 1 3
Sample Output 1
12
The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:
- Eat the 2-nd red apple.
- Eat the 1-st green apple.
- Paint the 1-st colorless apple green and eat it.
Sample Input 2
2 2 2 2 2 8 6 9 1 2 1
Sample Output 2
25
Sample Input 3
2 2 4 4 4 11 12 13 14 21 22 23 24 1 2 3 4
Sample Output 3
74
Time Limit: 3 sec / Memory Limit: 1024 MB
配点 : 600 点
問題文
1 から N までの番号が付けられた N 個の頂点を持つ木があります。この木の i 番目の辺は頂点 a_i と頂点 b_i を結んでいます。
k=1,...,N に対して、以下の問題を解いてください。
- 以下の手順に従って,木の各頂点に整数を書くことを考える。
- まず、頂点 k に 1 を書く。
- 2,...,N を順番に頂点に書く。書き込む頂点は、次のように決める。
- まだ整数が書かれていない頂点であって、整数が書かれた頂点に隣接しているものを選ぶ。このような頂点が複数存在する場合は、その中からランダムに選ぶ。
- 整数の書き方として考えられるものの数を 10^9+7 で割ったあまりを求めよ。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq a_i,b_i \leq N
- 与えられるグラフは木である
入力
入力は以下の形式で標準入力から与えられる。
N a_1 b_1 : a_{N-1} b_{N-1}
出力
k=1,2,...,N に対する問題の答えを、順番に一行に出力せよ。
入力例 1
3 1 2 1 3
出力例 1
2 1 1
この入力中のグラフは以下のようなものです。
k=1 に対する問題において、以下のように 2 通りの整数の書き方が考えられます。
- 頂点 1,2,3 に、それぞれ 1,2,3 を書く
- 頂点 1,2,3 に、それぞれ 1,3,2 を書く
入力例 2
2 1 2
出力例 2
1 1
この入力中のグラフは以下のようなものです。
入力例 3
5 1 2 2 3 3 4 3 5
出力例 3
2 8 12 3 3
この入力中のグラフは以下のようなものです。
入力例 4
8 1 2 2 3 3 4 3 5 3 6 6 7 6 8
出力例 4
40 280 840 120 120 504 72 72
この入力中のグラフは以下のようなものです。
Score : 600 points
Problem Statement
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below:
- Consider writing a number on each vertex in the tree in the following manner:
- First, write 1 on Vertex k.
- Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:
- Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.
- Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq a_i,b_i \leq N
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
N a_1 b_1 : a_{N-1} b_{N-1}
Output
For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.
Sample Input 1
3 1 2 1 3
Sample Output 1
2 1 1
The graph in this input is as follows:
For k=1, there are two ways in which we can write the numbers on the vertices, as follows:
- Writing 1, 2, 3 on Vertex 1, 2, 3, respectively
- Writing 1, 3, 2 on Vertex 1, 2, 3, respectively
Sample Input 2
2 1 2
Sample Output 2
1 1
The graph in this input is as follows:
Sample Input 3
5 1 2 2 3 3 4 3 5
Sample Output 3
2 8 12 3 3
The graph in this input is as follows:
Sample Input 4
8 1 2 2 3 3 4 3 5 3 6 6 7 6 8
Sample Output 4
40 280 840 120 120 504 72 72
The graph in this input is as follows: