Dataset Viewer
url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/abc382/tasks/abc382_a | Problem Statement
There are
N
boxes arranged in a row, and some of these boxes contain cookies.
The state of these boxes is represented by a string
S
of length
N
.
Specifically, the
i
-th box
(1\leq i \leq N)
from the left contains one cookie if the
i
-th character of
S
is
@
, and is empty if it is
.
.
Over the next
D
days, Takahashi will choose and eat one cookie per day from among the cookies in these boxes.
Determine how many of the
N
boxes will be empty after
D
days have passed.
(It can be proved that this value does not depend on which cookies Takahashi chooses each day.)
It is guaranteed that
S
contains at least
D
occurrences of
@
. | [
{
"input": "5 2\n.@@.@\n",
"output": "4\n"
},
{
"input": "3 3\n@@@\n",
"output": "3\n"
},
{
"input": "10 4\n@@@.@@.@@.\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_b | Problem Statement
This problem shares a similar setting with Problem A. The way Takahashi chooses cookies and what you are required to find are different from Problem A.
There are
N
boxes arranged in a row, and some of these boxes contain cookies.
The state of these boxes is represented by a string
S
of length
N
.
Specifically, the
i
-th box
(1\leq i \leq N)
from the left contains one cookie if the
i
-th character of
S
is
@
, and is empty if it is
.
.
Over the next
D
days, Takahashi will choose and eat one cookie per day from among the cookies in these boxes. On each day, he chooses the cookie in the rightmost box that contains a cookie at that point.
Determine, for each of the
N
boxes, whether it will contain a cookie after
D
days have passed.
It is guaranteed that
S
contains at least
D
occurrences of
@
. | [
{
"input": "5 2\n.@@.@\n",
"output": ".@...\n"
},
{
"input": "3 3\n@@@\n",
"output": "...\n"
},
{
"input": "10 4\n@@@.@@.@@.\n",
"output": "@@@.......\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_c | Problem Statement
There are
N
people numbered from
1
to
N
visiting a conveyor belt sushi restaurant.
The
gourmet level
of person
i
is
A_i
.
Now,
M
pieces of sushi will be placed on the conveyor belt.
The
deliciousness
of the
j
-th sushi is
B_j
.
Each piece of sushi passes in front of people
1, 2, \dots, N
in this order.
Each person, when a sushi whose deliciousness is not less than their gourmet level passes in front of them, will take and eat that sushi; otherwise, they do nothing.
A sushi that person
i
takes and eats will no longer pass in front of person
j\ (j > i)
.
For each of the
M
pieces of sushi, determine who eats that sushi, or if nobody eats it. | [
{
"input": "3 3\n3 8 2\n5 2 1\n",
"output": "1\n3\n-1\n"
},
{
"input": "3 3\n1 1 1\n1 1 1\n",
"output": "1\n1\n1\n"
},
{
"input": "10 5\n60 83 76 45 70 91 37 58 94 22\n70 39 52 33 18\n",
"output": "1\n7\n4\n10\n-1\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_d | Problem Statement
You are given integers
N
and
M
.
Print all integer sequences
(A_1, A_2, \ldots, A_N)
of length
N
that satisfy all of the following conditions, in lexicographical order.
1 \leq A_i
A_{i - 1} + 10 \leq A_i
for each integer
i
from
2
through
N
A_N \leq M
What is lexicographical order?
A sequence
S = (S_1, S_2, \ldots, S_N)
of length
N
is
smaller in lexicographical order
than a sequence
T = (T_1, T_2, \ldots, T_N)
of length
N
if and only if there exists an integer
1 \leq i \leq N
such that both of the following hold:
(S_1, S_2, \ldots, S_{i-1}) = (T_1, T_2, \ldots, T_{i-1})
S_i
is less than
T_i
(as a number). | [
{
"input": "3 23\n",
"output": "10\n1 11 21\n1 11 22\n1 11 23\n1 12 22\n1 12 23\n1 13 23\n2 12 22\n2 12 23\n2 13 23\n3 13 23\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_e | Problem Statement
There are infinitely many packs, each containing
N
cards. In each pack, the
i
-th card is rare with probability
P_i
percent. Whether each card is rare is independent of other cards being rare.
You will now open the packs one by one, and obtain all the cards in each opened pack. When you keep opening packs until you have obtained a total of at least
X
rare cards, find the expected number of packs you will open. | [
{
"input": "2 2\n50 100\n",
"output": "1.5000000000000000\n"
},
{
"input": "2 3\n40 60\n",
"output": "3.2475579530543811\n"
},
{
"input": "6 3\n10 33 33 10 100 10\n",
"output": "1.8657859189536100\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_f | Problem Statement
There is a grid with
H
rows and
W
columns.
Let
(i,j)
denote the cell at the
i
-th row from the top and the
j
-th column from the left.
There are
N
horizontal bars numbered from
1
to
N
placed on the grid.
Bar
i
consists of
L_i
blocks of size
1 \times 1
connected horizontally, and its leftmost block is initially at cell
(R_i, C_i)
.
That is, initially, bar
i
occupies the cells
(R_i, C_i), (R_i, C_i + 1), \dots, (R_i, C_i + L_i - 1)
.
It is guaranteed that there is no cell occupied by two different bars.
The current time is
t = 0
.
At every time
t = 0.5 + n
for some non-negative integer
n
, the following occurs in order of
i = 1, 2, \dots, N
:
If bar
i
is not on the bottom row (the
H
-th row), and none of the cells directly below the cells occupied by bar
i
is occupied by any bar, then bar
i
moves down by one cell. That is, if at that time bar
i
occupies the cells
(r,C_i),(r,C_i+1),\dots,(r,C_i+L_i-1)\ (r < H)
, and the cell
(r + 1, C_i + j)
is not occupied by any bar for all
j
(
0 \leq j \leq L_i - 1
), then bar
i
now occupies
(r + 1, C_i), (r + 1, C_i + 1), \dots, (r + 1, C_i + L_i - 1)
.
Otherwise, nothing happens.
Let
(R'_i, C_i), (R'_i, C_i + 1), \dots, (R'_i, C_i + L_i - 1)
be the cells occupied by bar
i
at time
t = 10^{100}
. Find
R'_1, R'_2, \dots, R'_N
. | [
{
"input": "4 4 4\n1 2 3\n3 2 2\n2 1 2\n2 4 1\n",
"output": "2\n4\n3\n4\n"
},
{
"input": "382 382 3\n3 3 3\n8 8 8\n2 2 2\n",
"output": "382\n382\n381\n"
},
{
"input": "5 10 8\n2 2 1\n4 3 1\n4 8 2\n1 2 2\n2 5 3\n5 4 3\n4 5 2\n1 5 2\n",
"output": "5\n5\n5\n4\n3\n5\n4\n2\n"
}
] |
https://atcoder.jp/contests/abc382/tasks/abc382_g | Problem Statement
Tiles are laid out covering the two-dimensional coordinate plane.
Each tile is a rectangle, and for each integer triple
(i, j, k)
satisfying
0 \leq k < K
, a corresponding tile is placed according to the following rules:
When
i
and
j
have the same parity (both even or both odd), the tile corresponding to
(i, j, k)
covers the area where
iK \leq x \leq (i + 1)K
and
jK + k \leq y \leq jK + k + 1
.
When
i
and
j
have different parity, the tile corresponding to
(i, j, k)
covers the area where
iK + k \leq x \leq iK + k + 1
and
jK \leq y \leq (j + 1)K
.
Two tiles are
adjacent
when their edges have a common segment of positive length.
Starting from the tile containing the point
(S_x + 0.5, S_y + 0.5)
, find the minimum number of times you need to move to an adjacent tile to reach the tile containing the point
(T_x + 0.5, T_y + 0.5)
.
There are
T
test cases; solve each of them. | [
{
"input": "3\n3 -2 1 4 -1\n4 8 8 0 2\n5 -1000000000000 -1000000000000 1000000000000 1000000000000\n",
"output": "4\n4\n800000000000\n"
}
] |
https://atcoder.jp/contests/agc069/tasks/agc069_a | Problem Statement
Takahashi decided to hold a tournament that lasts for
10^9
days in a single-elimination format.
There are
2^N
players, called player
1
,
\ldots
, player
2^N
. Player
i
plans to participate from day
l_i
to day
r_i
of the tournament, for a total of
r_i - l_i + 1
days.
First, we describe the flow of the tournament. There are
2^N - 1
matches in total, corresponding one-to-one with the integer pairs
(i, j)
satisfying
1 \leq i \leq N
and
1 \leq j \leq 2^{N - i}
. In the match corresponding to
(i, j)
, the following two players compete to decide the winner and the loser:
If
i = 1
, players
2j - 1
and
2j
If
i \geq 2
, the winners of the matches corresponding to
(i - 1, 2j - 1)
and
(i - 1, 2j)
Each match can be completed immediately when all the matches necessary to determine the two players who will compete in it have been completed, and both players are currently participating in the tournament. In particular, a single player can participate in multiple matches on the same day.
The match corresponding to
(N, 1)
is called the final, and the goal of the tournament is to complete it.
To successfully complete the final, Takahashi decided to perform the following manipulations:
Instruct the referees to fix the outcomes of the matches as desired.
Pay the players to change their participation schedules. To make player
i
participate from day
l'_i
to day
r'_i
, Takahashi needs to pay
|l_i - l'_i| + |r_i - r'_i|
yen. Here,
l'_i
and
r'_i
are integers satisfying
1 \leq l'_i \leq r'_i \leq 10^9
.
Find the minimum total amount of money Takahashi needs to pay the players. | [
{
"input": "3\n1 4\n1 3\n3 4\n2 2\n3 4\n4 4\n2 3\n3 4\n",
"output": "1\n"
},
{
"input": "1\n1 1\n1000000000 1000000000\n",
"output": "999999999\n"
},
{
"input": "4\n158260522 877914575\n24979445 602436426\n623690081 861648772\n433933447 476190629\n211047202 262703497\n628894325 971407775\n731963982 822804784\n430302156 450968417\n161735902 982631932\n880895728 923078537\n189330739 707723857\n802329211 910286918\n303238506 404539679\n317063340 492686568\n125660016 773361868\n650287940 839296263\n",
"output": "1088492036\n"
}
] |
https://atcoder.jp/contests/agc069/tasks/agc069_b | Problem Statement
You are given
N
strings
S_1, \ldots, S_N
, each of length
N
, consisting only of
0
and
1
. Let
S_{i,j}
denote the
j
-th character of
S_i
. It is guaranteed by the constraints that there exists at least one integer pair
(i, j)
satisfying
S_{i,j} =
1
.
Takahashi and Aoki play the following game:
Takahashi chooses one integer pair
(i, j)
satisfying
1 \leq i, j \leq N
and
S_{i,j} =
1
.
Aoki asks Takahashi at least
0
and at most
N
questions. In each question, Aoki chooses an integer pair
(i', j')
satisfying
1 \leq i', j' \leq N
, and Takahashi tells Aoki whether "At least one of
i = i'
or
j = j'
holds" is true or false.
Aoki guesses
(i, j)
. If his guess is correct, Aoki wins; otherwise, he loses.
Aoki knows the possible choices of
(i, j)
that Takahashi can choose, that is, he knows
S_1, \ldots, S_N
before playing the game. Also, in step 2, Aoki can choose
(i', j')
based on the answers to previous questions.
Determine whether Aoki can always win the game regardless of Takahashi's choice of
(i, j)
and randomness, if he uses an appropriate strategy.
There are
T
test cases in each input. | [
{
"input": "3\n2\n01\n11\n2\n11\n11\n10\n0101011110\n1100100001\n1101100000\n0111101010\n1000011001\n1110101010\n1110110100\n1110000110\n0000001011\n1001111100\n",
"output": "Yes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/agc069/tasks/agc069_c | Problem Statement
You are given two strings
S
and
T
of length
N
consisting of
A
and
B
. Let
s_i
denote the
i
-th character of
S
.
You can perform the following operation on
S
any number of times, possibly zero:
Choose an integer pair
(i, j)
satisfying the following conditions:
1 \leq i < j \leq N
s_i = s_j =
A
s_{i+1} = s_{i+2} = \ldots = s_{j-1} =
B
Then, simultaneously replace each of
s_i, s_{i+1}, \ldots, s_j
with the other character (
A
becomes
B
, and
B
becomes
A
).
Determine the minimum number of operations required to make
S
equal to
T
. If it is impossible, print
-1
. | [
{
"input": "5\nAAABA\nBAAAB\n",
"output": "2\n"
},
{
"input": "1\nA\nB\n",
"output": "-1\n"
},
{
"input": "1\nA\nA\n",
"output": "0\n"
},
{
"input": "10\nAAABBABAAB\nBBABBAAABB\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/agc069/tasks/agc069_d | Problem Statement
You are given an integer
N
and a prime
P
.
For a tree with
N
vertices labeled
1
through
N
, let
a_i
and
b_i
be the endpoints of the
i
-th edge
(1 \leq i \leq N-1)
. Also, define
x_j\ (1 \leq j \leq N-1)
as:
The number of integers
i\ (1 \leq i \leq N-1)
satisfying
\min(a_i,b_i) \leq j \lt \max(a_i,b_i)
.
Find the number, modulo
P
, of sequences that could be
(x_1, x_2, \ldots, x_{N - 1})
. | [
{
"input": "3 998244353\n",
"output": "3\n"
},
{
"input": "69 433416647\n",
"output": "243082757\n"
}
] |
https://atcoder.jp/contests/agc069/tasks/agc069_e | Problem Statement
You are given integers
N
,
M
,
X
, and
Y
.
Find the number, modulo
998244353
, of pairs
(A, B)
of sequences
A=(a_1,\ldots,a_N)
and
B=(b_1,\ldots,b_N)
that satisfy all of the following conditions:
A = (a_1, \ldots, a_N)
is a sequence of non-negative integers.
B = (b_1, \ldots, b_N)
is a subsequence of
(0, 1, \ldots, M - 1)
.
\sum\limits_{i=1}^{N} a_i = X
.
\sum\limits_{i=1}^{N} a_i b_i = Y
. | [
{
"input": "3 4 3 4\n",
"output": "5\n"
},
{
"input": "1 1 1 1\n",
"output": "0\n"
},
{
"input": "12345 67890 9876 54321\n",
"output": "150392014\n"
}
] |
https://atcoder.jp/contests/arc188/tasks/arc188_a | Problem Statement
For a non-empty string
T
consisting of
A
,
B
, and
C
, we call it a good string if it can be turned into an empty string by performing the following two types of operations any number of times in any order.
Operation
1
: Choose two identical characters in the string and delete them (cannot be performed if there are not two or more identical characters).
Operation
2
: Choose one
A
, one
B
, and one
C
in the string and delete them (cannot be performed if there are not one or more of each of
A
,
B
, and
C
).
For example,
ABACA
is a good string because it can be turned into an empty string by performing the operations as follows:
Choose the 2nd, 4th, and 5th characters and delete them (Operation
2
). The string becomes
AA
.
Choose the 1st and 2nd characters and delete them (Operation
1
). The string becomes an empty string.
You are given a string
S
of length
N
consisting of
A
,
B
,
C
, and
?
. How many ways are there to replace each
?
with
A
,
B
, or
C
to form a string that contains
at least
K
good strings as contiguous substrings? Substrings are counted separately if they are at different positions in the original string, even if they are identical strings.
Find the count modulo
998244353
. | [
{
"input": "4 2\nA?AB\n",
"output": "1\n"
},
{
"input": "50 411\n??AB??C???????????????????????????????A???C????A??\n",
"output": "457279314\n"
},
{
"input": "1 0\nA\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/arc188/tasks/arc188_b | Problem Statement
On a circle, there are
N
equally spaced points numbered
0,1,\ldots,N-1
in this order, with Alice at point
0
and Bob at point
K
. Initially, all points are colored white. Starting with Alice, they alternately perform the following operation:
Choose one of the currently white points and color it black. Here, after the operation, the coloring of the points must be symmetric with respect to the straight line connecting the operator and the center of the circle.
If the operator cannot perform an operation satisfying the above condition, the sequence of operations ends there.
Both players cooperate and make the best choices to maximize the total number of points colored black in the end. Determine whether all points are colored black at the end of the sequence of operations.
You are given
T
test cases to solve. | [
{
"input": "4\n6 2\n6 3\n6 1\n200000 100000\n",
"output": "Yes\nNo\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/arc188/tasks/arc188_c | Problem Statement
There is a village with
N
villagers numbered from
1
to
N
.
Each villager is honest or a liar. Additionally, some villagers are confused.
You have obtained
M
testimonies from the villagers. Each testimony is given by
A_i
,
B_i
,
C_i
for
i=1,2,\ldots,M
, representing:
If
C_i=0
, villager
A_i
testified that villager
B_i
is honest.
If
C_i=1
, villager
A_i
testified that villager
B_i
is a liar.
All villagers know whether every other villager is honest or a liar, and you know that they made their testimonies to you according to the following rules:
An honest villager who is not confused always tells the truth.
A liar who is not confused always tells lies.
A confused honest villager always tells lies.
A confused liar always tells the truth.
In other words, if they are not confused, honest villagers always tell the truth, and liars always tell lies, but if they are confused, it is reversed.
You have decided to guess the set of villagers who are confused.
Given a choice of villagers who are confused, whether the set of testimonies "contradicts" or not is determined.
Here, a set of testimonies is said to contradict if, no matter how you assign honest or liar statuses to the villagers, there is at least one testimony that violates the villagers' testimony rules.
Find a set of confused villagers such that the given set of testimonies does not contradict.
If no such set of confused villagers exists, indicate that fact. | [
{
"input": "3 3\n1 2 1\n1 3 0\n2 3 0\n",
"output": "010\n"
},
{
"input": "3 6\n1 2 1\n1 3 0\n2 1 1\n2 3 0\n3 1 1\n3 2 0\n",
"output": "-1\n"
},
{
"input": "3 0\n",
"output": "000\n"
}
] |
https://atcoder.jp/contests/arc188/tasks/arc188_d | Problem Statement
You are going to create
N
sequences of length
3
, satisfying the following conditions.
For each of
k = 1,2,3
, the following holds:
Among the
k
-th elements of the sequences, each integer from
1
through
N
appears exactly once.
For this sequence of sequences, define sequences
a=(a_1,a_2,\ldots,a_N)
and
b=(b_1,b_2,\ldots,b_N)
as follows.
Let
s_i
be the
i
-th sequence, and let
t_i
be the reverse of the
i
-th sequence. When all of these are sorted in lexicographical order,
s_i
comes
a_i
-th, and
t_i
comes
b_i
-th.
Here, if there are identical sequences among the
2N
sequences,
a
and
b
are not defined.
Therefore, if
a
and
b
are defined, each integer from
1
through
2N
appears exactly once in the concatenation of
a
and
b
.
You are given sequences
A
and
B
of length
N
, where each element of
A
is an integer between
1
and
2N
, and each element of
B
is either an integer between
1
and
2N
or
-1
.
Also, in the concatenation of
A
and
B
, each integer other than
-1
appears at most once.
How many pairs of sequences
a,b
are there such that
a
and
b
are defined and the following holds for each integer
i
from
1
through
N
?
a_i = A_i
.
b_i = B_i
if
B_i \neq -1
.
Find the count modulo
998244353
. | [
{
"input": "3\n2 3 6\n-1 1 -1\n",
"output": "1\n"
},
{
"input": "15\n5 16 1 12 30 20 4 13 9 8 24 21 26 28 17\n-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 29 -1 -1 -1\n",
"output": "758094847\n"
}
] |
https://atcoder.jp/contests/arc188/tasks/arc188_e | Problem Statement
There are
2N
cells numbered from
1
to
2N
arranged vertically in a column with cell
1
at the top. Each cell contains one ball. The weight of the ball in cell
i
at time
t=0
is
m_i
for
i=1,2,\ldots,N
, and
0
for
i=N+1,N+2,\ldots,2N
. Here,
(m_1, m_2, \ldots, m_N)
is a permutation of the integers from
1
to
N
.
In the following, we will refer to the ball of weight
i
as ball
i
, and the cell number where each ball is located as the position of the ball.
From time
t=0
onwards, every time the time advances by
1
, the heavier balls sink downward, and the lighter balls rise upward.
Formally, the positions of each ball at time
t=t_0+1
are determined from their positions at time
t=t_0
by the following procedure.
First, for
i=N,N-1,\ldots,2,1
in this order, perform the following operation.
If the position of ball
i
at
t=t_0+1
has already been determined:
Do nothing.
If the position of ball
i
at
t=t_0+1
has not been determined:
If there exists a cell immediately below ball
i
at
t=t_0
, and the ball in that cell (call it ball
j
) is lighter than ball
i
,
set the positions of balls
i
and
j
at
t=t_0+1
to be swapped from their positions at
t=t_0
.
Otherwise,
set the position of ball
i
at
t=t_0+1
to be the same as at
t=t_0
.
Next, for all balls of weight
0
whose positions at
t=t_0+1
have not been determined at this point,
set their positions at
t=t_0+1
to be the same as at
t=t_0
.
It can be shown that at some time, the balls will be arranged from top to bottom in ascending order of weight, and their positions will no longer change. Find the time when this state is reached. | [
{
"input": "3\n2 3 1\n",
"output": "6\n"
},
{
"input": "5\n4 1 2 3 5\n",
"output": "9\n"
},
{
"input": "1\n1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_a | Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems C and E.
A string
T
is called an
11/22 string
when it satisfies all of the following conditions:
|T|
is odd. Here,
|T|
denotes the length of
T
.
The
1
-st through
(\frac{|T|+1}{2} - 1)
-th characters are all
1
.
The
(\frac{|T|+1}{2})
-th character is
/
.
The
(\frac{|T|+1}{2} + 1)
-th through
|T|
-th characters are all
2
.
For example,
11/22
,
111/222
, and
/
are 11/22 strings, but
1122
,
1/22
,
11/2222
,
22/11
, and
//2/2/211
are not.
Given a string
S
of length
N
consisting of
1
,
2
, and
/
, determine whether
S
is an 11/22 string. | [
{
"input": "5\n11/22\n",
"output": "Yes\n"
},
{
"input": "1\n/\n",
"output": "Yes\n"
},
{
"input": "4\n1/22\n",
"output": "No\n"
},
{
"input": "5\n22/11\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_b | Problem Statement
A string
T
is called a
1122 string
if and only if it satisfies all of the following three conditions:
\lvert T \rvert
is even. Here,
\lvert T \rvert
denotes the length of
T
.
For each integer
i
satisfying
1\leq i\leq \frac{|T|}{2}
, the
(2i-1)
-th and
2i
-th characters of
T
are equal.
Each character appears in
T
exactly zero or two times. That is, every character contained in
T
appears exactly twice in
T
.
Given a string
S
consisting of lowercase English letters, print
Yes
if
S
is a 1122 string, and
No
otherwise. | [
{
"input": "aabbcc\n",
"output": "Yes\n"
},
{
"input": "aab\n",
"output": "No\n"
},
{
"input": "zzzzzz\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_c | Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems A and E.
A string
T
is called an
11/22 string
when it satisfies all of the following conditions:
|T|
is odd. Here,
|T|
denotes the length of
T
.
The
1
-st through
(\frac{|T|+1}{2} - 1)
-th characters are all
1
.
The
(\frac{|T|+1}{2})
-th character is
/
.
The
(\frac{|T|+1}{2} + 1)
-th through
|T|
-th characters are all
2
.
For example,
11/22
,
111/222
, and
/
are 11/22 strings, but
1122
,
1/22
,
11/2222
,
22/11
, and
//2/2/211
are not.
You are given a string
S
of length
N
consisting of
1
,
2
, and
/
, where
S
contains at least one
/
.
Find the maximum length of a (contiguous) substring of
S
that is an 11/22 string. | [
{
"input": "8\n211/2212\n",
"output": "5\n"
},
{
"input": "5\n22/11\n",
"output": "1\n"
},
{
"input": "22\n/1211/2///2111/2222/11\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_d | Problem Statement
A sequence
X = (X_1, X_2, \ldots)
of positive integers (possibly empty) is called a
1122 sequence
if and only if it satisfies all of the following three conditions: (The definition of a 1122 sequence is the same as in Problem F.)
\lvert X \rvert
is even. Here,
\lvert X \rvert
denotes the length of
X
.
For each integer
i
satisfying
1\leq i\leq \frac{|X|}{2}
,
X_{2i-1}
and
X_{2i}
are equal.
Each positive integer appears in
X
either not at all or exactly twice. That is, every positive integer contained in
X
appears exactly twice in
X
.
Given a sequence
A = (A_1, A_2, \ldots, A_N)
of length
N
consisting of positive integers, print the maximum length of a
(contiguous) subarray
of
A
that is a 1122 sequence. | [
{
"input": "8\n2 3 1 1 2 2 1 1\n",
"output": "4\n"
},
{
"input": "3\n1 2 2\n",
"output": "2\n"
},
{
"input": "1\n1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_e | Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems A and C.
A string
T
is called an
11/22 string
when it satisfies all of the following conditions:
|T|
is odd. Here,
|T|
denotes the length of
T
.
The
1
-st through
(\frac{|T|+1}{2} - 1)
-th characters are all
1
.
The
(\frac{|T|+1}{2})
-th character is
/
.
The
(\frac{|T|+1}{2} + 1)
-th through
|T|
-th characters are all
2
.
For example,
11/22
,
111/222
, and
/
are 11/22 strings, but
1122
,
1/22
,
11/2222
,
22/11
, and
//2/2/211
are not.
Given a string
S
of length
N
consisting of
1
,
2
, and
/
, process
Q
queries.
Each query provides two integers
L
and
R
. Let
T
be the
(contiguous)
substring of
S
from the
L
-th through
R
-th character. Find the maximum length of a subsequence
(not necessarily contiguous)
of
T
that is an 11/22 string. If no such subsequence exists, print
0
. | [
{
"input": "12 5\n111/212/1122\n1 7\n9 12\n3 6\n4 10\n1 12\n",
"output": "5\n0\n3\n1\n7\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_f | Problem Statement
A sequence
X = (X_1, X_2, \ldots)
of positive integers (possibly empty) is called a
1122 sequence
if and only if it satisfies all of the following three conditions: (The definition of a 1122 sequence is the same as in Problem D.)
\lvert X \rvert
is even. Here,
\lvert X \rvert
denotes the length of
X
.
For each integer
i
satisfying
1\leq i\leq \frac{|X|}{2}
,
X_{2i-1}
and
X_{2i}
are equal.
Each positive integer appears in
X
either not at all or exactly twice. That is, every positive integer contained in
X
appears exactly twice in
X
.
Given a sequence
A = (A_1, A_2, \ldots, A_N)
of length
N
consisting of positive integers, print the maximum length of a
subsequence (not necessarily contiguous)
of
A
that is a 1122 sequence. | [
{
"input": "7\n1 3 3 1 2 2 1\n",
"output": "4\n"
},
{
"input": "1\n20\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc381/tasks/abc381_g | Problem Statement
Define a sequence
a_1, a_2, a_3, \dots
as follows:
a_n = \begin{cases} x & (n=1) \\ y & (n=2) \\ a_{n-1} + a_{n-2} & (n \geq 3) \\ \end{cases}
Find
\left( \displaystyle \prod_{i=1}^N a_i \right) \bmod{998244353}
.
You are given
T
test cases to solve. | [
{
"input": "3\n5 1 1\n2024 11 22\n1000000000000000000 12345 6789\n",
"output": "30\n577322229\n726998219\n"
}
] |
https://atcoder.jp/contests/arc187/tasks/arc187_a | Problem Statement
You are given integers
N
,
K
, and a sequence
A = (A_1, \ldots, A_N)
of length
N
.
Determine whether it is possible to make
A
non-decreasing by performing the following operation at most
500000
times, and if possible, provide one sequence of operations to do so.
Choose an integer
i
between
1
and
N-1
, inclusive. Simultaneously replace
A_i
with
A_{i+1} + K
, and
A_{i+1}
with
A_i
. | [
{
"input": "3 2\n3 6 4\n",
"output": "Yes\n1\n2\n"
},
{
"input": "3 3\n1 5 8\n",
"output": "Yes\n2\n2 2\n"
}
] |
https://atcoder.jp/contests/arc187/tasks/arc187_b | Problem Statement
For a sequence
A = (A_1, \ldots, A_N)
of length
N
, define
f(A)
as follows.
Prepare a graph with
N
vertices labeled
1
to
N
and zero edges. For every integer pair
(i, j)
satisfying
1 \leq i < j \leq N
, if
A_i \leq A_j
, draw a bidirectional edge connecting vertices
i
and
j
. Define
f(A)
as the number of connected components in the resulting graph.
You are given a sequence
B = (B_1, \ldots, B_N)
of length
N
. Each element of
B
is
-1
or an integer between
1
and
M
, inclusive.
By replacing every occurrence of
-1
in
B
with an integer between
1
and
M
, one can obtain
M^q
sequences
B'
, where
q
is the number of
-1
in
B
.
Find the sum, modulo
998244353
, of
f(B')
over all possible
B'
. | [
{
"input": "3 3\n2 -1 1\n",
"output": "6\n"
},
{
"input": "10 8\n-1 7 -1 -1 -1 2 -1 1 -1 2\n",
"output": "329785\n"
},
{
"input": "11 12\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n",
"output": "529513150\n"
}
] |
https://atcoder.jp/contests/arc187/tasks/arc187_c | Problem Statement
For a permutation
P = (P_1, \ldots, P_N)
of
(1, \ldots, N)
, let
P' = (P'_1, \ldots, P'_N)
be the permutation obtained by performing the following operation once.
For
i = 1, 2, \ldots, N-1
in this order, if
P_i > P_{i+1}
, swap
P_i
and
P_{i+1}
.
You are given a sequence
Q = (Q_1, \ldots, Q_N)
of length
N
. Each
Q_i
is
-1
or an integer between
1
and
N
, inclusive.
Find the number, modulo
998244353
, of permutations
P
of
(1, \ldots, N)
such that, for every
i
, if
Q_i \neq -1
then
Q_i = P'_i
. | [
{
"input": "4\n-1 -1 2 4\n",
"output": "6\n"
},
{
"input": "6\n-1 -1 -1 -1 2 -1\n",
"output": "120\n"
},
{
"input": "15\n-1 -1 -1 -1 -1 4 -1 -1 -1 -1 7 -1 -1 -1 -1\n",
"output": "237554682\n"
}
] |
https://atcoder.jp/contests/arc187/tasks/arc187_d | Problem Statement
Define the
cost
of a sequence
X
as (the maximum value of
X
minus the minimum value of
X
).
You are given sequences
A = (A_1, \ldots, A_N)
and
B = (B_1, \ldots, B_N)
of length
N
. Solve the following problem for
k = 1, 2, \ldots, N
.
Find the minimum possible cost of the sequence
C = (C_1, \ldots, C_k)
whose
i
-th element
C_i
is
A_i
or
B_i
. | [
{
"input": "3\n8 11 10\n7 6 1\n",
"output": "0\n1\n3\n"
},
{
"input": "10\n43 35 36 58 25 7 61 4 96 3\n55 29 88 15 99 49 67 57 92 49\n",
"output": "0\n8\n8\n23\n28\n33\n36\n36\n64\n64\n"
}
] |
https://atcoder.jp/contests/arc187/tasks/arc187_e | Problem Statement
You are given a sequence
A = (A_1, \ldots, A_N)
of length
N
. Here,
N
is an integer not less than
3
.
You can perform the following operation any number of times (zero or more).
Choose an integer
i
satisfying
1 \leq i \leq N
and
A_i = A_{i+1} = A_{i+2}
. Replace two of
A_i
,
A_{i+1}
, and
A_{i+2}
with integers between
1
and
N
, inclusive. Here, assume
A_{N+1} = A_1
and
A_{N+2} = A_2
.
Find the number, modulo
998244353
, of possible resulting sequences
A
that are permutations of
(1, \ldots, N)
. | [
{
"input": "6\n1 2 3 3 1 1\n",
"output": "360\n"
},
{
"input": "5\n3 1 3 4 1\n",
"output": "0\n"
},
{
"input": "10\n1 1 1 8 8 8 7 7 7 10\n",
"output": "604800\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_a | Problem Statement
You are given a
6
-digit positive integer
N
.
Determine whether
N
satisfies all of the following conditions.
Among the digits of
N
, the digit
1
appears exactly once.
Among the digits of
N
, the digit
2
appears exactly twice.
Among the digits of
N
, the digit
3
appears exactly three times. | [
{
"input": "123233\n",
"output": "Yes\n"
},
{
"input": "123234\n",
"output": "No\n"
},
{
"input": "323132\n",
"output": "Yes\n"
},
{
"input": "500000\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_b | Problem Statement
Iroha has a sequence of positive integers
A = (A_1, A_2, \dots, A_N)
of length
N
(
N \ge 1
).
She generated a string
S
using
A
as follows:
Start with
S =
|
.
For
i = 1, 2, \dots, N
, perform the following operations in order:
Append
A_i
copies of
-
to the end of
S
.
Then, append one
|
to the end of
S
.
Given the generated string
S
, reconstruct the sequence
A
. | [
{
"input": "|---|-|----|-|-----|\n",
"output": "3 1 4 1 5\n"
},
{
"input": "|----------|\n",
"output": "10\n"
},
{
"input": "|-|-|-|------|\n",
"output": "1 1 1 6\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_c | Problem Statement
You are given a string
S
of length
N
consisting of
0
and
1
.
Move the
K
-th
1
-block from the beginning in
S
to immediately after the
(K-1)
-th
1
-block, and print the resulting string.
It is guaranteed that
S
contains at least
K
1
-blocks.
Here is a more precise description.
Let
S_{l\ldots r}
denote the substring of
S
from the
l
-th character through the
r
-th character.
We define a substring
S_{l\ldots r}
of
S
to be a
1
-block if it satisfies all of the following conditions:
S_l = S_{l+1} = \cdots = S_r =
1
l = 1
or
S_{l-1} =
0
r = N
or
S_{r+1} =
0
Suppose that all
1
-blocks in
S
are
S_{l_1\ldots r_1}, \ldots, S_{l_m\ldots r_m}
, where
l_1 < l_2 < \cdots < l_m
.
Then, we define the length
N
string
T
, obtained by moving the
K
-th
1
-block to immediately after the
(K-1)
-th
1
-block, as follows:
T_i = S_i
for
1 \leq i \leq r_{K-1}
T_i =
1
for
r_{K-1} + 1 \leq i \leq r_{K-1} + (r_K - l_K) + 1
T_i =
0
for
r_{K-1} + (r_K - l_K) + 2 \leq i \leq r_K
T_i = S_i
for
r_K + 1 \leq i \leq N | [
{
"input": "15 3\n010011100011001\n",
"output": "010011111000001\n"
},
{
"input": "10 2\n1011111111\n",
"output": "1111111110\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_d | Problem Statement
You are given a string
S
consisting of uppercase and lowercase English letters.
We perform the following operation on
S
10^{100}
times:
First, create a string
T
by changing uppercase letters in
S
to lowercase, and lowercase letters to uppercase.
Then, concatenate
S
and
T
in this order to form a new
S
.
Answer
Q
queries. The
i
-th query is as follows:
Find the
K_i
-th character from the beginning of
S
after all operations are completed. | [
{
"input": "aB\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n",
"output": "a B A b A b a B A b a B a B A b\n"
},
{
"input": "qWeRtYuIoP\n8\n1 1 2 3 5 8 13 21\n",
"output": "q q W e t I E Q\n"
},
{
"input": "AnUoHrjhgfLMcDIpzxXmEWPwBZvbKqQuiJTtFSlkNGVReOYCdsay\n5\n1000000000000000000 123456789 1 987654321 999999999999999999\n",
"output": "K a A Z L\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_e | Problem Statement
There are
N
cells in a row, numbered
1
to
N
.
For each
1 \leq i < N
, cells
i
and
i+1
are adjacent.
Initially, cell
i
is painted with color
i
.
You are given
Q
queries. Process them in order. Each query is of one of the following two types.
1 x c
: Repaint the following to color
c
: all reachable cells reachable from cell
x
by repeatedly moving to an adjacent cell painted in the same color as the current cell.
2 c
: Print the number of cells painted with color
c
. | [
{
"input": "5 6\n1 5 4\n1 4 2\n2 2\n1 3 2\n1 2 3\n2 3\n",
"output": "3\n4\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_f | Problem Statement
Takahashi and Aoki will play a game using cards with numbers written on them.
Initially, Takahashi has
N
cards with numbers
A_1, \ldots, A_N
in his hand, Aoki has
M
cards with numbers
B_1, \ldots, B_M
in his hand, and there are
L
cards with numbers
C_1, \ldots, C_L
on the table.
Throughout the game, both Takahashi and Aoki know all the numbers on all the cards, including the opponent's hand.
Starting with Takahashi, they take turns performing the following action:
Choose one card from his hand and put it on the table. Then, if there is a card on the table with a number less than the number on the card he just played, he may take one such card from the table into his hand.
The player who cannot make a move first loses, and the other player wins. Determine who wins if both players play optimally.
It can be proved that the game always ends in a finite number of moves. | [
{
"input": "1 1 2\n2\n4\n1 3\n",
"output": "Aoki\n"
},
{
"input": "4 4 4\n98 98765 987654 987654321\n987 9876 9876543 98765432\n123 12345 1234567 123456789\n",
"output": "Takahashi\n"
},
{
"input": "1 1 8\n10\n10\n1 2 3 4 5 6 7 8\n",
"output": "Aoki\n"
}
] |
https://atcoder.jp/contests/abc380/tasks/abc380_g | Problem Statement
You are given a permutation
P
of
(1,2,\dots,N)
and an integer
K
.
Find the expected value, modulo
998244353
, of the inversion number of
P
after performing the following operation:
First, choose an integer
i
uniformly at random between
1
and
N - K + 1
, inclusive.
Then, shuffle
P_i, P_{i+1}, \dots, P_{i+K-1}
uniformly at random.
What is the inversion number?
The inversion number of a sequence
(A_1, A_2, \dots, A_N)
is the number of integer pairs
(i, j)
satisfying
1 \le i < j \le N
and
A_i > A_j
.
What does "expected value modulo
998244353
" mean?
It can be proved that the sought expected value is always rational. Under the constraints of this problem, when this value is represented as an irreducible fraction
\frac{P}{Q}
, it can also be proved that
Q \not\equiv 0 \pmod{998244353}
. Thus, there is a unique integer
R
satisfying
R \times Q \equiv P \pmod{998244353}, \ 0 \le R < 998244353
. Report this integer
R
. | [
{
"input": "4 2\n1 4 2 3\n",
"output": "166374061\n"
},
{
"input": "1 1\n1\n",
"output": "0\n"
},
{
"input": "10 6\n7 4 10 5 6 1 8 2 3 9\n",
"output": "499122200\n"
}
] |
https://atcoder.jp/contests/joi2025yo1c/tasks/joi2025_yo1c_a | 問題文
ビ太郎は
1\,000
円札を
A
枚,
10\,000
円札を
B
枚持っている.全部でいくら持っているか出力せよ. | [
{
"input": "7\n2\n",
"output": "27000\n"
},
{
"input": "11\n1\n",
"output": "21000\n"
}
] |
https://atcoder.jp/contests/joi2025yo1c/tasks/joi2025_yo1c_b | 問題文
3
つの整数
A, B, C
が与えられる.
3
つの値の合計が
21
以下なら
1
を,そうでないなら
0
を出力せよ. | [
{
"input": "5\n10\n6\n",
"output": "1\n"
},
{
"input": "7\n8\n13\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/joi2025yo1c/tasks/joi2025_yo1c_c | 問題文
正整数
N
,
A
,
B
が与えられる.ここで,
A ≠ B
である.
1
以上
N
以下の整数のうち,
A
と
B
のいずれか片方のみで割り切れるものの個数を出力せよ. | [
{
"input": "6\n2\n3\n",
"output": "3\n"
},
{
"input": "1\n5\n3\n",
"output": "0\n"
},
{
"input": "100\n1\n2\n",
"output": "50\n"
}
] |
https://atcoder.jp/contests/joi2025yo1c/tasks/joi2025_yo1c_d | 問題文
長さ
N
の文字列
S
が与えられる.
S
の各文字は英小文字である.
ある文字列
T
および整数
m \ (2 \leqq m)
が存在して,空文字列に対して
T
を
m
回順に繋げた文字列が
S
に一致する時,
S
は
周期的
であるとする.
S
が周期的であるなら
Yes
を,そうでないならば
No
を出力せよ. | [
{
"input": "6\nababab\n",
"output": "Yes\n"
},
{
"input": "7\nabcabca\n",
"output": "No\n"
},
{
"input": "2\naa\n",
"output": "Yes\n"
},
{
"input": "8\nababcdcd\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/ahc039/tasks/ahc039_a | Problem Statement
There are
N
mackerels and
N
sardines on a two-dimensional plane.
Construct a polygon that satisfies the following conditions and maximize the value obtained by subtracting the total number of sardines inside the polygon from the total number of mackerels inside it.
Note that any points lying on the edges of the polygon are considered to be inside the polygon. | [] |
https://atcoder.jp/contests/abc379/tasks/abc379_a | Problem Statement
You are given a three-digit integer
N
where each digit is an integer between
1
and
9
, inclusive.
Let
a
,
b
,
c
be the hundreds, tens, ones digits of
N
, respectively. Print an integer formed by arranging
b
,
c
,
a
in this order, and an integer formed by arranging
c
,
a
,
b
in this order. | [
{
"input": "379\n",
"output": "793 937\n"
},
{
"input": "919\n",
"output": "199 991\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_b | Problem Statement
Takahashi has
N
teeth arranged in a single row from left to right. The current condition of his teeth is represented by a string
S
.
If the
i
-th character of
S
is
O
, it means that the
i
-th tooth from the left is healthy. If it is
X
, it means that the
i
-th tooth has a cavity. Healthy teeth do not have cavities.
When he has
K
consecutive healthy teeth, he can eat one strawberry using those
K
teeth. After eating a strawberry, those
K
teeth develop cavities and become unhealthy.
Find the maximum number of strawberries he can eat. | [
{
"input": "7 3\nOOXOOOO\n",
"output": "1\n"
},
{
"input": "12 2\nOXXOOOXOOOOX\n",
"output": "3\n"
},
{
"input": "22 5\nXXOOOOOOOOXXOOOOOXXXXX\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_c | Problem Statement
There are
N
cells numbered from
1
to
N
in a row. Initially,
M
cells contain stones, and cell
X_i
contains
A_i
stones
(1 \leq i \leq M)
.
You can perform the following operation any number of times (possibly zero):
If cell
i
(
1 \leq i \leq N-1
) contains a stone, move one stone from cell
i
to cell
i+1
.
Find the minimum number of operations required to reach a state where each of the
N
cells contains exactly one stone. If it is impossible, print
-1
. | [
{
"input": "5 2\n1 4\n3 2\n",
"output": "4\n"
},
{
"input": "10 3\n1 4 8\n4 2 4\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_d | Problem Statement
Takahashi has
10^{100}
flower pots. Initially, he is not growing any plants.
You are given
Q
queries to process in order.
There are three types of queries as follows.
1
: Prepare one empty flower pot and put a plant in it. Here, the plant's height is
0
.
2 T
: Wait for
T
days. During this time, the height of every existing plants increases by
T
.
3 H
: Harvest all plants with a height of at least
H
, and output the number of plants harvested. The harvested plants are removed from their flower pots.
Assume that performing queries of the first and third types takes zero time. | [
{
"input": "6\n1\n2 15\n1\n3 10\n2 20\n3 20\n",
"output": "1\n1\n"
},
{
"input": "15\n1\n1\n2 226069413\n3 1\n1\n1\n2 214168203\n1\n3 214168203\n1\n1\n1\n2 314506461\n2 245642315\n3 1\n",
"output": "2\n2\n4\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_e | Problem Statement
You are given a string
S
of length
N
consisting of digits from
1
through
9
.
For each pair of integers
(i,j) \ (1\leq i\leq j\leq N)
, define
f(i, j)
as the value obtained by interpreting the substring of
S
from the
i
-th through the
j
-th character as a decimal integer. Find
\displaystyle \sum_{i=1}^N \sum_{j=i}^N f(i, j)
. | [
{
"input": "3\n379\n",
"output": "514\n"
},
{
"input": "30\n314159265358979323846264338327\n",
"output": "369673254065355789035427227741\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_f | Problem Statement
There are
N
buildings, building
1
, building
2
,
\ldots
, building
N
, arranged in this order in a straight line from west to east. Building
1
is the westernmost, and building
N
is the easternmost. The height of building
i\ (1\leq i\leq N)
is
H_i
.
For a pair of integers
(i,j)\ (1\leq i\lt j\leq N)
, building
j
can be seen from building
i
if the following condition is satisfied.
There is no building taller than building
j
between buildings
i
and
j
. In other words, there is no integer
k\ (i\lt k\lt j)
such that
H_k > H_j
.
You are given
Q
queries. In the
i
-th query, given a pair of integers
(l_i,r_i)\ (l_i\lt r_i)
, find the number of buildings to the east of building
r_i
(that is, buildings
r_i + 1
,
r_i + 2
,
\ldots
,
N
) that can be seen from both buildings
l_i
and
r_i
. | [
{
"input": "5 3\n2 1 4 3 5\n1 2\n3 5\n1 4\n",
"output": "2\n0\n1\n"
},
{
"input": "10 10\n2 1 5 3 4 6 9 8 7 10\n3 9\n2 5\n4 8\n5 6\n3 8\n2 10\n7 8\n6 7\n8 10\n4 10\n",
"output": "1\n3\n1\n2\n1\n0\n1\n1\n0\n0\n"
}
] |
https://atcoder.jp/contests/abc379/tasks/abc379_g | Problem Statement
You are given a grid
S
with
H
rows and
W
columns consisting of
1
,
2
,
3
, and
?
. The character at the
i
-th row and
j
-th column is
S_{i,j}
.
By replacing each
?
in
S
with
1
,
2
, or
3
, we can obtain
3^q
different grids, where
q
is the number of
?
. Among these grids, how many satisfy the following condition? Print the count modulo
998244353
.
Any two adjacent (edge-sharing) cells contain different digits. | [
{
"input": "2 2\n1?\n??\n",
"output": "6\n"
},
{
"input": "2 3\n123\n3?1\n",
"output": "0\n"
},
{
"input": "8 8\n3?1?????\n???1????\n??????2?\n????????\n????????\n????13??\n??13?1??\n????????\n",
"output": "779135038\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_a | Problem Statement
There are four balls, and the color of the
i
-th ball is
A_i
.
Find the maximum number of times you can perform this operation: choose two balls of the same color and discard both. | [
{
"input": "2 1 2 1\n",
"output": "2\n"
},
{
"input": "4 4 4 1\n",
"output": "1\n"
},
{
"input": "1 2 3 4\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_b | Problem Statement
In AtCoder City,
N
types of garbage are collected regularly. The
i
-th type of garbage
(i=1,2,\dots,N)
is collected on days when the date modulo
q_i
equals
r_i
.
Answer
Q
queries. In the
j
-th query
(j=1,2,\dots,Q)
, given that the
t_j
-th type of garbage is put out on day
d_j
, answer the next day on which it will be collected.
Here, if the
i
-th type of garbage is put out on a day when that type of garbage is collected, then the garbage will be collected on the same day. | [
{
"input": "2\n7 3\n4 2\n5\n1 1\n1 3\n1 4\n1 15\n2 7\n",
"output": "3\n3\n10\n17\n10\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_c | Problem Statement
You are given a sequence of
N
positive numbers,
A = (A_1, A_2, \dots, A_N)
. Find the sequence
B = (B_1, B_2, \dots, B_N)
of length
N
defined as follows.
For
i = 1, 2, \dots, N
, define
B_i
as follows:
Let
B_i
be the most recent position before
i
where an element equal to
A_i
appeared. If such a position does not exist, let
B_i = -1
.
More precisely, if there exists a positive integer
j
such that
A_i = A_j
and
j < i
, let
B_i
be the largest such
j
. If no such
j
exists, let
B_i = -1
. | [
{
"input": "5\n1 2 1 1 3\n",
"output": "-1 -1 1 3 -1\n"
},
{
"input": "4\n1 1000000000 1000000000 1\n",
"output": "-1 -1 2 1\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_d | Problem Statement
There is a grid of
H \times W
cells. Let
(i, j)
denote the cell at the
i
-th row from the top and the
j
-th column from the left.
Cell
(i, j)
is empty if
S_{i,j}
is
.
, and blocked if it is
#
.
Count the number of ways to start from an empty cell and make
K
moves to adjacent cells (up, down, left, or right), without passing through blocked squares and not visiting the same cell more than once.
Specifically, count the number of sequences of length
K+1
,
((i_0, j_0), (i_1, j_1), \dots, (i_K, j_K))
, satisfying the following.
1 \leq i_k \leq H
,
1 \leq j_k \leq W
, and
S_{i_k, j_k}
is
.
, for each
0 \leq k \leq K
.
|i_{k+1} - i_k| + |j_{k+1} - j_k| = 1
for each
0 \leq k \leq K-1
.
(i_k, j_k) \neq (i_l, j_l)
for each
0 \leq k < l \leq K
. | [
{
"input": "2 2 2\n.#\n..\n",
"output": "2\n"
},
{
"input": "2 3 1\n.#.\n#.#\n",
"output": "0\n"
},
{
"input": "10 10 11\n....#..#..\n.#.....##.\n..#...##..\n...#......\n......##..\n..#......#\n#........#\n..##......\n.###....#.\n...#.....#\n",
"output": "218070\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_e | Problem Statement
You are given a sequence
A = (A_1, A_2, \dots, A_N)
of
N
non-negative integers, and a positive integer
M
.
Find the following value:
\[
\sum_{1 \leq l \leq r \leq N} \left( \left(\sum_{l \leq i \leq r} A_i\right) \mathbin{\mathrm{mod}} M \right).
\]
Here,
X \mathbin{\mathrm{mod}} M
denotes the remainder when the non-negative integer
X
is divided by
M
. | [
{
"input": "3 4\n2 5 0\n",
"output": "10\n"
},
{
"input": "10 100\n320 578 244 604 145 839 156 857 556 400\n",
"output": "2736\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_f | Problem Statement
You are given a tree with
N
vertices. The
i
-th edge
(1 \leq i \leq N-1)
connects vertices
u_i
and
v_i
bidirectionally.
Adding one undirected edge to the given tree always yields a graph with exactly one cycle.
Among such graphs, how many satisfy all of the following conditions?
The graph is simple.
All vertices in the cycle have degree
3
. | [
{
"input": "6\n1 2\n2 3\n3 4\n4 5\n3 6\n",
"output": "1\n"
},
{
"input": "7\n1 2\n2 7\n3 5\n7 3\n6 2\n4 7\n",
"output": "0\n"
},
{
"input": "15\n1 15\n11 14\n2 10\n1 7\n9 8\n6 9\n4 12\n14 5\n4 9\n8 11\n7 4\n1 13\n3 6\n11 10\n",
"output": "6\n"
}
] |
https://atcoder.jp/contests/abc378/tasks/abc378_g | Problem Statement
You are given integers
A
,
B
, and
M
.
How many permutations
P = (P_1, \dots, P_{AB-1})
of
(1, 2, \ldots, AB - 1)
satisfy all of the following conditions? Find the count modulo
M
.
The length of a longest increasing subsequence of
P
is
A
.
The length of a longest decreasing subsequence of
P
is
B
.
There exists an integer
n
such that appending
n + 0.5
to the end of
P
does not change either of the lengths of a longest increasing subsequence and a longest decreasing subsequence. | [
{
"input": "3 2 998244353\n",
"output": "10\n"
},
{
"input": "10 12 924844033\n",
"output": "623378361\n"
}
] |
https://atcoder.jp/contests/arc186/tasks/arc186_a | Problem Statement
For two
N \times N
matrices
A
and
B
whose elements are
0
or
1
, we say that
A
and
B
are
similar
if they satisfy the following conditions:
The sums of corresponding rows are equal. That is,
A_{i,1} + \dots + A_{i,N} = B_{i,1} + \dots + B_{i,N}
for any
i=1,\dots,N
.
The sums of corresponding columns are equal. That is,
A_{1,j} + \dots + A_{N,j} = B_{1,j} + \dots + B_{N,j}
for any
j=1,\dots,N
.
Furthermore, for an
N \times N
matrix
A
whose elements are
0
or
1
, and integers
i,j
(
1 \leq i,j \leq N
), we say that the element at row
i
column
j
is
fixed
if
A_{i,j} = B_{i,j}
holds for any matrix
B
that is similar to
A
.
Answer the following
Q
queries:
The
i
-th query: If there exists an
N \times N
matrix whose elements are
0
or
1
such that exactly
K_i
elements are fixed, output
Yes
; otherwise, output
No
. | [
{
"input": "3 3\n0\n9\n7\n",
"output": "Yes\nYes\nNo\n"
},
{
"input": "29 6\n186\n681\n18\n108\n123\n321\n",
"output": "No\nYes\nNo\nYes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/arc186/tasks/arc186_b | Problem Statement
You are given a sequence of integers
(A_1,\dots,A_N)
of length
N
. This sequence satisfies
0\le A_i < i
for each
i=1,\dots,N
.
Find the number of permutations
(P_1,\dots,P_N)
of
(1,\dots,N)
that satisfy the following conditions, modulo
998244353
.
For each
i=1,\dots,N
:
P_j > P_i
for any integer
j
with
A_i < j < i
P_{A_i} < P_i
if
A_i > 0
For the sequence
(A_1,\dots,A_N)
given in the input, it is guaranteed that there exists a permutation satisfying the conditions. | [
{
"input": "4\n0 1 0 3\n",
"output": "3\n"
},
{
"input": "22\n0 1 2 2 2 2 2 2 1 9 9 9 9 0 14 15 15 15 14 19 19 19\n",
"output": "353820794\n"
}
] |
https://atcoder.jp/contests/arc186/tasks/arc186_c | Problem Statement
Mr. Ball and Mr. Box will play a game with balls and boxes.
Initially, Mr. Ball has
10^{100}
balls of each of
M
different types, and Mr. Box has
10^{100}
yen.
There are
N
boxes, where the
i
-th box has capacity
V_i
and costs
P_i
yen. During the game, Mr. Box can buy any box at any time.
In this game, the following operations are repeated until the game ends:
Mr. Ball chooses one ball and gives it to Mr. Box.
Mr. Box either accepts the ball or ends the game without accepting it.
If Mr. Box accepts the ball, he chooses one of his purchased boxes and puts the ball in it.
If the box with the ball satisfies the following conditions, Mr. Box receives
1
yen. Otherwise, the game ends.
The number of balls in the box does not exceed its capacity.
All balls in the box are of the same type.
Mr. Ball will play optimally to minimize Mr. Box's final money, while Mr. Box will play optimally to maximize it.
How much will Mr. Box's money increase throughout the game?
Here, both players have access to all information. In particular, Mr. Ball can see the capacity, price, and contents (type and number of balls) of each box.
Also, note that Mr. Box's initial money is large enough that he will never run out of money to buy boxes.
Solve
T
test cases for each input file. | [
{
"input": "3\n3 2\n1 1000000000\n3 1\n3 1\n1 300000\n1000000000 1\n10 4\n22 5\n26 45\n72 21\n47 39\n97 2\n75 35\n82 24\n17 46\n32 22\n28 67\n",
"output": "2\n0\n28\n"
}
] |
https://atcoder.jp/contests/arc186/tasks/arc186_d | Problem Statement
Whether a non-empty sequence of non-negative integers
(V_1, V_2, \dots, V_M)
is
Polish
or not is recursively defined as follows:
We say
(V_1, V_2, \dots, V_M)
is Polish if there exist
V_1
Polish sequences
W_1, W_2, \dots, W_{V_1}
such that the concatenation of sequences
(V_1), W_1, W_2, \dots, W_{V_1}
in this order equals
(V_1, V_2, \dots, V_M)
.
In particular, the sequence
(0)
is Polish.
Given a sequence of non-negative integers
(A_1, A_2, \dots, A_N)
of length
N
, find the number of Polish sequences of length
N
that are lexicographically not greater than
(A_1, A_2, \dots, A_N)
, modulo
998244353
.
What is lexicographical order on sequences?
We say that sequence
S = (S_1,S_2,\ldots,S_{|S|})
is
lexicographically less
than sequence
T = (T_1,T_2,\ldots,T_{|T|})
if either condition 1. or 2. below holds.
Here,
|S|, |T|
represent the lengths of
S, T
respectively.
|S| \lt |T|
and
(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})
.
There exists an integer
1 \leq i \leq \min\lbrace |S|, |T| \rbrace
such that both of the following hold:
(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
S_i
is (numerically) less than
T_i
. | [
{
"input": "6\n1 1 1 2 0 0\n",
"output": "2\n"
},
{
"input": "11\n3 3 4 4 5 5 6 6 7 7 8\n",
"output": "13002\n"
},
{
"input": "19\n18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18\n",
"output": "477638700\n"
},
{
"input": "4\n1 1 0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/arc186/tasks/arc186_e | Problem Statement
You are given a sequence of integers
(X_1,\dots,X_M)
of length
M
consisting of
1,\dots,K
.
Find the number of sequences
(A_1,\dots,A_N)
of length
N
consisting of
1,\dots,K
that satisfy the following condition, modulo
998244353
:
Among all sequences of length
M
consisting of
1,\dots,K
, the only sequence that cannot be obtained as a (not necessarily contiguous) subsequence of
(A_1,\dots,A_N)
is
(X_1,\dots,X_M)
. | [
{
"input": "5 2 3\n1 1\n",
"output": "4\n"
},
{
"input": "400 3 9\n1 8 6\n",
"output": "417833302\n"
},
{
"input": "29 3 10\n3 3 3\n",
"output": "495293602\n"
},
{
"input": "29 3 10\n3 3 4\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_a | Problem Statement
You are given a string
S
of length
3
consisting of uppercase English letters.
Determine whether it is possible to rearrange the characters in
S
to make it match the string
ABC
. | [
{
"input": "BAC\n",
"output": "Yes\n"
},
{
"input": "AAC\n",
"output": "No\n"
},
{
"input": "ABC\n",
"output": "Yes\n"
},
{
"input": "ARC\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_b | Problem Statement
There is a grid of
64
squares with
8
rows and
8
columns.
Let
(i,j)
denote the square at the
i
-th row from the top
(1\leq i\leq8)
and
j
-th column from the left
(1\leq j\leq8)
.
Each square is either empty or has a piece placed on it.
The state of the squares is represented by a sequence
(S_1,S_2,S_3,\ldots,S_8)
of
8
strings of length
8
.
Square
(i,j)
(1\leq i\leq8,1\leq j\leq8)
is empty if the
j
-th character of
S_i
is
.
, and has a piece if it is
#
.
You want to place your piece on an
empty square
in such a way that it
cannot be captured by any of the existing pieces
.
A piece placed on square
(i,j)
can capture pieces that satisfy either of the following conditions:
Placed on a square in row
i
Placed on a square in column
j
For example, a piece placed on square
(4,4)
can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on? | [
{
"input": "...#....\n#.......\n.......#\n....#...\n.#......\n........\n........\n..#.....\n",
"output": "4\n"
},
{
"input": "........\n........\n........\n........\n........\n........\n........\n........\n",
"output": "64\n"
},
{
"input": ".#......\n..#..#..\n....#...\n........\n..#....#\n........\n...#....\n....#...\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_c | Problem Statement
There is a grid of
N^2
squares with
N
rows and
N
columns.
Let
(i,j)
denote the square at the
i
-th row from the top
(1\leq i\leq N)
and
j
-th column from the left
(1\leq j\leq N)
.
Each square is either empty or has a piece placed on it.
There are
M
pieces placed on the grid, and the
k
-th
(1\leq k\leq M)
piece is placed on square
(a_k,b_k)
.
You want to place your piece on an
empty square
in such a way that it
cannot be captured by any of the existing pieces
.
A piece placed on square
(i,j)
can capture pieces that satisfy any of the following conditions:
Placed on square
(i+2,j+1)
Placed on square
(i+1,j+2)
Placed on square
(i-1,j+2)
Placed on square
(i-2,j+1)
Placed on square
(i-2,j-1)
Placed on square
(i-1,j-2)
Placed on square
(i+1,j-2)
Placed on square
(i+2,j-1)
Here, conditions involving non-existent squares are considered to never be satisfied.
For example, a piece placed on square
(4,4)
can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on? | [
{
"input": "8 6\n1 4\n2 1\n3 8\n4 5\n5 2\n8 3\n",
"output": "38\n"
},
{
"input": "1000000000 1\n1 1\n",
"output": "999999999999999997\n"
},
{
"input": "20 10\n1 4\n7 11\n7 15\n8 10\n11 6\n12 5\n13 1\n15 2\n20 10\n20 15\n",
"output": "338\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_d | Problem Statement
You are given two sequences of positive integers of length
N
,
L=(L_1,L_2,\ldots,L_N)
and
R=(R_1,R_2,\ldots,R_N)
, and an integer
M
.
Find the number of pairs of integers
(l,r)
that satisfy both of the following conditions:
1\le l \le r \le M
For every
1\le i\le N
, the interval
[l,r]
does not completely contain the interval
[L_i,R_i]
. | [
{
"input": "2 4\n1 2\n3 4\n",
"output": "5\n"
},
{
"input": "6 5\n1 1\n2 2\n3 3\n4 4\n5 5\n1 5\n",
"output": "0\n"
},
{
"input": "6 20\n8 12\n14 20\n11 13\n5 19\n4 11\n1 6\n",
"output": "102\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_e | Problem Statement
You are given a permutation
P=(P_1,P_2,\ldots,P_N)
of
(1,2,\ldots,N)
.
The following operation will be performed
K
times:
For
i=1,2,\ldots,N
,
simultaneously
update
P_i
to
P_{P_i}
.
Print
P
after all operations. | [
{
"input": "6 3\n5 6 3 1 2 4\n",
"output": "6 1 3 2 4 5\n"
},
{
"input": "5 1000000000000000000\n1 2 3 4 5\n",
"output": "1 2 3 4 5\n"
},
{
"input": "29 51912426\n7 24 8 23 6 1 4 19 11 18 20 9 17 28 22 27 15 2 12 26 10 13 14 25 5 29 3 21 16\n",
"output": "18 23 16 24 21 10 2 27 19 7 12 8 13 5 15 26 17 4 3 9 1 22 25 14 28 11 29 6 20\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_f | Problem Statement
There is a grid of
N^2
squares with
N
rows and
N
columns.
Let
(i,j)
denote the square at the
i
-th row from the top
(1\leq i\leq N)
and
j
-th column from the left
(1\leq j\leq N)
.
Each square is either empty or has a piece placed on it.
There are
M
pieces placed on the grid, and the
k
-th
(1\leq k\leq M)
piece is placed on square
(a_k,b_k)
.
You want to place your piece on an
empty square
in such a way that it
cannot be captured by any of the existing pieces
.
A piece placed on square
(i,j)
can capture pieces that satisfy any of the following conditions:
Placed in row
i
Placed in column
j
Placed on any square
(a,b)\ (1\leq a\leq N,1\leq b\leq N)
where
i+j=a+b
Placed on any square
(a,b)\ (1\leq a\leq N,1\leq b\leq N)
where
i-j=a-b
For example, a piece placed on square
(4,4)
can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on? | [
{
"input": "8 6\n1 4\n2 1\n3 8\n4 5\n5 2\n8 3\n",
"output": "2\n"
},
{
"input": "1000000000 1\n1 1\n",
"output": "999999997000000002\n"
},
{
"input": "20 10\n1 4\n7 11\n7 15\n8 10\n11 6\n12 5\n13 1\n15 2\n20 10\n20 15\n",
"output": "77\n"
}
] |
https://atcoder.jp/contests/abc377/tasks/abc377_g | Problem Statement
You are given
N
strings
S_1,S_2,\ldots,S_N
. Each string consists of lowercase English letters.
For each
k=1,2,\ldots,N
, solve the following problem.
Let
T=S_k
and consider performing the following two types of operations any number of times in any order:
Pay a cost of
1
to delete the last character of
T
. This operation is possible when
T
is not empty.
Pay a cost of
1
to add any lowercase English letter to the end of
T
.
Find the minimum total cost needed to make
T
either empty or match one of
S_1,S_2,\ldots,S_{k-1}
. | [
{
"input": "3\nsnuke\nsnuki\nsnuuk\n",
"output": "5\n2\n4\n"
},
{
"input": "3\nabc\narc\nagc\n",
"output": "3\n3\n3\n"
},
{
"input": "8\nat\natatat\nattat\naatatatt\nattattat\nttatta\ntta\ntt\n",
"output": "2\n4\n3\n8\n3\n6\n3\n1\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_a | Problem Statement
There is a mysterious button.
When you press this button, you receive one candy, unless less than
C
seconds have elapsed since you last received a candy.
Takahashi decided to press this button
N
times.
He will press the button for the
i
-th time
T_i
seconds from now.
How many candies will he receive? | [
{
"input": "6 5\n1 3 7 8 10 12\n",
"output": "3\n"
},
{
"input": "3 2\n0 2 4\n",
"output": "3\n"
},
{
"input": "10 3\n0 3 4 6 9 12 15 17 19 20\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_b | Problem Statement
Note: This problem has almost the same setting as Problem F. Only the parts in bold in the main text and constraints differ.
You are holding a ring with both hands.
This ring consists of
N\ (N \geq 3)
parts numbered
1,2,\dots,N
, where parts
i
and
i+1
(
1 \leq i \leq N-1
) are adjacent, and parts
1
and
N
are also adjacent.
Initially, your left hand is holding part
1
, and your right hand is holding part
2
.
In one
operation
, you can do the following:
Move one of your hands to an adjacent part of the part it is currently holding. However, you can do this only if the other hand is not on the destination part.
The following figure shows the initial state and examples of operations that can and cannot be made from there. The number written on each part of the ring represents the part number, and the circles labeled L and R represent your left and right hands, respectively.
You need to follow
Q
instructions given to you in order.
The
i
-th (
1 \leq i \leq Q
) instruction is represented by a character
H_i
and an integer
T_i
, meaning the following:
Perform some number of operations (possibly zero) so that your left hand (if
H_i
is
L
) or your right hand (if
H_i
is
R
) is holding part
T_i
.
Here, you
must not
move the other hand not specified by
H_i
.
It is guaranteed that only achievable instructions are given.
Details
Under the settings of this problem, it can be proved that the positions of both hands are uniquely determined just before following the
i
-th instruction for each
i
.
At that time, if we denote the positions of the left and right hands as parts
l_i
and
r_i
, respectively, it is guaranteed that
T_i \neq r_i
when
H_i
is
L
, and
T_i \neq l_i
when
H_i
is
R
.
Find the minimum total number of operations required to follow all the instructions. | [
{
"input": "6 3\nR 4\nL 5\nR 6\n",
"output": "8\n"
},
{
"input": "100 2\nL 1\nR 2\n",
"output": "0\n"
},
{
"input": "30 8\nR 23\nR 26\nR 29\nL 20\nR 29\nR 19\nL 7\nL 16\n",
"output": "92\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_c | Problem Statement
There are
N
toys numbered from
1
to
N
, and
N-1
boxes numbered from
1
to
N-1
.
Toy
i\ (1 \leq i \leq N)
has a size of
A_i
, and box
i\ (1 \leq i \leq N-1)
has a size of
B_i
.
Takahashi wants to store all the toys in separate boxes, and he has decided to perform the following steps in order:
Choose an arbitrary positive integer
x
and purchase one box of size
x
.
Place each of the
N
toys into one of the
N
boxes (the
N-1
existing boxes plus the newly purchased box).
Here, each toy can only be placed in a box whose size is not less than the toy's size, and no box can contain two or more toys.
He wants to execute step
2
by purchasing a sufficiently large box in step
1
, but larger boxes are more expensive, so he wants to purchase the smallest possible box.
Determine whether there exists a value of
x
such that he can execute step
2
, and if it exists, find the minimum such
x
. | [
{
"input": "4\n5 2 3 7\n6 2 8\n",
"output": "3\n"
},
{
"input": "4\n3 7 2 5\n8 1 6\n",
"output": "-1\n"
},
{
"input": "8\n2 28 17 39 57 56 37 32\n34 27 73 28 76 61 27\n",
"output": "37\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_d | Problem Statement
There is a simple directed graph with
N
vertices numbered from
1
to
N
and
M
edges. The
i
-th edge
(1 \leq i \leq M)
is a directed edge from vertex
a_i
to vertex
b_i
.
Determine whether there exists a cycle that contains vertex
1
, and if it exists, find the minimum number of edges among such cycles. | [
{
"input": "3 3\n1 2\n2 3\n3 1\n",
"output": "3\n"
},
{
"input": "3 2\n1 2\n2 3\n",
"output": "-1\n"
},
{
"input": "6 9\n6 1\n1 5\n2 6\n2 1\n3 6\n4 2\n6 4\n3 5\n5 4\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_e | Problem Statement
You are given sequences of length
N
:
A = (A_1, A_2, \dots, A_N)
and
B = (B_1, B_2, \dots, B_N)
.
Let
S
be a subset of
\lbrace1, 2, \dots, N\rbrace
of size
K
.
Here, find the minimum possible value of the following expression:
\displaystyle \left(\max_{i \in S} A_i\right) \times \left(\sum_{i \in S} B_i\right).
You are given
T
test cases; solve each of them. | [
{
"input": "3\n3 2\n3 7 6\n9 2 4\n5 3\n6 4 1 5 9\n8 6 5 1 7\n10 6\n61 95 61 57 69 49 46 47 14 43\n39 79 48 92 90 76 30 16 30 94\n",
"output": "42\n60\n14579\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_f | Problem Statement
Note: This problem has almost the same setting as Problem B. Only the parts in bold in the main text and constraints differ.
You are holding a ring with both hands.
This ring consists of
N\ (N \geq 3)
parts numbered
1,2,\dots,N
, where parts
i
and
i+1
(
1 \leq i \leq N-1
) are adjacent, and parts
1
and
N
are also adjacent.
Initially, your left hand is holding part
1
, and your right hand is holding part
2
.
In one
operation
, you can do the following:
Move one of your hands to an adjacent part of the part it is currently holding. However, you can do this only if the other hand is not on the destination part.
The following figure shows the initial state and examples of operations that can and cannot be made from there. The number written on each part of the ring represents the part number, and the circles labeled L and R represent your left and right hands, respectively.
You need to follow
Q
instructions given to you in order.
The
i
-th (
1 \leq i \leq Q
) instruction is represented by a character
H_i
and an integer
T_i
, meaning the following:
Perform some number of operations (possibly zero) so that your left hand (if
H_i
is
L
) or your right hand (if
H_i
is
R
) is holding part
T_i
.
Here, you
may
move the other hand not specified by
H_i
.
Under the settings and constraints of this problem, it can be proved that any instructions are achievable.
Find the minimum total number of operations required to follow all the instructions. | [
{
"input": "6 3\nR 4\nL 5\nR 5\n",
"output": "6\n"
},
{
"input": "100 2\nL 1\nR 2\n",
"output": "0\n"
},
{
"input": "30 8\nR 23\nR 26\nR 29\nL 20\nR 29\nR 19\nL 7\nL 16\n",
"output": "58\n"
}
] |
https://atcoder.jp/contests/abc376/tasks/abc376_g | Problem Statement
There is a rooted tree with
N + 1
vertices numbered from
0
to
N
. Vertex
0
is the root, and the parent of vertex
i
is vertex
p_i
.
One of the vertices among vertex
1
, vertex
2
, ..., vertex
N
hides a treasure. The probability that the treasure is at vertex
i
is
\frac{a_i}{\sum_{j=1}^N a_j}
.
Also, each vertex is in one of the two states: "searched" and "unsearched". Initially, vertex
0
is searched, and all other vertices are unsearched.
Until the vertex containing the treasure becomes searched, you perform the following operation:
Choose an unsearched vertex whose parent is searched, and mark it as searched.
Find the expected number of operations required when you act to minimize the expected number of operations, modulo
998244353
.
You are given
T
test cases; solve each of them.
How to find an expected value modulo
998244353
It can be proved that the expected value is always a rational number. Under the constraints of this problem, it can also be proved that when the expected value is expressed as an irreducible fraction
\frac{P}{Q}
, we have
Q \not\equiv 0 \pmod{998244353}
. In this case, there is a unique integer
R
satisfying
R \times Q \equiv P \pmod{998244353},\ 0 \leq R < 998244353
. Report this
R
. | [
{
"input": "3\n3\n0 0 1\n1 2 3\n5\n0 1 0 0 0\n8 6 5 1 7\n10\n0 1 1 3 3 1 4 7 5 4\n43 39 79 48 92 90 76 30 16 30\n",
"output": "166374061\n295776107\n680203339\n"
}
] |
https://atcoder.jp/contests/arc185/tasks/arc185_a | Problem Statement
There are positive integers
N
and
M
, where
N \lt M
.
Alice and Bob will play a game. Each player has
N
cards with
1, 2, \dots, N
written on them, one for each number.
Starting with Alice, the two players take turns repeatedly performing this action: choose one card from their hand and play it onto the table.
Immediately after a card is played onto the table, if the sum of the numbers on the cards that have been played so far is divisible by
M
, the player who just played the card loses, and the other player wins.
If both players play all their cards without satisfying the above condition, Alice wins.
Who will win, Alice or Bob, when both play optimally?
You are given
T
test cases. Solve each of them. | [
{
"input": "8\n2 3\n3 6\n5 9\n45 58\n39 94\n36 54\n74 80\n61 95\n",
"output": "Alice\nAlice\nBob\nBob\nAlice\nBob\nBob\nAlice\n"
}
] |
https://atcoder.jp/contests/arc185/tasks/arc185_b | Problem Statement
You are given an integer sequence
A = (A_1, A_2, \dots, A_N)
of length
N
.
You can perform the following operation any number of times, possibly zero:
Choose an integer pair
(i, j)
satisfying
1 \leq i \lt j \leq N
, and replace
A_i
with
A_i + 1
and
A_j
with
A_j - 1
.
Determine whether it is possible to make
A
a non-decreasing sequence through the operations.
You are given
T
test cases. Solve each of them. | [
{
"input": "3\n3\n1 7 5\n2\n9 0\n10\n607 495 419 894 610 636 465 331 925 724\n",
"output": "Yes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/arc185/tasks/arc185_c | Problem Statement
You are given an integer sequence
A = (A_1, A_2, \dots, A_N)
and an integer
X
.
Print one triple of integers
(i, j, k)
satisfying all of the following conditions. If no such triple exists, report that fact.
1 \leq i \lt j \lt k \leq N
A_i + A_j + A_k = X | [
{
"input": "5 16\n1 8 5 10 13\n",
"output": "1 3 4\n"
},
{
"input": "5 20\n1 8 5 10 13\n",
"output": "-1\n"
},
{
"input": "10 100000\n73766 47718 74148 49218 76721 31902 21994 18880 29598 98917\n",
"output": "4 6 8\n"
}
] |
https://atcoder.jp/contests/arc185/tasks/arc185_d | Problem Statement
There is a tree with
N \times M + 1
vertices numbered
0, 1, \dots, N \times M
. The
i
-th edge
(1 \leq i \leq N \times M)
connects vertices
i
and
\max(i - N, 0)
.
Vertex
0
is painted. The other vertices are unpainted.
Takahashi is at vertex
0
. As long as there exists an unpainted vertex, he performs the following operation:
He chooses one of the vertices adjacent to his current vertex uniformly at random (all choices are independent) and moves to that vertex. Then, if the vertex he is on is unpainted, he paints it.
Find the expected number of times he performs the operation, modulo
998244353
.
What is the expected value modulo
998244353
?
It can be proved that the sought expected value is always rational. Under the constraints of this problem, when that value is expressed as an irreducible fraction
\frac{P}{Q}
, it can also be proved that
Q \not\equiv 0 \pmod{998244353}
. Then, there uniquely exists an integer
R
such that
R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353
. Report this
R
. | [
{
"input": "2 2\n",
"output": "20\n"
},
{
"input": "123456 185185\n",
"output": "69292914\n"
}
] |
https://atcoder.jp/contests/arc185/tasks/arc185_e | Problem Statement
Define the
score
of a sequence of positive integers
B = (B_1, B_2, \dots, B_k)
as
\displaystyle \sum_{i=1}^{k-1} \gcd(B_i, B_{i+1})
.
Given a sequence of positive integers
A = (A_1, A_2, \dots, A_N)
, solve the following problem for
m = 1, 2, \dots, N
.
There are
2^m - 1
non-empty subsequences of the sequence
(A_1, A_2, \dots, A_m)
. Find the sum of the scores of all those subsequences, modulo
998244353
. Two subsequences are distinguished if they are taken from different positions in the sequence, even if they coincide as sequences. | [
{
"input": "3\n9 6 4\n",
"output": "0\n3\n11\n"
},
{
"input": "5\n3 8 12 6 9\n",
"output": "0\n1\n13\n57\n155\n"
},
{
"input": "10\n47718 21994 74148 76721 98917 73766 29598 59035 69293 29127\n",
"output": "0\n2\n14\n35\n97\n372\n866\n1859\n4273\n43287\n"
}
] |
https://atcoder.jp/contests/joi2025yo1b/tasks/joi2025_yo1b_a | 問題文
ビ太郎は
T
秒間,秒速
V \:\mathrm{m}
で走った.何
\mathrm{m}
走ったか出力しなさい. | [
{
"input": "5\n3\n",
"output": "15\n"
},
{
"input": "2\n4\n",
"output": "8\n"
}
] |
https://atcoder.jp/contests/joi2025yo1b/tasks/joi2025_yo1b_b | 問題文
ビ太郎は JOI 鉄道に乗って旅行をする.JOI 鉄道の運賃ははじめの
P \: \mathrm{km}
までは
1 \: \mathrm{km}
あたり
A
円,それ以降の運賃は
1 \: \mathrm{km}
あたり
B
円で計算される.
Q\: \mathrm{km}
乗車するとき,運賃はいくらになるか出力せよ. | [
{
"input": "3 5\n2 1\n",
"output": "8\n"
},
{
"input": "3 2\n2 1\n",
"output": "4\n"
},
{
"input": "3 3\n5 5\n",
"output": "15\n"
}
] |
https://atcoder.jp/contests/joi2025yo1b/tasks/joi2025_yo1b_c | 問題文
長さ
N
の文字列
S, T
が与えられる.
S
の各文字は
R
,
S
のいずれかである.
T
の各文字は
R
,
P
のいずれかである.
葵とビ太郎は
N
回じゃんけんを行った.葵が
i
回目 (
1 \leqq i \leqq N
) のじゃんけんで出した手は
S
の
i
文字目が
R
,
S
のときそれぞれグー,チョキである.ビ太郎が
i
回目 (
1 \leqq i \leqq N
) のじゃんけんで出した手は
T
の
i
文字目が
R
,
P
のときそれぞれグー,パーである.
全
N
回のじゃんけんにおいて,葵が勝った回数とビ太郎が勝った回数を求めよ. | [
{
"input": "3\nRSR\nPPR\n",
"output": "1 1\n"
},
{
"input": "5\nRRRRR\nPPPPP\n",
"output": "0 5\n"
},
{
"input": "4\nRSRR\nRPRR\n",
"output": "1 0\n"
},
{
"input": "6\nRSSRSS\nPPRRRP\n",
"output": "2 3\n"
}
] |
https://atcoder.jp/contests/joi2025yo1b/tasks/joi2025_yo1b_d | 問題文
N
個の整数が黒板に左から右に書いてある.
左から
i
番目 (
1 \leqq i \leqq N
) の整数は
A_i
である.
黒板に書いてある整数列に対し,以下の操作を繰り返し行う.
操作
現在黒板の一番下の行に書いてある整数列の長さを
k
とおく.
この整数列の値を参照しながら,下に次のような長さ
k - 1
の新たな整数列を作り書き加える.
i=1, 2, \cdots , k-1
について,
i
番目の整数が,参照元の整数列の左から
i
番目と
i+1
番目の整数の合計となっている.
この操作を
N-1
回行うとき,黒板に書き加える整数列をすべて求めよ. | [
{
"input": "5\n1 3 5 7 9\n",
"output": "4 8 12 16\n12 20 28\n32 48\n80\n"
},
{
"input": "7\n1 2 3 4 3 2 1\n",
"output": "3 5 7 7 5 3\n8 12 14 12 8\n20 26 26 20\n46 52 46\n98 98\n196\n"
},
{
"input": "10\n1 9 2 4 4 9 2 3 5 6\n",
"output": "10 11 6 8 13 11 5 8 11\n21 17 14 21 24 16 13 19\n38 31 35 45 40 29 32\n69 66 80 85 69 61\n135 146 165 154 130\n281 311 319 284\n592 630 603\n1222 1233\n2455\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_a | Problem Statement
There are
N
seats in a row, numbered
1, 2, \ldots, N
.
The state of the seats is given by a string
S
of length
N
consisting of
#
and
.
. If the
i
-th character of
S
is
#
, it means seat
i
is occupied; if it is
.
, seat
i
is unoccupied.
Find the number of integers
i
between
1
and
N - 2
, inclusive, that satisfy the following condition:
Seats
i
and
i + 2
are occupied, and seat
i + 1
is unoccupied. | [
{
"input": "6\n#.##.#\n",
"output": "2\n"
},
{
"input": "1\n#\n",
"output": "0\n"
},
{
"input": "9\n##.#.#.##\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_b | Problem Statement
Takahashi is at the origin on a two-dimensional coordinate plane.
The cost for him to move from point
(a, b)
to point
(c, d)
is
\sqrt{(a - c)^2 + (b - d)^2}
.
Find the total cost when he starts at the origin, visits
N
points
(X_1, Y_1), \ldots, (X_N, Y_N)
in this order, and then returns to the origin. | [
{
"input": "2\n1 2\n-1 0\n",
"output": "6.06449510224597979401\n"
},
{
"input": "7\n-14142 13562\n-17320 50807\n-22360 67977\n24494 89742\n-26457 51311\n28284 27124\n31622 77660\n",
"output": "384694.57587932075868509383\n"
},
{
"input": "5\n-100000 100000\n100000 -100000\n-100000 100000\n100000 -100000\n-100000 100000\n",
"output": "1414213.56237309504880168872\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_c | Problem Statement
You are given a grid with
N
rows and
N
columns, where
N
is an even number. Let
(i, j)
denote the cell at the
i
-th row from the top and
j
-th column from the left.
Each cell is painted black or white. If
A_{i, j} =
#
, cell
(i, j)
is black; if
A_{i, j} =
.
, it is white.
Find the color of each cell after performing the following operation for
i = 1, 2, \ldots, \frac{N}{2}
in this order.
For all pairs of integers
x, y
between
i
and
N + 1 - i
, inclusive, replace the color of cell
(y, N + 1 - x)
with the color of cell
(x, y)
. Perform these replacements
simultaneously for all such pairs
x, y
. | [
{
"input": "8\n.......#\n.......#\n.####..#\n.####..#\n.##....#\n.##....#\n.#######\n.#######\n",
"output": "........\n#######.\n#.....#.\n#.###.#.\n#.#...#.\n#.#####.\n#.......\n########\n"
},
{
"input": "6\n.#.#.#\n##.#..\n...###\n###...\n..#.##\n#.#.#.\n",
"output": "#.#.#.\n.#.#.#\n#.#.#.\n.#.#.#\n#.#.#.\n.#.#.#\n"
},
{
"input": "12\n.......#.###\n#...#...#..#\n###.#..#####\n..#.#.#.#...\n.#.....#.###\n.......#.#..\n#...#..#....\n#####.......\n...#...#.#.#\n..###..#..##\n#..#.#.#.#.#\n.####.......\n",
"output": ".#..##...##.\n#.#.#.#.#...\n###.##..#...\n#.#.#.#.#...\n#.#.##...##.\n............\n............\n.###.###.###\n...#...#.#..\n.###...#.###\n...#...#...#\n.###...#.###\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_d | Problem Statement
You are given a string
S
consisting of uppercase English letters.
Find the number of integer triples
(i, j, k)
satisfying both of the following conditions:
1 \leq i < j < k \leq |S|
The length-
3
string formed by concatenating
S_i
,
S_j
, and
S_k
in this order is a palindrome.
Here,
|S|
denotes the length of
S
, and
S_x
denotes the
x
-th character of
S
. | [
{
"input": "ABCACC\n",
"output": "5\n"
},
{
"input": "OOOOOOOO\n",
"output": "56\n"
},
{
"input": "XYYXYYXYXXX\n",
"output": "75\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_e | Problem Statement
There are
N
people divided into three teams.
The people are numbered
1, 2, \ldots, N
, and the teams are numbered
1, 2, 3
. Currently, person
i
belongs to team
A_i
.
Each person has a value called
strength
; person
i
has a strength of
B_i
. The
strength
of a team is defined as the sum of the strengths of its members.
Determine whether it is possible for zero or more people to switch teams so that all teams have equal strength. If it is possible, find the minimum number of people who need to switch teams to achieve this.
You cannot create new teams other than teams
1
,
2
,
3
. | [
{
"input": "6\n1 2\n2 5\n1 5\n3 3\n1 3\n3 6\n",
"output": "2\n"
},
{
"input": "4\n1 1\n1 2\n2 3\n3 4\n",
"output": "-1\n"
},
{
"input": "3\n1 1\n2 1\n3 1\n",
"output": "0\n"
},
{
"input": "12\n2 5\n1 4\n3 3\n2 3\n3 9\n1 2\n2 2\n3 9\n2 6\n1 9\n1 1\n3 1\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_f | Problem Statement
In the nation of AtCoder, there are
N
cities numbered
1
to
N
, and
M
roads numbered
1
to
M
.
Road
i
connects cities
A_i
and
B_i
bidirectionally and has a length of
C_i
.
You are given
Q
queries to process in order. The queries are of the following two types.
1 i
: Road
i
becomes closed.
2 x y
: Print the shortest distance from city
x
to city
y
, using only roads that are not closed. If city
y
cannot be reached from city
x
, print
-1
instead.
It is guaranteed that each test case contains at most
300
queries of the first type. | [
{
"input": "3 3 5\n1 2 5\n1 3 10\n2 3 6\n2 1 3\n1 2\n2 1 3\n1 1\n2 1 3\n",
"output": "10\n11\n-1\n"
},
{
"input": "4 6 6\n2 3 1\n2 4 1\n3 4 1\n1 2 1\n1 3 1\n1 4 1\n1 4\n1 5\n1 6\n2 1 2\n2 1 3\n2 1 4\n",
"output": "-1\n-1\n-1\n"
}
] |
https://atcoder.jp/contests/abc375/tasks/abc375_g | Problem Statement
In the nation of AtCoder, there are
N
cities numbered
1
to
N
, and
M
roads numbered
1
to
M
.
Road
i
connects cities
A_i
and
B_i
bidirectionally and has a length of
C_i
.
For each
i = 1, \ldots, M
, determine whether the following two values are different.
The shortest distance from city
1
to city
N
when all roads are passable
The shortest distance from city
1
to city
N
when the
M - 1
roads other than road
i
are passable
If city
N
can be reached from city
1
in one of these cases but not the other, the two values are considered different. | [
{
"input": "3 3\n1 2 5\n1 3 10\n2 3 6\n",
"output": "No\nYes\nNo\n"
},
{
"input": "4 6\n2 3 1\n2 4 1\n3 4 1\n1 2 1\n1 3 1\n1 4 1\n",
"output": "No\nNo\nNo\nNo\nNo\nYes\n"
},
{
"input": "2 1\n1 2 1\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_a | Problem Statement
KEYENCE has a culture of addressing everyone with the suffix "-san," regardless of roles, age, or positions.
You are given a string
S
consisting of lowercase English letters.
If
S
ends with
san
, print
Yes
; otherwise, print
No
. | [
{
"input": "takahashisan\n",
"output": "Yes\n"
},
{
"input": "aokikun\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_b | Problem Statement
KEYENCE has a culture of reporting things as they are, whether good or bad.
So we want to check whether the reported content is exactly the same as the original text.
You are given two strings
S
and
T
, consisting of lowercase English letters.
If
S
and
T
are equal, print
0
; otherwise, print the position of the first character where they differ.
Here, if the
i
-th character exists in only one of
S
and
T
, consider that the
i
-th characters are different.
More precisely, if
S
and
T
are not equal, print the smallest integer
i
satisfying one of the following conditions:
1\leq i\leq |S|
,
1\leq i\leq |T|
, and
S_i\neq T_i
.
|S| < i \leq |T|
.
|T| < i \leq |S|
.
Here,
|S|
and
|T|
denote the lengths of
S
and
T
, respectively, and
S_i
and
T_i
denote the
i
-th characters of
S
and
T
, respectively. | [
{
"input": "abcde\nabedc\n",
"output": "3\n"
},
{
"input": "abcde\nabcdefg\n",
"output": "6\n"
},
{
"input": "keyence\nkeyence\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_c | Problem Statement
As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.
KEYENCE headquarters have
N
departments, and the number of people in the
i
-th department
(1\leq i\leq N)
is
K_i
.
When assigning each department to Group
A
or Group
B
, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group
A
and Group
B
do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group
A
, and the total number of people in departments assigned to Group
B
. | [
{
"input": "5\n2 3 5 10 12\n",
"output": "17\n"
},
{
"input": "2\n1 1\n",
"output": "1\n"
},
{
"input": "6\n22 25 26 45 22 31\n",
"output": "89\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_d | Problem Statement
There is a printing machine that prints line segments on the
xy
-plane by emitting a laser.
At the start of printing, the laser position is at coordinate
(0, 0)
.
When printing a line segment, the procedure below is followed.
First, move the laser position to one of the endpoints of the line segment.
One may start drawing from either endpoint.
Then, move the laser position in a straight line from the current endpoint to the other endpoint while emitting the laser.
It is not allowed to stop printing in the middle of a line segment.
When not emitting the laser, the laser position can move in any direction at a speed of
S
units per second.
When emitting the laser, the laser position can move along the line segment being printed at a speed of
T
units per second.
The time required for operations other than moving the laser position can be ignored.
Takahashi wants to print
N
line segments using this printing machine.
The
i
-th line segment connects coordinates
(A_i, B_i)
and
(C_i, D_i)
.
Some line segments may overlap, in which case he needs to print the overlapping parts for each line segment separately.
What is the minimum number of seconds required to complete printing all the line segments when he operates the printing machine optimally? | [
{
"input": "3 2 1\n1 3 2 1\n0 2 0 0\n3 0 2 0\n",
"output": "6.44317475868633722080\n"
},
{
"input": "2 1 1\n0 0 10 10\n0 2 2 0\n",
"output": "20.97056274847714058517\n"
},
{
"input": "6 3 2\n-1000 -1000 1000 1000\n1000 -1000 -1000 1000\n-1000 -1000 1000 1000\n1000 -1000 -1000 1000\n1000 1000 -1000 -1000\n-1000 1000 1000 -1000\n",
"output": "9623.35256169626864153344\n"
},
{
"input": "6 10 8\n1000 1000 -1000 -1000\n1000 -1000 -1000 -1000\n-1000 1000 1000 1000\n-1000 1000 -1000 -1000\n1000 1000 1000 -1000\n1000 -1000 -1000 1000\n",
"output": "2048.52813742385702910909\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_e | Problem Statement
The manufacturing of a certain product requires
N
processes numbered
1,2,\dots,N
.
For each process
i
, there are two types of machines
S_i
and
T_i
available for purchase to handle it.
Machine
S_i
: Can process
A_i
products per day per unit, and costs
P_i
yen per unit.
Machine
T_i
: Can process
B_i
products per day per unit, and costs
Q_i
yen per unit.
You can purchase any number of each machine, possibly zero.
Suppose that process
i
can handle
W_i
products per day as a result of introducing machines.
Here, we define the production capacity as the minimum of
W
, that is,
\displaystyle \min^{N}_{i=1} W_i
.
Given a total budget of
X
yen, find the maximum achievable production capacity. | [
{
"input": "3 22\n2 5 3 6\n1 1 3 3\n1 3 2 4\n",
"output": "4\n"
},
{
"input": "1 10000000\n100 1 100 1\n",
"output": "1000000000\n"
},
{
"input": "1 1\n1 10000000 1 10000000\n",
"output": "0\n"
},
{
"input": "10 7654321\n8 6 9 1\n5 6 4 3\n2 4 7 9\n7 8 9 1\n7 9 1 6\n4 8 9 1\n2 2 8 9\n1 6 2 6\n4 2 3 4\n6 6 5 2\n",
"output": "894742\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_f | Problem Statement
KEYENCE is famous for quick delivery.
In this problem, the calendar proceeds as Day
1
, Day
2
, Day
3
,
\dots
.
There are orders
1,2,\dots,N
, and it is known that order
i
will be placed on Day
T_i
.
For these orders, shipping is carried out according to the following rules.
At most
K
orders can be shipped together.
Order
i
can only be shipped on Day
T_i
or later.
Once a shipment is made, the next shipment cannot be made until
X
days later.
That is, if a shipment is made on Day
a
, the next shipment can be made on Day
a+X
.
For each day that passes from order placement to shipping, dissatisfaction accumulates by
1
per day.
That is, if order
i
is shipped on Day
S_i
, the dissatisfaction accumulated for that order is
(S_i - T_i)
.
Find the minimum possible total dissatisfaction accumulated over all orders when you optimally schedule the shipping dates. | [
{
"input": "5 2 3\n1 5 6 10 12\n",
"output": "2\n"
},
{
"input": "1 1 1000000000\n1000000000000\n",
"output": "0\n"
},
{
"input": "15 4 5\n1 3 3 6 6 6 10 10 10 10 15 15 15 15 15\n",
"output": "35\n"
}
] |
https://atcoder.jp/contests/abc374/tasks/abc374_g | Problem Statement
All KEYENCE product names consist of
two uppercase English letters
.
They have already used
N
product names, the
i
-th of which
(1\leq i\leq N)
is
S_i
.
Once a product name is used, it cannot be reused, so they decided to create an NG (Not Good) list to quickly identify previously used product names.
The NG list must satisfy the following conditions.
It consists of one or more strings, each consisting of uppercase English letters.
For each already used product name, there exists at least one string in the list that contains the name as a (contiguous) substring.
None of the strings in the list contain any length-
2
(contiguous) substring that is not an already used product name.
Find the minimum possible number of strings in the NG list. | [
{
"input": "7\nAB\nBC\nCA\nCD\nDE\nDF\nXX\n",
"output": "3\n"
},
{
"input": "5\nAC\nBC\nCD\nDE\nDF\n",
"output": "2\n"
},
{
"input": "6\nAB\nAC\nCB\nAD\nDB\nBA\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/ahc038/tasks/ahc038_a | Problem Statement
There is an
N \times N
takoyaki cooker.
Let
(0,0)
be the coordinates of the top-left square and
(i,j)
be the coordinates of the square located
i
squares down and
j
squares to the right from there.
Initially, takoyaki are placed on
M
different squares, and you need to move them to
M
specified target squares.
First, you must design the robotic arm.
The robotic arm is represented as a tree where the "joints" and "fingertips" are the vertices, and the rigid segments connecting them are the edges.
The fingertips correspond to the leaves of the tree, while the joints correspond to the other vertices.
The length of the edge connecting vertex
u
and its child
v
is denoted as
L(u,v)
.
You are given the number of vertices
V
available for the robotic arm, and your task is to design a tree with no more than
V
vertices and output it along with the initial position of the root.
The length of each edge
L(u,v)
must be an integer satisfying
1 \leq L(u,v) \leq N-1
.
Next, you must operate the designed robotic arm to move the takoyaki.
Starting from the initial position where the root is at the specified position and all edges extend to the right, you can perform the following operations independently each turn:
You can move the entire robotic arm one square up, down, left, or right. The new coordinates of the root
(x,y)
must satisfy
0 \leq x, y \leq N-1
.
For each vertex
u
other than the root, you can independently rotate the entire subtree rooted at
u
by 90 degrees either counterclockwise or clockwise around its parent
p
.
For each fingertip, you can independently place the takoyaki it is holding on the current square, or pick up a takoyaki from the current square. You cannot place a takoyaki on a square that already contains one or outside the
N \times N
grid. Each fingertip cannot hold more than one takoyaki at the same time.
Example of Operation 2
➡
➡
Starting from the left figure, rotating the entire subtree rooted at vertex 1 by 90 degrees clockwise around vertex 0 results in the middle figure.
Furthermore, rotating the entire subtree rooted at vertex 3 by 90 degrees clockwise around vertex 1 results in the right figure.
Operations are performed in the order of 1 and 2 first, followed by 3.
In operation 3, the fingertips are processed in order from the smallest vertex number to the largest (the order within 1 and 2 does not affect the result).
It is allowed for part of the robotic arm to extend outside the
N \times N
grid after an operation, and multiple vertices of the robotic arm can occupy the same square.
You can perform up to
10^5
turns. | [
{
"input": "4 3 4\n0000\n1010\n0000\n0100\n0100\n0001\n1000\n0000\n",
"output": "4\n0 1\n1 1\n1 2\n0 0\nRRL...PP\nR..R..P.\nDRR...P.\nD.....PP\n"
}
] |
https://atcoder.jp/contests/agc068/tasks/agc068_a | Problem Statement
There is a circle with circumference
L
, and
L
people are standing equally spaced along the circumference.
They are labeled as person
0, 1, \cdots, L-1
in clockwise order.
Consider choosing
N
from these
L
people.
The
cost
of a choice is defined as follows.
For every pair of persons among the
N
chosen people, find the minimum distance one person has to move along the circumference to reach the other person's position.
The maximum value among these distances is the cost.
Find the sum of costs over all possible choices, modulo
998244353
. | [
{
"input": "4 2\n",
"output": "8\n"
},
{
"input": "5 5\n",
"output": "2\n"
},
{
"input": "13 5\n",
"output": "7618\n"
},
{
"input": "1000000 100000\n",
"output": "664396470\n"
}
] |
https://atcoder.jp/contests/agc068/tasks/agc068_b | Problem Statement
A pair of strings
(S, T)
consisting of
0
and
1
is called
good
if and only if all of the following conditions are satisfied.
S
and
T
contain the same number of
0
s.
S
and
T
contain the same number of
1
s.
Particularly, for a good string pair
(S, T)
,
S
and
T
have the same length.
For a good string pair
(S, T)
, we define an undirected graph
G(S, T)
as follows.
Let
L
be the length of
S
. Create a graph
g
with vertices
1, 2, \cdots, L
.
Let
n
be the number of
0
s in
S
. Let the indices of
0
s in
S
be
1 \leq a_1 < a_2 < \cdots < a_n \leq L
. Let the indices of
0
s in
T
be
1 \leq b_1 < b_2 < \cdots < b_n \leq L
. For each
1 \leq i \leq n
, add an edge between vertices
a_i
and
b_i
to
g
.
Let
m
be the number of
1
s in
S
. Let the indices of
1
s in
S
be
1 \leq c_1 < c_2 < \cdots < c_m \leq L
. Let the indices of
1
s in
T
be
1 \leq d_1 < d_2 < \cdots < d_m \leq L
. For each
1 \leq i \leq m
, add an edge between vertices
c_i
and
d_i
to
g
.
The graph
g
obtained through the above steps is
G(S, T)
.
You are given an integer sequence
A = (A_1, A_2, \cdots, A_N)
of length
N
.
Find one good string pair
(S, T)
satisfying all of the following conditions.
Let
L
be the length of
S
. It satisfies
N \leq L \leq 10^5
.
For each pair
1 \leq i, j \leq N
, vertices
i
and
j
belong to the same connected component in
G(S, T)
if and only if
A_i = A_j
.
It can be proved that a solution always exists under the constraints of this problem. | [
{
"input": "3\n1 2 1\n",
"output": "4\n0011\n1100\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "5\n01010\n01010\n"
},
{
"input": "6\n1 1 1 1 1 1\n",
"output": "6\n011111\n111110\n"
},
{
"input": "10\n1 2 3 2 4 3 4 4 5 6\n",
"output": "21\n000101010111100011011\n011010000010101111110\n"
}
] |
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 47