Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は N 週間の間、自分が歩いた歩数を記録しました。i 日目に歩いた歩数は A_i でした。
各週に高橋君が歩いた歩数の合計を求めてください。
より正確には、1 週目( 1 日目から 7 日目まで)の 7 日間の歩数の合計、2 週目( 8 日目から 14 日目まで)の 7 日間の歩数の合計、……をそれぞれ求めてください。
制約
- 1 \leq N \leq 10
- 0 \leq A_i \leq 10^5
- 入力は整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \ldots A_{7N}
出力
i 週目に歩いた歩数を B_i とする。B_1,B_2,\ldots,B_N をこの順に空白区切りで出力せよ。
入力例 1
2 1000 2000 3000 4000 5000 6000 7000 2000 3000 4000 5000 6000 7000 8000
出力例 1
28000 35000
高橋君は 1 週目に 1000+2000+3000+4000+5000+6000+7000=28000 歩あるき、2 週目に 2000+3000+4000+5000+6000+7000+8000=35000 歩あるきました。
入力例 2
3 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 6286 20899 86280 34825 34211 70679 82148
出力例 2
314333 419427 335328
Score : 100 points
Problem Statement
Takahashi has recorded the number of steps he walked for N weeks. He walked A_i steps on the i-th day.
Find the total number of steps Takahashi walked each week.
More precisely, find the sum of the steps for the first week (the 1-st through 7-th day), the sum of the steps for the second week (the 8-th through 14-th day), and so on.
Constraints
- 1 \leq N \leq 10
- 0 \leq A_i \leq 10^5
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_{7N}
Output
Let B_i be the number of steps walked for the i-th week. Print B_1,B_2,\ldots,B_N in this order, separated by spaces.
Sample Input 1
2 1000 2000 3000 4000 5000 6000 7000 2000 3000 4000 5000 6000 7000 8000
Sample Output 1
28000 35000
For the first week, he walked 1000+2000+3000+4000+5000+6000+7000=28000 steps, and for the second week, he walked 2000+3000+4000+5000+6000+7000+8000=35000 steps.
Sample Input 2
3 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 6286 20899 86280 34825 34211 70679 82148
Sample Output 2
314333 419427 335328
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君は N 歳の誕生日を迎えました。この時の彼の身長は T cmです。
また、以下のことが分かっています。
- 高橋君は 0 歳の誕生日(生まれた当日)から X 歳の誕生日までの間、毎年身長が D cmずつ伸びた。より厳密に書くと、i=1,2,\ldots,X それぞれに対し、i-1 歳の誕生日から i 歳の誕生日までの間に身長が D cm伸びた。
- 高橋君は X 歳の誕生日から N 歳の誕生日までの間、身長が変化していない。
高橋君の M 歳の誕生日の時の身長が何cmだったかを求めてください。
制約
- 0 \leq M \lt N \leq 100
- 1 \leq X \leq N
- 1 \leq T \leq 200
- 1 \leq D \leq 100
- 高橋君の 0 歳の誕生日の時の身長は 1 cm以上である
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M X T D
出力
答えを整数として出力せよ。
入力例 1
38 20 17 168 3
出力例 1
168
この例では、高橋君の 38 歳の誕生日の時の身長が 168 cmです。また、17 歳の誕生日から 38 歳の誕生日までの間、身長が変化していません。
このことから、20 歳の誕生日の時の身長は 168 cmだったと言え、これが答えになります。
入力例 2
1 0 1 3 2
出力例 2
1
この例において、高橋君は 0(=M) 歳の誕生日の時の身長が 1 cmで、1(=N) 歳の誕生日の時の身長が 3(=T) cmです。
入力例 3
100 10 100 180 1
出力例 3
90
Score : 100 points
Problem Statement
Takahashi had his N-th birthday, when he was T centimeters tall.
Additionally, we know the following facts:
- In each year between Takahashi's birth (0-th birthday) and his X-th birthday, his height increased by D centimeters. More formally, for each i = 1, 2, \ldots, X, his height increased by D centimeters between his (i-1)-th birthday and his i-th birthday.
- Between Takahashi's X-th birthday and his N-th birthday, his height did not change.
Find Takahashi's height on his M-th birthday, in centimeters.
Constraints
- 0 \leq M \lt N \leq 100
- 1 \leq X \leq N
- 1 \leq T \leq 200
- 1 \leq D \leq 100
- Takahashi was at least 1 centimeter tall at his birth.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M X T D
Output
Print the answer as an integer.
Sample Input 1
38 20 17 168 3
Sample Output 1
168
In this sample, Takahashi was 168 centimeters tall on his 38-th birthday. Also, his height did not change between his 17-th birthday and 38-th birthday.
From these facts, we find that he was 168 centimeters tall on his 20-th birthday, so the answer is 168.
Sample Input 2
1 0 1 3 2
Sample Output 2
1
In this sample, Takahashi was 1 centimeter tall on his 0(=M)-th birthday and 3(=T) centimeters tall on his 1(=N)-st birthday.
Sample Input 3
100 10 100 180 1
Sample Output 3
90
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
人 1 、人 2 、\ldots 、人 N の N 人の人がルーレットの賭けに参加しました。 このルーレットの出目は、0 から 36 までの 37 個の整数のうちいずれかです。 i = 1, 2, \ldots, N について、人 i は 37 個の目のうち C_i 個の目 A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} に賭けました。
ルーレットが回され、出目は X でした。 X に賭けた人たちのうち、賭けた目の個数が最も少ない人たちの番号を昇順にすべて出力してください。
より形式的には、1 以上 N 以下の整数 i であって、下記の 2 つの条件をともに満たすものを昇順にすべて出力してください。
- 人 i は X に賭けている。
- 任意の j = 1, 2, \ldots, N について「人 j が X に賭けているならば、C_i \leq C_j 」が成り立つ。
出力するべき番号が 1 つも無い場合もあることに注意してください(入力例2を参照)。
制約
- 1 \leq N \leq 100
- 1 \leq C_i \leq 37
- 0 \leq A_{i, j} \leq 36
- 任意の i = 1, 2, \ldots, N について、A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} はすべて異なる。
- 0 \leq X \leq 36
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
C_1
A_{1, 1} A_{1, 2} \ldots A_{1, C_1}
C_2
A_{2, 1} A_{2, 2} \ldots A_{2, C_2}
\vdots
C_N
A_{N, 1} A_{N, 2} \ldots A_{N, C_N}
X
出力
出力するべき番号を昇順にすベて並べた列を、B_1, B_2, \ldots, B_K とする。 下記の形式にしたがい、1 行目には出力するべき番号の個数 K を、 2 行目には B_1, B_2, \ldots, B_K を空白区切りで、それぞれ出力せよ。
K B_1 B_2 \ldots B_K
入力例 1
4 3 7 19 20 4 4 19 24 0 2 26 10 3 19 31 24 19
出力例 1
2 1 4
ルーレットが回され、出目は 19 でした。 19 に賭けた人は人 1 、人 2 、人 4 の 3 人であり、それぞれが賭けた目の個数は 3, 4, 3 です。 よって、19 に賭けた人のうち、賭けた目の個数が最も少ない人は人 1 と人 4 の 2 人です。
入力例 2
3 1 1 1 2 1 3 0
出力例 2
0
ルーレットが回され出目は 0 でしたが、0 に賭けた人は一人もいないため、 出力するべき番号は 1 つもありません。
Score : 200 points
Problem Statement
N people, person 1, person 2, \ldots, person N, are playing roulette. The outcome of a spin is one of the 37 integers from 0 to 36. For each i = 1, 2, \ldots, N, person i has bet on C_i of the 37 possible outcomes: A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}.
The wheel has been spun, and the outcome is X. Print the numbers of all people who have bet on X with the fewest bets, in ascending order.
More formally, print all integers i between 1 and N, inclusive, that satisfy both of the following conditions, in ascending order:
- Person i has bet on X.
- For each j = 1, 2, \ldots, N, if person j has bet on X, then C_i \leq C_j.
Note that there may be no number to print (see Sample Input 2).
Constraints
- 1 \leq N \leq 100
- 1 \leq C_i \leq 37
- 0 \leq A_{i, j} \leq 36
- A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} are all different for each i = 1, 2, \ldots, N.
- 0 \leq X \leq 36
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
C_1
A_{1, 1} A_{1, 2} \ldots A_{1, C_1}
C_2
A_{2, 1} A_{2, 2} \ldots A_{2, C_2}
\vdots
C_N
A_{N, 1} A_{N, 2} \ldots A_{N, C_N}
X
Output
Let B_1, B_2, \ldots, B_K be the sequence of numbers to be printed in ascending order. Using the following format, print the count of numbers to be printed, K, on the first line, and B_1, B_2, \ldots, B_K separated by spaces on the second line:
K B_1 B_2 \ldots B_K
Sample Input 1
4 3 7 19 20 4 4 19 24 0 2 26 10 3 19 31 24 19
Sample Output 1
2 1 4
The wheel has been spun, and the outcome is 19. The people who has bet on 19 are person 1, person 2, and person 4, and the number of their bets are 3, 4, and 3, respectively. Therefore, among the people who has bet on 19, the ones with the fewest bets are person 1 and person 4.
Sample Input 2
3 1 1 1 2 1 3 0
Sample Output 2
0
The wheel has been spun and the outcome is 0, but no one has bet on 0, so there is no number to print.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は漢文の勉強をしていて、漢字を読む順番が分からず困っています。高橋君を助けましょう!
1 から N までの N 個の整数が小さい方から順に 1 列に並んでいます。
整数の間に M 個の「レ」が挟まっています。i 個目の「レ」は、整数 a_i と整数 a_i + 1 の間にあります。
あなたは次の手順に従って、N 個の整数を 1 回ずつ全て読みます。
- まず、頂点に 1 から N までの番号がついた N 頂点 M 辺の無向グラフ G を考える。i 本目の辺は頂点 a_i と頂点 a_i + 1 を結んでいる。
- そして、読まれていない整数が無くなるまで次の操作を繰り返す。
- 読まれていない整数のうち最小のものを x とする。頂点 x が含まれる連結成分 C を選び、C に含まれる頂点の番号を大きい方から順に全て読む。
例えば、整数と「レ」が

という順番で並んでいる場合を考えます。(この場合 N = 5, M = 3, a = (1, 3, 4) です。)
このとき、整数が読まれる順番は以下の手順によって 2, 1, 5, 4, 3 に決定します。
- 最初、読まれていない整数のうち最小のものは 1 であり、グラフ G の頂点 1 を含む連結成分に含まれる頂点は \lbrace 1, 2 \rbrace である。よって 2, 1 がこの順で読まれる。
- 次に、読まれていない整数のうち最小のものは 3 であり、グラフ G の頂点 3 を含む連結成分に含まれる頂点は \lbrace 3, 4, 5 \rbrace である。よって 5, 4, 3 がこの順で読まれる。
- すべての整数が読まれたので手順を終了する。
N, M, (a_1, a_2, \dots, a_M) が入力として与えられるので、 N 個の整数を読む順番を出力してください。
連結成分とは
あるグラフの 部分グラフ とは、元のグラフのいくつかの頂点といくつかの辺を選んでできるグラフのことをいいます。グラフが 連結 であるとは、グラフに含まれるすべての頂点同士が辺を経由して互いに行き来できることをいいます。
連結成分 とは、連結な部分グラフのうち、そのグラフを含んだより大きい連結な部分グラフが存在しないものをいいます。
制約
- 1 \leq N \leq 100
- 0 \leq M \leq N - 1
- 1 \leq a_1 \lt a_2 \lt \dots \lt a_M \leq N-1
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M a_1 a_2 \dots a_M
出力
答えを以下の形式で出力せよ。ここで p_i は、i 番目に読まれる整数を意味する。
p_1 p_2 \dots p_N
入力例 1
5 3 1 3 4
出力例 1
2 1 5 4 3
問題文の例にある通り、整数と「レ」が

という順で並んでいる場合は 2, 1, 5, 4, 3 の順で読みます。
入力例 2
5 0
出力例 2
1 2 3 4 5
「レ」が存在しない場合もあります。
入力例 3
10 6 1 2 3 7 8 9
出力例 3
4 3 2 1 5 6 10 9 8 7
Score : 200 points
Problem Statement
Studying Kanbun, Takahashi is having trouble figuring out the order to read words. Help him out!
There are N integers from 1 through N arranged in a line in ascending order.
Between them are M "レ" marks. The i-th "レ" mark is between the integer a_i and integer (a_i + 1).
You read each of the N integers once by the following procedure.
- Consider an undirected graph G with N vertices numbered 1 through N and M edges. The i-th edge connects vertex a_i and vertex (a_i+1).
- Repeat the following operation until there is no unread integer:
- let x be the minimum unread integer. Choose the connected component C containing vertex x, and read all the numbers of the vertices contained in C in descending order.
For example, suppose that integers and "レ" marks are arranged in the following order:

(In this case, N = 5, M = 3, and a = (1, 3, 4).)
Then, the order to read the integers is determined to be 2, 1, 5, 4, and 3, as follows:
- At first, the minimum unread integer is 1, and the connected component of G containing vertex 1 has vertices \lbrace 1, 2 \rbrace, so 2 and 1 are read in this order.
- Then, the minimum unread integer is 3, and the connected component of G containing vertex 3 has vertices \lbrace 3, 4, 5 \rbrace, so 5, 4, and 3 are read in this order.
- Now that all integers are read, terminate the procedure.
Given N, M, and (a_1, a_2, \dots, a_M), print the order to read the N integers.
What is a connected component?
A subgraph of a graph is a graph obtained by choosing some vertices and edges from the original graph.A graph is said to be connected if and only if one can travel between any two vertices in the graph via edges.
A connected component is a connected subgraph that is not contained in any larger connected subgraph.
Constraints
- 1 \leq N \leq 100
- 0 \leq M \leq N - 1
- 1 \leq a_1 \lt a_2 \lt \dots \lt a_M \leq N-1
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M a_1 a_2 \dots a_M
Output
Print the answer in the following format, where p_i is the i-th integers to read.
p_1 p_2 \dots p_N
Sample Input 1
5 3 1 3 4
Sample Output 1
2 1 5 4 3
As described in the Problem Statement, if integers and "レ" marks are arranged in the following order:

then the integers are read in the following order: 2, 1, 5, 4, and 3.
Sample Input 2
5 0
Sample Output 2
1 2 3 4 5
There may be no "レ" mark.
Sample Input 3
10 6 1 2 3 7 8 9
Sample Output 3
4 3 2 1 5 6 10 9 8 7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
上下左右に広がる N\times N のマス目があり、最初全てのマスは白く塗られています。このマス目の上から i 行目、左から j 列目のマスを (i,j) で表します。
高橋君は 1 以上 N 以下の整数 A, B を持っており、次のような操作を行います。
- \max(1-A,1-B)\leq k\leq \min(N-A,N-B) をみたす全ての整数 k について、(A+k,B+k) を黒く塗る。
- \max(1-A,B-N)\leq k\leq \min(N-A,B-1) をみたす全ての整数 k について、(A+k,B-k) を黒く塗る。
この操作を行った後のマス目について、P\leq i\leq Q かつ R\leq j\leq S をみたす各マス (i,j) がそれぞれ何色で塗られているか求めてください。
制約
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A B P Q R S
出力
Q-P+1 行出力せよ。
各行は # と . のみからなる長さ S-R+1 の文字列であり、
i 行目の文字列の j 番目の文字が
# であることは (P+i-1,R+j-1) が黒く塗られていることを、
. であることは (P+i-1,R+j-1) が白く塗られていることをさす。
入力例 1
5 3 2 1 5 1 5
出力例 1
...#. #.#.. .#... #.#.. ...#.
1 つめの操作で (2,1), (3,2), (4,3), (5,4) の 4 マスが、
2 つめの操作で (4,1), (3,2), (2,3), (1,4) の 4 マスが黒く塗られます。
よって、P=1, Q=5, R=1, S=5 より、上のように出力します。
入力例 2
5 3 3 4 5 2 5
出力例 2
#.#. ...#
操作によって、
(1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5) の 9 マスが
黒く塗られます。
P=4, Q=5, R=2, S=5 より、上のように出力します。
入力例 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
出力例 3
#.# .#. #.#
入力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 300 points
Problem Statement
There is an N\times N grid with horizontal rows and vertical columns, where all squares are initially painted white. Let (i,j) denote the square at the i-th row and j-th column.
Takahashi has integers A and B, which are between 1 and N (inclusive). He will do the following operations.
- For every integer k such that \max(1-A,1-B)\leq k\leq \min(N-A,N-B), paint (A+k,B+k) black.
- For every integer k such that \max(1-A,B-N)\leq k\leq \min(N-A,B-1), paint (A+k,B-k) black.
In the grid after these operations, find the color of each square (i,j) such that P\leq i\leq Q and R\leq j\leq S.
Constraints
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B P Q R S
Output
Print Q-P+1 lines.
Each line should contain a string of length S-R+1 consisting of # and ..
The j-th character of the string in the i-th line should be # to represent that (P+i-1, R+j-1) is painted black, and . to represent that (P+i-1, R+j-1) is white.
Sample Input 1
5 3 2 1 5 1 5
Sample Output 1
...#. #.#.. .#... #.#.. ...#.
The first operation paints the four squares (2,1), (3,2), (4,3), (5,4) black, and the second paints the four squares (4,1), (3,2), (2,3), (1,4) black.
Thus, the above output should be printed, since P=1, Q=5, R=1, S=5.
Sample Input 2
5 3 3 4 5 2 5
Sample Output 2
#.#. ...#
The operations paint the nine squares (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5).
Thus, the above output should be printed, since P=4, Q=5, R=2, S=5.
Sample Input 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
Sample Output 3
#.# .#. #.#
Note that the input may not fit into a 32-bit integer type.