Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10^{100} 行 7 列の行列 A があり、任意の整数対 (i,j)\ (1 \leq i \leq 10^{100}, 1 \leq j \leq 7) についてその (i,j) 成分は (i-1) \times 7 + j です。
N 行 M 列の行列 B が与えられるので、B が A から一部の矩形領域を(向きを変えずに)切り出したものであるかを判定してください。
制約
- 1 \leq N \leq 10^4
- 1 \leq M \leq 7
- 1 \leq B_{i,j} \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M B_{1,1} B_{1,2} \ldots B_{1,M} B_{2,1} B_{2,2} \ldots B_{2,M} \hspace{1.6cm}\vdots B_{N,1} B_{N,2} \ldots B_{N,M}
出力
B が A から一部の矩形領域を切り出したものであれば Yes
と、そうでないなら No
と出力せよ。
入力例 1
2 3 1 2 3 8 9 10
出力例 1
Yes
与えられる B は、A の左上 2 行 3 列を切り出したものとなっています。
入力例 2
2 1 1 2
出力例 2
No
与えられる B を 90 度回転させると A の左上 1 行 2 列と一致しますが、問題文中に「向きを変えずに」とある通り回転による一致は認められていないため、答えは No
となります。
入力例 3
10 4 1346 1347 1348 1349 1353 1354 1355 1356 1360 1361 1362 1363 1367 1368 1369 1370 1374 1375 1376 1377 1381 1382 1383 1384 1388 1389 1390 1391 1395 1396 1397 1398 1402 1403 1404 1405 1409 1410 1411 1412
出力例 3
Yes
Score : 300 points
Problem Statement
There is a 10^{100} \times 7 matrix A, where the (i,j)-th entry is (i-1) \times 7 + j for every pair of integers (i,j)\ (1 \leq i \leq 10^{100}, 1 \leq j \leq 7).
Given an N \times M matrix B, determine whether B is some (unrotated) rectangular part of A.
Constraints
- 1 \leq N \leq 10^4
- 1 \leq M \leq 7
- 1 \leq B_{i,j} \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M B_{1,1} B_{1,2} \ldots B_{1,M} B_{2,1} B_{2,2} \ldots B_{2,M} \hspace{1.6cm}\vdots B_{N,1} B_{N,2} \ldots B_{N,M}
Output
If B is some rectangular part of A, print Yes
; otherwise, print No
.
Sample Input 1
2 3 1 2 3 8 9 10
Sample Output 1
Yes
The given matrix B is the top-left 2 \times 3 submatrix of A.
Sample Input 2
2 1 1 2
Sample Output 2
No
Although the given matrix B would match the top-left 1 \times 2 submatrix of A after rotating 90 degrees, the Problem Statement asks whether B is an unrotated part of A, so the answer is No
.
Sample Input 3
10 4 1346 1347 1348 1349 1353 1354 1355 1356 1360 1361 1362 1363 1367 1368 1369 1370 1374 1375 1376 1377 1381 1382 1383 1384 1388 1389 1390 1391 1395 1396 1397 1398 1402 1403 1404 1405 1409 1410 1411 1412
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
正の整数 a があります。また、黒板に 1 個の数が 10 進表記で書かれています。
黒板に現在書かれている数を x としたとき、高橋君は次のいずれかの操作を行い、黒板に書かれている数を変化させることができます。
- x を消し、 x を a 倍した数を 10 進表記で新たに書きこむ。
- x を文字列とみなして、列の末尾の数字を文字列の先頭に移動させる。
ただし、この操作は x \geq 10 かつ x が 10 で割り切れないときにしか行えない。
たとえば a = 2, x = 123 であるとき、高橋君は次のいずれかの操作を行うことができます。
- x を消して、 x \times a = 123 \times 2 = 246 を新たに書きこむ。
- x を文字列とみなして、
123
の末尾の数字である3
を先頭に移動させる。黒板に書かれている数は 123 から 312 に変化する。
はじめ、黒板には 1 が書かれています。書かれている数を N に変化させるには最小で何回の操作が必要ですか?ただし、どのように操作しても書かれている数を N に変化させられない場合は -1 を出力してください。
制約
- 2 \leq a \lt 10^6
- 2 \leq N \lt 10^6
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
a N
出力
答えを出力せよ。
入力例 1
3 72
出力例 1
4
以下に説明する操作を行うことで、 黒板に書かれている数を 4 回で 1 から 72 に変化させることができます。
- 1 つ目の操作を行う。黒板に書かれている数は 1 \to 3 に変わる。
- 1 つ目の操作を行う。黒板に書かれている数は 3 \to 9 に変わる。
- 1 つ目の操作を行う。黒板に書かれている数は 9 \to 27 に変わる。
- 2 つ目の操作を行う。黒板に書かれている数は 27 \to 72 に変わる。
3 回以下の操作で 72 に変化させることはできないため、答えは 4 になります。
入力例 2
2 5
出力例 2
-1
どのように操作しても黒板に書かれている数を 5 に変化させることはできません。
入力例 3
2 611
出力例 3
12
適切に操作を選ぶことで、 1 \to 2 \to 4 \to 8 \to 16 \to 32 \to 64 \to 46 \to 92 \to 29 \to 58 \to 116 \to 611 と 12 回の操作で黒板に書かれている数を 611 に変化させることができ、これが最小です。
入力例 4
2 767090
出力例 4
111
Score : 400 points
Problem Statement
We have a positive integer a. Additionally, there is a blackboard with a number written in base 10.
Let x be the number on the blackboard. Takahashi can do the operations below to change this number.
- Erase x and write x multiplied by a, in base 10.
- See x as a string and move the rightmost digit to the beginning.
This operation can only be done when x \geq 10 and x is not divisible by 10.
For example, when a = 2, x = 123, Takahashi can do one of the following.
- Erase x and write x \times a = 123 \times 2 = 246.
- See x as a string and move the rightmost digit
3
of123
to the beginning, changing the number from 123 to 312.
The number on the blackboard is initially 1. What is the minimum number of operations needed to change the number on the blackboard to N? If there is no way to change the number to N, print -1.
Constraints
- 2 \leq a \lt 10^6
- 2 \leq N \lt 10^6
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
a N
Output
Print the answer.
Sample Input 1
3 72
Sample Output 1
4
We can change the number on the blackboard from 1 to 72 in four operations, as follows.
- Do the operation of the first type: 1 \to 3.
- Do the operation of the first type: 3 \to 9.
- Do the operation of the first type: 9 \to 27.
- Do the operation of the second type: 27 \to 72.
It is impossible to reach 72 in three or fewer operations, so the answer is 4.
Sample Input 2
2 5
Sample Output 2
-1
It is impossible to change the number on the blackboard to 5.
Sample Input 3
2 611
Sample Output 3
12
There is a way to change the number on the blackboard to 611 in 12 operations: 1 \to 2 \to 4 \to 8 \to 16 \to 32 \to 64 \to 46 \to 92 \to 29 \to 58 \to 116 \to 611, which is the minimum possible.
Sample Input 4
2 767090
Sample Output 4
111
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
空の列 A があります。クエリが Q 個与えられるので、与えられた順番に処理してください。
クエリは次の 3 種類のいずれかです。
1 x
: A の最後尾に x を追加する。2
: A の最初の要素を出力する。その後、その要素を削除する。このクエリが与えられるとき、A は空でないことが保証される。3
: A を昇順にソートする。
制約
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- クエリ
2
が与えられるとき、A は空でない。 - 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
i 番目のクエリ \mathrm{query} i では、まずクエリの種類 c_i( 1, 2, 3 のいずれか)が与えられる。 c_i = 1 の場合はさらに整数 x が追加で与えられる。
すなわち、各クエリは以下に示す 3 つの形式のいずれかである。
1 x
2
3
出力
c_i = 2 を満たすクエリの回数を q として q 行出力せよ。
j (1 \leq j \leq q) 行目では j 番目のそのようなクエリに対する答えを出力せよ。
入力例 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
出力例 1
1 2
入力例 1 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
入力例 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
出力例 2
5 3 5
入力例 2 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Score : 500 points
Problem Statement
We have an empty sequence A. You will be given Q queries, which should be processed in the order they are given. Each query is of one of the three kinds below:
1 x
: Append x to the end of A.2
: Print the element at the beginning of A. Then, delete that element. It is guaranteed that A will not empty when this query is given.3
: Sort A in ascending order.
Constraints
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- A will not be empty when a query
2
is given. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
The i-th query, \mathrm{query} i, begins with the kind of query c_i (1, 2, or 3). If c_i = 1, the line additionally has an integer x.
In other words, each query is in one of the three formats below.
1 x
2
3
Output
Print q lines, where q is the number of queries with c_i = 2.
The j-th line (1 \leq j \leq q) should contain the response for the j-th such query.
Sample Input 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
Sample Output 1
1 2
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 1.
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
Sample Input 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
Sample Output 2
5 3 5
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 2.
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
縦の長さが A、横の長さが B の長方形の内部に描ける正三角形の一辺の長さの最大値を求めてください。
制約
- 1 \leq A,B \leq 1000
- A,B は整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-9} 以下であれば正解として扱われる。
入力例 1
1 1
出力例 1
1.03527618041008295791
下図のように描くのが最適で、一辺の長さが \sqrt{6} - \sqrt{2} になります。
なお、この出力例の値は \sqrt{6}- \sqrt{2} と厳密には一致しませんが、誤差が 10^{-9} 以下なので正解として扱われます。
Score : 500 points
Problem Statement
Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are A and B.
Constraints
- 1 \leq A,B \leq 1000
- A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer.
Your output is considered correct if the absolute or relative error from the true answer is at most 10^{-9}.
Sample Input 1
1 1
Sample Output 1
1.03527618041008295791
The following figure shows an optimal drawing, with the side length of \sqrt{6} - \sqrt{2}.
Note that the sample output does not strictly match \sqrt{6}- \sqrt{2}, but the error is within 10^{-9}, so it is considered correct.