url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/joi2024yo1a/tasks/joi2024_yo1a_b | 問題文
3
つの正の整数
A, B, C
が与えられる.
このうちある
1
つの値がそれ以外の
2
つの値の和になっているなら
1
を,そうでないなら
0
を出力せよ. | [
{
"input": "3\n5\n2\n",
"output": "1\n"
},
{
"input": "2\n3\n4\n",
"output": "0\n"
},
{
"input": "100\n50\n50\n",
"output": "1\n"
},
{
"input": "1\n1\n1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/joi2024yo1a/tasks/joi2024_yo1a_c | 問題文
整数
N
と,
2
つの長さ
N
の 文字列
S, T
が与えられる.
S
と
T
のハミング距離を出力せよ.
ここで
S
と
T
のハミング距離とは,
S
の
i
文字目と
T
の
i
文字目が異なるような
i
(
1 \leqq i \leqq N
) の個数である. | [
{
"input": "3\njoi\nioi\n",
"output": "1\n"
},
{
"input": "5\nmarch\napril\n",
"output": "4\n"
},
{
"input": "6\nsample\nsample\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/joi2024yo1a/tasks/joi2024_yo1a_d | 問題文
0
以上
9
以下の整数からなる,長さ
N
の数列
A = (A_1, A_2, \dots, A_N)
が与えられる.数列
A
に少なくとも
1
回現れている整数をすべて,小さい順に出力せよ. | [
{
"input": "8\n2 0 2 3 0 9 1 6\n",
"output": "0\n1\n2\n3\n6\n9\n"
},
{
"input": "3\n9 9 9\n",
"output": "9\n"
},
{
"input": "10\n3 1 4 1 5 9 2 6 5 3\n",
"output": "1\n2\n3\n4\n5\n6\n9\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_a | Problem Statement
In AtCoder, the top
10
rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.
At the start of this contest, the usernames and ratings of the top
10
rated players in the algorithm category are as follows:
tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481
You are given the username
S
of one of these players. Print that player's rating. | [
{
"input": "tourist\n",
"output": "3858\n"
},
{
"input": "semiexp\n",
"output": "3481\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_b | Problem Statement
You are given a positive integer
N
. Print a string of length
(N+1)
,
s_0s_1\ldots s_N
, defined as follows.
For each
i = 0, 1, 2, \ldots, N
,
if there is a divisor
j
of
N
that is between
1
and
9
, inclusive, and
i
is a multiple of
N/j
, then
s_i
is the digit corresponding to the smallest such
j
(
s_i
will thus be one of
1
,
2
, ...,
9
);
if no such
j
exists, then
s_i
is
-
. | [
{
"input": "12\n",
"output": "1-643-2-346-1\n"
},
{
"input": "7\n",
"output": "17777771\n"
},
{
"input": "1\n",
"output": "11\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_c | Problem Statement
There is a
3\times3
grid with numbers between
1
and
9
, inclusive, written in each square. The square at the
i
-th row from the top and
j
-th column from the left
(1\leq i\leq3,1\leq j\leq3)
contains the number
c _ {i,j}
.
The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally.
More precisely, it is guaranteed that
c _ {i,j}
satisfies all of the following conditions.
c _ {i,1}=c _ {i,2}=c _ {i,3}
does not hold for any
1\leq i\leq3
.
c _ {1,j}=c _ {2,j}=c _ {3,j}
does not hold for any
1\leq j\leq3
.
c _ {1,1}=c _ {2,2}=c _ {3,3}
does not hold.
c _ {3,1}=c _ {2,2}=c _ {1,3}
does not hold.
Takahashi will see the numbers written in each cell in random order.
He will get
disappointed
when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.
The first two squares he sees contain the same number, but the last square contains a different number.
Find the probability that Takahashi sees the numbers in all the squares without getting disappointed. | [
{
"input": "3 1 9\n2 5 6\n2 7 1\n",
"output": "0.666666666666666666666666666667\n"
},
{
"input": "7 7 6\n8 6 8\n7 7 6\n",
"output": "0.004982363315696649029982363316\n"
},
{
"input": "3 6 7\n1 9 7\n5 7 5\n",
"output": "0.4\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_d | Problem Statement
Takahashi is displaying a sentence with
N
words in a window.
All words have the same height, and the width of the
i
-th word
(1\leq i\leq N)
is
L _ i
.
The words are displayed in the window separated by a space of width
1
.
More precisely, when the sentence is displayed in a window of width
W
, the following conditions are satisfied.
The sentence is divided into several lines.
The first word is displayed at the beginning of the top line.
The
i
-th word
(2\leq i\leq N)
is displayed either with a gap of
1
after the
(i-1)
-th word, or at the beginning of the line below the line containing the
(i-1)
-th word. It will not be displayed anywhere else.
The width of each line does not exceed
W
. Here, the width of a line refers to the distance from the left end of the leftmost word to the right end of the rightmost word.
When Takahashi displayed the sentence in the window, the sentence fit into
M
or fewer lines.
Find the minimum possible width of the window. | [
{
"input": "13 3\n9 5 2 7 1 8 8 2 1 5 2 3 6\n",
"output": "26\n"
},
{
"input": "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "10000000009\n"
},
{
"input": "30 8\n8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32 60\n",
"output": "189\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_e | Problem Statement
Takahashi is initially at his house and is about to visit Aoki's house.
There are
N
bus stops numbered
1
to
N
between the two houses, and Takahashi can move between them in the following ways:
He can walk from his house to bus stop
1
in
X
units of time.
For each
i = 1, 2, \ldots, N-1
, a bus departs from bus stop
i
at each time that is a multiple of
P_i
, and by taking this bus, he can get to bus stop
(i+1)
in
T_i
units of time.
Here, the constraints guarantee that
1 \leq P_i \leq 8
.
Takahashi can walk from bus stop
N
to Aoki's house in
Y
units of time.
For each
i = 1, 2, \ldots, Q
, process the following query.
Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time
q_i
.
Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus. | [
{
"input": "4 2 3\n5 4\n6 6\n3 1\n7\n13\n0\n710511029\n136397527\n763027379\n644706927\n447672230\n",
"output": "34\n22\n710511052\n136397548\n763027402\n644706946\n447672250\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_f | Problem Statement
There is a tree with
N
vertices.
The
1
-st vertex is the root, and the parent of the
i
-th vertex
(2\leq i\leq N)
is
p _ i\ (1\leq p _ i\lt i)
.
Each non-root vertex has an
enemy
or a
medicine
on it.
Takahashi wants to defeat all the enemies.
Initially, his strength is
1
, and he is at vertex
1
.
For
i=2,\ldots,N
, the information of the
i
-th vertex is represented by a triple of integers
(t _ i,s _ i,g _ i)
as follows.
If
t _ i=1
, there is an enemy at the
i
-th vertex. When Takahashi visits this vertex for the first time, if his strength is less than
s _ i
, Takahashi is defeated by the enemy and
loses
, after which he cannot move to other vertices. Otherwise, he defeats the enemy, and his strength increases by
g _ i
.
If
t _ i=2
, there is a medicine at the
i
-th vertex. When Takahashi visits this vertex for the first time, he takes the medicine, and his strength is multiplied by
g _ i
. (For a vertex with a medicine,
s _ i=0
.)
There are at most
10
vertices with a medicine.
Takahashi can repeatedly move to an adjacent vertex.
Determine if he can defeat all the enemies. | [
{
"input": "8\n1 2 0 3\n2 1 3 3\n1 2 0 4\n4 1 2 2\n1 2 0 5\n6 1 5 5\n5 1 140 1\n",
"output": "Yes\n"
},
{
"input": "12\n1 1 166 619\n1 1 17 592\n2 1 222 983\n2 1 729 338\n5 1 747 62\n3 1 452 815\n3 2 0 1\n4 2 0 40\n4 1 306 520\n6 1 317 591\n1 1 507 946\n",
"output": "No\n"
},
{
"input": "12\n1 1 1 791\n2 2 0 410\n2 1 724 790\n2 1 828 599\n5 2 0 13\n3 1 550 803\n1 1 802 506\n5 1 261 587\n6 1 663 329\n8 1 11 955\n9 1 148 917\n",
"output": "Yes\n"
},
{
"input": "12\n1 2 0 1000000000\n2 2 0 1000000000\n3 2 0 1000000000\n4 2 0 1000000000\n5 2 0 1000000000\n6 2 0 1000000000\n7 2 0 1000000000\n8 2 0 1000000000\n9 2 0 1000000000\n10 2 0 1000000000\n11 1 1 1\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc319/tasks/abc319_g | Problem Statement
We will perform the following operation on a complete undirected graph
G
with
N
vertices.
For each
i = 1, 2, \ldots, M
, delete the undirected edge connecting vertices
u_i
and
v_i
.
Determine if there is a path from vertex
1
to vertex
N
in
G
after the operation. If there is, find the number, modulo
998244353
, of shortest paths from vertex
1
to vertex
N
.
Here, a shortest path from vertex
1
to vertex
N
is a path from vertex
1
to vertex
N
that contains the minimum number of edges. | [
{
"input": "6 7\n4 3\n1 3\n2 4\n1 6\n4 6\n5 1\n6 2\n",
"output": "3\n"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/wtf22-day2-open/tasks/wtf22_day2_a | Problem Statement
You, the game master, and
N
players play a
Hat Guessing Game
.
The players line up behind one another, numbered
1
to
N
from front to back.
Each player wears a red or blue hat.
The colors of the hats are represented by a string
S
: player
i
wears a red hat if the
i
-th character of
S
is
R
, and a blue hat if it is
B
.
You know the string
S
, but the players do not.
Each player can only see the colors of hats of the players in front of them (namely, the players with smaller player numbers).
Particularly, they cannot see the color of their own hat.
The game goes as follows.
First, you count the numbers of players with red hats and those with blue hats, and tell them to all players.
Then, you repeat the following sequence of events (called a
round
)
10^{100}
times.
You ask each player, "Have you found out the color of your own hat?"
Each player will honestly answer
Yes
or
No
without being heard by other players.
After asking all players, you announce all players who have answered
Yes
.
All players can hear this announcement.
Note that you just announce the player numbers and not the colors of their hats.
All players are extremely clever and know that the other players are also clever.
They start answering
Yes
in the first round when the color of their hat is determined.
Additionally, they know that the other players also take this strategy, and use this knowledge to infer the color of their hat.
For each player, find whether they will have found out the color of their own hat after all rounds.
Process
T
test cases for each input file. | [
{
"input": "7\n3\nRBR\n4\nBRBR\n5\nBBBBB\n5\nBBBRR\n20\nBRBBRRRRBRRBRBBBRRBR\n50\nRRBRRRBBBRRRBBBRRBRRBBRBRRBBRRRRRBBBBBRRRBRBRRBRRR\n100\nBRBRBRBBRRRBBRRBRBBRBBBRBBRBBRRRRBBRRBBBBBBBBBBBBRRBBRBBRBBBBRRRRRRRRRBRBBRBBBBRBBBRBRRBRRBBRBBBBBBB\n",
"output": "101\n0101\n11111\n10111\n10111111010101011101\n11111010111010111010101010101011111111111011111111\n1111111001111001111111010001111101011111111011011011111111111111111101111111111111010101011111111111\n"
}
] |
https://atcoder.jp/contests/wtf22-day2-open/tasks/wtf22_day2_b | Problem Statement
You are given integers
N
and
K
, and a permutation
P=(P_1,P_2,\cdots,P_N)
of
(1,2,\cdots,N)
.
You can perform the following operation any number of times, possibly zero.
Choose an integer
i
(
1 \leq i \leq N-K+1
).
Swap the values of the two greatest elements among
P_i,P_{i+1},\cdots,P_{i+K-1}
.
Find the number, modulo
998244353
, of permutations that
P
can be after your operations. | [
{
"input": "3 3\n2 3 1\n",
"output": "2\n"
},
{
"input": "3 2\n1 3 2\n",
"output": "6\n"
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n",
"output": "144\n"
},
{
"input": "20 5\n8 13 6 11 20 3 12 18 17 4 10 1 7 16 19 5 2 15 14 9\n",
"output": "1451520\n"
}
] |
https://atcoder.jp/contests/wtf22-day2-open/tasks/wtf22_day2_c | Problem Statement
There are
N
gems numbered
1
to
N
.
Gem
i
has a color
C_i
and a value
V_i
.
Here, colors are represented as integers from
1
through
N
.
A pair of two gems
(i,j)
is said to be a
good
pair if (and only if) they satisfy the following conditions:
C_i \neq C_j
,
V_i + V_j \leq L
.
You will make some number of good pairs from the
N
gems.
A gem must not belong to multiple pairs, but it is fine if some gems belong to no pairs.
Find the maximum possible total value of all gems in your pairs. | [
{
"input": "4 5\n1 2\n1 3\n2 1\n2 4\n",
"output": "4\n"
},
{
"input": "5 10\n3 8\n4 2\n1 5\n1 3\n1 2\n",
"output": "17\n"
},
{
"input": "9 10\n8 2\n7 10\n1 4\n3 0\n5 3\n3 6\n2 5\n5 9\n5 4\n",
"output": "34\n"
},
{
"input": "20 1000000000\n15 239276621\n15 910500852\n15 245532750\n15 715892722\n16 80707349\n15 257261830\n12 950300098\n15 322288793\n15 256358887\n15 504976376\n2 907119713\n15 152036484\n13 298766520\n15 480968804\n15 285187325\n13 755031424\n15 69837029\n15 88860861\n9 596982638\n15 272961035\n",
"output": "4704511147\n"
}
] |
https://atcoder.jp/contests/wtf22-day2-open/tasks/wtf22_day2_d | Problem Statement
You are given a sequence of positive integers
A_1,A_2,\cdots,A_N
.
Let
S=N+\sum_{1 \leq i \leq N}A_i
.
Cat Snuke has
S
cards.
Each card has an integer written on it. The integers on the cards are
A_1,A_2,\cdots,A_N,-1,\cdots,-1
.
Particularly, there are
\sum_{1 \leq i \leq N}A_i
cards with
-1
.
Snuke is now standing at the coordinate
0
on a number line.
He will perform the following operation
S
times.
Let
x
be the current coordinate of Snuke.
Choose and discard one of the cards he has.
Let
v
be the number on the discarded card, and jump to the coordinate
x+v
.
If he has jumped to the coordinate
0
, earn one coin.
For each
k=1,2,\cdots,N
, find the number, modulo
998244353
, of sequences of moves for Snuke such that he earns exactly
k
coins.
Note that you should count sequences of moves.
Namely, if two cards have the same number, discarding one of them is not distinguished from discarding the other. | [
{
"input": "2\n1 1\n",
"output": "2\n4\n"
},
{
"input": "3\n1 2 3\n",
"output": "140\n220\n144\n"
},
{
"input": "20\n16 6 15 19 1 9 6 1 11 7 6 12 3 11 11 18 10 9 15 5\n",
"output": "507808441\n401798892\n110460932\n680359166\n737048635\n442374434\n737773176\n980506765\n473506608\n693729211\n532774651\n621434128\n4273369\n839437048\n585784927\n590354055\n969740008\n825216624\n442091194\n660636013\n"
}
] |
https://atcoder.jp/contests/wtf22-day2-open/tasks/wtf22_day2_e | Problem Statement
You are given
N
non-negative integers
A_1,A_2,\cdots,A_N
.
For each
k=1,2,\cdots,N
, solve the following problem.
Alice and Bob play the following game.
Alice chooses
k
numbers from
A_1,A_2,\cdots,A_N
.
Let
x_1,x_2,\cdots,x_k
be the chosen numbers (in arbitrary order).
Bob makes a sequence of
2k
non-negative integers
y=(y_1,y_2,\cdots,y_{2k})
, which must satisfy the following conditions.
0 \leq y_1 \leq y_2 \leq \cdots \leq y_{2k}
.
Let
z_i=y_{2i-1} \oplus y_{2i}
. Then,
\{z_1,z_2,\cdots,z_k\}
coincides with
\{x_1,x_2,\cdots,x_k\}
as a multiset.
Here,
\oplus
denotes bitwise
\mathrm{XOR}
.
Let the
score
of the game be the value of
y_{2k}
.
Bob plays to minimize the score.
With this in mind, Alice plays to maximize the score.
What will the score be?
What is bitwise
\mathrm{XOR}
?
The bitwise
\mathrm{XOR}
of non-negative integers
A
and
B
,
A\ \mathrm{XOR}\ B
, is defined as follows.
When
A\ \mathrm{XOR}\ B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3\ \mathrm{XOR}\ 5 = 6
(in binary:
011\ \mathrm{XOR}\ 101 = 110
).
Generally, the bitwise
\mathrm{XOR}
of
k
non-negative integers
p_1, p_2, p_3, \dots, p_k
is defined to be
(\dots ((p_1\ \mathrm{XOR}\ p_2)\ \mathrm{XOR}\ p_3)\ \mathrm{XOR}\ \dots\ \mathrm{XOR}\ p_k)
, which one can prove to be independent of the order of
p_1, p_2, p_3, \dots p_k
. | [
{
"input": "3\n1 2 3\n",
"output": "2\n6\n6\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "1\n3\n5\n7\n9\n"
},
{
"input": "5\n1 2 4 8 16\n",
"output": "16\n24\n28\n30\n31\n"
},
{
"input": "20\n167660508 377125547 866003430 419036363 234113368 201296307 408194538 249252693 207212853 190504619 306027011 652875643 335898069 545795899 204268068 274532279 342039277 975300308 901270584 360957186\n",
"output": "536870912\n1610612736\n2684354560\n3758096384\n4831838208\n4831838208\n4831838208\n4831838208\n4831838208\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n"
}
] |
https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_a | Problem Statement
You, the game master, and
N
players play a
Hat Guessing Game
.
The players line up behind one another, numbered
1
to
N
from front to back.
Each player wears a red or blue hat.
The colors of the hats are represented by a string
S
: player
i
wears a red hat if the
i
-th character of
S
is
R
, and a blue hat if it is
B
.
You know the string
S
, but the players do not.
Each player can only see the colors of hats of the players in front of them (namely, the players with smaller player numbers).
Particularly, they cannot see the color of their own hat.
The game goes as follows.
First, you count the numbers of players with red hats and those with blue hats, and tell them to all players.
Then, you repeat the following sequence of events (called a
round
)
10^{100}
times.
You ask each player, "Have you found out the color of your own hat?"
Each player will honestly answer
Yes
or
No
without being heard by other players.
After asking all players, you announce all players who have answered
Yes
.
All players can hear this announcement.
Note that you just announce the player numbers and not the colors of their hats.
All players are extremely clever and know that the other players are also clever.
They start answering
Yes
in the first round when the color of their hat is determined.
Additionally, they know that the other players also take this strategy, and use this knowledge to infer the color of their hat.
For each player, find whether they will have found out the color of their own hat after all rounds.
Process
T
test cases for each input file. | [
{
"input": "7\n3\nRBR\n4\nBRBR\n5\nBBBBB\n5\nBBBRR\n20\nBRBBRRRRBRRBRBBBRRBR\n50\nRRBRRRBBBRRRBBBRRBRRBBRBRRBBRRRRRBBBBBRRRBRBRRBRRR\n100\nBRBRBRBBRRRBBRRBRBBRBBBRBBRBBRRRRBBRRBBBBBBBBBBBBRRBBRBBRBBBBRRRRRRRRRBRBBRBBBBRBBBRBRRBRRBBRBBBBBBB\n",
"output": "101\n0101\n11111\n10111\n10111111010101011101\n11111010111010111010101010101011111111111011111111\n1111111001111001111111010001111101011111111011011011111111111111111101111111111111010101011111111111\n"
}
] |
https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_b | Problem Statement
You are given integers
N
and
K
, and a permutation
P=(P_1,P_2,\cdots,P_N)
of
(1,2,\cdots,N)
.
You can perform the following operation any number of times, possibly zero.
Choose an integer
i
(
1 \leq i \leq N-K+1
).
Swap the values of the two greatest elements among
P_i,P_{i+1},\cdots,P_{i+K-1}
.
Find the number, modulo
998244353
, of permutations that
P
can be after your operations. | [
{
"input": "3 3\n2 3 1\n",
"output": "2\n"
},
{
"input": "3 2\n1 3 2\n",
"output": "6\n"
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n",
"output": "144\n"
},
{
"input": "20 5\n8 13 6 11 20 3 12 18 17 4 10 1 7 16 19 5 2 15 14 9\n",
"output": "1451520\n"
}
] |
https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_c | Problem Statement
There are
N
gems numbered
1
to
N
.
Gem
i
has a color
C_i
and a value
V_i
.
Here, colors are represented as integers from
1
through
N
.
A pair of two gems
(i,j)
is said to be a
good
pair if (and only if) they satisfy the following conditions:
C_i \neq C_j
,
V_i + V_j \leq L
.
You will make some number of good pairs from the
N
gems.
A gem must not belong to multiple pairs, but it is fine if some gems belong to no pairs.
Find the maximum possible total value of all gems in your pairs. | [
{
"input": "4 5\n1 2\n1 3\n2 1\n2 4\n",
"output": "4\n"
},
{
"input": "5 10\n3 8\n4 2\n1 5\n1 3\n1 2\n",
"output": "17\n"
},
{
"input": "9 10\n8 2\n7 10\n1 4\n3 0\n5 3\n3 6\n2 5\n5 9\n5 4\n",
"output": "34\n"
},
{
"input": "20 1000000000\n15 239276621\n15 910500852\n15 245532750\n15 715892722\n16 80707349\n15 257261830\n12 950300098\n15 322288793\n15 256358887\n15 504976376\n2 907119713\n15 152036484\n13 298766520\n15 480968804\n15 285187325\n13 755031424\n15 69837029\n15 88860861\n9 596982638\n15 272961035\n",
"output": "4704511147\n"
}
] |
https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_d | Problem Statement
You are given a sequence of positive integers
A_1,A_2,\cdots,A_N
.
Let
S=N+\sum_{1 \leq i \leq N}A_i
.
Cat Snuke has
S
cards.
Each card has an integer written on it. The integers on the cards are
A_1,A_2,\cdots,A_N,-1,\cdots,-1
.
Particularly, there are
\sum_{1 \leq i \leq N}A_i
cards with
-1
.
Snuke is now standing at the coordinate
0
on a number line.
He will perform the following operation
S
times.
Let
x
be the current coordinate of Snuke.
Choose and discard one of the cards he has.
Let
v
be the number on the discarded card, and jump to the coordinate
x+v
.
If he has jumped to the coordinate
0
, earn one coin.
For each
k=1,2,\cdots,N
, find the number, modulo
998244353
, of sequences of moves for Snuke such that he earns exactly
k
coins.
Note that you should count sequences of moves.
Namely, if two cards have the same number, discarding one of them is not distinguished from discarding the other. | [
{
"input": "2\n1 1\n",
"output": "2\n4\n"
},
{
"input": "3\n1 2 3\n",
"output": "140\n220\n144\n"
},
{
"input": "20\n16 6 15 19 1 9 6 1 11 7 6 12 3 11 11 18 10 9 15 5\n",
"output": "507808441\n401798892\n110460932\n680359166\n737048635\n442374434\n737773176\n980506765\n473506608\n693729211\n532774651\n621434128\n4273369\n839437048\n585784927\n590354055\n969740008\n825216624\n442091194\n660636013\n"
}
] |
https://atcoder.jp/contests/wtf22-day2/tasks/wtf22_day2_e | Problem Statement
You are given
N
non-negative integers
A_1,A_2,\cdots,A_N
.
For each
k=1,2,\cdots,N
, solve the following problem.
Alice and Bob play the following game.
Alice chooses
k
numbers from
A_1,A_2,\cdots,A_N
.
Let
x_1,x_2,\cdots,x_k
be the chosen numbers (in arbitrary order).
Bob makes a sequence of
2k
non-negative integers
y=(y_1,y_2,\cdots,y_{2k})
, which must satisfy the following conditions.
0 \leq y_1 \leq y_2 \leq \cdots \leq y_{2k}
.
Let
z_i=y_{2i-1} \oplus y_{2i}
. Then,
\{z_1,z_2,\cdots,z_k\}
coincides with
\{x_1,x_2,\cdots,x_k\}
as a multiset.
Here,
\oplus
denotes bitwise
\mathrm{XOR}
.
Let the
score
of the game be the value of
y_{2k}
.
Bob plays to minimize the score.
With this in mind, Alice plays to maximize the score.
What will the score be?
What is bitwise
\mathrm{XOR}
?
The bitwise
\mathrm{XOR}
of non-negative integers
A
and
B
,
A\ \mathrm{XOR}\ B
, is defined as follows.
When
A\ \mathrm{XOR}\ B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3\ \mathrm{XOR}\ 5 = 6
(in binary:
011\ \mathrm{XOR}\ 101 = 110
).
Generally, the bitwise
\mathrm{XOR}
of
k
non-negative integers
p_1, p_2, p_3, \dots, p_k
is defined to be
(\dots ((p_1\ \mathrm{XOR}\ p_2)\ \mathrm{XOR}\ p_3)\ \mathrm{XOR}\ \dots\ \mathrm{XOR}\ p_k)
, which one can prove to be independent of the order of
p_1, p_2, p_3, \dots p_k
. | [
{
"input": "3\n1 2 3\n",
"output": "2\n6\n6\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "1\n3\n5\n7\n9\n"
},
{
"input": "5\n1 2 4 8 16\n",
"output": "16\n24\n28\n30\n31\n"
},
{
"input": "20\n167660508 377125547 866003430 419036363 234113368 201296307 408194538 249252693 207212853 190504619 306027011 652875643 335898069 545795899 204268068 274532279 342039277 975300308 901270584 360957186\n",
"output": "536870912\n1610612736\n2684354560\n3758096384\n4831838208\n4831838208\n4831838208\n4831838208\n4831838208\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n5100273664\n"
}
] |
https://atcoder.jp/contests/wtf22-day1-open/tasks/wtf22_day1_a | Problem Statement
You keep
N
monsters numbered
1
to
N
.
A hero has come to slay your monsters.
He will take
M
turns to attack the monsters.
In the
i
-th turn, he performs one of the following actions.
Consume
1
MP to attack monster
X_i
.
This action can only be performed when monster
X_i
is still alive and the hero has at least
1
MP.
Do nothing.
If the hero attacks, you will respond by performing one of the following actions.
Consume
1
MP to defend monster
X_i
.
This action can only be performed when you have at least
1
MP.
Do nothing. The monster will die.
Before the first turn begins, the hero has
A
MP, and you have
B
MP.
Both you and the hero know all values of
N
,
M
,
A
,
B
, and
X_i
.
Find the greatest integer
k
that satisfies the following condition.
By using an appropriate strategy, you can keep at least
k
monsters alive no matter how the hero acts. | [
{
"input": "2 3 2 1\n1 2 1\n",
"output": "1\n"
},
{
"input": "2 6 3 2\n1 1 1 2 2 2\n",
"output": "1\n"
},
{
"input": "100 1 1 1\n100\n",
"output": "100\n"
},
{
"input": "6 20 16 5\n5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/wtf22-day1-open/tasks/wtf22_day1_b | Problem Statement
You are given a permutation
P=(P_1,P_2,\cdots,P_N)
of
(1,2,\cdots,N)
.
Find one sequence of integer pairs
((l_1,r_1),(l_2,r_2),\cdots,(l_k,r_k))
that satisfies all of the following conditions.
The length
k
of the sequence satisfies
0 \leq k \leq N-1
.
1 \leq l_i \leq r_i \leq N
(
1 \leq i \leq k
).
For each
1 \leq i \leq k-1
, it holds that
r_{i+1} \leq l_i
or
r_i \leq l_{i+1}
.
Performing the following
k
operations sorts
P
in ascending order.
The
i
-th operation: swap the values of
P_{l_i}
and
P_{r_i}
.
If
l_i=r_i
, do nothing.
It can be proved that such a sequence always exists under the constraints of this problem.
Process
T
test cases for each input file. | [
{
"input": "3\n3\n2 3 1\n4\n4 3 2 1\n1\n1\n",
"output": "2\n2 3\n1 2\n3\n1 4\n1 1\n2 3\n0\n"
}
] |
https://atcoder.jp/contests/wtf22-day1-open/tasks/wtf22_day1_c | Problem Statement
You are given a tree
T
with
N
vertices numbered
1
to
N
.
The
i
-th edge connects vertices
A_i
and
B_i
.
You can perform the following operation any number of times, possibly zero.
Choose two leaves
u
and
v
of
T
such that the distance between them is odd.
Then, remove
u
and
v
from
T
(along with the incident edges).
Here, a vertex is said to be a leaf when its degree is exactly one at the time of the operation.
The distance between two vertices is the number of edges in the path connecting those vertices.
Find the number, modulo
998244353
, of sets that can be the vertex set of
T
after your operations. | [
{
"input": "4\n1 2\n2 3\n3 4\n",
"output": "3\n"
},
{
"input": "5\n2 1\n3 1\n4 1\n5 3\n",
"output": "3\n"
},
{
"input": "8\n2 1\n3 2\n4 1\n5 2\n6 5\n7 3\n8 7\n",
"output": "11\n"
},
{
"input": "24\n12 7\n14 4\n8 13\n24 13\n1 3\n4 9\n17 2\n1 21\n24 22\n11 1\n15 17\n22 5\n23 10\n24 12\n13 6\n12 16\n10 21\n19 22\n20 17\n4 20\n20 6\n10 18\n21 6\n",
"output": "5359\n"
}
] |
https://atcoder.jp/contests/wtf22-day1-open/tasks/wtf22_day1_d | Problem Statement
There are
M
competitive programmers (kyopro-ers) numbered
1
to
M
, who will visit Tokyo during the
N
days starting today.
Kyopro-er
i
will stay in Tokyo from the
L_i
-th day through the
R_i
-th day (
1 \leq L_i \leq R_i \leq N
).
Maroon is planning dinner parties with them.
If a dinner party is held on the
x
-th day (
1 \leq x \leq N
), he can make friends with all kyopro-ers
i
with
L_i \leq x \leq R_i
.
For each
k=1,2,\cdots,N
, solve the following problem.
Find the maximum number of kyopro-ers Maroon can make friends with if he holds exactly
k
dinner parties. | [
{
"input": "3 3\n1 1\n1 2\n3 3\n",
"output": "2\n3\n3\n"
},
{
"input": "4 4\n1 1\n2 2\n3 3\n4 4\n",
"output": "1\n2\n3\n4\n"
},
{
"input": "3 6\n1 1\n1 2\n1 2\n2 3\n2 3\n3 3\n",
"output": "4\n6\n6\n"
},
{
"input": "20 15\n15 19\n1 8\n6 11\n3 11\n11 17\n6 6\n16 20\n7 11\n11 14\n2 19\n1 3\n7 7\n6 19\n14 15\n15 15\n",
"output": "7\n11\n12\n13\n14\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n"
}
] |
https://atcoder.jp/contests/wtf22-day1-open/tasks/wtf22_day1_e | Problem Statement
You are given positive integers
N
and
M
. Here,
N<M
.
A sequence of
N
non-negative integers
a=(a_1,a_2,\cdots,a_N)
is said to be a
good
sequence when it satisfies the following condition:
0 \leq a_1 \leq a_2 \leq \cdots \leq a_N \leq M
.
For a good sequence
a
, let
f(a)
be the sequence resulting from sorting
(a_1-1,a_2-2,\cdots,a_N-N)
in ascending order.
For each
k=1,2,\cdots,N
, solve the following problem.
Assume that we have found the
k
-th element of
f(a)
for every possible good sequence
a
.
Find the sum, modulo
998244353
, of these values.
※ The answer should be between
0
and
998244352
even if the sum is negative. | [
{
"input": "2 3\n",
"output": "998244349\n4\n"
},
{
"input": "3 4\n",
"output": "998244329\n0\n24\n"
},
{
"input": "4 6\n",
"output": "998244233\n35\n175\n330\n"
},
{
"input": "10 1000000\n",
"output": "297189103\n747015740\n88545731\n123651717\n920498165\n977169022\n775771117\n810877103\n152407094\n602233731\n"
}
] |
https://atcoder.jp/contests/wtf22-day1/tasks/wtf22_day1_a | Problem Statement
You keep
N
monsters numbered
1
to
N
.
A hero has come to slay your monsters.
He will take
M
turns to attack the monsters.
In the
i
-th turn, he performs one of the following actions.
Consume
1
MP to attack monster
X_i
.
This action can only be performed when monster
X_i
is still alive and the hero has at least
1
MP.
Do nothing.
If the hero attacks, you will respond by performing one of the following actions.
Consume
1
MP to defend monster
X_i
.
This action can only be performed when you have at least
1
MP.
Do nothing. The monster will die.
Before the first turn begins, the hero has
A
MP, and you have
B
MP.
Both you and the hero know all values of
N
,
M
,
A
,
B
, and
X_i
.
Find the greatest integer
k
that satisfies the following condition.
By using an appropriate strategy, you can keep at least
k
monsters alive no matter how the hero acts. | [
{
"input": "2 3 2 1\n1 2 1\n",
"output": "1\n"
},
{
"input": "2 6 3 2\n1 1 1 2 2 2\n",
"output": "1\n"
},
{
"input": "100 1 1 1\n100\n",
"output": "100\n"
},
{
"input": "6 20 16 5\n5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/wtf22-day1/tasks/wtf22_day1_b | Problem Statement
You are given a permutation
P=(P_1,P_2,\cdots,P_N)
of
(1,2,\cdots,N)
.
Find one sequence of integer pairs
((l_1,r_1),(l_2,r_2),\cdots,(l_k,r_k))
that satisfies all of the following conditions.
The length
k
of the sequence satisfies
0 \leq k \leq N-1
.
1 \leq l_i \leq r_i \leq N
(
1 \leq i \leq k
).
For each
1 \leq i \leq k-1
, it holds that
r_{i+1} \leq l_i
or
r_i \leq l_{i+1}
.
Performing the following
k
operations sorts
P
in ascending order.
The
i
-th operation: swap the values of
P_{l_i}
and
P_{r_i}
.
If
l_i=r_i
, do nothing.
It can be proved that such a sequence always exists under the constraints of this problem.
Process
T
test cases for each input file. | [
{
"input": "3\n3\n2 3 1\n4\n4 3 2 1\n1\n1\n",
"output": "2\n2 3\n1 2\n3\n1 4\n1 1\n2 3\n0\n"
}
] |
https://atcoder.jp/contests/wtf22-day1/tasks/wtf22_day1_c | Problem Statement
You are given a tree
T
with
N
vertices numbered
1
to
N
.
The
i
-th edge connects vertices
A_i
and
B_i
.
You can perform the following operation any number of times, possibly zero.
Choose two leaves
u
and
v
of
T
such that the distance between them is odd.
Then, remove
u
and
v
from
T
(along with the incident edges).
Here, a vertex is said to be a leaf when its degree is exactly one at the time of the operation.
The distance between two vertices is the number of edges in the path connecting those vertices.
Find the number, modulo
998244353
, of sets that can be the vertex set of
T
after your operations. | [
{
"input": "4\n1 2\n2 3\n3 4\n",
"output": "3\n"
},
{
"input": "5\n2 1\n3 1\n4 1\n5 3\n",
"output": "3\n"
},
{
"input": "8\n2 1\n3 2\n4 1\n5 2\n6 5\n7 3\n8 7\n",
"output": "11\n"
},
{
"input": "24\n12 7\n14 4\n8 13\n24 13\n1 3\n4 9\n17 2\n1 21\n24 22\n11 1\n15 17\n22 5\n23 10\n24 12\n13 6\n12 16\n10 21\n19 22\n20 17\n4 20\n20 6\n10 18\n21 6\n",
"output": "5359\n"
}
] |
https://atcoder.jp/contests/wtf22-day1/tasks/wtf22_day1_d | Problem Statement
There are
M
competitive programmers (kyopro-ers) numbered
1
to
M
, who will visit Tokyo during the
N
days starting today.
Kyopro-er
i
will stay in Tokyo from the
L_i
-th day through the
R_i
-th day (
1 \leq L_i \leq R_i \leq N
).
Maroon is planning dinner parties with them.
If a dinner party is held on the
x
-th day (
1 \leq x \leq N
), he can make friends with all kyopro-ers
i
with
L_i \leq x \leq R_i
.
For each
k=1,2,\cdots,N
, solve the following problem.
Find the maximum number of kyopro-ers Maroon can make friends with if he holds exactly
k
dinner parties. | [
{
"input": "3 3\n1 1\n1 2\n3 3\n",
"output": "2\n3\n3\n"
},
{
"input": "4 4\n1 1\n2 2\n3 3\n4 4\n",
"output": "1\n2\n3\n4\n"
},
{
"input": "3 6\n1 1\n1 2\n1 2\n2 3\n2 3\n3 3\n",
"output": "4\n6\n6\n"
},
{
"input": "20 15\n15 19\n1 8\n6 11\n3 11\n11 17\n6 6\n16 20\n7 11\n11 14\n2 19\n1 3\n7 7\n6 19\n14 15\n15 15\n",
"output": "7\n11\n12\n13\n14\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n"
}
] |
https://atcoder.jp/contests/wtf22-day1/tasks/wtf22_day1_e | Problem Statement
You are given positive integers
N
and
M
. Here,
N<M
.
A sequence of
N
non-negative integers
a=(a_1,a_2,\cdots,a_N)
is said to be a
good
sequence when it satisfies the following condition:
0 \leq a_1 \leq a_2 \leq \cdots \leq a_N \leq M
.
For a good sequence
a
, let
f(a)
be the sequence resulting from sorting
(a_1-1,a_2-2,\cdots,a_N-N)
in ascending order.
For each
k=1,2,\cdots,N
, solve the following problem.
Assume that we have found the
k
-th element of
f(a)
for every possible good sequence
a
.
Find the sum, modulo
998244353
, of these values.
※ The answer should be between
0
and
998244352
even if the sum is negative. | [
{
"input": "2 3\n",
"output": "998244349\n4\n"
},
{
"input": "3 4\n",
"output": "998244329\n0\n24\n"
},
{
"input": "4 6\n",
"output": "998244233\n35\n175\n330\n"
},
{
"input": "10 1000000\n",
"output": "297189103\n747015740\n88545731\n123651717\n920498165\n977169022\n775771117\n810877103\n152407094\n602233731\n"
}
] |
https://atcoder.jp/contests/ahc023/tasks/asprocon10_a | Problem Statement
There is a rectangular piece of land with size
H \times W
.
This land is divided into square
blocks
of size
1 \times 1
, and some of the boundaries between the blocks are separated by
waterways
.
The border of the land is surrounded by fences except for a single
entrance
, which is the only way to enter or exit the land.
The entrance is set on one side of a single block.
You plan to grow
crops
on this land.
When planting or harvesting crops, you will need to move agricultural machinery from the entrance to the block you plan to work on.
However, there are no fixed pathways set as the passage for the machinery.
As it would be a challenging task to establish the pathways now, you have decided to move the machinery through the blocks which are not currently being used for growing crops.
In other words, when planting or harvesting crops in a particular block, it must be possible to reach to the block from the entrance while satisfying the following conditions:
You can only move to the four adjacent blocks from each block (moving diagonally is not allowed).
Yon cannot move from one block to another if they are separated by a waterway.
You may not pass through blocks which are currently being used for growing crops.
There are
K
kinds of crops available for planting, numbered
1, 2, \dots, K
.
You are to choose some of them to be planted and harvested in the following
T
months.
To plant crop
k
, you will need to plant it
no later than
the
S_k
-th month, and harvest it
at
the
D_k
-th month.
You can plant crop
k
before the
S_k
-th month, but even if you plant it earlier than required, you cannot harvest it before
D_k
-th month.
It is allowed to plant any kind of crop in any block, but one kind of crop cannot be planted in multiple blocks, and multiple kinds of crops cannot be planted in a single block.
Please make a planting plan which maximizes the utility of the land.
Details of the land
The land has coordinates with the northwest corner at
(0, 0)
, the southwest corner at
(H, 0)
, the northeast corner at
(0, W)
, and the southeast corner at
(H, W)
.
The block at the
i+1
-th row from the north and the
j+1
-th column from the west is a square with diagonal points
(i, j)
and
(i + 1, j + 1)
.
This square is referred to as block
(i, j)
(
0 \le i \le H - 1
,
0 \le j \le W - 1
).
The entrance is set at the west side of block
(i_0, 0)
(that is, on the segment between coordinates
(i_0, 0)
and
(i_0 + 1, 0)
).
For the blocks which shares sides, whether there is a waterway between them is determined by the given input.
Please refer to the "Input" section for the details of the input format for the waterway.
Details of the planting plan
A planting plan describes which crop are grown on which blocks, and when they are planted.
It is represented by a sequence
(k_1, i_1, j_1, s_1), \dots, (k_M, i_M, j_M, s_M)
.
The
m
-th element of this sequence signifies that crop
k_m
is planted in block
(i_m, j_m)
on the
s_m
-th month.
Based on a given planting plan, the following actions are taken on the
t
-th month (
t = 1, 2, \dots, T
).
At the beginning of the
t
-th month, for all
m
where
s_m = t
, crop
k_m
is planted in block
(i_m, j_m)
. During this process,
(i_m, j_m)
must be reachable from the entrance without crossing waterways or passing through blocks where crops are currently growing in.
At the end of the
t
-th month, for all
m
where
D_{k_m} = t
, crop
k_m
is harvested from block
(i_m, j_m)
. During this process,
(i_m, j_m)
must be reachable from the entrance without crossing waterways or passing through blocks where crops are currently growing in.
When planting multiple crops in a same month, the reachability condition above may depend on the order in which crops are planted.
For example, if crops
k_1
and
k_2
are to be planted in a same month, and
(i_2, j_2)
cannot be reached without passing through
(i_1, j_1)
, then planting crop
k_1
before
k_2
blocks the way for planting
k_2
.
In this case, a planting plan is considered valid if there exists an order such that planting them by the order does not lead to the situation above.
Such an order will be calculated by the judging program, so it does not have to be determined in the output.
Similarly, when harvesting multiple crops in a same month, the order of the crops will be calculated by the judging program and does not have to be determined in the output.
The planting plan must satisfy the following conditions.
The same crop can only be planted in the same block.
A block can only contains at most one kind of crop at the same time.
When planting crop
k
, it must be planted before
S_k
-th month.
When planting or harvesting crop, the target crop must be reachable from the entrance.
Note that, it is not required to plant all the
K
crops. | [
{
"input": "10 6 6 3\n011010\n000001\n011000\n000110\n011000\n00000\n10001\n10010\n00110\n10101\n10000\n20\n2 10\n1 10\n4 10\n1 10\n2 9\n4 5\n2 8\n4 10\n4 9\n1 9\n1 3\n1 6\n1 7\n3 6\n8 10\n1 7\n3 8\n2 8\n1 10\n2 10\n",
"output": "12\n1 0 0 2\n2 0 1 1\n3 1 0 4\n4 0 2 1\n5 3 1 2\n6 2 0 4\n7 4 0 2\n10 3 2 1\n15 2 0 8\n18 5 0 2\n19 0 3 1\n20 4 1 2\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_a | Problem Statement
Takahashi likes full moons.
Let today be day
1
. The first day on or after today on which he can see a full moon is day
M
. After that, he can see a full moon every
P
days, that is, on day
M+P
, day
M+2P
, and so on.
Find the number of days between day
1
and day
N
, inclusive, on which he can see a full moon. | [
{
"input": "13 3 5\n",
"output": "3\n"
},
{
"input": "5 6 6\n",
"output": "0\n"
},
{
"input": "200000 314 318\n",
"output": "628\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_b | Problem Statement
There are
N
rectangular sheets spread out on a coordinate plane.
Each side of the rectangular region covered by each sheet is parallel to the
x
- or
y
-axis.
Specifically, the
i
-th sheet covers exactly the region satisfying
A_i \leq x\leq B_i
and
C_i \leq y\leq D_i
.
Let
S
be the area of
the region covered by one or more sheets
. It can be proved that
S
is an integer under the constraints.
Print
S
as an integer. | [
{
"input": "3\n0 5 1 3\n1 4 0 5\n2 5 2 4\n",
"output": "20\n"
},
{
"input": "2\n0 100 0 100\n0 100 0 100\n",
"output": "10000\n"
},
{
"input": "3\n0 1 0 1\n0 3 0 5\n5 10 0 10\n",
"output": "65\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_c | Problem Statement
Takahashi is planning an
N
-day train trip.
For each day, he can pay the regular fare or use a one-day pass.
Here, for
1\leq i\leq N
, the regular fare for the
i
-th day of the trip is
F_i
yen.
On the other hand, a batch of
D
one-day passes is sold for
P
yen. You can buy as many passes as you want, but only in units of
D
.
Each purchased pass can be used on any day, and it is fine to have some leftovers at the end of the trip.
Find the minimum possible total cost for the
N
-day trip, that is, the cost of purchasing one-day passes plus the total regular fare for the days not covered by one-day passes. | [
{
"input": "5 2 10\n7 1 6 3 6\n",
"output": "20\n"
},
{
"input": "3 1 10\n1 2 3\n",
"output": "6\n"
},
{
"input": "8 3 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "3000000000\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_d | Problem Statement
You are given a weighted undirected complete graph with
N
vertices numbered from
1
to
N
. The edge connecting vertices
i
and
j
(i< j)
has a weight of
D_{i,j}
.
When choosing some number of edges under the following condition, find the maximum possible total weight of the chosen edges.
The endpoints of the chosen edges are pairwise distinct. | [
{
"input": "4\n1 5 4\n7 8\n6\n",
"output": "13\n"
},
{
"input": "3\n1 2\n3\n",
"output": "3\n"
},
{
"input": "16\n5 6 5 2 1 7 9 7 2 5 5 2 4 7 6\n8 7 7 9 8 1 9 6 10 8 8 6 10 3\n10 5 8 1 10 7 8 4 8 6 5 1 10\n7 4 1 4 5 4 5 10 1 5 1 2\n2 9 9 7 6 2 2 8 3 5 2\n9 10 3 1 1 2 10 7 7 5\n10 6 1 8 9 3 2 4 2\n10 10 8 9 2 10 7 9\n5 8 8 7 5 8 2\n4 2 2 6 8 3\n2 7 3 10 3\n5 7 10 3\n8 5 7\n9 1\n4\n",
"output": "75\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_e | Problem Statement
You are given a sequence of positive integers of length
N
:
A=(A_1,A_2,\ldots,A_N)
. Find the number of triples of positive integers
(i,j,k)
that satisfy all of the following conditions:
1\leq i < j < k\leq N
,
A_i = A_k
,
A_i \neq A_j
. | [
{
"input": "5\n1 2 1 3 2\n",
"output": "3\n"
},
{
"input": "7\n1 2 3 4 5 6 7\n",
"output": "0\n"
},
{
"input": "13\n9 7 11 7 3 8 1 13 11 11 11 6 13\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_f | Problem Statement
There is an octopus-shaped robot and
N
treasures on a number line.
The
i
-th treasure
(1\leq i\leq N)
is located at coordinate
X_i
.
The robot has one head and
N
legs, and the
i
-th leg
(1\leq i\leq N)
has a length of
L_i
.
Find the number of
integers
k
such that the robot can grab all
N
treasures as follows.
Place the head at coordinate
k
.
Repeat the following for
i=1,2,\ldots,N
in this order: if there is a treasure that has not been grabbed yet within a distance of
L_i
from the head, that is, at a coordinate
x
satisfying
k-L_i\leq x\leq k+L_i
, choose one such treasure and grab it. | [
{
"input": "3\n-6 0 7\n3 5 10\n",
"output": "6\n"
},
{
"input": "1\n0\n1000000000000000000\n",
"output": "2000000000000000001\n"
},
{
"input": "2\n-100 100\n1 1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_g | Problem Statement
You are given a simple connected undirected graph
G
with
N
vertices and
M
edges.
The vertices and edges of
G
are numbered as vertex
1
, vertex
2
,
\ldots
, vertex
N
, and edge
1
, edge
2
,
\ldots
, edge
M
, respectively, and edge
i
(1\leq i\leq M)
connects vertices
U_i
and
V_i
.
You are also given distinct vertices
A,B,C
on
G
.
Determine if there is a simple path connecting vertices
A
and
C
via vertex
B
.
What is a simple connected undirected graph?
A graph
G
is said to be a simple connected undirected graph when
G
is an undirected graph that is simple and connected.
A graph
G
is said to be an undirected graph when the edges of
G
have no direction.
A graph
G
is simple when
G
does not contain self-loops or multi-edges.
A graph
G
is connected when one can travel between all vertices of
G
via edges.
What is a simple path via vertex
Z
?
For vertices
X
and
Y
on a graph
G
, a simple path connecting
X
and
Y
is a sequence of distinct vertices
(v_1,v_2,\ldots,v_k)
such that
v_1=X
,
v_k=Y
, and for every integer
i
satisfying
1\leq i\leq k-1
, there is an edge on
G
connecting vertices
v_i
and
v_{i+1}
.
A simple path
(v_1,v_2,\ldots,v_k)
is said to be via vertex
Z
when there is an
i
(2\leq i\leq k-1)
satisfying
v_i=Z
. | [
{
"input": "6 7\n1 3 2\n1 2\n1 5\n2 3\n2 5\n2 6\n3 4\n4 5\n",
"output": "Yes\n"
},
{
"input": "6 6\n1 3 2\n1 2\n2 3\n2 5\n2 6\n3 4\n4 5\n",
"output": "No\n"
},
{
"input": "3 2\n1 3 2\n1 2\n2 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc318/tasks/abc318_h | Problem Statement
Snuke has come up with the following problem.
You are given permutations
P=(P_1,P_2,\ldots,P_N)
and
Q=(Q_1,Q_2,\ldots,Q_N)
of
(1,2,\ldots,N)
.
Let us build a graph with
N
vertices and
N
edges as follows.
For
i=1,2,\ldots,N
in this order, draw an edge of weight
Q_i
connecting vertices
i
and
P_i
bidirectionally.
When removing some number of edges to eliminate cycles from the graph, find the minimum possible total weight of the removed edges.
Alice and Bob came up with the following solutions.
Alice:
Initialize the answer to
0
. For
i=1,2,\ldots,N
in this order, if the edge connecting vertices
i
and
P_i
is contained in a cycle, remove that edge and add its weight to the answer.
Bob:
Initialize the answer to
0
. For
i=N,N-1,\ldots,1
in this order, if the edge connecting vertices
i
and
P_i
is contained in a cycle, remove that edge and add its weight to the answer.
Snuke has realized that their solutions are both incorrect, and he wants to know the number of inputs for which neither of their solutions gives the correct answer.
Among the
(N!)^2
possible inputs, find the number, modulo
998244353
, of inputs for which neither Alice's nor Bob's solution gives the correct answer. | [
{
"input": "3\n",
"output": "4\n"
},
{
"input": "2\n",
"output": "0\n"
},
{
"input": "6\n",
"output": "314708\n"
},
{
"input": "318\n",
"output": "321484323\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_a | Problem Statement
In Japan, swallows can be observed from April through September.
Given an integer
M
between
1
and
12
, determine if swallows can be observed in month
M
(where January is month
1
). | [
{
"input": "4\n",
"output": "Yes\n"
},
{
"input": "12\n",
"output": "No\n"
},
{
"input": "9\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_b | Problem Statement
You are given three positive integers
A
,
B
, and
C
.
Print
Yes
if
A
,
B
, and
C
are all equal, and
No
otherwise. | [
{
"input": "3 3 3\n",
"output": "Yes\n"
},
{
"input": "7 7 8\n",
"output": "No\n"
},
{
"input": "1 2 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_c | Problem Statement
You are going to hold a competitive programming contest several times.
Holding a contest requires preparing a total of eight problems: one problem of each
difficulty
from
1
through
8
.
You have prepared
N
problems, the
i
-th of which is of difficulty
A_i
.
If you cannot use the same problem for multiple contests, at most how many contests can you hold with the
N
problems prepared? | [
{
"input": "10\n1 2 3 4 5 5 6 7 8 8\n",
"output": "1\n"
},
{
"input": "27\n3 1 4 1 5 2 6 5 3 5 8 7 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7\n",
"output": "2\n"
},
{
"input": "1\n1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_d | Problem Statement
You held a programming contest. There were
N
participants, and the
i
-th
(1\leq i\leq N)
of them scored
A _ i
points.
In order to make their scores integers between
0
and
10^9
(inclusive), you are going to determine the relative score of the
i
-th participant for each
i=1,2,\ldots,N
by the following expression:
\operatorname{round}\left(10^9\times\dfrac{A _ i}{\max _ iA _ i}\right)
.
Here,
\max _ iA _ i
denotes the maximum value among
A _ i
, and
\operatorname{round}(x)
denotes
x
rounded off to an integer.
Formally,
\max _ iA _ i
is
A _ i
that satisfies
A _ j\leq A _ i
for all
j (1\leq j\leq N)
, and
\operatorname{round}(x)
is the unique integer
n
satisfying
n-\dfrac12\leq x\lt n+\dfrac12
.
Find the relative score of the
i
-th participant for
i=1,2,\ldots,N
. | [
{
"input": "3\n200 600 300\n",
"output": "333333333 1000000000 500000000\n"
},
{
"input": "2\n1 999999999\n",
"output": "1 1000000000\n"
},
{
"input": "10\n55580908 183811851 247188750 266233976 335843599 344138315 389659771 389921297 698238479 720357617\n",
"output": "77157382 255167498 343147270 369585841 466217877 477732597 540925454 541288504 969294226 1000000000\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_e | Problem Statement
Given a positive integer
X
,
find the minimum non-negative integer
n
such that
X\leq 10^n
. | [
{
"input": "23\n",
"output": "2\n"
},
{
"input": "1\n",
"output": "0\n"
},
{
"input": "12345678901234567890\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_h | Problem Statement
You are making plans for an upcoming
N
-day vacation.
On each day, you will either "play" or "study."
Among the
N
days, you need to study on at least
M
days.
You will not study on two or more days in a row.
If you play on day
i
, you get a
joy
of
A_i
; if you study, the joy is
0
on that day.
Find the maximum possible total joy of the
N
days. | [
{
"input": "5 2\n3 2 4 1 5\n",
"output": "12\n"
},
{
"input": "5 2\n3 5 4 1 2\n",
"output": "11\n"
},
{
"input": "10 0\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "10000000000\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_i | Problem Statement
N
children are standing in line. Initially, the
i
-th child from the front has
A_i
candies.
You are going to repeat the following operation
M
times.
Give
K
candies to the child with the fewest candies (if there are multiple such children, to the frontmost one among them).
Find how many candies the children will have after the
M
operations. | [
{
"input": "4 3 2\n3 4 1 10\n",
"output": "5 4 5 10\n"
},
{
"input": "2 1000000000000 100000\n1000000000000 1\n",
"output": "50000500000000000 50000500000000001\n"
},
{
"input": "3 1415 9\n26 53 58\n",
"output": "4292 4292 4288\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_j | Problem Statement
The New Year's bell rang
N
times at equal intervals.
More specifically, the bell rang at times
t, d+t, 2d+t, \ldots, (N-1)d+t
for some positive integer
d
and integer
t
.
Takahashi heard the bell ring at times
A_1, A_2, \ldots, A_K
.
Although it is certain that the bell actually rang when Takahashi heard the sound, the bell may have also rung at other times.
You are given
N
,
K
, and
A_1, A_2, \ldots, A_K
.
List all possible values for the positive integer
d
in ascending order
.
Under the constraints of this problem, it can be proved that the number of possible values for
d
is finite. | [
{
"input": "8 3\n3 7 15\n",
"output": "2\n2 4\n"
},
{
"input": "500 22\n30 42 138 318 354 378 450 462 522 582 630 738 834 894 930 942 1002 1050 1062 1110 1146 1158\n",
"output": "4\n3 4 6 12\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_k | Problem Statement
There is an
N \times N
grid. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th square from the left.
Each square is one of the following: the starting point, a goal, a passage, and a hole. The state of the square
(i,j)
is given as
S_{i,j}
.
S
indicates that the square is the starting point. There is exactly one starting point.
G
indicates that the square is a goal. There is one or more goals.
.
indicates that the square is a passage.
X
indicates that the square is a hole.
Solve the following problem for
k=1,2,\dots,N-1
.
You are initially at the starting square. Then, you repeat the following operation.
Choose one of the four directions: up, down, left, right. Move
k
squares consecutively in the chosen direction.
You may not pass through a hole square or exit the grid by the operation.
Determine if you can be at a goal square at the end of an operation, and if so, find the minimum number of operations required to do so.
Note that passing through a goal in the middle of an operation does not count as finishing at a goal square. | [
{
"input": "5\nSX...\n.....\n..GX.\n..XG.\nX.X.G\n",
"output": "4\n2\n-1\n-1\n"
},
{
"input": "2\nGX\nXS\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_l | Problem Statement
You are given a sequence of length
N
consisting of positive integers,
A=(A_1,A_2,\ldots,A_N)
, and an empty set
S
.
Let us define
f(L,R)
as
\displaystyle\sum_{i=L+1}^R \frac{A_i}{R-L}
for a pair of integers
(L,R)
such that
0\leq L<R\leq N
.
Process
Q
queries in the given order.
Each query is of one of the following two types.
Type
1
: You are given an integer
x
satisfying
0\leq x\leq N
. If
x
is not in
S
, add
x
to
S
; otherwise, remove
x
from
S
.
Type
2
: Let
X
be the maximum value of
f(l,r)
over all pairs of integers
(l,r)
such that
l,r\in S
and
0\leq l<r\leq N
. Then,
X
is uniquely represented as
\frac{P}{Q}
using positive integers
P
and
Q
that are coprime. Print
P
and
Q
separated by spaces. It is guaranteed that at the time this query is given, there is at least one pair
(l,r)
such that
l,r\in S
and
0\leq l<r\leq N
. | [
{
"input": "3 8\n2 3 5\n1 0\n1 3\n2\n1 2\n2\n1 1\n1 3\n2\n",
"output": "10 3\n5 1\n3 1\n"
},
{
"input": "2 3\n1 1\n1 0\n1 2\n2\n",
"output": "1 1\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_m | Problem Statement
There are two line segments in the
xy
-plane. The endpoints of the
i
-th line segment are at coordinates
(a_i,b_i)
and
(c_i,d_i)
.
Determine if these two line segments intersect. | [
{
"input": "0 0 10 10\n0 10 10 0\n",
"output": "Yes\n"
},
{
"input": "0 0 10 0\n0 10 0 0\n",
"output": "Yes\n"
},
{
"input": "0 0 10 0\n0 10 0 1\n",
"output": "No\n"
},
{
"input": "0 3 8 7\n0 3 8 7\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_n | Problem Statement
For a multiset (set with duplicate elements allowed)
S
of positive integers, let us define the function
f(S)
as follows.
First, let
A=(A_0,A_1,...,A_{|S|-1})
be the sorted list of the elements of
S
in ascending order.
Then, let
f(S)=\displaystyle \sum_{i=0}^{|S|-1} K^i A_i
. This constant
K
is given from the input.
Here, let
f(S)=0
if
S
is empty.
There is an initially empty multiset
T
. Let us perform the following operations on this set
Q
times in total.
+
X
Add one instance of
x
to
T
.
-
x
Remove one instance of
x
from
T
. It is guaranteed that at least one instance of
x
exists in
T
at this time.
After each operation, find the value of
f(T)
modulo
998244353
at that time. | [
{
"input": "10 2\n+ 7\n- 7\n+ 2\n+ 3\n- 2\n+ 3\n+ 5\n- 3\n+ 998244352\n+ 5\n",
"output": "7\n0\n2\n8\n3\n9\n29\n13\n9\n25\n"
}
] |
https://atcoder.jp/contests/past16-open/tasks/past202309_o | Problem Statement
You are given a sequence of length
N
,
A=(A_1,A_2,\ldots,A_N)
, and another of length
K
,
P=(P_1,P_2,\ldots,P_K)
.
We now perform the following
Q
operations on the sequence
A
.
The
q
-th operation
(1\leq q \leq Q)
is represented by integers
l_q,r_q\ (1\leq l_q \leq r_q\leq N)
and a sequence of length
K
,
b_q = (b_{q,1},b_{q,2},\ldots,b_{q,K})
.
For the
q
-th operation, consider the infinite sequence
B=(B_1,B_2,\ldots)
determined by the following linear recurrence relation, and add
B_i
to
A_{l_q+i-1}
for each
i=1,2,\ldots,r_q-l_q+1
.
B_j=b_{q,j}\ (1\leq j \leq K)
B_j=P_1B_{j-1}+P_2B_{j-2}+\ldots +P_KB_{j-K}\ (j > K)
Find the value, modulo
998244353
, of each element of
A
after all the operations. | [
{
"input": "5 2 3\n0 0 0 0 0\n2 1\n1 4\n3 1\n3 5\n4 1\n2 2\n5 9\n",
"output": "3 6 9 12 6\n"
},
{
"input": "1 3 1\n5\n1 0 1\n1 1\n3 1 4\n",
"output": "8\n"
},
{
"input": "10 3 5\n306334866 801978559 895954374 576826717 755317213 872021310 894146017 171871727 347837426 489203653\n259995927 523608184 755770553\n4 7\n822177140 73169010 811074390\n7 8\n739309938 819084714 711663615\n1 9\n105947194 88003242 226522376\n6 8\n544083472 975159386 830222368\n1 9\n478160947 233931690 460328037\n",
"output": "890443007 125669138 584560434 427420890 15883850 302004751 273022029 711724605 576696309 489203653\n"
}
] |
https://atcoder.jp/contests/toyota2023summer-final-open/tasks/toyota2023summer_final_a | Problem Statement
There is a warehouse with a grid of
D\times D
squares.
Let
(0,0)
be the coordinates of the northwesternmost square and
(i,j)
be the coordinates of the squares located
i
squares to the south and
j
squares to the east from there.
The warehouse entrance is in the square
(0,(D-1)/2)
, where
D
is an odd number.
There are impassable obstacles placed in
N
squares out the
D^2-4
squares except for the entrance and its
3
adjacent squares.
D^2-1-N
containers are brought into the warehouse one by one.
Each container is assigned a unique number from
0
to
D^2-2-N
which indicates the order in which the containers are to be transported out.
Information on the order of containers is not given in advance, and the number assigned to a container is revealed at the time it is brought in.
Each
D\times D-1-N
square other than the entrance and obstacles can hold at most
1
container.
Each time a container is brought in, choose a square to store it.
The chosen square must satisfy the following conditions.
It is neither the entrance nor an obstacle square, and there are no other containers stored at the chosen square.
It must be reachable from the entrance by only passing through adjacent empty squares in the four directions.
After all the containers are stored, please transport out all of them one by one.
The container to be transported out must satisfy the following conditions.
The square containing the container to be transported out must be reachable from the entrance by only passing through adjacent empty squares in the four directions.
Optimize the storage location of the containers and the order in which they are transported out so that the order is as close as possible to the specified order. | [] |
https://atcoder.jp/contests/toyota2023summer-final/tasks/toyota2023summer_final_a | Problem Statement
There is a warehouse with a grid of
D\times D
squares.
Let
(0,0)
be the coordinates of the northwesternmost square and
(i,j)
be the coordinates of the squares located
i
squares to the south and
j
squares to the east from there.
The warehouse entrance is in the square
(0,(D-1)/2)
, where
D
is an odd number.
There are impassable obstacles placed in
N
squares out the
D^2-4
squares except for the entrance and its
3
adjacent squares.
D^2-1-N
containers are brought into the warehouse one by one.
Each container is assigned a unique number from
0
to
D^2-2-N
which indicates the order in which the containers are to be transported out.
Information on the order of containers is not given in advance, and the number assigned to a container is revealed at the time it is brought in.
Each
D\times D-1-N
square other than the entrance and obstacles can hold at most
1
container.
Each time a container is brought in, choose a square to store it.
The chosen square must satisfy the following conditions.
It is neither the entrance nor an obstacle square, and there are no other containers stored at the chosen square.
It must be reachable from the entrance by only passing through adjacent empty squares in the four directions.
After all the containers are stored, please transport out all of them one by one.
The container to be transported out must satisfy the following conditions.
The square containing the container to be transported out must be reachable from the entrance by only passing through adjacent empty squares in the four directions.
Optimize the storage location of the containers and the order in which they are transported out so that the order is as close as possible to the specified order. | [] |
https://atcoder.jp/contests/abc317/tasks/abc317_a | Problem Statement
Naohiro has a monster. The monster's current health is
H
.
He also has
N
kinds of potions, numbered from
1
to
N
in ascending order of effectiveness.
If you give the monster potion
n
, its health will increase by
P_n
. Here,
P_1 \lt P_2 \lt \dots \lt P_N
.
He wants to increase the monster's health to
X
or above by giving it one of the potions.
Print the number of the least effective potion that can achieve the purpose. (The constraints guarantee that such a potion exists.) | [
{
"input": "3 100 200\n50 200 999\n",
"output": "2\n"
},
{
"input": "2 10 21\n10 999\n",
"output": "2\n"
},
{
"input": "10 500 999\n38 420 490 585 613 614 760 926 945 999\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_b | Problem Statement
Naohiro had
N+1
consecutive integers, one of each, but he lost one of them.
The remaining
N
integers are given in arbitrary order as
A_1,\ldots,A_N
. Find the lost integer.
The given input guarantees that the lost integer is uniquely determined. | [
{
"input": "3\n2 3 5\n",
"output": "4\n"
},
{
"input": "8\n3 1 4 5 9 2 6 8\n",
"output": "7\n"
},
{
"input": "16\n152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150\n",
"output": "151\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_c | Problem Statement
A region has
N
towns numbered
1
to
N
, and
M
roads numbered
1
to
M
.
The
i
-th road connects town
A_i
and town
B_i
bidirectionally with length
C_i
.
Find the maximum possible total length of the roads you traverse when starting from a town of your choice and getting to another town without passing through the same town more than once. | [
{
"input": "4 4\n1 2 1\n2 3 10\n1 3 100\n1 4 1000\n",
"output": "1110\n"
},
{
"input": "10 1\n5 9 1\n",
"output": "1\n"
},
{
"input": "10 13\n1 2 1\n1 10 1\n2 3 1\n3 4 4\n4 7 2\n4 8 1\n5 8 1\n5 9 3\n6 8 1\n6 9 5\n7 8 1\n7 9 4\n9 10 3\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_d | Problem Statement
Takahashi and Aoki are competing in an election.
There are
N
electoral districts. The
i
-th district has
X_i + Y_i
voters, of which
X_i
are for Takahashi and
Y_i
are for Aoki. (
X_i + Y_i
is always an odd number.)
In each district, the majority party wins all
Z_i
seats in that district. Then, whoever wins the majority of seats in the
N
districts as a whole wins the election. (
\displaystyle \sum_{i=1}^N Z_i
is odd.)
At least how many voters must switch from Aoki to Takahashi for Takahashi to win the election? | [
{
"input": "1\n3 8 1\n",
"output": "3\n"
},
{
"input": "2\n3 6 2\n1 8 5\n",
"output": "4\n"
},
{
"input": "3\n3 4 2\n1 2 3\n7 2 6\n",
"output": "0\n"
},
{
"input": "10\n1878 2089 16\n1982 1769 13\n2148 1601 14\n2189 2362 15\n2268 2279 16\n2394 2841 18\n2926 2971 20\n3091 2146 20\n3878 4685 38\n4504 4617 29\n",
"output": "86\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_e | Problem Statement
There is a field divided into a grid of
H
rows and
W
columns.
The square at the
i
-th row from the north (top) and the
j
-th column from the west (left) is represented by the character
A_{i, j}
. Each character represents the following.
.
: An empty square. Passable.
#
: An obstacle. Impassable.
>
,
v
,
<
,
^
: Squares with a person facing east, south, west, and north, respectively. Impassable. The person's line of sight is one square wide and extends straight in the direction the person is facing, and is blocked by an obstacle or another person. (See also the description at Sample Input/Output
1
.)
S
: The starting point. Passable. There is exactly one starting point. It is guaranteed not to be in a person's line of sight.
G
: The goal. Passable. There is exactly one goal. It is guaranteed not to be in a person's line of sight.
Naohiro is at the starting point and can move one square to the east, west, south, and north as many times as he wants. However, he cannot enter an impassable square or leave the field.
Determine if he can reach the goal without entering a person's line of sight, and if so, find the minimum number of moves required to do so. | [
{
"input": "5 7\n....Sv.\n.>.....\n.......\n>..<.#<\n^G....>\n",
"output": "15\n"
},
{
"input": "4 3\nS..\n.<.\n.>.\n..G\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_f | Problem Statement
You are given integers
N,A_1,A_2,A_3
. Find the number, modulo
998244353
, of triples of positive integers
(X_1,X_2,X_3)
that satisfy all of the following three conditions.
1\leq X_i \leq N
for every
i
.
X_i
is a multiple of
A_i
for every
i
.
(X_1 \oplus X_2) \oplus X_3 = 0
, where
\oplus
denotes bitwise xor.
What is bitwise xor?
The bitwise xor of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows.
When
A \oplus B
is written in binary, the
2^k
s place (
k \geq 0
) is
1
if exactly one of the
2^k
s places of
A
and
B
is
1
, and
0
otherwise.
For instance,
3 \oplus 5 = 6
(in binary:
011 \oplus 101 = 110
). | [
{
"input": "13 2 3 5\n",
"output": "4\n"
},
{
"input": "1000000000000000000 1 1 1\n",
"output": "426724011\n"
},
{
"input": "31415926535897932 3 8 4\n",
"output": "759934997\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_g | Problem Statement
There is a grid with
N
rows and
M
columns. The square at the
i
-th row from the top and the
j
-th column from the left contains the integer
A_{i,j}
.
Here, the squares contain
M
occurrences of each of
1,\ldots,N
, for a total of
NM
integers.
You perform the following operations to swap the numbers written on the squares.
For
i=1,\ldots,N
in this order, do the following.
Freely rearrange the numbers written in the
i
-th row. That is, freely choose a permutation
P=(P_{1},\ldots,P_{M})
of
1,\ldots,M
, and replace
A_{i,1},\ldots,A_{i,M}
with
A_{i,P_{1}},\ldots,A_{i,P_{M}}
simultaneously.
Your goal is to perform the operations so that each column contains each of
1,\ldots,N
once. Determine if this is possible, and if so, print such a resulting grid. | [
{
"input": "3 2\n1 1\n2 3\n2 3\n",
"output": "Yes\n1 1\n3 2\n2 3\n"
},
{
"input": "4 4\n1 2 3 4\n1 1 1 2\n3 2 2 4\n4 4 3 3\n",
"output": "Yes\n1 4 3 2\n2 1 1 1\n4 2 2 3\n3 3 4 4\n"
}
] |
https://atcoder.jp/contests/abc317/tasks/abc317_h | Problem Statement
We have a directed graph with
N
vertices numbered
1
to
N
. The graph has no multi-edges but can have self-loops. Also, every edge in the graph satisfies the following condition.
If the edge goes from vertex
s
to vertex
t
, then
s
and
t
satisfy at least one of
0 \leq t - s\leq 2
and
t = 1
.
The presence or absence of an edge in the graph is represented by sequences
A, B, C, D
, each of length
N
. Each element of
A, B, C, D
has the following meaning. (Let
A_n
denote the
n
-th element of
A
; the same applies to
B_n, C_n, D_n
.)
A_n
is
1
if there is an edge from vertex
n
to vertex
n
, and
0
otherwise.
B_n
is
1
if there is an edge from vertex
n
to vertex
n+1
, and
0
otherwise. (Here,
B_N = 0
.)
C_n
is
1
if there is an edge from vertex
n
to vertex
n+2
, and
0
otherwise. (Here,
C_{N-1} = C_N = 0
.)
D_n
is
1
if there is an edge from vertex
n
to vertex
1
, and
0
otherwise. (Here,
D_1 = A_1
.)
In the given graph, find the number, modulo
998244353
, of walks with
K
edges starting at vertex
1
and ending at vertex
N
.
Here, a walk with
K
edges starting at vertex
1
and ending at vertex
N
is a sequence of vertices
v_0 = 1, v_1, \dots, v_K = N
such that for each
i
(0 \leq i \lt K)
there is an edge from vertex
v_i
to vertex
v_{i + 1}
. Two walks are distinguished when they differ as sequences. | [
{
"input": "3 3\n1 0 1\n1 1 0\n1 0 0\n1 0 1\n",
"output": "6\n"
},
{
"input": "4 6\n1 1 1 1\n1 1 1 0\n1 1 0 0\n1 0 0 0\n",
"output": "50\n"
},
{
"input": "10 500000\n0 1 0 1 0 0 0 0 1 1\n1 1 1 0 1 1 1 0 1 0\n0 0 1 1 0 0 1 1 0 0\n0 1 1 1 1 1 0 1 1 0\n",
"output": "866263864\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_a | 問題文
広義単調増加な正整数列
(a_1,\ldots,a_N)
が与えられます。
以下の条件をすべて満たす正整数の組
(i,j)
が何個あるかを求めてください。
1 \leq i \lt j \leq N
a_i
は
a_j
の倍数 | [
{
"input": "3\n2 2 3\n",
"output": "1\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "10\n"
},
{
"input": "15\n2 17 22 25 26 29 45 47 72 75 75 81 82 84 97\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_b | 問題文
正整数
N,Q
が与えられます。
i=1,2,\ldots,Q
に対し以下の問題を解いてください。
項数
N
、初項
a_i
、公差
d_i
の等差数列から
k_i
個の項を選んだとき、そのスコアを選ばれた項の積とする。
\binom{N}{k_i}
通りの選び方に対するスコアの総和を
(10^9+7)
で割った余りを求めよ。 | [
{
"input": "4 3\n1 1 1\n1 1 2\n3 5 3\n",
"output": "10\n35\n3318\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_c | 問題文
黒板に
N
以下の正整数が
1
個ずつ書かれています。また、
M
個の正整数
x_1,\ldots,x_M
が与えられます。ここで、
i \neq j
ならば
x_i
と
x_j
は互いに素であることが保証されます。
あなたは次の操作を
0
回以上何度でも行えます。
1
以上
M
以下の整数
i
とある
x_i
の倍数
y
を選ぶ。黒板に
y
が書かれているならばそのうち
1
個を選び、
\frac{y}{x_i}
に書き換える。
操作後に黒板に書かれている整数の総和の最小値を求めてください。 | [
{
"input": "10 2\n2 3\n",
"output": "24\n"
},
{
"input": "2000000000 3\n20 23 7\n",
"output": "1597222223653885214\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_d | 問題文
正整数
K
と
4
種類の英大文字
ATGC
のみからなる文字列
S
が与えられます。
S君とU君がS君から始めて交互に次の操作を行います。
後述の条件を満たしながら以下の
3
種類の操作のうち
1
つを選んで実行する。
S
のある
1
文字を
ATGC
のどれか
1
文字に置換する。
S
のある位置(先頭・末尾でもよい)に
ATGC
のどれか
1
文字を挿入する。
S
のある
1
文字を削除する(この操作は
S
が非空の時にのみ行える)。
条件:操作前の文字列を
X
、操作後の文字列を
Y
とした時、以下の
2
つの条件を満たす
Y
の文字列長は
K
以下
Y
は
X
より辞書順で真に大きい
先に操作が出来なくなった方が負け、もう一方の人が勝ちとなります。
S君とU君が最善を尽くした場合、どちらが勝つかを判定してください。 | [
{
"input": "3\nAC\n",
"output": "S\n"
},
{
"input": "1\nT\n",
"output": "U\n"
},
{
"input": "1200\nAGC\n",
"output": "S\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_e | 問題文
(1,2,\ldots,N)
の順列
P=(p_1,p_2,\ldots,p_N)
が与えられます。
P
を
1
個以上の空でない連続部分列
X_1,X_2,\ldots,X_K
に分割し、以下のように
(m_1,m_2,\ldots,m_K)
を定めました。
i
が奇数ならば
m_i
は
X_i
に含まれる値の最小値
i
が偶数ならば
m_i
は
X_i
に含まれる値の最大値
(m_1,m_2,\ldots,m_K)
としてあり得るものの個数を
(10^9+7)
で割った余りを求めてください。 | [
{
"input": "3\n1 2 3\n",
"output": "3\n"
},
{
"input": "5\n5 4 1 3 2\n",
"output": "15\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_f | 問題文
以下の条件を満たす長さ
N+M
の文字列
X
が存在するかどうかを判定し、存在する場合は一つ示してください。
X
は
N
個の
0
と
M
個の
1
からなる
X
の長さ
K
の部分文字列はいずれも
1
をちょうど
S
個含む | [
{
"input": "2 1 2 1\n",
"output": "Yes\n010\n"
},
{
"input": "10 10 20 2\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_g | 問題文
S君は
xy
平面上の
(X,Y)
にある畑で農業を始めることにしました。
しかし、平面上には
N
頭のイノシシがいて畑を荒らそうとしています。
i
番目のイノシシは
(x_i,y_i)
に棲んでいます。
S君が対処法を求めて役所に相談したところ、
M
個の計画を提案されました。
i
番目の計画は直線
y = a_i x + b_i
上に柵を設置するというもので、実行する場合
2^{i-1}
円かかります。
畑を守るには
i=1,2,\ldots,N
すべてに対して、
(X,Y)
と
(x_i,y_i)
を結ぶ線分(端点含む)とある柵に対応する直線が交点を持つ必要があります。
計画を
0
個以上選んで実行し、畑を守るのに必要な金額の最小値を
C
円とします。
C
を
(10^9+7)
で割った余りを求めてください。
ただし、どのように計画を選んでも畑を守ることが出来ない場合、代わりに
-1
と出力してください。 | [
{
"input": "3 3 1 1\n2 4\n3 9\n-5 10\n-4 8\n3 -3\n-7 7\n",
"output": "5\n"
},
{
"input": "2 2 0 0\n10 3\n10 3\n5 2\n5 2\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/maximum-cup-2023/tasks/maximum_cup_2023_h | 問題文
変数
a
があり、初め
a=X
です。
i=1,2,\ldots,N
の順に次の操作をします。
1
以上
m_i
以下の整数を選び、
c
とする。そして、
a
を以下の条件を満たす整数
a'
の最小値に置き換える。
a \lt a'
a'
の二進数表記にはちょうど
c
個の
1
が含まれる
操作終了後の
a
の最大値を求めてください。 | [
{
"input": "1 11\n2\n",
"output": "16\n"
},
{
"input": "23 1000\n2 5 6 5 2 1 7 9 7 2 5 5 2 4 7 6 2 2 8 7 7 9 8\n",
"output": "4294967296\n"
}
] |
https://atcoder.jp/contests/editor-update-test/tasks/editor_update_test_a | 問題文
以下の条件を満たす整数の組
x,y
がいくつあるかを求めて下さい。
0 \leq x, y \leq N
Ax+By
は
C
の倍数
T
個のテストケースが与えられるので、それぞれについて答えを求めてください。 | [
{
"input": "1\n2 3 4 5\n",
"output": "2\n"
},
{
"input": "1\n1000 314159265 271828182 2023\n",
"output": "496\n"
}
] |
https://atcoder.jp/contests/editor-update-test/tasks/editor_update_test_b | 問題文
N
頂点の根付き木があります。根は頂点
1
です。頂点
i (2 \leq i \leq N)
の親は頂点
P_i
です。
各
i (1 \leq i \leq N)
について、頂点
i
を根とする部分木の頂点数を求めて下さい。すなわち、頂点
j
から頂点
1
へ到達するために必ず頂点
i
を経由する必要のあるような
j
の個数を求めて下さい。 | [
{
"input": "4\n1\n2\n2\n",
"output": "4\n3\n1\n1\n"
},
{
"input": "10\n1\n2\n3\n2\n1\n5\n6\n3\n4\n",
"output": "10\n7\n4\n2\n2\n2\n1\n1\n1\n1\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_a | Problem Statement
You are given a string
S
consisting of lowercase English letters.
Remove all occurrences of
a
,
e
,
i
,
o
,
u
from
S
and print the resulting string.
S
contains at least one character other than
a
,
e
,
i
,
o
,
u
. | [
{
"input": "atcoder\n",
"output": "tcdr\n"
},
{
"input": "xyz\n",
"output": "xyz\n"
},
{
"input": "aaaabbbbcccc\n",
"output": "bbbbcccc\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_b | Problem Statement
In the calendar of AtCoderLand, a year consists of
M
months: month
1
, month
2
,
\dots
, month
M
. The
i
-th month consists of
D_i
days: day
1
, day
2
,
\dots
, day
D_i
.
Furthermore, the number of days in a year is odd, that is,
D_1+D_2+\dots+D_M
is odd.
Find what day of what month is the middle day of the year.
In other words, let day
1
of month
1
be the first day, and find
a
and
b
such that the
((D_1+D_2+\dots+D_M+1)/2)
-th day is day
b
of month
a
. | [
{
"input": "12\n31 28 31 30 31 30 31 31 30 31 30 31\n",
"output": "7 2\n"
},
{
"input": "1\n1\n",
"output": "1 1\n"
},
{
"input": "6\n3 1 4 1 5 9\n",
"output": "5 3\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_c | Problem Statement
We have
N
cups of ice cream.
The flavor and deliciousness of the
i
-th cup are
F_i
and
S_i
, respectively (
S_i
is an even number).
You will choose and eat two of the
N
cups.
Your satisfaction here is defined as follows.
Let
s
and
t
(
s \ge t
) be the deliciousness of the eaten cups.
If the two cups have different flavors, your satisfaction is
\displaystyle s+t
.
Otherwise, your satisfaction is
\displaystyle s + \frac{t}{2}
.
Find the maximum achievable satisfaction. | [
{
"input": "4\n1 4\n2 10\n2 8\n3 6\n",
"output": "16\n"
},
{
"input": "4\n4 10\n3 2\n2 4\n4 12\n",
"output": "17\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_d | Problem Statement
There are
H \times W
cookies in
H
rows and
W
columns.
The color of the cookie at the
i
-row from the top and
j
-th column from the left is represented by a lowercase English letter
c_{i,j}
.
We will perform the following procedure.
1. For each row, perform the following operation: if there are two or more cookies remaining in the row and they all have the same color, mark them.
2. For each column, perform the following operation: if there are two or more cookies remaining in the column and they all have the same color, mark them.
3. If there are any marked cookies, remove them all and return to 1; otherwise, terminate the procedure.
Find the number of cookies remaining at the end of the procedure. | [
{
"input": "4 3\naaa\naaa\nabc\nabd\n",
"output": "2\n"
},
{
"input": "2 5\naaaaa\nabcde\n",
"output": "4\n"
},
{
"input": "3 3\nooo\nooo\nooo\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_e | Problem Statement
We have
N
books numbered
1
to
N
.
Book
i
assumes that you have read
C_i
books, the
j
-th of which is book
P_{i,j}
: you must read all these
C_i
books before reading book
i
.
Here, you can read all the books in some order.
You are trying to read the minimum number of books required to read book
1
.
Print the numbers of the books you must read excluding book
1
in the order they should be read. Under this condition, the set of books to read is uniquely determined.
If there are multiple reading orders that satisfy the condition, you may print any of them. | [
{
"input": "6\n3 2 3 4\n2 3 5\n0\n1 5\n0\n0\n",
"output": "5 3 4 2\n"
},
{
"input": "6\n1 2\n1 3\n1 4\n1 5\n1 6\n0\n",
"output": "6 5 4 3 2\n"
},
{
"input": "8\n1 5\n1 6\n1 7\n1 8\n0\n0\n0\n0\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_f | Problem Statement
There is a race through checkpoints
1,2,\dots,N
in this order on a coordinate plane.
The coordinates of checkpoint
i
are
(X_i,Y_i)
, and all checkpoints have different coordinates.
Checkpoints other than checkpoints
1
and
N
can be skipped.
However, let
C
be the number of checkpoints skipped, and the following penalty will be imposed:
\displaystyle 2^{C−1}
if
C>0
, and
0
if
C=0
.
Let
s
be the total distance traveled (Euclidean distance) from checkpoint
1
to checkpoint
N
plus the penalty.
Find the minimum achievable value as
s
. | [
{
"input": "6\n0 0\n1 1\n2 0\n0 1\n1 0\n2 1\n",
"output": "5.82842712474619009753\n"
},
{
"input": "10\n1 8\n3 7\n9 4\n4 9\n6 1\n7 5\n0 0\n1 3\n6 8\n6 4\n",
"output": "24.63441361516795872523\n"
},
{
"input": "10\n34 24\n47 60\n30 31\n12 97\n87 93\n64 46\n82 50\n14 7\n17 24\n3 78\n",
"output": "110.61238353245736230207\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_g | Problem Statement
You are given integers
N,A,B,C,X
. Find the number of triples of integers
(i,j,k)
that satisfy all of the following conditions.
1 \le i,j,k \le N
Ai+Bj+Ck=X | [
{
"input": "5 3 1 5 15\n",
"output": "3\n"
},
{
"input": "1 1 1 1 1\n",
"output": "0\n"
},
{
"input": "100000 31415 92653 58979 1000000000\n",
"output": "2896\n"
}
] |
https://atcoder.jp/contests/abc315/tasks/abc315_h | Problem Statement
You are given a sequence
(A_1, A_2, \ldots , A_N)
.
Let us define a sequence
(F_0, F_1, \ldots , F_N)
by the following formulae.
F_0 = 1
F_n = A_n\displaystyle\sum_{i+j<n}F_iF_j
(1 \leq n \leq N)
Find
F_1, \ldots , F_N
modulo
998244353
. | [
{
"input": "5\n1 2 3 4 5\n",
"output": "1 6 48 496 6240\n"
},
{
"input": "3\n12345 678901 2345678\n",
"output": "12345 790834943 85679169\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_a | Problem Statement
You are given a positive integer
N
.
Print an integer sequence of length
L \coloneqq N(N+1)/2
,
A = (A_1, A_2, \ldots, A_L)
, that satisfies all of the following conditions.
A
contains exactly
i
occurrences of
i
for every
i = 1, 2, \ldots, N
.
1 \leq |A_i - A_{i+1}| \leq 2
for every
i = 1, 2, \ldots, L
. Here,
A_{L+1}
means
A_1
.
It can be proved that, under the Constraints of this problem, there is always an integer sequence
A
of length
L
that satisfies all of the above conditions. | [
{
"input": "4\n",
"output": "1 3 4 2 4 3 4 2 4 3\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_b | Problem Statement
You are given a connected undirected graph
G
with
N
vertices and
M
edges. For each
i=1,2,\ldots,M
, the
i
-th edge connects vertices
a_i
and
b_i
, and is colored red if
c_i=
R
and blue if
c_i=
B
.
Determine if there is a spanning tree of
G
that satisfies the following condition, and if so, display such a tree.
For every
i=1,2,\ldots,N
,
if
s_i =
R
, at least one red edge has vertex
i
as its endpoint;
if
s_i =
B
, at least one blue edge has vertex
i
as its endpoint. | [
{
"input": "3 3\n1 2 R\n1 3 B\n2 3 B\nRRB\n",
"output": "Yes\n2 1\n"
},
{
"input": "3 4\n1 2 R\n1 2 B\n1 3 B\n2 3 B\nRRR\n",
"output": "No\n"
},
{
"input": "8 16\n5 7 B\n2 7 R\n1 6 R\n1 4 R\n6 7 R\n4 6 B\n4 8 R\n2 3 R\n3 5 R\n6 7 B\n2 6 B\n5 6 R\n1 3 B\n4 5 B\n2 7 B\n1 8 B\nBRBRRBRB\n",
"output": "Yes\n1 2 4 9 11 13 16\n"
},
{
"input": "8 10\n1 7 R\n1 3 B\n2 5 B\n2 8 R\n1 5 R\n3 6 R\n2 6 B\n3 4 B\n2 8 B\n4 6 B\nRRRBBBRB\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_c | Problem Statement
Takahashi and Aoki will play the following game.
For each
i=1,2,\ldots,N
in this order, do the following.
Write each integer from
l_i
through
r_i
once on the blackboard. (Here,
l_i
and
r_i
are non-negative integers from the input.)
While one or more integers are written on the blackboard, the players take turns doing the following, with Takahashi going first.
Choose and perform exactly one of the following two operations.
Delete all even numbers written on the blackboard, and replace each remaining integer with half its value rounded down to an integer.
Delete all odd numbers written on the blackboard, and replace each remaining integer with half its value.
When no integer is written on the blackboard, the game ends and the last player to perform an operation wins.
It can be proved that the game ends in a finite number of operations if Takahashi and Aoki act optimally. Find the winner in this case.
Solve the above problem for
T
cases. | [
{
"input": "3\n2\n1 2\n5 7\n1\n0 100\n10\n1312150450968413 28316250877914571\n74859962623690078 84324828731963974\n148049062628894320 252509054433933439\n269587449430302150 335408917861648766\n349993004923078531 354979173822804781\n522842184971407769 578223540024979436\n585335723211047194 615812229161735895\n645762258982631926 760713016476190622\n779547116602436424 819875141880895723\n822981260158260519 919845426262703496\n",
"output": "Aoki\nAoki\nTakahashi\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_d | Problem Statement
There are
N
squares: square
1
, square
2
,
\ldots
, square
N
. Each square is colored red or blue.
The colors of the squares are represented by a string
S
of length
N
. Specifically, for each
i = 1, 2, \ldots, N
, square
i
is colored red if the
i
-th character of
S
is
R
, and blue if it is
B
.
Square
N
is always colored blue.
Initially, each square has a chip of the same color as the square.
For each
i = 1, 2, \ldots, N-1
in this order, let us perform the following operation.
Choose an integer
j
such that
i \lt j \leq N
and square
j
is colored
blue
, and place the pile of chips on square
i
on top of the pile of chips on square
j
, keeping the order of the chips.
Print the number of possible sequences of colors of chips of the
N
-chip pile on square
N
from top to bottom after the above process, modulo
998244353
. | [
{
"input": "4\nRBRB\n",
"output": "2\n"
},
{
"input": "20\nRRBRRRBBRBBBBRBRBRBB\n",
"output": "92378\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_e | Problem Statement
You are given a positive integer
N
and integer sequences of length
N
:
A=(a_1,\ldots,a_N)
and
B=(b_1,\ldots,b_N)
.
Let
X
be the multiset of
N^2
instances
(a_i+b_j)(1 \leq i,j \leq N)
.
For an
N \times N
matrix
M
whose elements are integers between
-10^{18}
and
10^{18}
, inclusive, we define the score as follows.
Let
S
be the multiset of
N^2
instances, each of which is the sum of the
2N-1
elements in the
i
-th row or
j
-th column of
M
(1 \leq i,j \leq N)
. Then, the score is the sum of
\min(
the multiplicity of
z
in
X
, the multiplicity of
z
in
S)
over all integers
z
.
Find a matrix
M
with the maximum score.
Solve the above problem for
T
cases. | [
{
"input": "3\n1\n5\n-10\n2\n0 -1\n8 -11\n3\n20 23 26\n1 2 3\n",
"output": "-5\n8 9\n-10 -9\n2 9 4\n7 5 3\n6 1 8\n"
}
] |
https://atcoder.jp/contests/agc064/tasks/agc064_f | Problem Statement
You are given a positive integer
N
.
Print the number, modulo
998244353
, of sequences
A
of length
3N
that contain each integer from
1
through
N
three times and satisfy the following condition.
A
has no contiguous subsequence of length
N
that is a permutation of the sequence
(1, 2, \ldots, N)
. | [
{
"input": "3\n",
"output": "132\n"
},
{
"input": "123456\n",
"output": "31984851\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_a | Problem Statement
The number pi to the
100
-th decimal place is
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
.
You are given an integer
N
between
1
and
100
, inclusive.
Print the value of pi to the
N
-th decimal place.
More precisely, truncate the value of pi to
N
decimal places and print the result without removing the trailing
0
s. | [
{
"input": "2\n",
"output": "3.14\n"
},
{
"input": "32\n",
"output": "3.14159265358979323846264338327950\n"
},
{
"input": "100\n",
"output": "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_b | Problem Statement
N
people, person
1
, person
2
,
\ldots
, person
N
, are playing roulette.
The outcome of a spin is one of the
37
integers from
0
to
36
.
For each
i = 1, 2, \ldots, N
, person
i
has bet on
C_i
of the
37
possible outcomes:
A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}
.
The wheel has been spun, and the outcome is
X
.
Print the numbers of all people who have bet on
X
with the fewest bets, in
ascending order
.
More formally, print all integers
i
between
1
and
N
, inclusive, that satisfy both of the following conditions, in
ascending order
:
Person
i
has bet on
X
.
For each
j = 1, 2, \ldots, N
, if person
j
has bet on
X
, then
C_i \leq C_j
.
Note that there may be no number to print (see Sample Input 2). | [
{
"input": "4\n3\n7 19 20\n4\n4 19 24 0\n2\n26 10\n3\n19 31 24\n19\n",
"output": "2\n1 4\n"
},
{
"input": "3\n1\n1\n1\n2\n1\n3\n0\n",
"output": "0\n\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_c | Problem Statement
You are given a string
S
of length
N
consisting of lowercase English letters.
Each character of
S
is painted in one of the
M
colors: color
1
, color
2
, ..., color
M
; for each
i = 1, 2, \ldots, N
, the
i
-th character of
S
is painted in color
C_i
.
For each
i = 1, 2, \ldots, M
in this order, let us perform the following operation.
Perform a right circular shift by
1
on the part of
S
painted in color
i
.
That is, if the
p_1
-th,
p_2
-th,
p_3
-th,
\ldots
,
p_k
-th characters are painted in color
i
from left to right, then simultaneously replace the
p_1
-th,
p_2
-th,
p_3
-th,
\ldots
,
p_k
-th characters of
S
with the
p_k
-th,
p_1
-th,
p_2
-th,
\ldots
,
p_{k-1}
-th characters of
S
, respectively.
Print the final
S
after the above operations.
The constraints guarantee that at least one character of
S
is painted in each of the
M
colors. | [
{
"input": "8 3\napzbqrcs\n1 2 3 1 2 2 1 2\n",
"output": "cszapqbr\n"
},
{
"input": "2 1\naa\n1 1\n",
"output": "aa\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_d | Problem Statement
You are given a string
S
of length
N
consisting of uppercase and lowercase English letters.
Let us perform
Q
operations on the string
S
.
The
i
-th operation
(1\leq i\leq Q)
is represented by a tuple
(t _ i,x _ i,c _ i)
of two integers and one character, as follows.
If
t _ i=1
, change the
x _ i
-th character of
S
to
c _ i
.
If
t _ i=2
, convert all uppercase letters in
S
to lowercase (do not use
x _ i,c _ i
for this operation).
If
t _ i=3
, convert all lowercase letters in
S
to uppercase (do not use
x _ i,c _ i
for this operation).
Print the
S
after the
Q
operations. | [
{
"input": "7\nAtCoder\n5\n1 4 i\n3 0 a\n1 5 b\n2 0 a\n1 4 Y\n",
"output": "atcYber\n"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n10\n2 0 a\n1 19 G\n1 13 m\n1 2 E\n1 21 F\n2 0 a\n1 27 b\n3 0 a\n3 0 a\n1 15 i\n",
"output": "TEEQUICKBROWMFiXJUGPFOVERTBELAZYDOG\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_e | Problem Statement
There are
N
roulette wheels.
The
i
-th
(1\leq i\leq N)
wheel has
P _ i
integers
S _ {i,1},S _ {i,2},\ldots,S _ {i,P _ i}
written on it, and you can play it once by paying
C _ i
yen.
When you play the
i
-th wheel once, an integer
j
between
1
and
P _ i
, inclusive, is chosen uniformly at random, and you earn
S _ {i,j}
points.
The points you earn from the wheels are determined independently of past results.
Takahashi wants to earn at least
M
points.
Takahashi will act to minimize the amount of money he pays before he earns at least
M
points.
After each play, he can choose which wheel to play next based on the previous results.
Find the expected amount of money Takahashi will pay before he earns at least
M
points.
More formal definition
Here is a more formal statement.
For a strategy that Takahashi can adopt in choosing which wheel to play, the expected amount of money
E
that he pays before he earns at least
M
points with that strategy is defined as follows.
For a natural number
X
, let
f(X)
be the expected amount of money Takahashi pays before he earns at least
M
points or plays the wheels
X
times in total according to that strategy. Let
E=\displaystyle\lim _ {X\to+\infty}f(X)
.
Under the conditions of this problem, it can be proved that
\displaystyle\lim _ {X\to+\infty}f(X)
is finite no matter what strategy Takahashi adopts.
Find the value of
E
when he adopts a strategy that minimizes
E
. | [
{
"input": "3 14\n100 2 5 9\n50 4 1 2 4 8\n70 5 2 4 2 8 8\n",
"output": "215.913355350494384765625\n"
},
{
"input": "2 100\n1 2 1 2\n10 6 0 0 0 0 0 100\n",
"output": "60\n"
},
{
"input": "20 90\n3252 9 0 4 2 7 3 2 3 2 4\n2147 1 1\n4033 8 0 4 1 7 5 2 5 0\n3795 6 6 6 2 3 2 2\n3941 7 2 4 4 7 2 0 5\n2815 6 2 1 0 5 2 2\n3020 2 3 6\n3858 9 4 2 7 3 0 4 4 6 5\n4533 10 3 6 4 0 6 4 4 2 7 7\n4198 8 6 7 0 6 3 6 5 6\n3739 8 2 7 1 5 1 4 4 7\n2465 4 1 4 0 1\n4418 9 7 6 2 4 6 1 5 0 7\n5450 12 0 4 4 7 7 4 4 5 4 5 3 7\n4196 9 1 6 5 5 7 2 3 6 3\n4776 9 2 2 7 3 6 6 1 6 6\n2286 3 3 5 6\n3152 3 4 1 5\n3509 7 0 6 7 0 1 0 3\n2913 6 0 1 5 0 5 6\n",
"output": "45037.072314895291126319493887599716\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_f | Problem Statement
N
players, player
1
, player
2
, ..., player
N
, participate in a game tournament. Just before the tournament starts, each player forms a one-person team, so there are
N
teams in total.
The tournament has a total of
N-1
matches. In each match, two different teams are chosen. One team goes first, and the other goes second. Each match will result in exactly one team winning. Specifically, for each
i = 1, 2, \ldots, N-1
, the
i
-th match proceeds as follows.
The team with player
p_i
goes first, and the team with player
q_i
goes second.
Let
a
and
b
be the numbers of players in the first and second teams, respectively. The first team wins with probability
\frac{a}{a+b}
, and the second team wins with probability
\frac{b}{a+b}
.
Then, the two teams are combined into a single team.
The result of each match is independent of those of the others.
For each of the
N
players, print the expected number of times the team with that player wins throughout the tournament, modulo
998244353
.
How to print an expected value modulo
998244353
It can be proved that the sought expected value is always rational. Also, the constraints of this problem guarantee that if the sought expected value is expressed as an irreducible fraction
\frac{y}{x}
, then
x
is not divisible by
998244353
.
Now, there is a unique integer
z
between
0
and
998244352
, inclusive, such that
xz \equiv y \pmod{998244353}
. Report this
z
. | [
{
"input": "5\n1 2\n4 3\n5 3\n1 4\n",
"output": "698771048 698771048 964969543 964969543 133099248\n"
},
{
"input": "15\n9 2\n8 10\n13 6\n12 11\n7 10\n4 10\n14 2\n5 4\n1 15\n15 2\n6 9\n8 11\n6 3\n2 8\n",
"output": "43970290 310168785 806914186 501498951 950708909 272140427 335124893 168750835 310168785 168750835 280459129 280459129 272140427 476542843 43970290\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_g | Problem Statement
There are
N
monsters in a cave: monster
1
, monster
2
,
\ldots
, monster
N
. Each monster has a positive integer
attack power
and a
type
represented by an integer between
1
and
M
, inclusive.
Specifically, for
i = 1, 2, \ldots, N
, the attack power and type of monster
i
are
A_i
and
B_i
, respectively.
Takahashi will go on an adventure in this cave with a
health
of
H
and some of the
M
amulets: amulet
1
, amulet
2
,
\ldots
, amulet
M
.
In the adventure, Takahashi performs the following steps for
i = 1, 2, \ldots, N
in this order (as long as his health does not drop to
0
or below).
If Takahashi has not brought amulet
B_i
with him, monster
i
will attack him and decrease his health by
A_i
.
Then,
if his health is greater than
0
, he defeats monster
i
;
otherwise, he dies without defeating monster
i
and ends his adventure.
Solve the following problem for each
K = 0, 1, \ldots, M
independently.
Find the maximum number of monsters that Takahashi can defeat when choosing
K
of the
M
amulets to bring on the adventure.
The constraints guarantee that there is at least one monster of type
i
for each
i = 1, 2, \ldots, M
. | [
{
"input": "7 3 7\n3 2\n1 1\n4 2\n1 2\n5 1\n9 3\n2 3\n",
"output": "2 5 7 7\n"
},
{
"input": "15 5 400\n29 5\n27 4\n79 1\n27 2\n30 3\n4 1\n89 2\n88 3\n75 5\n3 1\n39 4\n12 1\n62 4\n38 2\n49 1\n",
"output": "8 12 15 15 15 15\n"
}
] |
https://atcoder.jp/contests/abc314/tasks/abc314_h | Problem Statement
There are
N
line segments in a coordinate plane, and the
i
-th line segment
(1\leq i\leq N)
has two points
(a _ i,b _ i)
and
(c _ i,d _ i)
as its endpoints.
Here, each line segment includes its endpoints.
Additionally, no two line segments share a point.
We want to place a single closed disk in this plane so that it shares a point with each line segment.
In other words, we want to draw a single circle so that each line segment shares a point with either the circumference of the circle or its interior (or both).
Find the smallest possible radius of such a disk. | [
{
"input": "4\n2 3 2 10\n4 0 12 6\n4 8 6 3\n7 8 10 8\n",
"output": "3.319048676309097923796460081961\n"
},
{
"input": "20\n0 18 4 28\n2 21 8 21\n3 4 10 5\n3 14 10 13\n5 9 10 12\n6 9 10 6\n6 28 10 18\n12 11 15 13\n12 17 12 27\n13 17 20 18\n13 27 19 26\n16 1 16 13\n16 22 19 25\n17 22 20 19\n18 4 23 4\n18 5 23 11\n22 16 22 23\n23 15 30 15\n23 24 30 24\n24 0 24 11\n",
"output": "12.875165712523887403637822024952\n"
},
{
"input": "30\n526 655 528 593\n628 328 957 211\n480 758 680 794\n940 822 657 949\n127 23 250 385\n281 406 319 305\n277 598 190 439\n437 450 725 254\n970 478 369 466\n421 225 348 141\n872 64 600 9\n634 460 759 337\n878 514 447 534\n142 237 191 269\n983 34 554 284\n694 160 589 239\n391 631 22 743\n377 656 500 606\n390 576 184 312\n556 707 457 699\n796 870 186 773\n12 803 505 586\n343 541 42 165\n478 340 176 2\n39 618 6 651\n753 883 47 833\n551 593 873 672\n983 729 338 747\n721 77 541 255\n0 32 98 597\n",
"output": "485.264732620930836460637042310401\n"
}
] |
https://atcoder.jp/contests/newjudge-2308-heuristic/tasks/newjudge_2308_heuristic_a | Problem Statement
AtCoder currently hosts four types of contests, ABC, ARC, AGC, and AHC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. Please schedule contests so that user satisfaction is as high as possible.
The amount of satisfaction increased by holding a contest will depend on various factors, such as the schedule of contests other than AtCoder, etc. Therefore, instead of deciding on the entire schedule in advance, it is necessary to determine it one day at a time.
The satisfaction is calculated as follows.
The satisfaction at the beginning of day 1 is 0. Satisfaction can take negative values.
Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors, such as the schedule of contests other than AtCoder, the day of the week, and so on. Holding a contest of type
i
on day
d
will increase the satisfaction by
s_{d,i}
.
The value
s_{d,i}
is only revealed at the time of determining the contest to be held on day
d
, so when determining the contest on day
d
, the value of
s_{d',i}
is unknown for day
d'\geq d+1
.
If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type
i
has an integer
c_i
, and at the end of each day
d=1,2,...,D
, the satisfaction decreases as follows. Let
\mathrm{last}(d,i)
be the last day before day
d
(including
d
) on which a contest of type
i
was held. If contests of type
i
have never been held yet, we define
\mathrm{last}(d,i)=0
. At the end of day
d
, the satisfaction decreases by
\sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i))
. | [] |
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc264_a | Problem Statement
Print the
L
-th through
R
-th characters of the string
atcoder
. | [
{
"input": "3 6\n",
"output": "code\n"
},
{
"input": "4 4\n",
"output": "o\n"
},
{
"input": "1 7\n",
"output": "atcoder\n"
}
] |
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc273_b | Problem Statement
Given a non-negative integer
X
, perform the following operation for
i=1,2,\dots,K
in this order and find the resulting
X
.
Round
X
off to the nearest
10^i
.
Formally, replace
X
with
Y
that is "the largest multiple of
10^i
that minimizes
|Y-X|
."
Here are some examples:
Rounding
273
off to the nearest
10^2
yields
300
.
Rounding
999
off to the nearest
10^3
yields
1000
.
Rounding
100
off to the nearest
10^{10}
yields
0
.
Rounding
1015
off to the nearest
10^1
yields
1020
. | [
{
"input": "2048 2\n",
"output": "2100\n"
},
{
"input": "1 15\n",
"output": "0\n"
},
{
"input": "999 3\n",
"output": "1000\n"
},
{
"input": "314159265358979 12\n",
"output": "314000000000000\n"
}
] |
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc244_c | Problem Statement
Takahashi and Aoki will play the following game against each other.
Starting from Takahashi, the two alternatingly declare an integer between
1
and
2N+1
(inclusive) until the game ends.
Any integer declared by either player cannot be declared by either player again.
The player who is no longer able to declare an integer loses; the player who didn't lose wins.
In this game, Takahashi will always win.
Your task is to actually play the game on behalf of Takahashi and win the game. | [] |
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc309_d | Problem Statement
We have an undirected graph with
(N_1+N_2)
vertices and
M
edges. For
i=1,2,\ldots,M
, the
i
-th edge connects vertex
a_i
and vertex
b_i
.
The following properties are guaranteed:
Vertex
u
and vertex
v
are connected, for all integers
u
and
v
with
1 \leq u,v \leq N_1
.
Vertex
u
and vertex
v
are connected, for all integers
u
and
v
with
N_1+1 \leq u,v \leq N_1+N_2
.
Vertex
1
and vertex
(N_1+N_2)
are disconnected.
Consider performing the following operation exactly once:
choose an integer
u
with
1 \leq u \leq N_1
and an integer
v
with
N_1+1 \leq v \leq N_1+N_2
, and add an edge connecting vertex
u
and vertex
v
.
We can show that vertex
1
and vertex
(N_1+N_2)
are always connected in the resulting graph; so let
d
be the minimum length (number of edges) of a path between vertex
1
and vertex
(N_1+N_2)
.
Find the maximum possible
d
resulting from adding an appropriate edge to add.
Definition of "connected"
Two vertices
u
and
v
of an undirected graph are said to be connected if and only if there is a path between vertex
u
and vertex
v
. | [
{
"input": "3 4 6\n1 2\n2 3\n4 5\n4 6\n1 3\n6 7\n",
"output": "5\n"
},
{
"input": "7 5 20\n10 11\n4 5\n10 12\n1 2\n1 5\n5 6\n2 4\n3 5\n9 10\n2 5\n1 4\n11 12\n9 12\n8 9\n5 7\n3 7\n3 6\n3 4\n8 12\n9 11\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc304_e | Problem Statement
You are given an undirected graph
G
with
N
vertices and
M
edges.
For
i = 1, 2, \ldots, M
, the
i
-th edge is an undirected edge connecting vertices
u_i
and
v_i
.
A graph with
N
vertices is called
good
if the following condition holds for all
i = 1, 2, \ldots, K
:
there is no path connecting vertices
x_i
and
y_i
in
G
.
The given graph
G
is good.
You are given
Q
independent questions. Answer all of them.
For
i = 1, 2, \ldots, Q
, the
i
-th question is as follows.
Is the graph
G^{(i)}
obtained by adding an undirected edge connecting vertices
p_i
and
q_i
to the given graph
G
good? | [
{
"input": "6 6\n1 2\n2 3\n2 3\n3 1\n5 4\n5 5\n3\n1 5\n2 6\n4 3\n4\n2 5\n2 6\n5 6\n5 4\n",
"output": "No\nNo\nYes\nYes\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.