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
... | [
{
"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
.
Spec... | [
{
"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 or... | [
{
"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,... | [
{
"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 p... | [
{
"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 i... | [
{
"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... | [
{
"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 ... | [
{
"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... |
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:
Takahas... | [
{
"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} ... | [
{
"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)... | [
{
"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
... | [
{
"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 performe... | [
{
"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. ... | [
{
"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 t... | [
{
"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... | [
{
"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
t... | [
{
"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... | [
{
"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 a... | [
{
"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... | [
{
"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
.... | [
{
"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... | [
{
"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
.... | [
{
"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
,... | [
{
"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 ... | [
{
"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 lengt... | [
{
"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)... | [
{
"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... | [
{
"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
... | [
{
"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 ... | [
{
"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
... | [
{
"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 12345... |
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 cell... | [
{
"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, b... | [
{
"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_... | [
{
"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 ... | [] |
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 ... | [
{
"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... | [
{
"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 he... | [
{
"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}^... | [
{
"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)
, ... | [
{
"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... | [
{
"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... | [
{
"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 posit... | [
{
"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 ... | [
{
"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 remai... | [
{
"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.
A... | [
{
"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
.
The... | [
{
"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... | [
{
"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
wit... | [
{
"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, ... | [
{
"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}... | [
{
"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 sequen... | [
{
"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,... | [
{
"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..#....... |
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\le... | [
{
"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 complet... | [
{
"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 ... |
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\... | [
{
"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 ... | [
{
"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
an... | [
{
"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... | [
{
"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... | [
{
"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
an... | [
{
"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, e... | [
{
"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 t... | [
{
"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 t... | [
{
"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 ... | [
{
"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 ... | [
{
"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 ... |
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, tha... | [
{
"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... |
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 af... | [
{
"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.... |
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 le... | [
{
"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... | [
{
"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 ... | [
{
"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
wh... | [
{
"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 posit... | [
{
"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 departme... | [
{
"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.
... | [
{
"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 ... |
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
pr... | [
{
"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... |
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 sh... | [
{
"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.
... | [
{
"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 s... | [
{
"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 ... | [
{
"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... | [
{
"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\n0110100000... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 19