実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字および英大文字のみからなる文字列 S, T が与えられます。
文字列 S が以下の条件を満たしているか判定してください。
- S の先頭でない英大文字の直前の文字はすべて T に含まれる。より形式的には、2 \leq i \leq |S| なる整数 i について S の i 番目の文字が英大文字ならば、S の i-1 番目の文字は T に含まれる。
制約
- S, T は長さ 1 以上 100 以下の英小文字および英大文字のみからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
S が問題文中の条件を満たしているとき Yes
と出力せよ。そうでないとき、No
と出力せよ。
入力例 1
AtCoder Total
出力例 1
Yes
S の先頭でない英大文字は 3 番目の文字の C
のみです。この直前の文字である t
は T に含まれているため、Yes
と出力すればよいです。
入力例 2
aBCdE abcdcba
出力例 2
No
S の 3 番目の文字は英大文字 C
であり、その直前の文字は B
ですが、B
は T に含まれていません。
入力例 3
abcde XYZ
出力例 3
Yes
Score : 200 points
Problem Statement
You are given strings S and T consisting of lowercase and uppercase English letters.
Determine whether the string S satisfies the following condition:
- Every uppercase letter in S that is not at the beginning is immediately preceded by a character contained in T. More formally, for all integers i such that 2 \leq i \leq |S|, if the i-th character of S is uppercase, then the (i-1)-th character of S is contained in T.
Constraints
- Each of S and T is a string consisting of lowercase and uppercase English letters with length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
S T
Output
If S satisfies the condition in the problem statement, output Yes
. Otherwise, output No
.
Sample Input 1
AtCoder Total
Sample Output 1
Yes
The only uppercase letter in S that is not at the beginning is the 3rd character C
. The immediately preceding character t
is contained in T, so output Yes
.
Sample Input 2
aBCdE abcdcba
Sample Output 2
No
The 3rd character of S is the uppercase letter C
, and its immediately preceding character is B
, but B
is not contained in T.
Sample Input 3
abcde XYZ
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
縦 8 マス、横 8 マスの 64 マスからなるマス目があります。 上から i 行目 (1\leq i\leq8) 、左から j 列目 (1\leq j\leq8) のマスをマス (i,j) と呼ぶことにします。
それぞれのマスは、空マスであるかコマが置かれているかのどちらかです。
マスの状態は長さ 8 の文字列からなる長さ 8 の列 (S _ 1,S _ 2,S _ 3,\ldots,S _ 8) で表されます。
マス (i,j) (1\leq i\leq8,1\leq j\leq8) は、S _ i の j 文字目が .
のとき空マスで、#
のときコマが置かれています。
あなたは、すでに置かれているどのコマにも取られないように、いずれかの空マスに自分のコマを置きたいです。
マス (i,j) に置かれているコマは、次のどちらかの条件を満たすコマを取ることができます。
- i 行目のマスに置かれている
- j 列目のマスに置かれている
たとえば、マス (4,4) に置かれているコマは、以下の図で青く示されたマスに置かれているコマを取ることができます。
あなたがコマを置くことができるマスがいくつあるか求めてください。
制約
- S _ i は
.
,#
からなる長さ 8 の文字列 (1\leq i\leq 8)
入力
入力は以下の形式で標準入力から与えられる。
S _ 1 S _ 2 S _ 3 S _ 4 S _ 5 S _ 6 S _ 7 S _ 8
出力
すでに置かれているコマに取られずに自分のコマを置くことができる空マスの個数を出力せよ。
入力例 1
...#.... #....... .......# ....#... .#...... ........ ........ ..#.....
出力例 1
4
すでに置かれているコマは、以下の図で青く示されたマスに置かれたコマを取ることができます。
よって、あなたがすでに置かれているコマに取られないように自分のコマを置くことができるマスはマス (6,6), マス (6,7), マス (7,6), マス (7,7) の 4 マスです。
入力例 2
........ ........ ........ ........ ........ ........ ........ ........
出力例 2
64
コマがひとつも置かれていないこともあります。
入力例 3
.#...... ..#..#.. ....#... ........ ..#....# ........ ...#.... ....#...
出力例 3
4
Score : 200 points
Problem Statement
There is a grid of 64 squares with 8 rows and 8 columns. Let (i,j) denote the square at the i-th row from the top (1\leq i\leq8) and j-th column from the left (1\leq j\leq8).
Each square is either empty or has a piece placed on it.
The state of the squares is represented by a sequence (S_1,S_2,S_3,\ldots,S_8) of 8 strings of length 8.
Square (i,j) (1\leq i\leq8,1\leq j\leq8) is empty if the j-th character of S_i is .
, and has a piece if it is #
.
You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.
A piece placed on square (i,j) can capture pieces that satisfy either of the following conditions:
- Placed on a square in row i
- Placed on a square in column j
For example, a piece placed on square (4,4) can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on?
Constraints
- Each S_i is a string of length 8 consisting of
.
and#
(1\leq i\leq 8).
Input
The input is given from Standard Input in the following format:
S_1 S_2 S_3 S_4 S_5 S_6 S_7 S_8
Output
Print the number of empty squares where you can place your piece without it being captured by any existing pieces.
Sample Input 1
...#.... #....... .......# ....#... .#...... ........ ........ ..#.....
Sample Output 1
4
The existing pieces can capture pieces placed on the squares shown in blue in the following figure:
Therefore, you can place your piece without it being captured on 4 squares: square (6,6), square (6,7), square (7,6), and square (7,7).
Sample Input 2
........ ........ ........ ........ ........ ........ ........ ........
Sample Output 2
64
There may be no pieces on the grid.
Sample Input 3
.#...... ..#..#.. ....#... ........ ..#....# ........ ...#.... ....#...
Sample Output 3
4
実行時間制限: 2 sec / メモリ制限: 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.
実行時間制限: 2 sec / メモリ制限: 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
X
to 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
実行時間制限: 2 sec / メモリ制限: 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