Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 300 点
問題文
長さ N の整数列 a_1,a_2,...,a_N が与えられます。
各 1≤i≤N に対し、a_i に 1 足すか、1 引くか、なにもしないかの三つの操作からどれか一つを選んで行います。
この操作の後、ある整数 X を選んで、a_i=X となる i の個数を数えます。
うまく操作を行い、X を選ぶことで、この個数を最大化してください。
制約
- 1≤N≤10^5
- 0≤a_i<10^5 (1≤i≤N)
- a_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N a_1 a_2 .. a_N
出力
うまく操作を行い、X を選んだ時の a_i=X なる i の個数の最大値を出力せよ。
入力例 1
7 3 1 4 1 5 9 2
出力例 1
4
例えば操作後の数列を 2,2,3,2,6,9,2 とすることができて、X=2 とすると 4 を得ることができ、これが最大です。
入力例 2
10 0 1 2 3 4 5 6 7 8 9
出力例 2
3
入力例 3
1 99999
出力例 3
1
Score : 300 points
Problem Statement
You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that a_i=X.
Maximize this count by making optimal choices.
Constraints
- 1≤N≤10^5
- 0≤a_i<10^5 (1≤i≤N)
- a_i is an integer.
Input
The input is given from Standard Input in the following format:
N a_1 a_2 .. a_N
Output
Print the maximum possible number of i such that a_i=X.
Sample Input 1
7 3 1 4 1 5 9 2
Sample Output 1
4
For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.
Sample Input 2
10 0 1 2 3 4 5 6 7 8 9
Sample Output 2
3
Sample Input 3
1 99999
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 400 点
問題文
1,2,..,N からなる順列 p_1,p_2,..,p_N が与えられます。 次の操作を何回か (0回でもよい) 行うことが出来ます。
操作: 順列で隣り合う二つの数を選んでスワップする。
何回か操作を行って、任意の 1≤i≤N に対して p_i ≠ i となるようにしたいです。 必要な操作の最小回数を求めてください。
制約
- 2≤N≤10^5
- p_1,p_2,..,p_N は 1,2,..,N の順列である。
入力
入力は以下の形式で標準入力から与えられる。
N p_1 p_2 .. p_N
出力
必要な操作の最小回数を出力せよ。
入力例 1
5 1 4 3 5 2
出力例 1
2
1 と 4 を入れ替え、その後 1 と 3 を入れ替えることで p は 4,3,1,5,2 となり、これは条件を満たします。 これが最小回数なので、答えは 2 となります。
入力例 2
2 1 2
出力例 2
1
1 と 2 を入れ替えれば条件を満たします。
入力例 3
2 2 1
出力例 3
0
初めから条件を満たしています。
入力例 4
9 1 2 4 9 5 8 7 3 6
出力例 4
3
Score : 400 points
Problem Statement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
Constraints
- 2≤N≤10^5
- p_1,p_2,..,p_N is a permutation of 1,2,..,N.
Input
The input is given from Standard Input in the following format:
N p_1 p_2 .. p_N
Output
Print the minimum required number of operations
Sample Input 1
5 1 4 3 5 2
Sample Output 1
2
Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition. This is the minimum possible number, so the answer is 2.
Sample Input 2
2 1 2
Sample Output 2
1
Swapping 1 and 2 satisfies the condition.
Sample Input 3
2 2 1
Sample Output 3
0
The condition is already satisfied initially.
Sample Input 4
9 1 2 4 9 5 8 7 3 6
Sample Output 4
3
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 700 点
問題文
二次元平面上に配置された N 個の点 (x_i,y_i) が与えられます。 N 点の部分集合 S であって、凸多角形をなすものを考えます。 ここで点集合Sが凸多角形をなすとは、 頂点の集合が S と一致するような正の面積の凸多角形が存在することとします。ただし、凸多角形の内角は全て 180° 未満である必要があります。
例えば下図では、S として {A,C,E}, {B,D,E} などは認められますが、{A,C,D,E}, {A,B,C,E}, {A,B,C}, {D,E}, {} などは認められません。
S に対し、N 個の点のうち S の凸包の内部と境界 (頂点も含む) に含まれる点の個数を n とおき、 S のスコアを、2^{n-|S|} と定義します。
凸多角形をなすような考えうる全ての S に対してスコアを計算し、これらを足し合わせたものを求めてください。
ただし答えはとても大きくなりうるので、998244353 で割った余りをかわりに求めてください。
制約
- 1≤N≤200
- 0≤x_i,y_i<10^4 (1≤i≤N)
- i≠j なら x_i≠x_j または y_i≠y_j
- x_i,y_i は整数
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 : x_N y_N
出力
スコアの総和を 998244353 で割った余りを出力せよ。
入力例 1
4 0 0 0 1 1 0 1 1
出力例 1
5
S として三角形(をなす点集合)が 4 つと四角形が 1 つとれます。どれもスコアは 2^0=1 となるので、答えは 5 です。
入力例 2
5 0 0 0 1 0 2 0 3 1 1
出力例 2
11
スコア 1 の三角形が 3 つ、スコア 2 の三角形が2つ、スコア 4 の三角形が 1 つあるので、答えは 11 です。
入力例 3
1 3141 2718
出力例 3
0
S として考えられるものがないので、答えは 0 です。
Score : 700 points
Problem Statement
You are given N points (x_i,y_i) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has the same set of vertices as S. All the interior angles of the polygon must be strictly less than 180°.
For example, in the figure above, {A,C,E} and {B,D,E} form convex polygons; {A,C,D,E}, {A,B,C,E}, {A,B,C}, {D,E} and {} do not.
For a given set S, let n be the number of the points among the N points that are inside the convex hull of S (including the boundary and vertices). Then, we will define the score of S as 2^{n-|S|}.
Compute the scores of all possible sets S that form convex polygons, and find the sum of all those scores.
However, since the sum can be extremely large, print the sum modulo 998244353.
Constraints
- 1≤N≤200
- 0≤x_i,y_i<10^4 (1≤i≤N)
- If i≠j, x_i≠x_j or y_i≠y_j.
- x_i and y_i are integers.
Input
The input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 : x_N y_N
Output
Print the sum of all the scores modulo 998244353.
Sample Input 1
4 0 0 0 1 1 0 1 1
Sample Output 1
5
We have five possible sets as S, four sets that form triangles and one set that forms a square. Each of them has a score of 2^0=1, so the answer is 5.
Sample Input 2
5 0 0 0 1 0 2 0 3 1 1
Sample Output 2
11
We have three "triangles" with a score of 1 each, two "triangles" with a score of 2 each, and one "triangle" with a score of 4. Thus, the answer is 11.
Sample Input 3
1 3141 2718
Sample Output 3
0
There are no possible set as S, so the answer is 0.
Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 700 点
問題文
パーツAとパーツBからなる砂時計があります。これらのパーツにはいくらかの砂が入っています。 砂時計を置くときはパーツAとパーツBのどちらかが上になり、そうでないほうが下になります。
1 秒間に 1 [g] の砂が上にあるパーツから下にあるパーツに落ちます。 ただし、上のパーツにもう砂が残っていない場合は砂は落ちません。
はじめ時刻 0 にパーツAが上にあり、a [g] の砂がパーツAに入っていて、X-a [g] の砂がパーツBに入っています(すなわち、合計 X [g] の砂が入っています)。
時刻 r_1,r_2, .., r_K に砂時計をひっくり返します。この操作は瞬間的に行われ、時間はかからないものとします。なお、時刻 t とは時刻 0 の t 秒後を指します。
クエリが Q 個与えられます。 各クエリは (t_i,a_i) の形をしています。 各クエリに対し、a=a_i だとして、時刻 t_i にパーツAに入っている砂の量が何gか答えてください。
制約
- 1≤X≤10^9
- 1≤K≤10^5
- 1≤r_1<r_2< .. <r_K≤10^9
- 1≤Q≤10^5
- 0≤t_1<t_2< .. <t_Q≤10^9
- 0≤a_i≤X (1≤i≤Q)
- 入力値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
X K r_1 r_2 .. r_K Q t_1 a_1 t_2 a_2 : t_Q a_Q
出力
各クエリの答えを 1 行ごとに出力せよ。
入力例 1
180 3 60 120 180 3 30 90 61 1 180 180
出力例 1
60 1 120
1 つめのクエリでは、はじめパーツAに 90 [g] 入っていた砂が 30 [g] 減り、60 [g] になります。 2 つめのクエリでは、はじめパーツAに入っていた 1 [g] の砂がパーツBに落ちた後、59 秒間変化は起こりません。ここで砂時計をひっくり返し、その 1 秒後にパーツAに入っている砂の量を聞かれているため、答えは 1 [g] になります。
入力例 2
100 1 100000 4 0 100 90 100 100 100 101 100
出力例 2
100 10 0 0
どのクエリでもはじめにパーツAに入っている砂は 100 [g] で、砂時計をひっくり返す前の時間での値を聞いています。
入力例 3
100 5 48 141 231 314 425 7 0 19 50 98 143 30 231 55 342 0 365 100 600 10
出力例 3
19 52 91 10 58 42 100
Score : 700 points
Problem Statement
We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X-a grams of sand (for a total of X grams).
We will turn over the sandglass at time r_1,r_2,..,r_K. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (t_i,a_i). For each query, assume that a=a_i and find the amount of sand that would be contained in bulb A at time t_i.
Constraints
- 1≤X≤10^9
- 1≤K≤10^5
- 1≤r_1<r_2< .. <r_K≤10^9
- 1≤Q≤10^5
- 0≤t_1<t_2< .. <t_Q≤10^9
- 0≤a_i≤X (1≤i≤Q)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X K r_1 r_2 .. r_K Q t_1 a_1 t_2 a_2 : t_Q a_Q
Output
For each query, print the answer in its own line.
Sample Input 1
180 3 60 120 180 3 30 90 61 1 180 180
Sample Output 1
60 1 120
In the first query, 30 out of the initial 90 grams of sand will drop from bulb A, resulting in 60 grams. In the second query, the initial 1 gram of sand will drop from bulb A, and nothing will happen for the next 59 seconds. Then, we will turn over the sandglass, and 1 second after this, bulb A contains 1 gram of sand at the time in question.
Sample Input 2
100 1 100000 4 0 100 90 100 100 100 101 100
Sample Output 2
100 10 0 0
In every query, the upper bulb initially contains 100 grams, and the question in time comes before we turn over the sandglass.
Sample Input 3
100 5 48 141 231 314 425 7 0 19 50 98 143 30 231 55 342 0 365 100 600 10
Sample Output 3
19 52 91 10 58 42 100