Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
英小文字のみからなる長さ 3 の文字列 S が与えられます。
S の各文字を並び替えて得られる文字列は、何種類ありますか?
制約
- S は英小文字のみからなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えて得られる文字列の種類数を出力せよ。
入力例 1
aba
出力例 1
3
S= aba の各文字を並び替えて得られる文字列は、aab, aba, baa の 3 通りです。
入力例 2
ccc
出力例 2
1
S= ccc の各文字を並び替えて得られる文字列は、ccc の 1 通りのみです。
入力例 3
xyz
出力例 3
6
S= xyz の各文字を並び替えて得られる文字列は、xyz, xzy, yxz, yzx, zxy, zyx の 6 通りです。
Score : 100 points
Problem Statement
You are given a string S of length 3 consisting of lowercase English letters.
How many different strings can be obtained by permuting the characters in S?
Constraints
- S is a string S of length 3 consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of different strings that can be obtained by permuting the characters in S.
Sample Input 1
aba
Sample Output 1
3
By permuting the characters in S= aba, three different strings can be obtained: aab, aba, baa.
Sample Input 2
ccc
Sample Output 2
1
By permuting the characters in S= ccc, just one string can be obtained: ccc.
Sample Input 3
xyz
Sample Output 3
6
By permuting the characters in S= xyz, six different strings can be obtained: xyz, xzy, yxz, yzx, zxy, zyx.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 以上 9 以下の整数 N が入力として与えられます。
数字 N を N 個繋げて得られる文字列を出力してください。
制約
- N は 1 以上 9 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
333
3 を 3 個繋げて得られる文字列は 333 です。
入力例 2
9
出力例 2
999999999
Score : 100 points
Problem Statement
You are given an integer N between 1 and 9, inclusive, as input.
Concatenate N copies of the digit N and print the resulting string.
Constraints
- N is an integer between 1 and 9, inclusive.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
333
Concatenate three copies of the digit 3 to yield the string 333.
Sample Input 2
9
Sample Output 2
999999999
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英大文字と英小文字からなる文字列のうち、以下の条件を全て満たすものを素晴らしい文字列ということとします。
- 英大文字が文字列の中に現れる。
- 英小文字が文字列の中に現れる。
- 全ての文字が相異なる。
例えば、AtCoder や Aa は素晴らしい文字列ですが、atcoder や Perfect は素晴らしい文字列ではありません。
文字列 S が与えられるので、S が素晴らしい文字列か判定してください。
制約
- 1 \le |S| \le 100
- S は英大文字と英小文字からなる文字列である。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が素晴らしい文字列ならば Yes を、そうでないならば No を出力せよ。
入力例 1
AtCoder
出力例 1
Yes
AtCoder は、英大文字が含まれ、英小文字も含まれ、かつ全ての文字が相異なるため素晴らしい文字列です。
入力例 2
Aa
出力例 2
Yes
A と a は違う文字であることに注意してください。この文字列は素晴らしい文字列です。
入力例 3
atcoder
出力例 3
No
英大文字が含まれていないため、素晴らしい文字列ではありません。
入力例 4
Perfect
出力例 4
No
2 文字目と 5 文字目が等しいため、素晴らしい文字列ではありません。
Score : 200 points
Problem Statement
Let us call a string consisting of uppercase and lowercase English alphabets a wonderful string if all of the following conditions are satisfied:
- The string contains an uppercase English alphabet.
- The string contains a lowercase English alphabet.
- All characters in the string are pairwise distinct.
For example, AtCoder and Aa are wonderful strings, while atcoder and Perfect are not.
Given a string S, determine if S is a wonderful string.
Constraints
- 1 \le |S| \le 100
- S is a string consisting of uppercase and lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
S
Output
If S is a wonderful string, print Yes; otherwise, print No.
Sample Input 1
AtCoder
Sample Output 1
Yes
AtCoder is a wonderful string because it contains an uppercase English alphabet, a lowercase English alphabet, and all characters in the string are pairwise distinct.
Sample Input 2
Aa
Sample Output 2
Yes
Note that A and a are different characters. This string is a wonderful string.
Sample Input 3
atcoder
Sample Output 3
No
It is not a wonderful string because it does not contain an uppercase English alphabet.
Sample Input 4
Perfect
Sample Output 4
No
It is not a wonderful string because the 2-nd and the 5-th characters are the same.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は chess960 と呼ばれるゲームで遊んでいます。 高橋君はランダムに決めた初期配置が chess960 の条件を満たすか確認するプログラムを書くことにしました。
長さ 8 の文字列 S が与えられます。S には K, Q がちょうど 1 文字ずつ、R, B, N がちょうど 2 文字ずつ含まれます。 S が以下の条件を全て満たしているか判定してください。
-
S において左から x,y\ (x < y) 文字目が
Bであるとする。このとき x と y の偶奇が異なる。 -
Kは 2 つのRの間にある。より形式的には、S において左から x,y\ (x < y) 文字目がRであり、 z 文字目がKであるとする。このとき、 x< z < y が成り立つ。
制約
- S は 長さ 8 の文字列であり、
K,Qがちょうど 1 文字ずつ、R,B,Nがちょうど 2 文字ずつ含まれる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が条件を満たす場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
RNBQKBNR
出力例 1
Yes
B は左から 3 番目、6 番目にあり、3 と 6 は偶奇が異なります。
また、K は 2 つの R の間にあります。よって条件を満たします。
入力例 2
KRRBBNNQ
出力例 2
No
K は 2 つの R の間にありません。
入力例 3
BRKRBQNN
出力例 3
No
Score : 200 points
Problem Statement
Takahashi is playing a game called Chess960. He has decided to write a code that determines if a random initial state satisfies the conditions of Chess960.
You are given a string S of length eight. S has exactly one K and Q, and exactly two R's, B's , and N's. Determine if S satisfies all of the following conditions.
-
Suppose that the x-th and y-th (x < y) characters from the left of S are
B; then, x and y have different parities. -
Kis between twoR's. More formally, suppose that the x-th and y-th (x < y) characters from the left of S areRand the z-th isK; then x< z < y.
Constraints
- S is a string of length 8 that contains exactly one
KandQ, and exactly twoR's,B's , andN's.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S satisfies the conditions; print No otherwise.
Sample Input 1
RNBQKBNR
Sample Output 1
Yes
The 3-rd and 6-th characters are B, and 3 and 6 have different parities.
Also, K is between the two R's. Thus, the conditions are fulfilled.
Sample Input 2
KRRBBNNQ
Sample Output 2
No
K is not between the two R's.
Sample Input 3
BRKRBQNN
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder 社はロゴ入りの T シャツを販売しています。
高橋君の N 日間の予定が 0, 1, 2 のみからなる長さ N の文字列 S で与えられます。
具体的には、1\leq i\leq N をみたす整数 i について、
- S の i 文字目が
0のとき、i 日目に何の予定も入っていません。 - S の i 文字目が
1のとき、i 日目に高橋君は食事に行く予定があります。 - S の i 文字目が
2のとき、i 日目に高橋君は競技プログラミングのイベントに行く予定が入っています。
高橋君は無地の T シャツを M 枚持っており、1 日目の直前の時点ですべて洗濯済みの状態となっています。
これに加えて、次の条件をみたすように行動できるように、高橋君は AtCoder のロゴ入りの T シャツを何枚か購入する事にしました。
- 食事に行く日には、無地の T シャツ 1 枚またはロゴ入りの T シャツ 1 枚を着用する。
- 競技プログラミングのイベントに行く日にはロゴ入りの T シャツ 1 枚を着用する。
- 何の予定もない日には T シャツを着用しない。加えて、その時点で着用済みの T シャツを全て洗濯する。 洗濯した T シャツは翌日から着用できる。
- 一度着用した T シャツは次に洗濯するまで着用できない。
N 日間のうち予定が入っている日すべてについて、条件をみたす T シャツを着用できるようにするために、高橋君は最低何枚のTシャツを購入する必要があるか求めてください。
新しく T シャツを購入する必要がないならば 0 を出力してください。
ただし、購入した T シャツも 1 日目の直前の時点ですべて洗濯済みの状態で存在するものとします。
制約
- 1\leq M\leq N\leq 1000
- S は
0,1,2のみからなる長さ N の文字列 - N,M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M S
出力
問題文の条件をみたすように行動するために
高橋君が購入する必要のある T シャツの枚数の最小値を出力せよ。
新しく購入する必要がないならば 0 を出力せよ。
入力例 1
6 1 112022
出力例 1
2
高橋君がロゴ入りの T シャツを 2 枚購入したとき、次のようにして高橋君は T シャツを着用することができます。
- 1 日目、高橋君はロゴ入りの T シャツを着用して食事に行きます。
- 2 日目、高橋君は無地の T シャツを着用して食事に行きます。
- 3 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
- 4 日目、高橋君は予定がないため、着用した T シャツをすべて洗濯します。これにより、1,2,3 日目に着用した T シャツを再び着用することが可能になります。
- 5 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
- 6 日目、高橋君はロゴ入りの T シャツを着用して競技プログラミングのイベントに行きます。
高橋君がロゴ入りの T シャツを 1 枚以下しか購入しなかった場合には、
どのようにしても条件をみたすように T シャツを着用することができません。
よって、2 を出力します。
入力例 2
3 1 222
出力例 2
3
入力例 3
2 1 01
出力例 3
0
高橋君は新しく T シャツを購入する必要はありません。
Score : 300 points
Problem Statement
AtCoder Inc. sells T-shirts with its logo.
You are given Takahashi's schedule for N days as a string S of length N consisting of 0, 1, and 2.
Specifically, for an integer i satisfying 1\leq i\leq N,
- if the i-th character of S is
0, he has no plan scheduled for the i-th day; - if the i-th character of S is
1, he plans to go out for a meal on the i-th day; - if the i-th character of S is
2, he plans to attend a competitive programming event on the i-th day.
Takahashi has M plain T-shirts, all washed and ready to wear just before the first day.
In addition, to be able to satisfy the following conditions, he will buy several AtCoder logo T-shirts.
- On days he goes out for a meal, he will wear a plain or logo T-shirt.
- On days he attends a competitive programming event, he will wear a logo T-shirt.
- On days with no plans, he will not wear any T-shirts. Also, he will wash all T-shirts worn at that point. He can wear them again from the next day onwards.
- Once he wears a T-shirt, he cannot wear it again until he washes it.
Determine the minimum number of T-shirts he needs to buy to be able to wear appropriate T-shirts on all scheduled days during the N days. If he does not need to buy new T-shirts, print 0.
Assume that the purchased T-shirts are also washed and ready to use just before the first day.
Constraints
- 1\leq M\leq N\leq 1000
- S is a string of length N consisting of
0,1, and2. - N and M are integers.
Input
The input is given from Standard Input in the following format:
N M S
Output
Print the minimum number of T-shirts Takahashi needs to buy to be able to satisfy the conditions in the problem statement.
If he does not need to buy new T-shirts, print 0.
Sample Input 1
6 1 112022
Sample Output 1
2
If Takahashi buys two logo T-shirts, he can wear T-shirts as follows:
- On the first day, he wears a logo T-shirt to go out for a meal.
- On the second day, he wears a plain T-shirt to go out for a meal.
- On the third day, he wears a logo T-shirt to attend a competitive programming event.
- On the fourth day, he has no plans, so he washes all the worn T-shirts. This allows him to reuse the T-shirts worn on the first, second, and third days.
- On the fifth day, he wears a logo T-shirt to attend a competitive programming event.
- On the sixth day, he wears a logo T-shirt to attend a competitive programming event.
If he buys one or fewer logo T-shirts, he cannot use T-shirts to meet the conditions no matter what. Hence, print 2.
Sample Input 2
3 1 222
Sample Output 2
3
Sample Input 3
2 1 01
Sample Output 3
0
He does not need to buy new T-shirts.