実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君は、ある web サイトに設定するパスワードを、英小文字のみからなる文字列 P にしようと考えています。
一方で、その web サイトのパスワードは長さ L 以上の文字列である必要があります。
P が長さの条件をみたすか、すなわち長さ L 以上の文字列であるか判定してください。
制約
- P は英小文字のみからなる長さ 1 以上 100 以下の文字列
- 1 \leq L \leq 100
- L は整数
入力
入力は以下の形式で標準入力から与えられる。
P L
出力
P が長さの条件をみたすならば Yes を、そうでないならば No を出力せよ。
入力例 1
chokudai 5
出力例 1
Yes
chokudai の長さは 8 であり、特に 5 以上であるため長さの条件をみたしています。
よって、Yes を出力します。
入力例 2
ac 3
出力例 2
No
ac の長さは 2 であり、特に 3 未満であるため長さの条件をみたしていません。
よって、No を出力します。
入力例 3
atcoder 7
出力例 3
Yes
atcoder の長さは 7 であり、特に 7 以上であるため長さの条件をみたしています。
よって、Yes を出力します。
Score : 100 points
Problem Statement
Takahashi wants to set his password for a certain website to a string P consisting of lowercase English letters.
The password for that website must be a string of length at least L.
Determine whether P satisfies the length condition, that is, whether it is a string of length at least L.
Constraints
- P is a string consisting of lowercase English letters with length between 1 and 100, inclusive.
- 1 \leq L \leq 100
- L is an integer.
Input
The input is given from Standard Input in the following format:
P L
Output
If P satisfies the length condition, print Yes; otherwise, print No.
Sample Input 1
chokudai 5
Sample Output 1
Yes
The length of chokudai is 8, which is at least 5, so it satisfies the length condition.
Thus, print Yes.
Sample Input 2
ac 3
Sample Output 2
No
The length of ac is 2, which is less than 3, so it does not satisfy the length condition.
Thus, print No.
Sample Input 3
atcoder 7
Sample Output 3
Yes
The length of atcoder is 7, which is at least 7, so it satisfies the length condition.
Thus, print Yes.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君はティーポットです。
高橋君はティーポットなので、紅茶なら喜んで受け入れますが、それ以外の液体を入れようとすると拒否してしまいます。
高橋君に S という名前の液体を入れることが出来るか判定してください。
英小文字からなる長さ N の文字列 S が与えられます。
S が tea で終わる文字列であるかどうかを判定してください。
制約
- 1 \leq N \leq 20
- N は整数
- S は英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S が tea で終わる文字列であれば Yes を、そうでなければ No を出力せよ。
入力例 1
8 greentea
出力例 1
Yes
greentea は tea で終わる文字列です。
入力例 2
6 coffee
出力例 2
No
coffee は tea で終わる文字列ではありません。
入力例 3
3 tea
出力例 3
Yes
入力例 4
1 t
出力例 4
No
Score : 100 points
Problem Statement
Takahashi is a teapot.
Since he is a teapot, he will gladly accept tea, but will refuse any other liquid.
Determine whether you can pour a liquid named S into him.
You are given a string S of length N consisting of lowercase English letters.
Determine whether S is a string that ends with tea.
Constraints
- 1 \leq N \leq 20
- N is an integer.
- S is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S
Output
If S is a string that ends with tea, print Yes; otherwise, print No.
Sample Input 1
8 greentea
Sample Output 1
Yes
greentea is a string that ends with tea.
Sample Input 2
6 coffee
Sample Output 2
No
coffee is not a string that ends with tea.
Sample Input 3
3 tea
Sample Output 3
Yes
Sample Input 4
1 t
Sample Output 4
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
健康に気を使っている高橋君は、M 種類の栄養素について、食事によって十分な量を摂取できているか気になりました。
i 番目の栄養素は 1 日あたり A_i 以上摂取することが目標です。
高橋君は今日 N 品の食品を食べ、i 品目の食品からは栄養素 j を X_{i,j} 摂取しました。
M 種類全ての栄養素で目標を達成しているかどうかを判定してください。
制約
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i,X_{i,j} \leq 10^7
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
出力
M 種類全ての栄養素で目標を達成しているなら Yes、そうでないならば No を出力せよ。
入力例 1
2 3 10 20 30 20 0 10 0 100 100
出力例 1
Yes
栄養素 1 は 1 品目から 20、2 品目から 0 摂取したため、合わせて 20 摂取しており、10 以上摂取するという目標を達成しています。
栄養素 2,3 についても同様に目標を達成しています。
入力例 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
出力例 2
No
栄養素 4 について目標を達成していません。
Score : 150 points
Problem Statement
Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet.
For the i-th nutrient, his goal is to take at least A_i units per day.
Today, he ate N foods, and from the i-th food, he took X_{i,j} units of nutrient j.
Determine whether he has met the goal for all M types of nutrients.
Constraints
- 1 \leq N \leq 100
- 1 \leq M \leq 100
- 0 \leq A_i, X_{i,j} \leq 10^7
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
A_1 \ldots A_M
X_{1,1} \ldots X_{1,M}
\vdots
X_{N,1} \ldots X_{N,M}
Output
Print Yes if the goal is met for all M types of nutrients, and No otherwise.
Sample Input 1
2 3 10 20 30 20 0 10 0 100 100
Sample Output 1
Yes
For nutrient 1, Takahashi took 20 units from the 1-st food and 0 units from the 2-nd food, totaling 20 units, thus meeting the goal of taking at least 10 units.
Similarly, he meets the goal for nutrients 2 and 3.
Sample Input 2
2 4 10 20 30 40 20 0 10 30 0 100 100 0
Sample Output 2
No
The goal is not met for nutrient 4.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
正整数 X が与えられます。
X を(先頭に 0 を含まない形で)十進表記した際に現れる数字を、先頭に 0 が来ないように 並び替えることで得られる正整数のうち、値が最小のものを求めてください。
制約
- 1\leq X < 10^5
- X は整数
入力
入力は以下の形式で標準入力から与えられる。
X
出力
答えを出力せよ。
入力例 1
903
出力例 1
309
X を十進表記した際に現れる数字を先頭に 0 が来ないように並び替えることで得られる正整数は、903, 930, 309, 390 の 4 通りであり、このうち値が最小のものは 309 です。
入力例 2
432
出力例 2
234
入力例 3
100
出力例 3
100
Score : 200 points
Problem Statement
You are given a positive integer X.
Find the minimum value among all positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X (without leading zeros) such that there is no leading zero.
Constraints
- 1\leq X < 10^5
- X is an integer.
Input
The input is given from Standard Input in the following format:
X
Output
Output the answer.
Sample Input 1
903
Sample Output 1
309
There are four positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X such that there is no leading zero: 903, 930, 309, 390; the minimum value among them is 309.
Sample Input 2
432
Sample Output 2
234
Sample Input 3
100
Sample Output 3
100
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
文字列 S の各文字を並べ替えて作ることが可能な文字列を辞書順にすべて列挙したとき、前から K 番目にくる文字列を求めてください。
「各文字を並べ替えて作ることが可能な文字列」とは?
「文字列 A が文字列 B の各文字を並べ替えて作ることが可能な文字列である」とは、任意の文字が文字列 A と文字列 B に同数含まれるということを指します。制約
- 1 \le |S| \le 8
- S は英小文字のみからなる
- S の各文字を並べ替えてできる文字列は K 種類以上存在する
入力
入力は以下の形式で標準入力から与えられる。
S K
出力
答えを出力せよ。
入力例 1
aab 2
出力例 1
aba
文字列 aab の各文字を並べ替えて作ることが可能な文字列は \{ aab, aba, baa \} の 3 つですが、このうち辞書順で前から 2 番目にくるものは aba です。
入力例 2
baba 4
出力例 2
baab
入力例 3
ydxwacbz 40320
出力例 3
zyxwdcba
Score : 300 points
Problem Statement
Find the K-th lexicographically smallest string among the strings that are permutations of a string S.
What is a permutation of a string?
A string A is said to be a permutation of a string B when any character occurs the same number of times in A and B.Constraints
- 1 \le |S| \le 8
- S consists of lowercase English letters.
- There are at least K distinct strings that are permutations of S.
Input
Input is given from Standard Input in the following format:
S K
Output
Print the answer.
Sample Input 1
aab 2
Sample Output 1
aba
There are three permutations of a string aab: \{ aab, aba, baa \}. The 2-nd lexicographically smallest of them is aba.
Sample Input 2
baba 4
Sample Output 2
baab
Sample Input 3
ydxwacbz 40320
Sample Output 3
zyxwdcba
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
2 次元座標平面があります。x 軸正方向を右向き、y 軸正方向を上向きとします。
この平面上に自己交差のない四角形があります。
4 つの頂点の座標は反時計回りに (A_x,A_y),(B_x,B_y),(C_x,C_y),(D_x,D_y) です。
この四角形が凸であるか判定してください。
なお、四角形の 4 つの内角が全て 180 度未満であるとき、かつ、その時に限り、その四角形は凸であるといいます。
制約
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- 入力に含まれる値は全て整数である
- 与えられる 4 点は四角形の 4 頂点を反時計回りに並べたものである
- 与えられる 4 点のなす四角形は自己交差がなく退化していない。すなわち
- どの 2 頂点も同じ座標にない
- どの 3 頂点も同一直線上にない
- 隣接しない 2 辺は共有点を持たない
入力
入力は以下の形式で標準入力から与えられる。
A_x A_y B_x B_y C_x C_y D_x D_y
出力
与えられる四角形が凸なら Yes、凸でないなら No を出力せよ。
入力例 1
0 0 1 0 1 1 0 1
出力例 1
Yes
与えられた四角形は正方形であり、4 つの内角は全て 90 度です。したがって、この四角形は凸です。

入力例 2
0 0 1 1 -1 0 1 -1
出力例 2
No
角 A が 270 度です。したがって、この四角形は凸ではありません。

Score : 300 points
Problem Statement
Consider a two-dimensional coordinate plane, where the x-axis is oriented to the right, and the y-axis is oriented upward.
In this plane, there is a quadrilateral without self-intersection.
The coordinates of the four vertices are (A_x,A_y), (B_x,B_y), (C_x,C_y), and (D_x,D_y), in counter-clockwise order.
Determine whether this quadrilateral is convex.
Here, a quadrilateral is convex if and only if all four interior angles are less than 180 degrees.
Constraints
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- All values in input are integers.
- The given four points are the four vertices of a quadrilateral in counter-clockwise order.
- The quadrilateral formed by the given four points has no self-intersection and is non-degenerate. That is,
- no two vertices are at the same coordinates;
- no three vertices are colinear; and
- no two edges that are not adjacent have a common point.
Input
Input is given from Standard Input in the following format:
A_x A_y B_x B_y C_x C_y D_x D_y
Output
If the given quadrilateral is convex, print Yes; otherwise, print No.
Sample Input 1
0 0 1 0 1 1 0 1
Sample Output 1
Yes
The given quadrilateral is a square, whose four interior angles are all 90 degrees. Thus, this quadrilateral is convex.

Sample Input 2
0 0 1 1 -1 0 1 -1
Sample Output 2
No
The angle A is 270 degrees. Thus, this quadrilateral is not convex.

実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
H \times W 枚のクッキーが H 行 W 列に並んでいます。
上から i 行目・左から j 列目のクッキーの色は英小文字 c_{i,j} で表されます。
これから、以下の手続きを行います。
1. 各行に対して次の操作を行う : その行に 2 枚以上のクッキーが残っており、それらの色がすべて同じならば、それらに印をつける。
2. 各列に対して次の操作を行う : その列に 2 枚以上のクッキーが残っており、それらの色がすべて同じならば、それらに印をつける。
3. 印のついたクッキーがあればそれらをすべて取り除いて 1. に戻り、なければ手続きを終了する。
手続きを終了した時点で残っているクッキーの枚数を求めてください。
制約
- 2 \leq H, W \leq 2000
- c_{i,j} は英小文字である
入力
入力は以下の形式で標準入力から与えられる。
H W
c_{1,1}c_{1,2} \ldots c_{1,W}
c_{2,1}c_{2,2} \ldots c_{2,W}
\vdots
c_{H,1}c_{H,2} \ldots c_{H,W}
出力
答えを出力せよ。
入力例 1
4 3 aaa aaa abc abd
出力例 1
2
以下で示す順で手続きを行います。
- 1. により、1, 2 行目のクッキーに印をつける。
- 2. により、1 列目のクッキーに印をつける。
- 3. により、印を付けたクッキーを取り除く。
この時点でクッキーは以下のようになっています。ただし、クッキーを取り除いた箇所は . で表しています。
... ... .bc .bd
- 1. により、何もしない。
- 2. により、2 列目のクッキーに印をつける。
- 3. により、印を付けたクッキーを取り除く。
この時点でクッキーは以下のようになっています。ただし、クッキーを取り除いた箇所は . で表しています。
... ... ..c ..d
- 1. により、何もしない。
- 2. により、何もしない。
- 3. により、印がついているクッキーが存在しないので手続きを終了する。
最終的に残っているクッキーの枚数は 2 枚です。
入力例 2
2 5 aaaaa abcde
出力例 2
4
入力例 3
3 3 ooo ooo ooo
出力例 3
0
Score : 400 points
Problem Statement
There are H \times W cookies in H rows and W columns.
The color of the cookie at the i-row from the top and j-th column from the left is represented by a lowercase English letter c_{i,j}.
We will perform the following procedure.
1. For each row, perform the following operation: if there are two or more cookies remaining in the row and they all have the same color, mark them.
2. For each column, perform the following operation: if there are two or more cookies remaining in the column and they all have the same color, mark them.
3. If there are any marked cookies, remove them all and return to 1; otherwise, terminate the procedure.
Find the number of cookies remaining at the end of the procedure.
Constraints
- 2 \leq H, W \leq 2000
- c_{i,j} is a lowercase English letter.
Input
The input is given from Standard Input in the following format:
H W
c_{1,1}c_{1,2} \ldots c_{1,W}
c_{2,1}c_{2,2} \ldots c_{2,W}
\vdots
c_{H,1}c_{H,2} \ldots c_{H,W}
Output
Print the answer.
Sample Input 1
4 3 aaa aaa abc abd
Sample Output 1
2
The procedure is performed as follows.
- 1. Mark the cookies in the first and second rows.
- 2. Mark the cookies in the first column.
- 3. Remove the marked cookies.
At this point, the cookies look like the following, where . indicates a position where the cookie has been removed.
... ... .bc .bd
- 1. Do nothing.
- 2. Mark the cookies in the second column.
- 3. Remove the marked cookies.
At this point, the cookies look like the following, where . indicates a position where the cookie has been removed.
... ... ..c ..d
- 1. Do nothing.
- 2. Do nothing.
- 3. No cookies are marked, so terminate the procedure.
The final number of cookies remaining is 2.
Sample Input 2
2 5 aaaaa abcde
Sample Output 2
4
Sample Input 3
3 3 ooo ooo ooo
Sample Output 3
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A=(A_0,A_1,\ldots,A_{N-1}) が与えられます。
最初の時点では空の皿があり、高橋君は次の操作を K 回繰り返します。
- 皿の中のアメの個数を X とする。皿に A_{(X\bmod N)} 個のアメを追加する。 ただし、X\bmod N で X を N で割った余りを表す。
K 回の操作の後で、皿の中には何個のアメがあるか求めてください。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq K \leq 10^{12}
- 1 \leq A_i\leq 10^6
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N K
A_0 A_1 \ldots A_{N-1}
出力
答えを出力せよ。
入力例 1
5 3 2 1 6 3 1
出力例 1
11
皿の中のアメの個数は次のように変化します。
- 1 回目の操作において、X=0 であるので、アメは A_{(0\mod 5)}=A_0=2 個追加されます。
- 2 回目の操作において、X=2 であるので、アメは A_{(2\mod 5)}=A_2=6 個追加されます。
- 3 回目の操作において、X=8 であるので、アメは A_{(8\mod 5)}=A_3=3 個追加されます。
よって、3 回の操作の後で、皿には 11 個のアメがあります。出力する値は N で割った余りではない事に注意してください。
入力例 2
10 1000000000000 260522 914575 436426 979445 648772 690081 933447 190629 703497 47202
出力例 2
826617499998784056
答えは 32 bit 整数型に収まらない場合があります。
Score : 500 points
Problem Statement
You are given a sequence A=(A_0,A_1,\ldots,A_{N-1}) of length N.
There is an initially empty dish. Takahashi is going to repeat the following operation K times.
- Let X be the number of candies on the dish. He puts A_{(X\bmod N)} more candies on the dish. Here, X\bmod N denotes the remainder when X is divided by N.
Find how many candies are on the dish after the K operations.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq K \leq 10^{12}
- 1 \leq A_i\leq 10^6
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
A_0 A_1 \ldots A_{N-1}
Output
Print the answer.
Sample Input 1
5 3 2 1 6 3 1
Sample Output 1
11
The number of candies on the dish transitions as follows.
- In the 1-st operation, we have X=0, so A_{(0\mod 5)}=A_0=2 more candies will be put on the dish.
- In the 2-nd operation, we have X=2, so A_{(2\mod 5)}=A_2=6 more candies will be put on the dish.
- In the 3-rd operation, we have X=8, so A_{(8\mod 5)}=A_3=3 more candies will be put on the dish.
Thus, after the 3 operations, there will be 11 candies on the dish. Note that you must not print the remainder divided by N.
Sample Input 2
10 1000000000000 260522 914575 436426 979445 648772 690081 933447 190629 703497 47202
Sample Output 2
826617499998784056
The answer may not fit into a 32-bit integer type.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
縦 N 行横 N 列のグリッドがあります。上から i 行目、左から j 列目のマスをマス (i,j) と表します。
高橋君は最初マス (1,1) におり、所持金は 0 です。
高橋君はマス (i,j) にいるとき、1 回の行動で以下のいずれかを行うことができます。
- 同じマスにとどまり、所持金を P_{i,j} 増やす。
- 所持金から R_{i,j} 払ってマス (i,j+1) に移動する。
- 所持金から D_{i,j} 払ってマス (i+1,j) に移動する。
所持金が負になる移動、グリッドの外に出る移動はできません。
高橋君が最適に行動したとき、何回の行動でマス (N,N) にたどり着くことができますか。
制約
- 2 \leq N \leq 80
- 1 \leq P_{i,j} \leq 10^9
- 1 \leq R_{i,j},D_{i,j} \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N
P_{1,1} \ldots P_{1,N}
\vdots
P_{N,1} \ldots P_{N,N}
R_{1,1} \ldots R_{1,N-1}
\vdots
R_{N,1} \ldots R_{N,N-1}
D_{1,1} \ldots D_{1,N}
\vdots
D_{N-1,1} \ldots D_{N-1,N}
出力
答えを出力せよ。
入力例 1
3 1 2 3 3 1 2 2 1 1 1 2 4 3 4 2 1 5 7 5 3 3
出力例 1
8

以下のようにして 8 回の行動でマス (3,3) にたどり着くことができます。
- マス (1,1) にとどまり、所持金を 1 増やす。所持金は 1 になる。
- 所持金から 1 払ってマス (2,1) に移動する。所持金は 0 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 3 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 6 になる。
- マス (2,1) にとどまり、所持金を 3 増やす。所持金は 9 になる。
- 所持金から 4 払ってマス (2,2) に移動する。所持金は 5 になる。
- 所持金から 3 払ってマス (3,2) に移動する。所持金は 2 になる。
- 所持金から 2 払ってマス (3,3) に移動する。所持金は 0 になる。
入力例 2
3 1 1 1 1 1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
4000000004
Score: 550 points
Problem Statement
There is a grid with N rows and N columns. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.
Takahashi is initially at square (1,1) with zero money.
When Takahashi is at square (i,j), he can perform one of the following in one action:
- Stay at the same square and increase his money by P_{i,j}.
- Pay R_{i,j} from his money and move to square (i,j+1).
- Pay D_{i,j} from his money and move to square (i+1,j).
He cannot make a move that would make his money negative or take him outside the grid.
If Takahashi acts optimally, how many actions does he need to reach square (N,N)?
Constraints
- 2 \leq N \leq 80
- 1 \leq P_{i,j} \leq 10^9
- 1 \leq R_{i,j},D_{i,j} \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
P_{1,1} \ldots P_{1,N}
\vdots
P_{N,1} \ldots P_{N,N}
R_{1,1} \ldots R_{1,N-1}
\vdots
R_{N,1} \ldots R_{N,N-1}
D_{1,1} \ldots D_{1,N}
\vdots
D_{N-1,1} \ldots D_{N-1,N}
Output
Print the answer.
Sample Input 1
3 1 2 3 3 1 2 2 1 1 1 2 4 3 4 2 1 5 7 5 3 3
Sample Output 1
8

It is possible to reach square (3,3) in eight actions as follows:
- Stay at square (1,1) and increase money by 1. His money is now 1.
- Pay 1 money and move to square (2,1). His money is now 0.
- Stay at square (2,1) and increase money by 3. His money is now 3.
- Stay at square (2,1) and increase money by 3. His money is now 6.
- Stay at square (2,1) and increase money by 3. His money is now 9.
- Pay 4 money and move to square (2,2). His money is now 5.
- Pay 3 money and move to square (3,2). His money is now 2.
- Pay 2 money and move to square (3,3). His money is now 0.
Sample Input 2
3 1 1 1 1 1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
4000000004