url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/arc138/tasks/arc138_e | Problem Statement
You are given integers
N
and
K
.
Let us call an integer sequence
A=(A_1,A_2,\cdots,A_N)
good
when it satisfies all of the conditions below.
0 \leq A_i \leq i
(
1 \leq i \leq N
)
For every integer
v=1,2,\cdots,N
, there is at most one index
i
such that
A_i=v
.
Find the sum, modulo
(10^9+7)
, of the answers to the following problem for all good sequences
A
.
Find the number of length-
K
(not necessarily contiguous) subsequences of
A
consisting of positive integers that are decreasing. In other words, find the number of sequences of indices
1 \leq i_1 < i_2 < \cdots < i_K \leq N
such that
A_{i_1}>A_{i_2}>\cdots>A_{i_K} \geq 1
. | [
{
"input": "3 2\n",
"output": "1\n"
},
{
"input": "6 2\n",
"output": "660\n"
},
{
"input": "10 3\n",
"output": "242595\n"
},
{
"input": "100 10\n",
"output": "495811864\n"
}
] |
https://atcoder.jp/contests/arc138/tasks/arc138_f | Problem Statement
There are
N
points in a plane, the
i
-th (
1 \leq i \leq N
) of which is
(i,P_i)
.
Here,
(P_1,P_2,\cdots,P_N)
is a permutation of
(1,2,\cdots,N)
.
You can
arrange
a non-empty set
s
of points, which is a recursive operation defined as follows.
If
s
contains exactly one point, arranging it creates a sequence composed of just that point.
If
s
contains two or more points, arranging it creates a sequence composed of those points by doing one of the following two operations.
Choose any integer
x
and divide
s
into two: the set
a
of points whose
X
-coordinates are less than
x
and the set
b
of the other points.
Here, neither
a
nor
b
should be empty.
Create a sequence by concatenating the sequence obtained by arranging
a
and the sequence obtained by arranging
b
in this order.
Choose any integer
y
and divide
s
into two: the set
a
of points whose
Y
-coordinates are less than
y
and the set
b
of the other points.
Here, neither
a
nor
b
should be empty.
Create a sequence by concatenating the sequence obtained by arranging
a
and the sequence obtained by arranging
b
in this order.
Find the number, modulo
(10^9+7)
, of sequences that can be obtained by arranging the set of points
\{(1,P_1),(2,P_2),\cdots,(N,P_N)\}
. | [
{
"input": "3\n3 1 2\n",
"output": "3\n"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "1\n"
},
{
"input": "10\n3 6 4 8 7 2 10 5 9 1\n",
"output": "1332\n"
},
{
"input": "30\n7 11 8 26 4 13 28 5 14 1 16 27 10 2 23 25 17 6 3 18 24 15 9 22 21 29 12 20 19 30\n",
"output": "641915679\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_a | Problem Statement
There is a rectangle in the
xy
-plane. Each edge of this rectangle is parallel to the
x
- or
y
-axis, and its area is not zero.
Given the coordinates of three of the four vertices of this rectangle,
(x_1, y_1)
,
(x_2, y_2)
, and
(x_3, y_3)
, find the coordinates of the other vertex. | [
{
"input": "-1 -1\n-1 2\n3 2\n",
"output": "3 -1\n"
},
{
"input": "-60 -40\n-60 -80\n-20 -80\n",
"output": "-20 -40\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_b | Problem Statement
From the point
(0,0)
in a two-dimensional plane, let us move the distance of
1
toward the point
(A, B)
. Find our coordinates after the move.
Here, after moving the distance of
d
from a point
X
to a point
Y
(
d \le
length of the segment
XY
), we are at the point on the segment
XY
whose distance from
X
is
d
.
The Constraints guarantee that the distance between the points
(0, 0)
and
(A, B)
is at least
1
. | [
{
"input": "3 4\n",
"output": "0.600000000000 0.800000000000\n"
},
{
"input": "1 0\n",
"output": "1.000000000000 0.000000000000\n"
},
{
"input": "246 402\n",
"output": "0.521964870245 0.852966983083\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_c | Problem Statement
There are
N
items in a shop. For each
i = 1, 2, \ldots, N
, the price of the
i
-th item is
A_i
yen (the currency of Japan).
Takahashi has
K
coupons.
Each coupon can be used on one item. You can use any number of coupons, possibly zero, on the same item. Using
k
coupons on an item with a price of
a
yen allows you to buy it for
\max\lbrace a - kX, 0\rbrace
yen.
Print the minimum amount of money Takahashi needs to buy all the items. | [
{
"input": "5 4 7\n8 3 10 5 13\n",
"output": "12\n"
},
{
"input": "5 100 7\n8 3 10 5 13\n",
"output": "0\n"
},
{
"input": "20 815 60\n2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202\n",
"output": "112\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_d | Problem Statement
Given an integer
N
, find the smallest integer
X
that satisfies all of the conditions below.
X
is greater than or equal to
N
.
There is a pair of non-negative integers
(a, b)
such that
X=a^3+a^2b+ab^2+b^3
. | [
{
"input": "9\n",
"output": "15\n"
},
{
"input": "0\n",
"output": "0\n"
},
{
"input": "999999999989449206\n",
"output": "1000000000000000000\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_e | Problem Statement
We have an
N \times N
chessboard. Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left of this board.
The board is described by
N
strings
S_i
.
The
j
-th character of the string
S_i
,
S_{i,j}
, means the following.
If
S_{i,j}=
.
, the square
(i, j)
is empty.
If
S_{i,j}=
#
, the square
(i, j)
is occupied by a white pawn, which cannot be moved or removed.
We have put a white bishop on the square
(A_x, A_y)
.
Find the minimum number of moves needed to move this bishop from
(A_x, A_y)
to
(B_x, B_y)
according to the rules of chess (see Notes).
If it cannot be moved to
(B_x, B_y)
, report
-1
instead. | [
{
"input": "5\n1 3\n3 5\n....#\n...#.\n.....\n.#...\n#....\n",
"output": "3\n"
},
{
"input": "4\n3 2\n4 2\n....\n....\n....\n....\n",
"output": "-1\n"
},
{
"input": "18\n18 1\n1 18\n..................\n.####.............\n.#..#..####.......\n.####..#..#..####.\n.#..#..###...#....\n.#..#..#..#..#....\n.......####..#....\n.............####.\n..................\n..................\n.####.............\n....#..#..#.......\n.####..#..#..####.\n.#.....####..#....\n.####.....#..####.\n..........#..#..#.\n.............####.\n..................\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_f | Problem Statement
We have a typewriter with
N
rows. The keys in the
i
-th row from the top can type the characters in a string
S_i
.
Let us use this keyboard to enter a string, as follows.
First, choose an integer
1 \le k \le N
.
Then, start with an empty string and only use the keys in the
k
-th row from the top to enter a string of length exactly
L
.
How many strings of length
L
can be entered in this way?
Since the answer can be enormous, print it modulo
998244353
. | [
{
"input": "2 2\nab\nac\n",
"output": "7\n"
},
{
"input": "4 3\nabcdefg\nhijklmnop\nqrstuv\nwxyz\n",
"output": "1352\n"
},
{
"input": "5 1000000000\nabc\nacde\ncefg\nabcfh\ndghi\n",
"output": "346462871\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_g | Problem Statement
There is a rooted tree with
N
vertices, Vertex
1
being the root.
For each
i = 1, 2, \ldots, N-1
, the
i
-th edge connects Vertex
u_i
and Vertex
v_i
.
Each vertex other than the root has a positive integer written on it: for each
i = 2, 3, \ldots, N
, the integer written on Vertex
i
is
A_i
.
Takahashi and Aoki will use this rooted tree and a piece to play the following game against each other.
The piece starts on Vertex
1
. Until the game ends, they repeat the following procedure.
First, Aoki chooses a non-root vertex and replaces the integer written on that vertex with
0
.
Next, Takahashi moves the piece to a (direct) child of the vertex the piece is on.
Then, the game ends if the piece is on a leaf. Even if that is not the case, Takahashi can choose to end the game immediately.
At the end of the game, Takahashi's score will be the integer written at that time on the vertex the piece is on.
Takahashi wants to make his score as large as possible, while Aoki wants to make it as small as possible.
Print the score Takahashi will get when both players play optimally for their respective purposes. | [
{
"input": "7\n2 4 6 5 6 10\n1 2\n1 3\n2 4\n2 5\n5 6\n5 7\n",
"output": "5\n"
},
{
"input": "30\n29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62 32 38 84 49 93 53 26 13 25\n13 15\n14 22\n17 24\n12 3\n4 3\n5 8\n26 15\n3 2\n2 9\n4 25\n4 13\n2 10\n28 15\n6 4\n2 5\n19 9\n2 7\n2 14\n23 30\n17 2\n7 16\n21 13\n13 23\n13 20\n1 2\n6 18\n27 6\n21 29\n11 8\n",
"output": "70\n"
}
] |
https://atcoder.jp/contests/abc246/tasks/abc246_h | Problem Statement
You are given a string
S
of length
N
consisting of
0
,
1
, and
?
.
You are also given
Q
queries
(x_1, c_1), (x_2, c_2), \ldots, (x_Q, c_Q)
.
For each
i = 1, 2, \ldots, Q
,
x_i
is an integer satisfying
1 \leq x_i \leq N
and
c_i
is one of the characters
0
,
1
, and
?
.
For
i = 1, 2, \ldots, Q
in this order, do the following process for the query
(x_i, c_i)
.
First, change the
x_i
-th character from the beginning of
S
to
c_i
.
Then, print the number of non-empty strings, modulo
998244353
, that can be obtained as a (not necessarily contiguous) subsequence of
S
after replacing each occurrence of
?
in
S
with
0
or
1
independently. | [
{
"input": "3 3\n100\n2 1\n2 ?\n3 ?\n",
"output": "5\n7\n10\n"
},
{
"input": "40 10\n011?0??001??10?0??0?0?1?11?1?00?11??0?01\n5 0\n2 ?\n30 ?\n7 1\n11 1\n3 1\n25 1\n40 0\n12 1\n18 1\n",
"output": "746884092\n532460539\n299568633\n541985786\n217532539\n217532539\n217532539\n573323772\n483176957\n236273405\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_a | 問題文
今年のパ研合宿には、外部から
4
人の講師が参加しています。
運営長であるペンギンくんは、パ研合宿のスケジュールを管理するにあたり、合宿の日程すべてに参加する講師の数を把握したいです。
今年のパ研合宿は
4
日間からなり、
i
人目の講師は文字列
S_i
の
j
文字目が
1
なら合宿の
j
日目に参加し、
0
なら合宿の
j
日目には欠席します。遅刻や早退は考慮しません。
ペンギンくんの代わりに、合宿の日程すべてに参加する講師の数を数えてあげてください。 | [
{
"input": "1111\n0101\n0000\n1111\n",
"output": "2\n"
},
{
"input": "1111\n1111\n1111\n1111\n",
"output": "4\n"
},
{
"input": "0010\n1000\n0110\n0010\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_b | 問題文
N
人のパ研部員が、円環上に配置されています。そしてまた彼らには、時計回りに
1
から
N
までの番号が振られています。
各パ研部員にはレートと呼ばれる値が定まっており、部員
i
のレートは
A_i
です。
パ研部長であるペンギンくんは、
N
人のパ研部員を円環上で連続した
2
つのグループに分け、片方のグループに含まれるパ研部員のレートの総和を
X
に、もう片方のグループに含まれるパ研部員のレートの総和を
Y
にしたいと考えています。
これが可能かを判定してください。 | [
{
"input": "5 6 11\n3 4 2 3 5\n",
"output": "Yes\n"
},
{
"input": "4 4 8\n1 2 3 4\n",
"output": "No\n"
},
{
"input": "10 191 376\n72 6 62 98 90 61 36 82 9 51\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_c | 問題文
正整数
n,k
に対して
f_k(n)
を、
n
の
10
進法での下
k
桁の桁和で定義します。例えば、
f_2(314)=5,f_1(100)=0,f_{100}(1)=1
です。
正整数
L,R,M
が与えられるので、
\displaystyle \sum_{k=L}^R f_M(5^k)
を求めてください。 | [
{
"input": "2 4\n3\n",
"output": "28\n"
},
{
"input": "333 4444\n5\n",
"output": "77100\n"
},
{
"input": "12 998244353\n5\n",
"output": "18717081408\n"
},
{
"input": "12321 123456787654321\n16\n",
"output": "8395076630065056\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_d | 問題文
20XX年、高校教師となったペンギンくんは期末試験の作成に勤しんでいます。
N
個の問題があり、この中から
1
問以上を選んで期末試験を作成します。試験時間は
T
分と決まっていますが、選ぶ問題の数は自由です。
期末試験はペンギンくんの教え子たちによって解かれますが、その中には太郎くんと次郎くんの
2
人がいます。各
i\ (1 \leq i \leq N)
について、太郎くんが
i
問目の問題を解くのにかかる時間は
A_i
分、次郎くんがかかる時間は
B_i
分であることが分かっています。
太郎くんを贔屓したいペンギンくんは、なるべく太郎くんに有利になるような試験を作ろうとしています。使用する問題をうまく選ぶことで、(太郎くんが解いた問題数)-(次郎くんが解いた問題数)を最大化してください。
ただし、太郎くん、次郎くんの
2
人は各々が試験中に解く問題の数を最大化するように問題を解くこととします。 | [
{
"input": "4 8\n3 4\n5 3\n3 4\n4 5\n",
"output": "1\n"
},
{
"input": "6 10\n1 2\n2 3\n2 5\n4 7\n4 8\n5 10\n",
"output": "2\n"
},
{
"input": "10 100\n95 5\n85 70\n8 44\n71 66\n74 11\n39 2\n26 81\n29 23\n92 70\n52 57\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_e | 問題文
Paken 王国には
N
校の学校があり、
1, 2, \ldots, N
の番号が付けられています。学校
i
には最初、
A_i
人の生徒が所属しています。もちろん学校である以上、同じ人が永遠に学校に所属し続けることはできません。生徒の人数は途中で変わることがあります。
Paken 王国では毎日のように王国主催の大会が開催されており、それぞれの大会では、招待する学校の候補を表す整数組
(l, r)
を定め、学校
l, l+1, \ldots, r
のうちから 1 校のみを選び、その学校の生徒を全員招待することになっています。
さて、大会では頭を使うため、糖分補給用に参加者にお菓子が配られます。しかし、このお菓子の個数には次のような条件があります。
人によってお菓子の個数が変わらないように、学校
l, l+1, \ldots, r
のどの学校に対しても、その学校の生徒の人数が用意するお菓子の個数の約数になるようにする。
Paken 王国にはあまりお金がないため、用意するお菓子の個数は、上の条件を満たす中で最小になるようにする。
あなたは Paken 王国で唯一のお菓子の会社の社長です。すべての大会のお菓子はあなたの会社に発注されます。あなたは会社の PR のため、どの学校が大会に招待される候補になっているのかを知りたくなりました。
そこで、それぞれの大会について、発注されたお菓子の個数から、その大会で定められた整数組
(l, r)
としてあり得るものの個数を求めることにしました。
Paken 王国で起こる出来事は
Q
個あり、それぞれの出来事は次のいずれかの形のクエリで表されます。
入学クエリ
1 k a
: 学校
k
に人が
a
人入学する。学校
k
に所属する生徒は
a
人増える。
卒業クエリ
2 k b
: 学校
k
から人が
b
人卒業する。学校
k
に所属する生徒は
b
人減る。
大会クエリ
3 s
: ある大会でお菓子が
s
個発注される。あなたは、その大会に招待される学校の候補を表す整数組
(l, r)
として考えられるものの個数を求める。
Q
個の出来事が順に起きたとき、それぞれの大会クエリに対する答えを求めて下さい。
なお、学校はあくまで学校であるので、どの学校も、その学校に所属する生徒の数は常に
1
以上
10^9
以下となることが保証されています。 | [
{
"input": "4 3\n1 2 3 4\n3 12\n1 1 3\n3 12\n",
"output": "3\n4\n"
},
{
"input": "10 5\n10 1 8 3 10 10 6 3 3 7\n3 30\n3 7\n3 4\n3 10\n3 1\n",
"output": "11\n1\n0\n5\n1\n"
},
{
"input": "20 20\n13 5 30 10 15 22 30 4 11 18 10 23 9 1 27 8 5 6 16 26\n3 60\n3 90\n2 19 11\n2 7 6\n2 5 6\n3 12870\n3 198\n1 12 3\n2 10 1\n3 30\n3 5\n2 18 5\n3 234\n3 291720\n1 10 6\n3 1776060\n3 198\n3 10\n3 792\n3 30\n",
"output": "1\n1\n1\n2\n7\n3\n2\n2\n1\n1\n2\n3\n4\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_f | 問題文
define 君は 4 月にオープンする遊園地「パ研ランド」の設計をしています。この遊園地は東西に細長いことが特徴で、その入口は遊園地の最も西にあります。以下、入口から東に
k
m 進んだ場所を地点
k
と呼ぶことにします。
この遊園地にはアトラクションが
N
基 あり、
1, 2, \dots, N
の番号が振られています。アトラクション
i
は地点
i
にあります。
define 君はパ研ランドのオープン日にぺんぎん君を招待しています。ぺんぎん君は
1
m 進むのに
1
秒掛かります。ぺんぎん君は
M
回に渡ってアトラクションに乗る計画を立てており、
i
番目に乗るのはアトラクション
A_i
と決めています。
この計画では、地点
A_i
から地点
A_{i+1}
への移動に掛かる最短時間を
T_i
秒として、移動に
\sum_{i=1}^{M-1}{T_i}
秒掛かります。
さて、オープン直前になって define 君は「アトラクションが一列に並んでいると移動しにくいのでは?」と思い始めました。このままでは、ぺんぎん君が途中で移動が嫌になって帰ってしまうかもしれません。
そこで、時間もないので
1
本だけワープ路を造る事にしました。地点を
2
つ選んでワープ路を造ると、その
2
地点間を双方向に
1
秒で移動する事ができます。
Q
個のクエリが与えられます。
i
番目のクエリは「地点
S_i
と地点
T_i
を結ぶワープ路を造った時にぺんぎん君の計画に掛かる移動時間は何秒か」というものです。それぞれのクエリに答えてください。 | [
{
"input": "5 6\n3 5 2 1 5 3\n2\n1 3\n2 5\n",
"output": "11\n8\n"
},
{
"input": "10 10\n3 1 4 1 2 9 3 2 7 10 \n10\n1 7\n1 4\n3 8\n6 9\n3 4\n1 8\n7 10\n4 10\n3 5\n6 9\n",
"output": "24\n27\n21\n27\n31\n23\n29\n25\n28\n27\n"
},
{
"input": "100 20\n6 97 94 50 96 51 94 86 92 77 9 73 21 9 46 42 76 77 49 17 \n20\n38 87\n20 60\n5 56\n8 82\n69 80\n13 42\n90 99\n97 98\n96 97\n95 97\n61 88\n48 61\n11 73\n42 81\n8 18\n78 83\n17 54\n41 68\n2 69\n72 100\n",
"output": "401\n451\n449\n417\n573\n489\n625\n633\n633\n631\n493\n535\n401\n393\n596\n609\n451\n467\n437\n543\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_g | 問題文
パ研王国は
1
から
N
までの番号が付けられた
N
個の都市と、
1
から
M
までの番号が付けられた
M
本の道路からなります。各
i\ (1 \leq i \leq M)
について、辺
i
は都市
u_i
と都市
v_i
を双方向に結んでいます。
ペンギンくんは今、パ研王国の中を旅行する計画を立てています。彼はその計画を立てるにあたって、以下の情報を知りたがっています。
1 \leq l \leq r \leq M
を満たす整数対
(l,r)
であって、以下の条件を満たすものはいくつあるか。
ある都市
X
を出発し、道路
l
、道路
l+1
、
\cdots
、道路
r
を
好きな順番でちょうど一度ずつ
通って
都市
X
に戻る
ような経路が存在する。
この値を求めることは、ペンギンくんには難しすぎました。そのため、彼の代わりに答えを求めてあげてください。
(16:30 補足:)
経路において道路
l
、道路
l+1
、
\cdots
、道路
r
以外の道路を通ることはできません。
経路の途中で都市
X
を経由することは可能です。 | [
{
"input": "4 4\n1 2\n2 3\n3 4\n2 4\n",
"output": "1\n"
},
{
"input": "5 8\n2 3\n3 1\n2 3\n3 2\n2 5\n3 2\n1 5\n2 1\n",
"output": "3\n"
},
{
"input": "6 10\n2 6\n6 1\n1 2\n2 6\n6 4\n4 3\n3 2\n2 5\n5 3\n3 5\n",
"output": "6\n"
},
{
"input": "8 12\n7 1\n7 1\n3 7\n3 7\n6 3\n6 3\n5 7\n5 7\n6 8\n6 8\n5 8\n5 8\n",
"output": "18\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day3/tasks/pakencamp_2021_day3_h | 問題文
パ研王国は
1
から
N
までの番号が振られた
N
個の都市と、それらの都市間を結ぶ
M
本の道路からなります。
i
本目の道路は、都市
u_i
と都市
v_i
を双方向に結んでおり、その長さは
l_i
メートルです。
あなたの属するペンギン株式会社は、パ研王国内において貨物の輸送を行うという仕事を
K
個受注しました。
i
番目の仕事(仕事
i
とする)では、都市
s_i
にある貨物を都市
g_i
に移動させる必要があり、仕事に成功した場合
m_i
円の利益が生まれます。
ただしこの
K
個の仕事には時間制限があり、ある時刻
T
までに仕事を行うことができなかった場合得られる利益は
0
円になります。
あなたは、ペンギン株式会社の利益のため、以下のような輸送計画を立てることにしました。
まずはじめに、行う仕事の集合を決める。
その後、行う仕事それぞれについて(仕事
x
とする)、経由する都市の列
(a_0=s_x, a_1, \ldots, a_k=g_x)
、および仕事を開始する時刻
t
を決める。
t
は整数である必要があり、また、このとき
1 \leq i \leq k
について都市
a_{i-1}
と都市
a_i
は直接道路で結ばれている必要がある。
時刻
0
以降、2. までで決めた内容をもとに実際に仕事を行う。行う仕事それぞれについて、時刻
t
に輸送する貨物を会社の車に乗せた状態から仕事を開始する。その後はその仕事が完了するまでの間、分速
1
メートルの速さで今いる地点から次に経由する都市に向けて移動し続ける。途中で車が止まることはない。
パ研王国の道路は非常に狭いため、同じ時刻に同じ道路内の同じ地点(道路の両端を除く)に複数の車が存在することは許されません。
得られる利益の合計をできるだけ大きくしてください。 | [
{
"input": "4 5 3 10\n1 3 4\n2 4 3\n1 4 4\n2 3 2\n3 4 2\n2 4 7\n3 1 8\n2 4 3\n",
"output": "2\n2 0 1\n3 1 \n3 7 1\n2 4\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_b | 問題文
パケンくんは、パソコン力を高めたいです。
ある日、パケンくんは問題を解くことでパソコン力を得られることに気づきました。
具体的には、難易度
x
の問題を解くと、
x^2 \times b
のパソコン力が得られます。
2
整数
a,b
が与えられるので、パケンくんが難易度
a
の問題を解いたときにいくつのパソコン力が得られるかを求め、出力してください。 | [
{
"input": "3 4\n",
"output": "36\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_c | 問題文
パ研くんは
2
日間にわたってプログラミングコンテストを開催しました。
1
日目のコンテストには
N
人が参加し、
2
日目のコンテストには
M
人が参加しました。
コンテストの参加者にはそれぞれ ID と呼ばれる整数が割り当てられていました。
1
日目の参加者の ID は順に
A_1, A_2, \ldots, A_N
で、
2
日目の参加者の ID は順に
B_1, B_2, \ldots, B_M
でした。異なる人に同じ ID が割り当てられたことはありません。
パ研くんは次の条件を満たす人の ID の一覧を欲しがっています。
1
日目のコンテストには参加しなかったが、
2
日目のコンテストには参加した。
パ研くんのかわりに条件を満たす人の ID を列挙してください。 | [
{
"input": "3 4\n1 3 4\n6 8 3 1\n",
"output": "2\n6\n8\n"
},
{
"input": "4 3\n8 4 2 1\n1 4 2\n",
"output": "0\n"
},
{
"input": "3 2\n1234 312 999\n888 519\n",
"output": "2\n519\n888\n"
},
{
"input": "10 8\n14 9 3 8 11 18 20 12 16 17\n6 4 5 18 11 14 19 20\n",
"output": "4\n4\n5\n6\n19\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_d | 問題文
筑駒 72 期 高校 1 年 3 学期の漢文の期末試験では、表紙に「選択問題の正答はすべて同じ選択肢で統一しています。この注意事項に気づいても試験終了までは声に出さずに秘密裡にすること。」という注意書きがなされていました。
仮にこの試験が
N
問の選択問題のみからなり、各問題は
1
から
M
までの選択肢から
1
つを選ばせるような出題形式になっていたとしましょう。
この注意書きに気づかなかったペンギンくんは、各
i\ (1 \leq i \leq N)
について
i
問目の答えを
A_i
と書いてしまいました。
ペンギンくんの正答数として考えられる値の最小値および最大値は、それぞれいくらになりますか? | [
{
"input": "3 2\n1 1 2\n",
"output": "1 2\n"
},
{
"input": "4 5\n5 1 1 5\n",
"output": "0 2\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_e | 問題文
正整数
N,M
が与えられます。すべての要素が
1
以上
M
以下である長さ
N
の正整数列
a
であって、以下の条件を満たすものの個数を
998244353
で割った余りを求めてください。
a
の長さ
2
以上の連続部分列であって、回文であるようなものが存在しない。 | [
{
"input": "2 2\n",
"output": "2\n"
},
{
"input": "3 3\n",
"output": "6\n"
},
{
"input": "314 159\n",
"output": "809839613\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_f | 問題文
正整数
N
が与えられます。
\dfrac{a}{b} < \dfrac{c}{d} < \dfrac{e}{f}
を満たす整数の組
(a,b,c,d,e,f)\ (1 \le a,b,c,d,e,f \le N)
のうち、
\dfrac{e}{f}-\dfrac{a}{b}
が最小になるものを一つ構築してください。
この問題の制約下で、
\dfrac{a}{b} < \dfrac{c}{d} < \dfrac{e}{f}
を満たす整数の組
(a,b,c,d,e,f)
は必ず存在します。 | [
{
"input": "2\n",
"output": "1 2 1 1 2 1\n"
},
{
"input": "3\n",
"output": "1 3 1 2 2 3\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_g | 問題文
パ研部長のぺんぎんくんは、パ研の部室を増やしたいと思いました。
ぺんぎんくんのいる学校には
N
個の部屋があり、部屋
1
から部屋
N
までの番号が付けられています。
また、
M
本の廊下があり、
i
番目の廊下は部屋
U_i
と部屋
V_i
を双方向に結んでいます。これらの廊下を使って移動することで、どの部屋からどの部屋にも行くことができます。
現在、パ研の部室は部屋
1
のみです。ぺんぎんくんは今日を
1
日目として、
1
日
1
回以下の操作を行うことで、
N-1
日目に全ての部屋がパ研の部室となっているようにします。
現時点でパ研の部室である部屋のいずれかと直接廊下で結ばれていてかつ現時点ではパ研の部室ではない部屋を
1
つ選び、新しくパ研の部室とする。
i
日目に部屋
j
を新しくパ研の部室にしたとき、ぺんぎんくんの
嬉しさ
は
A_{i,j}
上昇します。はじめ、ぺんぎんくんの嬉しさは
0
です。
N-1
日目の操作が終わった時点でのぺんぎんくんの嬉しさとして考えられる値の最大値を求め、出力してください。 | [
{
"input": "3 3\n1 2\n1 3\n2 3\n0 2 3\n0 4 3\n",
"output": "7\n"
},
{
"input": "4 5\n1 3\n2 3\n3 4\n2 4\n1 4\n0 1 2 3\n0 31 41 59\n0 1 6 82\n",
"output": "115\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_h | 問題文
プラプライムくんは、以下の条件をすべて満たす整数
N
が存在するか気になっています。
1 \leq N \leq 10^{18}
N
は与えられる
M
個の情報に矛盾しない。
i
個目の情報は素数
P_i
と正整数
S_i
の組
(P_i,S_i)
からなり、
N!
は
P_i^{S_i}
で割り切れるが、
P_i^{S_i+1}
で割り切れないことを表す。
プラプライムくんのために条件を満たす
N
を
1
つ見つけてあげるか、あるいはそのような
N
が存在しないことを教えてあげてください。 | [
{
"input": "2\n2 3\n5 1\n",
"output": "5\n"
},
{
"input": "3\n2 4\n5 1\n3 5\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_i | 問題文
長さ
N-1
の正整数
A=(A_2,A_3,\ldots,A_N),B=(B_2,B_3,\ldots,B_N)
が与えられます。(添字が
2
から始まることに注意してください)
数列
A
に対して以下の操作を
10^6
回以下行って
A=B
にする方法があるか判定し、あるならば
1
つ構築してください。
整数
i\ (2 \le i)
とその倍数
j
を選び、
A_i
の値と
A_j
の値を交換する。なお、このとき
i=j
であってもよい。 | [
{
"input": "4\n3 2 4\n4 2 3\n",
"output": "1\n2 4\n"
},
{
"input": "2\n3\n4\n",
"output": "-1\n"
},
{
"input": "6\n4 1 3 2 5\n1 5 4 2 3\n",
"output": "3\n3 6\n2 4\n2 6\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_j | 問題文
正整数
N,M
と長さ
N
の整数列
T=(T_1,T_2,\ldots,T_N),A=(A_1,A_2,\ldots,A_N)
が与えられます。
すべての要素が
1
以上
M
以下である長さ
N+1
の正整数列
b=(b_1,b_2,\ldots,b_{N+1})
であって、すべての
i\ (1 \le i \le N)
について以下の条件を満たすものの個数を
998244353
で割った余りを求めてください。
T_i=0
のとき、
\min(b_i,b_{i+1})=A_i
T_i=1
のとき、
\max(b_i,b_{i+1})=A_i | [
{
"input": "2 2\n0 0\n1 2\n",
"output": "1\n"
},
{
"input": "2 4\n0 1\n1 2\n",
"output": "6\n"
},
{
"input": "15 509\n1 0 1 1 1 1 0 1 1 1 1 1 1 0 0\n367 241 241 160 160 156 156 459 395 288 288 408 505 270 270\n",
"output": "684062245\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_k | 問題文
かめ君は、文字列で遊ぶのが好きです。今日は、空文字列
s
を用意し、以下の操作を
N
回行いました。
s
を文字列
l,r
に分割する。
s
を
l\ +
()
+\ r
に置き換える。
N
回の操作後の
s
の値が
T
として与えられるので、 操作の方法として考えられるものの個数を
998244353
で割った余りを求めてください。
ただし、ある正整数
k\ (1 \le k \le N)
が存在して
k
回目の操作における
(l,r)
の組
が異なるとき、またその時に限り
2
つの操作の方法を異なるとみなします。
また、かめ君は嘘をつかないので、必ず
s=T
となる操作の方法が
1
つは存在するような
T
のみが与えられます。 | [
{
"input": "3\n(())()\n",
"output": "3\n"
},
{
"input": "1\n()\n",
"output": "1\n"
},
{
"input": "7\n(()(()(())()))\n",
"output": "72\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_l | 問題文
N
頂点
M
辺の単純連結重み付き無向グラフが与えられます。頂点には
1
から
N
までの番号が、辺には
1
から
M
までの番号が振られています。辺
i
は頂点
U_i
と頂点
V_i
を結び、重みは
W_i
です。辺の重みは全て互いに異なることが保証されます。
頂点
1
から頂点
N
への、頂点の重複を許した道を考えます。通った辺の重みを順に並べた数列を
C = (C_1, C_2, \ldots, C_k)
として、次の条件を満たす道を
ジグザグ道
と定義します。
C_1 < C_2 > C_3 < \cdots
または
C_1 > C_2 < C_3 > \cdots
である。つまり、次の条件のいずれかを満たす。
任意の整数
i \, (1 \leq i \leq k - 1)
について、
i
が奇数ならば
C_i < C_{i+1}
であり、
i
が偶数ならば
C_i > C_{i+1}
である。
任意の整数
i \, (1 \leq i \leq k - 1)
について、
i
が奇数ならば
C_i > C_{i+1}
であり、
i
が偶数ならば
C_i < C_{i+1}
である。
ジグザグ道
は存在するでしょうか?存在するならば、通る辺の重みの総和の最小値も求めてください。 | [
{
"input": "5 5\n1 4 4\n3 5 2\n2 3 6\n2 5 1\n3 4 3\n",
"output": "14\n"
},
{
"input": "4 3\n1 2 4\n2 3 6\n3 4 8\n",
"output": "-1\n"
},
{
"input": "7 12\n2 5 657831697\n5 6 925940778\n1 2 749029915\n2 4 237755672\n3 6 60634766\n6 7 65418621\n1 4 194639839\n4 7 411656898\n3 7 367905753\n3 4 241675120\n1 6 858592389\n2 6 571202751\n",
"output": "562368346\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_m | 問題文
正の整数
N
が与えられます。Natsubi くんは、空の数列
Q
を用意したうえで、
(1,2,\dots,N)
を並び替えた数列
P=(P_1, P_2, \dots, P_N)
を自由に選んで、以下の一連の操作を
N
回行います。
P
の先頭の要素を
x
として、
Q
の先頭または末尾に
x
を追加する。
P
から
x
を削除する。
Natsubi くんは、最終的な
Q
の転倒数が最小となるように適切に操作を行います。
P
として考えられるものは
N!
通りありますが、それらすべてについて操作後の
Q
の転倒数の最小値を求め、その総和を
998244353
で割ったあまりを出力してください。
転倒数とは?
(1,2,\dots,N)
を並び替えた数列
P'=(P'_1, P'_2, \dots, P'_N)
に対する転倒数は、
1 \leq i < j \leq N
なる整数
i,j
の組であって、
P'_i > P'_j
を満たすものの個数のことを指します。 | [
{
"input": "4\n",
"output": "20\n"
},
{
"input": "220328\n",
"output": "192799865\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_n | 問題文
T
個のケースについて、以下の問題を解いてください。
整数
k
と
N
次の整数係数多項式
f(x)=a_Nx^N+a_{N-1}x^{N-1}+\ldots+a_0
、
M
次の整数係数多項式
g(x)=b_Mx^M+b_{M-1}x^{M-1}+\ldots+b_0
が与えられます。
f(k)
と
g(k)
の大小関係を求めてください。 | [
{
"input": "3\n2 1 3\n2 0 1\n4 5\n0 0 0\n2\n2\n5 7 -89401\n-79604 56304 -25588 -4414 73961 28352\n-6628 -12831 6978 373 -36054 82166 30928 50750\n",
"output": ">\n=\n<\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_o | 問題文
文字列
S
が与えられます。
S[i:j]
で
S
の
i
文字目から
j
文字目までを取り出した文字列を表すことにします。
文字列
T
が次の条件を全て満たすとき、
T
は
良い文字列
であると定義します。
1 \leq |T| \leq |S|
S[i:i+|T|-1] = T
を満たす整数
i
はちょうど
1
つだけ存在する
例えば
S
が
abcbabc
のとき、
cb
や
abcb
、
abcbabc
は
良い文字列
ですが、
abc
や
zyx
は
良い文字列
ではありません。
Q
個のクエリが与えられるので処理してください。
i
番目のクエリでは
1 \leq L_i \leq R_i \leq |S|
を満たす整数
L_i, R_i
が与えられるので、次の問題の答えを出力してください。
2
つの整数
l, r
であって、
1 \leq l \leq L_i
と
R_i \leq r \leq |S|
を満たし、かつ
S[l:r]
が
良い文字列
であるようなものを考える。
r-l+1
の最小値はいくつか? | [
{
"input": "abcbabc\n5\n2 3\n2 5\n1 7\n4 4\n6 6\n",
"output": "3\n4\n7\n2\n3\n"
},
{
"input": "yyxxzzyyxx\n5\n3 3\n1 1\n10 10\n5 5\n7 7\n",
"output": "3\n5\n5\n2\n2\n"
},
{
"input": "qprrrrrpprqrrppq\n20\n7 8\n6 8\n4 7\n7 12\n6 7\n5 5\n6 8\n4 6\n4 4\n2 3\n7 11\n8 9\n6 7\n11 12\n11 15\n5 6\n4 5\n13 13\n9 13\n5 7\n",
"output": "4\n4\n5\n6\n4\n4\n4\n5\n3\n3\n5\n3\n4\n2\n5\n4\n4\n3\n5\n4\n"
}
] |
https://atcoder.jp/contests/pakencamp-2021-day2/tasks/pakencamp_2021_day2_p | 問題文
T
個のケースについて、以下の問題を解いてください。
正整数
A,M
が与えられます。
A^k \equiv k \pmod M
を満たす非負整数
k\ (k < M \times \varphi (M))
の個数を求め(
ans
とします)、条件を満たす
k
を
\min(ans,1000)
個構築してください。
ただし、
\varphi(M)
は
オイラーのファイ関数
を表します。 | [
{
"input": "1\n2 4\n",
"output": "1\n4\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_a | 問題文
4
種類の文字
U
,
T
,
P
,
C
からなる長さ
N
の文字列
S
が与えられます。
あなたは、次の操作を好きな回数行うことが出来ます。
整数
i, j \, (1 \leq i < j \leq N)
を選ぶ。
S
の
i
番目の文字と
j
番目の文字を入れ替える。
文字列
S
が以下の条件を満たすようにするために必要な操作回数の最小値を求めてください。
S
は連続部分文字列として
UTPC
を含む。
ただし、
S
は
U
,
T
,
P
,
C
をそれぞれ
1
つ以上含むことが保証されます。 | [
{
"input": "5\nUTCUP\n",
"output": "2\n"
},
{
"input": "4\nUTPC\n",
"output": "0\n"
},
{
"input": "20\nPTPUTPTUCPTUPTUPCTPC\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_b | 問題文
長さ
N
の数列
A =(A_1,A_2,\ldots,A_N), B=(B_1,B_2,\ldots,B_N)
が与えられます。
あなたは次の操作を
0
回以上好きな回数行うことができます。
整数
i\ (1 \le i \le N)
を選ぶ。
A_i
と
B_i
を入れ替える。
数列のスコアを
\displaystyle\sum_{i=1}^N \sum_{j=1}^N \mathrm{min} (A_i,B_j)
で定めます。
あなたの目標は操作後の数列のスコアを最大化することです。
スコアの最大値を達成するような操作後の数列を一つ出力してください。
そのような数列が複数存在する場合、どれを出力しても構いません。
T
個のテストケースが与えられるので、それぞれについて答えを求めてください。 | [
{
"input": "2\n3\n1 2 3 \n4 5 6\n2\n1 2\n2 1\n",
"output": "4 2 6\n1 5 3\n1 2\n2 1\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_c | 問題文
赤いボールと青いボールがそれぞれ
N
個あります。
i
個目の赤いボールには整数
A_i
が、
i
個目の青いボールには整数
B_i
が書かれています。
あなたは次の操作を
0
回以上
N
回以下の好きな回数行えます。
赤いボールと青いボールを
1
個ずつ選び、食べる。
i
回目の操作では、食べたボールに書かれていた整数がそれぞれ
X, Y
であるとして、
XY + C_i
点を得る。
獲得可能な合計点数の最大値を求めてください。 | [
{
"input": "4\n6 -2 3 8\n-1 -1 7 -8\n3 2 5 4\n",
"output": "79\n"
},
{
"input": "10\n-809372 563575 -351229 -20556 -309920 85426 -952799 739479 -66554 -296504\n735902 631932 -407775 895728 302156 -968417 -963982 -894325 -804784 78537\n282707723857 731189330739 1910286918 339802329211 611404539679 296303238506 337317063340 503492686568 1614407806 11314313\n",
"output": "6622583878238\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_d | 問題文
以下の性質を持つ有向グラフを
Chain Graph
と呼ぶことにします。
相異なる頂点
i, j, k
について、
i \rightarrow j
と
j \rightarrow k
の辺があるとき、
i \rightarrow k
の辺も存在する。
無向グラフとしてみたときに、自己ループや多重辺が存在しない。
無向辺からなる
N
頂点の完全グラフが与えられます。頂点には
1
から
N
の番号がついています。はじめ、
N-1
本の辺が赤で塗られており、木をなしています。
i
番目の赤色の辺は
A_i
と
B_i
を結ぶ辺です。残りの辺は白色です。
あなたは、以下の操作を順番に行い、グラフの辺の色と向きを定めます。
全ての白色の辺をそれぞれ赤色、または青色に塗る。
全ての赤色の辺、青色の辺それぞれに向きをつける。
赤色、青色それぞれの辺のみからなるグラフが
Chain Graph
となるような操作後のグラフとしてありえるものの数を
998244353
で割ったあまりを求めてください。 | [
{
"input": "3\n1 2\n2 3\n",
"output": "10\n"
},
{
"input": "5\n1 2\n1 3\n2 4\n5 2\n",
"output": "1304\n"
},
{
"input": "10\n1 2\n1 3\n4 2\n2 5\n3 6\n6 7\n8 7\n9 5\n5 10\n",
"output": "793075136\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_e | 問題文
座標平面上に
N
個の点があります。
i
個目の点は、座標
(x_i, y_i)
に位置しており、その価値は
c_i
です。
あなたの仕事は、
N
個の点からちょうど
K
個の点を選ぶことです。その後、以下のように変数を定めます。
X_{\max}
\coloneqq
選んだ点の
x
座標の最大値
X_{\min}
\coloneqq
選んだ点の
x
座標の最小値
Y_{\max}
\coloneqq
選んだ点の
y
座標の最大値
Y_{\min}
\coloneqq
選んだ点の
y
座標の最小値
S
\coloneqq
選んだ点の価値の総和
点を選び終えた後、あなたは報酬として
(X_{\max} - X_{\min}) + (Y_{\max} - Y_{\min}) + S
円を獲得することができます。最大で何円の報酬を獲得可能か求めてください。 | [
{
"input": "3 2\n1 3 1\n3 1 1\n3 3 2\n",
"output": "6\n"
},
{
"input": "12 5\n79 29 4\n47 96 11\n31 100 13\n89 67 13\n28 45 9\n66 70 12\n18 12 9\n21 57 14\n67 17 6\n91 12 9\n79 11 8\n67 50 6\n",
"output": "220\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_f | 問題文
あなたは、魔物の群れに遭遇しました。魔物の群れは
N
匹の魔物で構成されており、あなたの目の前に縦一列に並んでいます。前から
i
番目の魔物の体力は
h_i
です。
あなたは、以下の
2
種類の攻撃を使い分けることによって、全ての魔物を倒すことにしました。
剣で攻撃する。一番前の生き残っている魔物に、その魔物の残りの体力と同じ分のダメージを与える。
槍で攻撃する。全ての生き残っている魔物に、
1
ダメージずつ与える。
体力が
0
となった魔物は消滅します。
あなたには、直属の上官が
2
人居ます。攻撃を行うたびに、その
1
回の攻撃で与えたダメージ量に応じて上官からボーナスとして勲章が与えられます。
1
人目の上官からは、魔物に与えたダメージの合計が
k_1
以上であれば、赤い勲章が
1
つ与えられます。
2
人目の上官からは、魔物に与えたダメージの合計が
k_2
以上であれば、青い勲章が
1
つ与えられます。
全ての魔物を消滅させたとき、持っている赤い勲章と青い勲章の合計個数としてあり得る最大値を求めてください。 | [
{
"input": "4 2 3\n3 2 1 1\n",
"output": "4\n"
},
{
"input": "5 4 5\n2 2 2 2 2\n",
"output": "4\n"
},
{
"input": "15 4 7\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n",
"output": "16\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_g | 問題文
あなたは
H
行
W
列の行列を持っています。行列の
i
行目、
j
列目の成分は
1
桁の正整数
S_{i, j}
です。
あなたは次の
2
種類の操作を好きな順序で、合計
H + W - 2
回行えます。
隣接する
2
行 (
i, i + 1
行目) を選び、
2
行の成分の総和の点数を得る。そして、
2
行を圧縮する。すなわち、(存在すれば)
i - 1
行目以前、
i
行目と
i + 1
行目の行ベクトルとしての和、(存在すれば)
i + 2
行目以降、をこの順に縦に連結したものに行列全体を置き換える。この操作は、行列が
2
行以上である場合に行える。
隣接する
2
列 (
j, j + 1
列目) を選び、
2
列の成分の総和の点数を得る。そして、
2
列を圧縮する。すなわち、(存在すれば)
j - 1
列目以前、
j
列目と
j + 1
列目の列ベクトルとしての和、(存在すれば)
j + 2
列目以降、をこの順に横に連結したものに行列全体を置き換える。この操作は、行列が
2
列以上である場合に行える。
獲得可能な合計点数の最大値を求めてください。 | [
{
"input": "3 3\n314\n159\n265\n",
"output": "130\n"
},
{
"input": "10 8\n82974679\n74744362\n34499984\n86891758\n56419363\n76176864\n78392791\n71539599\n44588446\n71227999\n",
"output": "4555\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_h | 問題文
数列内の隣接する二項の差の絶対値が全て
1
であるとき、その数列を
良い数列
と呼ぶことにします。
良い数列
X
のスコアを次のように定めます。
X_{i} - X_{i-1} = 1
となる全ての
i
について
X_i
をかけあわせた値
そのような
i
が存在しない場合は
1
長さが
N
、初項が
A
、 末項が
B
であるような
良い数列
全てに対するスコアの総和を
998244353
で割った余りを出力してください。 | [
{
"input": "3 0 2\n",
"output": "2\n"
},
{
"input": "5 0 2\n",
"output": "12\n"
},
{
"input": "1877 4 12\n",
"output": "672408519\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_i | 問題文
1
から
M
までの数が一つずつ書かれた
M
枚のカードからなる山札が
N
個あります。
i
個目の山札の上から
j
枚目には、
a_{i, j}
が書かれています。
あなたはこれらの山札に対して、以下の
2
種類の操作をそれぞれ好きな順に何度でも行うことができます。
操作
1
:山札を
1
つ選び、一番上のカードを、同じ山札の一番下に移動させる。
操作
2
:
N
個の山札の一番上のカードに書かれている数が全て同じなら、それらを全て取って食べる。
全てのカードを食べるために必要な操作
1
の回数の最小値はいくつですか? | [
{
"input": "4 3\n2 3 1\n1 2 3\n2 1 3\n3 2 1\n",
"output": "4\n"
},
{
"input": "7 6\n1 2 3 4 5 6\n3 5 6 1 4 2\n2 5 4 3 6 1\n5 1 2 4 6 3\n3 2 6 5 4 1\n4 1 2 5 3 6\n6 5 4 3 1 2\n",
"output": "35\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_j | 問題文
マコトくんは以下の問題を考えました。 | [
{
"input": "2\n",
"output": "8\n"
},
{
"input": "4\n",
"output": "4944\n"
},
{
"input": "2021\n",
"output": "383310824\n"
},
{
"input": "100000\n",
"output": "143469183\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_k | 問題文
P
を素数
998244353
とします。
多項式
f(x)
に対して次の一連の操作を定めます。
f(x)
と
(1 + x^k)g(x)
の各次数の係数を
P
で割った余りが等しくなるような正の整数
k
と有限次の多項式
g(x)\neq 0
を選択する。
その後、
f(x)
を上記の
g(x)
に置き換えて
2^k
のスコアを得る。
ある多項式に対して、この操作を好きな回数行って得られるスコアの総和の最大値を多項式の
美しさ
と定めます。
数列
A=(A_0,\ldots,A_{N - 1})
と
Q
個のクエリが与えられます。
i
番目のクエリでは整数
l_i,r_i
が与えられるので、多項式
\displaystyle f(x) = \sum_{j=0}^{r_i - l_i}A_{j + l_i}x^{j}
の
美しさ
を
P
で割った余りを求めてください。
ただし、操作における
g(x)
の係数は
998244353
未満の非負整数に限ります。(13:10 追記) | [
{
"input": "6 3\n1 2 1 1 1 1\n0 2\n2 5\n2 4\n",
"output": "4\n6\n0\n"
},
{
"input": "11 2\n1 1 0 0 0 0 0 0 0 1 1\n0 10\n4 5\n",
"output": "514\n0\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_l | 問題文
縦
H
行、横
W
列のグリッド状の迷路があります。
各マスには
S
,
G
,
#
,
.
のいずれかの文字が書かれています。
i
行目
j
列目のマスに書かれている文字は
c_{i,j}
です。
#
と書かれたマスは壁になっており、そうでないマスは壁ではありません。
また、
S
と
G
は
1
つずつで、上下左右に隣接していないことが保証されます。
迷路が次の条件を満たす時、
到達可能な状態
と呼ぶことにします。
S
と書かれたマスから、
G
と書かれたマスに、上下左右に隣接する壁でないマス (つまり
#
と書かれてないマス) のみを通って到達できる。
ただし、迷路の外に出るような移動はできない。
最初、迷路は
到達可能な状態
であることが保証されます。
Alice と Bob がこの迷路を使ってゲームをします。
Alice が先手で、交互に以下の操作を行います。
.
と書かれたマスを
1
つ選び、
#
と書かれたマスに変更する。
先に自分の操作終了時に、迷路が
到達可能な状態
でなくなったプレイヤーの勝利となります。
本問題の制約下で与えられる迷路では、必ず勝者が決定することが証明できます。
二人が最適に行動した場合、どちらが勝つか求めてください。
T
個のテストケースが与えられるので、それぞれについて答えを求めてください。 | [
{
"input": "2\n2 2\nS.\n.G\n2 3\n#G#\nS.#\n",
"output": "Bob\nAlice\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_m | 問題文
あなたの前に鍵のかかった扉が一つあります。鍵屋さんは
N
個の鍵を所有しており、その中にちょうど一つだけ正しい鍵が存在します。
i
番目の鍵が正しい鍵である確率は
p_i
%であることが分かっています。
扉は建付けが悪く、正しい鍵を選んでも扉が開くとは限りません。
i
番目の鍵を用いて扉を開こうとした場合、扉が開く確率は以下の通りです。
i
番目の鍵が正しい鍵である場合:
q_i
% の確率で扉が開く。複数回開こうとした場合は独立に判定される。
i
番目の鍵が正しい鍵でない場合:扉は開かない 。
あなたは 最初
K
円持っています。
扉が開くか、所持金が
0
円になるまで、以下の操作を行います。
鍵屋さんに
1
円支払う。鍵屋さんから鍵を一つ選んで借りて、扉を一回開こうとする。
その後、鍵を返す。
あなたの目的は操作が終了した時点での残った所持金の期待値を最大化することです。
最適な方法で操作を行ったときの期待値の最大値を求めてください。 | [
{
"input": "2 2\n50 50\n50 50\n",
"output": "0.25\n"
},
{
"input": "1 2\n100\n100\n",
"output": "1\n"
},
{
"input": "10 20\n10 10 10 20 6 5 4 8 12 15\n10 20 30 40 50 60 70 80 90 10\n",
"output": "8.2045400000000000031\n"
}
] |
https://atcoder.jp/contests/utpc2021/tasks/utpc2021_n | 問題文
N
頂点の木の辺の列
E = \left(\left(X_1, Y_1\right), \ldots, \left(X_{N-1}, Y_{N-1}\right) \right)
から以下のような手順で生成される順列を
f(E)
とします。
順列
Q = (1, \ldots, N)
を準備する。
i = 1, \ldots, N - 1
の順に
Q
の
X_i
番目と
Y_i
番目の要素を入れ替える。
最終的な
Q
を
f(E)
とする。
\left(1, \ldots, N \right)
の順列
P
と
M
個の辺
(A_i, B_i)
が与えられます。
M
個の辺をすべて含み、木をなすような辺の列
E
であって、
f(E) = P
を満たすものがあるかを判定し、存在する場合は一つ出力してください。複数存在する場合はどれを出力しても構いません。
M
個の辺からなるグラフは自己ループや閉路を持たないことが保証されます。 | [
{
"input": "3 1\n2 3 1\n3 2\n",
"output": "Yes\n1 2\n2 3\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_a | Problem Statement
One day, Takahashi got up at exactly
B
minutes past
A
o'clock (in
24
-hour clock), and Aoki got up at exactly
D
minutes and
1
second past
C
o'clock.
If Takahashi got up earlier than Aoki, print
Takahashi
; otherwise, print
Aoki
. | [
{
"input": "7 0 6 30\n",
"output": "Aoki\n"
},
{
"input": "7 30 7 30\n",
"output": "Takahashi\n"
},
{
"input": "0 0 23 59\n",
"output": "Takahashi\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_b | Problem Statement
You are given a sequence of length
N
consisting of integers:
A=(A_1,\ldots,A_N)
.
Find the smallest non-negative integer not in
(A_1,\ldots,A_N)
. | [
{
"input": "8\n0 3 2 6 2 1 0 0\n",
"output": "4\n"
},
{
"input": "3\n2000 2000 2000\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_c | Problem Statement
You are given two sequences, each of length
N
, consisting of integers:
A=(A_1, \ldots, A_N)
and
B=(B_1, \ldots, B_N)
.
Determine whether there is a sequence of length
N
,
X=(X_1, \ldots, X_N)
, satisfying all of the conditions below.
X_i = A_i
or
X_i = B_i
, for every
i(1\leq i\leq N)
.
|X_i - X_{i+1}| \leq K
, for every
i(1\leq i\leq N-1)
. | [
{
"input": "5 4\n9 8 3 7 2\n1 6 2 9 5\n",
"output": "Yes\n"
},
{
"input": "4 90\n1 1 1 100\n1 2 3 100\n",
"output": "No\n"
},
{
"input": "4 1000000000\n1 1 1000000000 1000000000\n1 1000000000 1 1000000000\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_d | Problem Statement
We have a polynomial of degree
N
,
A(x)=A_Nx^N+A_{N-1}x^{N-1}+\cdots +A_1x+A_0
,
and another of degree
M
,
B(x)=B_Mx^M+B_{M-1}x^{M-1}+\cdots +B_1x+B_0
.
Here, each coefficient of
A(x)
and
B(x)
is an integer whose absolute value is at most
100
, and the leading coefficients are not
0
.
Also, let the product of them be
C(x)=A(x)B(x)=C_{N+M}x^{N+M}+C_{N+M-1}x^{N+M-1}+\cdots +C_1x+C_0
.
Given
A_0,A_1,\ldots, A_N
and
C_0,C_1,\ldots, C_{N+M}
, find
B_0,B_1,\ldots, B_M
.
Here, the given inputs guarantee that there is a unique sequence
B_0, B_1, \ldots, B_M
that satisfies the given conditions. | [
{
"input": "1 2\n2 1\n12 14 8 2\n",
"output": "6 4 2\n"
},
{
"input": "1 1\n100 1\n10000 0 -1\n",
"output": "100 -1\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_e | Problem Statement
Takahashi has
N
pieces of chocolate. The
i
-th piece has a rectangular shape with a width of
A_i
centimeters and a length of
B_i
centimeters.
He also has
M
boxes. The
i
-th box has a rectangular shape with a width of
C_i
centimeters and a length of
D_i
centimeters.
Determine whether it is possible to put the
N
pieces of chocolate in the boxes under the conditions below.
A box can contain at most one piece of chocolate.
A_i \leq C_j
and
B_i \leq D_j
must hold when putting the
i
-th piece of chocolate in the
j
-th box (they cannot be rotated). | [
{
"input": "2 3\n2 4\n3 2\n8 1 5\n2 10 5\n",
"output": "Yes\n"
},
{
"input": "2 2\n1 1\n2 2\n100 1\n100 1\n",
"output": "No\n"
},
{
"input": "1 1\n10\n100\n100\n10\n",
"output": "No\n"
},
{
"input": "1 1\n10\n100\n10\n100\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_f | Problem Statement
We have a simple directed graph
G
with
N
vertices and
M
edges. The vertices are labeled as Vertex
1
, Vertex
2
,
\ldots
, Vertex
N
.
The
i
-th edge
(1\leq i\leq M)
goes from Vertex
U_i
to Vertex
V_i
.
Takahashi will start at a vertex and repeatedly travel on
G
from one vertex to another along a directed edge.
How many vertices of
G
have the following condition: Takahashi can start at that vertex and continue traveling indefinitely by carefully choosing the path? | [
{
"input": "5 5\n1 2\n2 3\n3 4\n4 2\n4 5\n",
"output": "4\n"
},
{
"input": "3 2\n1 2\n2 1\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_g | Problem Statement
There are
N
people and
K
nations, labeled as Person
1
, Person
2
,
\ldots
, Person
N
and Nation
1
, Nation
2
,
\ldots
, Nation
K
, respectively.
Each person belongs to exactly one nation: Person
i
belongs to Nation
A_i
.
Additionally, there are
L
popular people among them: Person
B_1
, Person
B_2
,
\ldots
, Person
B_L
are popular.
Initially, no two of the
N
people are friends.
For
M
pairs of people, Takahashi, a God, can make them friends by paying a certain cost: for each
1\leq i\leq M
, he can pay the cost of
C_i
to make Person
U_i
and Person
V_i
friends.
Now, for each
1\leq i\leq N
, solve the following problem.
Can Takahashi make Person
i
an indirect friend of a popular person belonging to a nation different from that of Person
i
?
If he can do so, find the minimum total cost needed.
Here, Person
s
is said to be an indirect friend of Person
t
when there exists a non-negative integer
n
and a sequence of people
(u_0, u_1, \ldots, u_n)
such that
u_0=s
,
u_n=t
, and Person
u_i
and Person
u_{i+1}
are friends for each
0\leq i < n
. | [
{
"input": "4 4 2 2\n1 1 2 2\n2 3\n1 2 15\n2 3 30\n3 4 40\n1 4 10\n",
"output": "45 30 30 25\n"
},
{
"input": "3 1 3 1\n1 2 3\n1\n1 2 1000000000\n",
"output": "-1 1000000000 -1\n"
}
] |
https://atcoder.jp/contests/abc245/tasks/abc245_h | Problem Statement
Among the sequences of length
K
consisting of integers,
A=(A_1, \ldots, A_K)
, how many satisfy all of the conditions below?
Find the count modulo
998244353
.
0\leq A_i \leq M-1
for every
i(1\leq i\leq K)
.
\displaystyle\prod_{i=1}^{K} A_i \equiv N \pmod M
. | [
{
"input": "2 3 6\n",
"output": "5\n"
},
{
"input": "10 0 2\n",
"output": "1023\n"
},
{
"input": "1000000000 20220326 1000000000000\n",
"output": "561382653\n"
}
] |
https://atcoder.jp/contests/ahc009/tasks/ahc009_a | Problem Statement
You are given a map consisting of
20\times 20
squares.
The outside of the map is surrounded by walls.
There may also be walls between adjacent squares.
Let
(0,0)
denote the top-left square, and
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
Takahashi's home is located at
(s_i, s_j)
and AtCoder's office is located at
(t_i, t_j)
.
By representing up, down, left, and right movements as
U
,
D
,
L
, and
R
, respectively, output a commuting route from the home to the office as a string of length less than or equal to
200
.
Let
L
be the length of the output string.
Starting from the home, Takahashi will do the following action in each
t=1,\cdots,L
turn.
With constant probability
p
, he cannot recall the
t
-th character and stays in the current square.
With the remaining probability
1-p
, he moves one square in the direction represented by the
t
-th character. If there is a wall in that direction, he stays in the current square.
When he gets to the office, he immediately terminate the move. | [
{
"input": "1 2 19 16 0.10\n0010000100110011100\n1000001000001000001\n0000000000000000010\n0100000000000110100\n0000000000000000100\n1000101100000101010\n0010001011000110000\n0000001001000000000\n0000000100010001001\n0010010000100000001\n0001000010000100000\n0011010000000001000\n0000000101010100000\n0000001000000100010\n0110100010000000000\n0010011101000101000\n0000100110010000000\n0010000101101000010\n1001000000000000000\n1000110000000000000\n00000001000000000100\n00001000010001000000\n00010001010000010000\n01110010101000010100\n00000000000001100000\n00001000010000000100\n00101000000010110011\n01010100000000000000\n00001101010010010010\n10000000000000010100\n01011010000001100100\n00000000000000010011\n00001100111000110100\n00000010000000000000\n00010000100111000000\n11010000001001010100\n01100010011001011001\n00000101000010101010\n00100000000000000001\n",
"output": "RDLRLRRDUUDRLURDRRDDLRLRUURUUUUDRDRUUDLRUDLLDDDDURLRUDDLDRDLRLLLLUDRUDRRULRULRDLRLDLLUUULDLUURRLRDRRRRDULDRLRRRRDDDDDRULDDURDDDRDLRRLDLDLDLRLLLUDDRDDDUURUDDLLLUULLLLDLUDRLLDLLULRLDLDDRLDRDLURURULRDDDR\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_a | Problem Statement
Given a string
S
of length
N
consisting of lowercase English alphabets, print the last character of
S
. | [
{
"input": "5\nabcde\n",
"output": "e\n"
},
{
"input": "1\na\n",
"output": "a\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_b | Problem Statement
Consider an
xy
-plane. The positive direction of the
x
-axis is in the direction of east, and the positive direction of the
y
-axis is in the direction of north.
Takahashi is initially at point
(x, y) = (0, 0)
and facing east (in the positive direction of the
x
-axis).
You are given a string
T = t_1t_2\ldots t_N
of length
N
consisting of
S
and
R
.
Takahashi will do the following move for each
i = 1, 2, \ldots, N
in this order.
If
t_i =
S
, Takahashi advances in the current direction by distance
1
.
If
t_i =
R
, Takahashi turns
90
degrees clockwise without changing his position. As a result, Takahashi's direction changes as follows.
If he is facing east (in the positive direction of the
x
-axis) before he turns, he will face south (in the negative direction of the
y
-axis) after he turns.
If he is facing south (in the negative direction of the
y
-axis) before he turns, he will face west (in the negative direction of the
x
-axis) after he turns.
If he is facing west (in the negative direction of the
x
-axis) before he turns, he will face north (in the positive direction of the
y
-axis) after he turns.
If he is facing north (in the positive direction of the
y
-axis) before he turns, he will face east (in the positive direction of the
x
-axis) after he turns.
Print the coordinates Takahashi is at after all the steps above have been done. | [
{
"input": "4\nSSRS\n",
"output": "2 -1\n"
},
{
"input": "20\nSRSRSSRSSSRSRRRRRSRR\n",
"output": "0 1\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_c | Problem Statement
Takahashi and Aoki will play the following game against each other.
Starting from Takahashi, the two alternatingly declare an integer between
1
and
2N+1
(inclusive) until the game ends.
Any integer declared by either player cannot be declared by either player again.
The player who is no longer able to declare an integer loses; the player who didn't lose wins.
In this game, Takahashi will always win.
Your task is to actually play the game on behalf of Takahashi and win the game. | [] |
https://atcoder.jp/contests/abc244/tasks/abc244_d | Problem Statement
There are three Takahashis numbered
1
,
2
and
3
, and three hats colored red, green, and blue. Each Takahashi is wearing one hat. The color of the hat that Takahashi
i
is currently wearing is represented by a character
S_i
. Here,
R
corresponds to red,
G
to green, and
B
to blue. Now, they will do the following operation
exactly
10^{18}
times.
Operation
Choose two out of the three Takahashis. The two exchange the hats they are wearing.
Is it possible to make Takahashi
i
wearing the hat of color corresponding to character
T_i
after the
10^{18}
repetitions? | [
{
"input": "R G B\nR G B\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_e | Problem Statement
You are given a simple undirected graph with
N
vertices and
M
edges. The vertices are numbered from
1
through
N
, and the edges are numbered from
1
through
M
. Edge
i
connects Vertex
U_i
and Vertex
V_i
.
You are given integers
K, S, T
, and
X
. How many sequences
A = (A_0, A_1, \dots, A_K)
are there satisfying the following conditions?
A_i
is an integer between
1
and
N
(inclusive).
A_0 = S
A_K = T
There is an edge that directly connects Vertex
A_i
and Vertex
A_{i+1}
.
Integer
X\ (X≠S,X≠T)
appears even number of times (possibly zero) in sequence
A
.
Since the answer can be very large, find the answer modulo
998244353
. | [
{
"input": "4 4 4 1 3 2\n1 2\n2 3\n3 4\n1 4\n",
"output": "4\n"
},
{
"input": "6 5 10 1 2 3\n2 3\n2 4\n4 6\n3 6\n1 5\n",
"output": "0\n"
},
{
"input": "10 15 20 4 4 6\n2 6\n2 7\n5 7\n4 5\n2 4\n3 7\n1 7\n1 4\n2 9\n5 10\n1 3\n7 8\n7 9\n1 6\n1 2\n",
"output": "952504739\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_f | Problem Statement
You are given a simple connected undirected graph with
N
vertices and
M
edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)
For
i = 1, 2, \ldots, M
, the
i
-th edge connects Vertex
u_i
and Vertex
v_i
.
A sequence
(A_1, A_2, \ldots, A_k)
is said to be a
path
of length
k
if both of the following two conditions are satisfied:
For all
i = 1, 2, \dots, k
, it holds that
1 \leq A_i \leq N
.
For all
i = 1, 2, \ldots, k-1
, Vertex
A_i
and Vertex
A_{i+1}
are directly connected by an edge.
An empty sequence is regarded as a path of length
0
.
Let
S = s_1s_2\ldots s_N
be a string of length
N
consisting of
0
and
1
.
A path
A = (A_1, A_2, \ldots, A_k)
is said to be a
good path
with respect to
S
if the following conditions are satisfied:
For all
i = 1, 2, \ldots, N
, it holds that:
if
s_i = 0
, then
A
has even number of
i
's.
if
s_i = 1
, then
A
has odd number of
i
's.
There are
2^N
possible
S
(in other words, there are
2^N
strings of length
N
consisting of
0
and
1
). Find the sum of "the length of the shortest good path with respect to
S
" over all those
S
.
Under the Constraints of this problem, it can be proved that, for any string
S
of length
N
consisting of
0
and
1
, there is at least one good path with respect to
S
. | [
{
"input": "3 2\n1 2\n2 3\n",
"output": "14\n"
},
{
"input": "5 5\n4 2\n2 3\n1 3\n2 1\n1 5\n",
"output": "108\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_g | Problem Statement
You are given a simple connected undirected graph with
N
vertices and
M
edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)
For
i = 1, 2, \ldots, M
, the
i
-th edge connects Vertex
u_i
and Vertex
v_i
.
A sequence
(A_1, A_2, \ldots, A_k)
is said to be a
path
of length
k
if both of the following two conditions are satisfied:
For all
i = 1, 2, \dots, k
, it holds that
1 \leq A_i \leq N
.
For all
i = 1, 2, \ldots, k-1
, Vertex
A_i
and Vertex
A_{i+1}
are directly connected with an edge.
An empty sequence is regarded as a path of length
0
.
You are given a sting
S = s_1s_2\ldots s_N
of length
N
consisting of
0
and
1
.
A path
A = (A_1, A_2, \ldots, A_k)
is said to be a
good path
with respect to
S
if the following conditions are satisfied:
For all
i = 1, 2, \ldots, N
, it holds that:
if
s_i = 0
, then
A
has even number of
i
's.
if
s_i = 1
, then
A
has odd number of
i
's.
Under the Constraints of this problem, it can be proved that there is at least one good path with respect to
S
of length at most
4N
.
Print a good path with respect to
S
of length at most
4N
. | [
{
"input": "6 6\n6 3\n2 5\n4 2\n1 3\n6 5\n3 2\n110001\n",
"output": "9\n2 5 6 5 6 3 1 3 6\n"
},
{
"input": "3 3\n3 1\n3 2\n1 2\n000\n",
"output": "0\n\n"
}
] |
https://atcoder.jp/contests/abc244/tasks/abc244_h | Problem Statement
There is a set
S
of points on a two-dimensional plane.
S
is initially empty.
For each
i = 1, 2, \dots, Q
in this order, process the following query.
You are given integers
X_i, Y_i, A_i
, and
B_i
. Add point
(X_i, Y_i)
to
S
, and then find
\displaystyle \max_{(x,y) \in S}\left\{A_ix + B_iy\right\}
. | [
{
"input": "4\n1 0 -1 -1\n0 1 2 0\n-1 0 1 1\n0 -1 1 -2\n",
"output": "-1\n2\n1\n2\n"
},
{
"input": "9\n-1 4 -8 -2\n9 -9 -7 7\n4 1 6 7\n-4 -1 -4 -5\n-9 3 -2 -6\n-1 0 -8 5\n-8 -5 0 0\n8 3 0 -4\n2 -5 2 5\n",
"output": "0\n35\n31\n21\n36\n87\n0\n36\n31\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_a | Problem Statement
You are given integers
L,R
(
L < R
).
Snuke is looking for a pair of integers
(x,y)
that satisfy both of the conditions below.
L \leq x < y \leq R
\gcd(x,y)=1
Find the maximum possible value of
(y-x)
in a pair that satisfies the conditions.
It can be proved that at least one such pair exists under the Constraints. | [
{
"input": "2 4\n",
"output": "1\n"
},
{
"input": "14 21\n",
"output": "5\n"
},
{
"input": "1 100\n",
"output": "99\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_b | Problem Statement
You are given an integer sequence of length
N
consisting of
0
and
1
:
A=(A_1,A_2,\cdots,A_N)
.
You will do the operation below exactly once.
Choose a
contiguous
subsequence of
A
and flip the elements in it: convert
0
to
1
and vice versa.
Here, you may choose an empty subsequence, in which case the elements of
A
do not change.
Your score will be the number of
1
's in
A
.
How many values are there that your score can take? | [
{
"input": "4\n0 1 1 0\n",
"output": "4\n"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "6\n"
},
{
"input": "6\n0 1 0 1 0 1\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_c | Problem Statement
You are given a non-negative integer sequence of length
N
:
A=(A_1,A_2,\cdots,A_N)
.
Here, all elements of
A
are pairwise distinct.
Alice and Bob will play a game.
They will alternately play a turn, with Alice going first.
In each turn, the player does the operation below.
Choose the largest element in
A
at the moment, and replace it with a smaller non-negative integer.
Here, all elements in
A
must still be pairwise distinct after this operation.
The first player to be unable to do the operation loses.
Determine the winner when both players play optimally. | [
{
"input": "2\n2 4\n",
"output": "Alice\n"
},
{
"input": "3\n0 1 2\n",
"output": "Bob\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_d | Problem Statement
You are given an integer sequence of length
N
:
A=(A_1,A_2,\cdots,A_N)
, and an integer
M
.
For each
k=1,2,\cdots,M
, find the value of
A_N
after doing the operation below
k
times.
For every
i
(
1 \leq i \leq N
), simultaneously, replace the value of
A_i
with
A_1 \oplus A_2 \oplus \cdots \oplus A_i
.
Here,
\oplus
denotes bitwise
\mathrm{XOR}
.
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
).
Generally, the bitwise
\mathrm{XOR}
of
k
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)
. We can prove that this value does not depend on the order of
p_1, p_2, p_3, \dots p_k
. | [
{
"input": "3 2\n2 1 3\n",
"output": "0 1\n"
},
{
"input": "10 12\n721939838 337089195 171851101 1069204754 348295925 77134863 839878205 89360649 838712948 918594427\n",
"output": "716176219 480674244 678890528 642764255 259091950 663009497 942498522 584528336 364872846 145822575 392655861 844652404\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_e | Problem Statement
Snuke runs a bakery.
He is planning for the next
N
days.
Let us call these days Day
1,2,\cdots,N
.
At the moment, the bakery hires nobody.
There are
M
bakers that Snuke can hire, numbered
1
to
M
.
C_i
yen must be paid to hire Baker
i
.
If Baker
i
is hired, they will work on Day
L_i, L_i+1, \cdots, R_i
, baking one loaf of bread each day.
For each
j
(
1 \leq j \leq N
), there is a limit
A_j
to the number of loaves of bread that can be sold on Day
j
. If
x_j
loaves of bread are baked on Day
j
,
\min(x_j, A_j)
loaves will be sold on that day.
Each loaf of bread sold will yield a profit of
D
yen.
Snuke wants to choose the set of bakers to hire to maximize the final profit:
(
The total number of loaves sold
) \times D - (
The total cost of hiring bakers
)
.
Find the maximum possible value of this. | [
{
"input": "7 4 3\n1 1 1 1 1 1 1\n1 2 3\n2 4 5\n4 6 3\n6 7 1\n",
"output": "11\n"
},
{
"input": "3 1 5\n1 1 1\n2 2 10\n",
"output": "0\n"
},
{
"input": "10 10 42\n6 5 1 5 2 4 2 7 10 9\n3 4 4\n3 7 136\n9 9 14\n2 7 152\n3 3 33\n2 4 100\n3 3 38\n1 10 28\n3 5 66\n8 8 15\n",
"output": "543\n"
}
] |
https://atcoder.jp/contests/arc137/tasks/arc137_f | Problem Statement
We have a bar of length
1
.
A point on the bar whose distance from the left end of the bar is
x
is said to have a coordinate
x
.
Snuke will do the operation below
N
times.
Choose two real numbers
x
and
y
uniformly at random from
[0, 1]
.
Put a sticker covering the range from the coordinate
\min(x,y)
to the coordinate
\max(x,y)
.
Here, all random choices are independent of each other.
Stickers can overlap.
The bar is said to be good when no point is covered by
K+1
or more stickers.
Find the probability, modulo
998244353
, of having a good bar after putting
N
stickers.
Definition of a probability modulo
998244353
It can be proved that the sought probability 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 be proved that
Q \not \equiv 0 \pmod{998244353}
. Thus, there is a unique integer
R
such that
R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353
. Report this
R
. | [
{
"input": "2 1\n",
"output": "332748118\n"
},
{
"input": "5 3\n",
"output": "66549624\n"
},
{
"input": "10000 5000\n",
"output": "642557092\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_a | Problem Statement
Three people live in Takahashi's house: Takahashi, his father, and his mother. All of them wash their hair in the bathroom each night.
His father, his mother, and Takahashi take a bath in this order and use
A
,
B
, and
C
milliliters of shampoo, respectively.
This morning, the bottle contained
V
milliliters of shampoo. Without refilling, who will be the first to run short of shampoo to wash their hair? | [
{
"input": "25 10 11 12\n",
"output": "T\n"
},
{
"input": "30 10 10 10\n",
"output": "F\n"
},
{
"input": "100000 1 1 1\n",
"output": "M\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_b | Problem Statement
You are given integer sequences, each of length
N
:
A = (A_1, A_2, \dots, A_N)
and
B = (B_1, B_2, \dots, B_N)
.
All elements of
A
are different. All elements of
B
are different, too.
Print the following two values.
The number of integers contained in both
A
and
B
, appearing at the same position in the two sequences. In other words, the number of integers
i
such that
A_i = B_i
.
The number of integers contained in both
A
and
B
, appearing at different positions in the two sequences. In other words, the number of pairs of integers
(i, j)
such that
A_i = B_j
and
i \neq j
. | [
{
"input": "4\n1 3 5 2\n2 3 1 4\n",
"output": "1\n2\n"
},
{
"input": "3\n1 2 3\n4 5 6\n",
"output": "0\n0\n"
},
{
"input": "7\n4 8 1 7 9 5 6\n3 5 1 7 8 2 6\n",
"output": "3\n2\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_c | Problem Statement
There are
N
people in an
xy
-plane. Person
i
is at
(X_i, Y_i)
. The positions of all people are different.
We have a string
S
of length
N
consisting of
L
and
R
.
If
S_i =
R
, Person
i
is facing right; if
S_i =
L
, Person
i
is facing left. All people simultaneously start walking in the direction they are facing. Here, right and left correspond to the positive and negative
x
-direction, respectively.
For example, the figure below shows the movement of people when
(X_1, Y_1) = (2, 3), (X_2, Y_2) = (1, 1), (X_3, Y_3) =(4, 1), S =
RRL
.
We say that there is a collision when two people walking in opposite directions come to the same position. Will there be a collision if all people continue walking indefinitely? | [
{
"input": "3\n2 3\n1 1\n4 1\nRRL\n",
"output": "Yes\n"
},
{
"input": "2\n1 1\n2 1\nRR\n",
"output": "No\n"
},
{
"input": "10\n1 3\n1 4\n0 0\n0 2\n0 4\n3 1\n2 4\n4 2\n4 4\n3 3\nRLRRRLRLRR\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_d | Problem Statement
There is a perfect binary tree with
2^{10^{100}}-1
vertices, numbered
1,2,...,2^{10^{100}}-1
.
Vertex
1
is the root. For each
1\leq i < 2^{10^{100}-1}
, Vertex
i
has two children: Vertex
2i
to the left and Vertex
2i+1
to the right.
Takahashi starts at Vertex
X
and performs
N
moves, represented by a string
S
. The
i
-th move is as follows.
If the
i
-th character of
S
is
U
, go to the parent of the vertex he is on now.
If the
i
-th character of
S
is
L
, go to the left child of the vertex he is on now.
If the
i
-th character of
S
is
R
, go to the right child of the vertex he is on now.
Find the index of the vertex Takahashi will be on after
N
moves. In the given cases, it is guaranteed that the answer is at most
10^{18}
. | [
{
"input": "3 2\nURL\n",
"output": "6\n"
},
{
"input": "4 500000000000000000\nRRUU\n",
"output": "500000000000000000\n"
},
{
"input": "30 123456789\nLRULURLURLULULRURRLRULRRRUURRU\n",
"output": "126419752371\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_e | Problem Statement
You are given a simple connected undirected graph with
N
vertices and
M
edges.
Edge
i
connects Vertex
A_i
and Vertex
B_i
, and has a length of
C_i
.
Let us delete some number of edges while satisfying the conditions below. Find the maximum number of edges that can be deleted.
The graph is still connected after the deletion.
For every pair of vertices
(s, t)
, the distance between
s
and
t
remains the same before and after the deletion. | [
{
"input": "3 3\n1 2 2\n2 3 3\n1 3 6\n",
"output": "1\n"
},
{
"input": "5 4\n1 3 3\n2 3 9\n3 5 3\n4 5 3\n",
"output": "0\n"
},
{
"input": "5 10\n1 2 71\n1 3 9\n1 4 82\n1 5 64\n2 3 22\n2 4 99\n2 5 1\n3 4 24\n3 5 18\n4 5 10\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_f | Problem Statement
Takahashi is participating in a lottery.
Each time he takes a draw, he gets one of the
N
prizes available. Prize
i
is awarded with probability
\frac{W_i}{\sum_{j=1}^{N}W_j}
. The results of the draws are independent of each other.
What is the probability that he gets exactly
M
different prizes from
K
draws? Find it modulo
998244353
. | [
{
"input": "2 1 2\n2\n1\n",
"output": "221832079\n"
},
{
"input": "3 3 2\n1\n1\n1\n",
"output": "0\n"
},
{
"input": "3 3 10\n499122176\n499122175\n1\n",
"output": "335346748\n"
},
{
"input": "10 8 15\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
"output": "755239064\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_g | Problem Statement
We have a sequence of length
1
:
A=(X)
. Let us perform the following operation on this sequence
10^{100}
times.
Operation: Let
Y
be the element at the end of
A
. Choose an integer between
1
and
\sqrt{Y}
(inclusive), and append it to the end of
A
.
How many sequences are there that can result from
10^{100}
operations?
You will be given
T
test cases to solve.
It can be proved that the answer is less than
2^{63}
under the Constraints. | [
{
"input": "4\n16\n1\n123456789012\n1000000000000000000\n",
"output": "5\n1\n4555793983\n23561347048791096\n"
}
] |
https://atcoder.jp/contests/abc243/tasks/abc243_h | Problem Statement
There is a grid with
H \times W
squares. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
C_{i,j}
represents the state of each square. Each square is in one of the following four states.
S
: The starting point. The grid has exactly one starting point.
G
: The goal. The grid has exactly one goal.
.
: A constructible square, where a wall can be built.
O
: An unconstructible square, where a wall cannot be built.
Aoki intends to start at the starting point and get to the goal. When he is at
(i,j)
, he can go to
(i+1,j)
,
(i,j+1)
,
(i-1,j)
, or
(i,j-1)
. It is not allowed to exit the grid or enter a square with a wall.
Takahashi decides to build a wall on one or more constructible squares of his choice before Aoki starts so that there is no way for Aoki to reach the goal. Here, the starting point and the goal cannot be chosen.
Is it possible for Takahashi to build walls to prevent Aoki from reaching the goal? If it is possible, also compute the two values below:
the minimum number
n
of walls needed to prevent Aoki from reaching the goal, and
the number of ways modulo
998244353
,
r
, to achieve that minimum number of walls. | [
{
"input": "4 3\nS..\nO..\n..O\n..G\n",
"output": "Yes\n3 6\n"
},
{
"input": "3 2\n.G\n.O\n.S\n",
"output": "No\n"
},
{
"input": "2 2\nS.\n.G\n",
"output": "Yes\n2 1\n"
},
{
"input": "10 10\nOOO...OOO.\n.....OOO.O\nOOO.OO.OOO\nOOO..O..S.\n....O.O.O.\n.OO.O.OOOO\n..OOOG.O.O\n.O.O..OOOO\n.O.O.OO...\n...O..O..O\n",
"output": "Yes\n10 12\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_a | Problem Statement
In a certain programming contest, T-shirts are awarded to participants according to the following rules.
All participants who ranked
A
-th or higher get a T-shirt.
Additionally, from the participants who ranked between
(A+1)
-th and
B
-th (inclusive),
C
participants chosen uniformly at random get a T-shirt.
There were
1000
participants in this contest, and all of them got different ranks.
Iroha-chan, who participated in this contest, ranked
X
-th.
Find the probability that she gets a T-shirt. | [
{
"input": "30 500 20 103\n",
"output": "0.042553191489\n"
},
{
"input": "50 500 100 1\n",
"output": "1.000000000000\n"
},
{
"input": "1 2 1 1000\n",
"output": "0.000000000000\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_b | Problem Statement
You are given a string
S
. Find the lexicographically smallest string
S'
obtained by permuting the characters of
S
.
Here, for different two strings
s = s_1 s_2 \ldots s_n
and
t = t_1 t_2 \ldots t_m
,
s \lt t
holds lexicographically when one of the conditions below is satisfied.
There is an integer
i\ (1 \leq i \leq \min(n,m))
such that
s_i \lt t_i
and
s_j=t_j
for all integers
j\ (1 \leq j \lt i)
.
s_i = t_i
for all integers
i\ (1 \leq i \leq \min(n,m))
, and
n \lt m
. | [
{
"input": "aba\n",
"output": "aab\n"
},
{
"input": "zzzz\n",
"output": "zzzz\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_c | Problem Statement
Given an integer
N
, find the number of integers
X
that satisfy all of the following conditions, modulo
998244353
.
X
is an
N
-digit positive integer.
Let
X_1,X_2,\dots,X_N
be the digits of
X
from top to bottom. They satisfy all of the following:
1 \le X_i \le 9
for all integers
1 \le i \le N
;
|X_i-X_{i+1}| \le 1
for all integers
1 \le i \le N-1
. | [
{
"input": "4\n",
"output": "203\n"
},
{
"input": "2\n",
"output": "25\n"
},
{
"input": "1000000\n",
"output": "248860093\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_d | Problem Statement
You are given a string
S
consisting of
A
,
B
,
C
.
Let
S^{(0)}:=S
. For
i=1,2,3,\ldots
, let
S^{(i)}
be the result of simultaneously replacing the characters of
S^{(i-1)}
as follows:
A
→
BC
,
B
→
CA
,
C
→
AB
.
Answer
Q
queries. The
i
-th query is as follows.
Print the
k_i
-th character from the beginning of
S^{(t_i)}
. | [
{
"input": "ABC\n4\n0 1\n1 1\n1 3\n1 6\n",
"output": "A\nB\nC\nB\n"
},
{
"input": "CBBAACCCCC\n5\n57530144230160008 659279164847814847\n29622990657296329 861239705300265164\n509705228051901259 994708708957785197\n176678501072691541 655134104344481648\n827291290937314275 407121144297426665\n",
"output": "A\nA\nC\nA\nA\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_e | Problem Statement
Solve the following problem for
T
test cases.
Given an integer
N
and a string
S
, find the number of strings
X
that satisfy all of the conditions below, modulo
998244353
.
X
is a string of length
N
consisting of uppercase English letters.
X
is a palindrome.
X \le S
in lexicographical order.
That is,
X=S
or
X
is lexicographically smaller than
S
. | [
{
"input": "5\n3\nAXA\n6\nABCZAZ\n30\nQWERTYUIOPASDFGHJKLZXCVBNMQWER\n28\nJVIISNEOXHSNEAAENSHXOENSIIVJ\n31\nKVOHEEMSOZZASHENDIGOJRTJVMVSDWW\n",
"output": "24\n29\n212370247\n36523399\n231364016\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_f | Problem Statement
Consider placing
B
black rooks and
W
white rooks on a grid with
N
horizontal rows and
M
vertical columns.
A placement of the rooks satisfying all of the following conditions is called a
good placement
.
All
B+W
rooks are placed on the grid.
At most one rook is placed in the same square.
There is no pair of white rook and black rook attacking each other. That is, there is no pair of white rook and black rook such that one of them can reach the square in which the other is placed in one move.
Here, in one move, a rook can reach any square that is on a horizontal or vertical line from its current position and is reachable without jumping over another rook.
How many good placements are there? Since this count can be enormous, print it modulo
998244353
.
Rooks in the same color are not distinguished. | [
{
"input": "2 2 1 1\n",
"output": "4\n"
},
{
"input": "1 2 1 1\n",
"output": "0\n"
},
{
"input": "40 40 30 30\n",
"output": "467620384\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_g | Problem Statement
N
people numbered
1,2,\dots,N
are standing in a row. Person
i
wears Color
A_i
.
Answer
Q
queries of the format below.
You are given integers
l
and
r
. Considering only Person
l,l+1,\dots,r
, how many pairs of people wearing the same color can be formed at most? | [
{
"input": "10\n1 2 3 2 3 1 3 1 2 3\n6\n6 10\n5 8\n3 6\n4 4\n1 6\n1 10\n",
"output": "2\n2\n1\n0\n3\n4\n"
}
] |
https://atcoder.jp/contests/abc242/tasks/abc242_h | Problem Statement
There are
N
squares numbered
1
to
N
. Initially, all squares are painted white.
Additionally, there are
M
balls numbered
1
to
M
in a box.
We repeat the procedure below until all squares are painted black.
Pick up a ball from a box uniformly at random.
Let
x
be the index of the ball. Paint Squares
L_x, L_x+1, \ldots, R_x
black.
Return the ball to the box.
Find the expected value of the number of times the procedure is done, modulo
998244353
(see Notes). | [
{
"input": "3 3\n1 1\n1 2\n2 3\n",
"output": "499122180\n"
},
{
"input": "13 10\n3 5\n5 9\n3 12\n1 13\n9 11\n12 13\n2 4\n9 12\n9 11\n7 11\n",
"output": "10\n"
},
{
"input": "100 11\n22 43\n84 93\n12 71\n49 56\n8 11\n1 61\n13 80\n26 83\n23 100\n80 85\n9 89\n",
"output": "499122193\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_a | Problem Statement
There are
3
cards.
The
1
-st card has an integer
A
written on it; the
2
-nd has an integer
B
; the
3
-rd has an integer
C
.
When choosing
2
cards out of these
3
cards, find the minimum and maximum possible products of the integers written on the chosen
2
cards. | [
{
"input": "5 -2 4\n",
"output": "-10 20\n"
},
{
"input": "0 0 0\n",
"output": "0 0\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_b | Problem Statement
Takahashi wants to make many bouquets. Each bouquet should consist of
A
red flowers and
B
blue flowers.
Takahashi has
X
red flowers and
Y
blue flowers. How many bouquets can he make at most? | [
{
"input": "3 2 6 4\n",
"output": "2\n"
},
{
"input": "3 3 100 0\n",
"output": "0\n"
},
{
"input": "5 10 30 23\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_c | Problem Statement
A monomial consisting of a number and an English lowercase variable is said to be a
good monomial
if an English lowercase single-letter variable is multiplied from the left by an integer coefficient between
1
and
999
(inclusive). Here, we assume that the coefficient in a good monomial is never omitted even if the coefficient is
1
.
For example,
123a
and
1z
are good monomials, while
0a
,
1000b
,
123
,
12ab
,
a123
, and
a
are not.
Next, let us define the value of a good monomial by the value when certain values are assigned to the monomial.
Specifically, the value for each variable to be assigned is determined by the following equations:
a=1000
b=1000a
\dots
z=1000y
For instance, the value of
123a
is
123000
, the value of
20b
is
20000000
, and the value of
1c
is
1000000000
.
Among the possible values of good monomials, print the maximum one not exceeding
\alpha
in the form of a good monomial.
We can prove that such monomial always uniquely exists under the Constraints of this problem. | [
{
"input": "123456789\n",
"output": "123b\n"
},
{
"input": "77777\n",
"output": "77a\n"
},
{
"input": "9982443539982448531000000007\n",
"output": "9i\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_d | Problem Statement
Takahashi took
T
tests of the same format. Each test has
N
subjects numbered
1
to
N
.
In the
i
-th test, he scored
P_{i,j}
points in Subject
j
.
For each
K=1,2,\ldots,T
, answer the following question.
Question:
Let
C_j
be the highest score in Subject
j
in the first
K
tests.
Find
C_1+\ldots+C_N
. | [
{
"input": "2 3\n50 80 60\n60 70 70\n",
"output": "190\n210\n"
},
{
"input": "4 4\n1 2 3 4\n2 3 4 1\n4 1 2 3\n3 4 1 2\n",
"output": "10\n13\n15\n16\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_e | Problem Statement
YYYY/MM/DD format is a notation of date, consisting of the zero-padded
4
-digit year, zero-padded
2
-digit month, and zero-padded
2
-digit day, separated by slashes. For example, January
1
,
2022
is represented as
2022/01/01
.
A date is called
good
when it has two or fewer different digits in YYYY/MM/DD format.
You are given a date
S
in YYYY/MM/DD format. Print the
first
good day not earlier than
S
, in YYYY/MM/DD format.
Here, we use the Gregorian calendar. | [
{
"input": "2022/01/01\n",
"output": "2022/02/02\n"
},
{
"input": "2002/02/22\n",
"output": "2002/02/22\n"
},
{
"input": "2002/02/23\n",
"output": "2020/02/02\n"
},
{
"input": "2999/12/31\n",
"output": "3000/03/03\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_f | Problem Statement
The Kingdom of Takahashi consists of
N
states numbered
1
to
N
.
The map of the kingdom is a grid with
H
rows and
W
columns. The square at the
i
-th row from the top and
j
-th column from the left belongs to State
A_{i,j}
.
Is the condition below satisfied when painting State
i
in Color
C_i
in this map?
Different states that are vertically or horizontally adjacent are painted in different colors. | [
{
"input": "2 4 3\n1 1 2 3\n1 2 2 3\n2 3 3\n",
"output": "No\n"
},
{
"input": "3 5 4\n1 1 1 3 2\n1 2 1 3 4\n1 1 1 3 2\n3 1 4 3\n",
"output": "Yes\n"
},
{
"input": "2 2 3\n1 2\n3 1\n1 2 2\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_g | Problem Statement
Assume that the equation
a x^5 + bx + c=0
satisfies the condition below.
It has exactly one solution in the interval
1\lt x \lt 2
.
Find the solution of the equation in the interval
1\lt x \lt 2
. | [
{
"input": "32 2 -246\n",
"output": "1.500000000000000000\n"
},
{
"input": "12 3 -45\n",
"output": "1.279562760087743278\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_h | Problem Statement
There is a graph with
N
vertices, numbered
1, \dots, N
. Initially, there is no edge in this graph.
Process
Q
queries of the format below.
1 u v
: Add an undirected edge connecting Vertex
u
and Vertex
v
.
2 u
: List in ascending order all indices of vertices reachable from Vertex
u
by traversing zero or more edges at the moment the query is given.
Here, it is guaranteed that the total number of vertices to be listed in queries of the form
2 u
within a single test case is at most
2 \times 10^5
. | [
{
"input": "5 7\n1 1 2\n2 2\n1 3 4\n2 5\n1 1 4\n2 1\n2 4\n",
"output": "1 2\n5\n1 2 3 4\n1 2 3 4\n"
},
{
"input": "1 2\n2 1\n2 1\n",
"output": "1\n1\n"
},
{
"input": "3 3\n1 1 2\n2 1\n1 1 2\n",
"output": "1 2\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_i | Problem Statement
Consider an infinite
xy
-plane.
You are given two sets of
N
points each:
S = \lbrace (x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N) \rbrace
and
T = \lbrace (X_1, Y_1), (X_2, Y_2), \ldots, (X_N, Y_N) \rbrace
.
You may do exactly one of the two operations below zero or one time.
Choose a line parallel to the
x
-axis and reflect each point in
S
over the chosen line.
Choose a line parallel to the
y
-axis and reflect each point in
S
over the chosen line.
Determine whether it is possible to make
S
equal
T
as a set. | [
{
"input": "3\n2 3\n0 3\n0 1\n-1 3\n1 1\n1 3\n",
"output": "Yes\n"
},
{
"input": "2\n1 1\n0 0\n0 0\n-1 -1\n",
"output": "No\n"
},
{
"input": "3\n3 1\n4 1\n5 9\n5 9\n3 1\n4 1\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_j | Problem Statement
From
N
integers
A_1,A_2,\ldots,A_N
, we will choose
K
distinct integers. Here, any combination of
K
of the integers is chosen with equal probability.
Let
X
and
Y
be the maximum and minimum values among the chosen integers, respectively. Find the expected value of
X-Y
, modulo
998244353
. | [
{
"input": "3 2\n3 7 5\n",
"output": "665496238\n"
},
{
"input": "3 1\n3 7 5\n",
"output": "0\n"
},
{
"input": "10 5\n384 887 778 916 794 336 387 493 650 422\n",
"output": "621922587\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_k | Problem Statement
You are given a weighted directed graph with
N
vertices and
M
edges.
The vertices are numbered
1
to
N
.
The
i
-th edge
(1 \leq i \leq M)
goes from Vertex
u_i
to Vertex
v_i
and has a weight of
w_i
.
For each
k=1,2,\ldots,N
, solve the problem below.
Determine whether there is a path that starts at Vertex
1
, visits Vertex
k
one or more times, and ends at Vertex
N
. If it exists, print the shortest possible length of such a path. | [
{
"input": "3 3\n1 2 3\n2 3 4\n1 3 2\n",
"output": "2\n7\n2\n"
},
{
"input": "5 10\n2 1 1\n2 5 5\n1 2 6\n2 5 4\n5 3 2\n1 3 1\n1 3 4\n3 5 4\n1 5 3\n5 2 3\n",
"output": "3\n10\n5\n-1\n3\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_l | Problem Statement
Find the remainder when an integer
N
is divided by
M
.
Since
N
is enormous, it is given to you in the format below.
Format: You are given
K
characters
C_i
and
K
positive integers
D_i
. Let
S_i
be the concatenation of
D_i
copies of the character
C_i
.
N
is the concatenation of
S_1,\ldots,S_N
in this order, seen as a decimal integer. | [
{
"input": "3 11\n1 4\n2 2\n3 1\n",
"output": "3\n"
},
{
"input": "2 10000\n1 1\n0 1000000000000\n",
"output": "0\n"
},
{
"input": "8 5054049\n1 41421356\n1 7320508075\n2 2360679\n3 141592653589\n0 57721566\n1 644934066848\n2 99792458\n9 192631770\n",
"output": "3689688\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_m | Problem Statement
N
players called Player
1
, Player
2
,
\ldots
, Player
N
are playing a game. The initial score of Player
i
is
P_i
points.
Process
Q
queries in the order they are given.
There are three kinds of queries, as follows.
1 a x
: Change the score of Player
a
to
x
.
2 a
: Print the current rank of Player
a
among the
N
players. Specifically, if Player
a
has the
r
-th highest score, print the integer
r
.
3 r
: Print the player who currently ranks
r
-th. Specifically, if Player
a
has the
r
-th highest score, print the integer
a
.
Here, it is guaranteed that the initial scores of the players, and the scores after the changes given as queries of the first kind, are all distinct. | [
{
"input": "3 5\n10 30 20\n2 1\n3 1\n1 2 0\n2 1\n3 2\n",
"output": "3\n2\n2\n1\n"
}
] |
https://atcoder.jp/contests/past202203-open/tasks/past202203_n | Problem Statement
You are given an integer sequence
A
of length
N
.
In an
N \times N
grid, Takahashi has written the value
A_i-A_j
in the square at the
i
-th row from the top and
j
-th column from the left.
How many different values are written in the grid? | [
{
"input": "3\n5 2 3\n",
"output": "7\n"
},
{
"input": "10\n13 21 34 55 89 1 2 3 5 8\n",
"output": "75\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.