Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
5 枚のカードがあり、それぞれのカードには整数 A,B,C,D,E が書かれています。
この 5 枚組は以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。
- 同じ数が書かれたカード 3 枚と、別の同じ数が書かれたカード 2 枚からなる。
5 枚組がフルハウスであるか判定してください。
制約
- 1 \leq A,B,C,D,E\leq 13
- A,B,C,D,E 全てが同じ値ではない
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E
出力
フルハウスである場合 Yes を、そうでないとき No を出力せよ。
入力例 1
1 2 1 2 1
出力例 1
Yes
1 が書かれたカード 3 枚と、2 が書かれたカード 2 枚からなるため、これはフルハウスです。
入力例 2
12 12 11 1 2
出力例 2
No
フルハウスの条件を満たしません。
Score : 100 points
Problem Statement
We have five cards with integers A, B, C, D, and E written on them, one on each card.
This set of five cards is called a Full house if and only if the following condition is satisfied:
- the set has three cards with a same number written on them, and two cards with another same number written on them.
Determine whether the set is a Full house.
Constraints
- 1 \leq A,B,C,D,E\leq 13
- Not all of A, B, C, D, and E are the same.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D E
Output
If the set is a Full house, print Yes; otherwise, print No.
Sample Input 1
1 2 1 2 1
Sample Output 1
Yes
The set has three cards with 1 written on them and two cards with 2 written on them, so it is a Full house.
Sample Input 2
12 12 11 1 2
Sample Output 2
No
The condition is not satisfied.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
8 種類の方角(北、東、西、南、北東、北西、南東、南西)のいずれかを表す文字列 D が与えられます。方角とそれを表す文字列は以下のように対応しています。
- 北:
N - 東:
E - 西:
W - 南:
S - 北東:
NE - 北西:
NW - 南東:
SE - 南西:
SW
D が表す方角の反対の方角を表す文字列を出力してください。
制約
- D は
N,E,W,S,NE,NW,SE,SWのいずれか
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
入力例 1
N
出力例 1
S
北の反対の方角である南を表す S を出力してください。
入力例 2
SE
出力例 2
NW
南東の反対の方角である北西を表す NW を出力してください。
Score : 100 points
Problem Statement
You are given a string D representing one of the eight directions (north, east, west, south, northeast, northwest, southeast, southwest). The correspondence between the directions and their representing strings is as follows.
- North:
N - East:
E - West:
W - South:
S - Northeast:
NE - Northwest:
NW - Southeast:
SE - Southwest:
SW
Print the string representing the direction opposite to the direction denoted by D.
Constraints
- D is one of
N,E,W,S,NE,NW,SE,SW.
Input
The input is given from Standard Input in the following format:
D
Output
Print the answer.
Sample Input 1
N
Sample Output 1
S
Print S, which represents south, the direction opposite to north.
Sample Input 2
SE
Sample Output 2
NW
Print NW, which represents northwest, the direction opposite to southeast.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
数直線の原点に高橋君がいます。高橋君は座標 X にあるゴールに移動しようとしています。
座標 Y には壁があり、最初、高橋君は壁を超えて移動することができません。
座標 Z にあるハンマーを拾った後でなら、壁を破壊して通過できるようになります。
高橋君がゴールに到達することが可能か判定し、可能であれば移動距離の最小値を求めてください。
制約
- -1000 \leq X,Y,Z \leq 1000
- X,Y,Z は相異なり、いずれも 0 でない
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
X Y Z
出力
高橋君がゴールに到達することが可能であれば、移動距離の最小値を出力せよ。不可能であれば、かわりに -1 と出力せよ。
入力例 1
10 -10 1
出力例 1
10
高橋君はまっすぐゴールに向かうことができます。
入力例 2
20 10 -10
出力例 2
40
ゴールは壁の向こう側にあります。まずハンマーを拾い、壁を壊すことでゴールに到達することができます。
入力例 3
100 1 1000
出力例 3
-1
Score : 200 points
Problem Statement
Takahashi is at the origin of a number line. He wants to reach a goal at coordinate X.
There is a wall at coordinate Y, which Takahashi cannot go beyond at first.
However, after picking up a hammer at coordinate Z, he can destroy that wall and pass through.
Determine whether Takahashi can reach the goal. If he can, find the minimum total distance he needs to travel to do so.
Constraints
- -1000 \leq X,Y,Z \leq 1000
- X, Y, and Z are distinct, and none of them is 0.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
X Y Z
Output
If Takahashi can reach the goal, print the minimum total distance he needs to travel to do so. If he cannot, print -1 instead.
Sample Input 1
10 -10 1
Sample Output 1
10
Takahashi can go straight to the goal.
Sample Input 2
20 10 -10
Sample Output 2
40
The goal is beyond the wall. He can get there by first picking up the hammer and then destroying the wall.
Sample Input 3
100 1 1000
Sample Output 3
-1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
26 個のキーが数直線上に並んだキーボードがあります。
このキーボードの配列は ABCDEFGHIJKLMNOPQRSTUVWXYZ を並べ替えた文字列 S で表されます。
文字 S_x に対応するキーが座標 x (1 \leq x \leq 26) にあります。 ここで、S_x は S の x 文字目を表します。
あなたはこのキーボードを使って ABCDEFGHIJKLMNOPQRSTUVWXYZ をこの順で右手人差し指で一度だけ入力します。
ある文字を入力するためには、その文字に対応するキーの座標に指を移動させてキーを押す必要があります。
はじめ、指は A に対応するキーの座標にあります。A に対応するキーを押してから、Z に対応するキーを押すまでの指の移動距離の合計として考えられる最小値を求めてください。ただし、
キーを押す動作は移動距離に含まれません。
制約
- S は
ABCDEFGHIJKLMNOPQRSTUVWXYZを並べ替えた文字列である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
出力例 1
25
A のキーを押してから Z のキーを押すまで指を 1 ずつ正の方向に移動させる必要があり、このときの移動距離の合計は 25 です。25 未満の総移動距離でキーを全て入力することはできないため、25 と出力します。
入力例 2
MGJYIZDKSBHPVENFLQURTCWOAX
出力例 2
223
Score : 200 points
Problem Statement
There is a keyboard with 26 keys arranged on a number line.
The arrangement of this keyboard is represented by a string S, which is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ.
The key corresponding to the character S_x is located at coordinate x (1 \leq x \leq 26). Here, S_x denotes the x-th character of S.
You will use this keyboard to input ABCDEFGHIJKLMNOPQRSTUVWXYZ in this order, typing each letter exactly once with your right index finger.
To input a character, you need to move your finger to the coordinate of the key corresponding to that character and press the key.
Initially, your finger is at the coordinate of the key corresponding to A. Find the minimal possible total traveled distance of your finger from pressing the key for A to pressing the key for Z. Here, pressing a key does not contribute to the distance.
Constraints
- S is a permutation of
ABCDEFGHIJKLMNOPQRSTUVWXYZ.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Sample Output 1
25
From pressing the key for A to pressing the key for Z, you need to move your finger 1 unit at a time in the positive direction, resulting in a total traveled distance of 25. It is impossible to press all keys with a total traveled distance less than 25, so print 25.
Sample Input 2
MGJYIZDKSBHPVENFLQURTCWOAX
Sample Output 2
223
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1 から N の番号がついた N 人の人がいます。人 i は数 A_i を持っています。
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たす人のうち、持っている数が最大である人の番号を求めてください。
条件を満たす人が存在しない場合、代わりにそのことを報告してください。
制約
- 1 \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たす人が存在しない場合、-1 と出力せよ。
条件を満たす人が存在する場合、そのうち、持っている数が最大である人の番号を出力せよ。
入力例 1
9 2 9 9 7 9 2 4 5 8
出力例 1
9
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たすのは人 4,7,8,9 の 4 人です。
これらの人が持っている数はそれぞれ 7,4,5,8 であり、最大の数を持っているのは人 9 です。
よって答えは 9 となります。
入力例 2
4 1000000000 1000000000 998244353 998244353
出力例 2
-1
条件を満たす人が存在しない場合、-1 を出力してください。
Score : 300 points
Problem Statement
There are N people, labeled 1 to N. Person i has an integer A_i.
Among the people who satisfy the condition "None of the other N-1 people has the same integer as themselves," find the one with the greatest integer, and print that person's label.
If no person satisfies the condition, report that fact instead.
Constraints
- 1 \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
If no person satisfies the condition "None of the other N-1 people has the same integer as themselves," print -1.
Otherwise, among those who satisfy it, print the label of the person whose integer is the largest.
Sample Input 1
9 2 9 9 7 9 2 4 5 8
Sample Output 1
9
Those who satisfy the condition are the persons labeled 4, 7, 8, and 9.
Their integers are 7, 4, 5, and 8, respectively, and the person with the largest integer is the person labeled 9.
Thus, the answer is 9.
Sample Input 2
4 1000000000 1000000000 998244353 998244353
Sample Output 2
-1
If no person satisfies the condition, print -1.