Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
非負整数 x に対し定義される関数 f(x) は以下の条件を満たします。
- f(0) = 1
- 任意の正整数 k に対し f(k) = k \times f(k-1)
このとき、 f(N) を求めてください。
制約
- N は 0 \le N \le 10 を満たす整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを整数として出力せよ。
入力例 1
2
出力例 1
2
f(2) = 2 \times f(1) = 2 \times 1 \times f(0) = 2 \times 1 \times 1 = 2 です。
入力例 2
3
出力例 2
6
f(3) = 3 \times f(2) = 3 \times 2 = 6 です。
入力例 3
0
出力例 3
1
入力例 4
10
出力例 4
3628800
Score : 100 points
Problem Statement
A function f(x) defined for non-negative integer x satisfies the following conditions:
- f(0) = 1;
- f(k) = k \times f(k-1) for all positive integers k.
Find f(N).
Constraints
- N is an integer such that 0 \le N \le 10.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample Input 1
2
Sample Output 1
2
We have f(2) = 2 \times f(1) = 2 \times 1 \times f(0) = 2 \times 1 \times 1 = 2.
Sample Input 2
3
Sample Output 2
6
We have f(3) = 3 \times f(2) = 3 \times 2 = 6.
Sample Input 3
0
Sample Output 3
1
Sample Input 4
10
Sample Output 4
3628800
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 社は、オンラインショップでグッズを販売しています。
高橋君はそこで N 種類の商品を購入することにしました。
1 以上 N 以下の整数 i について、i 種類目の商品は 1 個 P_i 円で、高橋君は Q_i 個購入します。
また、高橋君は送料を支払う必要があります。
送料は購入する商品の合計金額が S 円以上なら 0 円、そうでないならば K 円です。
高橋君が支払う金額は購入する商品の合計金額と送料の和です。
高橋君が支払う金額を求めてください。
制約
- 1\leq N\leq 100
- 1\leq S\leq 10000
- 1\leq K\leq 10000
- 1\leq P_i\leq 10000
- 1\leq Q_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S K P_1 Q_1 P_2 Q_2 \vdots P_N Q_N
出力
高橋君がオンラインショッピングで支払う金額を出力せよ。
入力例 1
2 2000 500 1000 1 100 6
出力例 1
2100
高橋君は 1 個 1000 円の商品を 1 個と、 1 個 100 円の商品を 6 つ購入します。
よって、購入する商品の合計金額は 1000\times 1+100\times 6=1600 円となります。
このとき購入する商品の合計金額は 2000 円未満であるため、送料は 500 円となります。
よって、高橋君の支払う金額は 1600+500=2100 円となります。
入力例 2
3 2000 500 1000 1 100 6 5000 1
出力例 2
6600
購入する商品の合計金額は 1000\times 1+100\times 6+5000\times 1=6600 円となります。
このとき購入する商品の合計金額は 2000 円以上であるため、送料は 0 円となります。
よって、高橋君の支払う金額は 6600+0=6600 円となります。
入力例 3
2 2000 500 1000 1 1000 1
出力例 3
2000
1 個あたりの価格が同じ商品が複数存在することもあります。
Score : 100 points
Problem Statement
AtCoder Inc. sells merchandise through its online shop.
Takahashi has decided to purchase N types of products from there.
For each integer i from 1 to N, the i-th type of product has a price of P_i yen each, and he will buy Q_i of this.
Additionally, he must pay a shipping fee.
The shipping fee is 0 yen if the total price of the products purchased is S yen or above, and K yen otherwise.
He will pay the total price of the products purchased plus the shipping fee.
Calculate the amount he will pay.
Constraints
- 1\leq N\leq 100
- 1\leq S\leq 10000
- 1\leq K\leq 10000
- 1\leq P_i\leq 10000
- 1\leq Q_i\leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N S K P_1 Q_1 P_2 Q_2 \vdots P_N Q_N
Output
Print the amount Takahashi will pay for online shopping.
Sample Input 1
2 2000 500 1000 1 100 6
Sample Output 1
2100
Takahashi buys one product for 1000 yen and six products for 100 yen each.
Thus, the total price of the products is 1000\times 1+100\times 6=1600 yen.
Since the total amount for the products is less than 2000 yen, the shipping fee will be 500 yen.
Therefore, the amount Takahashi will pay is 1600+500=2100 yen.
Sample Input 2
3 2000 500 1000 1 100 6 5000 1
Sample Output 2
6600
The total price of the products is 1000\times 1+100\times 6+5000\times 1=6600 yen.
Since the total amount for the products is not less than 2000 yen, the shipping fee will be 0 yen.
Therefore, the amount Takahashi will pay is 6600+0=6600 yen.
Sample Input 3
2 2000 500 1000 1 1000 1
Sample Output 3
2000
There may be multiple products with the same price per item.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
A に含まれる数を重複を除いて小さい順に出力してください。
制約
- 1\le N\le 100
- 1\le A_i\le 100
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
A に含まれる数を小さい順に C_1,C_2,\ldots , C_M として、以下の形式で出力せよ。
M C_1 C_2 \ldots C_M
入力例 1
4 3 1 4 1
出力例 1
3 1 3 4
A=(3,1,4,1) に含まれる数は小さい順に 1,3,4 の 3 つです。したがって、上記のように出力してください。
入力例 2
3 7 7 7
出力例 2
1 7
入力例 3
8 19 5 5 19 5 19 4 19
出力例 3
3 4 5 19
Score : 150 points
Problem Statement
An integer sequence A=(A_1,A_2,\ldots,A_N) of length N is given.
Output the numbers contained in A in ascending order, removing duplicates.
Constraints
- 1\le N\le 100
- 1\le A_i\le 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Let C_1,C_2,\ldots , C_M be the numbers contained in A in ascending order. Output in the following format:
M C_1 C_2 \ldots C_M
Sample Input 1
4 3 1 4 1
Sample Output 1
3 1 3 4
The numbers contained in A=(3,1,4,1) are 1,3,4 in ascending order, totalling 3 distinct numbers. Therefore, output as shown above.
Sample Input 2
3 7 7 7
Sample Output 2
1 7
Sample Input 3
8 19 5 5 19 5 19 4 19
Sample Output 3
3 4 5 19
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
縦 H マス \times 横 W マスのマス目があり、各マスに 1 つずつ英小文字が書き込まれています。 上から i 行目かつ左から j 列目のマスを (i,j) で表します。
マス目に書き込まれている英小文字は H 個の長さ W の文字列 S_1,S_2,\ldots, S_H によって与えられ、 S_i の j 文字目が、(i, j) に書き込まれた英小文字を表します。
マス目の中に、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる
場所がただ 1 つ存在します。
そのような場所を見つけ、そのマスの位置を出力の形式に従って出力してください。
ただし、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる場所とは、
5 つのマスの組 (A_1,A_2,A_3,A_4,A_5) であって、次をすべてみたすものをさします。
- A_1,A_2,A_3,A_4,A_5 に書き込まれた英小文字はそれぞれ
s,n,u,k,eである。 - 1\leq i\leq 4 について、A_i と A_{i+1} は頂点または辺を共有している。
- A_1,A_2,A_3,A_4,A_5 の中心はこの順に一直線上に等間隔で並んでいる。
制約
- 5\leq H\leq 100
- 5\leq W\leq 100
- H,W は整数
- S_i は英小文字のみからなる長さ W の文字列
- 与えられるマス目の中に条件をみたす場所がただ 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
次の形式にしたがって、5 行出力せよ。
条件をみたす場所のうち s, n, u, k, e が書かれたマスがそれぞれ (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) であるとき、
i 行目には R_i と C_i をこの順に空白区切りで出力せよ。
すなわち、以下のように出力せよ。
R_1 C_1 R_2 C_2 \vdots R_5 C_5
以下の入力例も参考にせよ。
入力例 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
出力例 1
5 2 5 3 5 4 5 5 5 6
この時、(A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) とすると、
それぞれのマスに書き込まれた英小文字は s, n, u, k, e であり、
1\leq i\leq 4 について、A_i と A_{i+1} は辺を共有しており、
各マスの中心は一直線上に存在するため、条件をみたしています。

入力例 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
出力例 2
5 5 4 4 3 3 2 2 1 1
(A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) が条件をみたしています。
例えば、(A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) は、1,2 つめの条件をみたしていますが、
マスの中心が一直線上に存在しないため、3 つめの条件をみたしていません。
入力例 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
出力例 3
9 3 8 3 7 3 6 3 5 3
Score : 250 points
Problem Statement
There is a grid with H horizontal rows and W vertical columns. Each cell has a lowercase English letter written on it. We denote by (i, j) the cell at the i-th row from the top and j-th column from the left.
The letters written on the grid are represented by H strings S_1,S_2,\ldots, S_H, each of length W. The j-th letter of S_i represents the letter written on (i, j).
There is a unique set of
contiguous cells (going vertically, horizontally, or diagonally) in the grid
with s, n, u, k, and e written on them in this order.
Find the positions of such cells and print them in the format specified in the Output section.
A tuple of five cells (A_1,A_2,A_3,A_4,A_5) is said to form
a set of contiguous cells (going vertically, horizontally, or diagonally) with s, n, u, k, and e written on them in this order
if and only if all of the following conditions are satisfied.
- A_1,A_2,A_3,A_4 and A_5 have letters
s,n,u,k, andewritten on them, respectively. - For all 1\leq i\leq 4, cells A_i and A_{i+1} share a corner or a side.
- The centers of A_1,A_2,A_3,A_4, and A_5 are on a common line at regular intervals.
Constraints
- 5\leq H\leq 100
- 5\leq W\leq 100
- H and W are integers.
- S_i is a string of length W consisting of lowercase English letters.
- The given grid has a unique conforming set of cells.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print five lines in the following format.
Let (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) be the cells in the sought set with s, n, u, k, and e written on them, respectively.
The i-th line should contain R_i and C_i in this order, separated by a space.
In other words, print them in the following format:
R_1 C_1 R_2 C_2 \vdots R_5 C_5
See also Sample Inputs and Outputs below.
Sample Input 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
Sample Output 1
5 2 5 3 5 4 5 5 5 6
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) satisfies the conditions.
Indeed, the letters written on them are s, n, u, k, and e;
for all 1\leq i\leq 4, cells A_i and A_{i+1} share a side;
and the centers of the cells are on a common line.

Sample Input 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
Sample Output 2
5 5 4 4 3 3 2 2 1 1
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) satisfies the conditions.
However, for example, (A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) violates the third condition because the centers of the cells are not on a common line, although it satisfies the first and second conditions.
Sample Input 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
Sample Output 3
9 3 8 3 7 3 6 3 5 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) があります。はじめ、A の要素は全て 0 です。
Q 個のクエリが与えられるので、順に処理してください。クエリは 2 種類あり、以下のいずれかの形式で与えられます。
1 x:A_x の値を 1 増やす。2:i=1,2,\ldots,N に対し、A_i \geq 1 ならば A_i の値を 1 減らす。
各クエリを処理した直後の A_1,A_2,\ldots,A_N のビット単位 \mathrm{XOR} を求めてください。
ビット単位 \mathrm{XOR} 演算とは
非負整数 A, B のビット単位 \mathrm{XOR} 、A \oplus B は、以下のように定義されます。
- A \oplus B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
一般に k 個の非負整数 p_1, p_2, p_3, \dots, p_k のビット単位 \mathrm{XOR} は (\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k) と定義され、これは p_1, p_2, p_3, \dots, p_k の順番によらないことが証明できます。
制約
- 1\le N\le 5\times 10^5
- 1\le Q\le 5\times 10^5
- 1\le x\le N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
各クエリは以下の 2 種類のいずれかの形式で与えられる。
1 x
2
出力
Q 行出力せよ。
i 行目 (1\le i\le Q) には、i 番目のクエリを処理した直後の A に対する A_1,A_2,\ldots,A_N のビット単位 \mathrm{XOR} を出力せよ。
入力例 1
2 5 1 2 1 2 1 1 2 2
出力例 1
1 2 3 1 0
1 番目のクエリを処理した後 A=(0,1) となります。0,1 のビット単位 \mathrm{XOR} は 1 なので、1 行目には 1 を出力してください。
2 番目のクエリを処理した後 A=(0,2) となります。0,2 のビット単位 \mathrm{XOR} は 2 なので、2 行目には 2 を出力してください。
3 番目のクエリを処理した後 A=(1,2) となります。1,2 のビット単位 \mathrm{XOR} は 3 なので、3 行目には 3 を出力してください。
4 番目のクエリを処理した後 A=(0,1) となります。0,1 のビット単位 \mathrm{XOR} は 1 なので、4 行目には 1 を出力してください。
5 番目のクエリを処理した後 A=(0,0) となります。0,0 のビット単位 \mathrm{XOR} は 0 なので、5 行目には 0 を出力してください。
入力例 2
3 8 1 2 1 3 1 1 1 2 1 1 2 1 3 1 1
出力例 2
1 0 1 2 1 0 1 2
Score : 300 points
Problem Statement
There is a length-N integer sequence A=(A_1,A_2,\ldots,A_N). Initially, all elements of A are 0.
You will be given Q queries, which should be processed in order. There are two types of queries, each given in one of the following formats:
1 x: Increase the value of A_x by 1.2: For each i=1,2,\ldots,N, if A_i \geq 1, decrease the value of A_i by 1.
Find the bitwise \mathrm{XOR} of A_1,A_2,\ldots,A_N immediately after processing each query.
What is bitwise \mathrm{XOR}?
The bitwise \mathrm{XOR} of non-negative integers A and B, denoted A \oplus B, is defined as follows:
- In the binary representation of A \oplus B, the digit in the 2^k (k \geq 0) place is 1 if exactly one of the digits in the 2^k place of A and B in their binary representations is 1, and 0 otherwise.
More generally, the bitwise \mathrm{XOR} of k non-negative integers p_1, p_2, p_3, \dots, p_k is defined as (\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k), and it can be proved that this value does not depend on the order of p_1, p_2, p_3, \dots, p_k.
Constraints
- 1\le N\le 5\times 10^5
- 1\le Q\le 5\times 10^5
- 1\le x\le N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Each query is given in one of the following 2 formats:
1 x
2
Output
Output Q lines.
The i-th line (1\le i\le Q) should contain the bitwise \mathrm{XOR} of A_1,A_2,\ldots,A_N for A immediately after processing the i-th query.
Sample Input 1
2 5 1 2 1 2 1 1 2 2
Sample Output 1
1 2 3 1 0
After processing the first query, A=(0,1). The bitwise \mathrm{XOR} of 0,1 is 1, so output 1 on the first line.
After processing the second query, A=(0,2). The bitwise \mathrm{XOR} of 0,2 is 2, so output 2 on the second line.
After processing the third query, A=(1,2). The bitwise \mathrm{XOR} of 1,2 is 3, so output 3 on the third line.
After processing the fourth query, A=(0,1). The bitwise \mathrm{XOR} of 0,1 is 1, so output 1 on the fourth line.
After processing the fifth query, A=(0,0). The bitwise \mathrm{XOR} of 0,0 is 0, so output 0 on the fifth line.
Sample Input 2
3 8 1 2 1 3 1 1 1 2 1 1 2 1 3 1 1
Sample Output 2
1 0 1 2 1 0 1 2