Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 次元座標平面があります。x 軸正方向を右向き、y 軸正方向を上向きとします。
この平面上に自己交差のない四角形があります。
4 つの頂点の座標は反時計回りに (A_x,A_y),(B_x,B_y),(C_x,C_y),(D_x,D_y) です。
この四角形が凸であるか判定してください。
なお、四角形の 4 つの内角が全て 180 度未満であるとき、かつ、その時に限り、その四角形は凸であるといいます。
制約
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- 入力に含まれる値は全て整数である
- 与えられる 4 点は四角形の 4 頂点を反時計回りに並べたものである
- 与えられる 4 点のなす四角形は自己交差がなく退化していない。すなわち
- どの 2 頂点も同じ座標にない
- どの 3 頂点も同一直線上にない
- 隣接しない 2 辺は共有点を持たない
入力
入力は以下の形式で標準入力から与えられる。
A_x A_y B_x B_y C_x C_y D_x D_y
出力
与えられる四角形が凸なら Yes、凸でないなら No を出力せよ。
入力例 1
0 0 1 0 1 1 0 1
出力例 1
Yes
与えられた四角形は正方形であり、4 つの内角は全て 90 度です。したがって、この四角形は凸です。

入力例 2
0 0 1 1 -1 0 1 -1
出力例 2
No
角 A が 270 度です。したがって、この四角形は凸ではありません。

Score : 300 points
Problem Statement
Consider a two-dimensional coordinate plane, where the x-axis is oriented to the right, and the y-axis is oriented upward.
In this plane, there is a quadrilateral without self-intersection.
The coordinates of the four vertices are (A_x,A_y), (B_x,B_y), (C_x,C_y), and (D_x,D_y), in counter-clockwise order.
Determine whether this quadrilateral is convex.
Here, a quadrilateral is convex if and only if all four interior angles are less than 180 degrees.
Constraints
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- All values in input are integers.
- The given four points are the four vertices of a quadrilateral in counter-clockwise order.
- The quadrilateral formed by the given four points has no self-intersection and is non-degenerate. That is,
- no two vertices are at the same coordinates;
- no three vertices are colinear; and
- no two edges that are not adjacent have a common point.
Input
Input is given from Standard Input in the following format:
A_x A_y B_x B_y C_x C_y D_x D_y
Output
If the given quadrilateral is convex, print Yes; otherwise, print No.
Sample Input 1
0 0 1 0 1 1 0 1
Sample Output 1
Yes
The given quadrilateral is a square, whose four interior angles are all 90 degrees. Thus, this quadrilateral is convex.

Sample Input 2
0 0 1 1 -1 0 1 -1
Sample Output 2
No
The angle A is 270 degrees. Thus, this quadrilateral is not convex.

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英大文字からなる長さ 3 の文字列 T が、英小文字からなる文字列 S の 空港コード であるとは、 T が S から次のいずれかの方法により得られることとします。
- S の長さ 3 の(連続とは限らない)部分列をとり、それを英大文字に変換したものを T とする
- S の長さ 2 の(連続とは限らない)部分列をとり、それを英大文字に変換したものの末尾に
Xを追加したものを T とする
文字列 S, T が与えられるので、 T が S の空港コードであるか判定してください。
制約
- S は英小文字からなる長さ 3 以上 10^5 以下の文字列
- T は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の空港コードであるならば Yes を、そうでないならば No を出力せよ。
入力例 1
narita NRT
出力例 1
Yes
narita の部分列 nrt を英大文字に変換した文字列 NRT は、 narita の空港コードです。
入力例 2
losangeles LAX
出力例 2
Yes
losangeles の部分列 la を英大文字に変換した文字列 LA の末尾に X を追加したもの LAX は、 losangeles の空港コードです。
入力例 3
snuke RNG
出力例 3
No
Score: 300 points
Problem Statement
A string T of length 3 consisting of uppercase English letters is an airport code for a string S of lowercase English letters if and only if T can be derived from S by one of the following methods:
- Take a subsequence of length 3 from S (not necessarily contiguous) and convert it to uppercase letters to form T.
- Take a subsequence of length 2 from S (not necessarily contiguous), convert it to uppercase letters, and append
Xto the end to form T.
Given strings S and T, determine if T is an airport code for S.
Constraints
- S is a string of lowercase English letters with a length between 3 and 10^5, inclusive.
- T is a string of uppercase English letters with a length of 3.
Input
The input is given from Standard Input in the following format:
S T
Output
Print Yes if T is an airport code for S, and No otherwise.
Sample Input 1
narita NRT
Sample Output 1
Yes
The subsequence nrt of narita, when converted to uppercase, forms the string NRT, which is an airport code for narita.
Sample Input 2
losangeles LAX
Sample Output 2
Yes
The subsequence la of losangeles, when converted to uppercase and appended with X, forms the string LAX, which is an airport code for losangeles.
Sample Input 3
snuke RNG
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
数直線上に N 個の村があります。i 番目の村は座標 X_i にあり、P_i 人の村人がいます。
Q 個のクエリに答えてください。i 番目のクエリは以下の形式です。
- 整数 L_i,R_i が与えられる。座標が L_i 以上 R_i 以下の村に住んでいる村人の人数の総数を求めよ。
制約
- 1\leq N,Q\leq 2\times 10^5
- -10^9\leq X_1 < X_2 < \ldots < X_N \leq 10^9
- 1\leq P_i\leq 10^9
- -10^9\leq L_i \leq R_i \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N X_1 \ldots X_N P_1 \ldots P_N Q L_1 R_1 \vdots L_Q R_Q
出力
Q 行出力せよ。
i\ (1\leq i \leq Q) 行目には、i 番目のクエリに対する答えを出力せよ。
入力例 1
4 1 3 5 7 1 2 3 4 4 1 1 2 6 0 10 2 2
出力例 1
1 5 10 0
1 番目のクエリについて考えます。座標が 1 以上 1 以下の村は、座標 1 にある村で、村人は 1 人います。よって答えは 1 です。
2 番目のクエリについて考えます。座標が 2 以上 6 以下の村は、座標 3 にある村と座標 5 にある村で、村人はそれぞれ 2 人と 3 人います。よって答えは 2+3=5 です。
入力例 2
7 -10 -5 -3 -1 0 1 4 2 5 6 5 2 1 7 8 -7 7 -1 5 -10 -4 -8 10 -5 0 -10 5 -8 7 -8 -3
出力例 2
26 15 7 26 18 28 26 11
Score : 350 points
Problem Statement
There are N villages on a number line. The i-th village is located at coordinate X_i, and has P_i villagers.
Answer Q queries. The i-th query is in the following format:
- Given integers L_i and R_i, find the total number of villagers living in villages located between coordinates L_i and R_i, inclusive.
Constraints
- 1\leq N,Q\leq 2\times 10^5
- -10^9\leq X_1 < X_2 < \ldots < X_N \leq 10^9
- 1\leq P_i\leq 10^9
- -10^9\leq L_i \leq R_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N X_1 \ldots X_N P_1 \ldots P_N Q L_1 R_1 \vdots L_Q R_Q
Output
Print Q lines.
The i-th line(1\leq i \leq Q) should contain the answer to the i-th query.
Sample Input 1
4 1 3 5 7 1 2 3 4 4 1 1 2 6 0 10 2 2
Sample Output 1
1 5 10 0
Consider the first query. The villages between coordinates 1 and 1 are the village at coordinate 1, with 1 villager. Hence, the answer is 1.
Consider the second query. The villages between coordinates 2 and 6 are the villages at coordinates 3 and 5, with 2 and 3 villagers, respectively. Hence, the answer is 2+3=5.
Sample Input 2
7 -10 -5 -3 -1 0 1 4 2 5 6 5 2 1 7 8 -7 7 -1 5 -10 -4 -8 10 -5 0 -10 5 -8 7 -8 -3
Sample Output 2
26 15 7 26 18 28 26 11
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
長さ 2N の非負整数列 A = (A_1, \dots, A_{2N}) が与えられます。
長さ 2N の括弧列 s のスコアを、以下で得られる値として定義します。
- s の i 文字目が
)であるようなすべての整数 i について A_i の値を 0 に変えた場合の、A の要素の総和。
長さ 2N の正しい括弧列のスコアとしてありうる最大値を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
正しい括弧列とは
正しい括弧列とは、() である部分文字列を削除することを 0 回以上繰り返して空文字列にできる文字列を指します。
制約
- 1 \leq T \leq 500
- 1 \leq N \leq 2 \times 10^5
- 各入力ファイルについて、すべてのテストケースの N の総和は 2 \times 10^5 以下である。
- 0 \leq A_i \leq 10^9 (1 \leq i \leq 2N)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
T
\textrm{case}_1
\textrm{case}_2
\vdots
\textrm{case}_T
\textrm{case}_i は i 番目のテストケースを表す。各テストケースは以下の形式で与えられる。
N
A_1
A_2
\vdots
A_{2N}
出力
T 行出力せよ。i 行目 (1 \leq i \leq T) には i 番目のテストケースに対する答えを出力せよ。
入力例 1
2 3 400 500 200 100 300 600 6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 1
1200 6000000000
1 番目のテストケースにおいて、正しい括弧列として (())() を選ぶと、そのスコアは 400+500+0+0+300+0=1200 となります。
1200 よりも高いスコアを得るような正しい括弧列は存在しないので、1 番目のテストケースの答えとして 1200 を出力します。
この入出力例における 2 番目のテストケースのように、答えが 32 bit 整数におさまらないことがあることに注意してください。
Score : 450 points
Problem Statement
You are given a sequence of non-negative integers A = (A_1,\dots,A_{2N}) of length 2N.
Define the score of a parenthesis sequence s of length 2N as follows:
- For every position i where the i-th character of s is
), set A_i to 0, then take the sum of all elements of A.
Find the maximum possible score of a correct parenthesis sequence of length 2N.
You are given T test cases; solve each.
What is a correct parenthesis sequence?
A correct parenthesis sequence is a string that can be reduced to the empty string by repeatedly removing substrings equal to().
Constraints
- 1 \le T \le 500
- 1 \le N \le 2 \times 10^{5}
- For each input file, the sum of N over all test cases is at most 2 \times 10^{5}.
- 0 \le A_i \le 10^{9} (1 \le i \le 2N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\textrm{case}_1
\textrm{case}_2
\vdots
\textrm{case}_T
\textrm{case}_i represents the i-th test case. Each test case is given in the following format:
N
A_1
A_2
\vdots
A_{2N}
Output
Output T lines. The i-th line (1 \le i \le T) should contain the answer for the i-th test case.
Sample Input 1
2 3 400 500 200 100 300 600 6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 1
1200 6000000000
In the first test case, choosing the correct parenthesis string (())() gives a score of 400+500+0+0+300+0=1200.
No correct parenthesis string yields a higher score, so the answer is 1200.
Note that, as in the second test case of this sample, the answer may exceed the 32-bit integer range.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
座標平面上にタイルが敷き詰められています。 1\times1 の大きさの小タイルと K\times K の大きさの大タイルの 2 種類があり、次の規則に従って敷き詰められています。
- 整数の組 (i,j) に対し、正方形 \lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace は 1 つの小タイルもしくは 1 つの大タイルに含まれる。
- \left\lfloor\dfrac iK\right\rfloor+\left\lfloor\dfrac jK\right\rfloor が偶数のとき、小タイルに含まれる。
- そうでないとき、大タイルに含まれる。
ただし、タイルは境界を含むものとし、共通部分が正の面積をもつような 2 つの異なるタイルは存在しないとします。
例えば、K=3 のとき、タイルは以下のようになります。

高橋君は、はじめ座標平面上の点 (S _ x+0.5,S _ y+0.5) にいます。
高橋君は、次の移動を好きなだけ繰り返します。
- 上下左右の方向と正の整数 n を選ぶ。その方向に n だけ進む。
高橋君が異なるタイルを通るたび、高橋君は通行料を 1 だけ支払います。
高橋君が点 (T _ x+0.5,T _ y+0.5) にたどり着くために支払わなければならない通行料の最小値を求めてください。
制約
- 1\leq K\leq10 ^ {16}
- 0\leq S _ x\leq2\times10 ^ {16}
- 0\leq S _ y\leq2\times10 ^ {16}
- 0\leq T _ x\leq2\times10 ^ {16}
- 0\leq T _ y\leq2\times10 ^ {16}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
K S _ x S _ y T _ x T _ y
出力
高橋君が支払わなければならない通行料の最小値を出力せよ。
入力例 1
3 7 2 1 6
出力例 1
5
例えば、以下のように移動することで支払う通行料を 5 にすることができます。

- 上に 3 進む。通行料を 1 支払う。
- 左に 2 進む。通行料を 1 支払う。
- 上に 1 進む。通行料を 1 支払う。
- 左に 4 進む。通行料を 2 支払う。
支払う通行料を 4 以下にすることはできないので、5 を出力してください。
入力例 2
1 41 42 13 56
出力例 2
42

高橋君が最短距離で移動するとき、どのように移動しても通行料を 42 だけ支払います。
支払う通行料を 41 以下にすることはできないので、42 を出力してください。
入力例 3
100 100 99 199 1
出力例 3
0
通行料を支払わなくてよい場合もあります。
入力例 4
96929423 5105216413055191 10822465733465225 1543712011036057 14412421458305526
出力例 4
79154049
Score: 550 points
Problem Statement
Tiles are laid out on a coordinate plane. There are two types of tiles: small tiles of size 1\times1 and large tiles of size K\times K, laid out according to the following rules:
- For each pair of integers (i,j), the square \lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace is contained within either one small tile or one large tile.
- If \left\lfloor\dfrac iK\right\rfloor+\left\lfloor\dfrac jK\right\rfloor is even, it is contained within a small tile.
- Otherwise, it is contained within a large tile.
Tiles include their boundaries, and no two different tiles have a positive area of intersection.
For example, when K=3, tiles are laid out as follows:

Takahashi starts at the point (S_x+0.5,S_y+0.5) on the coordinate plane.
He can repeat the following movement any number of times:
- Choose a direction (up, down, left, or right) and a positive integer n. Move n units in that direction.
Each time he crosses from one tile to another, he must pay a toll of 1.
Determine the minimum toll Takahashi must pay to reach the point (T_x+0.5,T_y+0.5).
Constraints
- 1\leq K\leq10^{16}
- 0\leq S_x\leq2\times10^{16}
- 0\leq S_y\leq2\times10^{16}
- 0\leq T_x\leq2\times10^{16}
- 0\leq T_y\leq2\times10^{16}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
K S_x S_y T_x T_y
Output
Print the minimum toll Takahashi must pay.
Sample Input 1
3 7 2 1 6
Sample Output 1
5
For example, he can move as follows, paying a toll of 5.

- Move up by 3. Pay a toll of 1.
- Move left by 2. Pay a toll of 1.
- Move up by 1. Pay a toll of 1.
- Move left by 4. Pay a toll of 2.
The toll paid cannot be 4 or less, so print 5.
Sample Input 2
1 41 42 13 56
Sample Output 2
42

When he moves the shortest distance, he will always pay a toll of 42.
The toll paid cannot be 41 or less, so print 42.
Sample Input 3
100 100 99 199 1
Sample Output 3
0
There are cases where no toll needs to be paid.
Sample Input 4
96929423 5105216413055191 10822465733465225 1543712011036057 14412421458305526
Sample Output 4
79154049