実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
100 以上の整数 N が与えられます。N の下 2 桁を出力してください。
ただし、N の下 2 桁とは十の位と一の位をこの順に並べたものを言います。
制約
- 100 \le N \le 999
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
254
出力例 1
54
254 の下 2 桁は 54 であるため、54 を出力します。
入力例 2
101
出力例 2
01
101 の下 2 桁は 01 であるため、01 を出力します。
Score : 100 points
Problem Statement
You are given an integer N at least 100. Print the last two digits of N.
Strictly speaking, print the tens and ones digits of N in this order.
Constraints
- 100 \le N \le 999
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
254
Sample Output 1
54
The last two digits of 254 are 54, which should be printed.
Sample Input 2
101
Sample Output 2
01
The last two digits of 101 are 01, which should be printed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君はたこ焼きを作ってすぬけ君に振る舞うことにしました。高橋君はすぬけ君に、たこ焼きを食べたいならば左手のみを挙げて、そうでないならば右手のみを挙げるよう指示しました。
すぬけ君が挙げた手の情報は整数 L, R によって与えられます。 すぬけ君は L = 1 のとき、またそのときに限り左手を挙げており、R = 1 のとき、またそのときに限り右手を挙げています。すぬけ君は指示に従わず、両手を挙げることも手を挙げないこともあります。
すぬけ君が片方の手のみを挙げている場合、すぬけ君がたこ焼きを食べたいならば Yes を、そうでないならば No を出力してください。すぬけ君が両手を挙げているか、手を挙げていないときは Invalid と出力してください。
ただし、すぬけ君が片方の手のみを挙げている場合は必ず指示に従った行動を取っているものとします。
制約
- L, R は 0 または 1
入力
入力は以下の形式で標準入力から与えられる。
L R
出力
問題文の指示に従って Yes, No, Invalid のいずれかを出力せよ。
入力例 1
1 0
出力例 1
Yes
すぬけ君はたこ焼きを食べたいので左手のみを挙げています。
入力例 2
1 1
出力例 2
Invalid
すぬけ君は両手を挙げています。
Score : 100 points
Problem Statement
Takahashi decided to make takoyaki (octopus balls) and serve it to Snuke. Takahashi instructed Snuke to raise only his left hand if he wants to eat takoyaki, and only his right hand otherwise.
You are given the information about which hand Snuke is raising as two integers L and R. He is raising his left hand if and only if L = 1, and raising his right hand if and only if R = 1. He might not follow the instructions and could raise both hands or not raise any hand at all.
If Snuke is raising only one hand, print Yes if he wants to eat takoyaki, and No if he does not. If he is raising both hands or not raising any hand, print Invalid.
Assume that if Snuke is raising only one hand, he is always following the instructions.
Constraints
- Each of L and R is 0 or 1.
Input
The input is given from Standard Input in the following format:
L R
Output
Print Yes, No, or Invalid according to the instructions in the problem statement.
Sample Input 1
1 0
Sample Output 1
Yes
Snuke wants to eat takoyaki, so he is raising only his left hand.
Sample Input 2
1 1
Sample Output 2
Invalid
Snuke is raising both hands.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S が良い文字列であるとは、すべての 1 以上の整数 i について次の性質が成り立つことであるとします。
- S にちょうど i 回現れる文字はちょうど 0 種類またはちょうど 2 種類ある
文字列 S が与えられるので、 S が良い文字列か判定してください。
制約
- S は英小文字からなる長さ 1 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が良い文字列ならば Yes を、そうでないならば No を出力せよ。
入力例 1
commencement
出力例 1
Yes
文字列 commencement にちょうど i 回現れる文字の種類数は以下のとおりです。
- i=1:
o,tの 2 種類 - i=2:
c,nの 2 種類 - i=3:
e,mの 2 種類 - i\geq 4: 0 種類
よって、commencement は良い文字列の条件を満たします。
入力例 2
banana
出力例 2
No
文字列 banana にちょうど 1 回現れる文字は b の 1 種類だけであり、良い文字列の条件を満たしません。
入力例 3
ab
出力例 3
Yes
Score: 200 points
Problem Statement
A string S consisting of lowercase English letters is a good string if and only if it satisfies the following property for all integers i not less than 1:
- There are exactly zero or exactly two different letters that appear exactly i times in S.
Given a string S, determine if it is a good string.
Constraints
- S is a string of lowercase English letters with a length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S is a good string, and No otherwise.
Sample Input 1
commencement
Sample Output 1
Yes
For the string commencement, the number of different letters that appear exactly i times is as follows:
- i=1: two letters (
oandt) - i=2: two letters (
candn) - i=3: two letters (
eandm) - i\geq 4: zero letters
Therefore, commencement satisfies the condition of a good string.
Sample Input 2
banana
Sample Output 2
No
For the string banana, there is only one letter that appears exactly one time, which is b, so it does not satisfy the condition of a good string.
Sample Input 3
ab
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ナオヒロ君は N+1 個の連続する整数を 1 個ずつ持っていましたが、そのうち 1 個をなくしてしまいました。
残っている N 個の整数が順不同で A_1,\ldots,A_N として与えられるので、なくした整数を求めてください。
なお、なくした整数が一意に定まるような入力のみが与えられます。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 入力は全て整数である
- なくした整数は一意に定まる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 2 3 5
出力例 1
4
ナオヒロ君は初め 2,3,4,5 の 4 個の整数を持っており、4 をなくし、2,3,5 が残っていました。
なくした整数である 4 を出力します。
入力例 2
8 3 1 4 5 9 2 6 8
出力例 2
7
入力例 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
出力例 3
151
Score : 200 points
Problem Statement
Naohiro had N+1 consecutive integers, one of each, but he lost one of them.
The remaining N integers are given in arbitrary order as A_1,\ldots,A_N. Find the lost integer.
The given input guarantees that the lost integer is uniquely determined.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- All input values are integers.
- The lost integer is uniquely determined.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
3 2 3 5
Sample Output 1
4
Naohiro originally had four integers, 2,3,4,5, then lost 4, and now has 2,3,5.
Print the lost integer, 4.
Sample Input 2
8 3 1 4 5 9 2 6 8
Sample Output 2
7
Sample Input 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
Sample Output 3
151
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
長さ M の A の連続部分列 B=(B_1,B_2,\dots,B_M) に対する、\displaystyle \sum_{i=1}^{M} i \times B_i の最大値を求めてください。
注記
数列の連続部分列とは、数列の先頭から 0 個以上、末尾から 0 個以上の要素を削除して得られる列のことをいいます。
例えば (2, 3) や (1, 2, 3) は (1, 2, 3, 4) の連続部分列ですが、(1, 3) や (3,2,1) は (1, 2, 3, 4) の連続部分列ではありません。
制約
- 1 \le M \le N \le 2 \times 10^5
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 2 5 4 -1 8
出力例 1
15
B=(A_3,A_4) とした場合、\displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times (-1) + 2 \times 8 = 15 となります。16 以上の値を達成することはできないため、解は 15 です。
B=(A_1,A_4) などを選ぶことができないことに注意してください。
入力例 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
出力例 2
31
Score : 300 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N.
Find the maximum value of \displaystyle \sum_{i=1}^{M} i \times B_i for a contiguous subarray B=(B_1,B_2,\dots,B_M) of A of length M.
Notes
A contiguous subarray of a number sequence is a sequence that is obtained by removing 0 or more initial terms and 0 or more final terms from the original number sequence.
For example, (2, 3) and (1, 2, 3) are contiguous subarrays of (1, 2, 3, 4), but (1, 3) and (3,2,1) are not contiguous subarrays of (1, 2, 3, 4).
Constraints
- 1 \le M \le N \le 2 \times 10^5
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 2 5 4 -1 8
Sample Output 1
15
When B=(A_3,A_4), we have \displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times (-1) + 2 \times 8 = 15. Since it is impossible to achieve 16 or a larger value, the solution is 15.
Note that you are not allowed to choose, for instance, B=(A_1,A_4).
Sample Input 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
Sample Output 2
31
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
長さ N の正整数のみからなる数列 A=(A_1,\dots,A_N) があります。
A を 10^{100} 回連結した数列を数列 B とします。
B の項を前から順に足したとき、和が初めて X を超えるのは何項目まで足したときですか?
すなわち、以下の式を満たす最小の整数 k を求めてください。
\displaystyle{\sum_{i=1}^{k} B_i \gt X}
制約
- 1 \leq N \leq 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N X
出力
答えを出力せよ。
入力例 1
3 3 5 2 26
出力例 1
8
B=(3,5,2,3,5,2,3,5,2,\dots) です。
\displaystyle{\sum_{i=1}^{8} B_i = 28 \gt 26} であり、k が 7 以下のとき条件を満たさないので、8 が答えです。
入力例 2
4 12 34 56 78 1000
出力例 2
23
Score : 300 points
Problem Statement
We have a sequence of N positive integers: A=(A_1,\dots,A_N).
Let B be the concatenation of 10^{100} copies of A.
Consider summing up the terms of B from left to right. When does the sum exceed X for the first time?
In other words, find the minimum integer k such that:
\displaystyle{\sum_{i=1}^{k} B_i \gt X}.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq X \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N X
Output
Print the answer.
Sample Input 1
3 3 5 2 26
Sample Output 1
8
We have B=(3,5,2,3,5,2,3,5,2,\dots).
\displaystyle{\sum_{i=1}^{8} B_i = 28 \gt 26} holds, but the condition is not satisfied when k is 7 or less, so the answer is 8.
Sample Input 2
4 12 34 56 78 1000
Sample Output 2
23
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
H 行 W 列のマス目からなる迷路があります。 上から i 行目、左から j 列目のマスを (i,j) と表記します。 マス (i,j) がどのようなマスであるかは文字 S_{i,j} として与えられ、各文字の意味は以下の通りです。
.: 空きマス#: 障害物マス- 英小文字(
a-z): ワープマス
迷路内では、以下の二種類の行動を好きな順序で何回でも行うことができます。
- 歩行:現在いるマスから上下左右の四方向のいずれかに 1 マス分進んだマスへ移動する。ただし、障害物マスへ移動することや、マス目の外に移動することはできない。
- ワープ:ワープマスにいるとき、そのワープマスと同じ文字が書かれたワープマスのうちいずれか好きなマスへと移動する。
マス (1,1) からマス (H,W) へ移動することが可能かどうか判定し、可能ならばそれに必要な最小の合計行動回数を求めてください。
制約
- 1\leq H,W \leq 1000
- H\times W \geq 2
- H,W は整数
- S_{i,j} は
.,#, または英小文字のいずれか - S_{1,1}\neq
# - S_{H,W}\neq
#
入力
入力は以下の形式で標準入力から与えられる。
H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
出力
マス (1,1) からマス (H,W) へ移動することが可能ならばそれに必要な最小の合計行動回数を、不可能ならば -1 を出力せよ。
入力例 1
3 4 ..a. #### ba#b
出力例 1
5
以下のように行動することで、マス (1,1) からマス (3,4) へ移動することができます。
- マス (1,1) からマス (1,2) へ歩行によって移動する。
- マス (1,2) からマス (1,3) へ歩行によって移動する。
- マス (1,3) からマス (3,2) へワープによって移動する。
- マス (3,2) からマス (3,1) へ歩行によって移動する。
- マス (3,1) からマス (3,4) へワープによって移動する。
このときの合計行動回数は 5 回であり、これが最小です。
入力例 2
3 4 ..a. #### b.#b
出力例 2
-1
マス (1,1) からマス (3,4) へ移動することは不可能です。
入力例 3
4 4 xxxx xxxx xxxx xxxx
出力例 3
1
入力例 4
7 11 u..#y..#... k..#.z.#.k. iju#...#x.. ########### ..x#.t.#..n abc#y..#... ..z#..t#.y.
出力例 4
12
Score : 400 points
Problem Statement
There is a maze consisting of a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left. The type of cell (i,j) is given as a character S_{i,j}, where each character has the following meaning:
.: Empty cell#: Obstacle cell- Lowercase English letter (
a-z): Warp cell
In the maze, you can perform the following two types of actions any number of times in any order:
- Walk: Move from the current cell to a cell that is one cell away in one of the four directions (up, down, left, right). However, you cannot move to an obstacle cell or outside the grid.
- Warp: When you are at a warp cell, move to any warp cell with the same character written on it.
Determine whether it is possible to move from cell (1,1) to cell (H,W), and if possible, find the minimum total number of actions required.
Constraints
- 1\leq H,W \leq 1000
- H\times W \geq 2
- H and W are integers.
- S_{i,j} is
.,#, or a lowercase English letter. - S_{1,1}\neq
# - S_{H,W}\neq
#
Input
The input is given from Standard Input in the following format:
H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}
Output
If it is possible to move from cell (1,1) to cell (H,W), print the minimum total number of actions required; otherwise, print -1.
Sample Input 1
3 4 ..a. #### ba#b
Sample Output 1
5
You can move from cell (1,1) to cell (3,4) by performing actions as follows:
- Move from cell (1,1) to cell (1,2) by walking.
- Move from cell (1,2) to cell (1,3) by walking.
- Move from cell (1,3) to cell (3,2) by warping.
- Move from cell (3,2) to cell (3,1) by walking.
- Move from cell (3,1) to cell (3,4) by warping.
The total number of actions is 5, which is the minimum.
Sample Input 2
3 4 ..a. #### b.#b
Sample Output 2
-1
It is impossible to move from cell (1,1) to cell (3,4).
Sample Input 3
4 4 xxxx xxxx xxxx xxxx
Sample Output 3
1
Sample Input 4
7 11 u..#y..#... k..#.z.#.k. iju#...#x.. ########### ..x#.t.#..n abc#y..#... ..z#..t#.y.
Sample Output 4
12
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の整数列 A = (A_1, A_2, \dots, A_N) が与えられます。
A の連続するとは限らない、長さが 2 以上である部分列 A'=(A'_1,A'_2,\ldots,A'_k) のうち以下の条件を満たすものの個数を求めてください。
- A'_1 \leq A'_k
なお、この値は非常に大きくなることがあるため、998244353 で割ったあまりを出力してください。
ただし、2 つの部分列は、列として同じであっても、取り出す添字が異なる場合は区別されます。
制約
- 2 \leq N \leq 3 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
A の連続するとは限らない、長さが 2 以上である部分列のうち問題文中の条件を満たすものの個数を、998244353 で割ったあまりを出力せよ。
入力例 1
3 1 2 1
出力例 1
3
A=(1,2,1) の連続するとは限らない、長さが 2 以上である部分列は (1,2), (1,1), (2,1), (1,2,1) の 4 通りあります。
そのうち問題文中の条件を満たすものは、(1,2), (1,1), (1,2,1) の 3 通りです。
入力例 2
3 1 2 2
出力例 2
4
列として同じであっても、取り出す添字が異なる場合 2 つの部分列は区別されることに注意してください。
この入出力例において、問題文中の条件を満たすような部分列は (1,2), (1,2), (2,2), (1,2,2) の 4 通りです。
入力例 3
3 3 2 1
出力例 3
0
問題文中の条件を満たすような部分列が存在しない場合もあります。
入力例 4
10 198495780 28463047 859606611 212983738 946249513 789612890 782044670 700201033 367981604 302538501
出力例 4
830
Score : 500 points
Problem Statement
Given is a sequence of N integers: A = (A_1, A_2, \dots, A_N).
Find the number of (not necessarily contiguous) subsequences A'=(A'_1,A'_2,\ldots,A'_k) of length at least 2 that satisfy the following condition:
- A'_1 \leq A'_k.
Since the count can be enormous, print it modulo 998244353.
Here, two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.
Constraints
- 2 \leq N \leq 3 \times 10^5
- 1 \leq A_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the number of (not necessarily contiguous) subsequences A'=(A'_1,A'_2,\ldots,A'_k) of length at least 2 that satisfy the condition in Problem Statement.
Sample Input 1
3 1 2 1
Sample Output 1
3
A=(1,2,1) has four (not necessarily contiguous) subsequences of length at least 2: (1,2), (1,1), (2,1), (1,2,1).
Three of them, (1,2), (1,1), (1,2,1), satisfy the condition in Problem Statement.
Sample Input 2
3 1 2 2
Sample Output 2
4
Note that two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.
In this Sample, there are four subsequences, (1,2), (1,2), (2,2), (1,2,2), that satisfy the condition.
Sample Input 3
3 3 2 1
Sample Output 3
0
There may be no subsequence that satisfies the condition.
Sample Input 4
10 198495780 28463047 859606611 212983738 946249513 789612890 782044670 700201033 367981604 302538501
Sample Output 4
830
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
AtCoder 島には N 種類のセミが生息しています。種類 i のセミ (1 \leq i \leq N) は A_i の倍数の年にのみ大量発生します。
1 年から Y 年までの Y 年間のうち、ちょうど M 種類のセミが大量発生する年が何回あるかを求めてください。
制約
- 1 \leq M \leq N \leq 20
- 1 \leq Y \leq 10^{18}
- 1 \leq A_i \leq 10^{18} (1 \leq i \leq N)
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M Y A_1 \cdots A_N
出力
答えを出力せよ。
入力例 1
3 2 16 4 2 3
出力例 1
4
1 年から 16 年までのうち、各種類のセミが大量発生するのは以下の年です。
- 種類 1 のセミは 4,8,12,16 年に大量発生する。
- 種類 2 のセミは 2,4,6,8,10,12,14,16 年に大量発生する。
- 種類 3 のセミは 3,6,9,12,15 年に大量発生する。
1 年から 16 年までのうち、ちょうど 2 種類のセミが大量発生するのは 4,6,8,16 年の 4 回です。
入力例 2
2 1 122333444422333 1429 73651
出力例 2
87266392324
答えが 32bit 整数に収まらないことがあります。
入力例 3
20 3 832725971730072237 19639596380058 49098990950145 32732660633430 114564312217005 68738587330203 45825724886802 252041486877411 180029633483865 108017780090319 72011853393546 468077047058049 297867211764213 212762294117295 127657376470377 85104917646918 723391799998803 612100753845141 389518661537817 278227615384155 166936569230493
出力例 3
24231
入力される値が 32bit 整数に収まらないことがあります。
Score : 525 points
Problem Statement
AtCoder Island has N species of cicadas. Cicadas of species i (1 \leq i \leq N) have mass outbreaks only in years that are multiples of A_i.
Among the Y years from year 1 to year Y, find how many years have mass outbreaks of exactly M species of cicadas.
Constraints
- 1 \leq M \leq N \leq 20
- 1 \leq Y \leq 10^{18}
- 1 \leq A_i \leq 10^{18} (1 \leq i \leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M Y A_1 \cdots A_N
Output
Output the answer.
Sample Input 1
3 2 16 4 2 3
Sample Output 1
4
From years 1 to 16, each species of cicada has mass outbreaks in the following years:
- Species 1 cicadas have mass outbreaks in years 4,8,12,16.
- Species 2 cicadas have mass outbreaks in years 2,4,6,8,10,12,14,16.
- Species 3 cicadas have mass outbreaks in years 3,6,9,12,15.
From years 1 to 16, exactly two species of cicadas have mass outbreaks four times in years 4,6,8,16.
Sample Input 2
2 1 122333444422333 1429 73651
Sample Output 2
87266392324
The answer may not fit in a 32-bit integer.
Sample Input 3
20 3 832725971730072237 19639596380058 49098990950145 32732660633430 114564312217005 68738587330203 45825724886802 252041486877411 180029633483865 108017780090319 72011853393546 468077047058049 297867211764213 212762294117295 127657376470377 85104917646918 723391799998803 612100753845141 389518661537817 278227615384155 166936569230493
Sample Output 3
24231
Input values may not fit in a 32-bit integer.