Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数 N が与えられます。N の各桁の数字を取り出して並べ(並べる順序は好きに変えてよい)、2 つの正整数に分離することを考えましょう。
例えば、123 という整数に対しては以下の 6 通りの分離の仕方が考えられます。
- 12 と 3
- 21 と 3
- 13 と 2
- 31 と 2
- 23 と 1
- 32 と 1
なお、ここで分離されたあとの 2 整数に leading zero が含まれていてはなりません。例えば、101 という整数を 1 と 01 の 2 つに分離することはできません。また上述の「正整数に分離する」という条件より、101 を 11 と 0 の 2 つに分離することもできません。
適切に N を分離したとき、分離後の 2 数の積の最大値はいくらになりますか?
制約
- N は 1 以上 10^9 以下の整数
- N には 0 でない桁が 2 つ以上含まれる
入力
入力は以下の形式で標準入力から与えられる。
N
出力
分離後の 2 数の積の最大値を出力せよ。
入力例 1
123
出力例 1
63
問題文中にある通り、以下の 6 通りの分離の仕方が考えられます。
- 12 と 3
- 21 と 3
- 13 と 2
- 31 と 2
- 23 と 1
- 32 と 1
積はそれぞれ 36, 63, 26, 62, 23, 32 であり、この中の最大値は 63 です。
入力例 2
1010
出力例 2
100
考えられる分離の仕方は以下の 2 通りです。
- 100 と 1
- 10 と 10
いずれの場合にも積は 100 となります。
入力例 3
998244353
出力例 3
939337176
Score : 300 points
Problem Statement
You are given an integer N. Consider permuting the digits in N and separate them into two positive integers.
For example, for the integer 123, there are six ways to separate it, as follows:
- 12 and 3,
- 21 and 3,
- 13 and 2,
- 31 and 2,
- 23 and 1,
- 32 and 1.
Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101 into 1 and 01. Additionally, since the resulting integers must be positive, it is not allowed to separate 101 into 11 and 0, either.
What is the maximum possible product of the two resulting integers, obtained by the optimal separation?
Constraints
- N is an integer between 1 and 10^9 (inclusive).
- N contains two or more digits that are not 0.
Input
Input is given from Standard Input in the following format:
N
Output
Print the maximum possible product of the two integers after separation.
Sample Input 1
123
Sample Output 1
63
As described in Problem Statement, there are six ways to separate it:
- 12 and 3,
- 21 and 3,
- 13 and 2,
- 31 and 2,
- 23 and 1,
- 32 and 1.
The products of these pairs, in this order, are 36, 63, 26, 62, 23, 32, with 63 being the maximum.
Sample Input 2
1010
Sample Output 2
100
There are two ways to separate it:
- 100 and 1,
- 10 and 10.
In either case, the product is 100.
Sample Input 3
998244353
Sample Output 3
939337176
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個のボールが左右一列に並んでいます。初め、左から i \, (1 \leq i \leq N) 番目のボールには整数 i が書かれています。
高橋君は Q 回の操作を行いました。 i \, (1 \leq i \leq Q) 回目に行われた操作は次のようなものです。
- 整数 x_i が書かれているボールをその右隣のボールと入れ替える。ただし、整数 x_i が書かれているボールが元々右端にあった場合、代わりに左隣のボールと入れ替える。
操作後において左から i \, (1 \leq i \leq N) 番目のボールに書かれている整数を a_i とします。 a_1,\ldots,a_N を求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q x_1 \vdots x_Q
出力
a_1,\ldots,a_N を空白区切りで出力せよ。
入力例 1
5 5 1 2 3 4 5
出力例 1
1 2 3 5 4
操作は以下のように行われます。
- 1 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 2,1,3,4,5 となる。
- 2 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 3 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,4,3,5 となる。
- 4 と書かれたボールを右隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,4,5 となる。
- 5 と書かれたボールは右端にあるので左隣のボールと入れ替える。ボールに書かれた整数は左から 1,2,3,5,4 となる。
入力例 2
7 7 7 7 7 7 7 7 7
出力例 2
1 2 3 4 5 7 6
入力例 3
10 6 1 5 2 9 6 6
出力例 3
1 2 3 4 5 7 6 8 10 9
Score : 300 points
Problem Statement
N balls are lined up in a row from left to right. Initially, the i-th (1 \leq i \leq N) ball from the left has an integer i written on it.
Takahashi has performed Q operations. The i-th (1 \leq i \leq Q) operation was as follows.
- Swap the ball with the integer x_i written on it with the next ball to the right. If the ball with the integer x_i written on it was originally the rightmost ball, swap it with the next ball to the left instead.
Let a_i be the integer written on the i-th (1 \leq i \leq N) ball after the operations. Find a_1,\ldots,a_N.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq x_i \leq N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N Q x_1 \vdots x_Q
Output
Print a_1,\ldots,a_N, with spaces in between.
Sample Input 1
5 5 1 2 3 4 5
Sample Output 1
1 2 3 5 4
The operations are performed as follows.
- Swap the ball with 1 written on it with the next ball to the right. Now, the balls have integers 2,1,3,4,5 written on them, from left to right.
- Swap the ball with 2 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 3 written on it with the next ball to the right. Now, the balls have integers 1,2,4,3,5 written on them, from left to right.
- Swap the ball with 4 written on it with the next ball to the right. Now, the balls have integers 1,2,3,4,5 written on them, from left to right.
- Swap the ball with 5 written on it with the next ball to the left, since it is the rightmost ball. Now, the balls have integers 1,2,3,5,4 written on them, from left to right.
Sample Input 2
7 7 7 7 7 7 7 7 7
Sample Output 2
1 2 3 4 5 7 6
Sample Input 3
10 6 1 5 2 9 6 6
Sample Output 3
1 2 3 4 5 7 6 8 10 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N \times N のマス目が与えられます。このうち上から i 行目、左から j 列目のマスを (i,j) と書きます。
各マスの状態を表す N 個の長さ N の文字列 S_1,S_2,\dots,S_N が以下の形式で与えられます。
- S_i の j 文字目が
oであるとき、 (i,j) にはoが書かれている。 - S_i の j 文字目が
xであるとき、 (i,j) にはxが書かれている。
以下の条件を全て満たすマスの三つ組の個数を求めてください。
- 組に含まれる 3 マスは相異なる。
- 3 マス全てに
oが書かれている。 - マスのうち、丁度 2 つが同じ行にある。
- マスのうち、丁度 2 つが同じ列にある。
但し、ふたつの三つ組は、丁度一方に含まれるマスが存在する場合のみ区別します。
制約
- N は 2 以上 2000 以下の整数
- S_i は長さ N の
oとxからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを整数として出力せよ。
入力例 1
3 ooo oxx xxo
出力例 1
4
以下の 4 つの三つ組が条件を満たします。
- (1,1),(1,2),(2,1)
- (1,1),(1,3),(2,1)
- (1,1),(1,3),(3,3)
- (1,2),(1,3),(3,3)
入力例 2
4 oxxx xoxx xxox xxxo
出力例 2
0
入力例 3
15 xooxxooooxxxoox oxxoxoxxxoxoxxo oxxoxoxxxoxoxxx ooooxooooxxoxxx oxxoxoxxxoxoxxx oxxoxoxxxoxoxxo oxxoxooooxxxoox xxxxxxxxxxxxxxx xooxxxooxxxooox oxxoxoxxoxoxxxo xxxoxxxxoxoxxoo xooxxxooxxoxoxo xxxoxxxxoxooxxo oxxoxoxxoxoxxxo xooxxxooxxxooox
出力例 3
2960
Score : 400 points
Problem Statement
You are given an N \times N grid. Let (i,j) denote the cell in the i-th row from the top and the j-th column from the left.
The states of the cells are given by N strings of length N, S_1, S_2, \dots, S_N, in the following format:
- If the j-th character of S_i is
o, there is anowritten in cell (i,j). - If the j-th character of S_i is
x, there is anxwritten in cell (i,j).
Find the number of triples of cells that satisfy all of the following conditions:
- The three cells in the triple are distinct.
- All three cells have an
owritten in them. - Exactly two of the cells are in the same row.
- Exactly two of the cells are in the same column.
Here, two triples are considered different if and only if some cell is contained in exactly one of the triples.
Constraints
- N is an integer between 2 and 2000, inclusive.
- S_i is a string of length N consisting of
oandx.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer as an integer.
Sample Input 1
3 ooo oxx xxo
Sample Output 1
4
The following four triples satisfy the conditions:
- (1,1),(1,2),(2,1)
- (1,1),(1,3),(2,1)
- (1,1),(1,3),(3,3)
- (1,2),(1,3),(3,3)
Sample Input 2
4 oxxx xoxx xxox xxxo
Sample Output 2
0
Sample Input 3
15 xooxxooooxxxoox oxxoxoxxxoxoxxo oxxoxoxxxoxoxxx ooooxooooxxoxxx oxxoxoxxxoxoxxx oxxoxoxxxoxoxxo oxxoxooooxxxoox xxxxxxxxxxxxxxx xooxxxooxxxooox oxxoxoxxoxoxxxo xxxoxxxxoxoxxoo xooxxxooxxoxoxo xxxoxxxxoxooxxo oxxoxoxxoxoxxxo xooxxxooxxxooox
Sample Output 3
2960
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A = (A_1, A_2, \dots, A_N) および整数 X, Y があります。 次の条件をすべて満たす整数の組 (L, R) の個数を求めてください。
- 1 \leq L \leq R \leq N
- A_L, A_{L+1}, \dots, A_R の最大値は X であり、最小値は Y である。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- 1 \leq Y \leq X \leq 2 \times 10^5
- 入力される値はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 1 2 3 1
出力例 1
4
条件を満たすのは (L,R)=(1,3),(1,4),(2,4),(3,4) の 4 通りです。
入力例 2
5 2 1 1 3 2 4 1
出力例 2
0
条件を満たす (L,R) は存在しません。
入力例 3
5 1 1 1 1 1 1 1
出力例 3
15
X=Y である場合もあります。
入力例 4
10 8 1 2 7 1 8 2 8 1 8 2 8
出力例 4
36
Score : 500 points
Problem Statement
We have a number sequence A = (A_1, A_2, \dots, A_N) of length N and integers X and Y. Find the number of pairs of integers (L, R) satisfying all the conditions below.
- 1 \leq L \leq R \leq N
- The maximum value of A_L, A_{L+1}, \dots, A_R is X, and the minimum is Y.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 2 \times 10^5
- 1 \leq Y \leq X \leq 2 \times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 3 1 1 2 3 1
Sample Output 1
4
4 pairs satisfy the conditions: (L,R)=(1,3),(1,4),(2,4),(3,4).
Sample Input 2
5 2 1 1 3 2 4 1
Sample Output 2
0
No pair (L,R) satisfies the condition.
Sample Input 3
5 1 1 1 1 1 1 1
Sample Output 3
15
It may hold that X=Y.
Sample Input 4
10 8 1 2 7 1 8 2 8 1 8 2 8
Sample Output 4
36
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
数直線上にりんごの木が並んでおり、 N 個のりんごが木から落ちてきます。
具体的には 1\leq i\leq N について、時刻 T_i に座標 X_i にりんごが落ちてきます。
高橋君は耐久性が D , 長さ W のカゴを持っており、一度だけ 次の行動を取ることができます。
正整数 S, L を選ぶ。高橋君は時刻 S-0.5 に L-0.5\leq x\leq L+W-0.5 の範囲を覆うようにカゴを設置し、時刻 S+D-0.5 に回収する。 高橋君はカゴを設置してから回収するまでの間に、カゴが設置されていた範囲に落ちてきたりんごをすべて得ることができる。
高橋君は一度設置したカゴを動かしたり、回収したカゴを再度設置することはできません。
高橋君が得られるりんごの数の最大値を求めてください。
制約
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- (T_i,X_i) はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
出力
高橋君が得られるりんごの数の最大値を出力せよ。
入力例 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
出力例 1
5
高橋君は S=3, L=2 を選ぶと、時刻 2.5 から 6.5 までカゴを 1.5\leq x\leq 4.5 の範囲に設置します。このとき、
- 時刻 T_2=3 に 座標 X_2=4 に落ちてくるりんご
- 時刻 T_3=6 に 座標 X_3=4 に落ちてくるりんご
- 時刻 T_4=5 に 座標 X_4=2 に落ちてくるりんご
- 時刻 T_5=4 に 座標 X_5=2 に落ちてくるりんご
- 時刻 T_6=4 に 座標 X_6=3 に落ちてくるりんご
の 5 個のりんごを得ることができます。
どのように行動しても 6 個以上のりんごを得ることはできないため、5 を出力します。
Score : 550 points
Problem Statement
There are apple trees lined up on a number line, and N apples fall from the trees.
Specifically, for each 1\leq i\leq N, an apple falls at coordinate X_i at time T_i.
Takahashi has a basket with durability D and length W, and he can take the following action exactly once.
Choose positive integers S and L. He sets up the basket to cover the range L-0.5\leq x\leq L+W-0.5 at time S-0.5, and retrieves it at time S+D-0.5. He gets all the apples that fell into the range covered by the basket between the time it was set up and the time it was retrieved.
He cannot move the basket once it has been set up, nor can he set it up again once it has been retrieved.
Find the maximum number of apples that he can get.
Constraints
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- All pairs (T_i,X_i) are different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
Output
Print the maximum number of apples that Takahashi can get.
Sample Input 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
Sample Output 1
5
If Takahashi chooses S=3 and L=2, he will set up the basket to cover the range 1.5\leq x\leq 4.5 from time 2.5 to 6.5. Then, he gets the following five apples:
- The apple that falls at coordinate X_2=4 at time T_2=3
- The apple that falls at coordinate X_3=4 at time T_3=6
- The apple that falls at coordinate X_4=2 at time T_4=5
- The apple that falls at coordinate X_5=2 at time T_5=4
- The apple that falls at coordinate X_6=3 at time T_6=4
There is no way to get six or more apples, so print 5.