C - Flip,Flip, and Flip......

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

縦横に無限に広がるマス目があり、そのうちの連続する NM 列の領域のすべてのマスに表裏の区別できるカードが置かれています。 最初はすべてのカードが表を向いています。

以下の操作を、カードが置かれている全てのマスについて 1 度ずつ行います。

  • そのマスと辺または点で接する 8 つのマスと、そのマスの合計 9 マスについて、カードが存在するなら裏返す。

すべての操作を行った後の各カードの状態は操作を行う順番に依らないことが証明できます。 すべての操作を行った後、裏を向いているカードの枚数を求めてください。

制約

  • 1 \leq N,M \leq 10^9
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N M

出力

すべての操作を行った後、裏を向いているカードの枚数を出力せよ。


入力例 1

2 2

出力例 1

0

4 回の操作のうちのどの操作でも、すべてのカードを裏返します。よって、すべての操作を行った後は、すべてのカードが表を向いています。


入力例 2

1 7

出力例 2

5

すべての操作を行った後は、両端以外のカードが裏を向いています。


入力例 3

314 1592

出力例 3

496080

Score : 300 points

Problem Statement

There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.

We will perform the following operation once for each square contains a card:

  • For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.

It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Constraints

  • 1 \leq N,M \leq 10^9
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of cards that face down after all the operations.


Sample Input 1

2 2

Sample Output 1

0

We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.


Sample Input 2

1 7

Sample Output 2

5

After all the operations, all cards except at both ends face down.


Sample Input 3

314 1592

Sample Output 3

496080
D - Remainder Reminder

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 400

問題文

高橋君は、N 以下の正の整数の 2 つ組 (a,b) を持っていましたが、忘れてしまいました。 高橋君は、ab で割ったあまりが K 以上であったことを覚えています。 高橋君が持っていた組としてあるうるものの個数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 0 \leq K \leq N-1
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N K

出力

高橋君が持っていた組としてあるうるものの個数を出力せよ。


入力例 1

5 2

出力例 1

7

ありうる組は、(2,3),(5,3),(2,4),(3,4),(2,5),(3,5),(4,5)7 組です。


入力例 2

10 0

出力例 2

100

入力例 3

31415 9265

出力例 3

287927211

Score : 400 points

Problem Statement

Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.

Constraints

  • 1 \leq N \leq 10^5
  • 0 \leq K \leq N-1
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of possible pairs that he may have had.


Sample Input 1

5 2

Sample Output 1

7

There are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).


Sample Input 2

10 0

Sample Output 2

100

Sample Input 3

31415 9265

Sample Output 3

287927211
E - LISDL

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700

問題文

1,2,...,N を並べ替えてできる列であって、以下の条件を満たすものがあるかどうか判定し、あればその例をひとつ構成してください。

  • 最長増加部分列の長さは A である
  • 最長減少部分列の長さは B である

注釈

P の部分列とは P の要素をいくつか抜き出して元の順に並べてできる列のことを指し、 また、列 P の最長増加部分列とは、P の単調増加な部分列の中で列の長さが最大のものを指します。

同様に、列 P の最長減少部分列とは、P の単調減少な部分列の中で列の長さが最大のものを指します。

制約

  • 1 \leq N,A,B \leq 3\times 10^5
  • 入力はすべて整数である

入力

入力は以下の形式で標準入力から与えられる。

N A B

出力

条件を満たす列が存在しない場合、-1 を出力せよ。

そうでない場合、整数を N 個出力せよ。 i 個目には、構成した列の i 番目の要素を出力せよ。


入力例 1

5 3 2

出力例 1

2 4 1 5 3

{2,4,5} が最長増加部分列の一例、{4,3} が最長減少部分列の一例です。


入力例 2

7 7 1

出力例 2

1 2 3 4 5 6 7

入力例 3

300000 300000 300000

出力例 3

-1

Score : 700 points

Problem Statement

Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:

  • The length of its longest increasing subsequence is A.
  • The length of its longest decreasing subsequence is B.

If it exists, construct one such sequence.

Notes

A subsequence of a sequence P is a sequence that can be obtained by extracting some of the elements in P without changing the order.

A longest increasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically increasing.

Similarly, a longest decreasing subsequence of a sequence P is a sequence with the maximum length among the subsequences of P that are monotonically decreasing.

Constraints

  • 1 \leq N,A,B \leq 3\times 10^5
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

If there are no sequences that satisfy the conditions, print -1.

Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed.


Sample Input 1

5 3 2

Sample Output 1

2 4 1 5 3

One longest increasing subsequence of this sequence is {2,4,5}, and one longest decreasing subsequence of it is {4,3}.


Sample Input 2

7 7 1

Sample Output 2

1 2 3 4 5 6 7

Sample Input 3

300000 300000 300000

Sample Output 3

-1
F - Strange Nim

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 900

問題文

高橋君と青木君は、石取りゲームをしています。最初、山が N 個あり、i 個目の山には A_i 個の石があり、整数 K_i が定まっています。

高橋君と青木君は、高橋君から始めて、交互に以下の操作を繰り返します。

  • 山を 1 つ選ぶ。i 個目の山を選び、その山に X 個の石が残っている場合、1 個以上 floor(X/K_i) 個以下の任意の個数の石を i 個目の山から取り除く。

先に操作ができなくなったプレイヤーが負けです。両者最善を尽くしたとき、どちらのプレイヤーが勝つか判定してください。 ただし、floor(x)x 以下の最大の整数を表します。

制約

  • 1 \leq N \leq 200
  • 1 \leq A_i,K_i \leq 10^9
  • 入力はすべて整数である

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 K_1
:
A_N K_N

出力

高橋君が勝つなら Takahashi を、青木君が勝つなら Aoki を出力せよ。


入力例 1

2
5 2
3 3

出力例 1

Aoki

最初、1 個目の山からは floor(5/2)=2 個まで、2 個目の山からは floor(3/3)=1 個までの石を一度に取り除くことができます。

  • 高橋君が最初に 1 個目の山から 2 個の石を取ると、1 個目の山からは floor(3/2)=1 個まで、2 個目の山からは floor(3/3)=1 個までの石を一度に取り除くことができるようになります。
  • 次に、青木君が 2 個目の山から 1 個の石を取ると、1 個目の山からは floor(3/2)=1 個までの石を取り除くことができ、2 個目の山からは (floor(2/3)=0 より) 石を取り除くことができなくなります。
  • 次に、高橋君が 1 個目の山から 1 個の石を取ると、1 個目の山からは floor(2/2)=1 個までの石を一度に取り除くことができるようになります。2 個目の山からは石を取り除くことはできません。
  • 次に、青木君が 1 個目の山から 1 個の石を取ると、1 個目の山からは floor(1/2)=0 個までの石を一度に取り除くことができるようになります。2 個目の山からは石を取り除くことはできません。

これ以上の操作はできないため、青木君の勝ちです。高橋君がそれ以外の行動をした場合も、青木君はうまく行動を選ぶことで勝つことができます。


入力例 2

3
3 2
4 3
5 1

出力例 2

Takahashi

入力例 3

3
28 3
16 4
19 2

出力例 3

Aoki

入力例 4

4
3141 59
26535 897
93 23
8462 64

出力例 4

Takahashi

Score : 900 points

Problem Statement

Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles of stones, and the i-th pile contains A_i stones and has an associated integer K_i.

Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following operation:

  • Choose a pile. If the i-th pile is selected and there are X stones left in the pile, remove some number of stones between 1 and floor(X/K_i) (inclusive) from the pile.

The player who first becomes unable to perform the operation loses the game. Assuming that both players play optimally, determine the winner of the game. Here, floor(x) represents the largest integer not greater than x.

Constraints

  • 1 \leq N \leq 200
  • 1 \leq A_i,K_i \leq 10^9
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 K_1
:
A_N K_N

Output

If Takahashi will win, print Takahashi; if Aoki will win, print Aoki.


Sample Input 1

2
5 2
3 3

Sample Output 1

Aoki

Initially, from the first pile at most floor(5/2)=2 stones can be removed at a time, and from the second pile at most floor(3/3)=1 stone can be removed at a time.

  • If Takahashi first takes two stones from the first pile, from the first pile at most floor(3/2)=1 stone can now be removed at a time, and from the second pile at most floor(3/3)=1 stone can be removed at a time.
  • Then, if Aoki takes one stone from the second pile, from the first pile at most floor(3/2)=1 stone can be removed at a time, and from the second pile no more stones can be removed (since floor(2/3)=0).
  • Then, if Takahashi takes one stone from the first pile, from the first pile at most floor(2/2)=1 stone can now be removed at a time, and from the second pile no more stones can be removed.
  • Then, if Aoki takes one stone from the first pile, from the first pile at most floor(1/2)=0 stones can now be removed at a time, and from the second pile no more stones can be removed.

No more operation can be performed, thus Aoki wins. If Takahashi plays differently, Aoki can also win by play accordingly.


Sample Input 2

3
3 2
4 3
5 1

Sample Output 2

Takahashi

Sample Input 3

3
28 3
16 4
19 2

Sample Output 3

Aoki

Sample Input 4

4
3141 59
26535 897
93 23
8462 64

Sample Output 4

Takahashi