url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/abc288/tasks/abc288_h | Problem Statement
Print the number of integer sequences of length
N
,
A = (A_1, A_2, \ldots, A_N)
, that satisfy both of the following conditions, modulo
998244353
.
0 \leq A_1 \leq A_2 \leq \cdots \leq A_N \leq M
A_1 \oplus A_2 \oplus \cdots \oplus A_N = X
Here,
\oplus
denotes bitwise XOR.
What is bitwise XOR?
The bitwise XOR of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows.
When
A \oplus B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3 \oplus 5 = 6
(in binary:
011 \oplus 101 = 110
). | [
{
"input": "3 3 2\n",
"output": "5\n"
},
{
"input": "200 900606388 317329110\n",
"output": "788002104\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_a | Problem Statement
You are given a string
S
of length
N
consisting of lowercase English letters, and a positive integer
K
.
Determine whether there is a string
S'
of length
K
that satisfies the following conditions.
The concatenation of
S
and
S'
in this order is a palindrome.
The concatenation of
S'
and
S
in this order is a palindrome.
You have
T
test cases to solve. | [
{
"input": "2\n6 2\nabbaab\n5 3\nabcbb\n",
"output": "Yes\nNo\n"
},
{
"input": "3\n12 400378271514996652\nnjvhhvjnnjvh\n10 884633988115575508\nrrhiyvrrur\n36 71630165869626180\nvsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh\n",
"output": "Yes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_b | Problem Statement
For a set
S
of pairs of non-negative integers, and a non-negative integer
x
, let
f_S(x)
defined as
\displaystyle f_S(x)=\min_{(a, b) \in S} \left| \left| x-a \right| - b \right|
.
We have a set
T
of pairs of non-negative integers. Initially,
T=\lbrace (A, B)\rbrace
.
Process
Q
queries. The
i
-th query gives you three non-negative integers
t_i
,
a_i
, and
b_i
, and asks you to do the following.
If
t_i=1
, add to
T
the pair
(a_i, b_i)
of non-negative integers.
If
t_i=2
, print the minimum value of
f_{T}(x)
for a non-negative integer
x
such that
a_i \leq x \leq b_i
. | [
{
"input": "4 0 5\n1 3 11\n2 7 8\n1 8 2\n2 8 9\n",
"output": "2\n1\n"
},
{
"input": "2 1 2\n1 2 3\n2 2 6\n",
"output": "0\n"
},
{
"input": "20 795629912 123625148\n2 860243184 892786970\n2 645778367 668513124\n1 531411849 174630323\n1 635062977 195695960\n2 382061637 411843651\n1 585964296 589553566\n1 310118888 68936560\n1 525351160 858166280\n2 395304415 429823333\n2 583145399 703645715\n2 97768492 218377432\n1 707220749 459967102\n1 210842017 363390878\n2 489541834 553583525\n2 731279777 811513313\n1 549864943 493384741\n1 815378318 826084592\n2 369622093 374205455\n1 78240781 821999998\n2 241667193 243982581\n",
"output": "26468090\n3491640\n25280111\n9543684\n0\n22804896\n20649370\n19245624\n4849993\n484865\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_c | Problem Statement
You are given integer sequences of length
N
:
A=(A_1, A_2, \dots, A_N)
and
B=(B_1, B_2, \dots, B_N)
.
You may perform the following operation any number of times:
Choose an integer
i\ (1 \leq i \leq N-2)
such that
A_i+A_{i+1}+A_{i+2}
is even. Then, rearrange
A_i
,
A_{i+1}
,
A_{i+2}
as you like.
Determine whether it is possible to make
A
equal
B
. | [
{
"input": "5\n1 2 3 4 5\n3 1 2 4 5\n",
"output": "Yes\n"
},
{
"input": "5\n1 2 4 6 5\n5 1 4 2 6\n",
"output": "No\n"
},
{
"input": "9\n2 10 4 3 6 2 6 8 5\n2 4 10 3 8 6 6 2 5\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_d | Problem Statement
For two non-negative integers
x
and
y
, let
\gcd(x,y)
be the greatest common divisor of
x
and
y
(for
x=0
, let
\gcd(x,y)=\gcd(y,x)=y
).
There are
N
integers on the blackboard, and the
i
-th integer is
A_i
. The greatest common divisor of these
N
integers is
1
.
Takahashi and Aoki will play a game against each other. After initializing an integer
G
to
0
, they will take turns performing the following operation, with Takahashi going first.
Choose a number
a
on the blackboard such that
\gcd(G,a)\neq 1
, erase it, and replace
G
with
\gcd(G,a)
.
The first player unable to play loses.
For each
i\ (1\leq i \leq N)
, determine the winner when Takahashi chooses the
i
-th integer on the blackboard in his first turn, and then both players play optimally. | [
{
"input": "4\n2 3 4 6\n",
"output": "Takahashi\nAoki\nTakahashi\nAoki\n"
},
{
"input": "4\n2 155 155 155\n",
"output": "Takahashi\nTakahashi\nTakahashi\nTakahashi\n"
},
{
"input": "20\n2579 25823 32197 55685 73127 73393 74033 95252 104289 114619 139903 144912 147663 149390 155806 169494 175264 181477 189686 196663\n",
"output": "Takahashi\nAoki\nTakahashi\nAoki\nTakahashi\nTakahashi\nTakahashi\nTakahashi\nAoki\nTakahashi\nTakahashi\nAoki\nAoki\nAoki\nAoki\nAoki\nTakahashi\nTakahashi\nAoki\nTakahashi\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_e | Problem Statement
For a set
X
of non-negative integers, let
f(X)
denote the set of non-negative integers that can be represented as the bitwise
\mathrm{XOR}
of two integers (possibly the same) in
X
. As an example, for
X=\lbrace 1, 2, 4\rbrace
, we have
f(X)=\lbrace 0, 3, 5, 6\rbrace
.
You are given a set of
N
non-negative integers less than
2^M
:
S=\lbrace A_1, A_2, \dots, A_N\rbrace
.
You may perform the following operation any number of times.
Divide
S
into two sets
T_1
and
T_2
(one of them may be empty). Then, replace
S
with the union of
f(T_1)
and
f(T_2)
.
Find the minimum number of operations needed to make
S=\lbrace 0\rbrace
.
What is bitwise
\mathrm{XOR}
?
The bitwise
\mathrm{XOR}
of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows.
When
A \oplus B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3 \oplus 5 = 6
(in binary:
011 \oplus 101 = 110
).
Generally, the bitwise
\mathrm{XOR}
of
k
non-negative integers
p_1, p_2, p_3, \dots, p_k
is defined as
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
, which can be proved to be independent of the order of
p_1, p_2, p_3, \dots, p_k
. | [
{
"input": "4 2\n00\n01\n10\n11\n",
"output": "2\n"
},
{
"input": "1 8\n10011011\n",
"output": "1\n"
},
{
"input": "1 2\n00\n",
"output": "0\n"
},
{
"input": "20 20\n10011011111101101111\n10100111100001111100\n10100111100110001111\n10011011100011011111\n11001000001110011010\n10100111111011000101\n11110100001001110010\n10011011100010111001\n11110100001000011010\n01010011101011010011\n11110100010000111100\n01010011101101101111\n10011011100010110111\n01101111101110001110\n00111100000101111010\n01010011101111010100\n10011011100010110100\n01010011110010010011\n10100111111111000001\n10100111111000010101\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/arc155/tasks/arc155_f | Problem Statement
You are given a sequence of
N
non-negative integers:
D=(D_1, D_2, \dots, D_N)
.
Find the number of labeled trees with
N
vertices numbered
1
to
N
that satisfy the following condition, modulo
998244353
.
There is a way to direct the
N-1
edges so that the outdegree of each vertex
i\ (1\leq i \leq N)
is
D_i
. | [
{
"input": "4\n0 1 0 2\n",
"output": "5\n"
},
{
"input": "5\n0 1 1 1 1\n",
"output": "125\n"
},
{
"input": "15\n0 0 0 0 0 0 0 1 1 1 1 1 2 3 4\n",
"output": "63282877\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_a | Problem Statement
There are
N
people. Each of them agrees or disagrees with a proposal. Here,
N
is an odd number.
The
i
-th
(i = 1, 2, \dots, N)
person's opinion is represented by a string
S_i
: the person agrees if
S_i =
For
and disagrees if
S_i =
Against
.
Determine whether the majority agrees with the proposal. | [
{
"input": "3\nFor\nAgainst\nFor\n",
"output": "Yes\n"
},
{
"input": "5\nAgainst\nAgainst\nFor\nAgainst\nFor\n",
"output": "No\n"
},
{
"input": "1\nFor\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_b | Problem Statement
You are given
N
strings of length six each, consisting of digits. Let
S_i
be the
i
-th
(i = 1, 2, \dots, N)
of them.
You are also given
M
strings of length three each, consisting of digits. Let
T_j
be the
j
-th
(j = 1, 2, \dots, M)
of them.
Find the number of strings among
S_1, S_2, \dots, S_N
whose last three characters coincide with one or more of
T_1, T_2, \dots, T_M
. | [
{
"input": "3 3\n142857\n004159\n071028\n159\n287\n857\n",
"output": "2\n"
},
{
"input": "5 4\n235983\n109467\n823476\n592801\n000333\n333\n108\n467\n983\n",
"output": "3\n"
},
{
"input": "4 4\n000000\n123456\n987111\n000000\n000\n111\n999\n111\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_c | Problem Statement
You are given a simple undirected graph with
N
vertices and
M
edges. The vertices are numbered
1, 2, \dots, N
, and the edges are numbered
1, 2, \dots, M
.
Edge
i \, (i = 1, 2, \dots, M)
connects vertices
u_i
and
v_i
.
Determine if this graph is a path graph.
What is a simple undirected graph?
A
simple undirected graph
is a graph without self-loops or multiple edges whose edges do not have a direction.
What is a path graph?
A graph with
N
vertices numbered
1, 2, \dots, N
is said to be a
path graph
if and only if there is a sequence
(v_1, v_2, \dots, v_N)
that is a permutation of
(1, 2, \dots, N)
and satisfies the following conditions:
For all
i = 1, 2, \dots, N-1
, there is an edge connecting vertices
v_i
and
v_{i+1}
.
If integers
i
and
j
satisfies
1 \leq i, j \leq N
and
|i - j| \geq 2
, then there is no edge that connects vertices
v_i
and
v_j
. | [
{
"input": "4 3\n1 3\n4 2\n3 2\n",
"output": "Yes\n"
},
{
"input": "2 0\n",
"output": "No\n"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_d | Problem Statement
You are given strings
S
and
T
consisting of lowercase English letters and
?
. Here,
|S| \gt |T|
holds (for a string
X
,
|X|
denotes the length of
X
).
Two strings
X
and
Y
such that
|X|=|Y|
is said to
match
if and only if:
one can make
X
equal
Y
by replacing each
?
in
X
and
Y
with any English letter independently.
Solve the following problem for each
x=0,1,\ldots,|T|
:
Let
S'
be the string of length
|T|
obtained by concatenating the first
x
characters and the last
(|T|-x)
characters of
S
without changing the order. Print
Yes
if
S'
and
T
match, and
No
otherwise. | [
{
"input": "a?c\nb?\n",
"output": "Yes\nNo\nNo\n"
},
{
"input": "atcoder\n?????\n",
"output": "Yes\nYes\nYes\nYes\nYes\nYes\n"
},
{
"input": "beginner\ncontest\n",
"output": "No\nNo\nNo\nNo\nNo\nNo\nNo\nNo\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_e | Problem Statement
You are given
N
strings consisting of lowercase English letters. Let
S_i
be the
i
-th
(i = 1, 2, \dots, N)
of them.
For two strings
x
and
y
,
\mathrm{LCP}(x, y)
is defined to be the maximum integer
n
that satisfies all of the following conditions:
The lengths of
x
and
y
are both at least
n
.
For all integers
i
between
1
and
n
, inclusive, the
i
-th character of
x
and that of
y
are equal.
Find the following value for all
i = 1, 2, \dots, N
:
\displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j) | [
{
"input": "3\nabc\nabb\naac\n",
"output": "2\n2\n1\n"
},
{
"input": "11\nabracadabra\nbracadabra\nracadabra\nacadabra\ncadabra\nadabra\ndabra\nabra\nbra\nra\na\n",
"output": "4\n3\n2\n1\n0\n1\n0\n4\n3\n2\n1\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_f | Problem Statement
You are given a tree with
N
vertices. The vertices are numbered
1
through
N
, and the
i
-th edge connects vertex
a_i
and vertex
b_i
.
Solve the following problem for each
x=1,2,\ldots,N
:
There are
(2^N-1)
non-empty subsets
V
of the tree's vertices. Find the number, modulo
998244353
, of such
V
that the subgraph induced by
V
has exactly
x
connected components.
What is an induced subgraph?
Let
S
be the subset of the vertices of a graph
G
; then the subgraph of
G
induced by
S
is a graph whose vertex set is
S
and whose edge set consists of all edges of
G
whose both ends are contained in
S
. | [
{
"input": "4\n1 2\n2 3\n3 4\n",
"output": "10\n5\n0\n0\n"
},
{
"input": "2\n1 2\n",
"output": "3\n0\n"
},
{
"input": "10\n3 4\n3 6\n6 9\n1 3\n2 4\n5 6\n6 10\n1 8\n5 7\n",
"output": "140\n281\n352\n195\n52\n3\n0\n0\n0\n0\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_g | Problem Statement
Takahashi has
10^{100}
cards of each of
N
kinds. Initially, the score and quota of the
i
-th kind of card are set to
a_i
and
b_i
, respectively.
Given
Q
queries in the following formats, process them in order.
1 x y
: set the score of the
x
-th kind of card to
y
.
2 x y
: set the quota of the
x
-th kind of card to
y
.
3 x
: if one can choose
x
cards subject to the following condition, print the maximum possible sum of the scores of the chosen cards; print
-1
otherwise.
The number of chosen cards of each kind does not exceed its quota. | [
{
"input": "3\n1 1\n2 2\n3 3\n7\n3 4\n1 1 10\n3 4\n2 1 0\n2 3 0\n3 4\n3 2\n",
"output": "11\n19\n-1\n4\n"
}
] |
https://atcoder.jp/contests/abc287/tasks/abc287_h | Problem Statement
There is a directed graph with
N
vertices and
M
edges. The vertices are numbered
1
through
N
, and the
i
-th directed edge goes from vertex
a_i
to vertex
b_i
.
The cost of a path on this graph is defined as:
the maximum index of a vertex on the path (including the initial and final vertices).
Solve the following problem for each
x=1,2,\ldots,Q
.
Find the minimum cost of a path from vertex
s_x
to vertex
t_x
. If there is no such path, print
-1
instead.
The use of fast input and output methods is recommended because of potentially large input and output. | [
{
"input": "4 4\n1 2\n2 3\n3 1\n4 3\n3\n1 2\n2 1\n1 4\n",
"output": "2\n3\n-1\n"
}
] |
https://atcoder.jp/contests/ahc017/tasks/ahc017_a | Problem Statement
Given an edge-weighted undirected planar graph with
N
vertices, we want to perform repair work on each edge exactly once in
D
days.
We can complete the repair work on each edge in a single day, and at most
K
edges can be repaired simultaneously on the same day.
Edges that are not under repair work are passable in both directions, and the weight of an edge represents the distance it takes to move on that edge.
Let
d(i,j)
be the shortest distance from vertex
i
to vertex
j
in the original graph.
Let
d_k(i,j)
be the shortest distance from vertex
i
to vertex
j
in the graph obtained by removing the edges to be repaired on day
k
from the original graph.
If
j
is unreachable from
i
, we define
d_k(i,j)=10^9
.
The frustration level
f_k
for the repair work on day
k
is defined as the expected increase in the shortest distance between two different vertices, as follows.
\[
f_k = \frac{\sum_{i\neq j}(d_k(i,j)-d(i,j))}{N(N-1)}
\]
Using the average of the frustration levels for each day, the frustration level for the whole repair work is defined as
\[
\mathrm{round}\left(10^3\times \frac{1}{D}\sum_{k=1}^D f_k\right)
\]
Find a repair schedule that causes as little frustration as possible. | [] |
https://atcoder.jp/contests/arc154/tasks/arc154_a | Problem Statement
You are given
N
-digit positive integers
A
and
B
whose topmost digits are not
0
.
You can repeat the following operation any number of times (possibly zero).
Choose an integer
i
such that
1 \le i \le N
and swap the
i
-th lowest digits of
A
and
B
.
Find the smallest possible value of
A \times B
after your operations, modulo
998244353
.
Note that you are not asked to minimize the remainder when
A \times B
is divided by
998244353
. | [
{
"input": "2\n13\n22\n",
"output": "276\n"
},
{
"input": "8\n20220122\n21002300\n",
"output": "54558365\n"
}
] |
https://atcoder.jp/contests/arc154/tasks/arc154_b | Problem Statement
You are given strings
S
and
T
of length
N
consisting of lowercase English letters.
You can repeat the following operation any number of times (possibly zero).
Erase the
first
character of
S
and insert the same character at any position of
S
.
Determine whether it is possible to make
S
equal
T
, and if it is possible, find the minimum number of operations needed. | [
{
"input": "4\nabab\nabba\n",
"output": "2\n"
},
{
"input": "3\narc\ncra\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/arc154/tasks/arc154_c | Problem Statement
You are given sequences of positive integers of length
N
:
A=(A_1,A_2,\dots,A_N)
and
B=(B_1,B_2,\dots,B_N)
.
You can repeat the following operation any number of times (possibly zero).
Choose an integer
i
such that
1 \le i \le N
and replace
A_i
with
A_{i+1}
.
Here, regard
A_{N+1}
as
A_1
.
Determine whether it is possible to make
A
equal
B
.
You have
T
test cases to solve. | [
{
"input": "3\n2\n1 2\n2 2\n4\n2 3 1 1\n2 1 1 2\n2\n1 1\n2 2\n",
"output": "Yes\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/arc154/tasks/arc154_d | Problem Statement
PCT has a permutation
(P_1,P_2,\dots,P_N)
of
(1,2,\dots,N)
. You are only informed of
N
.
You can ask him at most
25000
questions of the following form.
Specify a triple of integers
(i,j,k)
such that
1 \le i,j,k \le N
and ask whether
P_i + P_j > P_k
.
Find all of
P_1,P_2,\dots,P_N
. | [] |
https://atcoder.jp/contests/arc154/tasks/arc154_e | Problem Statement
For a permutation
Q=(Q_1,Q_2,\dots,Q_N)
of
(1,2,\dots,N)
, let
f(Q)
be the following value:
the sum of
j-i
over all pairs of integers
(i,j)
such that
1 \le i < j \le N
and
Q_i > Q_j
.
You are given a permutation
P=(P_1,P_2,\dots,P_N)
of
(1,2,\dots,N)
.
Let us repeat the following operation
M
times.
Choose a pair of integers
(i,j)
such that
1 \le i \le j \le N
. Reverse
P_i,P_{i+1},\dots,P_j
. Formally, replace the values of
P_i,P_{i+1},\dots,P_j
with
P_j,P_{j-1},\dots,P_i
simultaneously.
There are
\left(\frac{N(N+1)}{2}\right)^{M}
ways to repeat the operation. Assume that we have computed
f(P)
for all those ways.
Find the sum of these
\left(\frac{N(N+1)}{2}\right)^{M}
values, modulo
998244353
. | [
{
"input": "2 1\n1 2\n",
"output": "1\n"
},
{
"input": "3 2\n3 2 1\n",
"output": "90\n"
},
{
"input": "10 2023\n5 8 1 9 3 10 4 7 2 6\n",
"output": "543960046\n"
}
] |
https://atcoder.jp/contests/arc154/tasks/arc154_f | Problem Statement
We have an
N
-sided die where all sides have the same probability to show up. Let us repeat rolling this die until every side has shown up.
For integers
i
such that
1 \le i \le M
, find the expected value, modulo
998244353
, of the
i
-th power of the number of times we roll the die.
Definition of expected value modulo
998244353
It can be proved that the sought expected values are always rational numbers. Additionally, under the constraints of this problem, when such a value is represented as an irreducible fraction
\frac{P}{Q}
, it can be proved that
Q \neq 0 \pmod{998244353}
. Thus, there is a unique integer
R
such that
R \times Q = P \pmod{998244353}
and
0 \le R < 998244353
. Print this
R
. | [
{
"input": "3 3\n",
"output": "499122182\n37\n748683574\n"
},
{
"input": "7 8\n",
"output": "449209977\n705980975\n631316005\n119321168\n62397541\n596241562\n584585746\n378338599\n"
},
{
"input": "2023 7\n",
"output": "442614988\n884066164\n757979000\n548628857\n593993207\n780067557\n524115712\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_a | å顿
JOI 髿 ¡ã®çåŸã§ããèµã¯ïŒæåå
JOIG
ãïŒæåå
JOI
ã®æ«å°Ÿã«æå
G
ãä»ãå ããŠã§ããããšã«æ°ãä»ããïŒ
ããããèµã¯ïŒæ§ã
ãªæååã«ã€ããŠïŒæ«å°Ÿã«æå
G
ãä»ãå ãããïŒæ«å°Ÿã®æå
G
ãåãé€ããŠéã¶ããã«ãªã£ãïŒ
å
·äœçã«ã¯ïŒèµã¯æååãèŠããšæ¬¡ã®ããã«éã¶ïŒ
èŠãæååã®æ«å°Ÿã®æåã
G
ã®ãšãïŒæ«å°Ÿã®æå
G
ãåãé€ããæååãæãæµ®ãã¹ãïŒåãé€ãæåã¯æ«å°Ÿã®
1
æåã®ã¿ã§ããïŒ
èŠãæååã®æ«å°Ÿã®æåã
G
ã§ãªããšãïŒæååã®æ«å°Ÿã«æå
G
ãä»ãå ããæååãæãæµ®ãã¹ãïŒ
é·ã
N
ã®æåå
S
ãäžããããïŒèµãæåå
S
ãèŠããšãæãæµ®ãã¹ãæååãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "4\nJOIG\n",
"output": "JOI\n"
},
{
"input": "3\nJOI\n",
"output": "JOIG\n"
},
{
"input": "3\nEGG\n",
"output": "EG\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_b | å顿
JOI 髿 ¡ã®èµããã¯ïŒæ°åã«å¯ŸããŠïŒé£ãåãåé
ã®å·®ã®çµ¶å¯Ÿå€ãé ã«äžŠã¹ãæ°åãèããã®ã奜ãã§ããïŒ
ã¯ããïŒé»æ¿ã«ã¯é·ã
N
ã®æ°å
A_1,A_2,\ldots,A_N
ãæžãããŠããïŒ
èµããã¯ä»¥äžã®æäœã
N-1
åç¹°ãè¿ãïŒ
黿¿ã«æžãããŠããæ°åã®é·ãã
m
ã§ããïŒãã®æ°åã
b_1,b_2,\ldots,b_m
ã§ãããšããïŒ
黿¿ã«æžãããŠããæ°å
b_1,b_2,\ldots,b_m
ãæ¶ãïŒé·ã
m-1
ã®æ°å
|b_1-b_2|,|b_2-b_3|,\ldots,|b_{m-1}-b_m|
ãæ°ãã«é»æ¿ã«æžãïŒãã ãïŒ
|x|
ã¯
x
ã®çµ¶å¯Ÿå€ã衚ãïŒ
N-1
åã®æäœãçµäºããåŸïŒé»æ¿ã«ã¯
1
ã€ã®å€ïŒé·ã
1
ã®æ°åïŒãæžãããŠããïŒ
ã¯ãã黿¿ã«æžãããŠããæ°åã®æ
å ±ãäžããããã®ã§ïŒ
N-1
åã®æäœãçµäºããåŸé»æ¿ã«æžãããŠããå€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "4\n3 1 4 1\n",
"output": "1\n"
},
{
"input": "2\n2 4\n",
"output": "2\n"
},
{
"input": "6\n2 7 5 3 3 11\n",
"output": "3\n"
},
{
"input": "10\n3 1 4 1 5 9 2 6 5 3\n",
"output": "0\n"
},
{
"input": "2\n0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_c | å顿
JOI åžã«ã¯
1
æ¬ã®ååã«é·ãéè·¯ãããïŒãã®éè·¯ã¯æ°çŽç·ãšã¿ãªãããšãã§ãïŒåå°ç¹ã¯
1
åã®å®æ°ã«ãã座æšã§è¡šãããïŒ
ãŸãïŒJOI åžã«ã¯ãã®éè·¯ã«æ²¿ã£ãŠ
N
åã®éãããïŒåº§æšã®å°ããé ã«
1
ãã
N
ãŸã§ã®çªå·ãä»ããããŠããïŒé
i
(
1 ⊠i ⊠N
) ã¯åº§æš
A_i
ã«ããïŒ
JOI åžã§ã¯ïŒ
1
幎ã®çµããã«ãããã®éãäžæã«é³Žããã®ãäžå€§ã€ãã³ããšãªã£ãŠããïŒ
ã©ã®éãïŒé³Žãããšãã®éãšåãå°ç¹ã§ã¯åŒ·ã
K
ã®é³ã§èããããïŒè·é¢ã
1
é¢ããããšã«èãããé³ã®åŒ·ãã¯
1
å°ãããªãïŒè·é¢ã
K
以äžé¢ãããš
0
ã«ãªãïŒããªãã¡ïŒé
i
ã鳎ããããšãïŒåº§æš
x
ã§èãããé
i
ã®é³ã®åŒ·ãã¯
\max\{K - |x - A_i|, 0\}
ã§ããïŒãã ãïŒ
|t|
ã¯
t
ã®çµ¶å¯Ÿå€ã衚ãïŒ
ãã¹ãŠã®éã鳎ããããšãïŒåº§æš
x
ã§èãããéã®é³ã®åŒ·ãã¯ïŒåº§æš
x
ã§èãããããããã®éã®é³ã®åŒ·ãã®æå€§å€ã§ããïŒ
JOI åžã«ã¯ãã®éè·¯ã«æ²¿ã£ãŠ
M
åã®å®¶ãããïŒå€ãæ¹ããé ã«
1
ãã
M
ãŸã§ã®çªå·ãä»ããããŠããïŒå®¶
j
(
1 ⊠j ⊠M
) ã¯åº§æš
B_j
ã«ããïŒ
JOI åžã®åžé·ã§ããããªãã¯ïŒãã¹ãŠã®éã鳎ããããšãïŒããããã®å®¶ã§èãããéã®é³ã®åŒ·ããç¥ãããïŒ
JOI åžã®éãšå®¶ã®æ
å ±ãäžãããããšãïŒãã¹ãŠã®éã鳎ããããšãã«åº§æš
B_1, B_2, âŠ, B_M
ã§èãããéã®é³ã®åŒ·ããæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "1 5 10\n20\n20 15 28 10 32\n",
"output": "10\n5\n2\n0\n0\n"
},
{
"input": "3 4 100\n116 194 258\n57 155 222 360\n",
"output": "41\n61\n72\n0\n"
},
{
"input": "10 10 10000\n589 2398 6567 28817 29177 31636 45468 66751 82282 97509\n2196 54498 80474 61644 18007 38759 85590 72172 79533 69959\n",
"output": "9798\n970\n8192\n4893\n0\n3291\n6692\n4579\n7251\n6792\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_d | å顿
æºã®äžã«ïŒçžŠ
H
è¡ïŒæšª
W
åã®é·æ¹åœ¢ç¶ã«ã³ã€ã³ã䞊ã¹ãããŠããïŒ
æåïŒäžãã
i
è¡ç® (
1 \leqq i \leqq H
)ïŒå·Šãã
j
åç® (
1 \leqq j \leqq W
) ã®ã³ã€ã³ã¯ïŒ
S_{i,j}=
#
ã®ãšã衚é¢ïŒ
S_{i,j}=
.
ã®ãšãè£é¢ãèŠããŠããç¶æ
ã§ããïŒ
èµãšåã¯ïŒãããã®ã³ã€ã³ãçšããŠã²ãŒã ãè¡ãããšã«ããïŒã²ãŒã ã¯ä»¥äžã®ãããªæµãã§è¡ãããïŒ
èµãã©ãã
1
ã€ã®è¡ãéžã³ïŒãã®è¡ã®ã³ã€ã³ããã¹ãŠã²ã£ããè¿ãïŒ
åãã©ãã
1
ã€ã®åãéžã³ïŒãã®åã®ã³ã€ã³ããã¹ãŠã²ã£ããè¿ãïŒ
èµãïŒè¡šé¢ãèŠããã³ã€ã³ããã¹ãŠç²åŸããïŒãŸãåãïŒè£é¢ãèŠããã³ã€ã³ããã¹ãŠç²åŸããïŒ
èµãšåã¯ããããïŒã§ããã ãå€ãã®ã³ã€ã³ãç²åŸãããïŒ
ã²ãŒã éå§æã®ã³ã€ã³ã®ç¶æ
ãäžãããããšãïŒ
äž¡è
ãæåãå°œãããå Žåã«ãããããç²åŸã§ããã³ã€ã³ã®ææ°ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "1 1\n#\n",
"output": "1 0\n"
},
{
"input": "5 5\n#####\n####.\n###..\n##...\n#....\n",
"output": "13 12\n"
},
{
"input": "1 40\n..........##########..........##########\n",
"output": "19 21\n"
},
{
"input": "7 1\n#\n#\n#\n#\n#\n#\n#\n",
"output": "1 6\n"
},
{
"input": "5 5\n.###.\n...##\n..##.\n.##..\n##...\n",
"output": "11 14\n"
},
{
"input": "10 40\n........................................\n..######.....####.....#####.....####....\n.....#......#....#......#......#........\n.....#......#....#......#......#........\n.....#......#....#......#......#........\n.....#......#....#......#......#..####..\n..#..#......#....#......#......#....#...\n..#..#......#....#......#......#....#...\n...##........####.....#####.....####....\n........................................\n",
"output": "104 296\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_e | å顿
JOIG çåœã¯
H
è¡
W
åã®ãã¹ç®ã«åºåãããé·æ¹åœ¢ã®åœ¢ãããŠããïŒäžãã
i
è¡ç® (
1 \leqq i \leqq H
)ïŒå·Šãã
j
åç® (
1 \leqq j \leqq W
) ã®ãã¹ããã¹
(i,j)
ãšåŒã¶ïŒ
åãã¹ã«ã¯æšé«ãšåŒã°ããæŽæ°ãå®ãŸã£ãŠããïŒãã¹
(i,j)
ã®æšé«ã¯
A_{i,j}
ã§ããïŒ
JOIG çåœã§ã¯ïŒçåœã瞊æããéæ²³ã建èšããããšã«ããïŒéæ²³ã®å»ºèšã¯ïŒä»¥äžã®ããã«è¡ãããïŒ
ããæŽæ°
k
(
1 \leqq k < W
) ãå®ããïŒå·Šãã
k
åç®ãš
k+1
åç®ã®éã«ïŒçåœã®äžç«¯ããäžç«¯ãŸã§çžŠæããéæ²³ã建èšããïŒ
éæ²³ã暪åããïŒèŸºã§æ¥ããŠããæšé«ãåããã¹ãžã®ç§»åãç¹°ãè¿ãããšã§çžäºã«ç§»åã§ãããã¹ã®éãŸããããã§ã¯
å¹³å°
ãšåŒã¶ïŒåœåã管çããããããããïŒå¹³å°ã®åæ°ãã§ããã ãå°ãªããªãããã«éæ²³ã®å»ºèšäœçœ®ã決ãããïŒ
JOIG çåœã®å°åœ¢ã®æ
å ±ãäžãããããšãïŒéæ²³ã建èšããåŸã® JOIG çåœå
ã®å¹³å°ã®åæ°ãšããŠããããæå°å€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "4 4\n1 1 1 3\n2 2 1 3\n2 1 1 3\n2 2 2 2\n",
"output": "4\n"
},
{
"input": "5 8\n1 2 2 5 5 5 5 5\n1 1 2 2 5 6 5 6\n1 1 1 1 6 6 5 6\n1 1 3 1 1 6 7 6\n1 4 1 1 1 6 6 6\n",
"output": "8\n"
},
{
"input": "1 6\n1 1 2 2 3 3\n",
"output": "3\n"
},
{
"input": "2 10\n1 1 1 1 1 3 3 3 3 4\n1 2 1 3 3 3 1 1 3 3\n",
"output": "6\n"
}
] |
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_f | å顿
JOIG åœã§ã¯ JOIG èªã䜿çšãããŠããïŒJOIG èªã§ã¯æå
A
,
B
,
C
,
D
,
E
,
F
,
G
,
H
,
I
,
J
,
K
,
L
,
M
,
N
,
O
ã®
15
çš®é¡ã®æåãçšããããïŒ
æ¥æ JOIG åœã§éå¬ãããã¿ã€ãã³ã°å€§äŒã§ã¯ïŒJOIG èªã§çšãããã
15
çš®é¡ã®æåãããªãé·ã
N
ã®æåå
S
ãå
¥åããã®ã«ãããæéãç«¶ãïŒãã®å€§äŒã§ã¯ïŒåå è
ã¯ä»¥äžã®æ¡ä»¶ã§ã¿ã€ãã³ã°ãè¡ãïŒ
åå è
ã¯ïŒ
1
æ¬ã®æã䜿ã£ãŠã¿ã€ãã³ã°ãããïŒ
åå è
ã¯ïŒ
15
çš®é¡ã®æåã®ããŒ
1
ã€ãã€ã
1
åã«äžŠã¹ãïŒå·Šå³ã«çްé·ãããŒããŒãã䜿çšããïŒãªãïŒã©ã®äœçœ®ã«ã©ã®æåã®ããŒãé
眮ãããã¯ïŒååå è
ãèªç±ã«æ±ºããããšãã§ããïŒ
åå è
ã¯ïŒæåå
S
ã®
1, 2, \dots, N
æåç®ã®ããŒããã®é ã«æã€ããšã«ãã£ãŠæåå
S
ãå
¥åããïŒ
ãã®å€§äŒã«ã¯
Q
人ãåå ããäºå®ã§ããïŒåå è
ã«ãã£ãŠã¿ã€ãã³ã°ã®èœåã¯æ§ã
ã§ããïŒ
i
çªç® (
1 \leqq i \leqq Q
) ã®åå è
ã¯ïŒã¿ã€ãã³ã°ã«éããŠä»¥äžã®ãããªæéããããïŒ
æã®çäžã«ããããŒã
1
åæã€ã®ã«
A_i
ããªç§ãããïŒ
æã
1
ã€å·Šã®ããŒã®äžã«ç§»åãããã®ã«
L_i
ããªç§ãããïŒ
æã
1
ã€å³ã®ããŒã®äžã«ç§»åãããã®ã«
R_i
ããªç§ãããïŒ
æåå
S
ããã³ååå è
ã®æ
å ±ãäžããããã®ã§ïŒååå è
ã«å¯ŸããŠïŒæåå
S
ã®æåã®æåãæã¡å§ããŠããæåŸã®æåãæã¡çµãããŸã§ã«æçäœããªç§ãããããæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "6\nABAABB\n1\n100 150 210\n",
"output": "1110\n"
},
{
"input": "6\nCBACAB\n1\n150 240 220\n",
"output": "2260\n"
},
{
"input": "20\nAAAAAAAAAAAAAAAAAAAA\n1\n230000000 80000000 80000000\n",
"output": "4600000000\n"
},
{
"input": "7\nEACHBAG\n5\n130 104 162\n107 219 45\n144 168 157\n213 79 257\n100000000000 100000000000 100000000000\n",
"output": "2078\n1766\n2465\n2894\n1600000000000\n"
},
{
"input": "19\nJOIGCODINGCHALLENGE\n5\n1 1 1\n100 200 200\n225 111 111\n123456789 987654321 987654321\n31415926535 27182818284 27182818284\n",
"output": "48\n7700\n7494\n30987654300\n1385204334401\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_a | Problem Statement
You are given a sequence
A=(A_1,A_2,\ldots,A_N)
of length
N
and positive integers
P,Q,R
, and
S
.
Here,
P,Q,R
, and
S
satisfy
1\leq P\leq Q<R\leq S \leq N
and
Q-P=S-R
.
Let
B=(B_1, B_2,\ldots, B_N)
be the sequence obtained by swapping the
P
-th through
Q
-th terms and the
R
-th through
S
-th terms of
A
.
Print the sequence
B
. | [
{
"input": "8 1 3 5 7\n1 2 3 4 5 6 7 8\n",
"output": "5 6 7 4 1 2 3 8\n"
},
{
"input": "5 2 3 4 5\n2 2 1 1 1\n",
"output": "2 1 1 2 1\n"
},
{
"input": "2 1 1 2 2\n50 100\n",
"output": "100 50\n"
},
{
"input": "10 2 4 7 9\n22 75 26 45 72 81 47 29 97 2\n",
"output": "22 47 29 97 72 81 75 26 45 2\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_b | Problem Statement
You are given a string
S
of length
N
.
Find the string obtained by replacing all contiguous occurrences of
na
in
S
with
nya
. | [
{
"input": "4\nnaan\n",
"output": "nyaan\n"
},
{
"input": "4\nnear\n",
"output": "near\n"
},
{
"input": "8\nnational\n",
"output": "nyationyal\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_c | Problem Statement
You are given a string
S
of length
N
. Let
S_i\ (1\leq i \leq N)
be the
i
-th character of
S
from the left.
You may perform the following two kinds of operations zero or more times in any order:
Pay
A
yen (the currency in Japan). Move the leftmost character of
S
to the right end. In other words, change
S_1S_2\ldots S_N
to
S_2\ldots S_NS_1
.
Pay
B
yen. Choose an integer
i
between
1
and
N
, and replace
S_i
with any lowercase English letter.
How many yen do you need to pay to make
S
a palindrome?
What is a palindrome?
A string
T
is a palindrome if and only if the
i
-th character from the left and the
i
-th character from the right are the same for all integers
i
(
1 \le i \le |T|
), where
|T|
is the length of
T
. | [
{
"input": "5 1 2\nrrefa\n",
"output": "3\n"
},
{
"input": "8 1000000000 1000000000\nbcdfcgaa\n",
"output": "4000000000\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_d | Problem Statement
Takahashi has
N
kinds of coins;
specifically, for
1\leq i\leq N
, he has
B_i
coins worth
A_i
yen (the currency in Japan) each.
Determine if Takahashi can pay exactly
X
yen (without change) with the coins he currently has. | [
{
"input": "2 19\n2 3\n5 6\n",
"output": "Yes\n"
},
{
"input": "2 18\n2 3\n5 6\n",
"output": "No\n"
},
{
"input": "3 1001\n1 1\n2 1\n100 10\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_e | Problem Statement
There are
N
cities. There are also one-way direct flights that connect different cities.
The availability of direct flights is represented by
N
strings
S_1,S_2,\ldots,S_N
of length
N
each.
If the
j
-th character of
S_i
is
Y
, there is a direct flight from city
i
to city
j
;
if it is
N
, there is not.
Each city sells a souvenir; city
i
sells a souvenir of value
A_i
.
Consider the following problem:
Takahashi is currently at city
S
and wants to get to city
T
(that is different from city
S
) using some direct flights.
Every time he visits a city (including
S
and
T
), he buys a souvenir there.
If there are multiple routes from city
S
to city
T
, Takahashi decides the route as follows:
He tries to minimize the number of direct flights in the route from city
S
to city
T
.
Then he tries to maximize the total value of the souvenirs he buys.
Determine if he can travel from city
S
to city
T
using the direct flights.
If he can, find the "number of direct flights" and "total value of souvenirs" in the route that satisfies the conditions above.
You are given
Q
pairs
(U_i,V_i)
of distinct cities.
For each
1\leq i\leq Q
, print the answer to the problem above when
S=U_i
and
T=V_i
. | [
{
"input": "5\n30 50 70 20 60\nNYYNN\nNNYNN\nNNNYY\nYNNNN\nYNNNN\n3\n1 3\n3 1\n4 5\n",
"output": "1 100\n2 160\n3 180\n"
},
{
"input": "2\n100 100\nNN\nNN\n1\n1 2\n",
"output": "Impossible\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_f | Problem Statement
This is an
interactive task
, where your and the judge's programs interact via Standard Input and Output.
You and the judge will follow the procedure below.
The procedure consists of phases
1
and
2
; phase
1
is immediately followed by phase
2
.
(Phase
1
)
The judge decides an integer
N
between
1
and
10^9
(inclusive), which is hidden.
You print an integer
M
between
1
and
110
(inclusive).
You also print an integer sequence
A=(A_1,A_2,\ldots,A_M)
of length
M
such that
1 \leq A_i \leq M
for all
i = 1, 2, \ldots, M
.
(Phase
2
)
The judge gives you an integer sequence
B=(B_1,B_2,\ldots,B_M)
of length
M
. Here,
B_i = f^N(i)
.
f(i)
is defined by
f(i)=A_i
for all integers
i
between
1
and
M
(inclusive), and
f^N(i)
is the integer resulting from replacing
i
with
f(i)
N
times.
Based on the given
B
, you identify the integer
N
that the judge has decided, and print
N
.
After the procedure above, terminate the program immediately to be judged correct. | [] |
https://atcoder.jp/contests/abc286/tasks/abc286_g | Problem Statement
You are given a simple connected undirected graph
G
with
N
vertices and
M
edges.
The vertices of
G
are numbered vertex
1
, vertex
2
,
\ldots
, and vertex
N
, and its edges are numbered edge
1
, edge
2
,
\ldots
, and edge
M
.
Edge
i
connects vertex
U_i
and vertex
V_i
.
You are also given a subset of the edges:
S=\{x_1,x_2,\ldots,x_K\}
.
Determine if there is a walk on
G
that contains edge
x
exactly once for all
x \in S
.
The walk may contain an edge not in
S
any number of times (possibly zero).
What is a walk?
A walk on an undirected graph
G
is a sequence consisting of
k
vertices (
k
is a positive integer) and
(k-1)
edges occurring alternately,
v_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k
, such that
edge
e_i
connects vertex
v_i
and vertex
v_{i+1}
. The sequence may contain the same edge or vertex multiple times.
A walk is said to contain an edge
x
exactly once if and only if there is exactly one
1\leq i\leq k-1
such that
e_i=x
. | [
{
"input": "6 6\n1 3\n2 3\n3 4\n4 5\n4 6\n5 6\n4\n1 2 4 5\n",
"output": "Yes\n"
},
{
"input": "6 5\n1 2\n1 3\n1 4\n1 5\n1 6\n3\n1 2 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc286/tasks/abc286_h | Problem Statement
On a two-dimensional plane, there is a convex polygon
C
with
N
vertices, and points
S=(s_x, s_y)
and
T=(t_x,t_y)
. The vertices of
C
are
(x_1,y_1),(x_2,y_2),\ldots
, and
(x_N,y_N)
in counterclockwise order. It is guaranteed that
S
and
T
are outside the polygon.
Find the shortest distance that needs to be traveled to get from point
S
to point
T
without entering the interior of
C
except for its circumference. | [
{
"input": "4\n1 1\n3 1\n3 3\n1 3\n0 2\n5 2\n",
"output": "5.65028153987288474496\n"
},
{
"input": "3\n0 0\n2 0\n1 10\n3 7\n10 3\n",
"output": "8.06225774829854965279\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_a | Problem Statement
Determine if there is a segment that directly connects the points numbered
a
and
b
in the figure below. | [
{
"input": "1 2\n",
"output": "Yes\n"
},
{
"input": "2 8\n",
"output": "No\n"
},
{
"input": "14 15\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_b | Problem Statement
You are given a string
S
of length
N
consisting of lowercase English letters. The
x
-th
(1 \le x \le N)
character of
S
is
S_x
.
For each
i=1,2,\dots,N-1
, find the maximum non-negative integer
l
that satisfies all of the following conditions:
l+i \le N
, and
for all integers
k
such that
1 \le k \le l
, it holds that
S_{k} \neq S_{k+i}
.
Note that
l=0
always satisfies the conditions. | [
{
"input": "6\nabcbac\n",
"output": "5\n1\n2\n0\n1\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_c | Problem Statement
In a parallel universe, AtCoder holds AtCoder Big Contest, where
10^{16}
problems are given at once.
The IDs of the problems are as follows, from the
1
-st problem in order:
A
,
B
, ...,
Z
,
AA
,
AB
, ...,
ZZ
,
AAA
, ...
In other words, the IDs are given in the following order:
the strings of length
1
consisting of uppercase English letters, in lexicographical order;
the strings of length
2
consisting of uppercase English letters, in lexicographical order;
the strings of length
3
consisting of uppercase English letters, in lexicographical order;
...
Given a string
S
that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.) | [
{
"input": "AB\n",
"output": "28\n"
},
{
"input": "C\n",
"output": "3\n"
},
{
"input": "BRUTMHYHIIZP\n",
"output": "10000000000000000\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_d | Problem Statement
You run a web service with
N
users.
The
i
-th user with a current handle
S_i
wants to change it to
T_i
.
Here,
S_1,\ldots
, and
S_N
are pairwise distinct, and so are
T_1,\ldots
, and
T_N
.
Determine if there is an appropriate order to change their handles to fulfill all of their requests subject to the following conditions:
you change only one user's handle at a time;
you change each user's handle only once;
when changing the handle, the new handle should not be used by other users at that point. | [
{
"input": "2\nb m\nm d\n",
"output": "Yes\n"
},
{
"input": "3\na b\nb c\nc a\n",
"output": "No\n"
},
{
"input": "5\naaa bbb\nyyy zzz\nccc ddd\nxxx yyy\nbbb ccc\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_e | Problem Statement
In the world where Takahashi lives, a week has
N
days.
Takahashi, the king of the Kingdom of AtCoder, assigns "weekday" or "holiday" to each day of week. The assignments should be the same for all weeks. At least one day of week should be assigned "holiday".
Under such conditions, the productivity of the
i
-th day of week is defined by a sequence
A
of length
N
as follows:
if the
i
-th day of week is "holiday", its productivity is
0
;
if the
i
-th day of week is "weekday", its productivity is
A_{\min(x,y)}
, if the last holiday is
x
days before and the next one is
y
days after.
Note that the last/next holiday may belong to a different week due to the periodic assignments. For details, see the Samples.
Find the maximum productivity per week when the assignments are chosen optimally.
Here, the productivity per week refers to the sum of the productivities of the
1
-st,
2
-nd,
\dots
, and
N
-th day of week. | [
{
"input": "7\n10 10 1 1 1 1 1\n",
"output": "50\n"
},
{
"input": "10\n200000000 500000000 1000000000 800000000 100000000 80000000 600000 900000000 1 20\n",
"output": "5100000000\n"
},
{
"input": "20\n38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 1142 281 20537 15921 8945 26285 2997 14680\n",
"output": "236980\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_f | Problem Statement
You are given a string
S
of length
N
consisting of lowercase English letters, and
Q
queries. Process the queries in order.
Each query is of one of the following two kinds:
1 x c
: replace the
x
-th character of
S
by the character
c
.
2 l r
: let
T
be the string obtained by sorting the characters of
S
in ascending order. Print
Yes
if the string consisting of the
l
-th through
r
-th characters of
S
is a substring of
T
; print
No
otherwise.
What is a substring?
A
substring
of
S
is a string obtained by removing
0
or more initial characters and
0
or more final characters of
S
.
For example,
ab
is a substring of
abc
, while
ac
is not a substring of
abc
. | [
{
"input": "6\nabcdcf\n4\n2 1 3\n2 2 6\n1 5 e\n2 2 6\n",
"output": "Yes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_g | Problem Statement
We have a grid with
H
horizontal rows and
W
vertical columns. We denote by square
(i,j)
the square at the
i
-th row from the top and
j
-th column from the left.
We want to cover this grid with
1 \times 1
tiles and
1 \times 2
tiles so that no tiles overlap and everywhere is covered by a tile. (A tile can be rotated.)
Each square has
1
,
2
, or
?
written on it. The character written on square
(i, j)
is
c_{i,j}
.
A square with
1
written on it must be covered by a
1 \times 1
tile, and a square with
2
by a
1 \times 2
tile. A square with
?
may be covered by any kind of tile.
Determine if there is such a placement of tiles. | [
{
"input": "3 4\n2221\n?1??\n2?21\n",
"output": "Yes\n"
},
{
"input": "3 4\n2?21\n??1?\n2?21\n",
"output": "No\n"
},
{
"input": "5 5\n11111\n11111\n11211\n11111\n11111\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc285/tasks/abc285_h | Problem Statement
You are given integers
N
and
K
, and a sequence
E
of length
K
.
Find the number, modulo
\color{red}{10^9+7}
, of sequences of length
N
consisting of positive integers that satisfy the following conditions:
no element is a square number;
the product of all elements is
\displaystyle \prod_{i=1}^{K} p_i^{E_i}
.
Here,
p_i
denotes the
i
-th smallest prime.
Two sequences
A
and
B
of the same length consisting of positive integers are considered different if and only if there exists an integer
i
such that the
i
-th terms of
A
and
B
are different. | [
{
"input": "3 2\n3 2\n",
"output": "15\n"
},
{
"input": "285 10\n3141 5926 5358 9793 2384 6264 3383 279 5028 8419\n",
"output": "672860525\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_a | Problem Statement
A positive integer
x
is said to be a
beautiful integer
if and only if
x
is a
9
-digit integer whose decimal notation
S_1\ldots S_9
(
S_i
is the
i
-th character) satisfies all of the following conditions:
S_1
is not
0
,
S_1 = S_2
,
S_5 = S_6
, and
S_7 = S_9
.
For instance,
998244353
and
333333333
are beautiful integers, while
111112222
is not, since
S_5 \neq S_6
.
You are given a positive integer
N
. Print the
N
-th smallest beautiful integer. | [
{
"input": "3\n",
"output": "110000020\n"
},
{
"input": "882436\n",
"output": "998244353\n"
},
{
"input": "2023\n",
"output": "110200222\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_b | Problem Statement
We have a grid with
H
rows from top to bottom and
W
columns from left and right. Initially, the square at the
i
-th row from the top and
j
-th column from the left has a lowercase English letter
A_{i,j}
.
Let us perform
Q
operations on this grid. In the
i
-th operation, we are given integers
a_i
and
b_i
such that
1\leq a_i \leq H-1
and
1\leq b_i\leq W-1
, and do the following.
Let
R_1
,
R_2
,
R_3
, and
R_4
be rectangular regions within the grid defined as follows:
R_1
is the intersection of the top
a_i
rows and leftmost
b_i
columns;
R_2
is the intersection of the top
a_i
rows and rightmost
W-b_i
columns;
R_3
is the intersection of the bottom
H-a_i
rows and leftmost
b_i
columns;
R_4
is the intersection of the bottom
H-a_i
rows and rightmost
W-b_i
columns.
Rotate
180
degrees each of
R_1
,
R_2
,
R_3
, and
R_4
.
Here, a
180
-degree rotation of a rectangular region
R
within the grid moves the character on the square at the
i
-th from the top and
j
-th column from the left in
R
to the square at the
i
-th from the bottom and
j
-th column from the right in
R
. See also the figures for the samples.
Print the grid after all
Q
operations. | [
{
"input": "4 5\nabcde\nfghij\nklmno\npqrst\n1\n3 3\n",
"output": "mlkon\nhgfji\ncbaed\nrqpts\n"
},
{
"input": "3 7\natcoder\nregular\ncontest\n2\n1 1\n2 5\n",
"output": "testcon\noderatc\nularreg\n"
},
{
"input": "2 2\nac\nwa\n3\n1 1\n1 1\n1 1\n",
"output": "ac\nwa\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_c | Problem Statement
You are given a sequence of length
N
,
A = (A_1, \ldots, A_N)
, consisting of
1
and
-1
.
Determine whether there is an integer sequence
x = (x_1, \ldots, x_N)
that satisfies all of the following conditions, and print one such sequence if it exists.
|x_i| \leq 10^{12}
for every
i
(
1\leq i\leq N
).
x
is strictly increasing. That is,
x_1 < \cdots < x_N
.
\sum_{i=1}^N A_ix_i = 0
. | [
{
"input": "5\n-1 1 -1 -1 1\n",
"output": "Yes\n-3 -1 4 5 7\n"
},
{
"input": "1\n-1\n",
"output": "Yes\n0\n"
},
{
"input": "2\n1 -1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_d | Problem Statement
For a positive integer
x
, let
f(x)
denote the sum of its digits. For instance, we have
f(153) = 1 + 5 + 3 = 9
,
f(2023) = 2 + 0 + 2 + 3 = 7
, and
f(1) = 1
.
You are given a sequence of positive integers
A = (A_1, \ldots, A_N)
. Find the minimum possible value of
\sum_{i=1}^N f(A_i + x)
where
x
is a non-negative integer. | [
{
"input": "4\n4 13 8 6\n",
"output": "14\n"
},
{
"input": "4\n123 45 678 90\n",
"output": "34\n"
},
{
"input": "3\n1 10 100\n",
"output": "3\n"
},
{
"input": "1\n153153153\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_e | Problem Statement
For a positive integer
X
none of whose digits is
0
, consider obtaining a positive integer
Y
as follows.
Initialize
S
as an empty string.
Let
N
be the number of digits in
X
. For
i = 1, \ldots, N
in this order, do the following: insert the
i
-th character in the decimal notation of
X
at the beginning or end of
S
.
Let
Y
be the positive integer represented by the string
S
.
Let
f(X)
denote the minimum positive integer that can be obtained from
X
in this way.
You are given a positive integer
Y
none of whose digits is
0
. Print the number, modulo
998244353
, of positive integers
X
none of whose digits is
0
such that
f(X) = Y
. | [
{
"input": "1332\n",
"output": "3\n"
},
{
"input": "3312\n",
"output": "0\n"
},
{
"input": "12234433442\n",
"output": "153\n"
}
] |
https://atcoder.jp/contests/arc153/tasks/arc153_f | Problem Statement
You are given a simple connected undirected graph
G
with
N
vertices and
M
edges. The vertices are numbered
1
to
N
, and the
i
-th edge connects vertices
A_i
and
B_i
.
Find the number of ways to paint each edge of
G
in color
1
,
2
, or
3
so that the following condition is satisfied, modulo
998244353
.
There is a simple path in
G
that contains an edge in color
1
, an edge in color
2
, and an edge in color
3
.
What is a simple path?
A simple path is a pair of a sequence of vertices
(v_1, \ldots, v_{k+1})
and a sequence of edges
(e_1, \ldots, e_k)
that satisfies the following:
i\neq j \implies v_i\neq v_j
;
edge
e_i
connects vertices
v_i
and
v_{i+1}
. | [
{
"input": "3 3\n1 2\n1 3\n3 2\n",
"output": "0\n"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "534\n"
},
{
"input": "6 5\n1 3\n4 3\n5 4\n4 2\n1 6\n",
"output": "144\n"
},
{
"input": "6 7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n1 6\n",
"output": "1794\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_a | Problem Statement
You are given
N
strings
S_1,S_2,\ldots,S_N
in this order.
Print
S_N,S_{N-1},\ldots,S_1
in this order. | [
{
"input": "3\nTakahashi\nAoki\nSnuke\n",
"output": "Snuke\nAoki\nTakahashi\n"
},
{
"input": "4\n2023\nYear\nNew\nHappy\n",
"output": "Happy\nNew\nYear\n2023\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_b | Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer
T
. Solve the following problem for
T
test cases.
We have
N
positive integers
A_1, A_2, ..., A_N
. How many of them are odd? | [
{
"input": "4\n3\n1 2 3\n2\n20 23\n10\n6 10 4 1 5 9 8 6 5 1\n1\n1000000000\n",
"output": "2\n1\n5\n0\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_c | Problem Statement
You are given a simple 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
.
Find the number of connected components in this graph. | [
{
"input": "5 3\n1 2\n1 3\n4 5\n",
"output": "2\n"
},
{
"input": "5 0\n",
"output": "5\n"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_d | Problem Statement
You are given a positive integer
N
. It is known that
N
can be represented as
N=p^2q
using two different prime numbers
p
and
q
.
Find
p
and
q
.
You have
T
test cases to solve. | [
{
"input": "3\n2023\n63\n1059872604593911\n",
"output": "17 7\n3 7\n104149 97711\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_e | Problem Statement
You are given a simple 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
. The degree of each vertex is at most
10
.
Let
K
be the number of simple paths (paths without repeated vertices) starting from vertex
1
. Print
\min(K, 10^6)
. | [
{
"input": "4 2\n1 2\n2 3\n",
"output": "3\n"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"output": "16\n"
},
{
"input": "8 21\n2 6\n1 3\n5 6\n3 8\n3 6\n4 7\n4 6\n3 4\n1 5\n2 4\n1 2\n2 7\n1 4\n3 5\n2 5\n2 3\n4 5\n3 7\n6 7\n5 7\n2 8\n",
"output": "2023\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_f | Problem Statement
For a string
S
of length
N
and an integer
i\ (0\leq i\leq N)
, let us define the string
f_i(S)
as the concatenation of:
the first
i
characters of
S
,
the reversal of
S
, and
the last
(N-i)
characters of
S
,
in this order.
For instance, if
S=
abc
and
i=2
, we have
f_i(S)=
abcbac
.
You are given a string
T
of length
2N
.
Find a pair of a string
S
of length
N
and an integer
i\ (0\leq i\leq N)
such that
f_i(S)=T
.
If no such pair of
S
and
i
exists, report that fact. | [
{
"input": "3\nabcbac\n",
"output": "abc\n2\n"
},
{
"input": "4\nabababab\n",
"output": "abab\n1\n"
},
{
"input": "3\nagccga\n",
"output": "cga\n0\n"
},
{
"input": "4\natcodeer\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_g | Problem Statement
For a sequence of length
N
,
A = (A_1,A_2,\dots,A_N)
, consisting of integers between
1
and
N
, inclusive, and an integer
i\ (1\leq i \leq N)
, let us define a sequence of length
10^{100}
,
B_i=(B_{i,1},B_{i,2},\dots,B_{i,10^{100}})
, as follows.
B_{i,1}=i
.
B_{i,j+1}=A_{B_{i,j}}\ (1\leq j<10^{100})
.
Additionally, let us define
S_i
as the number of distinct integers that occur exactly once in the sequence
B_i
.
More formally,
S_i
is the number of values
k
such that exactly one index
j\ (1\leq j\leq 10^{100})
satisfies
B_{i,j}=k
.
You are given an integer
N
. There are
N^N
sequences that can be
A
. Find the sum of
\displaystyle \sum_{i=1}^{N} S_i
over all of them, modulo
M
. | [
{
"input": "4 100000000\n",
"output": "624\n"
},
{
"input": "7 1000000000\n",
"output": "5817084\n"
},
{
"input": "2023 998244353\n",
"output": "737481389\n"
},
{
"input": "100000 353442899\n",
"output": "271798911\n"
}
] |
https://atcoder.jp/contests/abc284/tasks/abc284_h | Problem Statement
You are to generate a graph by the following procedure.
Choose a simple undirected graph with
N
unlabeled vertices.
Write a positive integer at most
K
in each vertex in the graph. Here, there must not be a positive integer at most
K
that is not written in any vertex.
Find the number of possible graphs that can be obtained, modulo
P
. (
P
is a
prime
.)
Two graphs are considered the same if and only if one can label the vertices in each graph as
v_1, v_2, \dots, v_N
to satisfy the following conditions.
For every
i
such that
1 \leq i \leq N
, the numbers written in vertex
v_i
in the two graphs are the same.
For every
i
and
j
such that
1 \leq i \lt j \leq N
, there is an edge between
v_i
and
v_j
in one of the graphs if and only if there is an edge between
v_i
and
v_j
in the other graph. | [
{
"input": "3 1 998244353\n",
"output": "4\n"
},
{
"input": "3 2 998244353\n",
"output": "12\n"
},
{
"input": "5 5 998244353\n",
"output": "1024\n"
},
{
"input": "30 15 202300013\n",
"output": "62712469\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_a | Problem Statement
A string
x
consisting of lowercase English letters is said to be
good
if and only if the following condition is satisfied.
Every (contiguous) substring of
x
whose length is
2
or greater satisfies the following:
no character occupies the majority of that substring.
For example,
acbca
is not good because
c
occupies the majority of the substring
cbc
.
You are given a string
S
of length
N
consisting of lowercase English letters and
?
.
You want to replace each
?
with a lowercase English letter of your choice to make
S
a good string.
Find the number of ways to make
S
a good string, modulo
998244353
. | [
{
"input": "3\na?b\n",
"output": "24\n"
},
{
"input": "3\na?a\n",
"output": "0\n"
},
{
"input": "20\nugsyakganihodnwmktgi\n",
"output": "1\n"
},
{
"input": "20\n??a???h?m?y?ts???tl?\n",
"output": "444225229\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_b | Problem Statement
We have a grid with
N
rows and
M
columns.
You want to write an integer between
0
and
2^K-1
in each square in the grid to satisfy the following condition.
Consider a path that starts at the top-left square, repeatedly moves right or down to an adjacent square, and ends at the bottom-right square.
Such a path is said to be
good
if and only if the total
\mathrm{XOR}
of the integers written on the squares visited (including the starting and ending points) is
0
.
There is exactly one good path, which is the path represented by a string
S
.
The path represented by the string
S
is a path that, for each
i
(
1 \leq i \leq N+M-2
), the
i
-th move is right if the
i
-th character of
S
is
R
and down if that character is
D
.
Determine whether there is a way to write integers that satisfies the condition.
For each input file, solve
T
test cases.
What is bitwise
\mathrm{XOR}
?
The bitwise
\mathrm{XOR}
of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows.
When
A \oplus B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3 \oplus 5 = 6
(in binary:
011 \oplus 101 = 110
).
Generally, the bitwise
\mathrm{XOR}
of
k
non-negative integers
p_1, p_2, p_3, \dots, p_k
is defined as
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
, which can be proved to be independent of the order of
p_1, p_2, p_3, \dots, p_k
. | [
{
"input": "4\n2 2 1\nRD\n4 3 1\nRDDDR\n15 20 18\nDDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR\n20 15 7\nDRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD\n",
"output": "Yes\nNo\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_c | Problem Statement
Consider a permutation
P=(P_1,P_2,\cdots,P_{2^N-1})
of
(1,2,\cdots,2^N-1)
.
P
is said to be
heaplike
if and only if all of the following conditions are satisfied.
P_i < P_{2i}
(
1 \leq i \leq 2^{N-1}-1
)
P_i < P_{2i+1}
(
1 \leq i \leq 2^{N-1}-1
)
You are given integers
A
and
B
.
Let
U=2^A
and
V=2^{B+1}-1
.
Find the probability, modulo
998244353
, that
P_U<P_V
for a heaplike permutation chosen uniformly at random.
Definition of probability modulo
998244353
It can be proved that the sought probability is always rational. Additionally, under the constraints of this problem, when the sought rational number is represented as an irreducible fraction
\frac{P}{Q}
, it can be proved that
Q \neq 0 \pmod{998244353}
. Therefore, there is a unique integer
R
such that
R \times Q \equiv P \pmod{998244353}
and
0 \leq R \lt 998244353
. Print this
R
. | [
{
"input": "2 1 1\n",
"output": "499122177\n"
},
{
"input": "3 1 2\n",
"output": "124780545\n"
},
{
"input": "4 3 2\n",
"output": "260479386\n"
},
{
"input": "2022 12 25\n",
"output": "741532295\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_d | Problem Statement
Find the number of pairs
(P,Q)=((P_1,P_2,\cdots,P_N),(Q_1,Q_2,\cdots,Q_N))
of permutations of
(1,2,\cdots,N)
that satisfy the following condition, modulo
998244353
.
For every
i
(
1 \leq i \leq N-1
), one of the two conditions below holds.
P_i < P_{i+1}
and
Q_i < Q_{i+1}
.
P_i > P_{i+1}
and
Q_i > Q_{i+1}
. | [
{
"input": "2\n",
"output": "2\n"
},
{
"input": "3\n",
"output": "10\n"
},
{
"input": "4\n",
"output": "88\n"
},
{
"input": "10\n",
"output": "286574791\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_e | Problem Statement
In this problem, a permutation of
(1,2,\cdots,N)
is occasionally called just a permutation.
For a permutation
a=(a_1,a_2,\cdots,a_N)
, let
f(a)
be the number of cycles in
a
.
More accurately, the value of
f(a)
is defined as follows.
Consider an undirected graph consisting of
N
vertices numbered
1
to
N
.
For each
1 \leq i \leq N
, add an edge connecting vertex
i
and vertex
a_i
.
Then, let
f(a)
be the number of connected components in this graph.
You are given a permutation
P=(P_1,P_2,\cdots,P_N)
and an integer
K
.
Determine whether there is a permutation
x
that satisfies the following condition, and construct one if it exists.
Let
y_i=P_{x_i}
to define a permutation
y
.
Then,
f(x)+f(y)=K
holds.
For each input file, solve
T
test cases. | [
{
"input": "3\n3 3\n1 3 2\n2 2\n2 1\n4 8\n1 2 3 4\n",
"output": "Yes\n2 1 3\nNo\nYes\n1 2 3 4\n"
}
] |
https://atcoder.jp/contests/agc060/tasks/agc060_f | Problem Statement
You have a simple undirected graph.
Each vertex in this graph has an integer interval written on it, and there are
C_{i,j}
vertices with the interval
[i,j]
(
1 \leq i \leq j \leq N
).
There are no vertices with other intervals.
For any two vertices, there is an undirected edge between them if and only if the written intervals intersect.
Here, an interval
[a,b]
and an interval
[c,d]
intersect if and only if
\max(a,c) \leq \min(b,d)
.
Find the number of spanning trees of this graph, modulo
998244353
.
Here, all vertices are pairwise distinguishable. | [
{
"input": "2\n1 2\n1\n",
"output": "8\n"
},
{
"input": "3\n1 1 1\n1 1\n1\n",
"output": "99\n"
},
{
"input": "4\n8 3 8 10\n1 5 3\n1 6\n4\n",
"output": "971555314\n"
},
{
"input": "10\n2742 5611 1401 5439 5220 8571 4998 4194 7443 2492\n2393 3201 9106 1649 2456 1984 7159 9679 7695\n808 4600 2573 7771 5839 9504 4381 3223\n5325 2564 456 5050 6963 913 9072\n310 1521 9816 6205 2988 3614\n4810 2979 2852 9242 6290\n7551 7139 7228 699\n4869 889 7597\n4239 5970\n865\n",
"output": "234850531\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_a | Problem Statement
Given integers
A
and
B
,
print the value
A^B
. | [
{
"input": "4 3\n",
"output": "64\n"
},
{
"input": "5 5\n",
"output": "3125\n"
},
{
"input": "8 1\n",
"output": "8\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_b | Problem Statement
You are given an integer
N
and a sequence
A=(A _ 1,A _ 2,\ldots,A _ N)
of length
N
.
Given
Q
queries, process them in the given order.
Each query is of one of the following two kinds:
1 k x
: set the value
A _ k
to
x
.
2 k
: print the value
A _ k
. | [
{
"input": "3\n1 3 5\n7\n2 2\n2 3\n1 3 0\n2 3\n1 2 8\n2 2\n2 1\n",
"output": "3\n5\n0\n8\n1\n"
},
{
"input": "5\n22 2 16 7 30\n10\n1 4 0\n1 5 0\n2 2\n2 3\n2 4\n2 5\n1 4 100\n1 5 100\n2 3\n2 4\n",
"output": "2\n16\n0\n0\n16\n100\n"
},
{
"input": "7\n478 369 466 343 541 42 165\n20\n2 1\n1 7 729\n1 6 61\n1 6 838\n1 3 319\n1 4 317\n2 4\n1 1 673\n1 3 176\n1 5 250\n1 1 468\n2 6\n1 7 478\n1 5 595\n2 6\n1 6 599\n1 6 505\n2 3\n2 5\n2 1\n",
"output": "478\n317\n838\n838\n176\n595\n468\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_c | Problem Statement
Takahashi is a cashier.
There is a cash register with
11
keys:
00
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
, and
9
.
The cash register initially displays
0
.
Whenever he types the key
00
, the displayed number is multiplied by
100
;
whenever he types one of the others, the displayed number is multiplied by
10
, and then added by the number written on the key.
Takahashi wants the cash register to display an integer
S
.
At least how many keystrokes are required to make it display
S
? | [
{
"input": "40004\n",
"output": "4\n"
},
{
"input": "1355506027\n",
"output": "10\n"
},
{
"input": "10888869450418352160768000001\n",
"output": "27\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_d | Problem Statement
A string consisting of lowercase English letters,
(
, and
)
is said to be a
good string
if you can make it an empty string by the following procedure:
First, remove all lowercase English letters.
Then, repeatedly remove consecutive
()
while possible.
For example,
((a)ba)
is a good string, because removing all lowercase English letters yields
(())
, from which we can remove consecutive
()
at the
2
-nd and
3
-rd characters to obtain
()
, which in turn ends up in an empty string.
You are given a good string
S
.
We denote by
S_i
the
i
-th character of
S
.
For each lowercase English letter
a
,
b
,
\ldots
, and
z
, we have a ball with the letter written on it.
Additionally, we have an empty box.
For each
i = 1,2,
\ldots
,|S|
in this order, Takahashi performs the following operation unless he faints.
If
S_i
is a lowercase English letter, put the ball with the letter written on it into the box. If the ball is already in the box, he faints.
If
S_i
is
(
, do nothing.
If
S_i
is
)
, take the maximum integer
j
less than
i
such that the
j
-th through
i
-th characters of
S
form a good string. (We can prove that such an integer
j
always exists.) Take out from the box all the balls that he has put in the
j
-th through
i
-th operations.
Determine if Takahashi can complete the sequence of operations without fainting. | [
{
"input": "((a)ba)\n",
"output": "Yes\n"
},
{
"input": "(a(ba))\n",
"output": "No\n"
},
{
"input": "(((())))\n",
"output": "Yes\n"
},
{
"input": "abca\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_e | Problem Statement
You are given a matrix
A
with
H
rows and
W
columns. The value of each of its elements is
0
or
1
.
For an integer pair
(i, j)
such that
1 \leq i \leq H
and
1 \leq j \leq W
, we denote by
A_{i,j}
the element at the
i
-th row and
j
-th column.
You can perform the following operation on the matrix
A
any number of times (possibly zero):
Choose an integer
i
such that
1 \leq i \leq H
. For every integer
j
such that
1 \leq j \leq W
, replace the value of
A_{i,j}
with
1-A_{i,j}
.
A_{i,j}
is said to be
isolated
if and only if there is no adjacent element with the same value; in other words, if and only if none of the four integer pairs
(x,y) = (i-1,j),(i+1,j),(i,j-1),(i,j+1)
satisfies
1 \leq x \leq H, 1 \leq y \leq W
, and
A_{i,j} = A_{x,y}
.
Determine if you can make the matrix
A
in such a state that no element is isolated by repeating the operation. If it is possible, find the minimum number of operations required to do so. | [
{
"input": "3 3\n1 1 0\n1 0 1\n1 0 0\n",
"output": "1\n"
},
{
"input": "4 4\n1 0 0 0\n0 1 1 1\n0 0 1 0\n1 1 0 1\n",
"output": "2\n"
},
{
"input": "2 3\n0 1 0\n0 1 1\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_f | Problem Statement
You are given a permutation
P=(P _ 1,P _ 2,\ldots,P _ N)
of
(1,2,\ldots,N)
.
Find the following value for all
i\ (1\leq i\leq N)
:
D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen
.
What is a permutation?
A permutation of
(1,2,\ldots,N)
is a sequence that is obtained by rearranging
(1,2,\ldots,N)
.
In other words, a sequence
A
of length
N
is a permutation of
(1,2,\ldots,N)
if and only if each
i\ (1\leq i\leq N)
occurs in
A
exactly once. | [
{
"input": "4\n3 2 4 1\n",
"output": "2 2 3 3 \n"
},
{
"input": "7\n1 2 3 4 5 6 7\n",
"output": "2 2 2 2 2 2 2 \n"
},
{
"input": "16\n12 10 7 14 8 3 11 13 2 5 6 16 4 1 15 9\n",
"output": "3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7 \n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_g | Problem Statement
For a sequence of non-negative integers
(a _ 1,a _ 2,\ldots,a _ n)
, let us define its
\operatorname{xor}
as the integer
X
such that, for all non-negative integer
j
:
the
2^j
s place of
X
is
1
if and only if there is an odd number of elements among
a _ 1,\ldots,a _ n
whose
2^j
s place is
1
.
You are given a sequence of non-negative integers
A=(A _ 1,A _ 2,\ldots,A _ N)
of length
N
.
Let
\lbrace s _ 1,s _ 2,\ldots,s _ k\rbrace\ (s _ 1\lt s _ 2\lt\cdots\lt s _ k)
be the set of all non-negative integers that can be the
\operatorname{xor}
of a not-necessarily-contiguous (possibly empty) subsequence of
A
.
Given integers
L
and
R
, print
s _ L,s _ {L+1},\ldots,s _ R
in this order. | [
{
"input": "4 1 8\n2 21 17 21\n",
"output": "0 2 4 6 17 19 21 23\n"
},
{
"input": "4 3 7\n2 21 17 21\n",
"output": "4 6 17 19 21\n"
},
{
"input": "5 1 1\n0 0 0 0 0\n",
"output": "0\n"
},
{
"input": "6 21 21\n88 44 82 110 121 80\n",
"output": "41\n"
},
{
"input": "12 26 48\n19629557415 14220078328 11340722069 30701452525 22333517481 720413777 11883028647 20926361028 24376768297 720413777 27999065315 13558621130\n",
"output": "13558621130 14220078328 14586054825 15518998043 15970974282 16379590008 17091531049 17412316967 17836964726 18263536708 18965057557 19629557415 20282860278 20926361028 21302757781 21908867832 22333517481 22893781403 23595304394 23723463544 24376768297 24885524507 25261923402\n"
}
] |
https://atcoder.jp/contests/abc283/tasks/abc283_h | Problem Statement
Find the sum of popcounts of all integers between
1
and
N
, inclusive, such that the remainder when divided by
M
equals
R
.
Here, the popcount of a positive integer
X
is the number of
1
s in the binary notation of
X
, that is, the number of non-negative integers
k
such that the
2^k
s place is
1
.
For each input, process
T
test cases. | [
{
"input": "2\n12 5 1\n6 1 0\n",
"output": "6\n9\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_a | å顿
ããŒããªã³ã°ã®æäœãé«ã
500
åè¡ãããšã§ïŒä»¥äžã®ç»åã«è¿ãç»åãäœãäžããïŒ
åŸè¿°ã®éææ¡ä»¶ãæºãããŠããã°ïŒã«ã©ãã«ãªç»åã«ããŠãããïŒ | [] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_b | å顿
æŽæ°
N, K, P
ããã³ïŒæå
A
,
B
ãããªãé·ã
N
ã®æåå
S
ãäžããããïŒå
k = 1, 2, \ldots, K
ã«å¯ŸããŠä»¥äžã®åã«çãã (å
k
ã«é¢ããåã¯å¥ã
ã«èãã)ïŒ
ãããããšãããããåé¡ã®éè§£ãç«¶äºãè¡ãïŒåé¡ã¯
1
åãã€åºé¡ããïŒ
i
åç® (
i = 1, 2, \ldots
) ã¯ä»¥äžã®ããã«ãªãïŒ
i \le N
ãã€
S
ã®
i
æåç®ã
A
ã§ããå ŽåïŒç¢ºç
\frac{P}{100}
ã§ãããããå
ã«è§£ãïŒç¢ºç
1 - \frac{P}{100}
ã§ãããããå
ã«è§£ãïŒ
i \le N
ãã€
S
ã®
i
æåç®ã
B
ã§ããå ŽåïŒç¢ºç
1 - \frac{P}{100}
ã§ãããããå
ã«è§£ãïŒç¢ºç
\frac{P}{100}
ã§ãããããå
ã«è§£ãïŒ
i > N
ã®å ŽåïŒç¢ºç
\frac{1}{2}
ã§ãããããå
ã«è§£ãïŒç¢ºç
\frac{1}{2}
ã§ãããããå
ã«è§£ãïŒ
ã
i
åç®ããããããå
ã«è§£ãããšããäºè±¡ãã¡ã¯äºãã«ç¬ç«ã§ããïŒ
ãå
ã«è§£ããåé¡ãã
k
åã«å°éããããããçŸããæç¹ã§ç«¶äºãçµäºãïŒãã®ãããã®åªåãšããïŒãããããåªåãã確çãš
\frac{1}{2}
ã®
倧å°ãæ¯èŒããïŒ | [
{
"input": "2 2 25\nAB\n",
"output": "-0\n"
},
{
"input": "10 4 99\nAABBBAABBB\n",
"output": "++-+\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_c | å顿
(1,2,\ldots,N)
ã®é å
P=(P_1,P_2,\ldots,P_N)
ãš
Q=(Q_1,Q_2,\ldots,Q_N)
ãäžããããïŒä»¥äžã®æäœãé«ã
N^2
åè¡ã£ãŠ
P
ã
Q
ã«äžèŽããããããå€å®ãïŒå¯èœãªå Žåã¯ãã®ãããªæäœåã
1
éãæ±ããïŒ
æ¬¡ã®æ¡ä»¶ã®ãã¡å°ãªããšãäžæ¹ãæºããæŽæ°
i
ãéžã³ïŒ
P_i
ãš
P_{i+1}
ã®å€ãå
¥ãæ¿ããïŒ
1 \leq i \leq N-2
ãã€
\min(P_i,P_{i+1}) < P_{i+2} < \max(P_i,P_{i+1})
2 \leq i \leq N-1
ãã€
\min(P_i,P_{i+1}) < P_{i-1} < \max(P_i,P_{i+1}) | [
{
"input": "3\n2 1 3\n2 3 1\n",
"output": "1\n2\n"
},
{
"input": "3\n1 2 3\n1 3 2\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_d | å顿
éè² æŽæ°
N, A, B, C
ãäžããããïŒ
æ£
æŽæ°å
(x_0, x_1, \ldots, x_N)
ã§ãã£ãŠïŒä»¥äžã®æ¡ä»¶ããã¹ãŠæºãããã®ã®åæ°ã
998244353
ã§å²ã£ãäœããæ±ããïŒ
x_0 = 2^A \times 2^B
ïŒ
x_N = ((2^A + 1) \times 2^C) - 1
ïŒ
å
i = 0, 1, \ldots, N - 1
ã«å¯ŸãïŒ
x_{i+1} \in \{ \lfloor x_i/2 \rfloor, 2 x_i, 2 x_i + 1 \}
ïŒ | [
{
"input": "4 1 1 1\n",
"output": "7\n"
},
{
"input": "9 2 0 1\n",
"output": "1164\n"
},
{
"input": "1 0 2 4\n",
"output": "0\n"
},
{
"input": "2022 12 24 14\n",
"output": "426021617\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_e | å顿
æŽæ°
P_1, P_2, \ldots, P_N
ãäžããããïŒ
N
æã®ã³ã€ã³ãããïŒãããã
1, 2, \ldots, N
ã®çªå·ãä»ããŠããïŒã©ã®
2
æã®ã³ã€ã³ãåºå¥ã§ããïŒããããããããããç¹æ®ãªæ¹æ³ã§ãããã®ã³ã€ã³ãäžæã«æãïŒåã³ã€ã³ã衚ãŸãã¯è£ã®ããããäžæ¹ã«ãªãïŒ
ã³ã€ã³
i
ã¯ç¢ºç
\frac{P_i}{100}
ã§è¡šã«ãªãïŒç¢ºç
1 - \frac{P_i}{100}
ã§è£ã«ãªãããšãããã£ãŠãã (
1 \le i \le N
)ïŒãŸãïŒã©ã®ç°ãªã
2
æã®ã³ã€ã³
i, j
ã«ã€ããŠãïŒã³ã€ã³
i
ã衚ã«ãªãäºè±¡ãšã³ã€ã³
j
ã衚ã«ãªãäºè±¡ã¯ç¬ç«ã§ããããšãããã£ãŠãã (
1 \le i, j \le N
ïŒ
i \ne j
)ïŒ
ãã®ãšãïŒãã¹ãŠã®ã³ã€ã³ã衚ã«ãªã確çãšããŠèããããæå°å€ãæ±ããïŒãã®åé¡ã®å¶çŽäžã§æå°å€ãååšããããšã蚌æã§ããïŒ | [
{
"input": "2\n13 77\n",
"output": "0.1001\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_f | å顿
ç¡åã°ã©ã
G
ã¯
1, 2, \ldots, N
ãé ç¹ãšãïŒé ç¹
u
ãšé ç¹
v
ãçµã¶èŸºã¯ã¡ããã©
A_{u,v}
æ¬ãã (
1 \le u, v \le N
)ïŒãã¹ãŠã®èŸºã¯åºå¥ãããïŒ
å
k = 0, 1, \ldots, \lfloor N/2 \rfloor
ã«å¯ŸãïŒ
G
ã®å€§ãã
k
ã®ãããã³ã°ã®åæ°ã
2^{64}
ã§å²ã£ãäœããæ±ããïŒ
(
G
ã®å€§ãã
k
ã®ãããã³ã°ãšã¯ïŒ
G
ã®èŸº
k
æ¬ãããªãéåã§ãã£ãŠïŒãããã®ç«¯ç¹
2 k
åãçžç°ãªããããªãã®ãæãïŒ) | [
{
"input": "4\n0 10 300 0\n10 0 5 400\n300 5 0 20\n0 400 20 0\n",
"output": "1 735 120200\n"
},
{
"input": "7\n0 1 1 1 1 1 1\n1 0 1 1 1 1 1\n1 1 0 1 1 1 1\n1 1 1 0 1 1 1\n1 1 1 1 0 1 1\n1 1 1 1 1 0 1\n1 1 1 1 1 1 0\n",
"output": "1 21 105 105\n"
},
{
"input": "10\n0 8629318490492529455 16934461172002342162 16689922355946803515 6532726440738276996 1194408499640297875 15866676155001669889 6498797546467110859 16876940315014902410 12387509481131737340\n8629318490492529455 0 11507224725899007093 8715646015311805917 10082055328422634515 11661112510609506937 5671467989936109679 9958089075065687029 1044511129638713462 9641449008999128869\n16934461172002342162 11507224725899007093 0 9017212196119468141 8742031656924741889 16712732165713258491 12486619021854068086 8079880079267306335 7411259632269635598 847494329973810398\n16689922355946803515 8715646015311805917 9017212196119468141 0 16283252096557152371 8615030617835929416 17667878928797645683 18446439882335127774 11475081586957078864 15537196317840490094\n6532726440738276996 10082055328422634515 8742031656924741889 16283252096557152371 0 2328769271400341339 5743580703459253102 13482125554117518013 8310663885706538154 15657502149293391713\n1194408499640297875 11661112510609506937 16712732165713258491 8615030617835929416 2328769271400341339 0 13134573721194912427 3260072811817230082 12647757802949221999 15331084503094140917\n15866676155001669889 5671467989936109679 12486619021854068086 17667878928797645683 5743580703459253102 13134573721194912427 0 5011674754910118042 4293452480892783480 12853153721226986708\n6498797546467110859 9958089075065687029 8079880079267306335 18446439882335127774 13482125554117518013 3260072811817230082 5011674754910118042 0 8466317684966562639 13151347917827920992\n16876940315014902410 1044511129638713462 7411259632269635598 11475081586957078864 8310663885706538154 12647757802949221999 4293452480892783480 8466317684966562639 0 1834230013668150904\n12387509481131737340 9641449008999128869 847494329973810398 15537196317840490094 15657502149293391713 15331084503094140917 12853153721226986708 13151347917827920992 1834230013668150904 0\n",
"output": "1 13998873960259808869 16134958027077044128 15075909322183550749 13815169532537848652 14625654317779811048\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_g | å顿
1
åã®å
¥åãã¡ã€ã«ã«ã€ã
T
åã®ãã¹ãã±ãŒã¹ãäžããããïŒåãã¹ãã±ãŒã¹ã§æŽæ°
N, S
ãäžããããã®ã§ïŒä»¥äžã®åã«çããïŒ
æŽæ°
A_0, A_1, \ldots, A_{4N-1}
ã以äžã®ããã«å®ããïŒæ°åŒããã³ C++ ã³ãŒãçã§ç€ºãïŒ
倿°
s
ã
s \gets S
ãšããïŒ
i = 0, 1, \ldots, 4 N - 1
ã«å¯Ÿããã®é ã§ïŒ
A_i \gets \lfloor i/4 \rfloor + 1
ãšããïŒ
i = 0, 1, \ldots, 4 N - 1
ã«å¯Ÿããã®é ã§ïŒ
s \gets (s \times 2022) \bmod 998244353
ãšããŠããïŒ
s \not\equiv 0 \pmod{2}
ãªãã°
A_i \gets -A_i
ãšããïŒ
i = 0, 1, \ldots, 4 N - 1
ã«å¯Ÿããã®é ã§ïŒ
s \gets (s \times 2022) \bmod 998244353
ãšããŠããïŒ
A_{s \bmod (i+1)}
ãš
A_i
ã®å€ãå
¥ãæ¿ããïŒ
#include <vector>
std::vector<int> Generate(int N, long long S) {
long long s = S;
std::vector<int> A(4 * N);
for (int i = 0; i < 4 * N; ++i) {
A[i] = i / 4 + 1;
}
for (int i = 0; i < 4 * N; ++i) {
s = (s * 2022) % 998244353;
if (s % 2 != 0) {
A[i] = -A[i];
}
}
for (int i = 0; i < 4 * N; ++i) {
s = (s * 2022) % 998244353;
int j = s % (i + 1);
int t = A[j];
A[j] = A[i];
A[i] = t;
}
return A;
}
å
j = 1, 2, \ldots, N
ã«å¯ŸããŠ
+j
ãš
-j
ã®ããããã¡ããã©äžæ¹ããè¯ãæŽæ°ããšæ±ºããæ¹æ³
2^N
éãã®ãã¡ïŒä»¥äžã®
N
åã®æ¡ä»¶ããã¹ãŠæºãããã®ãååšãããã©ããå€å®ãïŒååšããå Žåã¯ãã®ãããªæ¹æ³ã
1
éãæ±ããïŒ
A_0, A_1, A_2, A_3
ã®ãã¡å°ãªããšã
1
åã¯è¯ãæŽæ°ã§ããïŒ
A_4, A_5, A_6, A_7
ã®ãã¡å°ãªããšã
1
åã¯è¯ãæŽæ°ã§ããïŒ
\cdots
A_{4N-4}, A_{4N-3}, A_{4N-2}, A_{4N-1}
ã®ãã¡å°ãªããšã
1
åã¯è¯ãæŽæ°ã§ããïŒ | [
{
"input": "2\n3 1\n4 20221224\n",
"output": "++-\n+--+\n"
}
] |
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_h | å顿
1
åã®å
¥åãã¡ã€ã«ã«ã€ã
T
åã®ãã¹ãã±ãŒã¹ãäžããããïŒåãã¹ãã±ãŒã¹ã§æ¬¡ã®ãããªã°ã©ã
G
ãäžããããã®ã§ïŒä»¥äžã®åã«çããïŒ
G
ã¯
N
é ç¹
M
蟺ãããªãé£çµãªåçŽç¡åã°ã©ãã§ããïŒé ç¹ã«ã¯
1
ãã
N
ãŸã§ã®çªå·ãã€ããŠããïŒ
i
çªç®ã®èŸºã¯é ç¹
A_i
ãš
B_i
ãçµãã§ãã (
1 \le i \le M
)ïŒ
ä»ïŒ
G
ã®é ç¹ã¯ãã¹ãŠçœè²ã§å¡ãããŠããïŒããããïŒãããããšãããããæ¬¡ã®ã²ãŒã ãè¡ãïŒ
ãŸãïŒããããã奜ããªé ç¹ã
1
åéžã³ïŒé»è²ã§å¡ãïŒ
ãã®åŸïŒçœè²ã«å¡ãããŠããé ç¹ãååšããéãïŒããããã以äžã®æäœãç¹°ãè¿ãïŒ
é»è²ã§å¡ãããŠããé ç¹ã«é£æ¥ããŠãããããªé ç¹ã
1
åãŸãã¯
2
åéžã¶ïŒéžãã é ç¹ããã¹ãŠé»è²ã§å¡ãïŒ
ããããã®æäœåæ°ã
ã¹ã³ã¢
ãšåŒã¶ïŒããããã®ç®çã¯ã¹ã³ã¢ã®æå€§åã§ããïŒããããã®ç®çã¯æå°åã§ããïŒäž¡è
ãæé©ã«è¡åããå Žåã®ã²ãŒã ã®ã¹ã³ã¢ãæ±ããïŒ | [
{
"input": "2\n3 2\n1 2\n2 3\n4 4\n1 2\n2 3\n3 4\n4 1\n",
"output": "2\n2\n"
},
{
"input": "2\n5 8\n5 1\n2 3\n2 4\n5 2\n1 3\n3 5\n1 4\n4 5\n20 40\n13 10\n13 19\n12 15\n14 7\n1 17\n8 17\n13 7\n10 7\n16 2\n5 20\n12 1\n3 12\n19 7\n8 20\n20 16\n2 5\n14 13\n3 9\n13 6\n5 16\n4 1\n2 4\n8 16\n14 10\n8 2\n11 8\n15 3\n18 5\n17 20\n11 17\n6 10\n16 11\n15 1\n9 6\n19 6\n8 4\n2 11\n20 11\n10 19\n16 18\n",
"output": "2\n11\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_a | Problem Statement
You are given an integer
K
.
Print a string that is a concatenation of the first
K
uppercase English letters in ascending order, starting from
A
. | [
{
"input": "3\n",
"output": "ABC\n"
},
{
"input": "1\n",
"output": "A\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_b | Problem Statement
N
participants, numbered
1
to
N
, will participate in a contest with
M
problems, numbered
1
to
M
.
For an integer
i
between
1
and
N
and an integer
j
between
1
and
M
, participant
i
can solve problem
j
if the
j
-th character of
S_i
is
o
, and cannot solve it if that character is
x
.
The participants must be in pairs. Print the number of ways to form a pair of participants who can collectively solve all the
M
problems.
More formally, print the number of pairs
(x,y)
of integers satisfying
1\leq x < y\leq N
such that for any integer
j
between
1
and
M
, at least one of participant
x
and participant
y
can solve problem
j
. | [
{
"input": "5 5\nooooo\noooxx\nxxooo\noxoxo\nxxxxx\n",
"output": "5\n"
},
{
"input": "3 2\nox\nxo\nxx\n",
"output": "1\n"
},
{
"input": "2 4\nxxxx\noxox\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_c | Problem Statement
You are given a string
S
of length
N
consisting of lowercase English letters,
,
, and
"
. It is guaranteed that
S
contains an even number of
"
.
Let
2K
be the number of
"
in
S
. For each
i=1,2,\ldots,K
, the characters from the
(2i-1)
-th
"
through the
(2i)
-th
"
are said to be
enclosed
.
Your task is to replace each
,
in
S
that is
not
an enclosed character with
.
and print the resulting string. | [
{
"input": "8\n\"a,b\"c,d\n",
"output": "\"a,b\"c.d\n"
},
{
"input": "5\n,,,,,\n",
"output": ".....\n"
},
{
"input": "20\na,\"t,\"c,\"o,\"d,\"e,\"r,\n",
"output": "a.\"t,\"c.\"o,\"d.\"e,\"r.\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_d | Problem Statement
You are given a simple undirected graph
G
with
N
vertices and
M
edges (a simple graph does not contain self-loops or multi-edges).
For
i = 1, 2, \ldots, M
, the
i
-th edge connects vertex
u_i
and vertex
v_i
.
Print the number of pairs of integers
(u, v)
that satisfy
1 \leq u \lt v \leq N
and both of the following conditions.
The graph
G
does not have an edge connecting vertex
u
and vertex
v
.
Adding an edge connecting vertex
u
and vertex
v
in the graph
G
results in a bipartite graph.
What is a bipartite graph?
An undirected graph is said to be
bipartite
if and only if one can paint each vertex black or white to satisfy the following condition.
No edge connects vertices painted in the same color. | [
{
"input": "5 4\n4 2\n3 1\n5 2\n3 2\n",
"output": "2\n"
},
{
"input": "4 3\n3 1\n3 2\n1 2\n",
"output": "0\n"
},
{
"input": "9 11\n4 9\n9 1\n8 2\n8 3\n9 2\n8 4\n6 7\n4 6\n7 5\n4 5\n7 8\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_e | Problem Statement
A box contains
N
balls, each with an integer between
1
and
M-1
written on it.
For
i = 1, 2, \ldots, N
, the integer written on the
i
-th ball is
A_i
.
While the box has two or more balls remaining, Takahashi will repeat the following.
First, choose two balls arbitrarily.
Then, get a score equal to the remainder when
x^y + y^x
is divided by
M
, where
x
and
y
are the integers written on the two balls.
Finally, choose one of the two balls arbitrarily, eat it, and return the other to the box.
Print the maximum possible total score Takahashi will get. | [
{
"input": "4 10\n4 2 3 2\n",
"output": "20\n"
},
{
"input": "20 100\n29 31 68 20 83 66 23 84 69 96 41 61 83 37 52 71 18 55 40 8\n",
"output": "1733\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_f | Problem Statement
This is an
interactive task
, where your and the judge's programs interact via Standard Input and Output.
You and the judge will follow the procedure below.
The procedure consists of phases
1
and
2
; phase
1
is immediately followed by phase
2
.
(Phase
1
)
The judge gives you an integer
N
.
You print an integer
M
between
1
and
50000
, inclusive.
You also print
M
pairs of integers
(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M)
such that
1 \leq l_i \leq r_i \leq N
for every
i = 1, 2, \ldots, M
(the
M
pairs do not have to be distinct).
(Phase
2
)
The judge gives you an integer
Q
.
You and the judge repeats the following
Q
times.
The judge gives you two integers
L
and
R
as a query.
You respond with two integers
a
and
b
between
1
and
M
, inclusive (possibly with
a = b
).
Here,
a
and
b
must satisfy the condition below. Otherwise, your submission will be judged incorrect.
The union of the set
\lbrace l_a, l_a+1, \ldots, r_a\rbrace
and the set
\lbrace l_b, l_b+1, \ldots, r_b\rbrace
equals the set
\lbrace L, L+1, \ldots, R\rbrace
.
After the procedure above, terminate the program immediately to be judged correct. | [] |
https://atcoder.jp/contests/abc282/tasks/abc282_g | Problem Statement
Below, a permutation of
(1,2,\ldots,N)
is simply called a permutation.
For two permutations
A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N)
, let us define their
similarity
as the number of integers
i
between
1
and
N-1
such that:
(A_{i+1}-A_i)(B_{i+1}-B_i)>0
.
Find the number, modulo a prime number
P
, of pairs of permutations
(A,B)
whose similarity is
K
. | [
{
"input": "3 1 282282277\n",
"output": "16\n"
},
{
"input": "50 25 998244353\n",
"output": "131276976\n"
}
] |
https://atcoder.jp/contests/abc282/tasks/abc282_h | Problem Statement
You are given two sequences of integers of length
N
:
A = (A_1, A_2, \ldots, A_N)
and
B = (B_1, B_2, \ldots, B_N)
.
Print the number of pairs of integers
(l, r)
that satisfy
1 \leq l \leq r \leq N
and the following condition.
\min\lbrace A_l, A_{l+1}, \ldots, A_r \rbrace + (B_l + B_{l+1} + \cdots + B_r) \leq S | [
{
"input": "4 15\n9 2 6 5\n3 5 8 9\n",
"output": "6\n"
},
{
"input": "15 100\n39 9 36 94 40 26 12 26 28 66 73 85 62 5 20\n0 0 7 7 0 5 5 0 7 9 9 4 2 5 2\n",
"output": "119\n"
}
] |
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_a | å顿
JOI åžã«ã¯
1
ãã
N
ãŸã§ã®çªå·ãä»ãããã
N
人ã®äœæ°ãããïŒäœæ°
i
(
1 \leqq i \leqq N
) ã®å¹Žéœ¢ã¯
A_i
æ³ã§ããïŒ
JOI åžã®äœæ°ã®å¹Žéœ¢
A_1, A_2, \dots, A_N
ãäžããããïŒ
i = 1, 2, \dots, N
ã«å¯ŸããŠïŒäœæ°
i
ãšä»ã®äœæ°ãšã®å¹Žéœ¢ã®å·®ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "3\n13 15 20\n",
"output": "7\n5\n7\n"
},
{
"input": "2\n100 100\n",
"output": "0\n0\n"
},
{
"input": "10\n440894064 101089692 556439322 34369336 98417847 216265879 623843484 554560874 247445405 718003331\n",
"output": "406524728\n616913639\n522069986\n683633995\n619585484\n501737452\n589474148\n520191538\n470557926\n683633995\n"
}
] |
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_b | å顿
JOI äžåŠæ ¡ã«ã¯
4N
人ã®äžå¹Žçãåšç±ããŠããïŒ
4
ã€ã®ã¯ã©ã¹ã«åãããŠããïŒåã¯ã©ã¹ã®æ
å ±ã¯ä»¥äžã®éãã§ããïŒ
1 幎 A çµïŒ
N
人ã®çåŸãããïŒããããã®çåŸã®èº«é·ã¯
A_1, A_2, \ldots, A_N
ã§ããïŒ
1 幎 B çµïŒ
N
人ã®çåŸãããïŒããããã®çåŸã®èº«é·ã¯
B_1, B_2, \ldots, B_N
ã§ããïŒ
1 幎 C çµïŒ
N
人ã®çåŸãããïŒããããã®çåŸã®èº«é·ã¯
C_1, C_2, \ldots, C_N
ã§ããïŒ
1 幎 D çµïŒ
N
人ã®çåŸãããïŒããããã®çåŸã®èº«é·ã¯
D_1, D_2, \ldots, D_N
ã§ããïŒ
æ¥æïŒJOI äžåŠæ ¡ã§ã¯äœè²ç¥ãéå¬ãããããšã«ãªã£ãïŒäœè²ç¥ã«ã¯ïŒãªã¬ãŒïŒéšéЬæŠïŒæ£åããªã©ã®æ§ã
ãªçš®ç®ããããïŒååŠå¹Žãèžããã³ã¹ã¯ãäœè²ç¥ã®è¯ããšãåŒã°ããæ³šç®ã®çš®ç®ã§ããïŒ
ããã§äžå¹Žçã¯ïŒåã¯ã©ã¹ãã代衚ã
1
人ãã€éžã³ïŒ
4
人ã§ãã³ã¹ãããããšã«ãªã£ãïŒãã³ã¹ã®èŠæ ããã§ããã ãè¯ãããããïŒèº«é·ã®å·®ãã§ããã ãå°ãããªãããã«
4
人çµãéžã¶ããšã«ããïŒ
äžå¹Žçã®èº«é·ãäžãããããšãïŒã
4
人ã®èº«é·ã®æå€§å€ããšã
4
人ã®èº«é·ã®æå°å€ãã®å·®ãšããŠèããããæå°ã®å€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "1\n169\n173\n152\n200\n",
"output": "48\n"
},
{
"input": "7\n7 9 9 4 6 3 5\n1 1 1 1 1 1 1\n1 1 1 1 1 1 1\n1 1 1 1 1 1 1\n",
"output": "2\n"
},
{
"input": "7\n1 1 1 1 2 1 1\n1 2 1 1 1 1 1\n1 1 1 1 2 1 1\n1 1 1 1 1 1 2\n",
"output": "0\n"
},
{
"input": "5\n287 690 413 420 138\n813 873 223 415 907\n261 330 361 747 787\n958 672 544 126 345\n",
"output": "70\n"
},
{
"input": "10\n1682 2008 1135 1576 2450 1362 1518 1925 2212 1275\n1993 1945 1312 1401 2027 1705 1086 2333 1787 1654\n2257 1548 1219 1031 2613 2171 1866 1532 2800 1497\n1062 1175 1984 1870 2059 1639 2107 1335 1289 2494\n",
"output": "79\n"
}
] |
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_c | å顿
JOI ããã¯ãçµµãããœããã§éãã§ããïŒ
ãçµµãããœããã§ã¯ïŒçžŠ
H
è¡ïŒæšª
W
åã®é·æ¹åœ¢ã®ãã¹ç®ã«çµµãæãããšãã§ããïŒããããã®ãã¹ã«ã¯è²ãå®ããããŠããïŒè²ã¯
1
以äž
10^9
以äžã®æŽæ°ã§è¡šãããïŒ
äžãã
i
è¡ç® (
1 \leqq i \leqq H
)ïŒå·Šãã
j
åç® (
1 \leqq j \leqq W
) ã®ãã¹ããã¹
(i,j)
ãšåŒã¶ïŒçŸåšïŒãã¹
(i,j)
ã®è²ã¯
A_{i,j}
ã§ããïŒ
ãã¹
(i,j)
ããèŸºã§æ¥ããŠãããã¹ãžã®ç§»åãç¹°ãè¿ãïŒãã¹
(i,j)
ãšè²ãç°ãªããã¹ã«å
¥ãããšãªãç§»åã§ãããã¹ã®éãŸããïŒããã§ã¯
ãã¹
(i,j)
ã®é å
ãšåŒã¶ïŒ
ãçµµãããœããã«ã¯ïŒ
å¡ãã€ã¶ã
ãšããæ©èœãããïŒãã®æ©èœã§ã¯ïŒãããã¹
(x,y)
(
1 \leqq x \leqq H
ïŒ
1 \leqq y \leqq W
) ãšè²
c
(
1 \leqq c \leqq 10^9
) ãæå®ãããšïŒãã¹
(x,y)
ã®é åã«å«ãŸãããã¹ã®è²ããã¹ãŠ
c
ã«å€åããïŒ
JOI ããã¯ãããã¹
(x,y)
ãšè²
c
ãéžã³ïŒãã®ãã¹ãšè²ãæå®ããŠå¡ãã€ã¶ããã¡ããã©
1
å䜿ãïŒå¡ãã€ã¶ãã䜿ã£ãåŸã®ãã¹
(x,y)
ã®é åã«å«ãŸãããã¹ã®åæ°ã JOI ããã®åŸç¹ãšãªãïŒ
JOI ããã®åŸç¹ãšããŠéæå¯èœãªæå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "4 4\n1 2 3 1\n2 2 3 1\n1 2 3 1\n3 3 2 2\n",
"output": "9\n"
},
{
"input": "2 10\n1 2 2 1 3 3 3 3 1 1\n1 1 1 1 1 1 1 3 3 3\n",
"output": "18\n"
},
{
"input": "5 5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n",
"output": "25\n"
}
] |
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_d | å顿
IOI ééã¯
1
æ¬ã®ééè·¯ç·ãéå¶ããŠããïŒIOI ééç·ã«ã¯äžçŽç·äžã«äžŠãã
N
åã®é§
ãããïŒé ã«
1
ãã
N
ãŸã§ã®çªå·ãä»ããããŠããïŒå
i
(
1 \leqq i \leqq N - 1
) ã«å¯ŸããŠïŒé§
i
ãšé§
i + 1
ã®éã¯ç·è·¯ã§çµã°ããŠããïŒãã®é·ãã¯
1
ã§ããïŒ
IOI ééã¯è²šç©ãåãæ±ã£ãŠããïŒé§
2, 3, \ldots, N
ã«ã¯è²šç©ã
1
ã€ãã€çœ®ãããŠããïŒé§
i
(
2 \leqq i \leqq N
) ã«çœ®ãããŠãã貚ç©ã®äŸ¡å€ã¯
A_i
ã§ããïŒ
IOI ééã¯è²šç©åè»ã
1
ç·šæææããŠããïŒãã®åè»ã¯æåé§
1
ã«ããïŒIOI ééç·äžãåæ¹åã«èµ°è¡ã§ããïŒããããã®é§
ã§ã¯ïŒãã®é§
ã«çœ®ããŠãã貚ç©ãåè»ã«ç©ãããšãïŒåè»ã«ç©ãŸããŠãã貚ç©ãäžããïŒãã®é§
ã«çœ®ããŠããããšãã§ããïŒ
ãã®è²šç©åè»ãçšã㊠é§
2, 3, \ldots, N
ã«çœ®ãããŠãã貚ç©ãé§
1
ã«èŒžéãããïŒãã ãïŒãã®åè»ã«ã¯è²šç©ã
W
å以äžããèŒããããšãã§ããªãïŒããªãã¡ïŒã©ã®æç¹ã«ãããŠãåè»ã«è²šç©ã
W + 1
å以äžèŒã£ãŠããããšã¯èš±ãããªãïŒãŸãïŒãã®åè»ã¯çæã®éœåäžïŒæå€§ã§ãç·è·é¢
D
ããèµ°è¡ããããšãã§ããªãïŒãã®ããïŒãã¹ãŠã®è²šç©ãé§
1
ã«èŒžéããããšã¯ã§ããªããããããªãïŒ
IOI ééã®ç€Ÿé·ã§ãã JOI ããã¯ïŒãã®æ¡ä»¶ã®ããšé©åã«è²šç©åè»ãèµ°è¡ãããããšã§ïŒæçµçã«é§
1
ã«çœ®ãããŠãã貚ç©ã®äŸ¡å€ã®åèšããªãã¹ã倧ãããããïŒ
貚ç©åè»ã®æ
å ±ãšåé§
ã«çœ®ãããŠãã貚ç©ã®æ
å ±ãäžãããããšãïŒæçµçã«é§
1
ã«çœ®ãããŠãã貚ç©ã®äŸ¡å€ã®åèšãšããŠéæå¯èœãªæå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "4 1 10\n1 1 1\n",
"output": "2\n"
},
{
"input": "7 3 16\n1 1 1 1 1 1\n",
"output": "5\n"
},
{
"input": "5 2 12\n40 30 20 10\n",
"output": "100\n"
},
{
"input": "5 1 11\n2 7 1 8\n",
"output": "10\n"
},
{
"input": "9 3 14\n54640 754112 604290 105866 591907 801383 502975 379373\n",
"output": "2214425\n"
}
] |
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_e | å顿
æ¥æ¬åå³¶ã¯æ±è¥¿ã«çްé·ãåå³¶ã§ããïŒæ¥æ¬åå³¶ã¯ååæ¹åã®å¢çç·ã«ãã
N
åã®åºç»ã«åããããŠããïŒåºç»ã«ã¯è¥¿ããé ã«
1
ãã
N
ãŸã§ã®çªå·ãä»ããããŠããïŒçŸåšïŒåºç»
i
(
1 \leqq i \leqq N
) ã®æšé«ã¯
A_i \: \mathrm{m}
ã§ããïŒ
æ¥æ¬åå³¶ã§ã¯ãã³ãã³åµãèµ·ããŠããïŒåµãèµ·ãããšæ³¢ã«ããæµžé£ã§ååºç»ã®æšé«ã以äžã®ããã«æžå°ããïŒ
匷ã
x
ã®
西颚ã®
åµã§ã¯ïŒè¥¿ããæ°ããŠ
x
å以å
ã®åºç»ã®ãã¡ïŒããããã西ã«èªèº«ããæšé«ã®é«ãåºç»ãååšããªãããããªãã¹ãŠã®åºç»ã®æšé«ã
1 \: \mathrm{m}
æžå°ããïŒããªãã¡ïŒåµã®åã®åºç»
i
ã®æšé«ã
a_i
ã§è¡šããšïŒ
i \leqq x
ãã€ïŒ
1 \leqq k \lt i
ãšãªããã¹ãŠã®
k
ã«å¯ŸããŠ
a_k \leqq a_i
ãšãªãå Žåã«åºç»
i
ã®æšé«ã¯
1 \: \mathrm{m}
æžãïŒãã以å€ã®å Žåã«ã¯å€ãããªãïŒ
匷ã
x
ã®
æ±é¢šã®
åµã§ã¯ïŒæ±ããæ°ããŠ
x
å以å
ã®åºç»ã®ãã¡ïŒãããããæ±ã«èªèº«ããæšé«ã®é«ãåºç»ãååšããªãããããªãã¹ãŠã®åºç»ã®æšé«ã
1 \: \mathrm{m}
æžå°ããïŒããªãã¡ïŒåµã®åã®åºç»
i
ã®æšé«ã
a_i
ã§è¡šããšïŒ
i \geqq N - x + 1
ãã€ïŒ
i \lt k \leqq N
ãšãªããã¹ãŠã®
k
ã«å¯ŸããŠ
a_k \leqq a_i
ãšãªãå Žåã«åºç»
i
ã®æšé«ã¯
1 \: \mathrm{m}
æžãïŒãã以å€ã®å Žåã«ã¯å€ãããªãïŒ
ããªãã¯ïŒä»åŸ
Q
æ¥éã®åºæ¥äºãã·ãã¥ã¬ãŒã·ã§ã³ããªããã°ãªããªãïŒ
j
æ¥ç® (
1 \leqq j \leqq Q
) ã«ã¯æ¬¡ã®ãããªåºæ¥äºãèµ·ããïŒ
T_j = 1
ã®ãšãïŒåŒ·ã
X_j
ã®è¥¿é¢šã®åµãèµ·ããïŒ
T_j = 2
ã®ãšãïŒåŒ·ã
X_j
ã®æ±é¢šã®åµãèµ·ããïŒ
T_j = 3
ã®ãšãïŒãã®æç¹ã§ã®åºç»
X_j
ã®æšé«ãå ±åããïŒ
ãªãïŒå¶çŽããïŒã©ã®åºç»ã®æšé«ãè² ã«ãªããªãããšãä¿èšŒãããïŒ
çŸåšã®ååºç»ã®æšé«ããã³ä»åŸ
Q
æ¥éã®åºæ¥äºãäžããããã®ã§ïŒ
T_j = 3
ã§ããæ¥ã«å¯ŸããŠïŒæå®ãããåºç»ã®æšé«ãæ±ããããã°ã©ã ãäœæããïŒ | [
{
"input": "5 7\n7 7 7 7 7\n1 3\n1 1\n3 1\n2 1\n2 5\n3 2\n3 4\n",
"output": "5\n6\n6\n"
},
{
"input": "5 7\n10 13 14 7 12\n1 5\n2 5\n3 3\n3 4\n2 5\n3 1\n3 2\n",
"output": "12\n7\n9\n11\n"
},
{
"input": "5 6\n8 6 7 8 9\n1 1\n3 1\n3 5\n1 3\n3 2\n3 3\n",
"output": "7\n9\n6\n6\n"
},
{
"input": "5 6\n6 8 6 9 7\n2 1\n2 4\n3 5\n1 5\n3 4\n3 3\n",
"output": "5\n7\n6\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_a | Problem Statement
Print all non-negative integers less than or equal to
N
in descending order. | [
{
"input": "3\n",
"output": "3\n2\n1\n0\n"
},
{
"input": "22\n",
"output": "22\n21\n20\n19\n18\n17\n16\n15\n14\n13\n12\n11\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n0\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_b | Problem Statement
You are given a string
S
consisting of uppercase English letters and digits. Determine whether
S
satisfies the following condition.
S
is a concatenation of the following characters and string in the order listed.
An uppercase English letter
A string of length
6
that is a decimal representation of an integer between
100000
and
999999
, inclusive
An uppercase English letter | [
{
"input": "Q142857Z\n",
"output": "Yes\n"
},
{
"input": "AB912278C\n",
"output": "No\n"
},
{
"input": "X900000\n",
"output": "No\n"
},
{
"input": "K012345K\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_c | Problem Statement
We have a playlist with
N
songs numbered
1, \dots, N
.
Song
i
lasts
A_i
seconds.
When the playlist is played, song
1
, song
2
,
\ldots
, and song
N
play in this order. When song
N
ends, the playlist repeats itself, starting from song
1
again. While a song is playing, the next song does not play; when a song ends, the next song starts immediately.
At exactly
T
seconds after the playlist starts playing, which song is playing? Also, how many seconds have passed since the start of that song?
There is no input where the playlist changes songs at exactly
T
seconds after it starts playing. | [
{
"input": "3 600\n180 240 120\n",
"output": "1 60\n"
},
{
"input": "3 281\n94 94 94\n",
"output": "3 93\n"
},
{
"input": "10 5678912340\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "6 678912340\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_d | Problem Statement
You are given a sequence of non-negative integers
A=(a_1,a_2,\ldots,a_N)
.
Let
S
be the set of non-negative integers that can be the sum of
K
terms in
A
(with distinct indices).
Find the greatest multiple of
D
in
S
. If there is no multiple of
D
in
S
, print
-1
instead. | [
{
"input": "4 2 2\n1 2 3 4\n",
"output": "6\n"
},
{
"input": "3 1 2\n1 3 5\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_e | Problem Statement
You are given an integer sequence
A = (A_1, \dots, A_N)
of length
N
, and integers
M
and
K
.
For each
i = 1, \dots, N - M + 1
, solve the following independent problem.
Find the sum of the first
K
values in the sorted list of the
M
integers
A_i, A_{i + 1}, \dots, A_{i + M - 1}
in ascending order. | [
{
"input": "6 4 3\n3 1 4 1 5 9\n",
"output": "5 6 10\n"
},
{
"input": "10 6 3\n12 2 17 11 19 8 4 3 6 20\n",
"output": "21 14 15 13 13\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_f | Problem Statement
You are given a sequence of non-negative integers
A=(a_1,\ldots,a_N)
.
Let us perform the following operation on
A
just once.
Choose a non-negative integer
x
. Then, for every
i=1, \ldots, N
, replace the value of
a_i
with the bitwise XOR of
a_i
and
x
.
Let
M
be the maximum value in
A
after the operation. Find the minimum possible value of
M
.
What is bitwise XOR?
The bitwise XOR of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows.
When
A \oplus B
is written in binary, the
k
-th lowest bit (
k \geq 0
) is
1
if exactly one of the
k
-th lowest bits of
A
and
B
is
1
, and
0
otherwise.
For instance,
3 \oplus 5 = 6
(in binary:
011 \oplus 101 = 110
). | [
{
"input": "3\n12 18 11\n",
"output": "16\n"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\n",
"output": "0\n"
},
{
"input": "5\n324097321 555675086 304655177 991244276 9980291\n",
"output": "805306368\n"
}
] |
https://atcoder.jp/contests/abc281/tasks/abc281_g | Problem Statement
You are given positive integers
N
and
M
.
Find the number, modulo
M
, of simple connected undirected graphs with
N
vertices numbered
1, \dots, N
that satisfy the following condition.
For every
u = 2, \dots, N-1
, the shortest distance from vertex
1
to vertex
u
is strictly smaller than the shortest distance from vertex
1
to vertex
N
.
Here, the shortest distance from vertex
u
to vertex
v
is the minimum number of edges in a simple path connecting vertices
u
and
v
.
Two graphs are considered different if and only if there are two vertices
u
and
v
that are connected by an edge in exactly one of those graphs. | [
{
"input": "4 1000000000\n",
"output": "8\n"
},
{
"input": "3 100000000\n",
"output": "1\n"
},
{
"input": "500 987654321\n",
"output": "610860515\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.