Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。
つまり、 ID は以下の順番で付けられています。
- 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
- 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
- ...
このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。
制約
- S は AtCoder Big Contest に含まれる問題の ID として正しい
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを整数として出力せよ。
入力例 1
AB
出力例 1
28
ID が AB である問題は、 AtCoder Big Contest の 28 問目です。
入力例 2
C
出力例 2
3
ID が C である問題は、 AtCoder Big Contest の 3 問目です。
入力例 3
BRUTMHYHIIZP
出力例 3
10000000000000000
ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。
Score : 300 points
Problem Statement
In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...
In other words, the IDs are given in the following order:
- the strings of length 1 consisting of uppercase English letters, in lexicographical order;
- the strings of length 2 consisting of uppercase English letters, in lexicographical order;
- the strings of length 3 consisting of uppercase English letters, in lexicographical order;
- ...
Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)
Constraints
- S is a valid ID of a problem given in AtCoder Big Contest.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer as an integer.
Sample Input 1
AB
Sample Output 1
28
The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.
Sample Input 2
C
Sample Output 2
3
The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.
Sample Input 3
BRUTMHYHIIZP
Sample Output 3
10000000000000000
The problem whose ID is BRUTMHYHIIZP is the
10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : {400} 点
問題文
高橋君は AtCoder Land にある屋外アトラクションに K 回乗ろうとしています。このアトラクションの一回の所要時間は T です。
現在の時刻は 0 です。時刻 0 から N までの降水量が与えられます。時刻 i から時刻 i+1 までの降水量は P_i です (0\leq i\lt N)。アトラクションには時刻 0,1,…,N−T に乗ることができます。時刻 t にアトラクションに乗ると時刻 t+T にアトラクションから降りることができ、アトラクションに乗っている間に P_t+P_{t+1}+\dots+P_{t+T-1} だけ濡れます。
高橋君はアトラクションに乗っている間にできるだけ雨に濡れないようにしたいです。時刻 N までに K 回アトラクションに乗るとき、高橋君が濡れる量の総和の最小値を求めてください。ただし、乗り換えにかかる時間や待ち時間は 0 とし、アトラクションから降りた時刻に新たにアトラクションに乗ることができるものとします。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq K\leq \min(N,100)
- 1\leq T\leq N/K
- 0\leq P_i\leq 10^{9}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K T
P_0 P_1 \ldots P_{N-1}
出力
答えを出力せよ。
入力例 1
8 3 2 3 5 10 4 1 7 3 9
出力例 1
23
次のようにアトラクションに 3 回乗ることで濡れる量を合計で 23 にすることができ、これが最小です。
- アトラクションに時刻 0 に乗り、時刻 2 に降りる。この間に P_0+P_1=3+5=8 濡れる。
- アトラクションに時刻 3 に乗り、時刻 5 に降りる。この間に P_3+P_4=4+1=5 濡れる。
- アトラクションに時刻 5 に乗り、時刻 7 に降りる。この間に P_5+P_6=7+3=10 濡れる。
入力例 2
5 1 3 1000 1 10000 100 10
出力例 2
10101
入力例 3
15 5 2 401054171 63773035 986525245 157986893 799814573 139201145 649233932 351289844 409065258 406122133 957285954 529460482 21179081 795984182 727882733
出力例 3
3522058414
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
高橋くんは睡眠記録をつけています。 睡眠記録は奇数長の数列 A=(A _ 1(=0), A _ 2,\ldots,A _ N) で表され、奇数番目は起床時刻を、偶数番目は就寝時刻を表しています。 より厳密には、睡眠記録をつけている間に高橋くんは次のような睡眠をとりました。
- すべての 1\leq i\leq\dfrac{N-1}2 を満たす整数 i について、睡眠記録をつけ始めてから A _ {2i} 分後ちょうどに寝て、A _ {2i+1} 分後ちょうどに起きた。
- それ以外の時間に寝ることも起きることもなかった。
次の Q 個の質問に答えてください。 i 番目の質問では、0\leq l _ i\leq r _ i\leq A _ N を満たす整数の組 (l _ i,r _ i) が与えられます。
- 睡眠記録をつけ始めてから l _ i 分後ちょうどから r _ i 分後ちょうどまでの r _ i-l _ i 分のうち、高橋くんが寝ていたのは何分間ですか?
制約
- 3\leq N\lt2\times10^5
- N は奇数
- 0=A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq10^9
- 1\leq Q\leq2\times10^5
- 0\leq l _ i\leq r _ i\leq A _ N\ (1\leq i\leq Q)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N Q l _ 1 r _ 1 l _ 2 r _ 2 \vdots l _ Q r _ Q
出力
答えを Q 行で出力せよ。 i 行目には i 番目の質問の答えを整数として出力せよ。
入力例 1
7 0 240 720 1320 1440 1800 2160 3 480 1920 720 1200 0 2160
出力例 1
480 0 960
高橋くんは、以下の図のように睡眠をとりました。

それぞれの質問の答えは以下のようになります。
- 睡眠記録をつけ始めてから 480 分後から 1920 分後の間、高橋くんは 480 分後から 720 分後、1320 分後から 1440 分後、1800 分後から 1920 分後の 3 つの睡眠をとりました。睡眠時間の合計は 240+120+120=480 分です。
- 睡眠記録をつけ始めてから 720 分後から 1200 分後の間、高橋くんは睡眠をとりませんでした。睡眠時間の合計は 0 分です。
- 睡眠記録をつけ始めてから 0 分後から 2160 分後の間、高橋くんは 240 分後から 720 分後、1320 分後から 1440 分後、1800 分後から 2160 分後の 3 つの睡眠をとりました。睡眠時間の合計は 480+120+360=960 分です。
よって、それぞれの行に 480,0,960 と出力してください。
入力例 2
21 0 20 62 192 284 310 323 324 352 374 409 452 486 512 523 594 677 814 838 946 1000 10 77 721 255 541 478 970 369 466 343 541 42 165 16 618 222 592 730 983 338 747
出力例 2
296 150 150 49 89 20 279 183 61 177
Score : 450 points
Problem Statement
Takahashi keeps a sleep log. The log is represented as an odd-length sequence A=(A _ 1(=0), A _ 2,\ldots,A _ N), where odd-numbered elements represent times he got up, and even-numbered elements represent times he went to bed. More formally, he had the following sleep sessions after starting the sleep log.
- For every integer i such that 1\leq i\leq\dfrac{N-1}2, he fell asleep exactly A _ {2i} minutes after starting the sleep log and woke up exactly A _ {2i+1} minutes after starting the sleep log.
- He did not fall asleep or wake up at any other time.
Answer the following Q questions. For the i-th question, you are given a pair of integers (l _ i,r _ i) such that 0\leq l _ i\leq r _ i\leq A _ N.
- What is the total number of minutes for which Takahashi was asleep during the r _ i-l _ i minutes from exactly l _ i minutes to r _ i minutes after starting the sleep log?
Constraints
- 3\leq N\lt2\times10^5
- N is odd.
- 0=A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq10^9
- 1\leq Q\leq2\times10^5
- 0\leq l _ i\leq r _ i\leq A _ N\ (1\leq i\leq Q)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A _ 1 A _ 2 \ldots A _ N Q l _ 1 r _ 1 l _ 2 r _ 2 \vdots l _ Q r _ Q
Output
Print the answer in Q lines. The i-th line should contain an integer answering to the i-th question.
Sample Input 1
7 0 240 720 1320 1440 1800 2160 3 480 1920 720 1200 0 2160
Sample Output 1
480 0 960
Takahashi slept as shown in the following figure.

The answers to each question are as follows.
- Between 480 minutes and 1920 minutes after starting the sleep log, Takahashi slept from 480 minutes to 720 minutes, from 1320 minutes to 1440 minutes, and from 1800 minutes to 1920 minutes in 3 sleep sessions. The total sleep time is 240+120+120=480 minutes.
- Between 720 minutes and 1200 minutes after starting the sleep log, Takahashi did not sleep. The total sleep time is 0 minutes.
- Between 0 minutes and 2160 minutes after starting the sleep log, Takahashi slept from 240 minutes to 720 minutes, from 1320 minutes to 1440 minutes, and from 1800 minutes to 2160 minutes in 3 sleep sessions. The total sleep time is 480+120+360=960 minutes.
Therefore, the three lines of the output should contain 480, 0, and 960.
Sample Input 2
21 0 20 62 192 284 310 323 324 352 374 409 452 486 512 523 594 677 814 838 946 1000 10 77 721 255 541 478 970 369 466 343 541 42 165 16 618 222 592 730 983 338 747
Sample Output 2
296 150 150 49 89 20 279 183 61 177
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
ある国には N 個の都市と M 個の発電所があります。これらを総称して地点と呼びます。
地点には 1,2,\dots,N+M の番号がつけられており、そのうち都市は地点 1,2,\dots,N で発電所は地点 N+1,N+2,\dots,N+M です。
この国には電線が E 本あり、電線 i ( 1 \le i \le E ) は地点 U_i と地点 V_i を双方向に結びます。
また、ある都市に 電気が通っている とは、ある都市から電線をいくつか辿って少なくともひとつの発電所に辿り着くことができる状態を言います。
今、 Q 個のイベントが起こります。そのうち i ( 1 \le i \le Q ) 番目のイベントでは電線 X_i が切れ、その電線を辿ることができなくなります。一度切れた電線は、その後のイベントにおいても切れたままです。
全てのイベントについて、そのイベントが終わった直後に電気が通っている都市の数を求めてください。
制約
- 入力は全て整数
- 1 \le N,M
- N+M \le 2 \times 10^5
- 1 \le Q \le E \le 5 \times 10^5
- 1 \le U_i < V_i \le N+M
- i \neq j ならば、 U_i \neq U_j または V_i \neq V_j
- 1 \le X_i \le E
- X_i は相異なる
入力
入力は以下の形式で標準入力から与えられる。
N M E U_1 V_1 U_2 V_2 \vdots U_E V_E Q X_1 X_2 \vdots X_Q
出力
Q 行出力せよ。
そのうち i ( 1 \le i \le Q ) 行目には i 番目のイベントが終わった直後に電気が通っている都市の数を出力せよ。
入力例 1
5 5 10 2 3 4 10 5 10 6 9 2 9 4 8 1 7 3 6 8 10 1 8 6 3 5 8 10 2 7
出力例 1
4 4 2 2 2 1
はじめ、全ての都市に電気が通っています。
- 1 番目のイベントによって地点 5 と地点 10 を結ぶ電線 3 が切れます。
- これにより、都市 5 に電気が通らなくなり、電気が通っている都市の数は 4 となります。
- 2 番目のイベントによって地点 2 と地点 9 を結ぶ電線 5 が切れます。
- 3 番目のイベントによって地点 3 と地点 6 を結ぶ電線 8 が切れます。
- これにより、都市 2,3 に電気が通らなくなり、電気が通っている都市の数は 2 となります。
- 4 番目のイベントによって地点 1 と地点 8 を結ぶ電線 10 が切れます。
- 5 番目のイベントによって地点 4 と地点 10 を結ぶ電線 2 が切れます。
- 6 番目のイベントによって地点 1 と地点 7 を結ぶ電線 7 が切れます。
- これにより、都市 1 に電気が通らなくなり、電気が通っている都市の数は 1 となります。
Score : 500 points
Problem Statement
A country has N cities and M power plants, which we collectively call places.
The places are numbered 1,2,\dots,N+M, among which Places 1,2,\dots,N are the cities and Places N+1,N+2,\dots,N+M are the power plants.
This country has E power lines. Power Line i (1 \le i \le E) connects Place U_i and Place V_i bidirectionally.
A city is said to be electrified if one can reach at least one of the power plants from the city using some power lines.
Now, Q events will happen. In the i-th (1 \le i \le Q) event, Power Line X_i breaks, making it unusable. Once a power line breaks, it remains broken in the succeeding events.
Find the number of electrified cities right after each events.
Constraints
- All values in input are integers.
- 1 \le N,M
- N+M \le 2 \times 10^5
- 1 \le Q \le E \le 5 \times 10^5
- 1 \le U_i < V_i \le N+M
- If i \neq j, then U_i \neq U_j or V_i \neq V_j.
- 1 \le X_i \le E
- X_i are distinct.
Input
Input is given from Standard Input in the following format:
N M E U_1 V_1 U_2 V_2 \vdots U_E V_E Q X_1 X_2 \vdots X_Q
Output
Print Q lines.
The i-th line should contain the number of electrified cities right after the i-th event.
Sample Input 1
5 5 10 2 3 4 10 5 10 6 9 2 9 4 8 1 7 3 6 8 10 1 8 6 3 5 8 10 2 7
Sample Output 1
4 4 2 2 2 1
Initially, all cities are electrified.
- The 1-st event breaks Power Line 3 that connects Point 5 and Point 10.
- Now City 5 is no longer electrified, while 4 cities remain electrified.
- The 2-nd event breaks Power Line 5 that connects Point 2 and Point 9.
- The 3-rd event breaks Power Line 8 that connects Point 3 and Point 6.
- Now Cities 2 and 3 are no longer electrified, while 2 cities remain electrified.
- The 4-th event breaks Power Line 10 that connects Point 1 and Point 8.
- The 5-th event breaks Power Line 2 that connects Point 4 and Point 10.
- The 6-th event breaks Power Line 7 that connects Point 1 and Point 7.
- Now City 1 is no longer electrified, while 1 city remains electrified.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A が与えられます。 数列の長さが 2 以上のとき、隣接する二つの値を選び、それらを削除し、それらが元にあった位置にそれらの和を挿入するという操作を好きなだけ行えます。 0 回以上の操作の後の数列として考えられるものは何通りあるか求め、998244353 で割ったあまりを出力してください。
制約
- 1 \leq N \leq 2\times 10^5
- |A_i| \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \cdots A_N
出力
答えを出力せよ。
入力例 1
3 1 -1 1
出力例 1
4
0 回以上の操作の後の数列として考えられるのは以下の 4 通りです。
- {1,-1,1}
- {1,0}
- {0,1}
- {1}
入力例 2
10 377914575 -275478149 0 -444175904 719654053 -254224494 -123690081 377914575 -254224494 -21253655
出力例 2
321
Score : 500 points
Problem Statement
Given is a sequence A of length N. You can do this operation any number of times: when the length of the sequence is at least 2, choose two adjacent values, delete them, and insert their sum where they were. How many sequences can result from zero or more operations? Find the count modulo 998244353.
Constraints
- 1 \leq N \leq 2\times 10^5
- |A_i| \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \cdots A_N
Output
Print the answer.
Sample Input 1
3 1 -1 1
Sample Output 1
4
The following four sequences can result from zero or more operations.
- {1,-1,1}
- {1,0}
- {0,1}
- {1}
Sample Input 2
10 377914575 -275478149 0 -444175904 719654053 -254224494 -123690081 377914575 -254224494 -21253655
Sample Output 2
321