url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/past202203-open/tasks/past202203_o | Problem Statement
You are given
M
pairs
(A_i,B_i)
of distinct integers between
1
and
N
(inclusive).
Determine whether there is a permutation
P=(P_1, P_2,\ldots , P_N)
of the integers
1
to
N
such that
P_{A_i}+P_{B_i}
is a multiple of
3
for all
1\leq i\leq M
. | [
{
"input": "5 2\n1 2\n2 3\n",
"output": "Yes\n"
},
{
"input": "3 2\n1 2\n2 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_a | Problem Statement
You are given a string
S
of length
N
consisting of
A
,
B
,
C
.
You can do the following two kinds of operations on
S
any number of times in any order.
Choose
A
in
S
, delete it, and insert
BB
at that position.
Choose two adjacent characters that are
BB
in
S
, delete them, and insert
A
at that position.
Find the lexicographically smallest possible string that
S
can become after your operations.
What is the lexicographical order?
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings
S
and
T
.
Below, let
S_i
denote the
i
-th character of
S
. Also, if
S
is lexicographically smaller than
T
, we will denote that fact as
S \lt T
; if
S
is lexicographically larger than
T
, we will denote that fact as
S \gt T
.
Let
L
be the smaller of the lengths of
S
and
T
. For each
i=1,2,\dots,L
, we check whether
S_i
and
T_i
are the same.
If there is an
i
such that
S_i \neq T_i
, let
j
be the smallest such
i
. Then, we compare
S_j
and
T_j
. If
S_j
comes earlier than
T_j
in alphabetical order, we determine that
S \lt T
and quit; if
S_j
comes later than
T_j
, we determine that
S \gt T
and quit.
If there is no
i
such that
S_i \neq T_i
, we compare the lengths of
S
and
T
. If
S
is shorter than
T
, we determine that
S \lt T
and quit; if
S
is longer than
T
, we determine that
S \gt T
and quit. | [
{
"input": "4\nCBAA\n",
"output": "CAAB\n"
},
{
"input": "1\nA\n",
"output": "A\n"
},
{
"input": "6\nBBBCBB\n",
"output": "ABCA\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_b | Problem Statement
You are given integer sequences of length
N
each:
A=(A_1,A_2,\cdots,A_N)
and
B=(B_1,B_2,\cdots,B_N)
.
You can repeat the following operation any number of times.
Choose an integer
i
(
1 \leq i \leq N-2
) and let
x,y,z
be the current values of
A_i,A_{i+1},A_{i+2}
, respectively.
Then, replace the values of
A_i,A_{i+1},A_{i+2}
with
z,x,y
, respectively.
Determine whether it is possible to make
A
equal
B
. | [
{
"input": "4\n3 1 4 5\n4 1 5 3\n",
"output": "Yes\n"
},
{
"input": "3\n1 2 2\n2 1 2\n",
"output": "Yes\n"
},
{
"input": "3\n1 2 3\n2 3 4\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_c | Problem Statement
We have an integer sequence of length
N
:
x=(x_0,x_1,\cdots,x_{N-1})
(note that its index is
0
-based).
Initially, all elements of
x
are
0
.
You can repeat the following operation any number of times.
Choose integers
i,k
(
0 \leq i \leq N-1
,
1 \leq k \leq N
).
Then, for every
j
such that
i \leq j \leq i+k-1
, increase the value of
x_{j\bmod N}
by
1
.
You are given an integer sequence of length
N
:
A=(A_0,A_1,\cdots,A_{N-1})
.
Find the minimum number of operations needed to make
x
equal
A
. | [
{
"input": "4\n1 2 1 2\n",
"output": "2\n"
},
{
"input": "5\n3 1 4 1 5\n",
"output": "7\n"
},
{
"input": "1\n1000000000\n",
"output": "1000000000\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_d | Problem Statement
You are given an integer sequence of length
N
:
A=(A_1,A_2,\cdots,A_N)
.
Find the number of pairs of integers
(i,j)
(
1 \leq i < j \leq N
) such that calculation of
A_i+A_j
by column addition does not involve carrying. | [
{
"input": "4\n4 8 12 90\n",
"output": "3\n"
},
{
"input": "20\n313923 246114 271842 371982 284858 10674 532090 593483 185123 364245 665161 241644 604914 645577 410849 387586 732231 952593 249651 36908\n",
"output": "6\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_e | Problem Statement
We have a directed graph
G
with
N
vertices numbered
1
to
N
.
Between two vertices
i,j
(
1 \leq i,j \leq N
,
i \neq j
), there is an edge
i \to j
if and only if both of the following conditions are satisfied.
i<j
\mathrm{gcd}(i,j)>1
Additionally, each vertex has an associated value: the value of Vertex
i
is
A_i
.
Consider choosing a set
s
of vertices so that the following condition is satisfied.
For every pair
(x,y)
(
x<y
) of different vertices in
s
,
y
is unreachable from
x
in
G
.
Find the maximum possible total value of vertices in
s
. | [
{
"input": "6\n1 1 1 1 1 1\n",
"output": "4\n"
},
{
"input": "6\n1 2 1 3 1 6\n",
"output": "8\n"
},
{
"input": "20\n40 39 31 54 27 31 80 3 62 66 15 72 21 38 74 49 15 24 44 3\n",
"output": "343\n"
}
] |
https://atcoder.jp/contests/arc136/tasks/arc136_f | Problem Statement
We have a checkerboard with
H
rows and
W
columns, where each square has a
0
or
1
written on it.
The current state of checkerboard is represented by
H
strings
S_1,S_2,\cdots,S_H
: the
j
-th character of
S_i
represents the digit in the square at the
i
-th row from the top and
j
-th column from the left.
Snuke will repeat the following operation.
Choose one square uniformly at random.
Then, flip the value written in that square. (In other words, change
0
to
1
and vice versa.)
By the way, he loves an integer sequence
A=(A_1,A_2,\cdots,A_H)
, so he will terminate the process at the moment when the following condition is satisfied.
For every
i
(
1 \leq i \leq H
), the
i
-th row from the top contains exactly
A_i
1
s.
Particularly, he may do zero operations.
Find the expected value of the number of operations Snuke does, modulo
998244353
.
Definition of the expected value modulo
998244353
It can be proved that the sought expected value is always a rational number. Additionally, under the Constraints of this problem, when that value is represented as an irreducible fraction
\frac{P}{Q}
, it can also be proved that
Q \not \equiv 0 \pmod{998244353}
. Thus, there uniquely exists an integer
R
such that
R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353
. Find this
R
. | [
{
"input": "1 2\n01\n0\n",
"output": "3\n"
},
{
"input": "3 3\n000\n100\n110\n0 1 2\n",
"output": "0\n"
},
{
"input": "2 2\n00\n01\n1 0\n",
"output": "332748127\n"
},
{
"input": "5 4\n1101\n0000\n0010\n0100\n1111\n1 3 3 2 1\n",
"output": "647836743\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_a | Problem Statement
There is a device with a screen that shows a single-digit number, and a button.
When the screen is showing a number
k
, pressing the button once changes the number on the screen to
a_k
.
The device currently shows
0
. After pressing the button
3
times, what will be shown on the screen? | [
{
"input": "9 0 1 2 3 4 5 6 7 8\n",
"output": "7\n"
},
{
"input": "4 8 8 8 0 8 8 8 8 8\n",
"output": "4\n"
},
{
"input": "0 0 0 0 0 0 0 0 0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_b | Problem Statement
There is pasta consisting of
N
noodles at Takahashi's home. The length of the
i
-th noodle is
A_i
.
Takahashi has a meal plan for the next
M
days.
On the
i
-th day, he is going to choose a pasta noodle of length exactly
B_i
and eat it.
If no such noodle is available on any day, his plan fails.
Additionally, he cannot eat the same noodle on multiple days.
Can Takahashi accomplish his meal plan? | [
{
"input": "3 2\n1 1 3\n3 1\n",
"output": "Yes\n"
},
{
"input": "1 1\n1000000000\n1\n",
"output": "No\n"
},
{
"input": "5 2\n1 2 3 4 5\n5 5\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_c | Problem Statement
There is a grid with
N
horizontal rows and
N
vertical columns, where each square is painted white or black.
The state of the grid is represented by
N
strings,
S_i
.
If the
j
-th character of
S_i
is
#
, the square at the
i
-th row from the top and the
j
-th column from the left is painted black.
If the character is
.
, then the square is painted white.
Takahashi can choose at most two of these squares that are painted white, and paint them black.
Determine if it is possible to make the grid contain
6
or more consecutive squares painted black aligned either vertically, horizontally, or diagonally.
Here, the grid is said to be containing
6
or more consecutive squares painted black aligned diagonally if the grid with
N
rows and
N
columns completely contains a subgrid with
6
rows and
6
columns such that all the squares on at least one of its diagonals are painted black. | [
{
"input": "8\n........\n........\n.#.##.#.\n........\n........\n........\n........\n........\n",
"output": "Yes\n"
},
{
"input": "6\n######\n######\n######\n######\n######\n######\n",
"output": "Yes\n"
},
{
"input": "10\n..........\n#..##.....\n..........\n..........\n....#.....\n....#.....\n.#...#..#.\n..........\n..........\n..........\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_d | Problem Statement
We have an empty sequence
A
.
Given
Q
queries, process them in order.
Each query is of one of the following three types.
1 x
: Insert
x
to
A
.
2 x k
: Among the elements of
A
that are less than or equal to
x
, print the
k
-th largest value. (
k
is no more than
\bf{5}
)
If there are less than
k
elements of
A
that are less than or equal to
x
, then print
-1
.
3 x k
: Among the elements of
A
that are greater than or equal to
x
, print the
k
-th smallest value. (
k
is no more than
\bf{5}
)
If there are less than
k
elements of
A
that are greater than or equal to
x
, then print
-1
. | [
{
"input": "11\n1 20\n1 10\n1 30\n1 20\n3 15 1\n3 15 2\n3 15 3\n3 15 4\n2 100 5\n1 1\n2 100 5\n",
"output": "20\n20\n30\n-1\n-1\n1\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_e | Problem Statement
You are given a sequence
A=(A_0,A_1,\ldots,A_{N-1})
of length
N
.
There is an initially empty dish. Takahashi is going to repeat the following operation
K
times.
Let
X
be the number of candies on the dish. He puts
A_{(X\bmod N)}
more candies on the dish.
Here,
X\bmod N
denotes the remainder when
X
is divided by
N
.
Find how many candies are on the dish after the
K
operations. | [
{
"input": "5 3\n2 1 6 3 1\n",
"output": "11\n"
},
{
"input": "10 1000000000000\n260522 914575 436426 979445 648772 690081 933447 190629 703497 47202\n",
"output": "826617499998784056\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_f | Problem Statement
There is a skating rink represented by a grid with
H
horizontal rows and
W
vertical columns. Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
The skating rink has
N
obstacles. The
i
-th obstacle is placed at
(X_i,Y_i)
.
In a single move, Takahashi chooses one of the four directions, up, down, left, or right, and keeps moving until he hits an obstacle.
When he hits an obstacle, he stops at the square right before the obstacle.
Since the skating rink is surrounded by cliffs, it is prohibited to start a move in which he will never hit an obstacle.
Takahashi is initially at
(s_x,s_y)
. He wants to make some number of moves to stop at
(g_x,g_y)
.
Find the minimum number of moves required to end up at
(g_x, g_y)
. If it is not possible, report the fact. | [
{
"input": "7 8 7\n3 4\n5 6\n1 4\n2 1\n2 8\n4 5\n5 7\n6 2\n6 6\n",
"output": "4\n"
},
{
"input": "4 6 2\n3 2\n3 5\n4 5\n2 5\n",
"output": "-1\n"
},
{
"input": "1 10 1\n1 5\n1 1\n1 7\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_g | Problem Statement
N
players numbered
1
through
N
will participate in a round-robin tournament.
Specifically, for every pair
(i,j) (1\leq i \lt j \leq N)
, Player
i
and Player
j
play a match against each other once, for a total of
\frac{N(N-1)}{2}
matches.
In every match, one of the players will be a winner and the other will be a loser; there is no draw.
M
matches have already ended. In the
i
-th match, Player
W_i
won Player
L_i
.
List all the players who may become the unique winner after the round-robin tournament is completed.
A player is said to be the unique winner if the number of the player's wins is strictly greater than that of any other player. | [
{
"input": "4 2\n2 1\n2 3\n",
"output": "2 4\n"
},
{
"input": "3 3\n1 2\n2 3\n3 1\n",
"output": "\n"
},
{
"input": "7 9\n6 5\n1 2\n3 4\n5 3\n6 2\n1 5\n3 2\n6 4\n1 4\n",
"output": "1 3 6 7\n"
}
] |
https://atcoder.jp/contests/abc241/tasks/abc241_h | Problem Statement
There are some cards. Each card has one of
N
integers written on it.
Specifically, there are
B_i
cards with
A_i
written on them.
Next, for a combination of
M
cards chosen out of these
(B_1+B_2\cdots +B_N)
cards,
we define the score of the combination by the product of the integers written on the
M
cards.
Supposed that cards with the same integer written on them are indistinguishable,
find the sum, modulo
998244353
, of the scores over all possible combinations of
M
cards. | [
{
"input": "3 3\n3 1\n5 2\n6 3\n",
"output": "819\n"
},
{
"input": "3 2\n1 1\n5 2\n25 1\n",
"output": "180\n"
},
{
"input": "10 232657150901347497\n139547946 28316250877914575\n682142538 78223540024979445\n110643588 74859962623690081\n173455495 60713016476190629\n271056265 85335723211047202\n801329567 48049062628894325\n864844366 54979173822804784\n338794337 69587449430302156\n737638908 15812229161735902\n462149872 49993004923078537\n",
"output": "39761306\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_a | Problem Statement
In the figure shown in the image below, are the points numbered
a
and
b
directly connected by a line segment? | [
{
"input": "4 5\n",
"output": "Yes\n"
},
{
"input": "3 5\n",
"output": "No\n"
},
{
"input": "1 10\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_b | Problem Statement
In a sequence of
N
positive integers
a = (a_1, a_2, \dots, a_N)
, how many different integers are there? | [
{
"input": "6\n1 4 1 2 2 1\n",
"output": "3\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "11\n3 1 4 1 5 9 2 6 5 3 5\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_c | Problem Statement
Takahashi is standing at the coordinate
0
on a number line.
He will now perform
N
jumps. In the
i
-th jump
(1 \leq i \leq N)
, he moves
a_i
or
b_i
in the positive direction.
Is it possible for him to be at the coordinate
X
after
N
jumps? | [
{
"input": "2 10\n3 6\n4 5\n",
"output": "Yes\n"
},
{
"input": "2 10\n10 100\n10 100\n",
"output": "No\n"
},
{
"input": "4 12\n1 8\n5 7\n3 4\n2 6\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_d | Problem Statement
Takahashi has
N
balls. Each ball has an integer not less than
2
written on it. He will insert them in a cylinder one by one. The integer written on the
i
-th ball is
a_i
.
The balls are made of special material. When
k
balls with
k
(k \geq 2)
written on them line up in a row, all these
k
balls will disappear.
For each
i
(1 \leq i \leq N)
, find the number of balls after inserting the
i
-th ball. | [
{
"input": "5\n3 2 3 2 2\n",
"output": "1\n2\n3\n4\n3\n"
},
{
"input": "10\n2 3 2 3 3 3 2 3 3 2\n",
"output": "1\n2\n3\n4\n5\n3\n2\n3\n1\n0\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_e | Problem Statement
You are given a rooted tree with
N
vertices. The root is Vertex
1
.
For each
i = 1, 2, \ldots, N-1
, the
i
-th edge connects Vertex
u_i
and Vertex
v_i
.
For each
i = 1, 2, \ldots, N
, let
S_i
denote the set of all vertices in the subtree rooted at Vertex
i
. (Each vertex is in the subtree rooted at itself, that is,
i \in S_i
.)
Additionally, for integers
l
and
r
, let
[l, r]
denote the set of all integers between
l
and
r
, that is,
[l, r] = \lbrace l, l+1, l+2, \ldots, r \rbrace
.
Consider a sequence of
N
pairs of integers
\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)
that satisfies the conditions below.
1 \leq L_i \leq R_i
for every integer
i
such that
1 \leq i \leq N
.
The following holds for every pair of integers
(i, j)
such that
1 \leq i, j \leq N
.
[L_i, R_i] \subseteq [L_j, R_j]
if
S_i \subseteq S_j
[L_i, R_i] \cap [L_j, R_j] = \emptyset
if
S_i \cap S_j = \emptyset
It can be shown that there is at least one sequence
\big((L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N)\big)
.
Among those sequences, print one that minimizes
\max \lbrace L_1, L_2, \ldots, L_N, R_1, R_2, \ldots, R_N \rbrace
, the maximum integer used. (If there are multiple such sequences, you may print any of them.) | [
{
"input": "3\n2 1\n3 1\n",
"output": "1 2\n2 2\n1 1\n"
},
{
"input": "5\n3 4\n5 4\n1 2\n1 4\n",
"output": "1 3\n3 3\n2 2\n1 2\n1 1\n"
},
{
"input": "5\n4 5\n3 2\n5 2\n3 1\n",
"output": "1 1\n1 1\n1 1\n1 1\n1 1\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_f | Problem Statement
There are integer sequences
A, B, C
of length
M
each.
C
is represented by integers
x_1, \dots, x_N, y_1, \dots, y_N
. The first
y_1
terms of
C
are
x_1
, the subsequent
y_2
terms are
x_2
,
\ldots
, the last
y_N
terms are
x_N
.
B
is defined by
B_i = \sum_{k = 1}^i C_k \, (1 \leq i \leq M)
.
A
is defined by
A_i = \sum_{k = 1}^i B_k \, (1 \leq i \leq M)
.
Find the maximum value among
A_1, \dots, A_M
.
You will be given
T
test cases to solve. | [
{
"input": "3\n3 7\n-1 2\n2 3\n-3 2\n10 472\n-4 12\n1 29\n2 77\n-1 86\n0 51\n3 81\n3 17\n-2 31\n-4 65\n4 23\n1 1000000000\n4 1000000000\n",
"output": "4\n53910\n2000000002000000000\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_g | Problem Statement
Takahashi is in the square
(0, 0, 0)
in an infinite three-dimensional grid.
He can teleport between squares.
From the square
(x, y, z)
, he can move to
(x+1, y, z)
,
(x-1, y, z)
,
(x, y+1, z)
,
(x, y-1, z)
,
(x, y, z+1)
, or
(x, y, z-1)
in one teleport. (Note that he cannot stay in the square
(x, y, z)
.)
Find the number of routes ending in the square
(X, Y, Z)
after exactly
N
teleports.
In other words, find the number of sequences of
N+1
triples of integers
\big( (x_0, y_0, z_0), (x_1, y_1, z_1), (x_2, y_2, z_2), \ldots, (x_N, y_N, z_N)\big)
that satisfy all three conditions below.
(x_0, y_0, z_0) = (0, 0, 0)
.
(x_N, y_N, z_N) = (X, Y, Z)
.
|x_i-x_{i-1}| + |y_i-y_{i-1}| + |z_i-z_{i-1}| = 1
for each
i = 1, 2, \ldots, N
.
Since the number can be enormous, print it modulo
998244353
. | [
{
"input": "3 2 0 -1\n",
"output": "3\n"
},
{
"input": "1 0 0 0\n",
"output": "0\n"
},
{
"input": "314 15 92 65\n",
"output": "106580952\n"
}
] |
https://atcoder.jp/contests/abc240/tasks/abc240_h | Problem Statement
You are given a string
S = s_1 s_2 \ldots s_N
of length
N
consisting of
0
's and
1
's.
Find the maximum integer
K
such that there is a sequence of
K
pairs of integers
\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)
that satisfy all three conditions below.
1 \leq L_i \leq R_i \leq N
for each
i = 1, 2, \ldots, K
.
R_i \lt L_{i+1}
for
i = 1, 2, \ldots, K-1
.
The string
s_{L_i}s_{L_i+1} \ldots s_{R_i}
is
strictly lexicographically smaller
than the string
s_{L_{i+1}}s_{L_{i+1}+1}\ldots s_{R_{i+1}}
. | [
{
"input": "7\n0101010\n",
"output": "3\n"
},
{
"input": "30\n000011001110101001011110001001\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_a | Problem Statement
Assuming that the horizon seen from a place
x
meters above the ground is
\sqrt{x(12800000+x)}
meters away,
find how many meters away the horizon seen from a place
H
meters above the ground is. | [
{
"input": "333\n",
"output": "65287.907678222\n"
},
{
"input": "634\n",
"output": "90086.635834623\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_b | Problem Statement
Given an integer
X
between
-10^{18}
and
10^{18}
(inclusive), print
\left\lfloor \dfrac{X}{10} \right\rfloor
. | [
{
"input": "47\n",
"output": "4\n"
},
{
"input": "-24\n",
"output": "-3\n"
},
{
"input": "50\n",
"output": "5\n"
},
{
"input": "-30\n",
"output": "-3\n"
},
{
"input": "987654321987654321\n",
"output": "98765432198765432\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_c | Problem Statement
On an
xy
-coordinate plane, is there a lattice point whose distances from two lattice points
(x_1, y_1)
and
(x_2, y_2)
are both
\sqrt{5}
? | [
{
"input": "0 0 3 3\n",
"output": "Yes\n"
},
{
"input": "0 1 2 3\n",
"output": "No\n"
},
{
"input": "1000000000 1000000000 999999999 999999999\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_d | Problem Statement
Takahashi and Aoki are playing a game.
First, Takahashi chooses an integer between
A
and
B
(inclusive) and tells it to Aoki.
Next, Aoki chooses an integer between
C
and
D
(inclusive).
If the sum of these two integers is a prime, then Aoki wins; otherwise, Takahashi wins.
When the two players play optimally, which player will win? | [
{
"input": "2 3 3 4\n",
"output": "Aoki\n"
},
{
"input": "1 100 50 60\n",
"output": "Takahashi\n"
},
{
"input": "3 14 1 5\n",
"output": "Aoki\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_e | Problem Statement
We have a rooted tree with
N
vertices. The vertices are numbered
1
through
N
, and the root is Vertex
1
.
The
i
-th edge connects Vertices
A_i
and
B_i
.
Vertex
i
has an integer
X_i
written on it.
You are given
Q
queries. For the
i
-th query, given a pair of integers
(V_i,K_i)
, answer the following question.
Question: among the integers written on the vertices in the subtree rooted at Vertex
V_i
, find the
K_i
-th largest value. | [
{
"input": "5 2\n1 2 3 4 5\n1 4\n2 1\n2 5\n3 2\n1 2\n2 1\n",
"output": "4\n5\n"
},
{
"input": "6 2\n10 10 10 9 8 8\n1 4\n2 1\n2 5\n3 2\n6 4\n1 4\n2 2\n",
"output": "9\n10\n"
},
{
"input": "4 4\n1 10 100 1000\n1 2\n2 3\n3 4\n1 4\n2 3\n3 2\n4 1\n",
"output": "1\n10\n100\n1000\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_f | Problem Statement
The Republic of Atcoder has
N
towns numbered
1
through
N
, and
M
highways numbered
1
through
M
.
Highway
i
connects Town
A_i
and Town
B_i
bidirectionally.
King Takahashi is going to construct
(N-M-1)
new highways so that the following two conditions are satisfied:
One can travel between every pair of towns using some number of highways
For each
i=1,\ldots,N
, exactly
D_i
highways are directly connected to Town
i
Determine if there is such a way of construction. If it exists, print one. | [
{
"input": "6 2\n1 2 1 2 2 2\n2 3\n1 4\n",
"output": "6 2\n5 6\n4 5\n"
},
{
"input": "5 1\n1 1 1 1 4\n2 3\n",
"output": "-1\n"
},
{
"input": "4 0\n3 3 3 3\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_g | Problem Statement
We have a simple connected undirected graph with
N
vertices and
M
edges.
The vertices are numbered as Vertex
1
, Vertex
2
,
\dots
, Vertex
N
.
The edges are numbered as Edge
1
, Edge
2
,
\dots
, Edge
M
. Edge
i
connects Vertex
a_i
and Vertex
b_i
bidirectionally. There is no edge that directly connects Vertex
1
and Vertex
N
.
Each vertex is either empty or occupied by a wall. Initially, every vertex is empty.
Aoki is going to travel from Vertex
1
to Vertex
N
along the edges on the graph. However, Aoki is not allowed to move to a vertex occupied by a wall.
Takahashi has decided to choose some of the vertices to build walls on, so that Aoki cannot travel to Vertex
N
no matter which route he takes.
Building a wall on Vertex
i
costs Takahashi
c_i
yen (the currency of Japan).
He cannot build a wall on Vertex
1
and Vertex
N
.
How many yens is required for Takahashi to build walls so that the conditions is satisfied? Also, print the way of building walls to achieve the minimum cost. | [
{
"input": "5 5\n1 2\n2 3\n3 5\n2 4\n4 5\n0 8 3 4 0\n",
"output": "7\n2\n3 4\n"
},
{
"input": "3 2\n1 2\n2 3\n0 1 0\n",
"output": "1\n1\n2\n"
},
{
"input": "5 9\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n0 1000000000 1000000000 1000000000 0\n",
"output": "3000000000\n3\n2 3 4\n"
}
] |
https://atcoder.jp/contests/abc239/tasks/abc239_h | Problem Statement
Snuke has a die (singular of dice) that shows integers from
1
through
N
with equal probability, and an integer
1
.
He repeats the following operation while his integer is less than or equal to
M
.
He rolls the die. If the die shows an integer
x
, he multiplies his integer by
x
.
Find the expected value of the number of times he rolls the die until he stops, modulo
10^9+7
.
Definition of the expected value modulo
10^9+7
We can prove that the desired expected value is always a rational number. Moreover, under the constraints of the problem, when the value is represented as an irreducible fraction
\frac{P}{Q}
, we can also prove that
Q \not\equiv 0 \pmod{10^9+7}
. Thus, an integer
R
such that
R \times Q \equiv P \pmod{10^9+7}
and
0 \leq R \lt 10^9+7
is uniquely determined. Answer such
R
. | [
{
"input": "2 1\n",
"output": "2\n"
},
{
"input": "2 39\n",
"output": "12\n"
},
{
"input": "3 2\n",
"output": "250000004\n"
},
{
"input": "2392 39239\n",
"output": "984914531\n"
},
{
"input": "1000000000 1000000000\n",
"output": "776759630\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_a | Problem Statement
There is an integer
X
written on a blackboard. You can do the operation below any number of times (possibly zero).
Choose an integer
x
written on the blackboard.
Erase one
x
from the blackboard and write two new integers
\lfloor \frac{x}{2}\rfloor
and
\lceil \frac{x}{2}\rceil
.
Find the maximum possible product of the integers on the blackboard after your operations, modulo
998244353
.
What are
\lfloor \frac{x}{2}\rfloor
and
\lceil \frac{x}{2}\rceil
?
For a real number
x
,
\lfloor x\rfloor
denotes the largest integer not greater than
x
, and
\lceil x\rceil
denotes the smallest integer not less than
x
. For example, the following holds.
For
x = 2
, we have
\lfloor \frac{x}{2}\rfloor = 1
and
\lceil \frac{x}{2}\rceil = 1
.
For
x = 3
, we have
\lfloor \frac{x}{2}\rfloor = 1
,
\lceil \frac{x}{2}\rceil = 2
. | [
{
"input": "15\n",
"output": "192\n"
},
{
"input": "3\n",
"output": "3\n"
},
{
"input": "100\n",
"output": "824552442\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_b | Problem Statement
You are given a sequence of
N
integers
S = (S_1, \ldots, S_N)
.
Determine whether there is a sequence of
N+2
integers
A = (A_1, \ldots, A_{N+2})
that satisfies the conditions below.
0\leq A_i
for every
i
(
1\leq i\leq N+2
).
S_i = A_{i} + A_{i+1} + A_{i+2}
for every
i
(
1\leq i\leq N
).
If it exists, print one such sequence. | [
{
"input": "5\n6 9 6 6 5\n",
"output": "Yes\n0 4 2 3 1 2 2\n"
},
{
"input": "5\n0 1 2 1 0\n",
"output": "No\n"
},
{
"input": "1\n10\n",
"output": "Yes\n0 0 10\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_c | Problem Statement
You are given a sequence of non-negative integers
A = (A_1, \ldots, A_N)
.
You can do the operation below any number of times (possibly zero).
Choose an integer
x\in \{A_1,\ldots,A_N\}
.
Replace
A_i
with
A_i\oplus x
for every
i
(
\oplus
denotes the bitwise
\mathrm{XOR}
operation).
Find the maximum possible value of
\sum_{i=1}^N A_i
after your operations.
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 base two, the digit in the
2^k
's place (
k \geq 0
) is
1
if exactly one of
A
and
B
is
1
, and
0
otherwise.
For example, we have
3 \oplus 5 = 6
(in base two:
011 \oplus 101 = 110
). | [
{
"input": "5\n1 2 3 4 5\n",
"output": "19\n"
},
{
"input": "5\n10 10 10 10 10\n",
"output": "50\n"
},
{
"input": "5\n3 1 4 1 5\n",
"output": "18\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_d | Problem Statement
We have an
H \times W
grid, where each square has one integer written on it.
For
1\leq i\leq H
and
1\leq j\leq W
, let
A_{i,j}
denote the integer written on the square at the
i
-th row and
j
-th column.
You can do the operation below any number of times (possibly zero).
Choose integers
i
and
j
such that
1\leq i\leq H - 1
and
1\leq j\leq W - 1
.
Choose another integer
x
.
Add
x
to each of
A_{i,j}
,
A_{i,j+1}
,
A_{i+1,j}
, and
A_{i+1,j+1}
.
Print the minimum possible value of
\sum_{i=1}^H \sum_{j=1}^W |A_{i,j}|
after your operations, and the integers on the grid when that value is achieved. | [
{
"input": "2 3\n1 2 3\n4 5 6\n",
"output": "9\n0 -3 -1\n3 0 2\n"
},
{
"input": "2 2\n1000000000 -1000000000\n-1000000000 1000000000\n",
"output": "4000000000\n2000000000 0\n0 2000000000\n"
},
{
"input": "3 4\n0 2 0 -2\n-3 -1 2 0\n-3 -3 2 2\n",
"output": "0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_e | Problem Statement
You are given integers
N
and
X
. Assume that an integer sequence
A = (A_1, \ldots, A_N)
satisfies all of the conditions below.
A_1 = X
.
For every
i
(
1\leq i\leq N
),
A_i
is a multiple of
i
.
A
is strictly increasing. In other words,
A_1 < \cdots < A_N
holds.
Find the minimum possible value of
\sum_{i=1}^N A_i
, modulo
998244353
.
There are
T
test cases, each of which should be solved. | [
{
"input": "5\n5 100\n1 10\n10 1\n1000000000000000000 1\n100 100\n",
"output": "525\n10\n55\n75433847\n61074\n"
}
] |
https://atcoder.jp/contests/arc135/tasks/arc135_f | Problem Statement
You are given an integer
N
. On an integer sequence
A = (1, 2, \ldots, N)
, let us do the operation below exactly
K
times.
Let
n
be the current number of terms in
A
. For all
i
such that
1\leq i \leq n
and
i\equiv 1\pmod{3}
, delete the
i
-th term of
A
, simultaneously.
Find the sum of the terms of
A
after
K
operations, modulo
998244353
. | [
{
"input": "10 2\n",
"output": "25\n"
},
{
"input": "10 10\n",
"output": "0\n"
},
{
"input": "10000 10\n",
"output": "862816\n"
}
] |
https://atcoder.jp/contests/loadchecking/tasks/loadchecking_a | 問題文
高橋君は、長さ
20
の順列
A
が好きです。ですが、高橋君の好きな順列は秘密です。
あなたが整数列
B
(順列である必要はない) を出力すると、高橋君はどれだけ近いかを点数で答えてくれます。数列
B
を出力してください。 | [
{
"input": "\n",
"output": "2\n2\n17\n14\n1\n10\n16\n9\n3\n4\n5\n13\n12\n7\n18\n15\n19\n20\n11\n8\n"
}
] |
https://atcoder.jp/contests/joi2022ho/tasks/joi2022ho_a | 問題文
時は
\mathrm{30XX}
年.科学者・技術者のたゆまぬ努力により,異星間の交流が盛んに行われるようになっていた.ビーバーのビ太郎は異星人に地球の食べ物を紹介するアンバサダーを務めており,今日の午後 1 時に JOI 星へ向けて出発する予定である.
今回 JOI 星人に紹介する食べ物のひとつとして,切り分けたカステラが用意されている.カステラは小麦粉に鶏卵・砂糖・水あめを加え,スポンジ状にふっくらと焼いた菓子である.
カステラは横長の直方体の形をしており,縦方向の切れ目に沿って
N
個のピースに分割されている.左から
i
番目 (
1 \leqq i \leqq N
) のピースの長さは整数
A_i
である.
つい先ほど,JOI 星人は偶数に嫌悪感を示すということが判明した.そこで対処として,長さが偶数のピースが無くなるまで以下の一連の操作を繰り返すことにした.
長さが偶数のピースのうち最も右にあるものを選ぶ.
選んだピースを縦方向に切って
2
等分する.すなわち,選んだピースの長さを
k
としたとき,そのピースを位置を変えずに長さ
\displaystyle\frac{k}{2}
のピース
2
つに分割する.
操作が正しく行われたかチェックするため,ビ太郎は
Q
個の質問を準備しておいた.
j
番目 (
1 \leqq j \leqq Q
) の質問は以下の通りである.
すべての操作が終了したとき,左から
X_j
番目にあるピースの長さは何であるか.
カステラと質問の情報が与えられたとき,各質問の答えを求めるプログラムを作成せよ. | [
{
"input": "4\n14\n9\n8\n12\n6\n2\n3\n5\n7\n11\n13\n",
"output": "7\n9\n1\n1\n1\n3\n"
},
{
"input": "13\n1\n4\n1\n4\n2\n1\n3\n5\n6\n2\n3\n7\n3\n8\n2\n10\n11\n13\n15\n17\n18\n20\n",
"output": "1\n1\n1\n1\n5\n3\n1\n3\n"
},
{
"input": "16\n536870912\n402653184\n536870912\n536870912\n134217728\n536870912\n671088640\n536870912\n536870912\n536870912\n939524096\n805306368\n536870912\n956301312\n536870912\n536870912\n5\n2500000000\n3355443201\n4294967296\n5111111111\n6190792704\n",
"output": "5\n1\n7\n57\n1\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.