C - Go Home

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

無限に左右に伸びている数直線上の 0 の地点に時刻 0 にカンガルーがいます。 カンガルーは時刻 i-1 から i にかけて、なにもしないか、もしくは長さがちょうど i のジャンプを、左右どちらかの方向を選んで行えます。 つまり、時刻 i-1 に座標 x にいたとすると、時刻 i には x-i, x, x+i のどれかに存在することが出来ます。 カンガルーの家は座標 X にあります。カンガルーはできるだけ早く座標 X まで移動しようとしています。 カンガルーが座標 X に到着する時刻の最小値を求めてください。

制約

  • X は整数
  • 1≦X≦10^9

入力

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

X

出力

カンガルーが座標 X に到着する時刻の最小値を出力せよ。


入力例 1

6

出力例 1

3

3 回右にジャンプすると時刻 3 に家にたどり着けて、これが最小です。


入力例 2

2

出力例 2

2

時刻 0 にはなにもせず、時刻 1 に右にジャンプすることで時刻 2 に家にたどり着けます。


入力例 3

11

出力例 3

5

Score : 200 points

Problem Statement

There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.

Constraints

  • X is an integer.
  • 1≤X≤10^9

Input

The input is given from Standard Input in the following format:

X

Output

Print the earliest possible time for the kangaroo to reach coordinate X.


Sample Input 1

6

Sample Output 1

3

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.


Sample Input 2

2

Sample Output 2

2

He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.


Sample Input 3

11

Sample Output 3

5
D - No Need

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 600

問題文

シカのAtCoDeerくんは正整数が書かれたカードを N 枚持っています。i(1≦i≦N) 枚目に書かれている数は a_i です。 AtCoDeerくんは大きい数が好きなので、カードに書かれた数の総和が K 以上になるようなカードの部分集合をよい集合と呼びます。

そして、各カード i に対して、そのカードが不必要かどうかを次のように判定します。

  • 「カード i を含む任意のよい集合に対して、その集合からカード i を除いたものもよい集合」 ならカード i不必要
  • それ以外の場合は、不必要でない

不必要なカードの枚数を求めてください。ただし、それぞれの判定は独立に行われ、不必要だからと言ってカードが途中で捨てられたりすることはありません。

制約

  • 入力は全て整数
  • 1≦N≦5000
  • 1≦K≦5000
  • 1≦a_i≦10^9 (1≦i≦N)

部分点

  • N,K≦400 を満たすデータセットに正解した場合は、部分点として 300 点が与えられる。

入力

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

N K
a_1 a_2 ... a_N

出力

不必要なカードの枚数を出力せよ。


入力例 1

3 6
1 4 3

出力例 1

1

よい集合は {2,3} と {1,2,3} の二つです。

カード 1 を含むよい集合は {1,2,3} しかなく、これから 1 を取り除いた {2,3} もよい集合なので、カード 1 は不必要です。

また、よい集合である {2,3} から 2 を取り除いた集合 {3} はよい集合ではないため、カード 2 は不必要ではありません。

カード 3 も同様に不必要ではないため、答えは 1 です。


入力例 2

5 400
3 1 4 1 5

出力例 2

5

この場合よい集合は存在しないため、全てのカードは不必要となります。


入力例 3

6 20
10 4 3 10 25 2

出力例 3

3

Score : 600 points

Problem Statement

AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.

Then, for each card i, he judges whether it is unnecessary or not, as follows:

  • If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
  • Otherwise, card i is NOT unnecessary.

Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.

Constraints

  • All input values are integers.
  • 1≤N≤5000
  • 1≤K≤5000
  • 1≤a_i≤10^9 (1≤i≤N)

Partial Score

  • 300 points will be awarded for passing the test set satisfying N,K≤400.

Input

The input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the number of the unnecessary cards.


Sample Input 1

3 6
1 4 3

Sample Output 1

1

There are two good sets: {2,3} and {1,2,3}.

Card 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.

For card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.

Neither is card 3 for a similar reason, hence the answer is 1.


Sample Input 2

5 400
3 1 4 1 5

Sample Output 2

5

In this case, there is no good set. Therefore, all the cards are unnecessary.


Sample Input 3

6 20
10 4 3 10 25 2

Sample Output 3

3
E - NarrowRectangles

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 1000

問題文

シカのAtCoDeerくんは縦の長さが 1 の細長い長方形が N 個机に置いてあるのを見つけました。 机を二次元平面とみなすと、以下の図のように、i(1≦i≦N) 個目の長方形は、縦は [i-1,i] の範囲を、横は [l_i,r_i] の範囲を占めています。

AtCoDeerくんはこの長方形をそれぞれ横に動かすことで、全ての長方形を連結にしようと考えました。 各長方形は横に距離 x 動かすのに x のコストがかかります。 全ての長方形を連結にするのに必要なコストの最小値を求めてください。 問題の制約のもとでこの値は整数になることが証明できます。

制約

  • 入力は全て整数である。
  • 1≦N≦10^5
  • 1≦l_i<r_i≦10^9

部分点

  • 1≦N≦400, 1≦l_i<r_i≦400 を満たすデータセットに正解した場合は、部分点として 300 点が与えられる。

入力

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

N
l_1 r_1
l_2 r_2
:
l_N r_N

出力

必要なコストの最小値を出力せよ。


入力例 1

3
1 3
5 7
1 3

出力例 1

2

2 個目の長方形を左に 2 動かすのが最小です。


入力例 2

3
2 5
4 6
1 4

出力例 2

0

はじめから連結になっているため、動かす必要はありません。


入力例 3

5
999999999 1000000000
1 2
314 315
500000 500001
999999999 1000000000

出力例 3

1999999680

入力例 4

5
123456 789012
123 456
12 345678901
123456 789012
1 23

出力例 4

246433

入力例 5

1
1 400

出力例 5

0

Score : 1000 points

Problem Statement

AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:

AtCoDeer will move these rectangles horizontally so that all the rectangles are connected. For each rectangle, the cost to move it horizontally by a distance of x, is x. Find the minimum cost to achieve connectivity. It can be proved that this value is always an integer under the constraints of the problem.

Constraints

  • All input values are integers.
  • 1≤N≤10^5
  • 1≤l_i<r_i≤10^9

Partial Score

  • 300 points will be awarded for passing the test set satisfying 1≤N≤400 and 1≤l_i<r_i≤400.

Input

The input is given from Standard Input in the following format:

N
l_1 r_1
l_2 r_2
:
l_N r_N

Output

Print the minimum cost to achieve connectivity.


Sample Input 1

3
1 3
5 7
1 3

Sample Output 1

2

The second rectangle should be moved to the left by a distance of 2.


Sample Input 2

3
2 5
4 6
1 4

Sample Output 2

0

The rectangles are already connected, and thus no move is needed.


Sample Input 3

5
999999999 1000000000
1 2
314 315
500000 500001
999999999 1000000000

Sample Output 3

1999999680

Sample Input 4

5
123456 789012
123 456
12 345678901
123456 789012
1 23

Sample Output 4

246433

Sample Input 5

1
1 400

Sample Output 5

0
F - HonestOrUnkind

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 1300

問題文

これはインタラクティブな問題です。

シカのAtCoDeerくんは 0~N-1 の番号がついた N 人の人が集まっているのを見つけました。 この内 A 人は正直者で、残りの B(=N-A) 人は不親切な人です。 N 人の人は全員、誰が正直者で、誰が不親切な人かを把握しています。 一方、AtCoDeerくんは、正直者A 人いて不親切な人B 人いることしか知りません。 そこで、AtCoDeerくんはこれらの N 人に質問をして、正直者を全員特定しようとしています。 一回の質問では、AtCoDeerくんは、0≦a,b≦N-1 なる a, b を選んで、a さんに「b さんは正直者ですか?」という質問をします。

正直者は、質問に対し常に Yes か No の正しい答えを返します。 一方、不親切な人は、質問に対し Yes か No のどちらかを恣意的に選んで返します。 つまり、常に嘘をついたり、半分の確率でランダムに答えるといった単純なアルゴリズムではない可能性があります。

AtCoDeerくんは高々 2N 回質問をすることができます。質問は順番に行われ、以前の質問の結果から次の質問を決めることが出来ます。

正直者を全員特定してください。 不可能な場合(正確には、どのような 2N 回の質問をしようと、不親切な人たちがうまく返答することで、正直者の集合としてありうるものが2つ以上存在するようにできる場合)は、その旨を出力してください。

制約

  • 1≦A,B≦2000

入出力

最初に、標準入力から AB が以下の形式で与えられる:

A B

もし特定が不可能な場合は、即座に次のように出力し、プログラムを終了しなければならない。:

Impossible

それ以外の場合は、次に、クエリを質問する。 各クエリは、標準出力に以下の形式で出力されなければならない:

? a b

ここで ab0 以上 N-1 以下の整数でなければならない。

次に、クエリの答えが標準入力から以下の形式で与えられる:

ans

ここで ansY または N である。 Y のときは質問の答えが Yes であることを、N のときは No であることを表す。

最後に、答えを以下の形式で出力しなければならない:

! s_0s_1...s_{N-1}

ここで s_ii 番の人が正直者なら 1不親切な人なら 0 でなければならない。

ジャッジ

  • 出力のあと、標準出力を flush しなければならない。 そうでないときは TLE の可能性がある。
  • 答えを出力した後、プログラムをすぐに終了しなければならない。そうでないときの挙動は定義されていない。
  • 出力の答えが間違っている場合の挙動は定義されていない (WAとは限らない)。

サンプル

このサンプルでは A = 2, B = 1 で、答えは 101 である。

Input Output
2 1
? 0 1
N
? 0 2
Y
? 1 0
Y
? 2 0
Y
? 2 2
Y
! 101

次のサンプルでは A = 1, B = 2 で、答えは Impossible である。

Input Output
1 2
Impossible

Score : 1300 points

Problem Statement

This is an interactive task.

AtCoDeer the deer came across N people. For convenience, the people are numbered 0 through N-1. Among them, A are honest and the remaining B(=N-A) are unkind. All of these N people know who are honest and who are unkind, but AtCoDeer only knows that there are A honest and B unkind people. He is trying to identify all of the honest people by asking questions to these N people. For one question, AtCoDeer selects a and b (0≤a,b≤N-1), and asks person a the following question: "Is person b honest?"

An honest person will always answer correctly by "Yes" or "No". An unkind person, however, will answer by selecting "Yes" or "No" arbitrarily. That is, the algorithm used by an unkind person may not be simple one such as always lying or giving random fifty-fifty answers.

AtCoDeer can ask at most 2N questions. He will ask questions one by one, and the responses to the previous questions can be used when deciding the next question to ask.

Identify all of the honest people. If it is impossible (more formally, if, for any strategy of asking 2N questions, there exists a strategy for unkind people to answer the questions so that there are two or more possible sets of the honest people), report that fact.

Constraints

  • 1≤A,B≤2000

Input and Output

First, A and B are given from Standard Input in the following format:

A B

If identifying the honest people is impossible, the program must immediately print the following output and terminate itself:

Impossible

Otherwise, the program shall ask questions. Each question must be written to Standard Output in the following format:

? a b

Here, a and b must be integers between 0 and N-1 (inclusive). The response to the question will be given from Standard Input in the following format:

ans

Here, ans is either Y or N. Y represents "Yes"; N represents "No".

Finally, the answer must be written to Standard Output in the following format:

! s_0s_1...s_{N-1}

Here, s_i must be 1 if person i is honest, and 0 if person i is unkind.

Judgement

  • After each output, you must flush Standard Output. Otherwise you may get TLE.
  • After you print the answer, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.
  • When your output is invalid or incorrect, the behavior of the judge is undefined (it does not necessarily give WA).

Samples

In the following sample, A = 2, B = 1, and the answer is 101.

Input Output
2 1
? 0 1
N
? 0 2
Y
? 1 0
Y
? 2 0
Y
? 2 2
Y
! 101

In the following sample, A = 1, B = 2, and the answer is Impossible.

Input Output
1 2
Impossible