Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
-10^{18} 以上 10^{18} 以下の整数 X が与えられるので、\left\lfloor \dfrac{X}{10} \right\rfloor を出力してください。
注記
実数 x に対して、「x 以下の整数の中で最大の整数」を \left\lfloor x \right\rfloor と表します。たとえば \left\lfloor 4.7 \right\rfloor = 4, \left\lfloor -2.4 \right\rfloor = -3, \left\lfloor 5 \right\rfloor = 5 のようになります。(詳しくは入出力例にある説明を参考にしてください。)
制約
- -10^{18} \leq X \leq 10^{18}
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
X
出力
\left\lfloor \frac{X}{10} \right\rfloor を出力せよ。整数として出力する必要があることに注意せよ。
入力例 1
47
出力例 1
4
\frac{47}{10} = 4.7 以下の整数は、すべての負の整数および 0, 1, 2, 3, 4 です。この中で一番大きい整数は 4 なので、\left\lfloor \frac{47}{10} \right\rfloor = 4 となります。
入力例 2
-24
出力例 2
-3
\frac{-24}{10} = -2.4 以下の整数の中で一番大きい整数は -3 なので、 \left\lfloor \frac{-24}{10} \right\rfloor = -3 となります。
-2 は -2.4 よりも大きいので、条件を満たさないことに注意してください。
入力例 3
50
出力例 3
5
\frac{50}{10} = 5 以下の整数の中で一番大きい整数は 5 自身です。よって \left\lfloor \frac{50}{10} \right\rfloor = 5 となります。
入力例 4
-30
出力例 4
-3
上の例と同様に \left\lfloor \frac{-30}{10} \right\rfloor = -3 となります。
入力例 5
987654321987654321
出力例 5
98765432198765432
答えは 98765432198765432 となります。すべての桁が正しく合っているか確認しましょう。
なお、もしも自分で書いたプログラムが想定通りの挙動をしない場合は、使用しているプログラミング言語の仕様を調べてみることを推奨します。
また、自分の書いたコードがどのように動作するかを確認したい場合は問題文上部の「コードテスト」をご利用ください。
Score : 200 points
Problem Statement
Given an integer X between -10^{18} and 10^{18} (inclusive), print \left\lfloor \dfrac{X}{10} \right\rfloor.
Notes
For a real number x, \left\lfloor x \right\rfloor denotes "the maximum integer not exceeding x". For example, we have \left\lfloor 4.7 \right\rfloor = 4, \left\lfloor -2.4 \right\rfloor = -3, and \left\lfloor 5 \right\rfloor = 5. (For more details, please refer to the description in the Sample Input and Output.)
Constraints
- -10^{18} \leq X \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
X
Output
Print \left\lfloor \frac{X}{10} \right\rfloor. Note that it should be output as an integer.
Sample Input 1
47
Sample Output 1
4
The integers that do not exceed \frac{47}{10} = 4.7 are all the negative integers, 0, 1, 2, 3, and 4. The maximum integer among them is 4, so we have \left\lfloor \frac{47}{10} \right\rfloor = 4.
Sample Input 2
-24
Sample Output 2
-3
Since the maximum integer not exceeding \frac{-24}{10} = -2.4 is -3, we have \left\lfloor \frac{-24}{10} \right\rfloor = -3.
Note that -2 does not satisfy the condition, as -2 exceeds -2.4.
Sample Input 3
50
Sample Output 3
5
The maximum integer that does not exceed \frac{50}{10} = 5 is 5 itself. Thus, we have \left\lfloor \frac{50}{10} \right\rfloor = 5.
Sample Input 4
-30
Sample Output 4
-3
Just like the previous example, \left\lfloor \frac{-30}{10} \right\rfloor = -3.
Sample Input 5
987654321987654321
Sample Output 5
98765432198765432
The answer is 98765432198765432. Make sure that all the digits match.
If your program does not behave as intended, we recommend you checking the specification of the programming language you use.
If you want to check how your code works, you may use "Custom Test" above the Problem Statement.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
文字列 S が与えられます。S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力してください。
なお、相異なる 2 つの文字列 s = s_1 s_2 \ldots s_n と t = t_1 t_2 \ldots t_m について、それらが以下の条件のいずれかを満たすとき、辞書順で s \lt t であるとします。
- ある整数 i\ (1 \leq i \leq \min(n,m)) が存在し、s_i \lt t_i かつすべての整数 j\ (1 \leq j \lt i) について s_j=t_j
- すべての整数 i\ (1 \leq i \leq \min(n,m)) について s_i = t_i かつ、n \lt m
制約
- S は英小文字のみからなる長さ 1 以上 2 \times 10^5 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の各文字を並び替えて得られる文字列 S' のうち、辞書順で最小のものを出力せよ。
入力例 1
aba
出力例 1
aab
S= aba
を並び替えて得られる文字列は以下の 3 つが考えられます。
aba
aab
baa
この中で辞書順で最小のものは、aab
です。
入力例 2
zzzz
出力例 2
zzzz
Score : 200 points
Problem Statement
You are given a string S. Find the lexicographically smallest string S' obtained by permuting the characters of S.
Here, for different two strings s = s_1 s_2 \ldots s_n and t = t_1 t_2 \ldots t_m, s \lt t holds lexicographically when one of the conditions below is satisfied.
- There is an integer i\ (1 \leq i \leq \min(n,m)) such that s_i \lt t_i and s_j=t_j for all integers j\ (1 \leq j \lt i).
- s_i = t_i for all integers i\ (1 \leq i \leq \min(n,m)), and n \lt m.
Constraints
- S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
Print the lexicographically smallest string S' obtained by permuting the characters in S.
Sample Input 1
aba
Sample Output 1
aab
Three strings can be obtained by permuting aba
:
aba
aab
baa
The lexicographically smallest among them is aab
.
Sample Input 2
zzzz
Sample Output 2
zzzz
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