url stringlengths 49 92 | description stringlengths 22 4.78k | cases listlengths 0 6 |
|---|---|---|
https://atcoder.jp/contests/agc068/tasks/agc068_c | Problem Statement
There are
N
boxes numbered from
1
to
N
, and
N
balls numbered from
1
to
N
.
You have assigned Snuke the following
procedure
as homework.
Put each ball into any box he likes. Multiple balls can be placed in the same box, and there can be boxes without balls.
For
i = 1, 2, \cdots, N
in this order, perfo... | [
{
"input": "5\n3\n1 1 1\n3\n2 2 2\n5\n1 2 3 4 5\n10\n8 3 8 10 1 5 3 1 6 4\n10\n1 5 1 2 4 8 8 6 7 3\n",
"output": "Yes\nNo\nYes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/agc068/tasks/agc068_d | Problem Statement
There is a rooted tree
T
with
N
vertices numbered from
1
to
N
.
Vertex
1
is the root, and the parent of vertex
i
(
2 \leq i \leq N
) is
P_i
(
P_i < i
).
A permutation
x = (x_1, x_2, \cdots, x_N)
of
(1, 2, \cdots, N)
is judged to be a
good
permutation or not by the following criteria.
Consider the fol... | [
{
"input": "3 100\n1 1\n",
"output": "50502\n"
},
{
"input": "5 100\n1 2 3 4\n",
"output": "504030201\n"
},
{
"input": "10 248730679\n1 2 1 2 5 6 1 8 1\n",
"output": "856673861\n"
},
{
"input": "20 480124393\n1 2 3 2 3 4 3 8 3 4 11 10 4 14 15 12 17 18 19\n",
"output": "48... |
https://atcoder.jp/contests/agc068/tasks/agc068_e | Problem Statement
You are given an
N \times N
integer matrix
A = (A_{i,j})_{1 \leq i \leq N, 1 \leq j \leq N}
and an integer
M
.
For an integer sequence
x = (x_1, x_2, \cdots, x_M)
of length
M
consisting of integers between
1
and
N
, inclusive, define
f(x)
as follows:
Let
y = (y_1, y_2, \cdots, y_M)
be the sequence obt... | [
{
"input": "2 2\n1 2\n3 4\n",
"output": "5 22\n"
},
{
"input": "2 3\n1 2\n3 4\n",
"output": "27 118\n"
},
{
"input": "5 4\n785439575 250040585 709423541 945005786 19237225\n404191279 250876592 22672563 519729086 344065186\n273714212 560047125 139793596 542901248 520999410\n855572558 4988... |
https://atcoder.jp/contests/abc373/tasks/abc373_a | Problem Statement
There are
12
strings
S_1, S_2, \ldots, S_{12}
consisting of lowercase English letters.
Find how many integers
i
(1 \leq i \leq 12)
satisfy that the length of
S_i
is
i
. | [
{
"input": "january\nfebruary\nmarch\napril\nmay\njune\njuly\naugust\nseptember\noctober\nnovember\ndecember\n",
"output": "1\n"
},
{
"input": "ve\ninrtfa\nnpccxva\ndjiq\nlmbkktngaovl\nmlfiv\nfmbvcmuxuwggfq\nqgmtwxmb\njii\nts\nbfxrvs\neqvy\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc373/tasks/abc373_b | Problem Statement
There is a keyboard with
26
keys arranged on a number line.
The arrangement of this keyboard is represented by a string
S
, which is a permutation of
ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
The key corresponding to the character
S_x
is located at coordinate
x
(1 \leq x \leq 26)
. Here,
S_x
denotes the
x
-th cha... | [
{
"input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
"output": "25\n"
},
{
"input": "MGJYIZDKSBHPVENFLQURTCWOAX\n",
"output": "223\n"
}
] |
https://atcoder.jp/contests/abc373/tasks/abc373_c | Problem Statement
You are given two integer sequences
A
and
B
, each of length
N
. Choose integers
i, j
(1 \leq i, j \leq N)
to maximize the value of
A_i + B_j
. | [
{
"input": "2\n-1 5\n3 -7\n",
"output": "8\n"
},
{
"input": "6\n15 12 3 -13 -1 -19\n7 17 -13 -10 18 4\n",
"output": "33\n"
}
] |
https://atcoder.jp/contests/abc373/tasks/abc373_d | Problem Statement
You are given a directed graph with
N
vertices and
M
edges. The
j
-th directed edge goes from vertex
u_j
to vertex
v_j
and has a weight of
w_j
.
Find one way to write an integer between
-10^{18}
and
10^{18}
, inclusive, to each vertex such that the following condition is satisfied.
Let
x_i
be the valu... | [
{
"input": "3 3\n1 2 2\n3 2 3\n1 3 -1\n",
"output": "3 5 2\n"
},
{
"input": "4 2\n2 1 5\n3 4 -3\n",
"output": "5 0 6 3\n"
},
{
"input": "5 7\n2 1 18169343\n3 1 307110901\n4 1 130955934\n2 3 -288941558\n2 5 96267410\n5 3 -385208968\n4 3 -176154967\n",
"output": "200401298 182231955 -1... |
https://atcoder.jp/contests/abc373/tasks/abc373_e | Problem Statement
An election is being held with
N
candidates numbered
1, 2, \ldots, N
. There are
K
votes, some of which have been counted so far.
Up until now, candidate
i
has received
A_i
votes.
After all ballots are counted, candidate
i
(1 \leq i \leq N)
will be elected if and only if the number of candidates who h... | [
{
"input": "5 2 16\n3 1 4 1 5\n",
"output": "2 -1 1 -1 0\n"
},
{
"input": "12 1 570\n81 62 17 5 5 86 15 7 79 26 6 28\n",
"output": "79 89 111 117 117 74 112 116 80 107 117 106\n"
}
] |
https://atcoder.jp/contests/abc373/tasks/abc373_f | Problem Statement
There are
N
types of items. The
i
-th type of item has a weight of
w_i
and a value of
v_i
. Each type has
10^{10}
items available.
Takahashi is going to choose some items and put them into a bag with capacity
W
. He wants to maximize the value of the selected items while avoiding choosing too many ite... | [
{
"input": "2 10\n3 4\n3 2\n",
"output": "5\n"
},
{
"input": "3 6\n1 4\n2 3\n2 7\n",
"output": "14\n"
},
{
"input": "1 10\n1 7\n",
"output": "12\n"
}
] |
https://atcoder.jp/contests/abc373/tasks/abc373_g | Problem Statement
There are
2N
points
P_1,P_2,\ldots,P_N, Q_1,Q_2,\ldots,Q_N
on a two-dimensional plane.
The coordinates of
P_i
are
(A_i, B_i)
, and the coordinates of
Q_i
are
(C_i, D_i)
.
No three different points lie on the same straight line.
Determine whether there exists a permutation
R = (R_1, R_2, \ldots, R_N)
o... | [
{
"input": "3\n0 0\n2 4\n4 2\n0 2\n2 0\n4 4\n",
"output": "2 1 3\n"
},
{
"input": "8\n59 85\n60 57\n72 12\n3 27\n16 58\n41 94\n77 64\n97 20\n32 37\n7 2\n57 94\n35 70\n38 60\n97 100\n5 76\n38 8\n",
"output": "3 5 8 2 7 4 6 1\n"
}
] |
https://atcoder.jp/contests/arc184/tasks/arc184_a | Problem Statement
This problem is
interactive
, and the
judge is adaptive
. See the notes for details.
Also, the parameters in the problem statement are fixed at
N=1000
,
M=10
,
Q=950
.
There are
N
coins numbered
1, 2, \dots, N
.
Exactly
M
of these coins are counterfeit.
An appraiser can, in one appraisal, determine wh... | [] |
https://atcoder.jp/contests/arc184/tasks/arc184_b | Problem Statement
You are given a positive integer
N
. There is an empty set
S
, and you can perform the following operation any number of times:
Choose any positive integer
x
. For each of
x
,
2x
, and
3x
, add it to
S
if it is not already in
S
.
Find the minimum number of operations required to satisfy
\{1, 2, \dots,... | [
{
"input": "7\n",
"output": "4\n"
},
{
"input": "25\n",
"output": "14\n"
}
] |
https://atcoder.jp/contests/arc184/tasks/arc184_c | Problem Statement
We have a long, thin piece of paper whose thickness can be ignored. We perform the following operation
100
times: lift the right end, fold it so that it aligns with the left end using the center as a crease. After completing the
100
folds, we unfold the paper back to its original state. At this point,... | [
{
"input": "4\n0 1 2 3\n",
"output": "3\n"
},
{
"input": "6\n0 2 3 5 7 8\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/arc184/tasks/arc184_d | Problem Statement
There are
N
balls on a two-dimensional plane, numbered from
1
to
N
. Ball
i
is at point
(X_i, Y_i)
. Here,
X = (X_1, X_2, \dots, X_N)
and
Y = (Y_1, Y_2, \dots, Y_N)
are permutations of
(1, 2, \dots, N)
.
You can perform the following operation any number of times:
Choose one of the remaining balls, sa... | [
{
"input": "3\n1 3\n2 1\n3 2\n",
"output": "3\n"
},
{
"input": "4\n4 2\n2 1\n3 3\n1 4\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/arc184/tasks/arc184_e | Problem Statement
You are given
N
length-
M
sequences, where each element is
0
or
1
. The
i
-th sequence is
A_i = (A_{i, 1}, A_{i, 2}, \dots, A_{i, M})
.
For integers
i, j \ (1 \leq i, j \leq N)
, define
f(i, j)
as follows:
f(i, j) :=
The smallest non-negative integer
x
such that
A_i
and
A_j
become identical after perf... | [
{
"input": "4 3\n1 0 0\n1 1 0\n1 0 1\n0 1 1\n",
"output": "8\n"
},
{
"input": "7 6\n1 0 0 0 0 0\n1 1 1 0 0 0\n1 0 1 1 0 0\n1 0 0 0 1 1\n1 0 0 0 0 1\n1 0 0 0 0 0\n1 1 1 1 1 1\n",
"output": "6\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_a | Problem Statement
You are given a string
S
consisting of lowercase English letters and
.
.
Find the string obtained by removing all
.
from
S
. | [
{
"input": ".v.\n",
"output": "v\n"
},
{
"input": "chokudai\n",
"output": "chokudai\n"
},
{
"input": "...\n",
"output": "\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_b | Problem Statement
You are given a positive integer
M
.
Find a positive integer
N
and a sequence of non-negative integers
A = (A_1, A_2, \ldots, A_N)
that satisfy all of the following conditions:
1 \le N \le 20
0 \le A_i \le 10
(1 \le i \le N)
\displaystyle \sum_{i=1}^N 3^{A_i} = M
It can be proved that under the const... | [
{
"input": "6\n",
"output": "2\n1 1\n"
},
{
"input": "100\n",
"output": "4\n2 0 2 4\n"
},
{
"input": "59048\n",
"output": "20\n0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_c | Problem Statement
You are given a string
S
of length
N
. You are also given
Q
queries, which you should process in order.
The
i
-th query is as follows:
Given an integer
X_i
and a character
C_i
, replace the
X_i
-th character of
S
with
C_i
. Then, print the number of times the string
ABC
appears as a substring in
S
.
H... | [
{
"input": "7 4\nABCDABC\n4 B\n3 A\n5 C\n4 G\n",
"output": "2\n1\n1\n0\n"
},
{
"input": "3 3\nABC\n1 A\n2 B\n3 C\n",
"output": "1\n1\n1\n"
},
{
"input": "15 10\nBBCCBCACCBACACA\n9 C\n11 B\n5 B\n11 B\n4 A\n8 C\n8 B\n5 B\n7 B\n14 B\n",
"output": "0\n0\n0\n0\n1\n1\n2\n2\n1\n1\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_d | Problem Statement
There are
N
buildings, Building
1
, Building
2
,
\ldots
, Building
N
, arranged in a line in this order. The height of Building
i
(1 \leq i \leq N)
is
H_i
.
For each
i = 1, 2, \ldots, N
, find the number of integers
j
(i < j \leq N)
satisfying the following condition:
There is no building taller than ... | [
{
"input": "5\n2 1 4 3 5\n",
"output": "3 2 2 1 0\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "3 2 1 0\n"
},
{
"input": "10\n1 9 6 5 2 7 10 4 8 3\n",
"output": "2 3 3 3 2 1 2 1 1 0\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_e | Problem Statement
There is an undirected graph with
N
vertices and
0
edges. The vertices are numbered
1
to
N
.
You are given
Q
queries to process in order. Each query is of one of the following two types:
Type
1
: Given in the format
1 u v
. Add an edge between vertices
u
and
v
.
Type
2
: Given in the format
2 v k
. Pr... | [
{
"input": "4 10\n1 1 2\n2 1 1\n2 1 2\n2 1 3\n1 1 3\n1 2 3\n1 3 4\n2 1 1\n2 1 3\n2 1 5\n",
"output": "2\n1\n-1\n4\n2\n-1\n"
},
{
"input": "6 20\n1 3 4\n1 3 5\n2 1 1\n2 3 1\n1 1 5\n2 6 9\n2 1 3\n2 6 1\n1 4 6\n2 2 1\n2 6 2\n2 4 7\n1 1 4\n2 6 2\n2 3 4\n1 2 5\n2 4 1\n1 1 6\n2 3 3\n2 1 3\n",
"output"... |
https://atcoder.jp/contests/abc372/tasks/abc372_f | Problem Statement
There is a simple directed graph
G
with
N
vertices and
N+M
edges. The vertices are numbered
1
to
N
, and the edges are numbered
1
to
N+M
.
Edge
i
(1 \leq i \leq N)
goes from vertex
i
to vertex
i+1
. (Here, vertex
N+1
is considered as vertex
1
.)
Edge
N+i
(1 \leq i \leq M)
goes from vertex
X_i
to verte... | [
{
"input": "6 2 5\n1 4\n2 5\n",
"output": "5\n"
},
{
"input": "10 0 200000\n",
"output": "1\n"
},
{
"input": "199 10 1326\n122 39\n142 49\n164 119\n197 127\n188 145\n69 80\n6 120\n24 160\n18 154\n185 27\n",
"output": "451022766\n"
}
] |
https://atcoder.jp/contests/abc372/tasks/abc372_g | Problem Statement
You are given three length-
N
sequences of positive integers:
A=(A_1,A_2,\ldots,A_N)
,
B=(B_1,B_2,\ldots,B_N)
, and
C=(C_1,C_2,\ldots,C_N)
.
Find the number of pairs of positive integers
(x, y)
that satisfy the following condition:
A_i \times x + B_i \times y < C_i
for all
1 \leq i \leq N
.
It can be ... | [
{
"input": "2\n2\n1 1 4\n1 2 5\n1\n1 1 2\n",
"output": "2\n0\n"
},
{
"input": "3\n7\n138 16011 918976\n5478 7748 499926\n5234 17727 748589\n1157 10511 643136\n31200 3005 721285\n28839 14469 798851\n1933 5378 864127\n9\n17775 1665 386430\n37001 863 922418\n9756 4182 746671\n12379 9106 807578\n3984 40... |
https://atcoder.jp/contests/ahc037/tasks/ahc037_a | Problem Statement
The
sweetness
and
carbonation level
of beverages are represented by non-negative integers. A beverage with sweetness
x
and carbonation level
y
is denoted by
(x, y)
.
Initially you only have beverage
(0, 0)
. Below we write
S
for the set of beverages already made. Initially
S = \{(0, 0)\}
.
You can ... | [
{
"input": "4\n0 6\n2 5\n3 2\n4 0\n",
"output": "6\n0 0 2 0\n0 0 0 6\n2 0 4 0\n2 0 2 2\n2 2 3 2\n2 2 2 5\n"
}
] |
https://atcoder.jp/contests/abc371/tasks/abc371_a | Problem Statement
There are three brothers named
A
,
B
, and
C
. The age relationships among them are given by three characters
S_{\mathrm{AB}}, S_{\mathrm{AC}}, S_{\mathrm{BC}}
, which mean the following:
If
S_{\mathrm{AB}}
is
<
, then
A
is younger than
B
; if it is
>
, then
A
is older than
B
.
If
S_{\mathrm{AC}}
is
<... | [
{
"input": "< < <\n",
"output": "B\n"
},
{
"input": "< < >\n",
"output": "C\n"
}
] |
https://atcoder.jp/contests/abc371/tasks/abc371_b | Problem Statement
In the Kingdom of AtCoder, the eldest son is always given the name Taro. No one else is given the name Taro.
The eldest son is the earliest born male child in each family.
There are
N
families in the Kingdom, and
M
babies were born. Before the
M
babies were born, none of the
N
families had had any ba... | [
{
"input": "2 4\n1 M\n1 M\n2 F\n2 M\n",
"output": "Yes\nNo\nNo\nYes\n"
},
{
"input": "4 7\n2 M\n3 M\n1 F\n4 F\n4 F\n1 F\n2 M\n",
"output": "Yes\nYes\nNo\nNo\nNo\nNo\nNo\n"
}
] |
https://atcoder.jp/contests/abc371/tasks/abc371_c | Problem Statement
You are given simple undirected graphs
G
and
H
, each with
N
vertices: vertices
1
,
2
,
\ldots
,
N
.
Graph
G
has
M_G
edges, and its
i
-th edge
(1\leq i\leq M_G)
connects vertices
u_i
and
v_i
.
Graph
H
has
M_H
edges, and its
i
-th edge
(1\leq i\leq M_H)
connects vertices
a_i
and
b_i
.
You can perform t... | [
{
"input": "5\n4\n1 2\n2 3\n3 4\n4 5\n4\n1 2\n1 3\n1 4\n1 5\n3 1 4 1\n5 9 2\n6 5\n3\n",
"output": "9\n"
},
{
"input": "5\n3\n1 2\n2 3\n3 4\n4\n1 2\n2 3\n3 4\n4 5\n9 1 1 1\n1 1 1\n1 1\n9\n",
"output": "3\n"
},
{
"input": "5\n3\n1 2\n2 3\n3 4\n4\n1 2\n2 3\n3 4\n4 5\n5 4 4 4\n4 4 4\n4 4\n5\... |
https://atcoder.jp/contests/abc371/tasks/abc371_d | Problem Statement
There are
N
villages on a number line. The
i
-th village is located at coordinate
X_i
, and has
P_i
villagers.
Answer
Q
queries. The
i
-th query is in the following format:
Given integers
L_i
and
R_i
, find the total number of villagers living in villages located between coordinates
L_i
and
R_i
, incl... | [
{
"input": "4\n1 3 5 7\n1 2 3 4\n4\n1 1\n2 6\n0 10\n2 2\n",
"output": "1\n5\n10\n0\n"
},
{
"input": "7\n-10 -5 -3 -1 0 1 4\n2 5 6 5 2 1 7\n8\n-7 7\n-1 5\n-10 -4\n-8 10\n-5 0\n-10 5\n-8 7\n-8 -3\n",
"output": "26\n15\n7\n26\n18\n28\n26\n11\n"
}
] |
https://atcoder.jp/contests/abc371/tasks/abc371_e | Problem Statement
You are given a sequence of integers
A = (A_1, A_2, \ldots, A_N)
of length
N
.
Define
f(l, r)
as:
the number of distinct values in the subsequence
(A_l, A_{l+1}, \ldots, A_r)
.
Evaluate the following expression:
\displaystyle \sum_{i=1}^{N}\sum_{j=i}^N f(i,j)
. | [
{
"input": "3\n1 2 2\n",
"output": "8\n"
},
{
"input": "9\n5 4 2 2 3 2 4 4 1\n",
"output": "111\n"
}
] |
https://atcoder.jp/contests/abc371/tasks/abc371_f | Problem Statement
There is a road extending east and west, and
N
persons are on the road.
The road extends infinitely long to the east and west from a point called the origin.
The
i
-th person
(1\leq i\leq N)
is initially at a position
X_i
meters east from the origin.
The persons can move along the road to the east or ... | [
{
"input": "5\n10 20 30 40 50\n4\n3 45\n4 20\n1 35\n2 60\n",
"output": "239\n"
},
{
"input": "8\n0 1 2 3 4 5 6 100000000\n6\n1 100000000\n8 0\n1 100000000\n8 4\n1 100000000\n5 21006578\n",
"output": "4294967297\n"
},
{
"input": "12\n1558 3536 3755 3881 4042 4657 5062 7558 7721 8330 8542 ... |
https://atcoder.jp/contests/abc371/tasks/abc371_g | Problem Statement
You are given permutations
P = (P_1, P_2, \ldots, P_N)
and
A = (A_1, A_2, \ldots, A_N)
of
(1,2,\ldots,N)
.
You can perform the following operation any number of times, possibly zero:
replace
A_i
with
A_{P_i}
simultaneously
for all
i=1,2,\ldots,N
.
Print the lexicographically smallest
A
that can be obt... | [
{
"input": "6\n3 1 5 6 2 4\n4 3 1 6 2 5\n",
"output": "1 4 2 5 3 6\n"
},
{
"input": "8\n3 5 8 7 2 6 1 4\n1 2 3 4 5 6 7 8\n",
"output": "1 2 3 4 5 6 7 8\n"
},
{
"input": "26\n24 14 4 20 15 19 16 11 23 22 12 18 21 3 6 8 26 2 25 7 13 1 5 9 17 10\n15 3 10 1 13 19 22 24 20 4 14 23 7 26 25 18 ... |
https://atcoder.jp/contests/joi2025yo1a/tasks/joi2025_yo1a_a | 問題文
JOI 君の所持金は
A
円である.JOI 君は
1
本
5
円の鉛筆を最大で何本買えるかを求めよ. | [
{
"input": "9\n",
"output": "1\n"
},
{
"input": "10\n",
"output": "2\n"
},
{
"input": "3\n",
"output": "0\n"
},
{
"input": "100\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/joi2025yo1a/tasks/joi2025_yo1a_b | 問題文
JOI 君は,一直線の道路上で散歩をしている.
JOI 君は以下の行動を行動 A → 行動 B → 行動 A →
\cdots
のように交互に繰り返す.
行動 A:
3 \: \mathrm{m}
前に進む.
行動 B:
2 \: \mathrm{m}
後ろに戻る.
行動 A と行動 B を合わせて
X
回行ったとき,はじめの位置から何
\mathrm{m}
前に移動したことになるか? | [
{
"input": "3\n",
"output": "4\n"
},
{
"input": "6\n",
"output": "3\n"
},
{
"input": "1\n",
"output": "3\n"
},
{
"input": "37\n",
"output": "21\n"
},
{
"input": "100\n",
"output": "50\n"
}
] |
https://atcoder.jp/contests/joi2025yo1a/tasks/joi2025_yo1a_c | 問題文
長さ
N
の文字列
S
が与えられる.
S
の各文字は
J
,
O
,
I
のいずれかである.
S
の各文字について,
J
を
O
に,
O
を
I
に,
I
を
J
に変換した後の文字列を出力せよ. | [
{
"input": "3\nJOI\n",
"output": "OIJ\n"
},
{
"input": "10\nJOIOOJOOOJ\n",
"output": "OIJIIOIIIO\n"
}
] |
https://atcoder.jp/contests/joi2025yo1a/tasks/joi2025_yo1a_d | 問題文
JOI 君はどら焼きを作ろうとしている.
どら焼きはちょうど
1
つずつの餡と皮から作ることができ,すべての餡と皮には正の整数で表される「美味しさ」が定義されている.
1
から
N
までの番号が付けられた
N
種類の餡があり,餡
i
(
1 \leqq i \leqq N
) の美味しさは
A_i
である.また,
1
から
M
までの番号が付けられた
M
種類の皮があり,皮
j
(
1 \leqq j \leqq M
) の美味しさは
B_j
である.
JOI 君はこれらの餡と皮の組み合わせをすべて試し,
N \times M
個のどら焼きを作る.各どら焼きの美味しさは,餡と皮の美味しさの和に,餡と皮の美味しさのうち大きい方... | [
{
"input": "2 2\n1 2\n2 5\n",
"output": "79\n"
},
{
"input": "1 5\n50\n9 7 5 4 1\n",
"output": "13800\n"
},
{
"input": "15 5\n5 10 52 31 14 16 19 1 9 20 80 19 11 34 72\n20 2 4 9 19\n",
"output": "116756\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_a | Problem Statement
Takahashi decided to make takoyaki (octopus balls) and serve it to Snuke. Takahashi instructed Snuke to raise only his left hand if he wants to eat takoyaki, and only his right hand otherwise.
You are given the information about which hand Snuke is raising as two integers
L
and
R
.
He is raising his ... | [
{
"input": "1 0\n",
"output": "Yes\n"
},
{
"input": "1 1\n",
"output": "Invalid\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_b | Problem Statement
There are
N
types of elements numbered
1, 2, \ldots, N
.
Elements can be combined with each other. When elements
i
and
j
are combined, they transform into element
A_{i, j}
if
i \geq j
, and into element
A_{j, i}
if
i < j
.
Starting with element
1
, combine it with elements
1, 2, \ldots, N
in this orde... | [
{
"input": "4\n3\n2 4\n3 1 2\n2 1 2 4\n",
"output": "2\n"
},
{
"input": "5\n5\n5 5\n5 5 5\n5 5 5 5\n5 5 5 5 5\n",
"output": "5\n"
},
{
"input": "6\n2\n1 5\n1 6 3\n2 6 1 4\n2 1 1 1 6\n5 6 1 2 2 5\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_c | Problem Statement
You are given two strings
S
and
T
consisting of lowercase English letters. Here,
S
and
T
have equal lengths.
Let
X
be an empty array, and repeat the following operation until
S
equals
T
:
Change one character in
S
, and append
S
to the end of
X
.
Find the array of strings
X
with the minimum number of ... | [
{
"input": "adbe\nbcbc\n",
"output": "3\nacbe\nacbc\nbcbc\n"
},
{
"input": "abcde\nabcde\n",
"output": "0\n"
},
{
"input": "afwgebrw\noarbrenq\n",
"output": "8\naawgebrw\naargebrw\naarbebrw\naarbebnw\naarbebnq\naarbeenq\naarbrenq\noarbrenq\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_d | 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
j
-th column from the left.
Initially, there is one wall in each cell.
After processing
Q
queries explained below in the order they are given, find the number of remaining walls.
In the
q
-th query,... | [
{
"input": "2 4 3\n1 2\n1 2\n1 3\n",
"output": "2\n"
},
{
"input": "5 5 5\n3 3\n3 3\n3 2\n2 2\n1 2\n",
"output": "10\n"
},
{
"input": "4 3 10\n2 2\n4 1\n1 1\n4 2\n2 1\n3 1\n1 3\n1 2\n4 3\n4 2\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_e | Problem Statement
You are given a sequence
A = (A_1, A_2, \dots, A_N)
of length
N
and an integer
K
.
There are
2^{N-1}
ways to divide
A
into several contiguous subsequences. How many of these divisions have no subsequence whose elements sum to
K
? Find the count modulo
998244353
.
Here, "to divide
A
into several contig... | [
{
"input": "3 3\n1 2 3\n",
"output": "2\n"
},
{
"input": "5 0\n0 0 0 0 0\n",
"output": "0\n"
},
{
"input": "10 5\n-5 -1 -7 6 -6 -2 -5 10 2 -10\n",
"output": "428\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_f | Problem Statement
There is a circular cake divided into
N
pieces by cut lines. Each cut line is a line segment connecting the center of the circle to a point on the arc.
The pieces and cut lines are numbered
1, 2, \ldots, N
in clockwise order, and piece
i
has a mass of
A_i
. Piece
1
is also called piece
N + 1
.
Cut lin... | [
{
"input": "5 2\n3 6 8 6 4\n",
"output": "13 1\n"
},
{
"input": "6 3\n4 7 11 3 9 2\n",
"output": "11 1\n"
},
{
"input": "10 3\n2 9 8 1 7 9 1 3 5 8\n",
"output": "17 4\n"
}
] |
https://atcoder.jp/contests/abc370/tasks/abc370_g | Problem Statement
We call a positive integer
n
a good integer if and only if the sum of its positive divisors is divisible by
3
.
You are given two positive integers
N
and
M
. Find the number, modulo
998244353
, of length-
M
sequences
A
of positive integers such that the product of the elements in
A
is a good integer n... | [
{
"input": "10 1\n",
"output": "5\n"
},
{
"input": "4 2\n",
"output": "2\n"
},
{
"input": "370 907\n",
"output": "221764640\n"
},
{
"input": "10000000000 100000\n",
"output": "447456146\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_a | Problem Statement
You are given two integers
A
and
B
.
How many integers
x
satisfy the following condition?
Condition: It is possible to arrange the three integers
A
,
B
, and
x
in some order to form an arithmetic sequence.
A sequence of three integers
p
,
q
, and
r
in this order is an arithmetic sequence if and only i... | [
{
"input": "5 7\n",
"output": "3\n"
},
{
"input": "6 1\n",
"output": "2\n"
},
{
"input": "3 3\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_b | Problem Statement
Takahashi has a piano with
100
keys arranged in a row.
The
i
-th key from the left is called key
i
.
He will play music by pressing
N
keys one by one.
For the
i
-th press, he will press key
A_i
, using his left hand if
S_i=
L
, and his right hand if
S_i=
R
.
Before starting to play, he can place bot... | [
{
"input": "4\n3 L\n6 R\n9 L\n1 R\n",
"output": "11\n"
},
{
"input": "3\n2 L\n2 L\n100 L\n",
"output": "98\n"
},
{
"input": "8\n22 L\n75 L\n26 R\n45 R\n72 R\n81 R\n47 L\n29 R\n",
"output": "188\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_c | Problem Statement
You are given a sequence of
N
positive integers
A=(A_1,A_2,\dots,A_N)
.
Find the number of pairs of integers
(l,r)
satisfying
1\leq l\leq r\leq N
such that the subsequence
(A_l,A_{l+1},\dots,A_r)
forms an arithmetic progression.
A sequence
(x_1,x_2,\dots,x_{|x|})
is an arithmetic progression if and on... | [
{
"input": "4\n3 6 9 3\n",
"output": "8\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "15\n"
},
{
"input": "8\n87 42 64 86 72 58 44 30\n",
"output": "22\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_d | Problem Statement
Takahashi will encounter
N
monsters in order. The
i
-th monster
(1\leq i\leq N)
has a strength of
A_i
.
For each monster, he can choose to either let it go or defeat it.
Each action awards him experience points as follows:
If he lets a monster go, he gains
0
experience points.
If he defeats a monster ... | [
{
"input": "5\n1 5 3 2 7\n",
"output": "28\n"
},
{
"input": "2\n1000000000 1000000000\n",
"output": "3000000000\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_e | Problem Statement
There are
N
islands and
M
bidirectional bridges connecting two islands. The islands and bridges are numbered
1
,
2
,
\ldots
,
N
and
1
,
2
,
\ldots
,
M
, respectively.
Bridge
i
connects islands
U_i
and
V_i
, and the time it takes to cross it in either direction is
T_i
.
No bridge connects an island to ... | [
{
"input": "3 5\n1 2 10\n1 3 20\n1 3 30\n2 3 15\n2 3 25\n2\n1\n1\n2\n3 5\n",
"output": "25\n70\n"
},
{
"input": "6 6\n1 5 1\n2 5 1\n2 4 1\n3 4 1\n3 6 1\n1 6 1\n2\n5\n1 2 3 4 5\n1\n5\n",
"output": "5\n3\n"
},
{
"input": "5 5\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\... |
https://atcoder.jp/contests/abc369/tasks/abc369_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
j
-th column from the left.
There are
N
coins on this grid, and the
i
-th coin can be picked up by passing through the cell
(R_i,C_i)
.
Your goal is to start from cell
(1,1)
, repeatedly move either... | [
{
"input": "3 4 4\n3 3\n2 1\n2 3\n1 4\n",
"output": "3\nDRRDR\n"
},
{
"input": "2 2 2\n2 1\n1 2\n",
"output": "1\nDR\n"
},
{
"input": "10 15 8\n2 7\n2 9\n7 9\n10 3\n7 11\n8 12\n9 6\n8 1\n",
"output": "5\nDRRRRRRRRDDDDDRRDRDDRRR\n"
}
] |
https://atcoder.jp/contests/abc369/tasks/abc369_g | Problem Statement
You are given a tree with
N
vertices.
The vertices are numbered
1
,
2
,
\ldots
,
N
.
The
i
-th edge (
1\leq i\leq N-1
) connects vertices
U_i
and
V_i
, with a length of
L_i
.
For each
K=1,2,\ldots, N
, solve the following problem.
Takahashi and Aoki play a game. The game proceeds as follows.
First, A... | [
{
"input": "5\n1 2 3\n2 3 5\n2 4 2\n1 5 3\n",
"output": "16\n22\n26\n26\n26\n"
},
{
"input": "3\n1 2 1000000000\n2 3 1000000000\n",
"output": "4000000000\n4000000000\n4000000000\n"
}
] |
https://atcoder.jp/contests/arc183/tasks/arc183_a | Problem Statement
You are given positive integers
N
and
K
.
An integer sequence of length
NK
where each integer from
1
to
N
appears exactly
K
times is called a
good
integer sequence.
Let
S
be the number of good integer sequences.
Find the
\operatorname{floor}((S+1)/2)
-th good integer sequence in lexicographical order... | [
{
"input": "2 2\n",
"output": "1 2 2 1\n"
},
{
"input": "1 5\n",
"output": "1 1 1 1 1\n"
},
{
"input": "6 1\n",
"output": "3 6 5 4 2 1\n"
},
{
"input": "3 3\n",
"output": "2 2 2 1 3 3 3 1 1\n"
}
] |
https://atcoder.jp/contests/arc183/tasks/arc183_b | Problem Statement
You are given integer sequences of length
N
:
A=(A_1,A_2,\cdots,A_N)
and
B=(B_1,B_2,\cdots,B_N)
, and an integer
K
.
You can perform the following operation zero or more times.
Choose integers
i
and
j
(
1 \leq i,j \leq N
).
Here,
|i-j| \leq K
must hold.
Then, change the value of
A_i
to
A_j
.
Determi... | [
{
"input": "4\n3 1\n1 1 2\n1 2 2\n5 4\n2 4 5 1 3\n2 1 3 2 2\n13 1\n3 1 3 3 5 3 3 4 2 2 2 5 1\n5 3 3 3 4 2 2 2 2 5 5 1 3\n20 14\n10 6 6 19 13 16 15 15 2 10 2 16 9 12 2 6 13 5 5 9\n5 9 6 2 10 19 16 15 13 12 10 2 9 6 5 16 19 12 15 13\n",
"output": "Yes\nYes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/arc183/tasks/arc183_c | Problem Statement
Find the number, modulo
998244353
, of permutations
P=(P_1,P_2,\cdots,P_N)
of
(1,2,\cdots,N)
that satisfy all of the following
M
conditions.
The
i
-th condition: The maximum among
P_{L_i},P_{L_i+1},\cdots,P_{R_i}
is
not
P_{X_i}
.
Here,
L_i
,
R_i
, and
X_i
are integers given in the input. | [
{
"input": "3 2\n1 3 2\n1 2 1\n",
"output": "1\n"
},
{
"input": "5 1\n1 1 1\n",
"output": "0\n"
},
{
"input": "10 5\n3 8 4\n3 10 4\n1 7 2\n1 8 3\n3 8 7\n",
"output": "1598400\n"
},
{
"input": "15 17\n2 11 9\n2 15 13\n1 14 2\n5 11 5\n3 15 11\n1 6 2\n4 15 12\n3 11 6\n9 13 10\n2... |
https://atcoder.jp/contests/arc183/tasks/arc183_d | Problem Statement
There is a tree with
N
vertices numbered from
1
to
N
.
The
i
-th edge connects vertices
A_i
and
B_i
.
Here,
N
is even, and furthermore, this tree has a perfect matching.
Specifically, for each
i
(
1 \leq i \leq N/2
), it is guaranteed that
A_i=i \times 2-1
and
B_i=i \times 2
.
You will perform the ... | [
{
"input": "4\n1 2\n3 4\n2 3\n",
"output": "4 1\n2 3\n"
},
{
"input": "8\n1 2\n3 4\n5 6\n7 8\n2 3\n1 5\n1 7\n",
"output": "4 8\n7 6\n5 3\n2 1\n"
},
{
"input": "14\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n2 8\n4 11\n5 12\n7 13\n11 14\n9 13\n",
"output": "1 6\n5 2\n8 12\n3 7\n10 4\n11 ... |
https://atcoder.jp/contests/arc183/tasks/arc183_e | Problem Statement
There is a rooted tree with
N
vertices numbered from
1
to
N
.
The root is vertex
1
, and the parent of vertex
i
(
2 \leq i \leq N
) is vertex
P_i
(
P_i<i
).
There are also integer sequences of length
M
:
A=(A_1,A_2,\cdots,A_M)
and
B=(B_1,B_2,\cdots,B_M)
, consisting of integers between
1
and
N
, inclu... | [
{
"input": "3 3\n1 2\n1 2 1\n1 2 3\n",
"output": "2\n"
},
{
"input": "4 3\n1 1 1\n2 3 4\n2 3 4\n",
"output": "1\n"
},
{
"input": "8 13\n1 2 2 3 4 4 3\n5 3 2 5 4 6 2 8 2 6 7 4 7\n5 5 8 5 6 6 5 8 3 6 7 4 7\n",
"output": "8\n"
},
{
"input": "30 27\n1 2 1 1 5 1 7 1 5 10 1 12 12 1... |
https://atcoder.jp/contests/arc183/tasks/arc183_f | Problem Statement
You are given positive integers
A
,
B
,
X
,
Y
, and
N
.
Here, the following is guaranteed:
A<B
\gcd(A,B)=1
1 \leq N \leq A+B-1
For an integer
n
, define
f(n)
as follows:
You start with an integer
x=0
.
f(n)
is the minimum total cost to achieve
x=n
by repeatedly performing the following operations.
Re... | [
{
"input": "4\n1 2 1 1 2\n3 5 2 4 6\n79 85 72 95 4\n80980429 110892168 22712439 520643153 66132787\n",
"output": "2\n34\n18111\n785776602\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_a | Problem Statement
There is a stack of
N
cards, and the
i
-th card from the top has an integer
A_i
written on it.
You take
K
cards from the bottom of the stack and place them on top of the stack, maintaining their order.
Print the integers written on the cards from top to bottom after the operation. | [
{
"input": "5 3\n1 2 3 4 5\n",
"output": "3 4 5 1 2\n"
},
{
"input": "6 2\n1 2 1 2 1 2\n",
"output": "1 2 1 2 1 2\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_b | Problem Statement
You are given a sequence of
N
positive integers
A = (A_1, A_2, \dots ,A_N)
. Takahashi repeats the following operation until
A
contains one or fewer positive elements:
Sort
A
in descending order. Then, decrease both
A_1
and
A_2
by
1
.
Find the number of times he performs this operation. | [
{
"input": "4\n1 2 3 3\n",
"output": "4\n"
},
{
"input": "3\n1 1 100\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_c | Problem Statement
You are playing a game.
There are
N
enemies lined up in a row, and the
i
-th enemy from the front has a health of
H_i
.
You will repeat the following action until the healths of all enemies become
0
or less, using a variable
T
initialized to
0
.
Increase
T
by
1
. Then, attack the frontmost enemy with ... | [
{
"input": "3\n6 2 2\n",
"output": "8\n"
},
{
"input": "9\n1 12 123 1234 12345 123456 1234567 12345678 123456789\n",
"output": "82304529\n"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "3000000000\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_d | Problem Statement
You are given a tree with
N
vertices numbered
1
to
N
. The
i
-th edge connects vertices
A_i
and
B_i
.
Consider a tree that can be obtained by removing some (possibly zero) edges and vertices from this graph. Find the minimum number of vertices in such a tree that includes all of
K
specified vertices
V... | [
{
"input": "7 3\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n1 3 5\n",
"output": "4\n"
},
{
"input": "4 4\n3 1\n1 4\n2 1\n1 2 3 4\n",
"output": "4\n"
},
{
"input": "5 1\n1 4\n2 3\n5 2\n1 2\n1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_e | Problem Statement
In the nation of Atcoder, there are
N
cities numbered
1
to
N
, and
M
trains numbered
1
to
M
.
Train
i
departs from city
A_i
at time
S_i
and arrives at city
B_i
at time
T_i
.
Given a positive integer
X_1
, find a way to set non-negative integers
X_2,\ldots,X_M
that satisfies the following condition wi... | [
{
"input": "3 6 15\n1 2 10 20\n1 2 20 30\n2 3 25 40\n2 3 35 50\n3 1 15 30\n3 1 45 60\n",
"output": "0 10 0 0 5\n"
},
{
"input": "10 9 100\n1 10 0 1\n10 2 1 100\n10 3 1 100\n10 4 1 100\n10 5 1 100\n10 6 1 100\n10 7 1 100\n10 8 1 100\n10 9 1 100\n",
"output": "100 100 100 100 100 100 100 100\n"
... |
https://atcoder.jp/contests/abc368/tasks/abc368_f | Problem Statement
You are given a sequence of
N
positive integers
A = (A_1, A_2, \dots ,A_N)
, where each element is at least
2
. Anna and Bruno play a game using these integers. They take turns, with Anna going first, performing the following operation.
Choose an integer
i \ (1 \leq i \leq N)
freely. Then, freely choo... | [
{
"input": "3\n2 3 4\n",
"output": "Anna\n"
},
{
"input": "4\n2 3 4 6\n",
"output": "Bruno\n"
}
] |
https://atcoder.jp/contests/abc368/tasks/abc368_g | Problem Statement
You are given sequences of positive integers
A
and
B
of length
N
. Process
Q
queries given in the following forms in the order they are given. Each query is of one of the following three types.
Type
1
: Given in the form
1 i x
. Replace
A_i
with
x
.
Type
2
: Given in the form
2 i x
. Replace
B_i
with
... | [
{
"input": "3\n3 2 4\n1 2 2\n3\n3 1 3\n1 1 1\n3 1 3\n",
"output": "12\n7\n"
},
{
"input": "6\n65 32 12 5 8 312\n4 1 3 15 16 2\n6\n3 2 6\n3 1 5\n1 5 6\n2 4 9\n3 2 6\n3 3 5\n",
"output": "46080\n69840\n27648\n1728\n"
}
] |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_a | 問題文
長さ
N
の正整数列
A=(A_1,A_2,\cdots,A_N)
が与えられます.
以降,
S=\sum_{1 \leq i \leq N} A_i
とおきます.
長さ
S
の整数列
x
は以下の条件をすべて満たすとき(そしてそのときのみ)
good
であると言います.
x
の各要素は
1
以上
N
以下
各整数
i
(
1 \leq i \leq N
) について,
x
はちょうど
A_i
個の
i
を含む
整数列
x=(x_1,x_2,\cdots,x_S)
に対し,
x_i>x_{i+1}
を満たす index
i
の個数を
f(x)
と表すことにします.
good な整数列
x
を一様ランダムにとるときの
f(x)... | [
{
"input": "2\n1 2\n",
"output": "665496236\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "2\n"
},
{
"input": "2\n2024 824\n",
"output": "841217737\n"
},
{
"input": "10\n19237224 3435339 227368010 836006 153314679 115537801 189694444 76016030 159566203 53238564\n",
"output... |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_b | 問題文
整数
N
が与えられます.
集合
S
を
S=\{1,2,\cdots,N\}
で初期化します.
その後,
S
が空になるまで次の操作を繰り返します.
S
の要素を一様ランダムに
1
つ選び,それを
v
とおく.
S
から
v
の倍数をすべて削除する.
操作回数の期待値を
\pmod{998244353}
で求めてください.
期待値
\pmod{998244353}
の定義
求める期待値は必ず有理数になることが証明できます. また,この問題の制約のもとでは,その値を既約分数
\frac{P}{Q}
で表した時,
Q \neq 0 \pmod{998244353}
となることも証明できます. よって,
R \times Q \... | [
{
"input": "2\n",
"output": "499122178\n"
},
{
"input": "6\n",
"output": "582309209\n"
},
{
"input": "23\n",
"output": "515759591\n"
},
{
"input": "5000000000\n",
"output": "64399530\n"
}
] |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_c | 問題文
長さ
N
の整数列
A=(A_1,A_2,\cdots,A_N)
と整数
K
が与えられます.
あなたは
A
のコピーを
K
個並べて連結し,長さ
NK
の整数列
x=(x_1,x_2,\cdots,x_{NK})
を得ました.
あなたはこれから次の操作をちょうど
1
回行います.
x
の(連続とは限らない)(空でもよい)部分列を選び,その要素を逆順に並べ替える.
より正確に述べれば,index の列
1 \leq i_1<i_2<\cdots<i_s \leq NK
(列の長さ
s
も任意) を選び,各
1 \leq j \leq s
に対して
x_{i_j}
の値を
x_{i_{s-j+1}}
で置き換える.
この置き換... | [
{
"input": "2 2\n1 2\n",
"output": "6\n"
},
{
"input": "3 2\n3 3 3\n",
"output": "1\n"
},
{
"input": "5 3\n1 2 3 4 5\n",
"output": "9216\n"
},
{
"input": "30 1000000000000\n8 3 8 10 1 5 3 1 6 4 3 6 2 6 6 9 5 5 8 3 3 4 10 2 3 2 8 10 8 1\n",
"output": "401626004\n"
}
] |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_d | 問題文
数列
a=(a_1,a_2,\cdots,a_k)
に対し,
f(a)
を以下のように定めます.
f(a)=\sum_{1 \leq i \leq k} \min(a_1,a_2,\cdots,a_i)
長さ
N
の整数列
A=(A_1,A_2,\cdots,A_N)
が与えられます.
整数列
A
を
2
つの(連続とは限らない)(空でもよい)部分列に分解し,それらを
X_1,X_2
とおきます.
分解の際,
A
の各要素がちょうど
1
つの部分列に含まれるようにします.
f(X_1)+f(X_2)
としてありうる最大値を求めてください. | [
{
"input": "6\n5 3 6 1 4 7\n",
"output": "23\n"
},
{
"input": "10\n22 7 20 26 1 11 7 1 15 10\n",
"output": "104\n"
},
{
"input": "15\n140039457 164832983 239276621 245532751 274195604 320064892 499774361 419370025 249168130 521915711 744280520 561032101 857077284 543856068 910500852\n",
... |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_e | 問題文
1
から
N
までの番号のついた
N
頂点からなる根付き木
T
があります.
根は頂点
1
で,頂点
i
(
2 \leq i \leq N
) の親は頂点
P_i
(
P_i<i
) です.
この木の辺は有向辺で,各辺は親から子の方向へ向いています.
あなたは
T
に
M
本の辺を追加し,有向グラフ
G
を作りました.
i
番目に追加した辺は,頂点
A_i
から頂点
B_i
へ向かう辺でした.
ここで,
A_i,B_i
は以下の条件を満たすことが保証されます.
1 \leq B_i<A_i \leq N
T
において頂点
A_i
は頂点
B_i
の子孫である
T
において頂点
A_i
は葉でない
なお,同じ辺を複数本追加す... | [
{
"input": "3 0\n1 2\n",
"output": "2 998244353\n"
},
{
"input": "3 1\n1 2\n2 1\n",
"output": "4 998244353\n"
},
{
"input": "7 5\n1 2 2 4 4 3\n3 1\n2 1\n3 2\n4 2\n3 2\n",
"output": "453747441 998244353\n"
},
{
"input": "20 25\n1 2 3 2 5 2 6 1 9 2 2 12 13 1 2 16 17 16 19\n13 1... |
https://atcoder.jp/contests/jsc2024-final/tasks/jsc2024_final_f | 問題文
1
から
N
までの番号がついた
N
頂点からなる DAG が与えられます.
辺は
M
本あり,
i
番目の辺は頂点
U_i
から頂点
V_i
に向かう辺です.
ここで,
U_i<V_i
が保証されます.
各頂点には整数が書かれており,頂点
i
には整数
A_i
が書かれています.
頂点の部分集合
s
に対し,
f(s)
を以下のように定めます.
f(s)=\sum_{v \in s} \min\{A_u\ |\ u \in s
かつ DAG において頂点
u
から頂点
v
へ移動できる
\}
各整数
K=1,2,\cdots,N
について,以下の問題に答えてください.
頂点集合
\{1,2,\cdots,N\}
を
K
個... | [
{
"input": "4 4\n1 2 3 4\n1 2\n1 3\n2 4\n3 4\n",
"output": "4 8 10 10\n"
},
{
"input": "10 9\n22 7 20 26 1 11 7 1 15 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n",
"output": "49 104 120 120 120 120 120 120 120 120\n"
},
{
"input": "15 13\n20 12 14 20 22 20 26 34 40 42 44 60 45 69 7... |
https://atcoder.jp/contests/ahc036/tasks/ahc036_a | Problem Statement
Country Y has
N
cities and
M
roads, where the
i
-th road connects city
u_i
and city
v_i
bidirectionally. None of the roads intersect, and the graph consisting of cities and roads is a planar graph.
Each city has a
traffic signal
to control the traffic entering the city.
The si... | [
{
"input": "7 9 3 7 4\n0 1\n0 2\n0 3\n1 2\n2 3\n3 4\n4 5\n5 6\n6 0\n4 1 5\n100 0\n200 0\n200 100\n100 100\n0 200\n0 100\n0 0\n",
"output": "0 1 3 4 5 6 2\ns 4 0 0\nm 3\nm 4\nm 3\nm 0\nm 1\ns 2 4 2\nm 0\nm 6\nm 5\n"
}
] |
https://atcoder.jp/contests/agc067/tasks/agc067_a | Problem Statement
You are given a simple undirected graph
G
with
N
vertices numbered
1
to
N
.
G
has
M
edges and the
i
-th edge connects vertices
A_i
and
B_i
.
Check if
G
satisfies the following condition:
For every subset
X
of the vertex set
\{1,2,\cdots,N\}
, there exists a subset
Y
of
X
such that
|Y|\ge \frac{|X|}{2}... | [
{
"input": "4\n3 3\n1 2\n1 3\n2 3\n3 2\n1 2\n1 3\n3 1\n1 2\n3 0\n",
"output": "Yes\nYes\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/agc067/tasks/agc067_b | Problem Statement
You have an integer sequence
a=(a_1,a_2,\cdots,a_N)
of length
N
.
All elements are initially
0
.
You are given an integer
C
and
M
intervals
([L_1,R_1],[L_2,R_2],\cdots,[L_M,R_M])
.
You will choose a permutation
p
of
(1,2,\cdots,M)
and an integer sequence
w=(w_1,w_2,\cdots,w_M)
of length
M
.
Here,
1\le... | [
{
"input": "5 5 2\n1 3\n2 2\n3 3\n1 5\n3 5\n",
"output": "16\n"
},
{
"input": "20 30 20\n1 14\n1 7\n1 16\n3 13\n1 17\n4 8\n2 11\n4 12\n9 14\n3 15\n11 19\n1 13\n4 15\n8 19\n3 17\n15 18\n10 18\n1 18\n17 19\n16 20\n1 8\n8 15\n13 17\n1 19\n13 19\n1 20\n6 13\n10 12\n11 20\n17 18\n",
"output": "258066... |
https://atcoder.jp/contests/agc067/tasks/agc067_c | Problem Statement
We call an infinite sequence of positive integers
(a_1,a_2,\cdots)
good
if and only if it satisfies both of the following conditions:
There exists a finite constant
C
such that
a_n \le C \cdot n
for all
1 \le n
;
For all pairs of positive integers
(n,m)
,
a_n \mid a_m
if and only if
n\mid m
. Here,
x ... | [
{
"input": "5\n5\n1 2 3 4 5\n5\n1 4 9 16 25\n5\n1 4 6 8 10\n5\n1 2 4 4 5\n5\n1 2 3 5 4\n",
"output": "Yes\nYes\nYes\nNo\nNo\n"
}
] |
https://atcoder.jp/contests/agc067/tasks/agc067_d | Problem Statement
You are given an integer
N
and prime
P
.
We call a sequence of
N
intervals
([L_1,R_1] ,[L_2,R_2], \cdots, [L_N,R_N])
good
if and only if both of the followings are satisfied:
1\le L_i\le R_i\le N
holds for all
1\le i\le N
.
There exists a
unique
permutation
x=(x_1,x_2,\cdots,x_N)
of
(1,2,\cdots,N)
suc... | [
{
"input": "2 1005488041\n",
"output": "6\n"
},
{
"input": "5 1005488041\n",
"output": "102960\n"
},
{
"input": "100 1005488041\n",
"output": "47599495\n"
},
{
"input": "1000 1005488041\n",
"output": "632708165\n"
}
] |
https://atcoder.jp/contests/agc067/tasks/agc067_e | Problem Statement
You are given an integer
N
and a prime
P
.
Count the number, modulo
P
, of undirected connected graphs
G
of
N
vertices numbered
1
to
N
that satisfy the following condition:
There are no self-loops in
G
. Note that multiple edges are allowed.
For all edges
(u,v)
in
G
, if we delete
(u,v)
from
G
,
G
rem... | [
{
"input": "2 1005976817\n",
"output": "1\n"
},
{
"input": "5 1000837403\n",
"output": "372\n"
},
{
"input": "10 1001160547\n",
"output": "789846604\n"
},
{
"input": "20 1006779551\n",
"output": "888612770\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_a | Problem Statement
In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at
A
o'clock every day.
Takahashi, who lives in the Kingdom of AtCoder, goes to bed at
B
o'clock and wakes up at
C
o'clock every day (in the
24
-hour clock). He can shout his love for takoyaki when he is awake, but cann... | [
{
"input": "21 8 14\n",
"output": "Yes\n"
},
{
"input": "0 21 7\n",
"output": "No\n"
},
{
"input": "10 7 17\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_b | Problem Statement
A real number
X
is given to the third decimal place.
Print the real number
X
under the following conditions.
The decimal part must not have trailing
0
s.
There must not be an unnecessary trailing decimal point. | [
{
"input": "1.012\n",
"output": "1.012\n"
},
{
"input": "12.340\n",
"output": "12.34\n"
},
{
"input": "99.900\n",
"output": "99.9\n"
},
{
"input": "0.000\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_c | Problem Statement
Print all integer sequences of length
N
that satisfy the following conditions, in ascending lexicographical order.
The
i
-th element is between
1
and
R_i
, inclusive.
The sum of all elements is a multiple of
K
.
What is lexicographical order for sequences?
A sequence
A = (A_1, \ldots, A_{|A|})
is
lexi... | [
{
"input": "3 2\n2 1 3\n",
"output": "1 1 2\n2 1 1\n2 1 3\n"
},
{
"input": "1 2\n1\n",
"output": "\n"
},
{
"input": "5 5\n2 3 2 3 2\n",
"output": "1 1 1 1 1\n1 2 2 3 2\n1 3 1 3 2\n1 3 2 2 2\n1 3 2 3 1\n2 1 2 3 2\n2 2 1 3 2\n2 2 2 2 2\n2 2 2 3 1\n2 3 1 2 2\n2 3 1 3 1\n2 3 2 1 2\n2 3 2... |
https://atcoder.jp/contests/abc367/tasks/abc367_d | Problem Statement
There are
N
rest areas around a lake.
The rest areas are numbered
1
,
2
, ...,
N
in clockwise order.
It takes
A_i
steps to walk clockwise from rest area
i
to rest area
i+1
(where rest area
N+1
refers to rest area
1
).
The minimum number of steps required to walk clockwise from rest area
s
to rest area... | [
{
"input": "4 3\n2 1 4 3\n",
"output": "4\n"
},
{
"input": "2 1000000\n1 1\n",
"output": "0\n"
},
{
"input": "9 5\n9 9 8 2 4 4 3 5 3\n",
"output": "11\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_e | Problem Statement
You are given a sequence
X
of length
N
where each element is between
1
and
N
, inclusive, and a sequence
A
of length
N
.
Print the result of performing the following operation
K
times on
A
.
Replace
A
with
B
such that
B_i = A_{X_i}
. | [
{
"input": "7 3\n5 2 6 3 1 4 6\n1 2 3 5 7 9 11\n",
"output": "7 2 3 5 1 9 3\n"
},
{
"input": "4 0\n3 4 1 2\n4 3 2 1\n",
"output": "4 3 2 1\n"
},
{
"input": "9 1000000000000000000\n3 7 8 5 9 3 7 4 2\n9 9 8 2 4 4 3 5 3\n",
"output": "3 3 3 3 3 3 3 3 3\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_f | Problem Statement
You are given sequences of positive integers of length
N
:
A=(A_1,A_2,\ldots,A_N)
and
B=(B_1,B_2,\ldots,B_N)
.
You are given
Q
queries to process in order. The
i
-th query is explained below.
You are given positive integers
l_i,r_i,L_i,R_i
. Print
Yes
if it is possible to rearrange the subsequence
(A_... | [
{
"input": "5 4\n1 2 3 2 4\n2 3 1 4 2\n1 3 1 3\n1 2 3 5\n1 4 2 5\n1 5 1 5\n",
"output": "Yes\nNo\nNo\nYes\n"
},
{
"input": "4 4\n4 4 4 4\n4 4 4 4\n1 2 2 3\n3 3 1 1\n1 3 1 4\n1 4 2 3\n",
"output": "Yes\nYes\nNo\nNo\n"
}
] |
https://atcoder.jp/contests/abc367/tasks/abc367_g | Problem Statement
You are given positive integers
N
,
M
,
K
, and a sequence of non-negative integers:
A=(A_1,A_2,\ldots,A_N)
.
For a non-empty non-negative integer sequence
B=(B_1,B_2,\ldots,B_{|B|})
, we define its
score
as follows.
If the length of
B
is a multiple of
M
:
(B_1 \oplus B_2 \oplus \dots \oplus B_{|B|})^... | [
{
"input": "3 2 2\n1 2 3\n",
"output": "14\n"
},
{
"input": "10 5 3\n100 100 100 100 100 100 100 100 100 100\n",
"output": "252000000\n"
},
{
"input": "16 4 100\n7053 3876 3178 8422 7802 5998 2334 6757 6889 6637 7365 9495 7848 9026 7312 6558\n",
"output": "432440016\n"
}
] |
https://atcoder.jp/contests/arc182/tasks/arc182_a | Problem Statement
There is an integer sequence
S
of length
N
. Initially, all elements of
S
are
0
.
You are also given two integer sequences of length
Q
:
P=(P_1,P_2,\dots,P_Q)
and
V=(V_1,V_2,\dots,V_Q)
.
Snuke wants to perform
Q
operations on the sequence
S
in order. The
i
-th operation is as follows:
Perform one of t... | [
{
"input": "8 3\n1 8\n8 1\n2 1\n",
"output": "1\n"
},
{
"input": "8 3\n8 1\n1 8\n1 2\n",
"output": "0\n"
},
{
"input": "241 82\n190 3207371\n229 3639088\n61 4428925\n84 17258698\n34 42692503\n207 59753183\n180 67198566\n78 99285033\n60 102449991\n234 122146510\n111 126959145\n141 1523315... |
https://atcoder.jp/contests/arc182/tasks/arc182_b | Problem Statement
You are given positive integers
N
and
K
.
An integer sequence of length
N
where all elements are between
1
and
2^K - 1
, inclusive, is called a
good sequence
.
The
score
of a good sequence
A=(A_1,A_2,\ldots,A_N)
is defined as follows:
The number of distinct integers that can be expressed as
\displayst... | [
{
"input": "3\n3 3\n7 2\n8 20\n",
"output": "5 6 7\n2 2 3 3 1 3 3\n662933 967505 876482 840117 1035841 651549 543175 781219\n"
}
] |
https://atcoder.jp/contests/arc182/tasks/arc182_c | Problem Statement
An integer sequence of length between
1
and
N
, inclusive, where each element is between
1
and
M
, inclusive, is called a
good sequence
.
The
score
of a good sequence is defined as the number of positive divisors of
X
, where
X
is the product of the elements in the sequence.
There are
\displaystyle \s... | [
{
"input": "1 7\n",
"output": "16\n"
},
{
"input": "3 11\n",
"output": "16095\n"
},
{
"input": "81131 14\n",
"output": "182955659\n"
}
] |
https://atcoder.jp/contests/arc182/tasks/arc182_d | Problem Statement
An integer sequence where no two adjacent elements are the same is called a
good sequence
.
You are given two good sequences of length
N
:
A=(A_1,A_2,\dots,A_N)
and
B=(B_1,B_2,\dots,B_N)
. Each element of
A
and
B
is between
0
and
M-1
, inclusive.
You can perform the following operations on
A
any numbe... | [
{
"input": "3 9\n2 0 1\n4 8 1\n",
"output": "3\n"
},
{
"input": "3 9\n1 8 2\n1 8 2\n",
"output": "0\n"
},
{
"input": "24 182\n128 115 133 52 166 92 164 119 143 99 54 162 86 2 59 166 24 78 81 5 109 67 172 99\n136 103 136 28 16 52 2 85 134 64 123 74 64 28 85 161 19 74 14 110 125 104 180 75... |
https://atcoder.jp/contests/arc182/tasks/arc182_e | Problem Statement
You are given positive integers
N
,
M
,
K
, a non-negative integer
C
, and an integer sequence
A=(A_1, A_2, \ldots, A_N)
of length
N
.
Find
\displaystyle \sum_{k=0}^{K-1}\min_{1\le i\le N}\lbrace(Ck+A_i)\ \mathrm{mod}\ M \rbrace
. | [
{
"input": "2 5 3 3\n1 3\n",
"output": "4\n"
},
{
"input": "5 4 3 182\n0 3 2 1 2\n",
"output": "0\n"
},
{
"input": "5 718 651 193855\n3 532 44 109 58\n",
"output": "29484897\n"
}
] |
https://atcoder.jp/contests/arc182/tasks/arc182_f | Problem Statement
You are given integers
N
and
Q
, and two integer sequences of length
Q
:
A=(A_1,A_2,\ldots,A_Q)
and
B=(B_1,B_2,\ldots, B_Q)
.
For each
k=1,2,\ldots,Q
, solve the following problem:
There is an undirected graph with
N
vertices numbered from
0
to
N-1
and
N
edges. The
i
-th edge
(0 \le i < N)
connects ve... | [
{
"input": "6 3\n2 1\n0 1\n1 0\n",
"output": "2\n1\n6\n"
},
{
"input": "11 3\n9 1\n5 3\n8 0\n",
"output": "3\n3\n2\n"
},
{
"input": "182 3\n61 2\n77 88\n180 55\n",
"output": "36\n14\n9\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_a | Problem Statement
A mayoral election is being held in AtCoder City. The candidates are Takahashi and Aoki.
There are
N
valid votes cast for either of the two candidates, and the counting is currently underway. Here,
N
is an odd number.
The current vote count is
T
votes for Takahashi and
A
votes for Aoki.
Determine if t... | [
{
"input": "7 4 2\n",
"output": "Yes\n"
},
{
"input": "99 12 48\n",
"output": "No\n"
},
{
"input": "1 0 0\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_b | Problem Statement
You are given a horizontally written text. Convert it to vertical writing, filling spaces with
*
.
You are given
N
strings
S_1, S_2, \dots, S_N
consisting of lowercase English letters. Let
M
be the maximum length of these strings.
Print
M
strings
T_1, T_2, \dots, T_M
that satisfy the following conditi... | [
{
"input": "3\nabc\nde\nfghi\n",
"output": "fda\ngeb\nh*c\ni\n"
},
{
"input": "3\natcoder\nbeginner\ncontest\n",
"output": "cba\noet\nngc\ntio\nend\nsne\nter\n*r\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_c | Problem Statement
You have an empty bag.
You are given
Q
queries, which must be processed in order.
There are three types of queries.
1 x
: Put one ball with the integer
x
written on it into the bag.
2 x
: Remove one ball with the integer
x
written on it from the bag and discard it. It is guaranteed that the bag has a... | [
{
"input": "8\n1 3\n1 1\n1 4\n3\n2 1\n3\n1 5\n3\n",
"output": "3\n2\n3\n"
},
{
"input": "8\n1 2\n1 2\n3\n2 2\n1 4\n1 4\n2 2\n3\n",
"output": "1\n1\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_d | Problem Statement
You are given a positive integer
N
, and an integer
A_{x,y,z}
for each triple of integers
(x, y, z)
such that
1 \leq x, y, z \leq N
.
You will be given
Q
queries in the following format, which must be processed in order.
For the
i
-th query
(1 \leq i \leq Q)
, you are given a tuple of integers
(Lx_i, ... | [
{
"input": "2\n1 2\n3 4\n5 6\n7 8\n2\n1 2 2 2 1 1\n2 2 1 2 1 2\n",
"output": "10\n26\n"
},
{
"input": "3\n733 857 714\n956 208 257\n123 719 648\n840 881 245\n245 112 746\n306 942 694\n58 870 849\n13 208 789\n687 906 783\n8\n3 3 3 3 1 1\n1 3 2 3 3 3\n2 2 2 3 1 1\n1 3 1 1 1 1\n2 3 2 3 2 3\n1 2 1 1 1 2... |
https://atcoder.jp/contests/abc366/tasks/abc366_e | Problem Statement
You are given
N
points
(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N)
on a two-dimensional plane, and a non-negative integer
D
.
Find the number of integer pairs
(x, y)
such that
\displaystyle \sum_{i=1}^N (|x-x_i|+|y-y_i|) \leq D
. | [
{
"input": "2 3\n0 0\n1 0\n",
"output": "8\n"
},
{
"input": "2 0\n0 0\n2 0\n",
"output": "0\n"
},
{
"input": "6 100\n9 -6\n10 -1\n2 10\n-1 7\n-7 5\n-1 -4\n",
"output": "419\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_f | Problem Statement
You are given
N
linear functions
f_1, f_2, \ldots, f_N
, where
f_i(x) = A_i x + B_i
.
Find the maximum possible value of
f_{p_1}(f_{p_2}(\ldots f_{p_K}(1) \ldots ))
for a sequence
p = (p_1, p_2, \ldots, p_K)
of
K
distinct
integers between
1
and
N
, inclusive. | [
{
"input": "3 2\n2 3\n1 5\n4 2\n",
"output": "26\n"
},
{
"input": "10 3\n48 40\n34 22\n24 37\n45 40\n48 31\n49 44\n45 40\n44 6\n35 22\n39 28\n",
"output": "216223\n"
}
] |
https://atcoder.jp/contests/abc366/tasks/abc366_g | Problem Statement
You are given a simple undirected graph with
N
vertices and
M
edges. The
i
-th edge connects vertices
u_i
and
v_i
bidirectionally.
Determine if there exists a way to write an integer between
1
and
2^{60} - 1
, inclusive, on each vertex of this graph so that the following condition is satisfied:
For ev... | [
{
"input": "3 3\n1 2\n1 3\n2 3\n",
"output": "Yes\n4 4 4\n"
},
{
"input": "2 1\n1 2\n",
"output": "No\n"
},
{
"input": "1 0\n",
"output": "Yes\n1\n"
},
{
"input": "4 5\n1 2\n1 3\n2 3\n2 4\n3 4\n",
"output": "Yes\n12 4 4 8\n"
}
] |
https://atcoder.jp/contests/arc181/tasks/arc181_a | Problem Statement
You are given a permutation
P=(P_1,P_2,\dots,P_N)
of
(1,2,\dots,N)
.
You want to satisfy
P_i=i
for all
i=1,2,\dots,N
by performing the following operation zero or more times:
Choose an integer
k
such that
1 \leq k \leq N
. If
k \geq 2
, sort the
1
-st through
(k-1)
-th terms of
P
in ascending order. T... | [
{
"input": "3\n5\n2 1 3 5 4\n3\n1 2 3\n7\n3 2 1 7 5 6 4\n",
"output": "1\n0\n2\n"
}
] |
https://atcoder.jp/contests/arc181/tasks/arc181_b | Problem Statement
For strings
S
and
T
consisting of lowercase English letters, and a string
X
consisting of
0
and
1
, define the string
f(S,T,X)
consisting of lowercase English letters as follows:
Starting with an empty string, for each
i=1,2,\dots,|X|
, append
S
to the end if the
i
-th character of
X
is
0
, and append... | [
{
"input": "3\naraara\n01\n111\naraaaa\n100100\n0010111\nabacabac\n0\n1111\n",
"output": "Yes\nNo\nNo\n"
},
{
"input": "2\nempty\n10101\n00\nempty\n11111\n111\n",
"output": "Yes\nYes\n"
}
] |
https://atcoder.jp/contests/arc181/tasks/arc181_c | Problem Statement
You are given two permutations
P=(P_1,P_2,\dots,P_N)
and
Q=(Q_1,Q_2,\dots,Q_N)
of
(1,2,\dots,N)
.
Write one of the characters
0
and
1
in each cell of an
N
-by-
N
grid so that all of the following conditions are satisfied:
Let
S_i
be the string obtained by concatenating the characters in the
i
-th row ... | [
{
"input": "3\n1 2 3\n2 1 3\n",
"output": "001\n101\n110\n"
},
{
"input": "15\n8 15 10 2 4 3 1 13 5 12 9 6 14 11 7\n4 1 5 14 3 12 13 7 11 8 6 2 9 15 10\n",
"output": "010001111110101\n001000000101001\n010001001100010\n010000011110010\n010011101101101\n100101110100000\n111100011001000\n0000010011... |
https://atcoder.jp/contests/arc181/tasks/arc181_d | Problem Statement
You are given a permutation
P=(P_1,P_2,\dots,P_N)
of
(1,2,\dots,N)
.
Consider the following operations
k\ (k=2,3,\dots,N)
on this permutation.
Operation
k
: For
i=1,2,\dots,k-1
in this order, if
P_i > P_{i+1}
, swap the values of the
i
-th and
(i+1)
-th elements of
P
.
You are also given a
non-decreas... | [
{
"input": "6\n3 2 4 1 6 5\n2\n4 6\n",
"output": "3\n1\n"
},
{
"input": "20\n12 14 16 8 7 15 19 6 18 5 13 9 10 17 4 1 11 20 2 3\n15\n3 4 6 8 8 9 10 12 13 15 18 18 19 19 20\n",
"output": "117\n116\n113\n110\n108\n105\n103\n99\n94\n87\n79\n72\n65\n58\n51\n"
}
] |
https://atcoder.jp/contests/arc181/tasks/arc181_e | Problem Statement
An undirected graph with numbered vertices is called a
good graph
if it has a spanning tree
T
that satisfies the following condition. Here, an edge connecting two vertices
u
and
v
(u < v)
is denoted as edge
(u,v)
.
For every edge
(u,v)
(u < v)
in the graph, the minimum and maximum vertex numbers on th... | [
{
"input": "6 9\n1 3\n1 5\n2 5\n2 6\n3 4\n3 5\n3 6\n4 6\n5 6\n",
"output": "No\nNo\nNo\nNo\nYes\nNo\nNo\nYes\nYes\n"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n",
"output": "No\nNo\nNo\nNo\n"
},
{
"input": "15 20\n12 13\n7 8\n5 7\n8 10\n9 12\n4 5\n11 12\n2 4\n6 8\n4 14\n1 2\n14 15\n2 9\n3 8... |
https://atcoder.jp/contests/arc181/tasks/arc181_f | Problem Statement
You are given an integer sequence
A=(A_1,A_2,\dots,A_N)
of length
N
. On this sequence, the following operation can be performed:
Choose
l
and
r
(1\leq l < r \leq N)
such that
A_l=A_r
,
A_{l+1}=A_{l+2}=\dots=A_{r-1}
, and
A_{l+1}\neq A_l
. Replace each of
A_{l+1},A_{l+2},\dots,A_{r-1}
with
A_l
. The c... | [
{
"input": "7\n1 2 3 2 3 2 1\n",
"output": "7\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "0\n"
},
{
"input": "40\n1 2 3 4 5 6 7 8 7 6 5 6 7 8 7 6 5 4 3 2 2 1 2 3 4 5 4 5 6 7 8 7 7 6 5 6 6 7 8 8\n",
"output": "44\n"
}
] |
https://atcoder.jp/contests/abc365/tasks/abc365_a | Problem Statement
You are given an integer
Y
between
1583
and
2023
.
Find the number of days in the year
Y
of the Gregorian calendar.
Within the given range, the year
Y
has the following number of days:
if
Y
is not a multiple of
4
, then
365
days;
if
Y
is a multiple of
4
but not a multiple of
100
, then
366
days;
if
Y
... | [
{
"input": "2023\n",
"output": "365\n"
},
{
"input": "1992\n",
"output": "366\n"
},
{
"input": "1800\n",
"output": "365\n"
},
{
"input": "1600\n",
"output": "366\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.