Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
チーム高橋とチーム青木が N 回の試合を行いました。 i 回め (1\leq i\leq N) の試合ではチーム高橋が X _ i 点、チーム青木が Y _ i 点を獲得しました。
N 回の試合で獲得した得点の合計がより多いチームの勝ちです。
どちらのチームが勝ったか出力してください。 ただし、獲得した得点の合計が等しい場合は引き分けとなります。
制約
- 1\leq N\leq 100
- 0\leq X _ i\leq 100\ (1\leq i\leq N)
- 0\leq Y _ i\leq 100\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X _ 1 Y _ 1 X _ 2 Y _ 2 \vdots X _ N Y _ N
出力
チーム高橋が勝った場合 Takahashi
を、チーム青木が勝った場合 Aoki
を、引き分けの場合 Draw
を出力せよ。
入力例 1
4 10 2 10 1 10 2 3 2
出力例 1
Takahashi
4 回の試合で、チーム高橋は 33 点、チーム青木は 7 点を獲得しました。
チーム高橋が勝ったため、Takahashi
を出力してください。
入力例 2
6 5 4 4 5 2 4 1 6 7 1 3 2
出力例 2
Draw
いずれのチームも 22 点を獲得しました。
引き分けなので、Draw
を出力してください。
入力例 3
4 0 0 10 10 50 50 0 100
出力例 3
Aoki
一方もしくは両方のチームが、一試合のうちに 1 点も取れない場合もあります。
Score: 100 points
Problem Statement
Team Takahashi and Team Aoki played N matches. In the i-th match (1\leq i\leq N), Team Takahashi scored X _ i points, and Team Aoki scored Y _ i points.
The team with the higher total score from the N matches wins.
Print the winner. If the two teams have the same total score, it is a draw.
Constraints
- 1\leq N\leq 100
- 0\leq X _ i\leq 100\ (1\leq i\leq N)
- 0\leq Y _ i\leq 100\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X _ 1 Y _ 1 X _ 2 Y _ 2 \vdots X _ N Y _ N
Output
If Team Takahashi wins, print Takahashi
; if Team Aoki wins, print Aoki
; if it is a draw, print Draw
.
Sample Input 1
4 10 2 10 1 10 2 3 2
Sample Output 1
Takahashi
In four matches, Team Takahashi scored 33 points, and Team Aoki scored 7 points.
Team Takahashi wins, so print Takahashi
.
Sample Input 2
6 5 4 4 5 2 4 1 6 7 1 3 2
Sample Output 2
Draw
Both teams scored 22 points.
It is a draw, so print Draw
.
Sample Input 3
4 0 0 10 10 50 50 0 100
Sample Output 3
Aoki
One or both teams may score no points in a match.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
0123456789
に加えて 10,11,12,13,14,15 に対応する数字として ABCDEF
を使う 16 進表記では、0 以上 255 以下の整数は 1 桁または 2 桁になります。
例えば、0 や 12 は 16 進表記では 0
や C
と 1 桁になり、99 や 255 は 16 進表記では 63
や FF
と 2 桁になります。
0 以上 255 以下の整数 N を、必要に応じて先頭に 0
を加えることでちょうど 2 桁の 16 進表記に変換してください。
注記
英大文字と英小文字は区別されます。特に、16 進表記の数字として ABCDEF
の代わりに abcdef
を使うことは出来ません。
制約
- 0 \leq N \leq 255
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
99
出力例 1
63
99 は 16 進表記で 63
です。
入力例 2
12
出力例 2
0C
12 は 16 進表記で C
です。
要求されているのはちょうど 2 桁の 16 進表記に変換することなので、C
の先頭に 0
を加えた 0C
が答えです。
入力例 3
0
出力例 3
00
入力例 4
255
出力例 4
FF
Score : 100 points
Problem Statement
In the hexadecimal system, where the digits ABCDEF
corresponding to 10,11,12,13,14, and 15 are used in addition to 0123456789
, every integer between 0 and 255 is represented as a 1- or 2-digit numeral.
For example, 0 and 12 are represented as 1-digit hexadecimal numerals 0
and C
; 99 and 255 are represented as 2-digit hexadecimals 63
and FF
.
Given an integer N between 0 and 255, convert it to an exactly two-digit hexadecimal numeral, prepending leading 0
s if necessary.
Notes
The judge is case-sensitive. Specifically, you cannot use abcdef
as hexadecimal digits instead of ABCDEF
.
Constraints
- 0 \leq N \leq 255
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
99
Sample Output 1
63
99 is represented as 63
in hexadecimal.
Sample Input 2
12
Sample Output 2
0C
12 is represented as C
in hexadecimal.
Since we ask you to convert it to a two-digit hexadecimal numeral, the answer is 0C
, where 0
is prepended to C
.
Sample Input 3
0
Sample Output 3
00
Sample Input 4
255
Sample Output 4
FF
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0
か 1
かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0
, 1
からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。
各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。
- その回の投票で
0
を選択した人が x 人、1
を選択した人が y 人いたとします。- x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
- そうでなく x<y である場合、その投票で
0
に投票した人のみに 1 点が与えられる。 - そうでない場合、その投票で
1
に投票した人のみに 1 点が与えられる。 - なお、 N が奇数であることから x=y となることはないことに留意してください。
M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。
制約
- N は 1 \le N \le 99 を満たす 奇数
- M は 1 \le M \le 100 を満たす整数
- S_i は長さ M の
0
,1
からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。
入力例 1
3 5 11100 10101 01110
出力例 1
2 3
このケースでは、 3 人が 5 回の投票を行いました。
- 1 回目の投票では人 1 が
1
、人 2 が1
、人 3 が0
に投票しました。よって、人 3 のみが 1 点を得ます。 - 2 回目の投票では人 1 が
1
、人 2 が0
、人 3 が1
に投票しました。よって、人 2 のみが 1 点を得ます。 - 3 回目の投票では人 1 が
1
、人 2 が1
、人 3 が1
に投票しました。よって、全員が 1 点を得ます。 - 4 回目の投票では人 1 が
0
、人 2 が0
、人 3 が1
に投票しました。よって、人 3 のみが 1 点を得ます。 - 5 回目の投票では人 1 が
0
、人 2 が1
、人 3 が0
に投票しました。よって、人 2 のみが 1 点を得ます。
この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。
入力例 2
5 4 0000 0000 0000 0000 0000
出力例 2
1 2 3 4 5
入力例 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
出力例 3
1 2 3
Score : 200 points
Problem Statement
People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0
or 1
.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0
and 1
, where the j-th character of S_i represents person i's vote content for the j-th vote.
In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:
- Suppose x people chose
0
and y people chose1
in that vote.- If x=0 or y=0, everyone receives 1 point for that vote.
- Otherwise, if x<y, only people who voted
0
in that vote receive 1 point. - Otherwise, only people who voted
1
in that vote receive 1 point. - Note that since N is odd, x=y never occurs.
After finishing M votes, find all people who have the highest total score from those votes.
Constraints
- N is an odd number satisfying 1 \le N \le 99.
- M is an integer satisfying 1 \le M \le 100.
- S_i is a string of length M consisting of
0
and1
.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Output all person numbers with the highest score in ascending order of person number, separated by spaces.
Sample Input 1
3 5 11100 10101 01110
Sample Output 1
2 3
In this case, three people conducted five votes.
- In the 1st vote, person 1 voted
1
, person 2 voted1
, person 3 voted0
. Thus, only person 3 receives 1 point. - In the 2nd vote, person 1 voted
1
, person 2 voted0
, person 3 voted1
. Thus, only person 2 receives 1 point. - In the 3rd vote, person 1 voted
1
, person 2 voted1
, person 3 voted1
. Thus, everyone receives 1 point. - In the 4th vote, person 1 voted
0
, person 2 voted0
, person 3 voted1
. Thus, only person 3 receives 1 point. - In the 5th vote, person 1 voted
0
, person 2 voted1
, person 3 voted0
. Thus, only person 2 receives 1 point.
As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.
Sample Input 2
5 4 0000 0000 0000 0000 0000
Sample Output 2
1 2 3 4 5
Sample Input 3
7 8 11010011 01000000 01111100 10111000 10011110 10100101 10010110
Sample Output 3
1 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
N 頂点の単純無向グラフ G があり、グラフの頂点には 1,2,\ldots, N の番号が付けられています。
G の隣接行列 (A_{i,j}) が与えられます。すなわち、G は A_{i,j} = 1 であるとき、またそのときに限り頂点 i と頂点 j を結ぶ辺を持ちます。
i = 1, 2, \ldots, N について、頂点 i と直接結ばれている頂点の番号を昇順に出力してください。
ただし、頂点 i と頂点 j が直接結ばれているとは、頂点 i と頂点 j を結ぶ辺が存在することをいいます。
制約
- 2 \leq N \leq 100
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 0
- A_{i,j} = A_{j,i}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_{1,1} A_{1,2} \ldots A_{1,N} A_{2,1} A_{2,2} \ldots A_{2,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N}
出力
N 行出力せよ。 i 行目には頂点 i と直接結ばれている頂点の番号を昇順に空白区切りで出力せよ。
入力例 1
4 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0
出力例 1
2 3 1 4 1 2
頂点 1 と直接結ばれている頂点は頂点 2, 3 です。したがって、1 行目には 2, 3 をこの順で出力します。
同様に、2 行目には 1, 4 をこの順に、3 行目には 1 を、4 行目には 2 を出力します。
入力例 2
2 0 0 0 0
出力例 2
G に辺が存在しないこともあります。
入力例 3
5 0 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 0
出力例 3
2 4 5 1 4 5 1 2 5 1 3 4
Score: 150 points
Problem Statement
There is a simple undirected graph G with N vertices labeled with numbers 1, 2, \ldots, N.
You are given the adjacency matrix (A_{i,j}) of G. That is, G has an edge connecting vertices i and j if and only if A_{i,j} = 1.
For each i = 1, 2, \ldots, N, print the numbers of the vertices directly connected to vertex i in ascending order.
Here, vertices i and j are said to be directly connected if and only if there is an edge connecting vertices i and j.
Constraints
- 2 \leq N \leq 100
- A_{i,j} \in \lbrace 0,1 \rbrace
- A_{i,i} = 0
- A_{i,j} = A_{j,i}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_{1,1} A_{1,2} \ldots A_{1,N} A_{2,1} A_{2,2} \ldots A_{2,N} \vdots A_{N,1} A_{N,2} \ldots A_{N,N}
Output
Print N lines. The i-th line should contain the numbers of the vertices directly connected to vertex i in ascending order, separated by a space.
Sample Input 1
4 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0
Sample Output 1
2 3 1 4 1 2
Vertex 1 is directly connected to vertices 2 and 3. Thus, the first line should contain 2 and 3 in this order.
Similarly, the second line should contain 1 and 4 in this order, the third line should contain 1, and the fourth line should contain 2.
Sample Input 2
2 0 0 0 0
Sample Output 2
G may have no edges.
Sample Input 3
5 0 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 0
Sample Output 3
2 4 5 1 4 5 1 2 5 1 3 4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は英小文字からなる文字列 T を青木君に向けて送りました。その結果、青木君は英小文字からなる文字列 T' を受信しました。
T' は T から一部が変更されてしまっている可能性があり、具体的には、下記の 4 つのうちのちょうど 1 つが成り立つことがわかっています。
- T' は、T と等しい。
- T' は、T のいずれか 1 つの位置(先頭と末尾も含む)に英小文字を 1 つ挿入して得られる文字列である。
- T' は、T からある 1 文字を削除して得られる文字列である。
- T' は、T のある 1 文字を別の英小文字に変更して得られる文字列である。
青木君が受信した文字列 T' と、英小文字からなる N 個の文字列 S_1, S_2, \ldots, S_N が入力として与えられるので、 S_1, S_2, \ldots, S_N のうち、高橋君が送った文字列 T と等しい可能性があるものをすべて求めてください。
制約
- N は整数
- 1 \leq N \leq 5 \times 10^5
- S_i と T' は英小文字からなる長さ 1 以上 5 \times 10^5 以下の文字列
- S_1, S_2, \ldots, S_N の長さの総和は 5 \times 10^5 以下
入力
入力は以下の形式で標準入力から与えられる。
N T' S_1 S_2 \vdots S_N
出力
S_1, S_2, \ldots, S_N のうち T と等しい可能性があるものすべての添字を昇順に並べた列を (i_1, i_2, \ldots, i_K) とする。 この列の長さ K および列自体を、下記の形式にしたがって出力せよ。
K i_1 i_2 \ldots i_K
入力例 1
5 ababc ababc babc abacbc abdbc abbac
出力例 1
4 1 2 3 4
S_1, S_2, \ldots, S_5 のうち、T と等しい可能性があるものは S_1, S_2, S_3, S_4 の 4 つであることが下記の通りわかります。
- S_1 は T と等しい可能性があります。なぜなら、T' =
ababc
は S_1 =ababc
と等しいからです。 - S_2 は T と等しい可能性があります。なぜなら、T' =
ababc
は S_2 =babc
の先頭に文字a
を挿入して得られる文字列だからです。 - S_3 は T と等しい可能性があります。なぜなら、T' =
ababc
は S_3 =abacbc
から 4 文字目のc
を削除して得られる文字列だからです。 - S_4 は T と等しい可能性があります。なぜなら、T' =
ababc
は S_4 =abdbc
の 3 文字目のd
をb
に変更して得られる文字列だからです。 - S_5 は T と等しい可能性はありません。なぜなら、S_5 =
abbac
を T としたとき、T' =ababc
は問題文中の 4 つの条件をいずれも満たさないからです。
入力例 2
1 aoki takahashi
出力例 2
0
入力例 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
出力例 3
6 1 2 4 7 8 9
Score : 300 points
Problem Statement
Takahashi sent a string T consisting of lowercase English letters to Aoki. As a result, Aoki received a string T' consisting of lowercase English letters.
T' may have been altered from T. Specifically, exactly one of the following four conditions is known to hold.
- T' is equal to T.
- T' is a string obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in T.
- T' is a string obtained by deleting one character from T.
- T' is a string obtained by changing one character in T to another lowercase English letter.
You are given the string T' received by Aoki and N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S_1, S_2, \ldots, S_N that could equal the string T sent by Takahashi.
Constraints
- N is an integer.
- 1 \leq N \leq 5 \times 10^5
- S_i and T' are strings of length between 1 and 5 \times 10^5, inclusive, consisting of lowercase English letters.
- The total length of S_1, S_2, \ldots, S_N is at most 5 \times 10^5.
Input
The input is given from Standard Input in the following format:
N T' S_1 S_2 \vdots S_N
Output
Let (i_1, i_2, \ldots, i_K) be the sequence of indices of all the strings among S_1, S_2, \ldots, S_N that could be equal to T, in ascending order. Print the length K of this sequence, and the sequence itself, in the following format:
K i_1 i_2 \ldots i_K
Sample Input 1
5 ababc ababc babc abacbc abdbc abbac
Sample Output 1
4 1 2 3 4
Among S_1, S_2, \ldots, S_5, the strings that could be equal to T are S_1, S_2, S_3, S_4, as explained below.
- S_1 could be equal to T, because T' =
ababc
is equal to S_1 =ababc
. - S_2 could be equal to T, because T' =
ababc
is obtained by inserting the lettera
at the beginning of S_2 =babc
. - S_3 could be equal to T, because T' =
ababc
is obtained by deleting the fourth characterc
from S_3 =abacbc
. - S_4 could be equal to T, because T' =
ababc
is obtained by changing the third characterd
in S_4 =abdbc
tob
. - S_5 could not be equal to T, because if we take S_5 =
abbac
as T, then T' =ababc
does not satisfy any of the four conditions in the problem statement.
Sample Input 2
1 aoki takahashi
Sample Output 2
0
Sample Input 3
9 atcoder atoder atcode athqcoder atcoder tacoder jttcoder atoder atceoder atcoer
Sample Output 3
6 1 2 4 7 8 9