実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
あなたはアイドルグループ Bit♡Beat のプロデューサーです。
Bit♡Beat の事務所に N 個のファンレターが届きました。 i 個目のファンレターは A_i 月 B_i 日に届いたものです。
これら N 個のファンレターの日付を早い順(1 月 1 日から始めて、先に訪れる順)に出力してください。
制約
- 1\le N\le 365
- A_i 月 B_i 日は平年(うるう年ではない年)において正しい日付である。
- (A_i , B_i) \neq (A_j , B_j) (i \neq j)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
N 行出力せよ。
i 行目 (1\le i\le N) には、届いた日付が i 番目に早いファンレターの日付の月と日を半角スペース区切りで出力せよ。
入力例 1
3 3 15 1 15 3 8
出力例 1
1 15 3 8 3 15
事務所には 3 月 15 日、 1 月 15 日、 3 月 8 日にファンレターが届きました。
これらの日付を早い順に並べると 1 月 15 日、 3 月 8 日、 3 月 15 日となります。したがって、上記のように出力してください。
入力例 2
5 1 1 1 2 1 3 1 4 1 5
出力例 2
1 1 1 2 1 3 1 4 1 5
入力例 3
10 9 21 8 22 10 28 6 22 6 26 7 10 5 3 8 31 9 4 11 21
出力例 3
5 3 6 22 6 26 7 10 8 22 8 31 9 4 9 21 10 28 11 21
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
初項が A、末項が B、公差が D であるような等差数列を出力してください。
なお、そのような等差数列が存在する入力のみが与えられます。
制約
- 1 \leq A \leq B \leq 100
- 1\leq D \leq 100
- 初項が A、末項が B、公差が D であるような等差数列が存在する
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
A B D
出力
初項が A、末項が B、公差が D であるような等差数列の項を順に空白区切りで出力せよ。
入力例 1
3 9 2
出力例 1
3 5 7 9
初項が 3、末項が 9、公差が 2 であるような等差数列は (3,5,7,9) です。
入力例 2
10 10 1
出力例 2
10
初項が 10、末項が 10、公差が 1 であるような等差数列は (10) です。
Score: 100 points
Problem Statement
Print an arithmetic sequence with first term A, last term B, and common difference D.
You are only given inputs for which such an arithmetic sequence exists.
Constraints
- 1 \leq A \leq B \leq 100
- 1 \leq D \leq 100
- There is an arithmetic sequence with first term A, last term B, and common difference D.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B D
Output
Print the terms of the arithmetic sequence with first term A, last term B, and common difference D, in order, separated by spaces.
Sample Input 1
3 9 2
Sample Output 1
3 5 7 9
The arithmetic sequence with first term 3, last term 9, and common difference 2 is (3,5,7,9).
Sample Input 2
10 10 1
Sample Output 2
10
The arithmetic sequence with first term 10, last term 10, and common difference 1 is (10).
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
H 行 W 列のグリッドがあり、はじめすべてのマスが白で塗られています。グリッドの上から i 行目、左から j 列目のマスを (i, j) と表記します。
このグリッドはトーラス状であるとみなします。すなわち、各 1 \leq i \leq H に対して (i, W) の右に (i, 1) があり、各 1 \leq j \leq W に対して (H, j) の下に (1, j) があるとします。
高橋君が (1, 1) にいて上を向いています。高橋君が以下の操作を N 回繰り返した後のグリッドの各マスがどの色で塗られているか出力してください。
- 現在いるマスが白で塗られている場合は、現在いるマスを黒に塗り替え、時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。そうでない場合は、現在いるマスを白に塗り替え、反時計回りに 90^\circ 回転し、向いている方向に 1 マス進む。
制約
- 1 \leq H, W \leq 100
- 1 \leq N \leq 1000
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W N
出力
H 行出力せよ。i 行目には長さ W の文字列であって、(i, j) が白で塗られている場合は j 文字目が .、黒で塗られている場合は j 文字目が # であるものを出力せよ。
入力例 1
3 4 5
出力例 1
.#.. ##.. ....
グリッドの各マスは操作によって以下のように変化します。
.... #... ##.. ##.. ##.. .#.. .... → .... → .... → .#.. → ##.. → ##.. .... .... .... .... .... ....
入力例 2
2 2 1000
出力例 2
.. ..
入力例 3
10 10 10
出力例 3
##........ ##........ .......... .......... .......... .......... .......... .......... .......... #........#
Score: 250 points
Problem Statement
There is a grid with H rows and W columns; initially, all cells are painted white. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left.
This grid is considered to be toroidal. That is, (i, 1) is to the right of (i, W) for each 1 \leq i \leq H, and (1, j) is below (H, j) for each 1 \leq j \leq W.
Takahashi is at (1, 1) and facing upwards. Print the color of each cell in the grid after Takahashi repeats the following operation N times.
- If the current cell is painted white, repaint it black, rotate 90^\circ clockwise, and move forward one cell in the direction he is facing. Otherwise, repaint the current cell white, rotate 90^\circ counterclockwise, and move forward one cell in the direction he is facing.
Constraints
- 1 \leq H, W \leq 100
- 1 \leq N \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W N
Output
Print H lines. The i-th line should contain a string of length W where the j-th character is . if the cell (i, j) is painted white, and # if it is painted black.
Sample Input 1
3 4 5
Sample Output 1
.#.. ##.. ....
The cells of the grid change as follows due to the operations:
.... #... ##.. ##.. ##.. .#.. .... → .... → .... → .#.. → ##.. → ##.. .... .... .... .... .... ....
Sample Input 2
2 2 1000
Sample Output 2
.. ..
Sample Input 3
10 10 10
Sample Output 3
##........ ##........ .......... .......... .......... .......... .......... .......... .......... #........#
実行時間制限: 2 sec / メモリ制限: 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
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
頂点に 1 から N の番号がついた N 頂点 M 辺の単純無向グラフが与えられます。i 番目の辺は頂点 u_i と頂点 v_i を結ぶ辺です。
グラフを森にするためには辺を最低何本削除する必要がありますか?
森とは
単純無向グラフ F が森であるとは、F が閉路を含まないことを言います。制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \left( \frac{N(N-1)}{2}, 2 \times 10^5\right)
- 1 \leq u_i \lt v_i \leq N
- 入力で与えられるグラフは単純
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
答えを出力せよ。
入力例 1
4 4 1 2 1 3 2 4 3 4
出力例 1
1
例えば 1 番目の辺を削除すると、グラフは森になります。
入力例 2
5 0
出力例 2
0
入力例 3
10 10 7 9 4 6 6 10 2 5 5 6 5 9 6 8 4 8 1 5 1 4
出力例 3
2
Score : 350 points
Problem Statement
You are given a simple undirected graph with N vertices and M edges, where the vertices are labeled 1 to N. The i-th edge connects vertices u_i and v_i.
What is the minimum number of edges that need to be deleted from this graph so that the graph becomes a forest?
What is a forest?
A simple undirected graph F is called a forest if and only if F does not contain any cycle.Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \left( \frac{N(N-1)}{2}, 2 \times 10^5\right)
- 1 \leq u_i < v_i \leq N
- The given graph is simple.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print the answer.
Sample Input 1
4 4 1 2 1 3 2 4 3 4
Sample Output 1
1
For example, if you delete the first edge, the graph becomes a forest.
Sample Input 2
5 0
Sample Output 2
0
Sample Input 3
10 10 7 9 4 6 6 10 2 5 5 6 5 9 6 8 4 8 1 5 1 4
Sample Output 3
2