Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
真夏の N 日間、高橋君は毎日の最高気温と最低気温を記録しました。 i 日目の最高気温は A_i 度、最低気温は B_i 度でした。
1 日の最高気温と最低気温の差が K 度以上の日を「寒暖差の大きい日」と呼びます。各日について、寒暖差の大きい日なら L 、そうでなければ S として、 1 日目から順に並べた長さ N の文字列を出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq K \leq 50
- 0 \leq B_i \leq A_i \leq 50
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 B_1 A_2 B_2 \vdots A_N B_N
- 1 行目には、日数 N と基準となる気温差 K がスペース区切りで与えられる。
- 2 行目から N 行にわたり、 1 + i 行目には i 日目の最高気温 A_i と最低気温 B_i がスペース区切りで与えられる。
出力
長さ N の文字列を 1 行で出力せよ。
入力例 1
4 10 35 22 30 25 38 20 29 28
出力例 1
LSLS
入力例 2
1 5 33 30
出力例 2
S
入力例 3
2 8 40 20 27 20
出力例 3
LS
入力例 4
1 1 33 30
出力例 4
L
入力例 5
6 38 12 2 39 18 49 4 26 1 43 12 2 1
出力例 5
SSLSSS
Score : 200 pts
Problem Statement
During N midsummer days, Takahashi recorded the highest and lowest temperatures each day. On day i, the highest temperature was A_i degrees and the lowest temperature was B_i degrees.
A day is called a "day with a large temperature difference" if the difference between the highest and lowest temperatures of that day is at least K degrees. For each day, let L denote a day with a large temperature difference and S denote any other day. Print the string of length N obtained by arranging these characters in order starting from day 1.
Constraints
- 1 \leq N \leq 100
- 1 \leq K \leq 50
- 0 \leq B_i \leq A_i \leq 50
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 B_1 A_2 B_2 \vdots A_N B_N
- The first line contains the number of days N and the reference temperature difference K, separated by a space.
- For each of the next N lines, line 1 + i contains the highest temperature A_i and the lowest temperature B_i of day i, separated by a space.
Output
Print a single string of length N on one line.
Sample Input 1
4 10 35 22 30 25 38 20 29 28
Sample Output 1
LSLS
Sample Input 2
1 5 33 30
Sample Output 2
S
Sample Input 3
2 8 40 20 27 20
Sample Output 3
LS
Sample Input 4
1 1 33 30
Sample Output 4
L
Sample Input 5
6 38 12 2 39 18 49 4 26 1 43 12 2 1
Sample Output 5
SSLSSS
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君の店では、 N 日間の祭日に特別セールを行いました。 i 日目の来客数は A_i 人でした。
来客数が最も多かった日は何日目かを求めてください。来客数が最も多い日が複数ある場合は、そのうち最も早い日を答えてください。
制約
- 1 \leq N \leq 100
- 0 \leq A_i \leq 10000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
- 1 行目には、祭日の日数 N が与えられる。
- 2 行目には、各日の来客数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
来客数が最も多かった日が何日目かを 1 行で出力せよ。複数ある場合は最も早い日を出力せよ。
入力例 1
5 3 8 2 8 5
出力例 1
2
入力例 2
1 0
出力例 2
1
入力例 3
4 1 2 3 4
出力例 3
4
入力例 4
4 2 2 3 4
出力例 4
4
入力例 5
4 1 4 3 4
出力例 5
2
Score : 233 pts
Problem Statement
Takahashi's shop held a special sale during a festival lasting N days. On day i, A_i customers visited the shop.
Find which day had the most visitors. If multiple days had the most visitors, answer the earliest such day.
Constraints
- 1 \leq N \leq 100
- 0 \leq A_i \leq 10000
- All input values are integers.
Input
Input is given from standard input in the following format:
N A_1 A_2 \ldots A_N
- The first line contains the number of festival days N.
- The second line contains the visitor counts A_1, A_2, \ldots, A_N for each day, separated by spaces.
Output
Print, on a single line, which day had the most visitors. If there are multiple such days, print the earliest one.
Sample Input 1
5 3 8 2 8 5
Sample Output 1
2
Sample Input 2
1 0
Sample Output 2
1
Sample Input 3
4 1 2 3 4
Sample Output 3
4
Sample Input 4
4 2 2 3 4
Sample Output 4
4
Sample Input 5
4 1 4 3 4
Sample Output 5
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 333 点
問題文
H 行 W 列のマス目があります。上から i 行目、左から j 列目のマスをマス (i, j) と呼びます。
各マス (i, j) には文字 C_{i, j} が書かれており、それぞれ以下の方向を表しています。
U: 上方向、すなわちマス (i - 1, j)D: 下方向、すなわちマス (i + 1, j)L: 左方向、すなわちマス (i, j - 1)R: 右方向、すなわちマス (i, j + 1)
高橋君は最初、マス (1, 1) にいます。
高橋君は現在いるマスに書かれた文字が指す方向の隣接するマスへ移動することを繰り返します。
ただし、移動先がマス目の外側になってしまう場合、高橋君は移動を行わずにそのマスで移動を終了します。
高橋君の移動が最終的に終了するかどうかを判定し、終了する場合は終了するまでに行った移動の回数を出力してください。
同じマスを再び訪れるなどして移動が永遠に終了しない場合は -1 を出力してください。
制約
- 1 \leq H \leq 2000
- 1 \leq W \leq 500
- H, W は整数
- C_{i, j} は
U,D,L,Rのいずれかである (1 \leq i \leq H,\ 1 \leq j \leq W)
入力
入力は以下の形式で標準入力から与えられる。
H W
C_{1,1}C_{1,2} \dots C_{1,W}
C_{2,1}C_{2,2} \dots C_{2,W}
:
C_{H,1}C_{H,2} \dots C_{H,W}
- 1 行目には、マス目の行数を表す H と列数を表す W が、スペース区切りで与えられる。
- 2 行目から H 行にわたって、各マスに書かれた文字を表す文字列が与えられる。
- 1 + i 行目には、長さ W の文字列が与えられ、その j 文字目はマス (i, j) に書かれた文字 C_{i, j} である。
出力
高橋君の移動が終了する場合は終了するまでに行った移動の回数を、移動が永遠に終了しない場合は -1 を 1 行に出力せよ。
入力例 1
3 4 RRRD ULLD UURR
出力例 1
5
入力例 2
2 2 RD UL
出力例 2
-1
入力例 3
6 6 RRRRRD DLLLLL RRRRRD DLLLLL RRRRRD LLLLLL
出力例 3
35
入力例 4
20 20 RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL
出力例 4
399
入力例 5
1 1 U
出力例 5
0
Score : 333 pts
Problem Statement
There is a grid with H rows and W columns. Let square (i, j) denote the square at the i-th row from the top and j-th column from the left.
Each square (i, j) has a character C_{i, j} written on it, which represents the following directions:
U: Up, that is, square (i - 1, j)D: Down, that is, square (i + 1, j)L: Left, that is, square (i, j - 1)R: Right, that is, square (i, j + 1)
Takahashi is initially at square (1, 1).
He repeatedly moves to the adjacent square in the direction indicated by the character written on the square he is currently on.
However, if the destination would be outside the grid, Takahashi does not move and terminates his movement at that square.
Determine whether Takahashi's movement eventually terminates. If it terminates, output the number of moves performed until it terminates.
If the movement never terminates, such as by visiting the same square again, output -1.
Constraints
- 1 \leq H \leq 2000
- 1 \leq W \leq 500
- H and W are integers.
- C_{i, j} is
U,D,L, orR(1 \leq i \leq H,\ 1 \leq j \leq W).
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}C_{1,2} \dots C_{1,W}
C_{2,1}C_{2,2} \dots C_{2,W}
:
C_{H,1}C_{H,2} \dots C_{H,W}
- The first line contains H, the number of rows of the grid, and W, the number of columns, separated by a space.
- The next H lines starting from the second line give strings representing the characters written on each square.
- The (1 + i)-th line contains a string of length W, whose j-th character is the character C_{i, j} written on square (i, j).
Output
If Takahashi's movement terminates, print the number of moves performed until it terminates. If the movement never terminates, print -1 in a single line.
Sample Input 1
3 4 RRRD ULLD UURR
Sample Output 1
5
Sample Input 2
2 2 RD UL
Sample Output 2
-1
Sample Input 3
6 6 RRRRRD DLLLLL RRRRRD DLLLLL RRRRRD LLLLLL
Sample Output 3
35
Sample Input 4
20 20 RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL RRRRRRRRRRRRRRRRRRRD DLLLLLLLLLLLLLLLLLLL
Sample Output 4
399
Sample Input 5
1 1 U
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は 1 日目から N 日目までの N 日間にわたるトレーニングの計画を立てています。
各日 i (1 \leq i \leq N) において、高橋君は以下の 2 つのメニューのうちいずれか一方を選んで行います。
- 通常トレーニングを行う。この場合、トレーニングの効果として A_i を得る。
- ハードトレーニングを行う。この場合、トレーニングの効果として B_i を得る。
ただし、体に過度な負担がかかるため、ハードトレーニングを 2 日連続で行うことはできません。すなわち、i 日目 (1 \leq i \leq N-1) にハードトレーニングを行った場合、i+1 日目にハードトレーニングを行うことはできません。
高橋君が N 日間のトレーニングメニューを適切に選んだとき、N 日間で得られる効果の合計として達成可能な最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N A_1 B_1 A_2 B_2 : A_N B_N
- 1 行目には、日数を表す整数 N が与えられる。
- 続く N 行のうち i 行目 (1 \leq i \leq N) には、i 日目に通常トレーニングを行った場合の効果を表す整数 A_i と、ハードトレーニングを行った場合の効果を表す整数 B_i が空白区切りで与えられる。
出力
得られる効果の合計の最大値を 1 行に出力してください。
入力例 1
3 3 5 2 8 4 6
出力例 1
15
入力例 2
4 10 15 20 10 5 30 10 25
出力例 2
75
入力例 3
8 100 200 150 180 300 100 200 500 120 130 400 600 250 800 300 350
出力例 3
2770
入力例 4
15 100000000 500000000 200000000 300000000 800000000 900000000 400000000 200000000 600000000 1000000000 700000000 750000000 300000000 800000000 500000000 600000000 900000000 950000000 150000000 400000000 600000000 650000000 850000000 900000000 200000000 700000000 450000000 500000000 1000000000 1000000000
出力例 4
9900000000
入力例 5
1 1 1000000000
出力例 5
1000000000
Score : 366 pts
Problem Statement
Takahashi is making a training plan spanning N days, from Day 1 to Day N.
On each day i (1 \leq i \leq N), Takahashi chooses and performs one of the following two routines:
- Perform regular training. In this case, he gains a training benefit of A_i.
- Perform hard training. In this case, he gains a training benefit of B_i.
However, because it puts excessive strain on his body, he cannot perform hard training on two consecutive days. That is, if he performs hard training on Day i (1 \leq i \leq N-1), he cannot perform hard training on Day i+1.
Find the maximum possible total benefit Takahashi can gain over the N days by choosing his training routines appropriately.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All input values are integers.
Input
The input is given in the following format:
N A_1 B_1 A_2 B_2 : A_N B_N
- The first line contains an integer N, representing the number of days.
- The i-th of the following N lines (1 \leq i \leq N) contains two space-separated integers, A_i, representing the benefit of performing regular training on Day i, and B_i, representing the benefit of performing hard training on Day i.
Output
Print the maximum possible total benefit in a single line.
Sample Input 1
3 3 5 2 8 4 6
Sample Output 1
15
Sample Input 2
4 10 15 20 10 5 30 10 25
Sample Output 2
75
Sample Input 3
8 100 200 150 180 300 100 200 500 120 130 400 600 250 800 300 350
Sample Output 3
2770
Sample Input 4
15 100000000 500000000 200000000 300000000 800000000 900000000 400000000 200000000 600000000 1000000000 700000000 750000000 300000000 800000000 500000000 600000000 900000000 950000000 150000000 400000000 600000000 650000000 850000000 900000000 200000000 700000000 450000000 500000000 1000000000 1000000000
Sample Output 4
9900000000
Sample Input 5
1 1 1000000000
Sample Output 5
1000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 433 点
問題文
高橋君は気象データの分析を行っています。ある観測地点で N 日間にわたって記録された日ごとの気温データ S_1, S_2, \ldots, S_N が与えられます。気温は整数値で表されます。
高橋君は、連続するちょうど K 日間の気温データが「山型パターン」を形成しているかどうかに興味があります。
具体的には、開始位置 l(1 \leq l \leq N-K+1)に対して、区間 S_l, S_{l+1}, \ldots, S_{l+K-1} が以下の条件を満たすとき、この区間は山型パターンであるといいます。
- ある位置 p(l < p < l+K-1)が存在して、
S_l < S_{l+1} < \cdots < S_p > S_{p+1} > \cdots > S_{l+K-1}
が成り立つ。すなわち、区間の左端から位置 p まで気温が狭義単調増加し、位置 p から区間の右端まで気温が狭義単調減少する。
ここで、p は区間の左端 l でも右端 l+K-1 でもない位置であるため、増加部分と減少部分はそれぞれ少なくとも1ステップ存在します。この条件を満たすには K \geq 3 が必要です。
高橋君は Q 個のクエリ K_1, K_2, \ldots, K_Q のそれぞれについて、長さ K_j の連続する区間のうち山型パターンの条件を満たすものがいくつあるかを求めたいと考えています。各 K_j に対する山型パターンの個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq N
- -10^9 \leq S_i \leq 10^9(1 \leq i \leq N)
- 3 \leq K_j \leq N(1 \leq j \leq Q)
- K_1, K_2, \ldots, K_Q はすべて異なる
- 入力はすべて整数
入力
N Q S_1 S_2 \ldots S_N K_1 K_2 \vdots K_Q
- 1 行目には、日数 N とクエリの数 Q がスペース区切りで与えられる。
- 2 行目には、各日の気温 S_1, S_2, \ldots, S_N がスペース区切りで与えられる。
- 3 行目から Q 行にわたり、各クエリの値 K_j が 1 つずつ与えられる。
出力
Q 行出力せよ。j 行目には、クエリ K_j に対する山型パターンの個数を出力せよ。
入力例 1
7 3 1 3 5 4 2 3 1 3 4 5
出力例 1
2 2 1
入力例 2
6 2 1 2 3 4 5 6 3 6
出力例 2
0 0
入力例 3
15 5 1 2 4 3 2 1 2 3 5 4 4 3 2 6 1 3 4 5 7 10
出力例 3
3 3 3 0 0
入力例 4
30 8 -5 -3 0 4 7 6 2 -1 0 3 6 9 8 5 1 -2 -2 1 5 4 3 2 10 9 8 7 6 0 -1 -3 3 4 6 8 10 12 15 20
出力例 4
4 7 9 4 0 0 0 0
入力例 5
3 1 -1000000000 0 -1000000000 3
出力例 5
1
Score : 433 pts
Problem Statement
Takahashi is analyzing weather data. He is given daily temperature data S_1, S_2, \ldots, S_N recorded over N days at a certain observation point. Temperatures are represented as integer values.
Takahashi is interested in whether the temperature data over exactly K consecutive days forms a "mountain pattern."
Specifically, for a starting position l (1 \leq l \leq N-K+1), the interval S_l, S_{l+1}, \ldots, S_{l+K-1} is called a mountain pattern if it satisfies the following condition:
- There exists a position p (l < p < l+K-1) such that
S_l < S_{l+1} < \cdots < S_p > S_{p+1} > \cdots > S_{l+K-1}
holds. That is, the temperature is strictly monotonically increasing from the left end of the interval to position p, and strictly monotonically decreasing from position p to the right end of the interval.
Since p is neither the left end l nor the right end l+K-1 of the interval, both the increasing part and the decreasing part consist of at least one step. This condition requires K \geq 3.
Takahashi wants to determine, for each of Q queries K_1, K_2, \ldots, K_Q, how many consecutive intervals of length K_j satisfy the mountain pattern condition. Find the number of mountain patterns for each K_j.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq N
- -10^9 \leq S_i \leq 10^9 (1 \leq i \leq N)
- 3 \leq K_j \leq N (1 \leq j \leq Q)
- K_1, K_2, \ldots, K_Q are all distinct
- All input values are integers
Input
N Q S_1 S_2 \ldots S_N K_1 K_2 \vdots K_Q
- The first line contains the number of days N and the number of queries Q, separated by a space.
- The second line contains the temperatures for each day S_1, S_2, \ldots, S_N, separated by spaces.
- The following Q lines each contain a single query value K_j.
Output
Output Q lines. On the j-th line, output the number of mountain patterns for query K_j.
Sample Input 1
7 3 1 3 5 4 2 3 1 3 4 5
Sample Output 1
2 2 1
Sample Input 2
6 2 1 2 3 4 5 6 3 6
Sample Output 2
0 0
Sample Input 3
15 5 1 2 4 3 2 1 2 3 5 4 4 3 2 6 1 3 4 5 7 10
Sample Output 3
3 3 3 0 0
Sample Input 4
30 8 -5 -3 0 4 7 6 2 -1 0 3 6 9 8 5 1 -2 -2 1 5 4 3 2 10 9 8 7 6 0 -1 -3 3 4 6 8 10 12 15 20
Sample Output 4
4 7 9 4 0 0 0 0
Sample Input 5
3 1 -1000000000 0 -1000000000 3
Sample Output 5
1