url stringlengths 49 92 | description stringlengths 22 4.78k | cases listlengths 0 6 |
|---|---|---|
https://atcoder.jp/contests/arc158/tasks/arc158_a | Problem Statement
You are given integers
x_1
,
x_2
, and
x_3
. For these integers, you can perform the following operation any number of times, possibly zero.
Choose a permutation
(i,j,k)
of
(1,2,3)
, that is, a triple of integers
(i,j,k)
such that
1\leq i,j,k\leq 3
and
i\neq j, i\neq k, j\neq k
.
Then, simultaneously ... | [
{
"input": "4\n2 8 8\n1 1 1\n5 5 10\n10 100 1000\n",
"output": "2\n0\n-1\n315\n"
}
] |
https://atcoder.jp/contests/arc158/tasks/arc158_b | Problem Statement
You are given non-zero integers
x_1, \ldots, x_N
. Find the minimum and maximum values of
\dfrac{x_i+x_j+x_k}{x_ix_jx_k}
for integers
i
,
j
,
k
such that
1\leq i < j < k\leq N
. | [
{
"input": "4\n-2 -4 4 5\n",
"output": "-0.175000000000000\n-0.025000000000000\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "3.000000000000000\n3.000000000000000\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "0.200000000000000\n1.000000000000000\n"
}
] |
https://atcoder.jp/contests/arc158/tasks/arc158_c | Problem Statement
For a positive integer
x
, let
f(x)
denote the sum of its digits. For instance,
f(158) = 1 + 5 + 8 = 14
,
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
\sum_{i=1}^N\sum_{j=1}^N f(A_i + A_j)
. | [
{
"input": "2\n53 28\n",
"output": "36\n"
},
{
"input": "1\n999999999999999\n",
"output": "135\n"
},
{
"input": "5\n123 456 789 101 112\n",
"output": "321\n"
}
] |
https://atcoder.jp/contests/arc158/tasks/arc158_d | Problem Statement
You are given a positive integer
n
, and a prime number
p
at least
5
.
Find a triple of integers
(x,y,z)
that satisfies all of the following conditions.
1\leq x < y < z \leq p - 1
.
(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) \equiv x^{3n}+y^{3n}+z^{3n}\pmod{p}
.
It can be proved that such a triple
(x,... | [
{
"input": "3\n1 7\n2 7\n10 998244353\n",
"output": "1 4 6\n1 2 5\n20380119 21549656 279594297\n"
}
] |
https://atcoder.jp/contests/arc158/tasks/arc158_e | Problem Statement
We have a grid with
2
rows and
N
columns. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
(i,j)
has a postive integer
x_{i,j}
written on it.
Two squares are said to be
adjacent
when they share a side.
A
path
from square
X
to
Y
is a sequence
(P_1, \ldots, P_n)
... | [
{
"input": "1\n3\n5\n",
"output": "24\n"
},
{
"input": "2\n1 2\n3 4\n",
"output": "76\n"
},
{
"input": "5\n1 1000000000 1 1 1\n1 1 1 1000000000 1\n",
"output": "66714886\n"
}
] |
https://atcoder.jp/contests/arc158/tasks/arc158_f | Problem Statement
For non-negative integers
x
and
k
, the
k
-th lowest digit of
x
is the remainder when
\bigl\lfloor \frac{x}{10^k}\bigr\rfloor
is divided by
10
. For instance, the
0
-th,
1
-st,
2
-nd, and
3
-rd lowest digits of
123
are
3
,
2
,
1
, and
0
, respectively.
You are given positive integers
N
,
M
,
K
, and s... | [
{
"input": "3 2 3\n74 42 54\n42 54 74\n",
"output": "5\n"
},
{
"input": "2 1 1\n2 3\n3 2\n",
"output": "0\n"
},
{
"input": "5 100 4\n0 12 34 56 78\n0 12 34 56 78\n",
"output": "982924732\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_a | Problem Statement
You are given a string
S
of even length consisting of lowercase English letters. Let
|S|
be the length of
S
, and
S_i
be the
i
-th character of
S
.
Perform the following operation for each
i = 1, 2, \ldots, \frac{|S|}{2}
in this order, and print the final
S
.
Swap
S_{2i-1}
and
S_{2i}
. | [
{
"input": "abcdef\n",
"output": "badcfe\n"
},
{
"input": "aaaa\n",
"output": "aaaa\n"
},
{
"input": "atcoderbeginnercontest\n",
"output": "taocedbrgeniencrnoetts\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_b | Problem Statement
There are
N
people whose IDs are
1
,
2
,
\ldots
, and
N
.
Each of person
1
, person
2
,
\ldots
, and person
N
performs the following action once in this order:
If person
i
's ID has not been called out yet, call out person
A_i
's ID.
Enumerate the IDs of all the people whose IDs are never called out u... | [
{
"input": "5\n3 1 4 5 4\n",
"output": "2\n2 4\n"
},
{
"input": "20\n9 7 19 7 10 4 13 9 4 8 10 15 16 3 18 19 12 13 2 12\n",
"output": "10\n1 2 5 6 8 11 14 17 18 20\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_c | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns.
For two integers
i
and
j
such that
1 \leq i \leq H
and
1 \leq j \leq W
,
the square at the
i
-th row from the top and
j
-th column from the left (which we denote by
(i, j)
) has an integer
A_{i, j}
written on it.
Takahashi is currently a... | [
{
"input": "3 3\n3 2 2\n2 1 3\n1 5 4\n",
"output": "3\n"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10\n11 12 13 14 15 16 17 18 19 20\n21 22 23 24 25 26 27 28 29 30\n31 32 33 34 35 36 37 38 39 40\n41 42 43 44 45 46 47 48 49 50\n51 52 53 54 55 56 57 58 59 60\n61 62 63 64 65 66 67 68 69 70\n71 72 73 74 7... |
https://atcoder.jp/contests/abc293/tasks/abc293_d | Problem Statement
There are
N
ropes numbered
1
through
N
. One end of each rope is painted red, and the other is painted blue.
You are going to perform
M
operations of tying ropes. In the
i
-th operation, you tie the end of rope
A_i
painted
B_i
with the end of rope
C_i
painted
D_i
, where
R
means red and
B
means blue... | [
{
"input": "5 3\n3 R 5 B\n5 R 3 B\n4 R 2 B\n",
"output": "1 2\n"
},
{
"input": "7 0\n",
"output": "0 7\n"
},
{
"input": "7 6\n5 R 3 R\n7 R 4 R\n4 B 1 R\n2 R 3 B\n2 B 5 B\n1 B 7 B\n",
"output": "2 1\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_e | Problem Statement
Given integers
A
,
X
, and
M
, find
\displaystyle \sum_{i = 0}^{X-1} A^i
, modulo
M
. | [
{
"input": "3 4 7\n",
"output": "5\n"
},
{
"input": "8 10 9\n",
"output": "0\n"
},
{
"input": "1000000000 1000000000000 998244353\n",
"output": "919667211\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_f | Problem Statement
Given an integer
N
not less than
2
, find the number of integers
b
not less than
2
such that:
when
N
is written in base
b
, every digit is
0
or
1
.
Find the answer for
T
independent test cases.
It can be proved that there is a finite number of desired integers
b
not less than
2
under the constraints o... | [
{
"input": "3\n12\n2\n36\n",
"output": "4\n1\n5\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_g | Problem Statement
You are given a length-
N
sequence
(A_1, A_2, \ldots, A_N)
of positive integers, and
Q
queries about the sequence.
For each
q = 1, 2, \ldots, Q
, the
q
-th query gives you an integer pair
(l_q, r_q)
;
print the number of integer triplets
(i, j, k)
such that
l_q \leq i \lt j \lt k \leq r_q
, and
A_i = ... | [
{
"input": "10 4\n2 7 1 8 2 8 1 8 2 8\n1 10\n1 9\n2 10\n5 5\n",
"output": "5\n2\n4\n0\n"
},
{
"input": "20 10\n2 2 2 2 1 1 2 2 1 1 1 2 1 2 1 2 2 1 2 1\n12 16\n17 18\n12 18\n4 9\n13 13\n2 5\n6 13\n2 14\n7 14\n8 12\n",
"output": "1\n0\n5\n2\n0\n1\n11\n55\n8\n1\n"
}
] |
https://atcoder.jp/contests/abc293/tasks/abc293_h | Problem Statement
You are given a tree with
N
vertices numbered
1
through
N
. The
i
-th edge connects vertex
A_i
and vertex
B_i
.
Find the minimum integer
K
such that you can paint each vertex in a color so that the following two conditions are satisfied. You may use any number of colors.
For each color, the set of v... | [
{
"input": "7\n3 4\n1 5\n4 5\n1 2\n7 4\n1 6\n",
"output": "3\n"
},
{
"input": "6\n3 5\n6 4\n6 3\n4 2\n1 5\n",
"output": "1\n"
},
{
"input": "9\n1 3\n9 5\n8 7\n2 1\n5 2\n5 8\n4 8\n6 1\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/toyota-hc-2023spring/tasks/toyota_hc_2023spring_a | 問題文
トヨタ自動車株式会社では、たくさんの荷物をコンテナに入れて運んでいる。
荷物の集合とコンテナのサイズのデータが与えられるので、全ての荷物をコンテナに上手く積み込む方法を出力せよ。
荷物を積み込む順番は任意ではあるが、積み込み作業の効率化のため、出来るだけ順番通りに積んで欲しい。 | [
{
"input": "4 1120 680 30 1200\n355 360 285 3 Y Y\n155 210 120 1 Y Y\n510 820 380 1 Y N\n370 710 330 1 Y Y\n",
"output": "0 0 0 30 0\n0 1 360 30 0\n0 0 715 0 0\n1 1 0 385 0\n3 0 30 30 285\n2 0 0 30 615\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_a | Problem Statement
You are given a string
S
consisting of lowercase English letters.
Uppercase each character of
S
and print the resulting string
T
. | [
{
"input": "abc\n",
"output": "ABC\n"
},
{
"input": "a\n",
"output": "A\n"
},
{
"input": "abcdefghjiklnmoqprstvuwxyz\n",
"output": "ABCDEFGHJIKLNMOQPRSTVUWXYZ\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_b | Problem Statement
N
players numbered
1
to
N
will play a soccer game.
When a player commits an offense, that player will receive a
yellow card
or a
red card
.
A player who satisfies one of the following conditions will be
removed
from the game.
Accumulates two yellow cards.
Receives a red card.
Once a player is removed,... | [
{
"input": "3 9\n3 1\n3 2\n1 2\n2 1\n3 1\n3 2\n1 2\n3 2\n3 3\n",
"output": "No\nNo\nYes\nNo\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_c | Problem Statement
You are given a positive integer
N
.
Find the number of quadruples of positive integers
(A,B,C,D)
such that
AB + CD = N
.
Under the constraints of this problem, it can be proved that the answer is at most
9 \times 10^{18}
. | [
{
"input": "4\n",
"output": "8\n"
},
{
"input": "292\n",
"output": "10886\n"
},
{
"input": "19876\n",
"output": "2219958\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_d | Problem Statement
You are given an 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
.
Determine whether every connected component in this graph satisfies the following condition.
The connected component has the same number of vertices and edges. | [
{
"input": "3 3\n2 3\n1 1\n2 3\n",
"output": "Yes\n"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n3 5\n1 5\n",
"output": "Yes\n"
},
{
"input": "13 16\n7 9\n7 11\n3 8\n1 13\n11 11\n6 11\n8 13\n2 11\n3 3\n8 12\n9 11\n1 11\n5 13\n3 12\n6 9\n1 10\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_e | Problem Statement
You are given a simple directed graph with
N
vertices numbered
1
to
N
and
M
edges numbered
1
to
M
. Edge
i
is a directed edge from vertex
u_i
to vertex
v_i
.
You may perform the following operation zero or more times.
Choose distinct vertices
x
and
y
such that there is no directed edge from vertex
x
t... | [
{
"input": "4 3\n2 4\n3 1\n4 3\n",
"output": "3\n"
},
{
"input": "292 0\n",
"output": "0\n"
},
{
"input": "5 8\n1 2\n2 1\n1 3\n3 1\n1 4\n4 1\n1 5\n5 1\n",
"output": "12\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_f | Problem Statement
Find the maximum side length of a regular triangle that can be drawn within a rectangle whose side lengths are
A
and
B
. | [
{
"input": "1 1\n",
"output": "1.03527618041008295791\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_g | Problem Statement
You are given a sequence
S_1,\ldots,S_N
of length-
M
strings consisting of digits (
0123456789
) and
?
.
There are
10^q
ways to replace the occurrences of
?
with digits independently, where
q
is the total number of
?
in
S_1,\ldots,S_N
. Among them, how many satisfy
S_1\lt S_2 \lt \ldots \lt S_N
when t... | [
{
"input": "3 2\n?0\n??\n05\n",
"output": "4\n"
},
{
"input": "2 1\n0\n0\n",
"output": "0\n"
},
{
"input": "10 10\n1?22??37?4\n1??8?0??49\n3?02??8044\n51?4?8?7??\n5?9?20???2\n68?7?6?800\n?3??2???23\n?442312158\n??2??921?8\n????5?96??\n",
"output": "137811792\n"
}
] |
https://atcoder.jp/contests/abc292/tasks/abc292_h | Problem Statement
You will participate in
N
contests, numbered
1
to
N
in chronological order.
A participant in each contest will be given a value called
performance
for that contest. Let
P_i
be the performance for contest
i
.
Additionally, you have a value called
rating
, which changes according to the performances in ... | [
{
"input": "5 6 7\n5 1 9 3 8\n4 9\n2 10\n1 0\n3 0\n3 30\n5 100\n1 100\n",
"output": "6.000000000000000\n7.500000000000000\n6.333333333333333\n5.400000000000000\n13.333333333333334\n13.333333333333334\n100.000000000000000\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_a | Problem Statement
Alice and Bob play a game.
Initially, the pile has
N
stones. The two players alternately remove one stone from the pile.
If
S
is
0
, Alice goes first; if it is
1
, Bob goes first.
If
T
is
0
, the player who removes the last stone wins; if it is
1
, the player who removes the last stone loses (and the... | [
{
"input": "3 0 1\n",
"output": "Bob\n"
},
{
"input": "2 1 0\n",
"output": "Alice\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_b | Problem Statement
You are given decimals
A
and
B
with
D
decimal places.
Precisely compute
A+B
and print the result in the same format. | [
{
"input": "1\n1.2\n1.8\n",
"output": "3.0\n"
},
{
"input": "3\n1.234\n7.890\n",
"output": "9.124\n"
},
{
"input": "4\n1.2345\n8.7655\n",
"output": "10.0000\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_c | Problem Statement
You are given a sequence
P = (P_1, P_2, \ldots, P_N)
that is a permutation of a length-
N
sequence
(1, 2, 3, \ldots, N)
.
For each
K = 1, 2, \ldots, N
, find the integer
X_K
such that
K
is the
X_K
-th element of the sequence
P
. | [
{
"input": "5\n5 2 4 1 3\n",
"output": "4 2 5 3 1\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "10\n10 2 3 7 8 6 1 9 5 4\n",
"output": "7 2 3 10 9 6 4 5 8 1\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_d | Problem Statement
You are playing a game, where you buy and use items to beat an enemy with stamina
H
. There are two kinds of items.
Item
1
:
when you use it, the enemy's stamina is reduced by
A
. The price is
B
yen (the currency in Japan).
Item
2
:
when you use it, the enemy's stamina is reduced by
C
. Let
h
be ... | [
{
"input": "13 6 5 1 7\n",
"output": "12\n"
},
{
"input": "1000 1 1 1 10000\n",
"output": "1000\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_e | Problem Statement
You are given figures
S
and
T
with
H
rows and
W
columns consisting of
#
and
.
.
The figure
S
is given as
H
strings
S _ 1,S _ 2,\ldots,S _ H
; the
j
-th character of
S _ i
represents the element at the
i
-th row and
j
-th column of
S
. The figure
T
is given similarly.
Determine whether one can rearrang... | [
{
"input": "3 4\n##.#\n##..\n.#..\n###.\n#..#\n...#\n",
"output": "Yes\n"
},
{
"input": "3 4\n#...\n#..#\n.###\n..##\n#..#\n##..\n",
"output": "No\n"
},
{
"input": "2 1\n#\n.\n#\n.\n",
"output": "Yes\n"
},
{
"input": "8 7\n..#.#.#\n..#....\n#.#....\n..#.#.#\n..#..#.\n..#...#\... |
https://atcoder.jp/contests/past202303-open/tasks/past202303_f | Problem Statement
Given a set of
N
integers,
S=\{S_1,S_2,\dots,S_N\}
, answer
Q
queries in the following format:
given a set of
M
integers,
T=\{T_1,T_2,\dots,T_M\}
, find how many integers the union of
S
and
T
contains. | [
{
"input": "5\n2 3 5 7 11\n5\n6\n1 3 5 7 9 11\n6\n12 10 8 6 4 2\n3\n5 7 3\n3\n8 4 6\n12\n3 2 1 6 5 4 9 8 7 12 11 10\n",
"output": "7\n10\n5\n8\n12\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_g | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns. The square at the
i
-th row from the top and
j
-th column from the left has a number
A_{i,j}
written on it.
A_{i,j}
are distinct integers between
1
and
HW
.
Find all the integer pairs
(x,y)
satisfying
1\leq x < y \leq HW
such that the squ... | [
{
"input": "2 3\n2 3 4\n1 6 5\n",
"output": "1 2\n1 6\n2 3\n3 4\n3 6\n4 5\n5 6\n"
},
{
"input": "3 1\n1\n2\n3\n",
"output": "1 2\n2 3\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_h | Problem Statement
You have a hand of
N
cards. The
i
-th card
(1 \leq i \leq N)
has an integer
A_i
written on it. You can perform the following operation any number of times.
Choose three cards with consecutive integers written on them, and discard them from hand. In other words, for some integer
x
, choose a card with
... | [
{
"input": "7\n2 4 2 1 6 3 5\n",
"output": "1\n"
},
{
"input": "10\n1 2 2 4 6 7 9 9 10 12\n",
"output": "10\n"
},
{
"input": "3\n999999998 999999999 1000000000\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_i | Problem Statement
N
players numbered
1, \dots, N
sitting around a table play a card game. There are
26
kinds of cards, each of which has
A
,
B
, …, or
Z
written on it. Five cards are placed on the table, and four are dealt to each player.
The cards on the table are represented by a string
X
of length five, and the ca... | [
{
"input": "3\nAABCD\nDDBC\nABBQ\nXYZA\n",
"output": "2\n"
},
{
"input": "4\nABBDE\nADDZ\nBEEZ\nDDDD\nBDDE\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_j | Problem Statement
You are given figures
S
and
T
with
H
rows and
W
columns consisting of
#
and
.
.
The figure
S
is given as
H
strings
S _ 1,S _ 2,\ldots,S _ H
; the
j
-th character of
S _ i
represents the element at the
i
-th row and
j
-th column of
S
. The figure
T
is given similarly.
Determine whether it is possible t... | [
{
"input": "3 4\n##.#\n##..\n.#..\n.###\n..##\n...#\n",
"output": "Yes\n"
},
{
"input": "3 4\n##..\n#..#\n..##\n..##\n#..#\n##..\n",
"output": "No\n"
},
{
"input": "2 1\n#\n.\n#\n.\n",
"output": "Yes\n"
},
{
"input": "8 7\n.#.....\n..#....\n....#..\n#.....#\n.#.....\n..#....\... |
https://atcoder.jp/contests/past202303-open/tasks/past202303_k | Problem Statement
Takahashi and Aoki are playing a game with
N
rounds.
For
i=1,\ldots,N
, the
i
-th round consists of the following steps in the order from top to bottom.
If
i \geq 2
and Takahashi received a penalty in the
(i-1)
-th round, the
i
-th round ends without performing the steps below.
Takahashi is dealt
a_i... | [
{
"input": "3 10 50\n100 10 300\n",
"output": "384.50000000000000000000\n"
},
{
"input": "3 1 10\n192 191 190\n",
"output": "570.89999999999997726263\n"
},
{
"input": "4 17 55\n32 10 77 1000000000\n",
"output": "906500100.00000000000000000000\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_l | Problem Statement
There are
N
players numbered
1,2,\dots
, and
N
.
These
N
players are playing the same game. In this game, two players play a match against each other. The
N
players have distinct strengths; the player with the greater strength always wins a match.
There were
M
matches. The
i
-th match was between p... | [
{
"input": "3 1\n3 1\n",
"output": "2 3 1\n"
},
{
"input": "7 0\n",
"output": "1 2 3 4 5 6 7\n"
}
] |
https://atcoder.jp/contests/past202303-open/tasks/past202303_m | Problem Statement
We have
N
parcels numbered
1
to
N
. Parcel
i
has a size of
A_i
.
There are
M
boxes numbered
1
to
M
arranged in a row in numerical order: box
1
is the leftmost, and box
M
is the rightmost.
Box
i
has a size of
B_i
.
Each box can contain any number of parcels as long as the total size of the parcels is n... | [
{
"input": "3 3\n4 7 3\n10 4 8\n",
"output": "Yes\n7 0 7\n"
},
{
"input": "3 2\n4 7 3\n10 4\n",
"output": "No\n2\n"
},
{
"input": "5 5\n5 4 3 2 1\n1 2 3 4 5\n",
"output": "Yes\n1 2 3 4 5\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_f | 問題文
N \times N
のマス目があります。
i = 1,2,\dots,N
について、左から
i
列目には下から
M_i
個の
1 \times 1
の正方形のブロックがあり、それぞれのブロックには色が塗られています。ここで、
M_1,M_2,\dots,M_N
は単調非増加です。左から
i
列目の下から
j
個目のブロックには色
C_{i,j}
が塗られています。
マス目に対して、以下のような操作を考えます。
マス目を時計回りに瞬間的に
90^\circ
回転させた後、色のついたブロックを重力に従って同時に落下させる。より形式的には、左から
i
列目の下から
j
個目のブロックについて、そのブロックと同じ高さでそのブロック... | [
{
"input": "2\n2 1 2\n1 3\n",
"output": "3\n"
},
{
"input": "2\n2 1 1\n1 1\n",
"output": "1\n"
},
{
"input": "3\n3 1 2 3\n1 4\n0\n",
"output": "6\n"
},
{
"input": "5\n5 1 2 3 4 5\n4 6 7 7 9\n3 10 7 12\n2 13 14\n0\n",
"output": "22\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_g | 問題文
正整数
N
が与えられます。長さ
M
の正整数列
A
は、次の条件を満たすとき
良い数列
であるといいます。
任意の整数の組
(x,y)
(1\leq x\lt y\leq N)
に対して、
(A_i,A_{i+1})=(x,y)
または
(A_i,A_{i+1})=(y,x)
を満たす整数
i\ (1\leq i\leq M-1)
が存在する。
長さ
M
が最小であるような良い数列のうち、辞書順最小のものを求めてください。
T
個のテストケースが与えられるので、それぞれについて答えを求めてください。 | [
{
"input": "2\n3\n2\n",
"output": "1 2 3 1\n1 2\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_h | 問題文
(1,2,\ldots,N)
の順列を以下では単に順列と呼びます。
順列
P
に対して、順列
\mathrm{NextPermutation} (P)
を次で定めます。
P=(N,N-1,\ldots,2,1)
のとき
(1,2,\ldots,N-1,N)
そうでないとき、長さ
N
の順列全てを辞書順昇順に並べたときに
P
の次に来るもの
2
つの順列
P=(P_1, P_2, \ldots,P_N), Q=(Q_1, Q_2, \ldots, Q_N)
が与えられます。
P
が
(1,2,\ldots, N-1,N)
に一致するまで、次の操作を繰り返します。
P
を
\mathrm{NextPermutation} (P)... | [
{
"input": "3\n2 3 1\n3 2 1\n",
"output": "2 1 3\n"
},
{
"input": "4\n4 2 1 3\n2 1 3 4\n",
"output": "2 4 1 3\n"
},
{
"input": "4\n1 2 3 4\n1 2 3 4\n",
"output": "1 2 3 4\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_i | 問題文
正整数
L,R
が与えられます。
L
以上
R
以下の正整数からなる空でない集合
S
であって、
S
のすべての要素を割り切るような正整数のうち最大のものが
1
であるようなものはいくつありますか?
998244353
で割った余りを求めてください。 | [
{
"input": "1 4\n",
"output": "11\n"
},
{
"input": "5 10\n",
"output": "51\n"
},
{
"input": "100 100\n",
"output": "0\n"
},
{
"input": "123456789 987654321\n",
"output": "884200911\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_j | 問題文
N
本の縦線からなるアミダクジがあります。
それぞれの縦線の長さは
2M+1
[\mathrm{cm}]
であり、横線は以下の条件を満たす必要があります。
横線の端点となれるのは上から
1,2,\dots,2M
[\mathrm{cm}]
の高さのみであり、横線の両端点の高さは等しい
全ての横線は、隣り合う
2
つの縦線のみを繋ぐ
同じ高さにある横線は高々
1
本
初め、このアミダクジに
M
本の横線がひかれています。
j\ (j=1,2,\dots,M)
本目の横線は、上から
2j
[\mathrm{cm}]
の位置にひかれており、左から
a_j
本目の縦線と
a_j+1
本目の縦線を結んでいます。
このアミダクジに以下の... | [
{
"input": "3 2\n1 2\n",
"output": "2\n1 1\n3 2\n"
},
{
"input": "5 4\n2 3 4 1\n",
"output": "4\n1 2\n3 3\n5 4\n7 1\n"
},
{
"input": "100000 4\n1 2 2 1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_k | 問題文
長さ
N
の正整数列
(A_1,A_2,\dots,A_N)
が与えられます。
M=\max\,\{A_i\mid 1\leq i\leq N\}
とし、区間
(0,M]
を
K
個の区間に分割します。すなわち、非負実数
m_i \, (i=0,1,\dots,K)
を
0=m_0<m_1<m_2<\dots<m_{K-1}<m_K=M
を満たすように選んで
(0,M]=(m_0,m_1]\cup(m_1,m_2]\cup\dots\cup(m_{Kー1},m_{K}]
とします。
区切り方を適切に定めたとき、
\[
\displaystyle \sum_{i=1}^{K} m_i \times (A_j \in (m_... | [
{
"input": "4 2\n3 7 4 5\n",
"output": "22\n"
},
{
"input": "19 4\n3279 97197 36049 32099 29257 18290 96531 13435 88697 97081 71483 11396 77398 55303 4166 3906 12281 28658 30496\n",
"output": "917886\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_m | 問題文
根付き木
S
に対して、根付き木
f(S)
を、
S
に対して次の操作を行ったものとします。
木
S
の葉をすべて
S
自身で置き換える
根付き木
S
に対して、木の無限列
(S_1, S_2, \dots)
を次のようにして定義します。
S_1 := S
S_i := f(S_{i-1}) \quad (i > 1)
無限木
S_{\infty}:= \displaystyle\lim_{n\to\infty} S_n
を
S
から誘導される
fractal tree
と呼びます。
K
個の根付き木
T_1, T_2, \dots, T_K
が与えられます。
T_i\,(i=1,2,\dots,K)
は、以下の条件をみたす... | [
{
"input": "4\n2 1\n3 1 2\n3 1 1\n5 1 1 2 2\n",
"output": "1100\n1100\n0011\n0011\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_n | 問題文
2 \times 2
行列
A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}
が与えられます。
A
の要素は非負整数です。
あおばさんとひろせさんがこの行列を用いてゲームをします。あおばさんが先手で、交互に以下の行動をします。
A
の行または列を一つ選んで、選んだ行または列の各要素から同じ正整数を引く。このとき、
A
の要素が負になってはいけない。
行動ができなくなった方の負けで、負けなかった方が勝ちです。両者がそれぞれ自身が勝つために最適な戦略をとる場合に、どちらが勝つかを判定してください。
T
個のテストケースが与えられるので、それぞれについて答えを求めてください。 | [
{
"input": "4\n1 3 5 0\n3 0 0 7\n3 1 4 1\n5 9 2 5\n",
"output": "First\nSecond\nFirst\nSecond\n"
}
] |
https://atcoder.jp/contests/tupc2022/tasks/tupc2022_o | 問題文
S_{n,m}
を
n
文字の
0
と
m
文字の
1
からなる長さ
n+m
の文字列全体の集合とします。
s_1, s_2\in S_{n,m}
に対して、
s_1, s_2
の距離
d(s_1, s_2)
を「隣り合った
2
文字を入れ替える操作によって文字列
s_1
を文字列
s_2
に並び替えるのに必要な最小の操作回数」と定義します。
また、
s_1, s_2\in S_{n,m}
に対して、
f(s_1,s_2)
を次で定めます。
d(s_1,t)=d(s_2,t)
となる文字列
t\in S_{n,m}
が存在するとき、そのような文字列の中で辞書順最小のものを返す。そのような文字列が存在しないときは
-1
を返す... | [
{
"input": "2 2\n0101\n",
"output": "4\n"
},
{
"input": "4 1\n00100\n",
"output": "4\n"
},
{
"input": "3 3\n111000\n",
"output": "0\n"
},
{
"input": "6 4\n0001111000\n",
"output": "1254\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_a | Problem Statement
You are given a string
S
consisting of uppercase and lowercase English letters.
Here, exactly one character of
S
is uppercase, and the others are all lowercase.
Find the integer
x
such that the
x
-th character of
S
is uppercase.
Here, the initial character of
S
is considered the
1
-st one. | [
{
"input": "aBc\n",
"output": "2\n"
},
{
"input": "xxxxxxXxxx\n",
"output": "7\n"
},
{
"input": "Zz\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_b | Problem Statement
Takahashi is participating in a gymnastic competition.
In the competition, each of
5N
judges grades Takahashi's performance, and his score is determined as follows:
Invalidate the grades given by the
N
judges who gave the highest grades.
Invalidate the grades given by the
N
judges who gave the lowest ... | [
{
"input": "1\n10 100 20 50 30\n",
"output": "33.333333333333336\n"
},
{
"input": "2\n3 3 3 4 5 6 7 8 99 100\n",
"output": "5.500000000000000\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_c | Problem Statement
Takahashi is on a two-dimensional plane. Starting from the origin, he made
N
moves.
The
N
moves are represented by a string of length
N
as described below:
Takahashi's coordinates after the
i
-th move are:
(x+1,y)
if the
i
-th character of
S
is
R
;
(x-1,y)
if the
i
-th character of
S
is
L
;
(x,y+1)
i... | [
{
"input": "5\nRLURU\n",
"output": "Yes\n"
},
{
"input": "20\nURDDLLUUURRRDDDDLLLL\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_d | Problem Statement
N
cards, numbered
1
through
N
, are arranged in a line. For each
i\ (1\leq i < N)
, card
i
and card
(i+1)
are adjacent to each other.
Card
i
has
A_i
written on its front, and
B_i
written on its back. Initially, all cards are face up.
Consider flipping zero or more cards chosen from the
N
cards.
Amon... | [
{
"input": "3\n1 2\n4 2\n3 4\n",
"output": "4\n"
},
{
"input": "4\n1 5\n2 6\n3 7\n4 8\n",
"output": "16\n"
},
{
"input": "8\n877914575 602436426\n861648772 623690081\n476190629 262703497\n971407775 628894325\n822804784 450968417\n161735902 822804784\n161735902 822804784\n822804784 161735... |
https://atcoder.jp/contests/abc291/tasks/abc291_e | Problem Statement
There is a length-
N
sequence
A=(A_1,\ldots,A_N)
that is a permutation of
1,\ldots,N
.
While you do not know
A
, you know that
A_{X_i}<A_{Y_i}
for
M
pairs of integers
(X_i,Y_i)
.
Can
A
be uniquely determined? If it is possible, find
A
. | [
{
"input": "3 2\n3 1\n2 3\n",
"output": "Yes\n3 1 2\n"
},
{
"input": "3 2\n3 1\n3 2\n",
"output": "No\n"
},
{
"input": "4 6\n1 2\n1 2\n2 3\n2 3\n3 4\n3 4\n",
"output": "Yes\n1 2 3 4\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_f | Problem Statement
There are
N
cities numbered city
1
, city
2
,
\ldots
, and city
N
.
There are also one-way teleporters that send you to different cities.
Whether a teleporter can send you directly from city
i
(1\leq i\leq N)
to another is represented by a length-
M
string
S_i
consisting of
0
and
1
. Specifically, fo... | [
{
"input": "5 2\n11\n01\n11\n10\n00\n",
"output": "2 3 2\n"
},
{
"input": "6 3\n101\n001\n101\n000\n100\n000\n",
"output": "-1 3 3 -1\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_g | Problem Statement
There are length-
N
sequences
A=(A_0,A_1,\ldots,A_{N-1})
and
B=(B_0,B_1,\ldots,B_{N-1})
.
Takahashi may perform the following operation on
A
any number of times (possibly zero):
apply a left cyclic shift to the sequence
A
. In other words, replace
A
with
A'
defined by
A'_i=A_{(i+1)\% N}
, where
x\% N... | [
{
"input": "3\n0 1 3\n0 2 3\n",
"output": "8\n"
},
{
"input": "5\n1 6 1 4 3\n0 6 4 0 1\n",
"output": "23\n"
}
] |
https://atcoder.jp/contests/abc291/tasks/abc291_h | Problem Statement
You are given a tree
T
with
N
vertices. The
i
-th edge connects vertices
A_i
and
B_i
.
Construct an
N
-vertex rooted tree
R
that satisfies the following conditions.
For all integer pairs
(x,y)
such that
1 \leq x < y \leq N
,
if the lowest common ancestor in
R
of vertices
x
and
y
is vertex
z
, then ve... | [
{
"input": "4\n1 2\n2 3\n3 4\n",
"output": "2 -1 4 2\n"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5\n",
"output": "-1 1 1 1 1\n"
}
] |
https://atcoder.jp/contests/arc157/tasks/arc157_a | Problem Statement
Determine whether there is a string
S
of length
N
consisting of
X
and
Y
that satisfies the following condition.
Condition:
Among the
(N - 1)
pairs of consecutive characters in
S
,
exactly
A
are
XX
,
exactly
B
are
XY
,
exactly
C
are
YX
, and
exactly
D
are
YY
. | [
{
"input": "5 1 1 1 1\n",
"output": "Yes\n"
},
{
"input": "5 1 2 1 0\n",
"output": "Yes\n"
},
{
"input": "5 0 4 0 0\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/arc157/tasks/arc157_b | Problem Statement
You are given a string
S
of length
N
consisting of
X
and
Y
.
You will choose
K
characters at distinct positions in
S
and change each of them:
X
becomes
Y
and
Y
becomes
X
.
Find the maximum possible number of pairs of consecutive
Y
s in the resulting string. | [
{
"input": "5 1\nXYXYX\n",
"output": "2\n"
},
{
"input": "5 4\nXYXYX\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/arc157/tasks/arc157_c | Problem Statement
There is a grid with
H
rows and
W
columns where each square has one of the characters
X
and
Y
written on it.
Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
The characters on the grid are given as
H
strings
S_1, S_2, \dots, S_H
: the
j
-th character of
S_i
... | [
{
"input": "2 2\nYY\nXY\n",
"output": "4\n"
},
{
"input": "2 2\nXY\nYY\n",
"output": "2\n"
},
{
"input": "10 20\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\nYYYYYYYYYYYYYYYYYYYY\... |
https://atcoder.jp/contests/arc157/tasks/arc157_d | Problem Statement
There is a grid with
H
rows and
W
columns where each square has one of the characters
X
and
Y
written on it.
Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
The characters on the grid are given as
H
strings
S_1, S_2, \dots, S_H
: the
j
-th character of
S_i
... | [
{
"input": "2 3\nXYY\nYXY\n",
"output": "2\n"
},
{
"input": "2 3\nXYX\nYYY\n",
"output": "0\n"
},
{
"input": "2 58\nYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXY\nYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXYXXY\n",
"output": "164036797\n"
}
] |
https://atcoder.jp/contests/arc157/tasks/arc157_e | Problem Statement
You are given a rooted tree with
N
vertices.
The vertices are numbered
1
to
N
, and the root is vertex
1
.
The parent of each vertex
i
except the root is vertex
P_i
. Each vertex, including the root, has
no child or exactly two children
.
Determine whether it is possible to write one of the characte... | [
{
"input": "3\n7 2 2 2\n1 1 2 2 3 3\n7 0 2 4\n1 1 2 2 3 3\n7 2 0 4\n1 1 2 2 4 4\n",
"output": "Yes\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/arc157/tasks/arc157_f | Problem Statement
You are given strings
S
and
T
of length
N
consisting of
X
and
Y
.
For each
i = 1, 2, \dots, N
, you can swap the
i
-th character of
S
and the
i
-th character of
T
or choose not to do it.
There are
2^N
pairs of strings that can result from this process, including duplicates. Find the longest string t... | [
{
"input": "3\nXXX\nYYY\n",
"output": "XY\n"
},
{
"input": "1\nX\nY\n",
"output": "\n"
},
{
"input": "4\nXXYX\nYYYY\n",
"output": "XYY\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_a | Problem Statement
There was a contest with
N
problems. The
i
-th
(1\leq i\leq N)
problem was worth
A_i
points.
Snuke took part in this contest and solved
M
problems: the
B_1
-th,
B_2
-th,
\ldots
, and
B_M
-th ones.
Find his total score.
Here, the total score is defined as the sum of the points for the problems he sol... | [
{
"input": "3 2\n10 20 30\n1 3\n",
"output": "40\n"
},
{
"input": "4 1\n1 1 1 100\n4\n",
"output": "100\n"
},
{
"input": "8 4\n22 75 26 45 72 81 47 29\n4 6 7 8\n",
"output": "202\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_b | Problem Statement
There were
N
contestants in the qualification round of a programming contest. All contestants got distinct ranks.
You are given a length-
N
string
S
, which represents whether the contestants want to participate in the final round or not. Specifically,
if the
i
-th character of
S
is
o
, the contesta... | [
{
"input": "10 3\noxxoxooxox\n",
"output": "oxxoxoxxxx\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_c | Problem Statement
You are given a length-
N
sequence of non-negative integers.
When
B
is a sequence obtained by choosing
K
elements from
A
and concatenating them without changing the order, find the maximum possible value of
MEX(B)
.
Here, for a sequence
X
, we define
MEX(X)
as the unique non-negative integer
m
that sa... | [
{
"input": "7 3\n2 0 2 3 2 1 9\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_d | Problem Statement
There are
N
squares indexed
0
through
(N-1)
arranged in a line.
Snuke is going to mark every square by the following procedure.
Mark square
0
.
Repeat the following steps i - iii
(N-1)
times.
Initialize a variable
x
with
(A+D) \bmod N
, where
A
is the index of the square marked last time.
While square... | [
{
"input": "9\n4 2 1\n4 2 2\n4 2 3\n4 2 4\n5 8 1\n5 8 2\n5 8 3\n5 8 4\n5 8 5\n",
"output": "0\n2\n1\n3\n0\n3\n1\n4\n2\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_e | Problem Statement
For a sequence
X
, let
f(X) =
(the minimum number of elements one must modify to make
X
a palindrome).
Given a sequence
A
of length
N
, find the sum of
f(X)
over all
contiguous
subarrays of
A
.
Here, a sequence
X
of length
m
is said to be a palindrome if and only if the
i
-th and the
(m+1-i)
-th eleme... | [
{
"input": "5\n5 2 1 2 2\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_f | Problem Statement
For a sequence
X=(X_1,X_2\ldots,X_N)
of length
N
consisting of positive integers, we define
f(X)
as follows:
A tree with
N
vertices is said to be good if and only if the degree of the
i
-th
(1 \leq i \leq N)
vertex is
X_i
.
If a good tree exists,
f(X)
is the maximum diameter of a good tree; if it doe... | [
{
"input": "10\n2\n3\n5\n8\n13\n21\n34\n55\n89\n144\n",
"output": "1\n6\n110\n8052\n9758476\n421903645\n377386885\n881422708\n120024839\n351256142\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_g | Problem Statement
Solve the following problem for
T
test cases.
We have a perfect
K
-ary tree of depth
D
(with
1+K+K^2+\dots+K^D
vertices).
Your objective is to cut some of the edges to obtain a connected component with exactly
X
vertices.
At least how many edges must be cut to achieve the objective? | [
{
"input": "11\n2 2 1\n2 2 2\n2 2 3\n2 2 4\n2 2 5\n2 2 6\n2 2 7\n1 999999999999999999 1\n1 999999999999999999 2\n1 999999999999999999 999999999999999999\n1 999999999999999999 1000000000000000000\n",
"output": "1\n2\n1\n1\n2\n1\n0\n1\n999999999999999998\n1\n0\n"
}
] |
https://atcoder.jp/contests/abc290/tasks/abc290_h | Problem Statement
There are
N
dogs numbered
1
through
N
and
M
cats numbered
1
through
M
.
You will arrange the
(N+M)
animals in a line from left to right.
An arrangement causes each animal's
frustration
as follows:
The frustration of dog
i
is
A_i\times|x-y|
, where
x
and
y
are the numbers of cats to the left and righ... | [
{
"input": "2 2\n1 3\n2 4\n",
"output": "6\n"
},
{
"input": "1 2\n100\n100 290\n",
"output": "390\n"
},
{
"input": "5 7\n522 575 426 445 772\n81 447 629 497 202 775 325\n",
"output": "13354\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_a | Problem Statement
We have
N
coins numbered
1
to
N
with two distinguishable sides. A string
S
represents the current state of the coins. If the
i
-th character of
S
is
1
, coin
i
is showing heads; if that character is
0
, coin
i
is showing tails.
You can repeat the following operation zero or more times.
Choose a pair o... | [
{
"input": "5\n3\n101\n6\n101101\n5\n11111\n6\n000000\n30\n111011100110101100101000000111\n",
"output": "1\n2\n-1\n0\n8\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_b | Problem Statement
For a finite multiset
S
of non-negative integers, let us define
\mathrm{mex}(S)
as the smallest non-negative integer not in
S
. For instance,
\mathrm{mex}(\lbrace 0,0, 1,3\rbrace ) = 2, \mathrm{mex}(\lbrace 1 \rbrace) = 0, \mathrm{mex}(\lbrace \rbrace) = 0
.
There are
N
non-negative integers on a bla... | [
{
"input": "3 1\n0 1 3\n",
"output": "3\n"
},
{
"input": "2 1\n0 0\n",
"output": "2\n"
},
{
"input": "5 10\n3 1 4 1 5\n",
"output": "7109\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_c | Problem Statement
We have a tree
T
with vertices numbered
1
to
N
. The
i
-th edge of
T
connects vertex
u_i
and vertex
v_i
.
Let us use
T
to define the
similarity
of a permutation
P = (P_1,P_2,\ldots,P_N)
of
(1,2,\ldots,N)
as follows.
For a simple path
x=(x_1,x_2,\ldots,x_k)
in
T
, let
y=(P_{x_1}, P_{x_2},\ldots,P_{x_k}... | [
{
"input": "3\n1 2\n2 3\n",
"output": "3 2 1\n"
},
{
"input": "4\n2 1\n2 3\n2 4\n",
"output": "3 4 1 2\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_d | Problem Statement
You are given a sequence of
N
non-negative integers
A=(A_1,A_2,\dots,A_N)
and a positive integer
K
.
Find the bitwise
\mathrm{XOR}
of
\displaystyle \sum_{i=1}^{K} A_{X_i}
over all
N^K
sequences of
K
positive integer sequences
X=(X_1,X_2,\dots,X_K)
such that
1 \leq X_i \leq N\ (1\leq i \leq K)
.
What i... | [
{
"input": "2 2\n10 30\n",
"output": "40\n"
},
{
"input": "4 10\n0 0 0 0\n",
"output": "0\n"
},
{
"input": "11 998244353\n314 159 265 358 979 323 846 264 338 327 950\n",
"output": "236500026047\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_e | Problem Statement
Find the number, modulo
998244353
, of
good sequences
of length
N
whose elements are integers between
0
and
M
, inclusive, and whose sum is at most
K
.
Here, a length-
N
sequence
X=(X_1,X_2,\ldots,X_N)
is said to be good if and only if there is a graph
G
that satisfies all of the following conditions.... | [
{
"input": "4 1 2\n",
"output": "3\n"
},
{
"input": "10 0 0\n",
"output": "1\n"
},
{
"input": "314 159 26535\n",
"output": "248950743\n"
}
] |
https://atcoder.jp/contests/arc156/tasks/arc156_f | Problem Statement
You are given three integer sequences of length
N
:
A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_N),C=(C_1,C_2,\dots,C_N)
.
Find one set of integers that satisfies the following conditions.
It can be obtained as follows: start with an empty set, and for each
i=1,2,\dots,N
in this order, add
A_i
or
B_i
to ... | [
{
"input": "3\n1 1 1\n2 3 4\n5 4 2\n",
"output": "3\n4 1 2\n"
},
{
"input": "15\n1 1 15 11 13 7 7 1 6 1 5 7 4 9 8\n11 30 1 18 16 15 19 17 3 27 22 7 21 29 9\n24 14 23 17 18 16 9 12 10 5 26 29 20 19 11\n",
"output": "12\n7 9 11 17 19 1 15 4 5 6 29 13\n"
}
] |
https://atcoder.jp/contests/ahc018/tasks/ahc018_a | Problem Statement
There is plot of land, represented by a grid of
N
rows and
N
columns.
On the grid, there are
water sources
in
W
spots, and
houses
in
K
spots.
Let us call the cell on
i
th (
0 \leq i \lt N
) row from top and
j
th column (
0 \leq j \lt N
) from left,
(i, j)
.
Each cell
(i, j)
has an associated integer
S... | [] |
https://atcoder.jp/contests/agc061/tasks/agc061_a | Problem Statement
There is an array
A_1, \ldots, A_N
, and initially
A_i = i
for all
i
. Define the following routine
\mathrm{shuffle}(L, R)
:
If
R = L + 1
, swap values of
A_L
and
A_R
and terminate.
Otherwise, run
\mathrm{shuffle}(L, R - 1)
followed by
\mathrm{shuffle}(L + 1, R)
.
Suppose we run
\mathrm{shuffle}(1, N)... | [
{
"input": "7\n2 1\n2 2\n5 1\n5 2\n5 3\n5 4\n5 5\n",
"output": "2\n1\n2\n4\n1\n5\n3\n"
}
] |
https://atcoder.jp/contests/agc061/tasks/agc061_b | Problem Statement
There is a graph with
N
vertices
v_1, \ldots, v_N
on the left, and
N + 1
vertices
u_1, \ldots, u_{N + 1}
on the right. Each vertex
v_i
(
1 \leq i \leq N
) is connected to each vertex
u_j
(
1 \leq j \leq N + 1
), that is, the graph contains
N(N + 1)
edges.
We color every edge with one of the
N
colors
1... | [
{
"input": "2\n1\n2\n",
"output": "Yes\n1 1\nNo\n"
}
] |
https://atcoder.jp/contests/agc061/tasks/agc061_c | Problem Statement
There are
N
customers named
1,\ldots,N
visiting a shop. Customer
i
arrives at time
A_i
and leaves at time
B_i
. The queue order is
first in-first out
, so
A_i
are increasing, and
B_i
are increasing. Additionally, all
A_i
and
B_i
are pairwise distinct.
At the entrance there's a list of visitors to put ... | [
{
"input": "3\n1 3\n2 5\n4 6\n",
"output": "3\n"
},
{
"input": "4\n1 2\n3 4\n5 6\n7 8\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/agc061/tasks/agc061_d | Problem Statement
There are positive integers
N, M
, and an
N \times M
positive integer matrix
A_{i, j}
. For two
(strictly) increasing
positive integer sequences
X = (X_1, \ldots, X_N)
and
Y = (Y_1, \ldots, Y_M)
, we define the penalty
D(X, Y)
as
\max_{1 \leq i \leq N, 1 \leq j \leq M} |X_i Y_j - A_{i, j}|
.
Find two
... | [
{
"input": "1 1\n853922530\n",
"output": "0\n31415\n27182\n"
},
{
"input": "3 3\n4 4 4\n4 4 4\n4 4 4\n",
"output": "5\n1 2 3 \n1 2 3 \n"
},
{
"input": "3 4\n4674 7356 86312 100327\n8737 11831 145034 167690\n47432 66105 809393 936462\n",
"output": "357\n129 216 1208 \n39 55 670 775 \n... |
https://atcoder.jp/contests/agc061/tasks/agc061_e | Problem Statement
There is a non-negative integer
X
initially equal to
S
. One can perform the following operations, in any order, any number of times:
Add
1
to
X
. This has a cost of
A
.
Choose
i
between
1
and
N
, and replace
X
with
X \oplus Y_i
. This has a cost of
C_i
. Here,
\oplus
denotes bitwise
\mathrm{XOR}
.
Fi... | [
{
"input": "1 15 0 1\n8 2\n",
"output": "5\n"
},
{
"input": "3 21 10 100\n30 1\n12 1\n13 1\n",
"output": "3\n"
},
{
"input": "1 2 0 1\n1 1\n",
"output": "-1\n"
},
{
"input": "8 352217 670575 84912\n239445 2866\n537211 16\n21812 6904\n50574 8842\n380870 5047\n475646 8924\n1882... |
https://atcoder.jp/contests/agc061/tasks/agc061_f | Problem Statement
There are positive integers
N
and
M
.
A binary string
s
is called
good
if all of the followings are satisfied:
s
is non-empty.
The number of
1
s in
s
is a multiple of
N
.
The number of
0
s in
s
is a multiple of
M
.
A good string is called
perfect
if it doesn't contain shorter good (contiguous) substri... | [
{
"input": "2 2\n",
"output": "4\n"
},
{
"input": "3 2\n",
"output": "7\n"
},
{
"input": "23 35\n",
"output": "212685109\n"
}
] |
https://atcoder.jp/contests/joi2023ho/tasks/joi2023ho_a | 問題文
JOI 君は
N
個の碁石を持っている.それぞれの碁石には
1
から
N
までの番号が付けられており,
1
以上
10^9
以下の整数で表される色で塗られている.最初,碁石
i
(
1 \leqq i \leqq N
) の色は
A_i
である.
JOI 君はこれから
N
回の操作を行い,碁石をテーブルの上に
1
列に並べたい.
i
回目 (
1 \leqq i \leqq N
) の操作は以下のような手順で行われる.
碁石
i
を碁石
i-1
の右隣に置く.ただし,
i=1
の場合は,碁石
1
をテーブルの上に置く.
碁石
1, 2, \dots, i-1
のうち現在の色が碁石
i
と同じであるものが存在する場合,それらの... | [
{
"input": "6\n1\n2\n1\n2\n3\n2\n",
"output": "1\n1\n1\n2\n2\n2\n"
},
{
"input": "10\n1\n1\n2\n2\n1\n2\n2\n1\n1\n2\n",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n"
}
] |
https://atcoder.jp/contests/joi2023ho/tasks/joi2023ho_b | 問題文
JOI 国には
N
人の住人がおり,
1
から
N
までの番号が付けられている.
住人
i
(
1 \leqq i \leqq N
) は数直線上の座標
X_i
に住んでおり,その
影響力
は
E_i
である.同じ座標に複数の住人が住んでいることもある.
影響力が高い住人ほど宣伝効果が大きい一方で,本を買うのに慎重になる.
理恵さんは情報科学の本を出版した.本を多くの人に買ってもらうため,何人かの住人に献本をすることができる.
住民
i
(
1 \leqq i \leqq N
) に献本した場合,住人
i
は理恵さんの本を手に入れる.
さらに,まだ理恵さんの本を持っていない住人のうち,次の条件を満たすようなすべての住人
j
... | [
{
"input": "4\n4 2\n2 3\n3 4\n6 5\n",
"output": "2\n"
},
{
"input": "3\n7 10\n10 10\n7 10\n",
"output": "2\n"
},
{
"input": "10\n31447678 204745778\n430226982 292647686\n327782937 367372305\n843320852 822224390\n687565054 738216211\n970840050 766211141\n563662348 742939240\n103739645 854... |
https://atcoder.jp/contests/joi2023ho/tasks/joi2023ho_c | 問題文
迷路を解くのが好きな K 理事長は,迷路になりそうなマス目を見つけた.マス目は縦
R
行,横
C
列の長方形の形をしており,各マスは白または黒で塗られている.上から
i
行目 (
1 \leqq i \leqq R
),左から
j
列目 (
1 \leqq j \leqq C
) のマスをマス
(i, j)
と呼ぶことにする.
K 理事長は,マス目の白いマスは通れるマス,黒いマスは通れないマスとして,迷路を解くことにした.具体的には,以下のようにして迷路を解く.
白いマスの中からスタートのマス
(S_r, S_c)
とゴールのマス
(G_r, G_c)
を選ぶ.
上下左右に隣接する白いマスに移動することを繰り返して,スタート... | [
{
"input": "2 4 2\n1 1\n2 4\n.###\n###.\n",
"output": "1\n"
},
{
"input": "6 6 1\n1 6\n6 1\n..#.#.\n##.###\n####.#\n...###\n##.##.\n.#.###\n",
"output": "4\n"
},
{
"input": "6 7 6\n6 4\n3 1\n..#.#.#\n##.##..\n.######\n#..#.#.\n.######\n..#.##.\n",
"output": "1\n"
},
{
"input"... |
https://atcoder.jp/contests/joi2023ho/tasks/joi2023ho_d | 問題文
N
個のキャットタワーがあり,それぞれに
1
から
N
までの番号が付けられている.
タワー
i
(
1 \leqq i \leqq N
) の高さは
P_i
である.
タワーの高さは
1
以上
N
以下の相異なる整数である.
N-1
組のタワーが隣接しており,各
j
(
1 \leqq j \leqq N-1
) について,
タワー
A_j
とタワー
B_j
が隣接している.
はじめ,どのタワーからどのタワーへも隣接するタワーへ移動する操作を繰り返して移動できる.
最初,猫が高さ
N
のタワーの上にいる.
次に,
キャットエクササイズ
を行う.
キャットエクササイズとは,
1
つのタワーを選んでそこに障害物を置く操作の繰り... | [
{
"input": "4\n3 4 1 2\n1 2\n2 3\n3 4\n",
"output": "3\n"
},
{
"input": "7\n3 2 7 1 5 4 6\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/joi2023ho/tasks/joi2023ho_e | 問題文
ビ太郎は,誕生日プレゼントとして JOI マシンをもらった.
JOI マシンは,
1
個の
ボール
,
N
個の
ライトタイル
,
M
個の
ボタン
からなる.
ライトタイルにはそれぞれ
1
から
N
までの番号が付けられており,
電源を入れると,ライトタイル
i
(
1 \leqq i \leqq N
) は色
C_i
(青 (
B
),赤 (
R
) のいずれか) で光るようになっている.
また,ボタンにはそれぞれ
1
から
M
までの番号が付けられており,
ボタン
j
(
1 \leqq j \leqq M
) を押すと,次のようなことが起こる.
ライトタイル
A_j
の上にボールが置かれる.
ライトタイル
A_j
の... | [
{
"input": "5 1\nRBRRB\n4\n1\n1 1\n",
"output": "1\n"
},
{
"input": "5 3\nRBRBR\n1 3 4\n2\n2 3\n1 3\n",
"output": "5\n0\n"
},
{
"input": "10 3\nBBRRBRBRRB\n2 10 5\n1\n1 3\n",
"output": "2\n"
},
{
"input": "10 10\nRRRRRRRRRR\n3 1 4 1 5 9 2 6 5 3\n5\n1 7\n2 8\n3 9\n4 10\n1 10\n... |
https://atcoder.jp/contests/abc289/tasks/abc289_a | Problem Statement
You are given a string
s
consisting of two kinds of characters,
0
and
1
.
Print the string obtained by replacing
0
with
1
and
1
with
0
in
s
. | [
{
"input": "01\n",
"output": "10\n"
},
{
"input": "1011\n",
"output": "0100\n"
},
{
"input": "100100001\n",
"output": "011011110\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_b | Problem Statement
Studying
Kanbun
, Takahashi is having trouble figuring out the order to read words. Help him out!
There are
N
integers from
1
through
N
arranged in a line in ascending order.
Between them are
M
"レ" marks. The
i
-th "レ" mark is between the integer
a_i
and integer
(a_i + 1)
.
You read each of the
N
in... | [
{
"input": "5 3\n1 3 4\n",
"output": "2 1 5 4 3\n"
},
{
"input": "5 0\n\n",
"output": "1 2 3 4 5\n"
},
{
"input": "10 6\n1 2 3 7 8 9\n",
"output": "4 3 2 1 5 6 10 9 8 7\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_c | Problem Statement
There are
M
sets, called
S_1, S_2, \dots, S_M
, consisting of integers between
1
and
N
.
S_i
consists of
C_i
integers
a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}
.
There are
(2^M-1)
ways to choose one or more sets from the
M
sets.
How many of them satisfy the following condition?
For all integers
x
such tha... | [
{
"input": "3 3\n2\n1 2\n2\n1 3\n1\n2\n",
"output": "3\n"
},
{
"input": "4 2\n2\n1 2\n2\n1 3\n",
"output": "0\n"
},
{
"input": "6 6\n3\n2 3 6\n3\n2 4 6\n2\n3 6\n3\n1 5 6\n3\n1 3 6\n2\n1 4\n",
"output": "18\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_d | Problem Statement
There is a staircase with infinite steps.
The foot of the stairs is the
0
-th step, the next step is the
1
-st step, the next is the
2
-nd, and so on.
There is a stair-climbing robot on the
0
-th step.
The robot can climb up
A _ 1,A _ 2,\ldots
, or
A _ N
steps at a time.
In other words, when the ro... | [
{
"input": "3\n3 4 5\n4\n4 5 6 8\n15\n",
"output": "Yes\n"
},
{
"input": "4\n2 3 4 5\n4\n3 4 5 6\n8\n",
"output": "No\n"
},
{
"input": "4\n2 5 7 8\n5\n2 9 10 11 19\n20\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_e | Problem Statement
There is a simple undirected graph with
N
vertices numbered
1
through
N
and
M
edges numbered
1
through
M
. Edge
i
connects vertex
u_i
and vertex
v_i
.
Every vertex is painted either red or blue. The color of vertex
i
is represented by
C_i
; vertex
i
is painted red if
C_i
is
0
and blue if
C_i
is
1
.
... | [
{
"input": "3\n4 4\n0 1 0 1\n1 2\n2 3\n1 3\n2 4\n3 3\n0 1 0\n1 2\n2 3\n1 3\n6 6\n0 0 1 1 0 1\n1 2\n2 6\n3 6\n4 6\n4 5\n2 4\n",
"output": "3\n-1\n3\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_f | Problem Statement
Takahashi is on an
xy
-plane.
Initially, he is at point
(s _ x,s _ y)
,
and he wants to reach point
(t _ x,t _ y)
.
On the
xy
-plane is a rectangle
R\coloneqq\lbrace(x,y)\mid a-0.5\leq x\leq b+0.5,c-0.5\leq y\leq d+0.5\rbrace
.
Consider the following operation:
Choose a lattice point
(x,y)
containe... | [
{
"input": "1 2\n7 8\n7 9 0 3\n",
"output": "Yes\n7 0\n9 3\n7 1\n8 1\n"
},
{
"input": "0 0\n8 4\n5 5 0 0\n",
"output": "No\n"
},
{
"input": "1 4\n1 4\n100 200 300 400\n",
"output": "Yes\n"
},
{
"input": "22 2\n16 7\n14 30 11 14\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc289/tasks/abc289_g | Problem Statement
Takahashi runs AtCoder store.
N
customers visit the store, and
M
items are sold in the store.
The motivation of the
i
-th
(1\leq i\leq N)
customer is
B _ i
.
The value of the
j
-th
(1\leq j\leq M)
item is
C _ j
.
Takahashi sets a price for each item.
The
i
-th customer buys one
j
-th item if and on... | [
{
"input": "5 4\n100 200 300 400 500\n120 370 470 80\n",
"output": "1280 2350 2850 1140\n"
},
{
"input": "4 4\n0 2 10 2\n13 13 0 4\n",
"output": "52 52 10 18\n"
},
{
"input": "12 15\n16 592 222 983 729 338 747 61 451 815 838 281\n406 319 305 519 317 590 507 946 365 5 673 478 340 176 2\n"... |
https://atcoder.jp/contests/abc289/tasks/abc289_h | Problem Statement
On a number line are person
1
, person
2
, and person
3
. At time
0
, person
1
is at point
A
, person
2
is at point
B
, and person
3
is at point
C
.
Here,
A
,
B
, and
C
are all integers, and
A \equiv B \equiv C \pmod{2}
.
At time
0
, the three people start random walks. Specifically, a person that i... | [
{
"input": "1 1 3 1\n",
"output": "873463809\n"
},
{
"input": "0 0 0 0\n",
"output": "1\n"
},
{
"input": "0 2 8 9\n",
"output": "744570476\n"
},
{
"input": "47717 21993 74147 76720\n",
"output": "844927176\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_a | Problem Statement
You are given
N
pairs of integers:
(A_1, B_1), (A_2, B_2), \ldots, (A_N, B_N)
.
For each
i = 1, 2, \ldots, N
, print
A_i + B_i
. | [
{
"input": "4\n3 5\n2 -6\n-5 0\n314159265 123456789\n",
"output": "8\n-4\n-5\n437616054\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_b | Problem Statement
There were
N
participants in a contest. The participant ranked
i
-th had the nickname
S_i
.
Print the nicknames of the top
K
participants in
lexicographical order
.
What is lexicographical order?
Simply put, the lexicographical order is the order of words in a dictionary. As a formal description, belo... | [
{
"input": "5 3\nabc\naaaaa\nxyz\na\ndef\n",
"output": "aaaaa\nabc\nxyz\n"
},
{
"input": "4 4\nz\nzyx\nzzz\nrbg\n",
"output": "rbg\nz\nzyx\nzzz\n"
},
{
"input": "3 1\nabc\narc\nagc\n",
"output": "abc\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_c | Problem Statement
You are given a simple undirected graph with
N
vertices and
M
edges. The vertices are numbered
1
to
N
, and the
i
-th edge connects vertex
A_i
and vertex
B_i
.
Let us delete zero or more edges to remove cycles from the graph. Find the minimum number of edges that must be deleted for this purpose.
Wha... | [
{
"input": "6 7\n1 2\n1 3\n2 3\n4 2\n6 5\n4 6\n4 5\n",
"output": "2\n"
},
{
"input": "4 2\n1 2\n3 4\n",
"output": "0\n"
},
{
"input": "5 3\n1 2\n1 3\n2 3\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_d | Problem Statement
You are given an integer sequence of length
N
,
A = (A_1, A_2, \ldots, A_N)
, and a positive integer
K
.
For each
i = 1, 2, \ldots, Q
, determine whether a contiguous subsequence of
A
,
(A_{l_i}, A_{l_i+1}, \ldots, A_{r_i})
, is a
good sequence
.
Here, a sequence of length
n
,
X = (X_1, X_2, \ldots, X... | [
{
"input": "7 3\n3 -1 1 -2 2 0 5\n2\n1 6\n2 7\n",
"output": "Yes\nNo\n"
},
{
"input": "20 4\n-19 -66 -99 16 18 33 32 28 26 11 12 0 -16 4 21 21 37 17 55 -19\n5\n13 16\n4 11\n3 12\n13 18\n4 10\n",
"output": "No\nYes\nNo\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_e | Problem Statement
There are
N
items in a shop, numbered as Item
1
, Item
2
,
\ldots
, Item
N
.
For each
i = 1, 2, \ldots, N
, the
regular price
of Item
i
is
A_i
yen. For each item, there is only one in stock.
Takahashi wants
M
items: Item
X_1
, Item
X_2
,
\ldots
, Item
X_M
.
He repeats the following until he gets all i... | [
{
"input": "5 2\n3 1 4 1 5\n9 2 6 5 3\n3 5\n",
"output": "17\n"
},
{
"input": "20 8\n29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62\n32 38 84 49 93 53 26 13 25 2 76 32 42 34 18 77 14 67 88 12\n1 3 4 5 8 14 16 20\n",
"output": "533\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_f | Problem Statement
You are given a positive integer
X
with
N
digits in decimal representation. None of the digits of
X
is
0
.
For a subset
S
of
\lbrace 1,2, \ldots, N-1 \rbrace
, let
f(S)
be defined as follows.
See the decimal representation of
X
as a string of length
N
, and decompose it into
|S| + 1
strings by splitti... | [
{
"input": "3\n234\n",
"output": "418\n"
},
{
"input": "4\n5915\n",
"output": "17800\n"
},
{
"input": "9\n998244353\n",
"output": "258280134\n"
}
] |
https://atcoder.jp/contests/abc288/tasks/abc288_g | Problem Statement
There is zero or one bomb at each of positions
0, 1, 2, \ldots, 3^N-1
.
Let us say that positions
x
and
y
are
neighboring
each other if and only if the following condition is satisfied for every
i=1, \ldots, N
.
Let
x'
and
y'
be the
i
-th lowest digits of
x
and
y
in ternary representation, respectivel... | [
{
"input": "1\n0 1 1\n",
"output": "0 0 1\n"
},
{
"input": "2\n2 3 2 4 5 3 3 4 2\n",
"output": "0 1 0 1 0 1 1 1 0\n"
},
{
"input": "2\n0 0 0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 0 0\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.