実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
概要:以下のような N\times N の模様を作成してください。########### #.........# #.#######.# #.#.....#.# #.#.###.#.# #.#.#.#.#.# #.#.###.#.# #.#.....#.# #.#######.# #.........# ###########
正整数 N が与えられます。
N\times N のグリッドがあります。このグリッドの上から i 行目、左から j 列目のマスをマス (i,j) と表します。はじめ、どのマスにも色は塗られていません。
これから、i=1,2,\dots,N の順に、以下の操作を行います。
- j=N+1-i とする。
- i\leq j であるならば、i が奇数ならば黒、偶数ならば白で、マス (i,i) を左上、マス (j,j) を右下とする矩形領域に含まれるマスを塗りつぶす。このとき、既に色が塗られているマスについては色を上書きする。
- i\gt j であるならば、何もしない。
すべての操作を行った後、色が塗られていないマスが存在しないことが証明できます。最終的に各マスがどの色で塗られているかを求めてください。
制約
- 1\leq N\leq 50
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N 行出力せよ。i 行目には、最終的にグリッドの i 行目に塗られている色を以下のような長さ N の文字列 S_i として出力せよ。入出力例も参考にすること。
- マス (i,j) が最終的に黒で塗られているならば、S_i の j 文字目は
#である。 - マス (i,j) が最終的に白で塗られているならば、S_i の j 文字目は
.である。
入力例 1
11
出力例 1
########### #.........# #.#######.# #.#.....#.# #.#.###.#.# #.#.#.#.#.# #.#.###.#.# #.#.....#.# #.#######.# #.........# ###########
概要で示した模様と同じです。
入力例 2
5
出力例 2
##### #...# #.#.# #...# #####
以下のように色が塗られます。ここで、まだ色が塗られていないマスを ? と表します。
i=1 i=2 i=3 i=4 i=5 ????? ##### ##### ##### ##### ##### ????? ##### #...# #...# #...# #...# ????? -> ##### -> #...# -> #.#.# -> #.#.# -> #.#.# ????? ##### #...# #...# #...# #...# ????? ##### ##### ##### ##### #####
入力例 3
8
出力例 3
######## #......# #.####.# #.#..#.# #.#..#.# #.####.# #......# ########
入力例 4
2
出力例 4
## ##
Score : 200 points
Problem Statement
Overview: Create an N \times N pattern as follows.########### #.........# #.#######.# #.#.....#.# #.#.###.#.# #.#.#.#.#.# #.#.###.#.# #.#.....#.# #.#######.# #.........# ###########
You are given a positive integer N.
Consider an N \times N grid. Let (i,j) denote the cell at the i-th row from the top and the j-th column from the left. Initially, no cell is colored.
Then, for i = 1,2,\dots,N in order, perform the following operation:
- Let j = N + 1 - i.
- If i \leq j, fill the rectangular region whose top-left cell is (i,i) and bottom-right cell is (j,j) with black if i is odd, or white if i is even. If some cells are already colored, overwrite their colors.
- If i > j, do nothing.
After all these operations, it can be proved that there are no uncolored cells. Determine the final color of each cell.
Constraints
- 1 \leq N \leq 50
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
Output
Print N lines. The i-th line should contain a length-N string S_i representing the colors of the i-th row of the grid after all operations, as follows:
- If cell (i,j) is finally colored black, the j-th character of S_i should be
#. - If cell (i,j) is finally colored white, the j-th character of S_i should be
..
Sample Input 1
11
Sample Output 1
########### #.........# #.#######.# #.#.....#.# #.#.###.#.# #.#.#.#.#.# #.#.###.#.# #.#.....#.# #.#######.# #.........# ###########
This matches the pattern shown in the Overview.
Sample Input 2
5
Sample Output 2
##### #...# #.#.# #...# #####
Colors are applied as follows, where ? denotes a cell not yet colored:
i=1 i=2 i=3 i=4 i=5 ????? ##### ##### ##### ##### ##### ????? ##### #...# #...# #...# #...# ????? -> ##### -> #...# -> #.#.# -> #.#.# -> #.#.# ????? ##### #...# #...# #...# #...# ????? ##### ##### ##### ##### #####
Sample Input 3
8
Sample Output 3
######## #......# #.####.# #.#..#.# #.#..#.# #.####.# #......# ########
Sample Input 4
2
Sample Output 4
## ##
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
N 個の整数 A_1,A_2,\dots,A_N が、 1 行に 1 つずつ、 N 行にわたって与えられます。但し、 N は入力では与えられません。
さらに、以下が保証されます。
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
A_N, A_{N-1},\dots,A_1 をこの順に出力してください。
制約
- 入力は全て整数
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
入力
入力は以下の形式で標準入力から与えられる。
A_1 A_2 \vdots A_N
出力
A_N, A_{N-1},\dots,A_1 をこの順に、改行区切りで整数として出力せよ。
入力例 1
3 2 1 0
出力例 1
0 1 2 3
繰り返しになりますが、 N は入力では与えられないことに注意してください。
この入力においては N=4 で、 A=(3,2,1,0) です。
入力例 2
0
出力例 2
0
A=(0) です。
入力例 3
123 456 789 987 654 321 0
出力例 3
0 321 654 987 789 456 123
Score: 150 points
Problem Statement
You are given N integers A_1,A_2,\dots,A_N, one per line, over N lines. However, N is not given in the input.
Furthermore, the following is guaranteed:
- A_i \neq 0 ( 1 \le i \le N-1 )
- A_N = 0
Print A_N, A_{N-1},\dots,A_1 in this order.
Constraints
- All input values are integers.
- 1 \le N \le 100
- 1 \le A_i \le 10^9 ( 1 \le i \le N-1 )
- A_N = 0
Input
The input is given from Standard Input in the following format:
A_1 A_2 \vdots A_N
Output
Print A_N, A_{N-1}, \dots, A_1 in this order, as integers, separated by newlines.
Sample Input 1
3 2 1 0
Sample Output 1
0 1 2 3
Note again that N is not given in the input. Here, N=4 and A=(3,2,1,0).
Sample Input 2
0
Sample Output 2
0
A=(0).
Sample Input 3
123 456 789 987 654 321 0
Sample Output 3
0 321 654 987 789 456 123
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
ピザ屋で働く高橋くんは、まかないとして美味しいチーズピザを作ることにしました。
今、高橋くんの目の前に N 種類のチーズがあります。
i 種類目のチーズは 1 [g] あたりのおいしさが A_i で、 B_i [g] あります。
ピザのおいしさは、ピザに乗せたチーズのおいしさの総和で決まります。
但し、チーズを使いすぎると怒られてしまうため、乗せたチーズの重さは合計で W [g] 以下である必要があります。
この条件のもとで、可能なピザのおいしさの最大値を求めてください。
制約
- 入力は全て整数
- 1 \le N \le 3 \times 10^5
- 1 \le W \le 3 \times 10^8
- 1 \le A_i \le 10^9
- 1 \le B_i \le 1000
入力
入力は以下の形式で標準入力から与えられる。
N W A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
答えを整数として出力せよ。
入力例 1
3 5 3 1 4 2 2 3
出力例 1
15
1 種類目のチーズを 1 [g] 、 2 種類目のチーズを 2 [g] 、 3 種類目のチーズを 2 [g] 乗せるのが最適です。
このとき、ピザのおいしさは 15 となります。
入力例 2
4 100 6 2 1 5 3 9 8 7
出力例 2
100
チーズの重量の総和が W [g] に満たないケースもあります。
入力例 3
10 3141 314944731 649 140276783 228 578012421 809 878510647 519 925326537 943 337666726 611 879137070 306 87808915 39 756059990 244 228622672 291
出力例 3
2357689932073
Score : 300 points
Problem Statement
Takahashi, who works for a pizza restaurant, is making a delicious cheese pizza for staff meals.
There are N kinds of cheese in front of him.
The deliciousness of the i-th kind of cheese is A_i per gram, and B_i grams of this cheese are available.
The deliciousness of the pizza will be the total deliciousness of cheese he puts on top of the pizza.
However, using too much cheese would make his boss angry, so the pizza can have at most W grams of cheese on top of it.
Under this condition, find the maximum possible deliciousness of the pizza.
Constraints
- All values in input are integers.
- 1 \le N \le 3 \times 10^5
- 1 \le W \le 3 \times 10^8
- 1 \le A_i \le 10^9
- 1 \le B_i \le 1000
Input
Input is given from Standard Input in the following format:
N W A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print the answer as an integer.
Sample Input 1
3 5 3 1 4 2 2 3
Sample Output 1
15
The optimal choice is to use 1 gram of cheese of the first kind, 2 grams of the second kind, and 2 grams of the third kind.
The pizza will have a deliciousness of 15.
Sample Input 2
4 100 6 2 1 5 3 9 8 7
Sample Output 2
100
There may be less than W grams of cheese in total.
Sample Input 3
10 3141 314944731 649 140276783 228 578012421 809 878510647 519 925326537 943 337666726 611 879137070 306 87808915 39 756059990 244 228622672 291
Sample Output 3
2357689932073
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
正整数 N が与えられます。
N 以下の正整数であって回文立方数であるものの最大値を求めてください。
ただし、正整数 K は以下の 2 つの条件を満たすとき、またそのときに限り回文立方数であると定義します。
- ある正整数 x が存在し、x^3 = K を満たす。
- K を先頭に 0 をつけずに 10 進表記した文字列が回文となる。より厳密には、0 以上 9 以下の整数 A_0, A_1, \ldots, A_{L-2} および 1 以上 9 以下の整数 A_{L-1} を用いて K = \sum_{i = 0}^{L-1} A_i10^i と表記したときに i = 0, 1, \ldots, L-1 に対して A_i = A_{L-1-i} を満たす。
制約
- N は 10^{18} 以下の正整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
345
出力例 1
343
343 は回文立方数であり、344, 345 は回文立方数ではありません。したがって、343 が答えとなります。
入力例 2
6
出力例 2
1
入力例 3
123456789012345
出力例 3
1334996994331
Score: 250 points
Problem Statement
You are given a positive integer N.
Find the maximum value of a palindromic cube number not greater than N.
Here, a positive integer K is defined to be a palindromic cube number if and only if it satisfies the following two conditions:
- There is a positive integer x such that x^3 = K.
- The decimal representation of K without leading zeros is a palindrome. More precisely, if K is represented as K = \sum_{i = 0}^{L-1} A_i10^i using integers A_0, A_1, \ldots, A_{L-2} between 0 and 9, inclusive, and an integer A_{L-1} between 1 and 9, inclusive, then A_i = A_{L-1-i} for all i = 0, 1, \ldots, L-1.
Constraints
- N is a positive integer not greater than 10^{18}.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
345
Sample Output 1
343
343 is a palindromic cube number, while 344 and 345 are not. Thus, the answer is 343.
Sample Input 2
6
Sample Output 2
1
Sample Input 3
123456789012345
Sample Output 3
1334996994331
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
T 個のテストケースについて、以下の問題を解いてください。
非負整数 a,s が与えられます。以下の条件を両方とも満たす非負整数の組 (x,y) は存在しますか?
- x\ \text{AND}\ y=a
- x+y=s
\text{AND} とは
非負整数 n, m の bit ごとの論理積 n\ \text{AND}\ m は、以下のように定義されます。
- n\ \text{AND}\ m を二進表記した際の 2^k \, (k \geq 0) の位の数は、n, m を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1、そうでなければ 0 である。
制約
- 1 \leq T \leq 10^5
- 0 \leq a,s \lt 2^{60}
- 入力はすべて整数
入力
入力は標準入力から与えられる。入力の 1 行目は以下の形式である。
T
その後、 T 個のテストケースが続く。各テストケースは以下の形式で与えられる。
a s
出力
T 行出力せよ。i\ (1 \leq i \leq T) 行目には、i 番目に与えられるテストケースについて問題文中の条件を両方とも満たす非負整数の組 (x,y) が存在するなら Yes を、存在しないなら No を出力せよ。
入力例 1
2 1 8 4 2
出力例 1
Yes No
1 番目のテストケースにおいては、(x,y)=(3,5) などが条件を満たします。
2 番目のテストケースにおいては、条件を満たす非負整数の組 (x,y) は存在しません。
入力例 2
4 201408139683277485 381410962404666524 360288799186493714 788806911317182736 18999951915747344 451273909320288229 962424162689761932 1097438793187620758
出力例 2
No Yes Yes No
Score : 400 points
Problem Statement
Solve the following problem for T test cases.
Given are non-negative integers a and s. Is there a pair of non-negative integers (x,y) that satisfies both of the conditions below?
- x\ \text{AND}\ y=a
- x+y=s
What is bitwise \mathrm{AND}?
The bitwise \mathrm{AND} of integers A and B, A\ \mathrm{AND}\ B, is defined as follows:
- When A\ \mathrm{AND}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if those of A and B are both 1, and 0 otherwise.
Constraints
- 1 \leq T \leq 10^5
- 0 \leq a,s \lt 2^{60}
- All values in input are integers.
Input
Input is given from Standard Input. The first line is in the following format:
T
Then, T test cases follow. Each test case is in the following format:
a s
Output
Print T lines. The i-th line (1 \leq i \leq T) should contain Yes if, in the i-th test case, there is a pair of non-negative integers (x,y) that satisfies both of the conditions in the Problem Statement, and No otherwise.
Sample Input 1
2 1 8 4 2
Sample Output 1
Yes No
In the first test case, some pairs such as (x,y)=(3,5) satisfy the conditions.
In the second test case, no pair of non-negative integers satisfies the conditions.
Sample Input 2
4 201408139683277485 381410962404666524 360288799186493714 788806911317182736 18999951915747344 451273909320288229 962424162689761932 1097438793187620758
Sample Output 2
No Yes Yes No