url stringlengths 49 92 | description stringlengths 22 4.78k | cases listlengths 0 6 |
|---|---|---|
https://atcoder.jp/contests/abc305/tasks/abc305_a | Problem Statement
There is an ultramarathon course totaling
100\;\mathrm{km}
.
Water stations are set up every
5\;\mathrm{km}
along the course, including the start and goal, for a total of
21
.
Takahashi is at the
N\;\mathrm{km}
point of this course.
Find the position of the nearest water station to him.
Under the co... | [
{
"input": "53\n",
"output": "55\n"
},
{
"input": "21\n",
"output": "20\n"
},
{
"input": "100\n",
"output": "100\n"
}
] |
https://atcoder.jp/contests/abc305/tasks/abc305_b | Problem Statement
There are
7
points
A
,
B
,
C
,
D
,
E
,
F
, and
G
on a straight line, in this order. (See also the figure below.)
The distances between adjacent points are as follows.
Between
A
and
B
:
3
Between
B
and
C
:
1
Between
C
and
D
:
4
Between
D
and
E
:
1
Between
E
and
F
:
5
Between
F
and
G
:
9
You are given t... | [
{
"input": "A C\n",
"output": "4\n"
},
{
"input": "G B\n",
"output": "20\n"
},
{
"input": "C F\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/abc305/tasks/abc305_c | Problem Statement
There is a grid with
H
rows and
W
columns. Let
(i, j)
denote the square at the
i
-th row from the top and the
j
-th column from the left.
Initially, there was one cookie on each square inside a rectangle whose
height and width were at least
2
squares long
, and no cookie on the other squares.
Formally... | [
{
"input": "5 6\n......\n..#.#.\n..###.\n..###.\n......\n",
"output": "2 4\n"
},
{
"input": "3 2\n#.\n##\n##\n",
"output": "1 2\n"
},
{
"input": "6 6\n..####\n..##.#\n..####\n..####\n..####\n......\n",
"output": "2 5\n"
}
] |
https://atcoder.jp/contests/abc305/tasks/abc305_d | Problem Statement
Takahashi keeps a sleep log.
The log is represented as an odd-length sequence
A=(A _ 1(=0), A _ 2,\ldots,A _ N)
, where odd-numbered elements represent times he got up, and even-numbered elements represent times he went to bed.
More formally, he had the following sleep sessions after starting the sl... | [
{
"input": "7\n0 240 720 1320 1440 1800 2160\n3\n480 1920\n720 1200\n0 2160\n",
"output": "480\n0\n960\n"
},
{
"input": "21\n0 20 62 192 284 310 323 324 352 374 409 452 486 512 523 594 677 814 838 946 1000\n10\n77 721\n255 541\n478 970\n369 466\n343 541\n42 165\n16 618\n222 592\n730 983\n338 747\n",... |
https://atcoder.jp/contests/abc305/tasks/abc305_e | Problem Statement
There is a simple undirected graph with
N
vertices and
M
edges, where vertices are numbered from
1
to
N
, and edges are numbered from
1
to
M
. Edge
i
connects vertex
a_i
and vertex
b_i
.
K
security guards numbered from
1
to
K
are on some vertices. Guard
i
is on vertex
p_i
and has a stamina of
h_i
. Al... | [
{
"input": "5 5 2\n1 2\n2 3\n2 4\n3 5\n1 5\n1 1\n5 2\n",
"output": "4\n1 2 3 5\n"
},
{
"input": "3 0 1\n2 3\n",
"output": "1\n2\n"
},
{
"input": "10 10 2\n2 1\n5 1\n6 1\n2 4\n2 5\n2 10\n8 5\n8 6\n9 6\n7 9\n3 4\n8 2\n",
"output": "7\n1 2 3 5 6 8 9\n"
}
] |
https://atcoder.jp/contests/abc305/tasks/abc305_f | Problem Statement
This is an
interactive problem
(where your program and the judge program interact through Standard Input and Output).
There is a simple connected undirected graph with
N
vertices and
M
edges.
The vertices are numbered with integers from
1
to
N
.
Initially, you are at vertex
1
.
Repeat moving to an a... | [] |
https://atcoder.jp/contests/abc305/tasks/abc305_g | Problem Statement
You are given a set
S=\lbrace s _ 1,s _ 2,\ldots,s _ M\rbrace
of non-empty strings of length at most
6
consisting of
a
and
b
.
Find the number of strings
T
of length
N
consisting of
a
and
b
that satisfy the following condition:
T
does not contain
s _ i
as a consecutive substring for any
s _ i\in S
.
... | [
{
"input": "4 3\naab\nbbab\nabab\n",
"output": "10\n"
},
{
"input": "20 1\naa\n",
"output": "17711\n"
},
{
"input": "1000000007 28\nbbabba\nbbbbaa\naabbab\nbbbaba\nbaaabb\nbabaab\nbbaaba\naabaaa\naaaaaa\naabbaa\nbbaaaa\nbbaabb\nbbabab\naababa\nbaaaba\nababab\nabbaba\naabaab\nababaa\nabbb... |
https://atcoder.jp/contests/abc305/tasks/abc305_h | Problem Statement
You have decided to
practice
. Practice means solving a large number of problems in AtCoder.
Practice takes place over several days. The practice for one day is carried out in the following steps.
Let
M
be the number of problems to be solved on that day. Each problem has a value called
difficulty
, wh... | [
{
"input": "3 100\n2 2\n3 4\n5 7\n",
"output": "1 52\n"
},
{
"input": "3 30\n2 2\n3 4\n5 7\n",
"output": "2 17\n"
},
{
"input": "5 50000000\n100000 10000000\n100000 10000000\n100000 10000000\n100000 10000000\n100000 10000000\n",
"output": "5 50000000\n"
},
{
"input": "10 1000... |
https://atcoder.jp/contests/abc304/tasks/abc304_a | Problem Statement
There are
N
people numbered
1, 2, \ldots, N
, sitting in this clockwise order around a round table.
In particular, person
1
is sitting next to person
N
in the clockwise direction.
For each
i = 1, 2, \ldots, N
, person
i
has a name
S_i
and an age
A_i
.
Here, no two people have the same name or the sa... | [
{
"input": "5\nalice 31\nbob 41\ncarol 5\ndave 92\nellen 65\n",
"output": "carol\ndave\nellen\nalice\nbob\n"
},
{
"input": "2\ntakahashi 1000000000\naoki 999999999\n",
"output": "aoki\ntakahashi\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_b | Problem Statement
You are given an integer
N
.
Print an approximation of
N
according to the following instructions.
If
N
is less than or equal to
10^3-1
, print
N
as it is.
If
N
is between
10^3
and
10^4-1
, inclusive, truncate the ones digit of
N
and print the result.
If
N
is between
10^4
and
10^5-1
, inclusive, trunca... | [
{
"input": "20230603\n",
"output": "20200000\n"
},
{
"input": "0\n",
"output": "0\n"
},
{
"input": "304\n",
"output": "304\n"
},
{
"input": "500600\n",
"output": "500000\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_c | Problem Statement
There are
N
people numbered
1, 2, \ldots, N
on a two-dimensional plane, and person
i
is at the point represented by the coordinates
(X_i,Y_i)
.
Person
1
has been infected with a virus. The virus spreads to people within a distance of
D
from an infected person.
Here, the distance is defined as the Eucl... | [
{
"input": "4 5\n2 -1\n3 1\n8 8\n0 5\n",
"output": "Yes\nYes\nNo\nYes\n"
},
{
"input": "3 1\n0 0\n-1000 -1000\n1000 1000\n",
"output": "Yes\nNo\nNo\n"
},
{
"input": "9 4\n3 2\n6 -1\n1 6\n6 5\n-2 -3\n5 3\n2 -3\n2 1\n2 6\n",
"output": "Yes\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_d | Problem Statement
There is a rectangular cake with some strawberries on the
xy
-plane. The cake occupies the rectangular area
\lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace
.
There are
N
strawberries on the cake, and the coordinates of the
i
-th strawberry are
(p_i, q_i)
for
i = 1, 2, \ldots, N
. No two stra... | [
{
"input": "7 6\n5\n6 1\n3 1\n4 2\n1 5\n6 2\n2\n2 5\n2\n3 4\n",
"output": "0 2\n"
},
{
"input": "4 4\n4\n1 1\n3 1\n3 3\n1 3\n1\n2\n1\n2\n",
"output": "1 1\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_e | Problem Statement
You are given an undirected graph
G
with
N
vertices and
M
edges.
For
i = 1, 2, \ldots, M
, the
i
-th edge is an undirected edge connecting vertices
u_i
and
v_i
.
A graph with
N
vertices is called
good
if the following condition holds for all
i = 1, 2, \ldots, K
:
there is no path connecting vertices
... | [
{
"input": "6 6\n1 2\n2 3\n2 3\n3 1\n5 4\n5 5\n3\n1 5\n2 6\n4 3\n4\n2 5\n2 6\n5 6\n5 4\n",
"output": "No\nNo\nYes\nYes\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_f | Problem Statement
Takahashi and Aoki will work part-time for the next
N
days.
Takahashi's shift schedule is given by the string
S
, where the
i
-th character of
S
is
#
if he works on the
i
-th day, and
.
if he is absent on the
i
-th day.
Based on this, Aoki created his shift schedule as follows.
First, take a positive ... | [
{
"input": "6\n##.#.#\n",
"output": "3\n"
},
{
"input": "7\n...####\n",
"output": "1\n"
},
{
"input": "12\n####.####.##\n",
"output": "19\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_g | Problem Statement
You are given a sequence of length
2N
:
A = (A_1, A_2, \ldots, A_{2N})
.
Find the maximum value that can be obtained as the median of the length-
N
sequence
(A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N})
by rearranging the elements of the sequence
A
.
Here,
\oplus
represents bitwise ... | [
{
"input": "4\n4 0 0 11 2 7 9 5\n",
"output": "14\n"
},
{
"input": "1\n998244353 1000000007\n",
"output": "1755654\n"
},
{
"input": "5\n1 2 4 8 16 32 64 128 256 512\n",
"output": "192\n"
}
] |
https://atcoder.jp/contests/abc304/tasks/abc304_h | Problem Statement
You are given a directed graph with
N
vertices and
M
edges.
For
i = 1, 2, \ldots, M
, the
i
-th edge is directed from vertex
s_i
to vertex
t_i
.
Determine whether there is a permutation
P = (P_1, P_2, \ldots, P_N)
of
(1, 2, \ldots, N)
that satisfies both of the following conditions, and if there is, ... | [
{
"input": "5 4\n1 5\n2 1\n2 5\n4 3\n1 5\n1 3\n3 4\n1 3\n4 5\n",
"output": "Yes\n3 1 4 2 5\n"
},
{
"input": "2 2\n1 2\n2 1\n1 2\n1 2\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_a | Problem Statement
Takahashi participated in a contest. He made
A
wrong submissions before being accepted
T
minutes into the contest.
Compute the penalty value represented by the following expression:
5\times A + T. | [
{
"input": "3 10\n",
"output": "25\n"
},
{
"input": "1 8\n",
"output": "13\n"
},
{
"input": "0 10\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_b | Problem Statement
In AtCoder, the programming contest hosting website, those whose maximum rating is
2800
or greater is in the "hall of fame".
Takahashi's current rating is
C
and the maximum rating is
H
.
Print
o
if he is in the "hall of fame", and
x
otherwise. | [
{
"input": "3085 3085\n",
"output": "o\n"
},
{
"input": "2580 2631\n",
"output": "x\n"
},
{
"input": "0 2800\n",
"output": "o\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_c | Problem Statement
On a two-dimensional plane, there is a circle of radius
R
centered at point
(X, Y)
.
For an integer pair
(i, j)
, let us define
S_{i,j} =
#
if point
(i, j)
is in the interior or on the circumference of the circle, and
S_{i,j} =
.
otherwise.
Print
S_{i,j}
for all integer pairs
(i, j)
such that
-N \leq ... | [
{
"input": "1 -2 1 3\n",
"output": ". . . . . . .\n. . . . . . .\n. . . . . . .\n. # . . . . .\n# # # . . . .\n. # . . . . .\n. . . . . . .\n"
},
{
"input": "-3 1 4 8\n",
"output": ". . . . . . . . . . . . . . . . .\n. . . . . . . . . # . . . . . . .\n. . . . . . . # # # # # . . . . .\n. . . . .... |
https://atcoder.jp/contests/past15-open/tasks/past202306_d | Problem Statement
Takahashi is trying to record a certain television program (hereafter called "the program") with a recorder.
At time
0
, the program is scheduled to be broadcasted from time
A
to time
A + R
. However, the broadcast time of the program may change due to programming circumstances. Therefore, Takahashi h... | [
{
"input": "5 3 15 20 20\n",
"output": "Yes\n"
},
{
"input": "5 3 27 30 20\n",
"output": "No\n"
},
{
"input": "930 542 605 509 582\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_e | Problem Statement
In a certain programming contest,
N
problems are set, and if you answer the
i
-th problem correctly, you are given
A_i
points.
Consider choosing and solving exactly
K
problems out of these
N
problems.
When you calculate the "total score obtained when all the selected problems are solved" for all ways ... | [
{
"input": "4 2\n100 200 300 400\n",
"output": "3000\n"
},
{
"input": "1 1\n2718\n",
"output": "2718\n"
},
{
"input": "8 4\n597 1035 2048 994 1843 601 7 659\n",
"output": "272440\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_f | Problem Statement
Given a sequence
A
of length
N
, find a sequence
B
that satisfies all of the following conditions.
We can prove that this sequence
B
is unique.
B
is a sequence obtained by rearranging
(1,2,...,N)
.
For all integer pairs
(i,j)(i \neq j)
, the following conditions are satisfied:
if
A_i<A_j
, then
B_i<B_... | [
{
"input": "10\n2 3 4 4 4 4 3 3 2 1\n",
"output": "2 4 7 8 9 10 5 6 3 1\n"
},
{
"input": "1\n1000000000\n",
"output": "1\n"
},
{
"input": "20\n30 10 40 10 50 90 20 60 50 30 50 80 90 70 90 30 20 30 80 40\n",
"output": "5 1 9 2 11 18 3 14 12 6 13 16 19 15 20 7 4 8 17 10\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_g | Problem Statement
Determine if there is a way to assign
0
or
1
to each of
N
variables
x_1,x_2,\ldots,x_N
so that:
for all
i=1,2,\ldots,M
,
there exists an integer
j (1 \leq j \leq k_i)
such that
x_{a_{i,j}}=b_{i,j}
. | [
{
"input": "5 3\n1\n4 0\n1\n5 0\n2\n2 0\n3 1\n",
"output": "Yes\n"
},
{
"input": "1 2\n1\n1 0\n1\n1 1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_h | Problem Statement
When you represent an integer
N
as the sum of one or more distinct positive integers, at most how many positive integers can be used? | [
{
"input": "7\n",
"output": "3\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "164312478120341038\n",
"output": "573258192\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_i | Problem Statement
You are given
N
integers
A_1, A_2, \ldots, A_N
.
Consider choosing
K
of them. Find the maximum possible greatest common divisor of the chosen integers. | [
{
"input": "3 2\n2 3 4\n",
"output": "2\n"
},
{
"input": "3 3\n5 5 5\n",
"output": "5\n"
},
{
"input": "10 4\n225707 265514 765350 617700 837712 187034 799142 35549 784661 961512\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_j | Problem Statement
A ninja will fight against
N
monsters one by one in order. The attack power of the
i
-th monster is
a_i
, and its health is
b_i
. A monster is immediately defeated when its health becomes
0
or less.
Each monster is either on the ground or flying. If
x_i = 0
, the
i
-th monster is on the ground, and if... | [
{
"input": "2 1\n2 2 1\n5 2 0\n",
"output": "4\n"
},
{
"input": "1 2\n1 4 1\n",
"output": "1\n"
},
{
"input": "4 3\n5 4 1\n6 2 0\n4 5 1\n3 2 0\n",
"output": "25\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_k | Problem Statement
There is a sequence of length
N
,
P=(P_1,P_2,\ldots,P_N)
, which is a permutation of
(1,2,\ldots,N)
.
You can perform the following operation on this sequence any number of times, possibly zero:
Choose an integer
i
between
1
and
N-1
, inclusive, and swap the
i
-th element and the
(i+1)
-th element of
... | [
{
"input": "4\n3 2 1 4\n",
"output": "12\n"
},
{
"input": "9\n3 1 4 5 9 2 6 8 7\n",
"output": "96\n"
},
{
"input": "6\n1 2 3 4 5 6\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_l | Problem Statement
You are given an
H
-by-
W
matrix
A
consisting of non-negative integers.
You can perform the following operations any number of times (possibly zero):
Choose an integer
i
satisfying
1 \le i \le H
and a non-negative integer
X
, and replace each element
A_{i,j}
in the
i
-th row of the matrix
A
with
A_{i,... | [
{
"input": "2 2\n1 2\n3 4\n-1 3\n1 7\n",
"output": "Yes\n"
},
{
"input": "2 2\n1 2\n3 4\n5 3\n1 7\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_m | Problem Statement
There are
N
points on a number line, numbered from
1
to
N
. The
N
points satisfy the following condition:
The distance between point
i
and point
i+1
is
d_i
.
(1 \leq i \leq N - 1)
Find the minimum possible distance between point
1
and point
N
. | [
{
"input": "4\n5 2 4\n",
"output": "1\n"
},
{
"input": "10\n314 159 265 358 979 323 846 264 338\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_n | Problem Statement
There are
N
real numbers
x_1,\ldots,x_N
between
0
(inclusive) and
M
(exclusive).
Among these
N
numbers, it is known that there are
C_k
numbers between
k
(inclusive) and
k+1
(exclusive) for
k=0,1,\ldots,M-1
.
You are curious about how small the absolute difference between the median and the mean of
x_1... | [
{
"input": "3 3\n0 1 2\n",
"output": "0.0\n"
},
{
"input": "4 5\n2 1 0 0 1\n",
"output": "0.25\n"
},
{
"input": "10 10\n1 0 0 0 0 0 0 0 0 9\n",
"output": "0.4\n"
}
] |
https://atcoder.jp/contests/past15-open/tasks/past202306_o | Problem Statement
You are given integers
N
,
A
, and
B
. Solve the following problem.
An arithmetic sequence
S = (S_1, S_2, \dots, S_N)
of length
N
is defined as
S_i = A \times (i - 1) + B
.
Find the number of prime numbers in
S
. | [
{
"input": "10 3 4\n",
"output": "4\n"
},
{
"input": "99 1 2\n",
"output": "25\n"
},
{
"input": "314159 265358 499999999999\n",
"output": "23166\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_a | Problem Statement
Let
N
be a positive
odd
number.
A sequence of integers of length
N
,
S = (S_1, S_2, \dots, S_N)
, is said to be
M-type
if "for each even number
i = 2, 4, \dots, N - 1
, it holds that
S_{i-1} < S_i
and
S_i > S_{i+1}
".
You are given a sequence of positive integers of length
N
,
A = (A_1, A_2, \dots, A... | [
{
"input": "5\n1 2 3 4 5\n",
"output": "Yes\n"
},
{
"input": "5\n1 6 1 6 1\n",
"output": "Yes\n"
},
{
"input": "5\n1 6 6 6 1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_b | Problem Statement
For a positive integer
X
, let
f(X)
be the number of
1
s that appear when
X
is represented in binary notation.
For example,
6 = 110_{(2)}, \ 11 = 1011_{(2)}, \ 16 = 10000_{(2)}
, so
f(6) = 2, \ f(11) = 3, \ f(16) = 1
.
You are given a positive integer
N
.
Determine whether there is a positive intege... | [
{
"input": "4\n16\n161\n4\n1000000000000000000\n",
"output": "14\n161\n-1\n936748722493063168\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_c | Problem Statement
You are given a tree with
N
vertices.
The vertices are labeled from
1
to
N
, and the
i
-th edge connects vertex
A_i
and vertex
B_i
.
Moreover, for every vertex, the
number of incident edges is odd
.
You will color each vertex of the given tree either black (
B
) or white (
W
).
Here, the string obt... | [
{
"input": "2\n4\n1 2\n1 3\n1 4\nBWWW\n4\n1 2\n1 3\n1 4\nBBWW\n",
"output": "WBBW\n-1\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_d | Problem Statement
We define the
density
of a non-empty simple undirected graph as
\displaystyle\frac{(\text{number\ of\ edges})}{(\text{number\ of\ vertices})}
.
You are given positive integers
N
and
D
. Determine whether there is a simple undirected graph
G
with
N
vertices and
DN
edges that satisfies the following con... | [
{
"input": "3 1\n",
"output": "Yes\n1 2\n1 3\n2 3\n"
},
{
"input": "4 2\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_e | Problem Statement
You are given a connected simple undirected graph with
N
vertices and
\displaystyle\frac{3}{2}N
edges, where
N
is a positive
even number
.
The vertices are labeled from
1
to
N
, and the
i
-th edge connects vertex
A_i
and vertex
B_i
.
Moreover, for every vertex, the
number of incident edges is exact... | [
{
"input": "2\n4\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n10\n1 2\n1 3\n1 4\n2 3\n2 4\n3 5\n4 5\n5 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10\n",
"output": "BWWW\nBWWWBWWWBB\n"
}
] |
https://atcoder.jp/contests/arc161/tasks/arc161_f | Problem Statement
We define the
density
of a non-empty simple undirected graph as
\displaystyle\frac{(\text{number\ of\ edges})}{(\text{number\ of\ vertices})}
.
You are given positive integers
N
,
D
, and a simple undirected graph
G
with
N
vertices and
DN
edges.
The vertices of
G
are numbered from
1
to
N
, and the
i
... | [
{
"input": "2\n3 1\n1 2\n1 3\n2 3\n4 1\n1 2\n1 3\n2 3\n3 4\n",
"output": "Yes\nNo\n"
}
] |
https://atcoder.jp/contests/abc303/tasks/abc303_a | Problem Statement
Two characters
x
and
y
are called similar characters if and only if one of the following conditions is satisfied:
x
and
y
are the same character.
One of
x
and
y
is
1
and the other is
l
.
One of
x
and
y
is
0
and the other is
o
.
Two strings
S
and
T
, each of length
N
, are called similar strings if and... | [
{
"input": "3\nl0w\n1ow\n",
"output": "Yes\n"
},
{
"input": "3\nabc\narc\n",
"output": "No\n"
},
{
"input": "4\nnok0\nn0ko\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc303/tasks/abc303_b | Problem Statement
N
people numbered
1,2,\ldots,N
were in
M
photos. In each of the photos, they stood in a single line. In the
i
-th photo, the
j
-th person from the left is person
a_{i,j}
.
Two people who did not stand next to each other in any of the photos may be in a bad mood.
How many pairs of people may be in a ... | [
{
"input": "4 2\n1 2 3 4\n4 3 1 2\n",
"output": "2\n"
},
{
"input": "3 3\n1 2 3\n3 1 2\n1 2 3\n",
"output": "0\n"
},
{
"input": "10 10\n4 10 7 2 8 3 9 1 6 5\n3 6 2 9 1 8 10 7 4 5\n9 3 4 5 7 10 1 8 2 6\n7 3 1 8 4 9 5 6 2 10\n5 2 1 4 10 7 9 8 3 6\n5 8 1 6 9 3 2 4 7 10\n8 10 3 4 5 7 2 9 6 1... |
https://atcoder.jp/contests/abc303/tasks/abc303_c | Problem Statement
On a two-dimensional plane, Takahashi is initially at point
(0, 0)
, and his initial health is
H
.
M
items to recover health are placed on the plane; the
i
-th of them is placed at
(x_i,y_i)
.
Takahashi will make
N
moves. The
i
-th move is as follows.
Let
(x,y)
be his current coordinates. He consume... | [
{
"input": "4 2 3 1\nRUDL\n-1 -1\n1 0\n",
"output": "Yes\n"
},
{
"input": "5 2 1 5\nLDRLD\n0 0\n-1 -1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc303/tasks/abc303_d | Problem Statement
Your computer has a keyboard with three keys: 'a' key, Shift key, and Caps Lock key. The Caps Lock key has a light on it.
Initially, the light on the Caps Lock key is off, and the screen shows an empty string.
You can do the following three actions any number of times in any order:
Spend
X
millisecon... | [
{
"input": "1 3 3\nAAaA\n",
"output": "9\n"
},
{
"input": "1 1 100\naAaAaA\n",
"output": "6\n"
},
{
"input": "1 2 4\naaAaAaaAAAAaAaaAaAAaaaAAAAA\n",
"output": "40\n"
}
] |
https://atcoder.jp/contests/abc303/tasks/abc303_e | Problem Statement
A graph with
(k+1)
vertices and
k
edges is called a level-
k\ (k\geq 2)
star if and only if:
it has a vertex that is connected to each of the other
k
vertices with an edge, and there are no other edges.
At first, Takahashi had a graph consisting of stars. He repeated the following operation until eve... | [
{
"input": "6\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"output": "2 2\n"
},
{
"input": "9\n3 9\n7 8\n8 6\n4 6\n4 1\n5 9\n7 3\n5 2\n",
"output": "2 2 2\n"
},
{
"input": "20\n8 3\n8 18\n2 19\n8 20\n9 17\n19 7\n8 7\n14 12\n2 15\n14 10\n2 13\n2 16\n2 1\n9 5\n10 15\n14 6\n2 4\n2 11\n5 12\n",
"output"... |
https://atcoder.jp/contests/abc303/tasks/abc303_f | Problem Statement
A monster with health
H
has appeared in front of you, and a turn-based battle has started.
In each turn
1,2,…
, you cast one of
N
spells, spells
1,…,N
.
If you cast spell
i
in turn
j
, the monster's health reduces by
d_i
in each turn
j,j+1,…,j+t_i -1
.
Find the earliest turn that you can make the mons... | [
{
"input": "2 20\n2 2\n5 1\n",
"output": "6\n"
},
{
"input": "10 200\n1 21\n1 1\n1 1\n8 4\n30 1\n3 1\n10 2\n8 1\n9 1\n4 4\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc303/tasks/abc303_g | Problem Statement
N
bags are arranged in a row. The
i
-th bag contains
x_i
yen (the currency in Japan).
Takahashi and Aoki, who have sufficient money, take alternating turns to perform the following action:
choose one of the following three actions and perform it.
choose the leftmost or rightmost bag and take it.
pay
... | [
{
"input": "5 10 2 1000000000 1\n1 100 1 1 1\n",
"output": "90\n"
},
{
"input": "10 45 3 55 4\n5 10 15 20 25 30 35 40 45 50\n",
"output": "85\n"
},
{
"input": "15 796265 10 165794055 1\n18804175 185937909 1934689 18341 68370722 1653 1 2514380 31381214 905 754483 11 5877098 232 31600\n",
... |
https://atcoder.jp/contests/abc303/tasks/abc303_h | Problem Statement
You are given an integer
N
and a set
S=\lbrace S_1,S_2,\ldots,S_K\rbrace
consisting of integers between
1
and
N-1
.
Find the number, modulo
998244353
, of trees
T
with
N
vertices numbered
1
through
N
such that:
d_i\in S
for all
i\ (1\leq i \leq N)
, where
d_i
is the degree of vertex
i
in
T
. | [
{
"input": "4 2\n1 3\n",
"output": "4\n"
},
{
"input": "10 5\n1 2 3 5 6\n",
"output": "68521950\n"
},
{
"input": "100 5\n1 2 3 14 15\n",
"output": "888770956\n"
}
] |
https://atcoder.jp/contests/agc062/tasks/agc062_a | Problem Statement
For a string
T=T_1T_2\dots T_n
of length
n\ (2\leq n)
consisting of
A
and
B
, we define a string
f(T)
of length
n-1
as follows.
Let
a_1 < a_2 < \dots < a_{m}
be the indices
i\ (1\leq i \leq n-1)
such that
T_i={}
A
, and
b_1 < b_2 < \dots < b_k
be the indices
i\ (1\leq i \leq n-1)
such that
T_i={}
B
. ... | [
{
"input": "3\n2\nAB\n3\nAAA\n4\nABAB\n",
"output": "B\nA\nA\n"
}
] |
https://atcoder.jp/contests/agc062/tasks/agc062_b | Problem Statement
There is a permutation
A=(A_1,A_2,\dots,A_N)
of the integers from
1
to
N
. Initially, we have
A_i=i\ (1\leq i \leq N)
.
Takahashi will perform the following operation on this sequence
K
times.
Choose an integer
k
such that
0 \leq k < N
. Take the last
k
terms of
A
and insert them among the first
N-k
.... | [
{
"input": "4 1\n3\n3 1 2 4\n",
"output": "6\n"
},
{
"input": "4 1\n3\n4 3 2 1\n",
"output": "-1\n"
},
{
"input": "20 10\n874735445 684260477 689935252 116941558 915603029 923404262 843759669 656978932 286318130 255195090\n11 15 20 10 6 8 18 2 12 4 9 13 19 3 16 7 14 17 5 1\n",
"outpu... |
https://atcoder.jp/contests/agc062/tasks/agc062_c | Problem Statement
You are given an integer sequence of length
N
:
A=(A_1,A_2,\dots,A_N)
.
Find the
K
smallest positive integers
X
that satisfy the following condition.
There is
no
non-empty (not necessarily contiguous) subsequence of
A
whose elements sum to
X
. | [
{
"input": "3 3\n1 2 5\n",
"output": "4 9 10\n"
},
{
"input": "20 10\n324 60 1 15 60 15 1 60 319 1 327 1 2 60 2 345 1 2 2 15\n",
"output": "14 29 44 59 74 89 104 119 134 149\n"
}
] |
https://atcoder.jp/contests/agc062/tasks/agc062_d | Problem Statement
Takahashi, with a notepad, is standing at the origin
(0,0)
of a two-dimensional plane. His notepad has
N
even numbers
D_i\ (1\leq i \leq N)
written.
Takahashi will perform the following actions
N
times on the plane.
He chooses and erases one even number written on the notepad. Let
d
be the chosen even... | [
{
"input": "3\n2 4 6\n",
"output": "4\n"
},
{
"input": "5\n2 2 2 2 6\n",
"output": "3\n"
},
{
"input": "2\n2 200000\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/agc062/tasks/agc062_e | Problem Statement
You are given an
odd
number
N
and a non-negative integer
K
.
Find the number, modulo
998244353
, of sequences of integer pairs
((L_1,R_1),(L_2,R_2),\dots,(L_N,R_N))
satisfying all of the following conditions.
(L_1,R_1,L_2,R_2,\dots,L_N,R_N)
is a permutation of the integers from
1
to
2N
.
L_1 \leq L_2 ... | [
{
"input": "3 1\n",
"output": "2\n"
},
{
"input": "1 0\n",
"output": "0\n"
},
{
"input": "521 400\n",
"output": "0\n"
},
{
"input": "199999 2023\n",
"output": "283903125\n"
}
] |
https://atcoder.jp/contests/agc062/tasks/agc062_f | Problem Statement
There are
N
decks of cards, each card in which has an integer between
1
and
M
, inclusive, written on it. The
i
-th deck
(1\leq i \leq N)
contains
K_i
cards, and the number written on the
j
-th card from the top is
A_{i,j}\ (1\leq j \leq K_i)
.
Initially, the integers written on the cards satisfy the ... | [
{
"input": "2 4\n4 1 2 3 4\n4 3 2 1 4\n",
"output": "1\n"
},
{
"input": "4 6\n2 6 4\n3 2 5 3\n4 3 1 5 6\n3 4 1 2\n",
"output": "12\n"
},
{
"input": "3 3\n2 1 2\n2 2 3\n2 3 1\n",
"output": "0\n"
},
{
"input": "12 40\n4 35 39 11 21\n7 31 29 16 15 30 32 34\n4 21 27 38 40\n11 17 ... |
https://atcoder.jp/contests/abc302/tasks/abc302_a | Problem Statement
There is an enemy with stamina
A
. Every time you attack the enemy, its stamina reduces by
B
.
At least how many times do you need to attack the enemy to make its stamina
0
or less? | [
{
"input": "7 3\n",
"output": "3\n"
},
{
"input": "123456789123456789 987654321\n",
"output": "124999999\n"
},
{
"input": "999999999999999998 2\n",
"output": "499999999999999999\n"
}
] |
https://atcoder.jp/contests/abc302/tasks/abc302_b | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns. Each cell has a lowercase English letter written on it.
We denote by
(i, j)
the cell at the
i
-th row from the top and
j
-th column from the left.
The letters written on the grid are represented by
H
strings
S_1,S_2,\ldots, S_H
, each of... | [
{
"input": "6 6\nvgxgpu\namkxks\nzhkbpp\nhykink\nesnuke\nzplvfj\n",
"output": "5 2\n5 3\n5 4\n5 5\n5 6\n"
},
{
"input": "5 5\nezzzz\nzkzzz\nezuzs\nzzznz\nzzzzs\n",
"output": "5 5\n4 4\n3 3\n2 2\n1 1\n"
},
{
"input": "10 10\nkseeusenuk\nusesenesnn\nkskekeeses\nnesnusnkkn\nsnenuuenke\nkukk... |
https://atcoder.jp/contests/abc302/tasks/abc302_c | Problem Statement
You are given
N
strings
S_1,S_2,\dots,S_N
, each of length
M
, consisting of lowercase English letter. Here,
S_i
are pairwise distinct.
Determine if one can rearrange these strings to obtain a new sequence of strings
T_1,T_2,\dots,T_N
such that:
for all integers
i
such that
1 \le i \le N-1
, one can ... | [
{
"input": "4 4\nbbed\nabcd\nabed\nfbed\n",
"output": "Yes\n"
},
{
"input": "2 5\nabcde\nabced\n",
"output": "No\n"
},
{
"input": "8 4\nfast\nface\ncast\nrace\nfact\nrice\nnice\ncase\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc302/tasks/abc302_d | Problem Statement
Takahashi has decided to give
one
gift to Aoki and
one
gift to Snuke.
There are
N
candidates of gifts for Aoki,
and their values are
A_1, A_2, \ldots,A_N
.
There are
M
candidates of gifts for Snuke,
and their values are
B_1, B_2, \ldots,B_M
.
Takahashi wants to choose gifts so that the difference in... | [
{
"input": "2 3 2\n3 10\n2 5 15\n",
"output": "8\n"
},
{
"input": "3 3 0\n1 3 3\n6 2 7\n",
"output": "-1\n"
},
{
"input": "1 1 1000000000000000000\n1000000000000000000\n1000000000000000000\n",
"output": "2000000000000000000\n"
},
{
"input": "8 6 1\n2 5 6 5 2 1 7 9\n7 2 5 5 2 ... |
https://atcoder.jp/contests/abc302/tasks/abc302_e | Problem Statement
There is an undirected graph with
N
vertices numbered
1
through
N
, and initially with
0
edges.
Given
Q
queries, process them in order. After processing each query,
print the number of vertices that are not connected to any other vertices by an edge.
The
i
-th query,
\mathrm{query}_i
, is of one of ... | [
{
"input": "3 7\n1 1 2\n1 1 3\n1 2 3\n2 1\n1 1 2\n2 2\n1 1 2\n",
"output": "1\n0\n0\n1\n0\n3\n1\n"
},
{
"input": "2 1\n2 1\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc302/tasks/abc302_f | Problem Statement
On a blackboard, there are
N
sets
S_1,S_2,\dots,S_N
consisting of integers between
1
and
M
. Here,
S_i = \lbrace S_{i,1},S_{i,2},\dots,S_{i,A_i} \rbrace
.
You may perform the following operation any number of times (possibly zero):
choose two sets
X
and
Y
with at least one common element. Erase them ... | [
{
"input": "3 5\n2\n1 2\n2\n2 3\n3\n3 4 5\n",
"output": "2\n"
},
{
"input": "1 2\n2\n1 2\n",
"output": "0\n"
},
{
"input": "3 5\n2\n1 3\n2\n2 4\n3\n2 4 5\n",
"output": "-1\n"
},
{
"input": "4 8\n3\n1 3 5\n2\n1 2\n3\n2 4 7\n4\n4 6 7 8\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc302/tasks/abc302_g | Problem Statement
You are given a sequence
A=(A_1,A_2,\ldots,A_N)
of length
N
, consisting of integers between
1
and
4
.
Takahashi may perform the following operation any number of times (possibly zero):
choose a pair of integer
(i,j)
such that
1\leq i<j\leq N
, and swap
A_i
and
A_j
.
Find the minimum number of operati... | [
{
"input": "6\n3 4 1 1 2 4\n",
"output": "3\n"
},
{
"input": "4\n2 3 4 1\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc302/tasks/abc302_h | Problem Statement
We have a tree with
N
vertices. The
i
-th
(1 \le i \le N-1)
edge is an undirected edge between vertices
U_i
and
V_i
. Vertex
i
(1 \le i \le N)
has a ball with
A_i
written on it and another with
B_i
.
For each
v = 2,3,\dots,N
, answer the following question. (Each query is independent.)
Consider tra... | [
{
"input": "4\n1 2\n2 3\n3 1\n1 2\n1 2\n2 3\n3 4\n",
"output": "2 3 3\n"
},
{
"input": "10\n2 5\n2 2\n8 8\n4 3\n6 10\n8 1\n9 10\n1 7\n9 3\n5 10\n9 3\n1 9\n3 6\n4 1\n3 8\n10 9\n5 4\n7 2\n9 7\n",
"output": "4 3 2 3 4 3 4 2 3\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_a | Problem Statement
You are given a permutation
A = (A_1, A_2, \dots, A_N)
of
(1, 2, \dots, N)
.
For a pair of integers
(L, R)
such that
1 \leq L \leq R \leq N
, let
f(L, R)
be the permutation obtained by reversing the
L
-th through
R
-th elements of
A
, that is, replacing
A_L, A_{L+1}, \dots, A_{R-1}, A_R
with
A_R, A_{R... | [
{
"input": "3 5\n1 3 2\n",
"output": "2 3 1\n"
},
{
"input": "5 15\n1 2 3 4 5\n",
"output": "5 4 3 2 1\n"
},
{
"input": "10 37\n9 2 1 3 8 7 10 4 5 6\n",
"output": "9 2 1 6 5 4 10 7 8 3\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_b | Problem Statement
You are given a positive integer
N
.
Find the number, modulo
998244353
, of triples of positive integers
(x,y,z)
that satisfy the following condition.
All of
xy
,
yz
,
zx
are less than or equal to
N
.
You have
T
test cases to solve. | [
{
"input": "4\n1\n2\n5\n998244353\n",
"output": "1\n4\n17\n727512986\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_c | Problem Statement
You are given a multiset of positive integers with
N
elements:
A=\lbrace A_1,A_2,\dots,A_N \rbrace
.
You may repeat the following operation any number of times (possibly zero).
Choose a positive integer
x
that occurs at least twice in
A
. Delete two occurrences of
x
from
A
, and add one occurrence of
... | [
{
"input": "4\n1 1 2 4\n",
"output": "3\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "1\n"
},
{
"input": "13\n3 1 4 1 5 9 2 6 5 3 5 8 9\n",
"output": "66\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_d | Problem Statement
Find the number, modulo
998244353
, of sequences of
N
non-negative integers
A=(A_1,A_2,\dots,A_N)
totaling
M
that satisfy the following condition.
It is possible to make all elements of
A
equal
0
by repeatedly choosing one of the following operations and performing it.
Choose an integer
i
such that
1 ... | [
{
"input": "3 2 2\n",
"output": "5\n"
},
{
"input": "100 998244353 100\n",
"output": "0\n"
},
{
"input": "2000 545782618661124208 533\n",
"output": "908877889\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_e | Problem Statement
You are given an undirected tree
G
with
N
vertices.
The degree of every vertex in
G
is at most
3
.
The vertices are numbered
1
to
N
. The edges are numbered
1
to
N-1
, and edge
i
connects vertex
u_i
and vertex
v_i
.
Each vertex has a fixed weight, and the weight of vertex
i
is
W_i
.
You will add zero ... | [
{
"input": "2\n3\n2 3 5\n1 2\n2 3\n7\n1 10 100 1000 10000 100000 1000000\n1 2\n2 3\n2 4\n3 5\n3 6\n4 7\n",
"output": "1\n1 3\n2\n7 6\n1 5\n"
}
] |
https://atcoder.jp/contests/arc160/tasks/arc160_f | Problem Statement
There are an integer
N
and
M
pairs of integers:
(a_1, b_1), (a_2, b_2), \dots, (a_M, b_M)
. Each pair
(a_i, b_i)
satisfies
1 \leq a_i \lt b_i \leq N
.
Initally, you have all
N!
permutations of
(1,2,\dots,N)
.
You will perform
M
operations. The
i
-th operation is as follows.
Do the following for each o... | [
{
"input": "2 1\n1 1\n",
"output": "2\n"
},
{
"input": "3 4\n0 1\n2 1\n1 1\n0 1\n",
"output": "2\n4\n4\n6\n"
},
{
"input": "5 5\n4 4\n0 4\n1 1\n2 4\n1 2\n",
"output": "2\n4\n4\n8\n16\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_a | Problem Statement
Takahashi and Aoki played
N
games.
You are given a string
S
of length
N
, representing the results of these games.
Takahashi won the
i
-th game if the
i
-th character of
S
is
T
, and Aoki won that game if it is
A
.
The overall winner between Takahashi and Aoki is the one who won more games than the ... | [
{
"input": "5\nTTAAT\n",
"output": "T\n"
},
{
"input": "6\nATTATA\n",
"output": "T\n"
},
{
"input": "1\nA\n",
"output": "A\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_b | Problem Statement
We have a sequence of length
N
consisting of positive integers:
A=(A_1,\ldots,A_N)
. Any two adjacent terms have different values.
Let us insert some numbers into this sequence by the following procedure.
If every pair of adjacent terms in
A
has an absolute difference of
1
, terminate the procedure.
L... | [
{
"input": "4\n2 5 1 2\n",
"output": "2 3 4 5 4 3 2 1 2\n"
},
{
"input": "6\n3 4 5 6 5 4\n",
"output": "3 4 5 6 5 4\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_c | Problem Statement
A single-player card game is popular in AtCoder Inc.
Each card in the game has a lowercase English letter or the symbol
@
written on it. There is plenty number of cards for each kind.
The game goes as follows.
Arrange the same number of cards in two rows.
Replace each card with
@
with one of the fol... | [
{
"input": "ch@ku@ai\nchoku@@i\n",
"output": "Yes\n"
},
{
"input": "ch@kud@i\nakidu@ho\n",
"output": "Yes\n"
},
{
"input": "aoki\n@ok@\n",
"output": "No\n"
},
{
"input": "aa\nbb\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_d | Problem Statement
You are given an integer
N
and a string
S
consisting of
0
,
1
, and
?
.
Let
T
be the set of values that can be obtained by replacing each
?
in
S
with
0
or
1
and interpreting the result as a binary integer.
For instance, if
S=
?0?
, we have
T=\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\rbrace=\lbra... | [
{
"input": "?0?\n2\n",
"output": "1\n"
},
{
"input": "101\n4\n",
"output": "-1\n"
},
{
"input": "?0?\n1000000000000000000\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_e | Problem Statement
We have a grid with
H
rows and
W
columns.
Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
Each square in the grid is one of the following: the start square, the goal square, an empty square, a wall square, and a candy square.
(i,j)
is represented by a charac... | [
{
"input": "3 3 5\nS.G\no#o\n.#.\n",
"output": "1\n"
},
{
"input": "3 3 1\nS.G\n.#o\no#.\n",
"output": "-1\n"
},
{
"input": "5 10 2000000\nS.o..ooo..\n..o..o.o..\n..o..ooo..\n..o..o.o..\n..o..ooo.G\n",
"output": "18\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_f | Problem Statement
A
DDoS
-type string is a string of length
4
consisting of uppercase and lowercase English letters satisfying both of the following conditions.
The first, second, and fourth characters are uppercase English letters, and the third character is a lowercase English letter.
The first and second characters ... | [
{
"input": "DD??S\n",
"output": "676\n"
},
{
"input": "????????????????????????????????????????\n",
"output": "858572093\n"
},
{
"input": "?D??S\n",
"output": "136604\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_g | Problem Statement
There are
N
people in a three-dimensional space. The
i
-th person is at the coordinates
(X_i,Y_i,Z_i)
.
All people are at different coordinates, and we have
X_i>0
for every
i
.
You will choose a point
p=(x,y,z)
such that
x<0
, and take a photo in the positive
x
-direction.
If the point
p
and the posit... | [
{
"input": "3\n1 1 1\n2 2 2\n100 99 98\n",
"output": "2\n"
},
{
"input": "8\n1 1 1\n1 1 -1\n1 -1 1\n1 -1 -1\n3 2 2\n3 2 -2\n3 -2 2\n3 -2 -2\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc301/tasks/abc301_h | Problem Statement
We have a connected undirected graph with
N
vertices numbered
1
to
N
and
M
edges numbered
1
to
M
.
Edge
i
connects vertex
U_i
and vertex
V_i
, and has an integer weight of
W_i
.
For
1\leq s,t \leq N,\ s\neq t
, let us define
d(s,t)
as follows.
For every path connecting vertex
s
and vertex
t
, consid... | [
{
"input": "6 6\n1 2 1\n3 1 5\n4 1 5\n3 4 3\n5 6 4\n2 6 5\n7\n1 4 6\n2 4 6\n3 4 6\n4 4 6\n5 4 6\n6 4 6\n5 6 5\n",
"output": "0\n0\n0\n0\n0\n1\n1\n"
},
{
"input": "2 2\n1 2 1\n1 2 1\n1\n1 1 2\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_a | Problem Statement
Given integers
A
and
B
, find
A+B
.
This is a
N
-choice problem; the
i
-th choice is
C_i
.
Print the
index
of the correct choice. | [
{
"input": "3 125 175\n200 300 400\n",
"output": "2\n"
},
{
"input": "1 1 1\n2\n",
"output": "1\n"
},
{
"input": "5 123 456\n135 246 357 468 579\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_b | Problem Statement
Takahashi is developing an RPG. He has decided to write a code that checks whether two maps are equal.
We have grids
A
and
B
with
H
horizontal rows and
W
vertical columns. Each cell in the grid has a symbol
#
or
.
written on it.
The symbols written on the cell at the
i
-th row from the top and
j
-th... | [
{
"input": "4 3\n..#\n...\n.#.\n...\n#..\n...\n.#.\n...\n",
"output": "Yes\n"
},
{
"input": "3 2\n##\n##\n#.\n..\n#.\n#.\n",
"output": "No\n"
},
{
"input": "4 5\n#####\n.#...\n.##..\n..##.\n...##\n#...#\n#####\n...#.\n",
"output": "Yes\n"
},
{
"input": "10 30\n..........#####... |
https://atcoder.jp/contests/abc300/tasks/abc300_c | Problem Statement
We have a grid with
H
horizontal rows and
W
vertical columns. We denote by
(i, j)
the cell at the
i
-th row from the top and
j
-th column from the left of the grid.
Each cell in the grid has a symbol
#
or
.
written on it. Let
C[i][j]
be the character written on
(i, j)
. For integers
i
and
j
such that ... | [
{
"input": "5 9\n#.#.#...#\n.#...#.#.\n#.#...#..\n.....#.#.\n....#...#\n",
"output": "1 1 0 0 0\n"
},
{
"input": "3 3\n...\n...\n...\n",
"output": "0 0 0\n"
},
{
"input": "3 16\n#.#.....#.#..#.#\n.#.......#....#.\n#.#.....#.#..#.#\n",
"output": "3 0 0\n"
},
{
"input": "15 20\... |
https://atcoder.jp/contests/abc300/tasks/abc300_d | Problem Statement
How many positive integers no greater than
N
can be represented as
a^2 \times b \times c^2
with three
primes
a,b
, and
c
such that
a<b<c
? | [
{
"input": "1000\n",
"output": "3\n"
},
{
"input": "1000000000000\n",
"output": "2817785\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_e | Problem Statement
You have an integer
1
and a die that shows integers between
1
and
6
(inclusive) with equal probability.
You repeat the following operation while your integer is strictly less than
N
:
Cast a die. If it shows
x
, multiply your integer by
x
.
Find the probability, modulo
998244353
, that your integer e... | [
{
"input": "6\n",
"output": "239578645\n"
},
{
"input": "7\n",
"output": "0\n"
},
{
"input": "300\n",
"output": "183676961\n"
},
{
"input": "979552051200000000\n",
"output": "812376310\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_f | Problem Statement
You are given a string
S
of length
N
consisting of
o
and
x
, and integers
M
and
K
.
S
is guaranteed to contain at least one
x
.
Let
T
be the string of length
NM
obtained by concatenating
M
copies of
S
.
Consider replacing exactly
K
x
's in
T
with
o
.
Your objective is to have as long a contiguous subs... | [
{
"input": "10 1 2\nooxxooooox\n",
"output": "9\n"
},
{
"input": "5 3 4\noxxox\n",
"output": "8\n"
},
{
"input": "30 1000000000 9982443530\noxoxooxoxoxooxoxooxxxoxxxooxox\n",
"output": "19964887064\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_g | Problem Statement
A positive integer is called a
k
-smooth number if none of its prime factors exceeds
k
.
Given an integer
N
and a prime
P
not exceeding
100
, find the number of
P
-smooth numbers not exceeding
N
. | [
{
"input": "36 3\n",
"output": "14\n"
},
{
"input": "10000000000000000 97\n",
"output": "2345134674\n"
}
] |
https://atcoder.jp/contests/abc300/tasks/abc300_h | Problem Statement
We define the general term
a_n
of a sequence
a_0, a_1, a_2, \dots
by:
a_n = \begin{cases} 1 & (0 \leq n \lt K) \\ \displaystyle{\sum_{i=1}^K} a_{n-i} & (K \leq n). \\ \end{cases}
Given an integer
N
, find the sum, modulo
998244353
, of
a_m
over all non-negative integers
m
such that
m\text{ AND }N = m
... | [
{
"input": "2 6\n",
"output": "21\n"
},
{
"input": "2 8\n",
"output": "35\n"
},
{
"input": "1 123456789\n",
"output": "65536\n"
},
{
"input": "300 20230429\n",
"output": "125461938\n"
},
{
"input": "42923 999999999558876113\n",
"output": "300300300\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_a | Problem Statement
You are given a string
S
of length
N
consisting of three kinds of characters:
.
,
|
, and
*
.
S
contains exactly two
|
and exactly one
*
.
Determine whether the
*
is between the two
|
, and if so, print
in
; otherwise, print
out
.
More formally, determine whether one of the characters before the
*
is
... | [
{
"input": "10\n.|..*...|.\n",
"output": "in\n"
},
{
"input": "10\n.|..|.*...\n",
"output": "out\n"
},
{
"input": "3\n|*|\n",
"output": "in\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_b | Problem Statement
N
players with
ID numbers
1, 2, \ldots, N
are playing a card game.
Each player plays one card.
Each card has two parameters:
color
and
rank
, both of which are represented by positive integers.
For
i = 1, 2, \ldots, N
, the card played by player
i
has a color
C_i
and a rank
R_i
.
All of
R_1, R_2, \ld... | [
{
"input": "4 2\n1 2 1 2\n6 3 4 5\n",
"output": "4\n"
},
{
"input": "4 2\n1 3 1 4\n6 3 4 5\n",
"output": "1\n"
},
{
"input": "2 1000000000\n1000000000 1\n1 1000000000\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_c | Problem Statement
For a positive integer
L
, a level-
L
dango string is a string that satisfies the following conditions.
It is a string of length
L+1
consisting of
o
and
-
.
Exactly one of the first character and the last character is
-
, and the other
L
characters are
o
.
For instance,
ooo-
is a level-
3
dango string... | [
{
"input": "10\no-oooo---o\n",
"output": "4\n"
},
{
"input": "1\n-\n",
"output": "-1\n"
},
{
"input": "30\n-o-o-oooo-oo-o-ooooooo--oooo-o\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_d | Problem Statement
This is an
interactive task
, where your program and the judge interact via Standard Input and Output.
The judge has a string of length
N
consisting of
0
and
1
:
S = S_1S_2\ldots S_N
.
Here,
S_1 = 0
and
S_N = 1
.
You are given the length
N
of
S
, but not the contents of
S
.
Instead, you can ask the ... | [] |
https://atcoder.jp/contests/abc299/tasks/abc299_e | Problem Statement
You are given a simple connected undirected graph with
N
vertices and
M
edges (a simple graph contains no self-loop and no multi-edges).
For
i = 1, 2, \ldots, M
, the
i
-th edge connects vertex
u_i
and vertex
v_i
bidirectionally.
Determine whether there is a way to paint each vertex black or white to ... | [
{
"input": "5 5\n1 2\n2 3\n3 1\n3 4\n4 5\n2\n1 0\n5 2\n",
"output": "Yes\n10100\n"
},
{
"input": "5 5\n1 2\n2 3\n3 1\n3 4\n4 5\n5\n1 1\n2 1\n3 1\n4 1\n5 1\n",
"output": "No\n"
},
{
"input": "1 0\n0\n",
"output": "Yes\n1\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_f | Problem Statement
You are given a string
S
consisting of lowercase English letters.
Print the number of non-empty strings
T
that satisfy the following condition, modulo
998244353
.
The concatenation
TT
of two copies of
T
is a subsequence of
S
(not necessarily contiguous). | [
{
"input": "ababbaba\n",
"output": "8\n"
},
{
"input": "zzz\n",
"output": "1\n"
},
{
"input": "ppppqqppqqqpqpqppqpqqqqpppqppq\n",
"output": "580\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_g | Problem Statement
We have a sequence
A
of length
N
consisting of integers between
1
and
M
. Here, every integer from
1
to
M
appears at least once in
A
.
Among the length-
M
subsequences of
A
where each of
1, \ldots, M
appears once, find the lexicographically smallest one. | [
{
"input": "4 3\n2 3 1 3\n",
"output": "2 1 3\n"
},
{
"input": "4 4\n2 3 1 4\n",
"output": "2 3 1 4\n"
},
{
"input": "20 10\n6 3 8 5 8 10 9 3 6 1 8 3 3 7 4 7 2 7 8 5\n",
"output": "3 5 8 10 9 6 1 4 2 7\n"
}
] |
https://atcoder.jp/contests/abc299/tasks/abc299_h | Problem Statement
Takahashi has an unbiased six-sided die and a positive integer
R
less than
10^9
.
Each time the die is cast, it shows one of the numbers
1,2,3,4,5,6
with equal probability, independently of the outcomes of the other trials.
Takahashi will perform the following procedure.
Initially,
C=0
.
Cast the di... | [
{
"input": "1\n",
"output": "291034221\n"
},
{
"input": "720357616\n",
"output": "153778832\n"
}
] |
https://atcoder.jp/contests/abc298/tasks/abc298_a | Problem Statement
Takahashi had a job interview.
You are given the number of interviewers,
N
, and a string
S
of length
N
representing the interviewers' evaluations of him.
For each
i=1,2,\ldots,N
, the
i
-th character of
S
corresponds to the
i
-th interviewer's evaluation;
o
means Good,
-
means Fair, and
x
means Poor.... | [
{
"input": "4\noo--\n",
"output": "Yes\n"
},
{
"input": "3\n---\n",
"output": "No\n"
},
{
"input": "1\no\n",
"output": "Yes\n"
},
{
"input": "100\nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooox\n",
"output": "No\n"
}... |
https://atcoder.jp/contests/abc298/tasks/abc298_b | Problem Statement
You are given
N
-by-
N
matrices
A
and
B
where each element is
0
or
1
.
Let
A_{i,j}
and
B_{i,j}
denote the element at the
i
-th row and
j
-th column of
A
and
B
, respectively.
Determine whether it is possible to rotate
A
so that
B_{i,j} = 1
for every pair of integers
(i, j)
such that
A_{i,j} = 1
.
Here... | [
{
"input": "3\n0 1 1\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 1 1\n",
"output": "Yes\n"
},
{
"input": "2\n0 0\n0 0\n1 1\n1 1\n",
"output": "Yes\n"
},
{
"input": "5\n0 0 1 1 0\n1 0 0 1 0\n0 0 1 0 1\n0 1 0 1 0\n0 1 0 0 1\n1 1 0 0 1\n0 1 1 1 0\n0 0 1 1 1\n1 0 1 0 1\n1 1 0 1 0\n",
"output": "No\n"... |
https://atcoder.jp/contests/abc298/tasks/abc298_c | Problem Statement
We have
N
boxes numbered
1
to
N
that are initially empty, and an unlimited number of blank cards.
Process
Q
queries in order. There are three kinds of queries as follows.
1 i j
\colon
Write the number
i
on a blank card and put it into box
j
.
2 i
\colon
Report all numbers written on the cards in box
i... | [
{
"input": "5\n8\n1 1 1\n1 2 4\n1 1 4\n2 4\n1 1 4\n2 4\n3 1\n3 2\n",
"output": "1 2\n1 1 2\n1 4\n4\n"
},
{
"input": "1\n5\n1 1 1\n1 2 1\n1 200000 1\n2 1\n3 200000\n",
"output": "1 2 200000\n1\n"
}
] |
https://atcoder.jp/contests/abc298/tasks/abc298_d | Problem Statement
We have a string
S
. Initially,
S=
1
.
Process
Q
queries in the following formats in order.
1 x
: Append a digit
x
at the end of
S
.
2
: Delete the digit at the beginning of
S
.
3
: Print the number represented by
S
in decimal, modulo
998244353
. | [
{
"input": "3\n3\n1 2\n3\n",
"output": "1\n12\n"
},
{
"input": "3\n1 5\n2\n3\n",
"output": "5\n"
},
{
"input": "11\n1 9\n1 9\n1 8\n1 2\n1 4\n1 4\n1 3\n1 5\n1 3\n2\n3\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc298/tasks/abc298_e | Problem Statement
Takahashi and Aoki will play a game of sugoroku.
Takahashi starts at point
A
, and Aoki starts at point
B
. They will take turns throwing dice.
Takahashi's die shows
1, 2, \ldots, P
with equal probability, and Aoki's shows
1, 2, \ldots, Q
with equal probability.
When a player at point
x
throws his die... | [
{
"input": "4 2 3 3 2\n",
"output": "665496236\n"
},
{
"input": "6 4 2 1 1\n",
"output": "1\n"
},
{
"input": "100 1 1 10 10\n",
"output": "264077814\n"
}
] |
https://atcoder.jp/contests/abc298/tasks/abc298_f | Problem Statement
We have a grid with
10^9
rows and
10^9
columns. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
For
i=1,2,\ldots,N
, a positive integer
x_i
is written on
(r_i,c_i)
. On the other
10^{18}-N
squares,
0
is written.
You choose a square
(R,C)
and compute the sum
S
... | [
{
"input": "4\n1 1 2\n1 2 9\n2 1 8\n3 2 3\n",
"output": "20\n"
},
{
"input": "1\n1 1000000000 1\n",
"output": "1\n"
},
{
"input": "15\n158260522 877914575 602436426\n24979445 861648772 623690081\n433933447 476190629 262703497\n211047202 971407775 628894325\n731963982 822804784 450968417\... |
https://atcoder.jp/contests/abc298/tasks/abc298_g | Problem Statement
We have a rectangular cake. It is partitioned into
H
rows and
W
columns of sections, and the section at the
i
-th row from the top and
j
-th column from the left has
s_{i,j}
strawberries on it.
You will make
T
cuts to divide the cake into
T+1
pieces. Each cut will be done in one of the following two m... | [
{
"input": "2 3 4\n2 3 4\n4 1 3\n",
"output": "2\n"
},
{
"input": "2 2 3\n0 0\n0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc298/tasks/abc298_h | Problem Statement
You are given a tree with
N
vertices. The vertices are numbered
1
to
N
, and the
i
-th edge connects vertex
A_i
and vertex
B_i
.
Let
d(x,y)
denote the distance between vertex
x
and
y
in this tree. Here, the distance between vertex
x
and
y
is the number of edges on the shortest path from vertex
x
to
y
... | [
{
"input": "5\n3 4\n4 5\n2 5\n1 5\n3\n4 1\n1 2\n5 3\n",
"output": "4\n6\n3\n"
},
{
"input": "8\n4 2\n4 1\n5 6\n6 1\n7 6\n8 1\n3 7\n7\n8 4\n4 4\n7 2\n4 4\n5 3\n4 4\n6 1\n",
"output": "14\n16\n10\n16\n14\n16\n8\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_a | Problem Statement
Takahashi turned on a computer at time
0
and clicked the mouse
N
times. The
i
-th
(1 \le i \le N)
click was at time
T_i
.
If he consecutively clicked the mouse at time
x_1
and time
x_2
(where
x_1 < x_2
), a double click is said to be fired at time
x_2
if and only if
x_2 - x_1 \le D
.
What time was a ... | [
{
"input": "4 500\n300 900 1300 1700\n",
"output": "1300\n"
},
{
"input": "5 99\n100 200 300 400 500\n",
"output": "-1\n"
},
{
"input": "4 500\n100 600 1100 1600\n",
"output": "600\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_b | Problem Statement
Takahashi is playing a game called Chess960.
He has decided to write a code that determines if a random initial state satisfies the conditions of Chess960.
You are given a string
S
of length eight.
S
has exactly one
K
and
Q
, and exactly two
R
's,
B
's , and
N
's. Determine if
S
satisfies all of the... | [
{
"input": "RNBQKBNR\n",
"output": "Yes\n"
},
{
"input": "KRRBBNNQ\n",
"output": "No\n"
},
{
"input": "BRKRBQNN\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_c | Problem Statement
Planning to place many PCs in his room, Takahashi has decided to write a code that finds how many PCs he can place in his room.
You are given
H
strings
S_1,S_2,\ldots,S_H
, each of length
W
, consisting of
.
and
T
.
Takahashi may perform the following operation any number of times (possibly zero):
Cho... | [
{
"input": "2 3\nTTT\nT.T\n",
"output": "PCT\nT.T\n"
},
{
"input": "3 5\nTTT..\n.TTT.\nTTTTT\n",
"output": "PCT..\n.PCT.\nPCTPC\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.