Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
スーパーマーケットで卵のパックが売られています。
卵 6 個入りのパックは S 円、卵 8 個入りのパックは M 円、卵 12 個入りのパックは L 円です。
どのパックも何パックでも購入できるとき、N 個以上の卵を買うために必要な最小の金額を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq S,M,L \leq 10^4
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N S M L
出力
答えを出力せよ。
入力例 1
16 120 150 200
出力例 1
300
8 個入りのパックを 2 個買うのが最適です。
入力例 2
10 100 50 10
出力例 2
10
12 個入りのパックを 1 個買うのが最適です。
入力例 3
99 600 800 1200
出力例 3
10000
8 個入りのパックと 12 個入りのパックを 5 個ずつ買うのが最適です。
Score : 200 points
Problem Statement
A supermarket sells egg packs.
A pack of 6 eggs costs S yen, a pack of 8 eggs costs M yen, and a pack of 12 eggs costs L yen.
When you can buy any number of each pack, find the minimum amount of money required to purchase at least N eggs.
Constraints
- 1 \leq N \leq 100
- 1 \leq S,M,L \leq 10^4
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N S M L
Output
Print the answer.
Sample Input 1
16 120 150 200
Sample Output 1
300
It is optimal to buy two 8-egg packs.
Sample Input 2
10 100 50 10
Sample Output 2
10
It is optimal to buy one 12-egg pack.
Sample Input 3
99 600 800 1200
Sample Output 3
10000
It is optimal to buy five 8-egg packs and five 12-egg packs.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
プレイヤー 1 、プレイヤー 2 、\ldots 、プレイヤー N と番号がつけられた N 人のプレイヤーがカードゲームで対戦します。
各プレイヤーはカードを 1 枚場に出します。
各カードは色と値の 2 つの属性を持ち、どちらの属性も正整数で表されます。
i = 1, 2, \ldots, N について、プレイヤー i が場に出したカードの色は C_i であり、値は R_i です。
R_1, R_2, \ldots, R_N はすべて異なります。
N 人のプレイヤーの中から 1 人の勝者を下記の方法で決めます。
- 色が T であるカードが 1 枚以上場に出された場合、色が T であるカードのうち値が最大のものを出したプレイヤーが勝者である。
- 色が T であるカードが場に 1 枚も出されなかった場合、プレイヤー 1 が出したカードと同じ色のカードのうち値が最大のものを出したプレイヤーが勝者である。(プレイヤー 1 自身も勝者となり得ることに注意してください。)
勝者となるプレイヤーの番号を出力してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq R_i \leq 10^9
- i \neq j \implies R_i \neq R_j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T C_1 C_2 \ldots C_N R_1 R_2 \ldots R_N
出力
答えを出力せよ。
入力例 1
4 2 1 2 1 2 6 3 4 5
出力例 1
4
色が 2 であるカードが 1 枚以上場に出されています。 よって、色が 2 であるカードのうち値が最大の 5 のカードを出した、プレイヤー 4 が勝者です。
入力例 2
4 2 1 3 1 4 6 3 4 5
出力例 2
1
色が 2 であるカードが 1 枚も場に出されていません。 よって、プレイヤー 1 が出したカードの色と同じ色(すなわち色 1 )のカードのうち値が最大の 6 のカードを出した、プレイヤー 1 が勝者です。
入力例 3
2 1000000000 1000000000 1 1 1000000000
出力例 3
1
Score : 200 points
Problem Statement
N players with ID numbers 1, 2, \ldots, N are playing a card game.
Each player plays one card.
Each card has two parameters: color and rank, both of which are represented by positive integers.
For i = 1, 2, \ldots, N, the card played by player i has a color C_i and a rank R_i.
All of R_1, R_2, \ldots, R_N are different.
Among the N players, one winner is decided as follows.
- If one or more cards with the color T are played, the player who has played the card with the greatest rank among those cards is the winner.
- If no card with the color T is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 1 is the winner. (Note that player 1 may win.)
Print the ID number of the winner.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq R_i \leq 10^9
- i \neq j \implies R_i \neq R_j
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N T C_1 C_2 \ldots C_N R_1 R_2 \ldots R_N
Output
Print the answer.
Sample Input 1
4 2 1 2 1 2 6 3 4 5
Sample Output 1
4
Cards with the color 2 are played. Thus, the winner is player 4, who has played the card with the greatest rank, 5, among those cards.
Sample Input 2
4 2 1 3 1 4 6 3 4 5
Sample Output 2
1
No card with the color 2 is played. Thus, the winner is player 1, who has played the card with the greatest rank, 6, among the cards with the color of the card played by player 1 (color 1).
Sample Input 3
2 1000000000 1000000000 1 1 1000000000
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
上下左右に広がる N\times N のマス目があり、最初全てのマスは白く塗られています。このマス目の上から i 行目、左から j 列目のマスを (i,j) で表します。
高橋君は 1 以上 N 以下の整数 A, B を持っており、次のような操作を行います。
- \max(1-A,1-B)\leq k\leq \min(N-A,N-B) をみたす全ての整数 k について、(A+k,B+k) を黒く塗る。
- \max(1-A,B-N)\leq k\leq \min(N-A,B-1) をみたす全ての整数 k について、(A+k,B-k) を黒く塗る。
この操作を行った後のマス目について、P\leq i\leq Q かつ R\leq j\leq S をみたす各マス (i,j) がそれぞれ何色で塗られているか求めてください。
制約
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A B P Q R S
出力
Q-P+1 行出力せよ。
各行は # と . のみからなる長さ S-R+1 の文字列であり、
i 行目の文字列の j 番目の文字が
# であることは (P+i-1,R+j-1) が黒く塗られていることを、
. であることは (P+i-1,R+j-1) が白く塗られていることをさす。
入力例 1
5 3 2 1 5 1 5
出力例 1
...#. #.#.. .#... #.#.. ...#.
1 つめの操作で (2,1), (3,2), (4,3), (5,4) の 4 マスが、
2 つめの操作で (4,1), (3,2), (2,3), (1,4) の 4 マスが黒く塗られます。
よって、P=1, Q=5, R=1, S=5 より、上のように出力します。
入力例 2
5 3 3 4 5 2 5
出力例 2
#.#. ...#
操作によって、
(1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5) の 9 マスが
黒く塗られます。
P=4, Q=5, R=2, S=5 より、上のように出力します。
入力例 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
出力例 3
#.# .#. #.#
入力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 300 points
Problem Statement
There is an N\times N grid with horizontal rows and vertical columns, where all squares are initially painted white. Let (i,j) denote the square at the i-th row and j-th column.
Takahashi has integers A and B, which are between 1 and N (inclusive). He will do the following operations.
- For every integer k such that \max(1-A,1-B)\leq k\leq \min(N-A,N-B), paint (A+k,B+k) black.
- For every integer k such that \max(1-A,B-N)\leq k\leq \min(N-A,B-1), paint (A+k,B-k) black.
In the grid after these operations, find the color of each square (i,j) such that P\leq i\leq Q and R\leq j\leq S.
Constraints
- 1 \leq N \leq 10^{18}
- 1 \leq A \leq N
- 1 \leq B \leq N
- 1 \leq P \leq Q \leq N
- 1 \leq R \leq S \leq N
- (Q-P+1)\times(S-R+1)\leq 3\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B P Q R S
Output
Print Q-P+1 lines.
Each line should contain a string of length S-R+1 consisting of # and ..
The j-th character of the string in the i-th line should be # to represent that (P+i-1, R+j-1) is painted black, and . to represent that (P+i-1, R+j-1) is white.
Sample Input 1
5 3 2 1 5 1 5
Sample Output 1
...#. #.#.. .#... #.#.. ...#.
The first operation paints the four squares (2,1), (3,2), (4,3), (5,4) black, and the second paints the four squares (4,1), (3,2), (2,3), (1,4) black.
Thus, the above output should be printed, since P=1, Q=5, R=1, S=5.
Sample Input 2
5 3 3 4 5 2 5
Sample Output 2
#.#. ...#
The operations paint the nine squares (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5).
Thus, the above output should be printed, since P=4, Q=5, R=2, S=5.
Sample Input 3
1000000000000000000 999999999999999999 999999999999999999 999999999999999998 1000000000000000000 999999999999999998 1000000000000000000
Sample Output 3
#.# .#. #.#
Note that the input may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1,2,\dots,N が 1 回ずつ現れる長さ N の数列を「長さ N の順列」と呼びます。
長さ N の順列 P = (p_1, p_2,\dots,p_N) が与えられるので、以下の条件を満たす長さ N の順列 Q = (q_1,\dots,q_N) を出力してください。
- 全ての i (1 \leq i \leq N) に対して Q の p_i 番目の要素が i である。
ただし、条件を満たす Q は必ずただ 1 つ存在することが証明できます。
制約
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) は長さ N の順列である。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N p_1 p_2 \dots p_N
出力
数列 Q を空白区切りで 1 行で出力せよ。
q_1 q_2 \dots q_N
入力例 1
3 2 3 1
出力例 1
3 1 2
以下に説明する通り、 Q=(3,1,2) は条件を満たす順列です。
- i = 1 のとき p_i = 2, q_2 = 1
- i = 2 のとき p_i = 3, q_3 = 2
- i = 3 のとき p_i = 1, q_1 = 3
入力例 2
3 1 2 3
出力例 2
1 2 3
全ての i (1 \leq i \leq N) に対して p_i = i が成り立つときは P = Q になります。
入力例 3
5 5 3 2 4 1
出力例 3
5 3 2 4 1
Score : 300 points
Problem Statement
We will call a sequence of length N where each of 1,2,\dots,N occurs once as a permutation of length N.
Given a permutation of length N, P = (p_1, p_2,\dots,p_N), print a permutation of length N, Q = (q_1,\dots,q_N), that satisfies the following condition.
- For every i (1 \leq i \leq N), the p_i-th element of Q is i.
It can be proved that there exists a unique Q that satisfies the condition.
Constraints
- 1 \leq N \leq 2 \times 10^5
- (p_1,p_2,\dots,p_N) is a permutation of length N (defined in Problem Statement).
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N p_1 p_2 \dots p_N
Output
Print the sequence Q in one line, with spaces in between.
q_1 q_2 \dots q_N
Sample Input 1
3 2 3 1
Sample Output 1
3 1 2
The permutation Q=(3,1,2) satisfies the condition, as follows.
- For i = 1, we have p_i = 2, q_2 = 1.
- For i = 2, we have p_i = 3, q_3 = 2.
- For i = 3, we have p_i = 1, q_1 = 3.
Sample Input 2
3 1 2 3
Sample Output 2
1 2 3
If p_i = i for every i (1 \leq i \leq N), we will have P = Q.
Sample Input 3
5 5 3 2 4 1
Sample Output 3
5 3 2 4 1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
0, 1, ? からなる文字列 S および整数 N が与えられます。
S に含まれる ? をそれぞれ 0 または 1 に置き換えて 2 進整数とみなしたときに得られる値の集合を T とします。
たとえば、S= ?0? のとき、
T=\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\rbrace=\lbrace 0,1,4,5\rbrace です。
T に含まれる N 以下の値のうち最大のものを (10 進整数として) 出力してください。
N 以下の値が T に含まれない場合は、代わりに -1 を出力してください。
制約
- S は
0,1,?からなる文字列 - S の長さは 1 以上 60 以下
- 1\leq N \leq 10^{18}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
S N
出力
答えを出力せよ。
入力例 1
?0? 2
出力例 1
1
問題文中で例示したとおり、T=\lbrace 0,1,4,5\rbrace です。 T に含まれる N 以下の値は 0 と 1 なので、そのうちの最大である 1 を出力します。
入力例 2
101 4
出力例 2
-1
T=\lbrace 5\rbrace であるため、N 以下の値は T に含まれません。
入力例 3
?0? 1000000000000000000
出力例 3
5
Score : 400 points
Problem Statement
You are given an integer N and a string S consisting of 0, 1, and ?.
Let T be the set of values that can be obtained by replacing each ? in S with 0 or 1 and interpreting the result as a binary integer.
For instance, if S= ?0?, we have T=\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\rbrace=\lbrace 0,1,4,5\rbrace.
Print (as a decimal integer) the greatest value in T less than or equal to N.
If T does not contain a value less than or equal to N, print -1 instead.
Constraints
- S is a string consisting of
0,1, and?. - The length of S is between 1 and 60, inclusive.
- 1\leq N \leq 10^{18}
- N is an integer.
Input
The input is given from Standard Input in the following format:
S N
Output
Print the answer.
Sample Input 1
?0? 2
Sample Output 1
1
As shown in the problem statement, T=\lbrace 0,1,4,5\rbrace. Among them, 0 and 1 are less than or equal to N, so you should print the greatest of them, 1.
Sample Input 2
101 4
Sample Output 2
-1
We have T=\lbrace 5\rbrace, which does not contain a value less than or equal to N.
Sample Input 3
?0? 1000000000000000000
Sample Output 3
5