Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力してください。
なお、相異なる 2 つの文字列 s = s_1 s_2 \ldots s_n と t = t_1 t_2 \ldots t_m について、それらが以下の条件のいずれかを満たすとき、辞書順で s \lt t であるとします。
- ある整数 i\ (1 \leq i \leq \min(n,m)) が存在し、s_i \lt t_i かつすべての整数 j\ (1 \leq j \lt i) について s_j=t_j
- すべての整数 i\ (1 \leq i \leq \min(n,m)) について s_i = t_i かつ、n \lt m
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力せよ。
入力例 1
aba
出力例 1
aab
S= aba
を並び替えて得られる文字列は以下の 3 つが考えられます。
aba
aab
baa
この中で辞書順で最小のものは、aab
です。
入力例 2
zzzz
出力例 2
zzzz
Score : 200 points
Problem Statement
You are given a string S. Find the lexicographically smallest string S' obtained by permuting the characters of S.
Here, for different two strings s = s_1 s_2 \ldots s_n and t = t_1 t_2 \ldots t_m, s \lt t holds lexicographically when one of the conditions below is satisfied.
- There is an integer i\ (1 \leq i \leq \min(n,m)) such that s_i \lt t_i and s_j=t_j for all integers j\ (1 \leq j \lt i).
- s_i = t_i for all integers i\ (1 \leq i \leq \min(n,m)), and n \lt m.
Constraints
- S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the lexicographically smallest string S' obtained by permuting the characters in S.
Sample Input 1
aba
Sample Output 1
aab
Three strings can be obtained by permuting aba
:
aba
aab
baa
The lexicographically smallest among them is aab
.
Sample Input 2
zzzz
Sample Output 2
zzzz
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。
S の中に A
, B
, C
がこの順に等間隔に並んでいる場所が何箇所あるか求めてください。
厳密には、3 つの整数の組 (i,j,k) であって、以下の条件をすべて満たすものの個数を求めてください。 ここで、|S| で S の長さを、S_x で S の x 文字目を表すものとします。
- 1\leq i<j<k\leq |S|
- j-i = k-j
- S_i=
A
- S_j=
B
- S_k=
C
制約
- S は英大文字からなる長さ 3 以上 100 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
AABCC
出力例 1
2
(i,j,k)=(1,3,5),(2,3,4) の 2 つの組が条件を満たします。
入力例 2
ARC
出力例 2
0
入力例 3
AABAAABBAEDCCCD
出力例 3
4
Score : 200 points
Problem Statement
A string S is given.
Find how many places in S have A
, B
, and C
in this order at even intervals.
Specifically, find the number of triples of integers (i,j,k) that satisfy all of the following conditions. Here, |S| denotes the length of S, and S_x denotes the x-th character of S.
- 1 \leq i < j < k \leq |S|
- j - i = k - j
- S_i =
A
- S_j =
B
- S_k =
C
Constraints
- S is an uppercase English string with length between 3 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
AABCC
Sample Output 1
2
There are two triples (i,j,k) = (1,3,5) and (2,3,4) that satisfy the conditions.
Sample Input 2
ARC
Sample Output 2
0
Sample Input 3
AABAAABBAEDCCCD
Sample Output 3
4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。
N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
- S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X 個 (X>0) 存在するならば、X を文字列として扱って S_i+
(
+X+)
を出力する。
制約
- 1 \leq N \leq 2\times 10^5
- S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
問題文中の指示にしたがって、N 行出力せよ。
入力例 1
5 newfile newfile newfolder newfile newfolder
出力例 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
入力例 2
11 a a a a a a a a a a a
出力例 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Score : 300 points
Problem Statement
For two strings A and B, let A+B denote the concatenation of A and B in this order.
You are given N strings S_1,\ldots,S_N. Modify and print them as follows, in the order i=1, \ldots, N:
- if none of S_1,\ldots,S_{i-1} is equal to S_i, print S_i;
- if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i, print S_i+
(
+X+)
, treating X as a string.
Constraints
- 1 \leq N \leq 2\times 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines as specified in the Problem Statement.
Sample Input 1
5 newfile newfile newfolder newfile newfolder
Sample Output 1
newfile newfile(1) newfolder newfile(2) newfolder(1)
Sample Input 2
11 a a a a a a a a a a a
Sample Output 2
a a(1) a(2) a(3) a(4) a(5) a(6) a(7) a(8) a(9) a(10)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
9\times 9 のマス目 A があり、各マスには 1 以上 9 以下の整数が書き込まれています。
具体的には、 A の上から i 行目、左から j 列目のマスには A_{i,j} が書き込まれています。
A が次の条件をすべてみたしているならば Yes
を、そうでないならば No
を出力してください。
- A の各行について、その行に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の各列について、その列に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の行を上から 3 行ずつ 3 つに分け、同様に列も左から 3 列ずつ 3 つに分ける。 これによって A を 9 つの 3\times 3 のマス目に分けたとき、それぞれの 3\times 3 のマス目には 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
制約
- 1\leq A_{i,j}\leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
出力
マス目 A が問題文の条件をすべてみたすならば Yes
を、
そうでないならば No
を出力せよ。
入力例 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
出力例 1
Yes
マス目 A は次のようになっています。
マス目 A は 3 つの条件をすべてみたしているため、Yes
を出力します。
入力例 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
出力例 2
No
マス目 A は次のようになっています。
例えば左上の 3\times 3 のマス目に注目すると 3 つめの条件をみたしていないことが分かるため、No
を出力します。
入力例 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
出力例 3
No
マス目 A は次のようになっています。
例えば一番左の列に注目すると 2 つめの条件をみたしていないことが分かるため、No
を出力します。
Score : 250 points
Problem Statement
There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.
If A satisfies all of the following conditions, print Yes
. Otherwise, print No
.
- For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
- For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
- Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.
Constraints
- 1\leq A_{i,j}\leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} \ldots A_{1,9} A_{2,1} A_{2,2} \ldots A_{2,9} \vdots A_{9,1} A_{9,2} \ldots A_{9,9}
Output
If the grid A satisfies all the conditions in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
Sample Output 1
Yes
The grid A is shown below.
The grid A satisfies all three conditions, so print Yes
.
Sample Input 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
Sample Output 2
No
The grid A is shown below.
For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No
.
Sample Input 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
Sample Output 3
No
The grid A is shown below.
For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No
.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
両面に整数が書かれたカードが N 枚あり、i \, (1 \leq i \leq N) 枚目のカードの表には a_i が、裏には b_i が書かれています。
あなたは、それぞれのカードについて、表を上に向けて置くか裏を上に向けて置くかを自由に決めることができます。
上に向けられた面に書かれた整数の総和がちょうど S となるようにカードを置くことができるか判定し、可能ならそのようなカードの置き方の一例を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq S \leq 10000
- 1 \leq a_i, b_i \leq 100 \, (1 \leq i \leq N)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N S a_1 b_1 \vdots a_N b_N
出力
まず、上に向けられた面に書かれた整数の総和がちょうど S となるようにカードを置くことができるならば Yes
を、できなければ No
を出力し、改行せよ。
さらに、そのようにカードを置くことができるならば、カードの置き方を表す H
および T
のみからなる長さ N の文字列を出力せよ。
この文字列の i \, (1 \leq i \leq N) 文字目は、i 枚目のカードを表を上に向けて置くなら H
、裏を上に向けて置くなら T
でなければならない。
条件を満たすカードの置き方が複数考えられる場合、どれを出力しても正解となる。
入力例 1
3 11 1 4 2 3 5 7
出力例 1
Yes THH
例えば次のように置くことで、上に向けられた面に書かれた整数の総和がちょうど S (= 11) となります。
- 1 枚目は表、2 枚目は裏、3 枚目は裏を上に向けて置く。
- 1 枚目は裏、2 枚目は表、3 枚目は表を上に向けて置く。
よって、HTT
や THH
といった出力が正解となります。
入力例 2
5 25 2 8 9 3 4 11 5 1 12 6
出力例 2
No
上に向けられた面に書かれた整数の総和がちょうど S (= 25) となるようにカードを置くことはできません。
Score : 400 points
Problem Statement
There are N cards with an integer written on each side. Card i (1 \leq i \leq N) has an integer a_i written on the front and an integer b_i written on the back.
You may choose whether to place each card with its front or back side visible.
Determine if you can place the cards so that the sum of the visible integers exactly equals S. If possible, find a placement of the cards to realize it.
Constraints
- 1 \leq N \leq 100
- 1 \leq S \leq 10000
- 1 \leq a_i, b_i \leq 100 \, (1 \leq i \leq N)
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N S a_1 b_1 \vdots a_N b_N
Output
First, print Yes
if you can make the sum of the visible integers exactly equal S, and No
otherwise, followed by a newline.
Additionally, if such a placement is possible, print a string of length N consisting of H
and T
that represents the placement of the cards to realize it.
The i-th (1 \leq i \leq N) character should be H
if the i-th card should be placed with its front side visible, and T
with its back.
If there are multiple possible placements to realize the sum, printing any of them is accepted.
Sample Input 1
3 11 1 4 2 3 5 7
Sample Output 1
Yes THH
For example, the following placements make the sum of the visible integers exactly equal S (= 11):
- Place the 1-st card with its front side visible, 2-nd with its back, and 3-rd with its back.
- Place the 1-st card with its back side visible, 2-nd with its front, and 3-rd with its front.
Therefore, outputs like HTT
and THH
are accepted.
Sample Input 2
5 25 2 8 9 3 4 11 5 1 12 6
Sample Output 2
No
You cannot place the cards so that the sum of the visible integers exactly equals S (= 25).