Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 N および、英小文字からなる長さが N 未満 の文字列 S が与えられます。
長さが N になるまで S の先頭に英小文字 o を追加し続けることで得られる文字列を出力してください。
制約
- 2\leq N \leq 100
- N は整数
- S は長さ 1 以上 N 未満の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
5 abc
出力例 1
ooabc
N=5、S の長さは 3 であるため、S の先頭に o を 5-3=2 個追加した文字列が答えとなります。
入力例 2
2 o
出力例 2
oo
入力例 3
12 vgxgpuam
出力例 3
oooovgxgpuam
Score : 100 points
Problem Statement
You are given an integer N and a string S consisting of lowercase English letters with length less than N.
Print the string obtained by repeatedly adding the lowercase English letter o to the beginning of S until its length becomes N.
Constraints
- 2\leq N \leq 100
- N is an integer.
- S is a string consisting of lowercase English letters with length between 1 and N - 1, inclusive.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
5 abc
Sample Output 1
ooabc
Since N=5 and the length of S is 3, the answer is the string obtained by adding 5-3=2 os to the beginning of S.
Sample Input 2
2 o
Sample Output 2
oo
Sample Input 3
12 vgxgpuam
Sample Output 3
oooovgxgpuam
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君のケーキが誰かに食べられてしまいました。ケーキを食べた犯人の候補として、人 1、人 2、人 3 の三人が挙げられています。
犯人の目撃者はりんごさんとすぬけくんの二人がいます。りんごさんは人 A が犯人でないことを覚えており、すぬけくんは人 B が犯人でないことを覚えています。
二人の記憶から犯人を一人に特定できるかどうか判定し、特定できるならばその人の番号を出力してください。
制約
- 1\leq A,B\leq 3
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
二人の記憶から犯人を一人に特定できるならばその人の番号を出力し、特定できないならば -1 を出力せよ。
入力例 1
1 2
出力例 1
3
二人の記憶から、人 3 が犯人であることが特定できます。
入力例 2
1 1
出力例 2
-1
二人の記憶からでは、人 2,3 のどちらが犯人か特定することができません。よって -1 を出力します。
入力例 3
3 1
出力例 3
2
Score : 100 points
Problem Statement
Takahashi's cake has been eaten by someone. There are three suspects: person 1, person 2, and person 3.
There are two witnesses, Ringo and Snuke. Ringo remembers that person A is not the culprit, and Snuke remembers that person B is not the culprit.
Determine if the culprit can be uniquely identified based on the memories of the two witnesses. If the culprit can be identified, print the person's number.
Constraints
- 1 \leq A, B \leq 3
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
If the culprit can be uniquely identified based on the memories of the two witnesses, print the person's number; otherwise, print -1.
Sample Input 1
1 2
Sample Output 1
3
From the memories of the two witnesses, it can be determined that person 3 is the culprit.
Sample Input 2
1 1
Sample Output 2
-1
From the memories of the two witnesses, it cannot be determined whether person 2 or person 3 is the culprit. Therefore, print -1.
Sample Input 3
3 1
Sample Output 3
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N + 1 個の部屋が一列に並んでおり、順に 0, 1, \ldots, N の番号が付けられています。
部屋の間には N 個のドアがあり、1, 2, \ldots, N の番号が付けられています。ドア i は部屋 i - 1 と部屋 i の間にあります。
各ドアについて鍵の状態を表す値 L_i が与えられ、L_i = 0 のときドア i の鍵は開いており、L_i = 1 のときドア i の鍵は閉まっています。
2 人の人がおり、1 人は部屋 0 に、もう 1 人は部屋 N にいます。それぞれの人は、ドア i の鍵が開いているときに限り、部屋 i - 1 と部屋 i の間を移動することができます。
このとき、2 人のいずれも到達できない部屋の個数を求めてください。
制約
- 2 \leq N \leq 100
- L_i \in \lbrace 0, 1 \rbrace
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 L_2 \ldots L_N
出力
答えを出力せよ。
入力例 1
5 0 1 0 0 1
出力例 1
3
2 人のいずれも到達できない部屋は部屋 2, 3, 4 の 3 つです。
入力例 2
3 1 0 1
出力例 2
2
入力例 3
8 0 0 1 1 0 1 0 0
出力例 3
3
Score : 200 points
Problem Statement
There are N + 1 rooms arranged in a line, numbered 0, 1, \ldots, N in order.
Between the rooms, there are N doors numbered 1, 2, \ldots, N. Door i is between rooms i - 1 and i.
For each door, a value L_i representing the lock state is given. When L_i = 0, door i is unlocked, and when L_i = 1, door i is locked.
There are two people, one in room 0 and the other in room N. Each person can move between rooms i - 1 and i only when door i is unlocked.
Find the number of rooms that neither of the two people can reach.
Constraints
- 2 \leq N \leq 100
- L_i \in \lbrace 0, 1 \rbrace
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 L_2 \ldots L_N
Output
Output the answer.
Sample Input 1
5 0 1 0 0 1
Sample Output 1
3
The rooms that neither of the two people can reach are rooms 2, 3, 4, which is 3 rooms.
Sample Input 2
3 1 0 1
Sample Output 2
2
Sample Input 3
8 0 0 1 1 0 1 0 0
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数 A,B が与えられます。
A+B を(十進法で)計算する時、繰り上がりが生じないなら Easy 、生じるなら Hard と出力してください。
制約
- A,B は整数
- 1 \le A,B \le 10^{18}
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
繰り上がりが生じないなら Easy 、生じるなら Hard と出力せよ。
入力例 1
229 390
出力例 1
Hard
229+390 を計算する際、十の位から百の位へと繰り上がりが発生します。よって、答えは Hard です。
入力例 2
123456789 9876543210
出力例 2
Easy
繰り上がりは発生しません。答えは Easy です。
また、入力が 32bit 整数に収まらないこともあります。
Score : 200 points
Problem Statement
You are given positive integers A and B.
Let us calculate A+B (in decimal). If it does not involve a carry, print Easy; if it does, print Hard.
Constraints
- A and B are integers.
- 1 \le A,B \le 10^{18}
Input
Input is given from Standard Input in the following format:
A B
Output
If the calculation does not involve a carry, print Easy; if it does, print Hard.
Sample Input 1
229 390
Sample Output 1
Hard
When calculating 229+390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input 2
123456789 9876543210
Sample Output 2
Easy
We do not have a carry here; the answer is Easy.
Note that the input may not fit into a 32-bit integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
正整数 n が次の条件を満たす時、n を 良い整数 と呼びます。
- 0 \lt x \lt y かつ x^2+y^2=n を満たす整数の組 (x,y) がただ 1 つ存在する。
例えば n=2026 とすると、0 \lt x \lt y かつ x^2+y^2=n を満たす整数の組は (x,y)=(1,45) しか存在しないことが確認できます。よって 2026 は良い整数です。
正整数 N が与えられます。N 以下の良い整数を全て列挙してください。
制約
- 1 \leq N \leq 10^7
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N 以下の良い整数が k 個あり、それらを昇順に並べた列が (a_1, a_2, \dots, a_k) であるとする。この時、以下の形式で答えを出力せよ。(k=0 である場合は 2 行目は空行として出力せよ。)
k a_1 a_2 \dots a_k
入力例 1
10
出力例 1
2 5 10
0 \lt x \lt y かつ x^2+y^2=5 を満たす整数の組は (x,y)=(1,2) しか存在しないので 5 は良い整数です。
0 \lt x \lt y かつ x^2+y^2=10 を満たす整数の組は (x,y)=(1,3) しか存在しないので 10 は良い整数です。
N 以下の良い整数はこの 2 個のみです。
入力例 2
1
出力例 2
0
入力例 3
50
出力例 3
14 5 10 13 17 20 25 26 29 34 37 40 41 45 50
Score : 300 points
Problem Statement
A positive integer n is called a good integer when it satisfies the following condition:
- There exists exactly one pair of integers (x,y) that satisfies 0 \lt x \lt y and x^2+y^2=n.
For example, when n=2026, it can be verified that (x,y)=(1,45) is the only pair of integers that satisfies 0 \lt x \lt y and x^2+y^2=n. Thus, 2026 is a good integer.
You are given a positive integer N. Enumerate all good integers not exceeding N.
Constraints
- 1 \leq N \leq 10^7
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Let there be k good integers not exceeding N, and let (a_1, a_2, \dots, a_k) be the sequence of these integers in ascending order. Output the answer in the following format. (If k=0, output the second line as an empty line.)
k a_1 a_2 \dots a_k
Sample Input 1
10
Sample Output 1
2 5 10
(x,y)=(1,2) is the only pair of integers that satisfies 0 \lt x \lt y and x^2+y^2=5, so 5 is a good integer.
(x,y)=(1,3) is the only pair of integers that satisfies 0 \lt x \lt y and x^2+y^2=10, so 10 is a good integer.
These are the only two good integers not exceeding N.
Sample Input 2
1
Sample Output 2
0
Sample Input 3
50
Sample Output 3
14 5 10 13 17 20 25 26 29 34 37 40 41 45 50