Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S と T が与えられます。
以下の条件を満たす 1 \leq c \leq w < |S| となる整数の組 c と w が存在するか判定してください。ただし、 |S| は文字列 S の長さを表します。ここで、w は |S| 未満である必要があることに注意してください。
- S を先頭から順に w 文字毎に区切ったとき、長さが c 以上の文字列の c 文字目を順番に連結した文字列が T と一致する
制約
- S と T は英小文字からなる文字列
- 1 \leq |T| \leq |S| \leq 100
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w が存在する場合は Yes
を、存在しない場合は No
を出力せよ。
入力例 1
atcoder toe
出力例 1
Yes
S を 2 文字毎に区切ると以下のようになります。
at co de r
区切った後、 2 文字以上の文字列の 2 文字目を取り出し連結させたときの文字列は、 toe
となり T と一致します。よって、 Yes
を出力します。
入力例 2
beginner r
出力例 2
No
w=|S| であることはないため、条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w は存在しません。よって、 No
を出力します。
入力例 3
verticalreading agh
出力例 3
No
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters.
Determine if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the following condition is satisfied. Here, |S| denotes the length of the string S. Note that w must be less than |S|.
- If S is split at every w characters from the beginning, the concatenation of the c-th characters of the substrings of length at least c in order equals T.
Constraints
- S and T are strings consisting of lowercase English letters.
- 1 \leq |T| \leq |S| \leq 100
Input
The input is given from Standard Input in the following format:
S T
Output
Print Yes
if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the condition is satisfied, and No
otherwise.
Sample Input 1
atcoder toe
Sample Output 1
Yes
If S is split at every two characters, it looks like this:
at co de r
Then, the concatenation of the 2nd characters of the substrings of length at least 2 is toe
, which equals T. Thus, print Yes
.
Sample Input 2
beginner r
Sample Output 2
No
w=|S| is not allowed, and no pair of integers 1 \leq c \leq w < |S| satisfies the condition. Thus, print No
.
Sample Input 3
verticalreading agh
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
正整数からなる長さ N の数列 A=(A_1,\ldots,A_N) があります。どの隣接する 2 項の値も相異なります。
この数列に対し、次の操作によりいくつか数を挿入します。
- 数列 A のどの隣接する 2 項の差の絶対値も 1 であるとき、操作を終了する。
- 数列 A の先頭から見て、隣接する 2 項の差の絶対値が 1 でない最初の箇所を A_i,A_{i+1} とする。
- A_i < A_{i+1} ならば、A_i と A_{i+1} の間に、A_i+1,A_i+2,\ldots,A_{i+1}-1 を挿入する。
- A_i > A_{i+1} ならば、A_i と A_{i+1} の間に、A_i-1,A_i-2,\ldots,A_{i+1}+1 を挿入する。
- 手順 1 に戻る。
操作が終了したときの数列を出力してください。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
操作が終了したときの数列の各要素を空白区切りで出力せよ。
入力例 1
4 2 5 1 2
出力例 1
2 3 4 5 4 3 2 1 2
最初、数列は (2,5,1,2) です。操作は以下のように行われます。
- 1 項目の 2 と 2 項目の 5 の間に 3,4 を挿入する。数列は (2,3,4,5,1,2) となる。
- 4 項目の 5 と 5 項目の 1 の間に 4,3,2 を挿入する。数列は (2,3,4,5,4,3,2,1,2) となる。
入力例 2
6 3 4 5 6 5 4
出力例 2
3 4 5 6 5 4
一度も挿入が行われないこともあります。
Score : 200 points
Problem Statement
We have a sequence of length N consisting of positive integers: A=(A_1,\ldots,A_N). Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
- If every pair of adjacent terms in A has an absolute difference of 1, terminate the procedure.
- Let A_i, A_{i+1} be the pair of adjacent terms nearest to the beginning of A whose absolute difference is not 1.
- If A_i < A_{i+1}, insert A_i+1,A_i+2,\ldots,A_{i+1}-1 between A_i and A_{i+1}.
- If A_i > A_{i+1}, insert A_i-1,A_i-2,\ldots,A_{i+1}+1 between A_i and A_{i+1}.
- Return to step 1.
Print the sequence when the procedure ends.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_i \neq A_{i+1}
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the terms in the sequence when the procedure ends, separated by spaces.
Sample Input 1
4 2 5 1 2
Sample Output 1
2 3 4 5 4 3 2 1 2
The initial sequence is (2,5,1,2). The procedure goes as follows.
- Insert 3,4 between the first term 2 and the second term 5, making the sequence (2,3,4,5,1,2).
- Insert 4,3,2 between the fourth term 5 and the fifth term 1, making the sequence (2,3,4,5,4,3,2,1,2).
Sample Input 2
6 3 4 5 6 5 4
Sample Output 2
3 4 5 6 5 4
No insertions may be performed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
AtCoder Land には 1 から N までの番号が付けられた N 個のポップコーン売り場があります。 売られているポップコーンの味には味 1,2,\dots,M の M 種類がありますが、すべての売り場ですべての味のポップコーンを売っているわけではありません。
高橋君は、それぞれのポップコーン売り場でどの味のポップコーンを売っているかの情報を入手しました。
この情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N によって表され、S_i の j 文字目が o
であるとき売り場 i が味 j のポップコーンを売っていることを、
x
であるとき売っていないことを示します。
どの売り場も最低 1 種類の味のポップコーンを売っており、どの味のポップコーンも最低 1 つの売り場で売られています。
高橋君は全種類のポップコーンを食べたがっていますが、あまり何度も移動はしたくありません。 高橋君がすべての味のポップコーンを購入するためには最低何個の売り場を訪れる必要があるか求めてください。
制約
- N,M は整数
- 1\leq N,M \leq 10
- S_i は
o
およびx
からなる長さ M の文字列 - すべての i\ (1\leq i\leq N) について、S_i の中には
o
が 1 つ以上存在する - すべての j\ (1\leq j\leq M) について、S_i の j 文字目が
o
であるような i が 1 つ以上存在する
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
高橋君がすべての味のポップコーンを購入するために訪れる必要がある売り場の個数の最小値を出力せよ。
入力例 1
3 5 oooxx xooox xxooo
出力例 1
2
1 つめの売り場と 3 つめの売り場を訪れることで、すべての味のポップコーンを購入することができます。 1 つの売り場ですべての味のポップコーンを購入することはできないので、答えは 2 です。
入力例 2
3 2 oo ox xo
出力例 2
1
入力例 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
出力例 3
3
Score : 300 points
Problem Statement
In AtCoder Land, there are N popcorn stands numbered 1 to N. They have M different flavors of popcorn, labeled 1, 2, \dots, M, but not every stand sells all flavors of popcorn.
Takahashi has obtained information about which flavors of popcorn are sold at each stand. This information is represented by N strings S_1, S_2, \dots, S_N of length M. If the j-th character of S_i is o
, it means that stand i sells flavor j of popcorn. If it is x
, it means that stand i does not sell flavor j. Each stand sells at least one flavor of popcorn, and each flavor of popcorn is sold at least at one stand.
Takahashi wants to try all the flavors of popcorn but does not want to move around too much. Determine the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Constraints
- N and M are integers.
- 1 \leq N, M \leq 10
- Each S_i is a string of length M consisting of
o
andx
. - For every i (1 \leq i \leq N), there is at least one
o
in S_i. - For every j (1 \leq j \leq M), there is at least one i such that the j-th character of S_i is
o
.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print the minimum number of stands Takahashi needs to visit to buy all the flavors of popcorn.
Sample Input 1
3 5 oooxx xooox xxooo
Sample Output 1
2
By visiting the 1st and 3rd stands, you can buy all the flavors of popcorn. It is impossible to buy all the flavors from a single stand, so the answer is 2.
Sample Input 2
3 2 oo ox xo
Sample Output 2
1
Sample Input 3
8 6 xxoxxo xxoxxx xoxxxx xxxoxx xxoooo xxxxox xoxxox oxoxxo
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
長さ N の整数列 A,B が与えられます。1 以上 N 以下の整数 i,j を選んで、 A_i + B_j の値を最大化してください。
制約
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9\,(i=1,2,\dots,N)
- |B_j| \leq 10^9\,(j=1,2,\dots,N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
A_i + B_j の最大値を出力せよ。
入力例 1
2 -1 5 3 -7
出力例 1
8
(i,j)=(1,1),(1,2),(2,1),(2,2) に対する A_i+B_j の値はそれぞれ 2,-8,8,-2 であり、(i,j)=(2,1) が最大値 8 を達成します。
入力例 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
出力例 2
33
Score : 250 points
Problem Statement
You are given two integer sequences A and B, each of length N. Choose integers i, j (1 \leq i, j \leq N) to maximize the value of A_i + B_j.
Constraints
- 1 \leq N \leq 5 \times 10^5
- |A_i| \leq 10^9 (i=1,2,\dots,N)
- |B_j| \leq 10^9 (j=1,2,\dots,N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the maximum possible value of A_i + B_j.
Sample Input 1
2 -1 5 3 -7
Sample Output 1
8
For (i,j) = (1,1), (1,2), (2,1), (2,2), the values of A_i + B_j are 2, -8, 8, -2 respectively, and (i,j) = (2,1) achieves the maximum value 8.
Sample Input 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
Sample Output 2
33
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
数字のみからなる、長さ N の文字列 S が与えられます。
S を並べ替えてできる文字列を十進法の整数として解釈したもののうち、平方数であるようなものがいくつあるか求めてください。
より厳密には、次のようになります。
S の先頭から i 番目 (1\leq i\leq N) の数字に対応する数を s _ i とします。
(1, \ldots, N) の順列 P=(p _ 1,p _ 2,\ldots,p _ N) によって \displaystyle \sum _ {i=1} ^ N s _ {p _ i}10 ^ {N-i} と書ける整数のうち、平方数であるようなものがいくつあるか求めてください。
制約
- 1\leq N\leq 13
- S は数字のみからなる長さ N の文字列
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを 1 行で出力せよ。
入力例 1
4 4320
出力例 1
2
P=(4,2,3,1) とすると、s _ 4\times10 ^ 3+s _ 2\times10 ^ 2+s _ 3\times10 ^ 1+s _ 1=324=18 ^ 2 となります。
P=(3,2,4,1) とすると、s _ 3\times10 ^ 3+s _ 2\times10 ^ 2+s _ 4\times10 ^ 1+s _ 1=2304=48 ^ 2 となります。
これら以外の並べ替え方では平方数にならないため、2 を出力してください。
入力例 2
3 010
出力例 2
2
P=(1,3,2) もしくは P=(3,1,2) とすると、\displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=1=1 ^ 2 となります。
P=(2,1,3) もしくは P=(2,3,1) とすると、\displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=100=10 ^ 2 となります。
これら以外の並べ替え方では平方数にならないため、2 を出力してください。 異なる並べ替え方でも、並べ替えた結果の数が同じなら 1 つと数えることに注意してください。
入力例 3
13 8694027811503
出力例 3
840
Score : 425 points
Problem Statement
You are given a string S of length N consisting of digits.
Find the number of square numbers that can be obtained by interpreting a permutation of S as a decimal integer.
More formally, solve the following.
Let s _ i be the number corresponding to the i-th digit (1\leq i\leq N) from the beginning of S.
Find the number of square numbers that can be represented as \displaystyle \sum _ {i=1} ^ N s _ {p _ i}10 ^ {N-i} with a permutation P=(p _ 1,p _ 2,\ldots,p _ N) of (1, \dots, N).
Constraints
- 1\leq N\leq 13
- S is a string of length N consisting of digits.
- N is an integer.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer in a single line.
Sample Input 1
4 4320
Sample Output 1
2
For P=(4,2,3,1), we have s _ 4\times10 ^ 3+s _ 2\times10 ^ 2+s _ 3\times10 ^ 1+s _ 1=324=18 ^ 2.
For P=(3,2,4,1), we have s _ 3\times10 ^ 3+s _ 2\times10 ^ 2+s _ 4\times10 ^ 1+s _ 1=2304=48 ^ 2.
No other permutations result in square numbers, so you should print 2.
Sample Input 2
3 010
Sample Output 2
2
For P=(1,3,2) or P=(3,1,2), we have \displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=1=1 ^ 2.
For P=(2,1,3) or P=(2,3,1), we have \displaystyle\sum _ {i=1} ^ Ns _ {p _ i}10 ^ {N-i}=100=10 ^ 2.
No other permutations result in square numbers, so you should print 2. Note that different permutations are not distinguished if they result in the same number.
Sample Input 3
13 8694027811503
Sample Output 3
840