url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/abc297/tasks/abc297_d | Problem Statement
You are given positive integers
A
and
B
.
You will repeat the following operation until
A=B
:
compare
A
and
B
to perform one of the following two:
if
A > B
, replace
A
with
A-B
;
if
A < B
, replace
B
with
B-A
.
How many times will you repeat it until
A=B
? It is guaranteed that a finite repetition makes
A=B
. | [
{
"input": "3 8\n",
"output": "4\n"
},
{
"input": "1234567890 1234567890\n",
"output": "0\n"
},
{
"input": "1597 987\n",
"output": "15\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_e | Problem Statement
In AtCoder Kingdom,
N
kinds of
takoyaki
s (ball-shaped Japanese food) are sold. A takoyaki of the
i
-th kind is sold for
A_i
yen.
Takahashi will buy at least one takoyaki in total. He is allowed to buy multiple takoyakis of the same kind.
Find the
K
-th lowest price that Takahashi may pay. Here, if there are multiple sets of takoyakis that cost the same price, the price is counted only once. | [
{
"input": "4 6\n20 25 30 100\n",
"output": "50\n"
},
{
"input": "2 10\n2 1\n",
"output": "10\n"
},
{
"input": "10 200000\n955277671 764071525 871653439 819642859 703677532 515827892 127889502 881462887 330802980 503797872\n",
"output": "5705443819\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_f | Problem Statement
We have a grid with
H
rows and
W
columns.
We choose
K
cells in this grid uniformly at random. The score is the number of cells in the minimum rectangle (whose edges are parallel to the axes of the grid) that contains all of the chosen cells.
Find the expected score modulo
998244353
.
What is rational number modulo
998244353
?
We can prove that the sought expected value is always a rational number.
Moreover, under the Constraints of this problem, when the value is represented as
\frac{P}{Q}
by two coprime integers
P
and
Q
, we can prove that there is a unique integer
R
such that
R \times Q \equiv P\pmod{998244353}
and
0 \leq R \lt 998244353
. Find such
R
. | [
{
"input": "2 2 2\n",
"output": "665496238\n"
},
{
"input": "10 10 1\n",
"output": "1\n"
},
{
"input": "314 159 2653\n",
"output": "639716353\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_g | Problem Statement
There are
N
piles of stones. Initially, the
i
-th pile contains
A_i
stones. With these piles, Taro the First and Jiro the Second play a game against each other.
Taro the First and Jiro the Second make the following move alternately, with Taro the First going first:
Choose a pile of stones, and remove between
L
and
R
stones (inclusive) from it.
A player who is unable to make a move loses, and the other player wins. Who wins if they optimally play to win? | [
{
"input": "3 1 2\n2 3 3\n",
"output": "First\n"
},
{
"input": "5 1 1\n3 1 4 1 5\n",
"output": "Second\n"
},
{
"input": "7 3 14\n10 20 30 40 50 60 70\n",
"output": "First\n"
}
] |
https://atcoder.jp/contests/abc297/tasks/abc297_h | Problem Statement
A positive-integer sequence is said to be
splendid
if no two adjacent elements are equal.
Find the sum, modulo
998244353
, of the lengths of all splendid sequences whose elements have a sum of
N
. | [
{
"input": "4\n",
"output": "8\n"
},
{
"input": "297\n",
"output": "475867236\n"
},
{
"input": "123456\n",
"output": "771773807\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_a | Problem Statement
You are given an
N
-by-
N
matrix
A=(a_{i,j})
, where
a_{i,j} \in \{0,1\}
.
We have the following directed graph.
The graph has
NK
vertices numbered
1,2,\ldots,NK
.
The edges correspond to the
NK
-by-
NK
matrix
X=(x_{i,j})
obtained by arranging
K^2
copies of
A
in
K
rows and
K
columns (see Sample Input/Output 1 for an example). If
x_{i,j}=1
, there is a directed edge from vertex
i
to vertex
j
; if
x_{i,j}=0
, that edge does not exist.
Answer the following question for
i=1,2,\ldots,Q
.
Find the shortest length (number of edges) of a path from vertex
s_i
to vertex
t_i
. If there is no such path, print
-1
instead. | [
{
"input": "3 2\n1 1 1\n1 1 0\n0 1 0\n4\n1 2\n1 4\n1 6\n6 3\n",
"output": "1\n1\n1\n3\n"
},
{
"input": "4 1000000000\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n1\n1 4000000000\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_b | Problem Statement
We have variables
a
and
b
. Initially,
a=A
and
b=B
.
Takahashi will repeat the following operation while both
a
and
b
are greater than or equal to
1
.
Let
g
be the greatest common divisor of
a
and
b
, and replace
a
and
b
with
a-g
and
b-g
, respectively.
How many times will he perform the operation? | [
{
"input": "15 9\n",
"output": "2\n"
},
{
"input": "1 1\n",
"output": "1\n"
},
{
"input": "12345678910 10987654321\n",
"output": "36135\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_c | Problem Statement
You are given a sequence of positive integers:
A=(a_1,\ldots,a_N)
.
Determine whether it is possible to make all elements of
A
equal by repeating the following operation between
0
and
10^4
times, inclusive. If it is possible, show one way to do so.
Choose a permutation
(p_1,\ldots,p_N)
of
(1,\ldots,N)
, and replace
A
with
(a_1+p_1,\ldots,a_N+p_N)
. | [
{
"input": "2\n15 9\n",
"output": "Yes\n8\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n"
},
{
"input": "5\n1 2 3 10 10\n",
"output": "No\n"
},
{
"input": "4\n1 1 1 1\n",
"output": "Yes\n0\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_d | Problem Statement
We have a sequence
X
, which is initially empty.
Takahashi has performed the following operation for
i=1,2,\ldots,N
in this order.
Append
l_i,l_i+1,\ldots,r_i
in this order to the end of
X
.
Find the greatest length of a strictly increasing subsequence of the final
X
. | [
{
"input": "4\n1 1\n2 4\n10 11\n7 10\n",
"output": "8\n"
},
{
"input": "4\n1 1\n1 1\n1 1\n1 1\n",
"output": "1\n"
},
{
"input": "1\n1 1000000000\n",
"output": "1000000000\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_e | Problem Statement
You are given a positive integer
N
, and
M
pairs of positive integers:
(a_0,b_0),\ldots,(a_{M-1},b_{M-1})
(note that
a_i
and
b_i
start with index
0
).
We have the following sequence of non-negative integers
X=(x_1,\ldots,x_N)
.
x_i
is determined as follows.
Let
l=1
,
r=N
, and
t=0
.
Let
m=\left \lfloor \dfrac{a_{t \bmod M} \times l + b_{t \bmod M} \times r}{a_{t \bmod M} +b_{t \bmod M}} \right \rfloor
(
\lfloor x \rfloor
is the greatest integer not exceeding
x
). If
m=i
, let
x_i=t
and terminate.
If
l \leq i \lt m
, let
r=m-1
; otherwise, let
l=m+1
. Increment
t
by
1
and return to step 2.
Find
\sum_{j=c_i}^{d_i-1} |x_j - x_{j+1}|
for
i=1,2,\ldots,Q
.
It can be proved that the answers are at most
10^{18}
under the constraints of this problem. | [
{
"input": "5 1\n1 1\n3\n1 2\n2 4\n3 5\n",
"output": "1\n3\n2\n"
},
{
"input": "1000000000000000 2\n15 9\n9 15\n3\n100 10000\n5000 385723875\n150 17095708\n",
"output": "19792\n771437738\n34191100\n"
}
] |
https://atcoder.jp/contests/arc159/tasks/arc159_f | Problem Statement
A sequence
X
is called
good
when the following holds.
X
can be emptied by repeating the following operation zero or more times.
Delete two adjacent elements
x_i
and
x_{i+1}
of
X
such that
x_i \neq x_{i+1}
.
You are given a sequence with
2N
elements:
A=(a_1,\ldots,a_{2N})
.
Among the
2^{2N-1}
ways to divide
A
into one or more contiguous subsequences, how many are such that all those contiguous subsequences are good? Find the count modulo
998244353
. | [
{
"input": "3\n1 1 2 3 4 5\n",
"output": "2\n"
},
{
"input": "1\n1 2\n",
"output": "1\n"
},
{
"input": "1\n1 1\n",
"output": "0\n"
},
{
"input": "12\n4 2 17 12 18 15 17 4 22 6 9 20 21 16 23 16 13 2 20 15 16 3 7 15\n",
"output": "2048\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_a | Problem Statement
There is a row of
N
people. They are described by a string
S
of length
N
. The
i
-th person from the front is male if the
i
-th character of
S
is
M
, and female if it is
F
.
Determine whether the men and women are alternating.
It is said that the men and women are alternating if and only if there is no position where two men or two women are adjacent. | [
{
"input": "6\nMFMFMF\n",
"output": "Yes\n"
},
{
"input": "9\nFMFMMFMFM\n",
"output": "No\n"
},
{
"input": "1\nF\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_b | Problem Statement
Locate a piece on a chessboard.
We have a grid with
8
rows and
8
columns of squares. Each of the squares has a
2
-character name determined as follows.
The first character of the name of a square in the
1
-st column from the left is
a
. Similarly, the first character of the name of a square in the
2
-nd,
3
-rd,
\ldots
,
8
-th column from the left is
b
,
c
,
d
,
e
,
f
,
g
,
h
, respectively.
The second character of the name of a square in the
1
-st row from the bottom is
1
. Similarly, the second character of the name of a square in the
2
-nd,
3
-rd,
\ldots
,
8
-th row from the bottom is
2
,
3
,
4
,
5
,
6
,
7
,
8
, respectively.
For instance, the bottom-left square is named
a1
, the bottom-right square is named
h1
, and the top-right square is named
h8
.
You are given
8
strings
S_1,\ldots,S_8
, each of length
8
, representing the state of the grid.
The
j
-th character of
S_i
is
*
if the square at the
i
-th row from the top and
j
-th column from the left has a piece on it, and
.
otherwise.
The character
*
occurs exactly once among
S_1,\ldots,S_8
.
Find the name of the square that has a piece on it. | [
{
"input": "........\n........\n........\n........\n........\n........\n........\n*.......\n",
"output": "a1\n"
},
{
"input": "........\n........\n........\n........\n........\n.*......\n........\n........\n",
"output": "b3\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_c | Problem Statement
You are given a sequence of
N
numbers:
A=(A_1,\ldots,A_N)
.
Determine whether there is a pair
(i,j)
with
1\leq i,j \leq N
such that
A_i-A_j=X
. | [
{
"input": "6 5\n3 1 4 1 5 9\n",
"output": "Yes\n"
},
{
"input": "6 -4\n-2 -7 -1 -8 -2 -8\n",
"output": "No\n"
},
{
"input": "2 0\n141421356 17320508\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_d | Problem Statement
You are given positive integers
N
and
M
.
Find the smallest positive integer
X
that satisfies both of the conditions below, or print
-1
if there is no such integer.
X
can be represented as the product of two integers
a
and
b
between
1
and
N
, inclusive. Here,
a
and
b
may be the same.
X
is at least
M
. | [
{
"input": "5 7\n",
"output": "8\n"
},
{
"input": "2 5\n",
"output": "-1\n"
},
{
"input": "100000 10000000000\n",
"output": "10000000000\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_e | Problem Statement
You are given a sequence of
N
numbers:
A=(A_1,A_2,\ldots,A_N)
. Here, each
A_i
(1\leq i\leq N)
satisfies
1\leq A_i \leq N
.
Takahashi and Aoki will play
N
rounds of a game. For each
i=1,2,\ldots,N
, the
i
-th game will be played as follows.
Aoki specifies a positive integer
K_i
.
After knowing
K_i
Aoki has specified, Takahashi chooses an integer
S_i
between
1
and
N
, inclusive, and writes it on a blackboard.
Repeat the following
K_i
times.
Replace the integer
x
written on the blackboard with
A_x
.
If
i
is written on the blackboard after the
K_i
iterations, Takahashi wins the
i
-th round; otherwise, Aoki wins.
Here,
K_i
and
S_i
can be chosen independently for each
i=1,2,\ldots,N
.
Find the number of rounds Takahashi wins if both players play optimally to win. | [
{
"input": "3\n2 2 3\n",
"output": "2\n"
},
{
"input": "2\n2 1\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_f | Problem Statement
You are given two sequences of
N
numbers:
A=(A_1,A_2,\ldots,A_N)
and
B=(B_1,B_2,\ldots,B_N)
.
Takahashi can repeat the following operation any number of times (possibly zero).
Choose three pairwise distinct integers
i
,
j
, and
k
between
1
and
N
.
Swap the
i
-th and
j
-th elements of
A
, and swap the
i
-th and
k
-th elements of
B
.
If there is a way for Takahashi to repeat the operation to make
A
and
B
equal, print
Yes
; otherwise, print
No
.
Here,
A
and
B
are said to be equal when, for every
1\leq i\leq N
, the
i
-th element of
A
and that of
B
are equal. | [
{
"input": "3\n1 2 1\n1 1 2\n",
"output": "Yes\n"
},
{
"input": "3\n1 2 2\n1 1 2\n",
"output": "No\n"
},
{
"input": "5\n1 2 3 2 1\n3 2 2 1 1\n",
"output": "Yes\n"
},
{
"input": "8\n1 2 3 4 5 6 7 8\n7 8 5 6 4 3 1 2\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_g | Problem Statement
There is a convex
N
-gon
S
in the two-dimensional coordinate plane where the positive
x
-axis points to the right and the positive
y
-axis points upward. The vertices of
S
have the coordinates
(X_1,Y_1),\ldots,(X_N,Y_N)
in counter-clockwise order.
For each of
Q
points
(A_i,B_i)
, answer the following question: is that point inside or outside or on the boundary of
S
? | [
{
"input": "4\n0 4\n-2 2\n-1 0\n3 1\n3\n-1 3\n0 2\n2 0\n",
"output": "ON\nIN\nOUT\n"
},
{
"input": "3\n0 0\n1 0\n0 1\n3\n0 0\n1 0\n0 1\n",
"output": "ON\nON\nON\n"
}
] |
https://atcoder.jp/contests/abc296/tasks/abc296_h | Problem Statement
We have a grid with
N
rows and
M
columns, where each square is painted black or white.
Here, at least one square is painted black.
The initial state of the grid is given as
N
strings
S_1,S_2,\ldots,S_N
of length
M
.
The square at the
i
-th row from the top and
j
-th column from the left is painted black if the
j
-th character of
S_i
is
#
, and white if it is
.
.
Takahashi wants to repaint some white squares (possibly zero) black so that the squares painted black are
connected
.
Find the minimum number of squares he needs to
repaint
to achieve his objective.
Here, the squares painted black are said to be
connected
when, for every pair of squares
(S,T)
painted black, there are a positive integer
K
and a sequence of
K
squares
X=(x_1,x_2,\ldots,x_K)
painted black such that
x_1=S
,
x_K=T
, and
x_i
and
x_{i+1}
share a side for every
1\leq i\leq K-1
.
It can be proved that, under the constraints of the problem, there is always a way for Takahashi to achieve his objective. | [
{
"input": "3 5\n...#.\n.#...\n....#\n",
"output": "3\n"
},
{
"input": "3 3\n###\n###\n###\n",
"output": "0\n"
},
{
"input": "10 1\n.\n#\n.\n.\n.\n.\n.\n.\n#\n.\n",
"output": "6\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_a | å顿
2N+1
è¡ã
2N+1
åã®ãã¹ç®ããããŸããäžãã
i
è¡ç®ãå·Šãã
j
åç®ã®ãã¹ç®ã®ããšããã¹
(i,j)
ãšåŒã¶ããšã«ããŸãã
ãŸãã
(2N+1) \times (2N+1)
æŽæ°è¡å
A
ãäžããããŸãã
ããã§ããã¹
(1,N+1),(2N+1,N+1)
ãé€ãåãã¹ã«ã¯å£ãèšçœ®ããããšãã§ãããã¹
(i,j)
ã«å£ãèšçœ®ãã
ã³ã¹ã
ã¯
A_{i,j}
ã§ãã
ããŸããã¹
(1,N+1)
ã«é§ã眮ãããŠããŸãããã®é§ã¯ä»ãããã¹ç®ãšäžäžå·Šå³ã«é£æ¥ãããã€å£ã眮ãããŠããªããã¹ç®ã«ç§»åãããšããæäœãä»»æã®åæ°è¡ãããšãã§ããŸãã
å³å¯ã«ã¯ããã¹
(x,y)
ã«é§ã眮ãããŠããæããã¹
(x',y')
ã§ãã£ãŠæ¬¡ã®æ¡ä»¶ãå
šãŠæºãããã¹ã«ç§»åããããšãã§ããŸãã
1 \le x',y' \le 2N+1
ãã¹
(x',y')
ã«å£ãèšçœ®ãããŠããªãã
|x-x'|+|y-y'| = 1
ããªãã¯ãå£ãããã€ãé
眮ããããšã§é§ãã©ããªåãããããšããŠããã¹
(2N+1,N+1)
ã«å°éã§ããªãããã«ãããã§ãããã®ãšããé
眮ããå£ã®ã³ã¹ãã®åãšããŠèããããæå°å€ãæ±ããŠãã ããã | [
{
"input": "1\n1 -1 5\n2 4 6\n3 -1 7\n",
"output": "10\n"
},
{
"input": "2\n8 1 -1 5 5\n7 4 9 9 3\n3 2 1 1 8\n4 4 3 3 4\n3 5 -1 5 8\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_b | å顿
é·ã
N
ã®æ£æŽæ°å
A
ãäžããããŸãããããããã®æ°åã«ä»¥äžã®
M
åã®åŠçãè¡ããŸãã
i\ (1 \le i \le M)
åç®ã®åŠç :
1 \le j \le N
ãæºããæŽæ°
j
ãéžã¶ã
A_j
ã
\max(A_j,B_i)
ã«çœ®ãæããã
åŠçã®çµæã§ãã
A
ãšããŠèãããããã®ã®åæ°ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã | [
{
"input": "6 1\n1 2 3 4 5 6\n5\n",
"output": "5\n"
},
{
"input": "3 3\n1 1 1\n1 1 1\n",
"output": "1\n"
},
{
"input": "6 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n",
"output": "203\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_c | å顿
ãã®åé¡ã«ãããŠã¯ãã
1
çªç®ã®æåãã§æå
a
ããã
2
çªç®ã®æåãã§æå
b
ãã...ãã
26
çªç®ã®æåãã§æå
z
ãæããã®ãšããŸãã
è±å°æåãããªãæåå
S
ãäžããããŸãã
ããªãã¯
1\leq L\leq R\leq |S|
ãšãªãæŽæ°
L, R
ããã³
(1,2,\ldots,26)
ã®é å
(p_1,p_2,\ldots,p_{26})
ãéžã³ãŸãããã®åŸã以äžã®æé ã§æ°ããªæåå
T
ãäœããŸãã
S'
ã
S
ã®
L
æåç®ãã
R
æåç®ãåãåºããŠã§ããæååãšããã
1
以äž
26
以äžã®å
šãŠã®æŽæ°
i
ã«ã€ããŠã
S'
ã«å«ãŸããã
i
çªç®ã®æåããã
p_i
çªç®ã®æåãã§çœ®ãæããããã®æäœã¯å
šãŠã®
i
ã«å¯ŸããŠåæã«è¡ãããã®çµæã§ããæååã
T
ãšããã
T
ãšããŠèããããæååã®ãã¡èŸæžé ã§
æå€§
ã®ãã®ãæ±ããŠãã ããã | [
{
"input": "abcba\n",
"output": "zyzx\n"
},
{
"input": "nolemonnomelon\n",
"output": "zzyxwvyz\n"
},
{
"input": "hhhhhqqqhhhhhjjhhhhhpppp\n",
"output": "zzzzzyyzzzzzxxxx\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_d | å顿
ããã«
N
åã®ç®±ããããç®±
i
ã«ã¯
A_i
åã®ããŒã«ãå
¥ã£ãŠããŸããããªãã¯ã以äžã®æäœã
0
å以äž
2 \times 10^6
å以äžè¡ãããšãã§ããŸãã
æŽæ°å¯Ÿ
(X,Y)(X \neq Y)
ã§ãã£ãŠããç®±
X
ã«å
¥ã£ãŠããããŒã«ã®åæ°ãããç®±
Y
ã«å
¥ã£ãŠããããŒã«ã®åæ°ã以äžã§ãããã®ãéžã¶ã
ãããŠãç®±
X
ã«å
¥ã£ãŠããããŒã«ã®æ°ã ãç®±
Y
ããç®±
X
ã«ããŒã«ãç§»ãã
äžã€ã®ç®±ã«ãã¹ãŠã®ããŒã«ãå
¥ã£ãŠããç¶æ
ã«ã§ãããå€å®ããå¯èœãªãã°æäœåãäžã€æ§ç¯ããŠãã ããã | [
{
"input": "3\n1 3 4\n",
"output": "Yes\n3\n1 2\n2 1\n3 2\n"
},
{
"input": "4\n7 2 3 1\n",
"output": "No\n"
},
{
"input": "5\n2 6 2 1 5\n",
"output": "Yes\n6\n4 5\n1 2\n4 3\n2 1\n5 4\n5 2\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_e | å顿
1
以äž
2 \times 10^6
以äžã®æŽæ°ãããªãé·ã
10^5
ã®æ°åã®çµ
(A,B)
ã§ãã£ãŠã以äžã®æ¡ä»¶ãæºãããã®ãäžã€æ§ç¯ããŠãã ããã
1
以äž
2 \times 10^6
以äžã®ãã¹ãŠã®æŽæ°
k
ã«ã€ããŠã
A_i\times B_j=k
ãæºããæŽæ°å¯Ÿ
(i,j)
ãååšããã | [] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_f | å顿
0
以äž
2^M
æªæºã®æŽæ°ãããªãé·ã
N
ã®æ°å
A=(A_0,A_1,\ldots,A_{N-1})
ã§ãã£ãŠã以äžã®æ¡ä»¶ãæºãããã®ã®åæ°ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã
ãã¹ãŠã®æŽæ°
i\ (0 \le i \le N-1)
ã«ã€ããŠã
A_i \oplus A_{(i+1) \bmod N} \neq T_i
ãã€
A_i \oplus A_{(i+1) \bmod N} \neq U_i
ãæãç«ã€
ãã ã
\oplus
ã¯ãããåäœ
\mathrm{XOR}
æŒç®ã衚ããŸãã
ãããåäœ
\mathrm{XOR}
æŒç®ãšã¯
éè² æŽæ°
A,B
ã®ãããåäœ
\mathrm{XOR}
æŒç®ã
A\oplus B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A\oplus B
ãäºé²è¡šèšããéã®
2^k\ (k\geq 0)
ã®äœã®æ°ã¯ã
A,B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡äžæ¹ã®ã¿ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3\oplus 5 = 6
ãšãªããŸãïŒäºé²è¡šèšãããš:
011\oplus 101 = 110
)ã | [
{
"input": "3 2\n0 1\n1 2\n2 3\n",
"output": "8\n"
},
{
"input": "3 1\n0 1\n0 1\n0 1\n",
"output": "0\n"
},
{
"input": "5 10\n31 415\n92 653\n58 979\n32 384\n62 643\n",
"output": "552613140\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_g | å顿
N\times N
æŽæ°è¡å
A
ãäžããããŸãã以äžã®æ¡ä»¶ãæºãã
N \times N
æŽæ°è¡å
B
ãååšãããå€å®ããŠãã ããã
ãã¹ãŠã®æŽæ°å¯Ÿ
(i,j)
ã«ã€ããŠã
A_{i,j} \neq -1
ãªãã°
A_{i,j}=B_{i,j}
B
ã®ã©ã®
4 \times 4
ã®éšåæ£æ¹åœ¢ãåãåºããŠãããã®éšåæ£æ¹åœ¢ã¯
1
以äž
16
以äžã®æŽæ°ããã¹ãŠå«ãã | [
{
"input": "4\n1 2 -1 -1\n5 -1 7 -1\n9 10 -1 -1\n13 14 15 -1\n",
"output": "Yes\n"
},
{
"input": "5\n1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 -1 1 -1\n-1 -1 -1 -1 -1\n",
"output": "No\n"
},
{
"input": "6\n1 -1 -1 -1 -1 1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -1\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_h | å顿
æ³å®è§£ã«èª€ããèŠã€ãã£ããããæ£ããè§£æ³ã«å·®ãæ¿ããããã§åé¡ã®å¶çŽã倿ŽããŸããã(
M \le 10^{12}
ãã
M \le 10^9
)圱é¿ãåããæ¹ãç³ãèš³ãããŸããã(15:29)
æ£æŽæ°
N,M
ãäžããããŸãã
0\leq K\leq N-1
ãæºããå
šãŠã®
K
ã«å¯ŸããŠã次ã®å€ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã
1
以äž
M
以äžã®æŽæ°ã®ã¿ãããªãé·ã
N
ã®æ°å
A=(A_1,A_2,\ldots,A_N)
ã§ãã£ãŠã
A_i \times A_{i+1}
ãå¹³æ¹æ°ã§ãããããª
i\,(1\leq i\leq N-1)
ãã¡ããã©
K
åååšãããããªãã®ã®ç·æ° | [
{
"input": "3 2\n",
"output": "2\n4\n2\n"
},
{
"input": "7 9\n",
"output": "1236360\n1801104\n1168800\n444960\n111630\n17796\n2319\n"
},
{
"input": "10 1000000000\n",
"output": "463421383\n80897715\n609130572\n681545366\n345958046\n718253740\n76864047\n286280738\n642996694\n527041309\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_i | å顿
é·ã
N
ã®éè² æŽæ°å
A=(A_1,A_2,\ldots,A_N)
ãäžããããŸãã
A
ã®èŠçŽ ãèªç±ã«äžŠã³æ¿ããããšãã§ãããšãã以äžã®å€ãšããŠããããæå°å€ãæ±ããŠãã ããã
\displaystyle \sum_{k=1}^N(A_1\lor A_2\lor\cdots\lor A_k)
ãã ã
\lor
ã¯ãããåäœ
\operatorname{OR}
æŒç®ã衚ããŸãã
ãããåäœ
\operatorname{OR}
æŒç®ãšã¯
éè² æŽæ°
A,B
ã«å¯Ÿãããããåäœ
\operatorname{OR}
æŒç®
A\lor B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A\lor B
ãäºé²è¡šèšããéã®
2^k\,(k\geq0)
ã®äœã®æ°ã¯ã
A,B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡å°ãªããšãäžæ¹ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3\lor5=7
ãšãªããŸãïŒäºé²è¡šèšãããš
010\lor101=111
ïŒã | [
{
"input": "3\n4 1 2\n",
"output": "11\n"
},
{
"input": "3\n2 5 6\n",
"output": "15\n"
},
{
"input": "4\n13 13 13 13\n",
"output": "52\n"
},
{
"input": "6\n11 15 10 9 4 12\n",
"output": "74\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_j | å顿
é·ã
N
ã®æŽæ°å
A
ãäžããããŸããé·ã
N
ã®é å
P
ã以äžã®æ¡ä»¶ãæºãããšãã
\displaystyle \max_{1 \le i,j \le N} |iP_i-jP_j|
ãšããŠããããæå°ã®å€ãæ±ããŠãã ããã
ãã¹ãŠã®
i
ã«ã€ããŠã
A_i \neq -1
ãªãã°
A_i = P_i | [
{
"input": "3\n-1 -1 2\n",
"output": "4\n"
},
{
"input": "1\n-1\n",
"output": "0\n"
},
{
"input": "5\n2 4 5 1 3\n",
"output": "13\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_k | å顿
é·ã
N
ã®æŽæ°å
A = (A_0, A_1, \ldots, A_{N-1}),B=(B_1,B_2,\ldots,B_N)
ãé·ã
M
ã®æŽæ°å
C=(C_0,C_1,\ldots,C_{M-1}),D=(D_1,D_2,\ldots,D_M)
ãšéè² æŽæ°
K
ãäžããããŸãã
ããã§ãé·ã
K+1
ã®æ°å
F=(F_0,F_1,\ldots,F_K),G=(G_0,G_1,\ldots,G_K)
ã以äžã§å®çŸ©ããŸãã
F_i = A_i\ (0 \le i < N)
\displaystyle F_i = \sum_{k=1}^N B_kF_{i-k}\ (N \le i \le K)
G_j = C_j\ (0 \le j < M)
\displaystyle G_j = \sum_{k=1}^M D_kG_{j-k}\ (M \le j \le K)
\displaystyle \sum_{i=0}^K F_iG_i
ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã | [
{
"input": "2 2 5\n0 1\n1 1\n0 1\n1 1\n",
"output": "40\n"
},
{
"input": "3 2 1\n1 2 3\n4 5 6\n7 8\n9 10\n",
"output": "23\n"
},
{
"input": "6 7 924844033\n3 1 4 1 5 9\n2 6 5 3 5 8\n9 7 9 3 2 3 8\n4 6 2 6 4 3 3\n",
"output": "142556085\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_l | å顿
0
以äž
2^M
æªæºã®æŽæ°ãããªãé·ã
N
ã®æ°å
A
ãã¹ãŠã«ã€ããŠä»¥äžã®å€ãèãããã®ç·åã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã
(A_1\times A_2) \oplus (A_2\times A_3) \oplus \ldots \oplus (A_{N-1}\times A_N)
ã
2^M
ã§å²ã£ãäœã
ãã ã
\oplus
ã¯ãããåäœ
\mathrm{XOR}
æŒç®ã衚ããŸãã
ãããåäœ
\mathrm{XOR}
æŒç®ãšã¯
éè² æŽæ°
A,B
ã®ãããåäœ
\mathrm{XOR}
æŒç®ã
A\oplus B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A\oplus B
ãäºé²è¡šèšããéã®
2^k\ (k\geq 0)
ã®äœã®æ°ã¯ã
A,B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡äžæ¹ã®ã¿ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3\oplus 5 = 6
ãšãªããŸãïŒäºé²è¡šèšãããš:
011\oplus 101 = 110
)ã | [
{
"input": "2 1\n",
"output": "1\n"
},
{
"input": "2 2\n",
"output": "16\n"
},
{
"input": "314 159\n",
"output": "856758166\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_a | å顿
ãç çåœã¯
N
åã®è¡ãšãããç¹ã
M
æ¬ã®éè·¯ãããªããŸããè¡ã«ã¯æšé«ãé«ãé ã«
1, 2, \ldots, N
ã®çªå·ãã€ããŠãããå
šãŠã®éè·¯ã¯æšé«ãé«ãè¡ããäœãè¡ãžäžæ¹åã«ç§»åããããšãã§ããŸããå
·äœçã«ã¯ã
i
çªç®ã®éè·¯ã¯è¡
A_i
ããè¡
B_i
ãžã®äžæ¹åã«ç§»åããããšãã§ããŸã
(A_i < B_i)
ã
ããŠãä»å¹Žããç å宿ãéå¬ãããŸããä»å¹Žã®ãç å宿ã§ã¯ããã€ãã®è¡ã«äŒå Žãèšãããç çåœã®ã©ã®è¡ããã§ã
0
æ¬ä»¥äžã®éè·¯ãéãããšã§äŒå Žã®ããè¡ã«ç§»åã§ããããã«ããŸãã
ããããäºç®ã«å¶çŽããããããäŒå Žãèšããè¡ãã§ããã ãå°ãªããããã§ãããã®ãšããäŒå Žãèšããè¡ã®éåãäžã€å®ããŠäžããã | [
{
"input": "4 4\n1 2\n1 3\n1 4\n2 4\n",
"output": "2\n3 4\n"
},
{
"input": "10 20\n4 6\n7 9\n1 8\n4 7\n2 3\n5 6\n5 8\n8 10\n8 9\n3 4\n7 8\n3 6\n1 2\n4 9\n8 10\n6 10\n5 9\n2 7\n6 10\n1 8\n",
"output": "2\n9 10\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_b | å顿
ãç åŠåã§ã¯å幎床ã«
N
åã®åŠæãããã
1, 2, \ldots, N
ã®çªå·ãä»ããŠããŸããååŠæããšã«æçžŸãä»ããæçžŸã¯
1
ãã
N
ãŸã§ã®æŽæ°å€ã§è¡šãããŸãã
ããŠããç åŠåã®çåŸã§ããããªãã¯ãäžå¹Žã®æåŸã«èªåã®ååŠæã®æçžŸè¡šãçºããŠããŸããããããšã次ã®ããšã«æ°ãä»ããŸãããããã§
i
çªç®ã®åŠæã®æçžŸã
G_i
ãšããŸãã
G
ã¯é·ã
N
ã®é åã§ããã
2
åŠæä»¥éã«ã€ããŠãåã®åŠæããæçžŸãäžãã£ãŠããåŠæãååšãããããã¯é£ç¶ãã
1
ã€ã®åºéã«ãªã£ãŠããã
ãã®ãšãããããã®æ¡ä»¶ãæºããæçžŸ
G_1, G_2, \ldots, G_N
ã®åæ°ãæ±ããŠäžããããã ããçãã¯ãšãŠã倧ãããªãããšãããã®ã§ãçãã
998244353
ã§å²ã£ãäœããåºåããŠãã ããã | [
{
"input": "4\n",
"output": "18\n"
},
{
"input": "13\n",
"output": "398574\n"
},
{
"input": "2947\n",
"output": "663703367\n"
},
{
"input": "999999\n",
"output": "946508973\n"
},
{
"input": "1000000000000000000\n",
"output": "856673235\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_c | å顿
ãç çºã«ã¯ãç çŸè¡é€šãšããŸã°çŸè¡é€šããããŸããããããã®çŸè¡é€šã«ã¯
N
åã®çŸè¡åãäžåã«å±ç€ºãããŠããããç çŸè¡é€šã®å·Šãã
i
çªç®ã®çŸè¡åã®äŸ¡å€ã¯
A_i
ã§ãããŸã°çŸè¡é€šã®å·Šãã
i
çªç®ã®çŸè¡åã®äŸ¡å€ã¯
B_i
ã§ããæ¥å Žè
ãããæ¥œããŸããããã«ãçŸè¡åã¯å·Šããå³ã«åãã£ãŠäŸ¡å€ã®äœãç©ããé«ãç©ã®é ã«äžŠãã§ããŸãã
ãç çŸè¡é€šãšããŸã°çŸè¡é€šã¯ã³ã©ãå±ç€ºãããããšã«ãªããŸãããã³ã©ãã«ã¯
Q
åã®ãã©ã³ãããã
i
çªç®ã®ãã©ã³ã§ã¯ããç çŸè¡é€šã®å·Šãã
L_i
çªç®ãã
R_i
çªç®ã®çŸè¡åãšãããŸã°çŸè¡é€šã®å·Šãã
X_i
çªç®ãã
Y_i
çªç®ã®çŸè¡åãå±ç€ºããŸããã³ã©ãå±ç€ºã§ãåæ§ã«ãçŸè¡åã¯å·Šããå³ã«åãã£ãŠäŸ¡å€ã®äœãç©ããé«ãç©ã®é ã«äžŠã¹ãŸãã
ããå±ç€ºã®æºè¶³åºŠããé£ãåãçŸè¡åã®äŸ¡å€ã®å·®ã®æå°å€ãšããŸããããå
i \ (1 \leq i \leq Q)
ã«ã€ããŠã
i
çªç®ã®ãã©ã³ã§å±ç€ºãè¡ã£ãéã®æºè¶³åºŠãæ±ããŠãã ããã | [
{
"input": "6\n1 3 6 8 9 11\n2 2 4 7 10 11\n4\n1 6 2 5\n1 6 5 5\n2 5 5 5\n4 6 3 6\n",
"output": "1\n1\n1\n0\n"
},
{
"input": "10\n4 14 18 31 47 51 59 72 78 96\n2 23 25 36 58 60 63 85 88 97\n7\n1 3 5 5\n6 10 3 4\n8 10 1 4\n7 10 2 4\n6 7 1 3\n2 4 6 9\n2 3 2 9\n",
"output": "4\n6\n2\n2\n2\n3\n2\n"
},
{
"input": "15\n1141 1334 2083 2504 4031 4238 4328 5260 5315 6427 6991 8127 8199 8356 9136\n189 403 1035 1126 1165 1477 2021 2100 2528 3892 4108 4459 5792 7050 8709\n8\n4 7 7 15\n8 11 8 11\n7 11 2 15\n2 13 6 11\n11 12 3 10\n8 10 3 12\n3 11 3 10\n3 11 8 10\n",
"output": "24\n55\n39\n17\n39\n39\n17\n17\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_d | å顿
0
ãš
1
ãããªãé·ã
N
ã®æååã§ãã£ãŠ
1
以äž
M
以äžã®å
šãŠã®æŽæ°
i
ã«ã€ããŠæ¬¡ã®æ¡ä»¶ãæºãããã®ã®åæ°ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã
L_i
æåç®ãã
R_i
æåç®ã®éã«æå
C_i
ãååšãã | [
{
"input": "3 2\n1 3 0\n1 2 1\n",
"output": "5\n"
},
{
"input": "5 4\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n",
"output": "13\n"
},
{
"input": "7 9\n4 6 0\n1 2 0\n5 7 1\n3 4 0\n7 7 0\n6 7 1\n2 5 1\n3 5 0\n1 7 1\n",
"output": "13\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_e | å顿
ãç æ¥œå£ã«ã¯ã
N
äººã®æŒå¥è
ãããŸãããŸãããç æ¥œå£ã¯
M
çš®é¡ã®æ¥œåšãææããŠããŸãã
i
人ç®ã®æŒå¥è
ã®ç緎床ã¯
A_i
ã§æ
åœæ¥œåšã¯
B_i
ãæ¥œåšã®ç§»è¡ã³ã¹ãã¯
C_i
ã§ãã
i
人ç®ã®æŒå¥è
ã¯
C_i
ã®ç§»è¡ã³ã¹ãã§æ
åœã®æ¥œåšã奜ããªãã®ã«å€æŽããããšãã§ããŸãã
楜å£ã®èª¿å床ã以äžã®ããã«å®çŸ©ããŸãã
M
çš®é¡ã®æ¥œåšããããã«ã€ããŠããã®æ¥œåšãæ
åœãã人ã®çç·ŽåºŠã®æå€§å€ãèããããã®
M
åã®å€ã®æå°å€ã調å床ã§ããããã ããæ
åœãã人ãããªã楜åšãååšããå Žåã調å床ã¯
0
ã§ããã
x = X_1, X_2, \ldots ,X_Q
ã«ã€ããŠãç§»è¡ã³ã¹ãã®ç·åã
x
ãè¶
ããã«å®çŸã§ããæå€§ã®èª¿ååºŠãæ±ããŠãã ããã | [
{
"input": "5 3\n7 1 4\n10 3 3\n8 3 3\n9 3 5\n7 1 4\n6\n2 9 12 15 25 46\n",
"output": "0\n8\n8\n8\n8\n8\n"
},
{
"input": "10 6\n10 3 4\n12 2 5\n2 1 3\n7 3 15\n12 1 10\n8 3 3\n11 3 14\n13 6 9\n3 3 12\n4 5 1\n10\n1 3 7 37 53 85 88 91 94 148\n",
"output": "0\n4\n8\n8\n8\n8\n8\n8\n8\n8\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_f | å顿
ãç åã¯ã次ã®åé¡ãè§£ããŠããŸãã
N
é ç¹ã®æšãäžãããããé ç¹ã«ã¯
1, 2, \ldots, N
ã®çªå·ãä»ããããŠããã
åé ç¹ã«ã€ããŠããã®é ç¹ããæãé¢ããé ç¹ãäžã€æ±ãããè€æ°ããå Žåã¯ã©ããæ±ããŠãããã
ãç åã¯ãã®åé¡ãè§£ãã
1 \leq i \leq N
ã«ã€ããŠé ç¹
i
ããæãé¢ããé ç¹ã®ãã¡äžã€ãé ç¹
A_i
ã§ãããšåãããŸããã
ããããªããšããäºã§ãããããã£ããåé¡ãè§£ããã®ã«ãå
ã®æšã
A
ã®äžéšã®å€ãåãããªããªã£ãŠããŸããŸãããããªãã¯ãç åã®ããã«ãæ°å
A
ã埩å
ããŠãããããšèããŸããã
ä»ããªãã«ã¯é·ã
N
ã®æ°å
B
ãäžããããŸãããã®æ°åã¯æ®ã£ãŠãã
A
ã®æ
å ±ã衚ããŠããŸãããã®ãšããæ¬¡ã®å
šãŠã®æ¡ä»¶ãæºããé·ã
N
ã®æ°å
A
ãèããŸãã
B_i \neq -1
ãªãã°
A_i = B_i
ã§ãã
ããæšãååšãã
1 \leq i \leq N
ã«ã€ããŠãé ç¹
i
ããæãé¢ããé ç¹ã®äžã€ãé ç¹
A_i
ã§ãã
ãã®ãããªæ¡ä»¶ãæºãã
A
ãããã€ãããããç åã«æããŠãããŠãã ããããã ãããç åãåé¡ãè§£ãééããŠããå¯èœæ§ããããããæ¡ä»¶ãæºãã
A
ãååšããªãå ŽåããããŸãã
ãªããçãã¯å€§ãããªãå Žåãããã®ã§ã代ããã«çãã
998244353
ã§å²ã£ãããŸããæ±ããŠäžããã | [
{
"input": "3\n2 -1 -1\n",
"output": "3\n"
},
{
"input": "8\n-1 8 7 5 -1 1 2 3\n",
"output": "47\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_g | å顿
ãã®åé¡ã¯ã€ã³ã¿ã©ã¯ãã£ããªåé¡ã§ãã
ãç çºã«ã¯
N
æžã®å®¶ãããã
1, 2, \ldots, N
ã®çªå·ãä»ããŠããŸãããŸãå®¶ãšå®¶ãåæ¹åã«çµã¶
0
æ¬ä»¥äžã®éè·¯ããããéè·¯ã¯
300
æ¬ä»¥äžã§ããããšãåãã£ãŠããŸãããäœæ¬ãããããããããã®éè·¯ãã©ã®å®¶ãšã©ã®å®¶ãçµãã§ãããã¯åãããŸããããã ãã䞡端ãåãå®¶ãçµãã§ããéè·¯ã¯ãªããè€æ°ã®éè·¯ãåãå®¶ã®çµãçµãã§ããããšããããŸããã
ãç çºã®çºé·ãšãªã£ãããªãã¯ãããããæ¯æ¥
1
åãã€éäŒãéããŸãã
N
æžã®å®¶ããããã«ã€ããŠããã®å®¶ã®äœäººãæåŸ
ãããããªããæ±ºããããšãã§ããŸãã
ãããããç çºã¯éåžžã«éºæªãªçºã§ããç¹ã«é£äººãã€ãŸã
1
ã€ã®éè·¯ã§çµã°ãã
2
ã€ã®å®¶ã«äœãäœäººã¯ãéäŒã§é¡ãåãããã ãã§éäŒã®å
šå¡ãå·»ã蟌ãã ä¹±éãèµ·ããŠããŸããŸãã
ããŠãããªãã¯ãç çºã®éè·¯ã®æ¬æ°ããããããã®éè·¯ãã©ã®å®¶ãšã©ã®å®¶ãçµãã§ãããã調ã¹ãããšæããŸãããããã§ã忥ã«éäŒã«æåŸ
ãã人ã工倫ããä¹±éãèµ·ãããã©ããã調ã¹ãããšã§ããç çºã®æ§é ã調ã¹ãããšã«ããŸããã
ããã¯æããã«è·æš©æ¿«çšãªã®ã§ã
3200
æ¥éãŸã§ããéäŒãéããŸãããéäŒã«æåŸ
ããäººãæ±ºããæŠç¥ãå®ããããã°ã©ã ãäœæããŠãã ããã
ãªããããªãèªèº«ã¯èª°ãšãé£äººã§ãªããã®ãšããŸãããŸãã誰ãåŒã°ãã«äžäººã§éäŒãè¡ãããšãã§ããŸãã | [] |
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_h | å顿
ãç éšå¡ãäžåã«
N
人䞊ãã§ããŸããå·Šãã
i \ (1 \leq i \leq N)
çªç®ã®éšå¡ãéšå¡
i
ãšåŒã¶ããšã«ããŸããçŸåšã®éšå¡
i
ã®ããœã³ã³åã¯
A_i
ã§ããé£ãåãéšå¡å士ã«ã¯ä»²è¯ã床ãšããææšãååšãã
1 \leq i \leq N - 1
ã«ã€ããŠçŸåšã®éšå¡
i
ãšéšå¡
i + 1
ã®ä»²è¯ã床ã¯
B_i
ã§ããããã§
B_i
ã¯çžç°ãªããŸãã
ãç éšå¡ã¯æŽŸé¥äºãã倧奜ãã§ããæ®æ®µã¯æŽŸé¥äºããçŠæ¢ãããŠããŸãããäžãäžæŽŸé¥äºããèµ·ãã£ãŠããŸã£ããšãã®ããšãèããŠã¿ãŸãããã
人
l, l + 1, \cdots , r \ (1 \leq l \leq r \leq N)
ãæŽŸé¥äºããå§ãããšã以äžã®äºæãèµ·ãããŸãã
ã¯ãããæŽŸé¥
l, l + 1, \cdots ,r
ãååšããéšå¡
i \ (l \leq i \leq r)
ã¯æŽŸé¥
i
ã«å±ããããã以å€ã®éšå¡ã¯æŽŸé¥ã«å±ããªãã
掟é¥
a, b \ (l \leq a < b \leq r)
ã®ä»²è¯ã床ã¯ã以äžã®ããã«å®çŸ©ãããã
ã©ã®æç¹ã«ãããŠããæŽŸé¥
a
ã«äºº
i
ãæå±ããæŽŸé¥
b
ã«äºº
i+1
ãæå±ããŠãããããª
i
ã¯é«ã
1
ã€ååšããããšã蚌æã§ããã仲è¯ã床ã¯ããã®ãããª
i
ãååšããªãå Žå
-10^{100}
ã§ãããååšããå Žå
B_i
ã§ããã
掟é¥ã
1
ã€ã«ãªããŸã§ã以äžã®ã€ãã³ããç¹°ãè¿ãããã
仲è¯ã床ãæå€§ã§ãã
2
掟é¥
a, b \ (a < b)
ãèãããåæŽŸé¥ã«æå±ãã人ã®ããœã³ã³åã®ç·åã
s, t
ãšããããã®ãšã
s \geq t
ãªã掟é¥
b
ã«æå±ãã人ãå
šå¡æŽŸé¥
a
ã«æå±ãå€ãã
s < t
ãªã掟é¥
a
ã«æå±ãã人ãå
šå¡æŽŸé¥
b
ã«æå±ãå€ããããŸããæå±ãã人ãããªããªã£ã掟é¥ã¯æ¶æ»
ããã
ãç ã®æŽ»åã¯ææ¥ããã®
Q
æ¥ã®é掻çºãªã®ã§ãéšå¡ã®ããœã³ã³åã仲è¯ã床ã¯é »ç¹ã«å€ãããŸããå
·äœçã«ã¯ã
j \ (1 \leq j \leq Q)
æ¥ç®ã«ã¯ä»¥äžã®å€åãèµ·ãããŸãã
T_j = 1
ã®å Žåãéšå¡
P_j
ã®ããœã³ã³åã
V_j
ã«ãªãã
T_j = 2
ã®å Žåãéšå¡
P_j
ãšéšå¡
P_j + 1
ã®éã®ä»²è¯ã床ã
V_j
ã«ãªãã
ãã ãããããã®æç¹ã«ãããŠãéšå¡å士ã®ä»²è¯ã床ã¯çžç°ãªãããšãä¿èšŒãããŸãã
掟é¥äºããæ³åããã®ã倧奜ããªæŽŸé¥å€ªéåã¯ãæ¯æ¥æŽŸé¥äºãã®æèå®éšãè¡ããŸããå
·äœçã«ã¯ã
j \ (1 \leq j \leq Q)
æ¥ç®ã®çµããã«ã¯ãéšå¡
L_j, L_j + 1, \cdots ,R_j
ãæŽŸé¥äºããå§ãããšãæåŸã«æ®ã掟é¥ãæ±ããŸãã
åæèå®éšã®çµæãæ±ããŠãã ããã | [
{
"input": "5\n5 9 9 7 9\n6 7 3 4\n3\n1 4 7 4 5\n2 4 10 1 3\n1 1 6 1 3\n",
"output": "5\n2\n2\n"
},
{
"input": "8\n14 10 12 20 18 1 6 13\n2 16 1 3 4 12 11\n5\n1 2 3 1 8\n1 3 8 1 8\n1 1 4 1 8\n1 7 15 1 8\n1 4 19 1 8\n",
"output": "8\n8\n8\n7\n7\n"
},
{
"input": "8\n10 17 13 17 16 1 19 8\n11 1 9 4 2 12 10\n5\n2 2 7 1 8\n2 4 15 1 8\n2 3 5 1 8\n2 2 13 1 8\n2 6 14 1 8\n",
"output": "4\n4\n2\n2\n2\n"
},
{
"input": "8\n11 11 2 2 10 5 2 15\n9 1 10 19 7 14 20\n3\n1 1 11 8 8\n1 1 11 4 6\n1 1 11 2 6\n",
"output": "8\n5\n5\n"
},
{
"input": "20\n30 95 72 93 69 100 45 51 7 19 40 61 73 51 98 71 25 51 15 91\n20 69 94 58 63 70 80 17 66 10 83 48 40 86 23 67 60 44 96\n6\n2 9 71 6 15\n1 2 46 11 15\n1 6 15 6 19\n2 8 8 1 13\n2 8 26 6 18\n1 9 31 5 14\n",
"output": "12\n12\n12\n4\n12\n8\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_a | å顿
座æšå¹³é¢äžã®ç¹
P(X, Y)
ããæ¬¡ã®æäœãç¹°ãè¿ããŠåç¹ã«åããããã§ãã
ãã宿°
a
ãéžã³ã
P
ã®çŸåšã®åº§æšã
(x, y)
ãšããŠã
P
ã
(x, a)
ãŸãã¯
(a, y)
ã«åããã
å¿
èŠãªæå°ã®æäœåæ°ãæ±ããŠãã ããã | [
{
"input": "6 4\n",
"output": "2\n"
},
{
"input": "0 1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_b | å顿
XXXX 幎ã®ãç å宿ã«ã¯
N
人ã®åå è
ãããŸããã
ããœã³ã³ãå
é»ããããã«
1
人
1
ã€ã®ã³ã³ã»ã³ããå¿
èŠã§ããããããäŒå Žã«ã¯äœ¿çšå¯èœãªã³ã³ã»ã³ãã
1
ã€ãããããŸããã§ããããã®ãããéå¶ã¯
M
åå£ã®é»æºã¿ãããããã€ãçšæããããšã«ããŸããã
M
åå£ã®é»æºã¿ãã
1
ã€ãæªäœ¿çšã®äœ¿çšå¯èœãªã³ã³ã»ã³ã
1
ã€ã«æ¿ãããšã§ãæ°ãã«äœ¿çšå¯èœãªã³ã³ã»ã³ãã
M
åã§ããŸãã
åå è
1
人ã«ã€ãæäœã§ã
1
ã€äœ¿çšå¯èœãªã³ã³ã»ã³ããããããã«ããã«ã¯æäœã§äœåã®é»æºã¿ãããçšæããå¿
èŠããããŸããïŒããã ãã
1
人
1
ã€ã®ã³ã³ã»ã³ããçšæããããšãäžå¯èœã§ããå Žåã¯ãã®ããšãå ±åããŠãã ããã | [
{
"input": "5 5\n",
"output": "1\n"
},
{
"input": "30 1\n",
"output": "-1\n"
},
{
"input": "998244353 3\n",
"output": "499122176\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_c | å顿
è±å°æåãš
?
ã®ã¿ãããªãæåå
S
ãäžããããŸãã
æåå
S
ã«å«ãŸãã
?
ããããã奜ããªè±å°æåã«çœ®ãæããããšã§äœããåæã¯äœéããããæ±ããŠãã ããã
ãã ããçãã¯éåžžã«å€§ãããªãå¯èœæ§ãããã®ã§ã
998244353
ã§å²ã£ãããŸããåºåããŠãã ããã
åæã®å®çŸ©
æåå
T
ãåæã§ãããšã¯ã
1 \leq i \leq | T |
ãæºãããã¹ãŠã®æŽæ°
i
ã«ã€ããŠã
T
ã®åãã
i
æåç®ã®æåãšåŸããã
i
æåç®ã®æåãåãæåã§ããããšããããŸãã | [
{
"input": "a??\n",
"output": "26\n"
},
{
"input": "atcoder\n",
"output": "0\n"
},
{
"input": "?????????????\n",
"output": "45855352\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_d | å顿
N
åã®æ€
åãæšªäžåã«äžŠãã§ããŸãããããã®æ€
åã«
K
人ã®äººã座ãããŸãã
1
ã€ã®æ€
åã«åº§ã人ã¯é«ã
1
人ã§ããå¿
èŠããããŸãããã®ãšãæ¬¡ã®æ¡ä»¶ãæºãã
i \,(2 \leq i \leq N-1)
ã®åæ°ãæå°åãããã§ãã
å·Šãã
i-1 , i , i+1
çªç®ã®æ€
åå
šãŠã«äººã座ã£ãŠãã
ãã®ãããªåº§ãæ¹ãäžã€èŠã€ããŠãã ããã | [
{
"input": "6 4\n",
"output": "1 2 4 6 \n"
},
{
"input": "6 5\n",
"output": "1 2 4 5 6 \n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_e | å顿
瞊ã®é·ãã
H
ãæšªã®é·ãã
W
ã®é·æ¹åœ¢ã®äžã«ååŸã®é·ããçãã
2
ã€ã®åæ¿ãå
¥ããããšãèããŸãããã®ãšããåæ¿ãé·æ¹åœ¢ããã¯ã¿åºãããã
2
ã€ã®åæ¿ã®å
±ééšåã®é¢ç©ã
0
ãã倧ãããªã£ããããŠã¯ãããŸããããã®ãšããåæ¿ã®ååŸã®æå€§å€ãè§£çããŠãã ããã | [
{
"input": "6 4\n",
"output": "1.535898384862246\n"
},
{
"input": "4 1\n",
"output": "0.500000000000000\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_f | å顿
ãç å宿㮠K éå¶é·ã¯ããäžæ¥ã«éå¬ããã€ãã³ããäœã«ãããæ±ºãããã§ãã
çŸåš
N
åã®ã€ãã³ãã®åè£ãããããç å宿ã®åå è
ã¯
M
人ã§ãã
i
åç®ã®ã€ãã³ãã®æéã®é·ãã¯
L_i
ã§ãããŸãã
i
åç®ã®ã€ãã³ãã«å¯Ÿãã
j
人ç®ã®åå è
ã®æºè¶³åºŠã¯
A_{i,j}
ã§ãã
1
å以äžã®è¡ãã€ãã³ããå®ãããšãããã®ã€ãã³ãã®éåã«å¯Ÿããè¯ãã¯å
šãŠã®äººã«å¯ŸããŠã®ã€ãã³ãã®æºè¶³åºŠã®æå€§å€ã®ç·åãšå®çŸ©ãããŸãã
äžæ¥ã®æéã¯éãããŠãããããã€ãã³ãã®æéã®é·ãã®åèšã¯
D
以äžã§ããå¿
èŠããããŸãããã®ãšããè¡ãã€ãã³ãã®éåã®è¯ãã¯æå€§ã§ããã€ã«ãªããŸããïŒ
ãã ããã€ãã³ããäžåãè¡ãããšãã§ããªãå Žåã¯ãã®ããšãå ±åããŠãã ããã | [
{
"input": "2 4 10\n5 6\n1 2 3 4\n5 6 7 8\n",
"output": "26\n"
},
{
"input": "1 4 10\n11\n3 6 1 8\n",
"output": "-1\n"
},
{
"input": "4 8 100\n30 40 50 110\n3 1 4 1 5 9 2 6\n5 3 5 8 9 7 9 3\n2 3 8 4 6 2 6 4\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "54\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_g | å顿
N
é ç¹ã®æ ¹ä»ãæšãäžããããŸããé ç¹ã«ã¯
1
ãã
N
ãŸã§ã®çªå·ãæ¯ãããŠãããæ ¹ã¯é ç¹
1
ã§ãé ç¹
i\,(2\leq i\leq N)
ã®èŠªã¯é ç¹
P_i
ã§ãã
Q
åã®è³ªåãäžããããã®ã§çããŠãã ããã
i
çªç®ã®è³ªåã§ã¯æŽæ°
X_i, Y_i
ãäžããããŸããé ç¹
X_i
ã¯é ç¹
Y_i
ã®ç¥å
ã§ãããäºé ç¹éã®è·é¢ã
d
ãšãããš
d\geq2
ã§ããé ç¹
X_i
ãš
Y_i
ãçµã¶ãã¹äžã®é ç¹ã®çªå·ãé ã«
v_0,v_1,\ldots,v_d
ïŒãã ãã
v_0=X_i, v_d=Y_i
ïŒãšãããšãã
v_1
ãåºåããŠãã ããã | [
{
"input": "7\n1 1 3 3 5 5\n3\n1 7\n3 6\n3 7\n",
"output": "3\n5\n5\n"
},
{
"input": "7\n1 2 3 4 5 6\n5\n1 6\n2 5\n3 7\n3 7\n1 4\n",
"output": "2\n3\n4\n4\n2\n"
},
{
"input": "7\n1 1 1 4 3 2\n3\n1 6\n1 7\n1 5\n",
"output": "3\n2\n4\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_h | å顿
hiikunZ åã¯ã¯ã€ãºå€§äŒã®äž»å¬è
ã§ãããåŸç¹ã®ç®¡çãèŠæã§ããããã§ãããªãããã¢ã¿ãã¯ãµãã€ãã«ããšããã«ãŒã«ã«ãããŠåŸç¹ã®ç®¡çãè¡ãããã°ã©ã ãæžããŠãããããšã«ããŸããã以äžã®åé¡ãè§£ãããã°ã©ã ãæžããŠãã ããã
ã¯ã€ãºå€§äŒã«
N
人ã®åå è
ãåå ããŠããŠã
1
ãã
N
ãŸã§ã®çªå·ãã€ããããŠããŸããååå è
ã¯ãäœåããšãããã©ã¡ãŒã¿ãæã£ãŠããŸããã¯ãããåå è
i
ã®äœåã¯
A_i
ã§ãããããŠ
Q
åã以äžã®
2
çš®é¡ã®ã€ãã³ããçºçããŸãã
1 x y
: åå è
x
ãé
ç¹
y
ã®åé¡ã«æ£è§£ããããããšãåå è
x
以å€ã®äœåã
0
ãã倧ãããã¹ãŠã®åå è
ã®äœåã
y
æžãã
2 x y
: åå è
x
ãé
ç¹
y
ã®åé¡ã«èª€çããããããšãåå è
x
ã®äœåã
y
æžãã
åã€ãã³ãããšã«ãã€ãã³ãã®åã«ã¯äœåã
0
ãã倧ããã£ãããã€ãã³ãã®åŸã«ã¯äœåã
0
以äžã«ãªã£ãåå è
ã®çªå·ã
æé ã«
åæããŠãã ããã | [
{
"input": "4 2\n5 5 5 10\n1 2 5\n2 4 5\n",
"output": "2 1 3\n1 4\n"
},
{
"input": "4 3\n20 10 5 5\n1 2 1\n1 2 500\n2 2 500\n",
"output": "0\n3 1 3 4\n1 2\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_i | å顿
ããªãã¯é·ã
N
ã®æ°å
X=(X_1,X_2,\ldots,X_N)
ãæã£ãŠããŸãããã
X
ã®åèŠçŽ ã®å
·äœçãªå€ã¯å¿ããŠããŸããŸãããããªãã¯æ¬¡ã®ããšãèŠããŠããŸãã
(15:18 ä¿®æ£)
X
ã®ãã¹ãŠã®èŠçŽ ã¯æ£æŽæ°ã§ããã
i=1,2,\ldots,P
ã«ã€ããŠã
X_{A_i}=X_{B_i}
i=1,2,\ldots,Q
ã«ã€ããŠã
X_{C_i}\neq X_{D_i}
X
ãšããŠèãããããã®ã®ãã¡ãèŸæžé ã§æå°ã®ãã®ãæ±ããŠãã ããããã ãã
X
ãšããŠèãããããã®ãååšããªãå Žåã¯ãã®ããšãå ±åããŠãã ããã | [
{
"input": "5 2 3\n1 2\n2 4\n1 3\n4 5\n3 5\n",
"output": "1 1 2 1 3\n"
},
{
"input": "5 1 1\n1 2\n1 2\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_j | å顿
ãç çåœã«ã¯
N
åã®è¡ãããã
1,2,3,\ldots,N
ãšçªå·ãã€ããŠããŸãã
çåœã«ã¯
N-1
æ¬ã®éè·¯ãããã
i
æ¬ç®ã®éè·¯ã¯è¡
A_i
ãšè¡
B_i
ãçµãã§ããŠã
C_i
ãšããéã¿ãå®ãŸã£ãŠããŸãããç çåœã®ãã¹ãŠã®è¡ã¯éè·¯ã䜿ã£ãŠè¡ãæ¥ããããšãã§ããŸãã
ãç çåœã® K åœçã¯å€ãã£ãŠããã®ã§ã
Q
åã®è¡ã®çµãããªãã«èšãæž¡ããåçµ
(S_i,T_i)(1 \leq i \leq Q)
ã«ã€ããŠè¡
S_i
ããè¡
T_i
ãžã®ãã¹äžã®éè·¯ã®éã¿ã®äžå€®å€ãæ±ããããšèšããŸãããå¬äœ¿ã®ããªã㯠K åœçã®ä»£ããã«çãæ±ãããå€ãæ±ããŠãããŠãã ããã
(2023/03/27 15:36远èš:) æ°å
X
ã«å¯Ÿããäžå€®å€ã¯ãèŠçŽ æ°ãå¶æ°ã®å Žåã¯èŠçŽ ãæé ã«äžŠã¹ãåã
X_1,X_2,...,X_n
ãšãããšãã
(X_{n/2} + X_{n/2+1}) / 2
ã§å®çŸ©ãããŸãã
奿°ã®å Žåã¯ãèŠçŽ ãæé ã«äžŠã¹ãåã
X_1,X_2,...,X_n
ãšãããšãã
X_{(n+1)/2}
ã§å®çŸ©ãããŸãã | [
{
"input": "5\n1 2 50\n2 3 100\n1 4 20\n4 5 30\n1\n3 5\n",
"output": "40\n"
},
{
"input": "3\n1 2 100\n2 3 50\n1\n1 3\n",
"output": "75\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_k | å顿
æ°å
X=(X_1,X_2,\ldots,X_M)
ã®
çŸãã
ã以äžã®ããã«å®ããŸãã
Y_i\coloneqq \max(X_1,X_2,\ldots,X_i)
ãšãããšãã®ã
Y_1,Y_2,\ldots,Y_M
ã«å«ãŸããæ°ã®çš®é¡æ°
é·ã
N
ã®æ°å
A=(A_1,A_2,\ldots,A_N)
ãäžããããŸãã
Q
åã®ã¯ãšãªãåŠçããŠãã ããã
i
çªç®ã®ã¯ãšãªã§ã¯æŽæ°
L_i,R_i
ãäžããããã®ã§ãæ°å
(A_{L_i},A_{L_i+1},\ldots,A_{R_i})
ã®
çŸãã
ãåºåããŠãã ããã | [
{
"input": "5\n1 5 2 4 3\n4\n1 5\n2 5\n3 3\n3 5\n",
"output": "2\n1\n1\n2\n"
},
{
"input": "5\n3 2 2 4 5\n4\n1 5\n1 5\n4 5\n4 5\n",
"output": "3\n3\n2\n2\n"
},
{
"input": "5\n4 4 1 3 5\n15\n1 1\n1 2\n1 3\n1 4\n1 5\n2 2\n2 3\n2 4\n2 5\n3 3\n3 4\n3 5\n4 4\n4 5\n5 5\n",
"output": "1\n1\n1\n1\n2\n1\n1\n1\n2\n1\n2\n3\n1\n2\n1\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_l | å顿
æéåã®éè² æŽæ°ãããªãå€ééå
S
ã«å¯ŸããŠã
\operatorname{mex}(S)
ã
S
ã«å«ãŸããªãæå°ã®éè² æŽæ°ãšå®çŸ©ããŸããäŸãã°ã
\operatorname{mex}(\lbrace 0,0,1,3 \rbrace)=2,\operatorname{mex}(\lbrace 1 \rbrace)=0,\operatorname{mex}(\lbrace\rbrace)=0
ã§ãã
黿¿ã«é·ã
N
ã®éè² æŽæ°å
A=(A_1,A_2,\ldots,A_N)
ãæžãããŠããŸãã
ããªãã¯ã以äžã®æäœãã¡ããã©
K
åè¡ããŸãã
A
ã®äžããéè² æŽæ°ã
0
å以äžéžã¶ãéžãã éè² æŽæ°ãããªãå€ééåã
S
ãšããŠã
\operatorname{mex}(S)
ã
A
ã®åŸãã«è¿œå ããã
æçµçã«é»æ¿ã«æžãããŠããéè² æŽæ°å
A
ãšããŠãããããã®ã®åæ°ã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããã | [
{
"input": "3 1\n0 1 3\n",
"output": "3\n"
},
{
"input": "5 10\n3 1 4 1 5\n",
"output": "14476910\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_m | å顿
é ç¹
1
ãæ ¹ãšãã
N
é ç¹ã®æ ¹ä»ãæšããããŸããé ç¹
i
ã®èŠªã¯é ç¹
P_i
ã§ããããããåé ç¹ã«
0
ãŸãã¯
1
ãæžã蟌ã¿ããã§ãã
以äžã®äžããããæ¡ä»¶ãæºãããããªé ç¹ã«å¯Ÿãã
0
ãš
1
ã®å²ãåœãŠæ¹ãäžã€æ±ããŠãã ããããŸãããã®ãããªå²ãåœãŠæ¹ãååšããªãå Žåã¯ãã®ããšãå ±åããŠãã ããã
K
åã®é ç¹
M_1 ,M_2, \cdots M_K
ã«ã¯ãããã
S_1 ,S_2, \cdots S_K
ãæžã蟌ãŸããŠããã
é ç¹
i
ã«
1
ãæžã蟌ãŸããŠãããªãã°ãé ç¹
A_i
ãšãã®åå«ã®é ç¹ã«ã¯
1
ãæžã蟌ãŸããŠããã
é ç¹
i
ã«
0
ãæžã蟌ãŸããŠãããªãã°ãé ç¹
A_i
ãšãã®åå«ã®é ç¹ã«ã¯
0
ãæžã蟌ãŸããŠããã | [
{
"input": "4\n1 1 2\n1\n2 1\n3 4 3 2\n",
"output": "1111\n"
},
{
"input": "5\n1 2 3 4\n2\n1 1\n2 0\n3 1 4 1 5\n",
"output": "IMPOSSIBLE\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_n | å顿
ã¯ããã«æŽæ°
T
ãäžããããŸãã
T
åã®ãã¹ãã±ãŒã¹ã«ã€ããŠæ¬¡ã®åé¡ãè§£ããŠãã ããã
hiikunZ åã¯ãèªçæ¥ãã¬ãŒã³ããšããŠãç ãã·ã³ãããããŸããã
ãç ãã·ã³ã«ã¯ããã£ã¹ãã¬ã€ãã©ã€ãããã¿ã³ã
1
ã€ãã€ã€ããŠããŸãã
ã¯ããããã£ã¹ãã¬ã€ã«ã¯æŽæ°
s
ã衚瀺ãããŠããŠãã©ã€ãã¯èµ€ã«ç¹ç¯ããŠããŸãã
hiikunZ åããã¿ã³ãæŒããã³ã«ããã£ã¹ãã¬ã€ã«è¡šç€ºãããæŽæ°
x
ãšã©ã€ãã®è²ã¯ã次ã®éãã«å€åããŸãã
ãã¿ã³ãæŒãåã«ãã©ã€ããèµ€ã«ç¹ç¯ããŠããå Žåã
x
ã¯
A_r \times x + B_r
ãçŽ æ°
P
ã§å²ã£ãããŸãã«å€åããã©ã€ãã¯éã«ç¹ç¯ããã
ãã¿ã³ãæŒãåã«ãã©ã€ããéã«ç¹ç¯ããŠããå Žåã
x
ã¯
A_b \times x + B_b
ãçŽ æ°
P
ã§å²ã£ãããŸãã«å€åããã©ã€ãã¯é»ã«ç¹ç¯ããã
ãã¿ã³ãæŒãåã«ãã©ã€ããé»ã«ç¹ç¯ããŠããå Žåã
x
ã¯
A_y \times x + B_y
ãçŽ æ°
P
ã§å²ã£ãããŸãã«å€åããã©ã€ãã¯èµ€ã«ç¹ç¯ããã
hiikunZ åã¯ãã¿ã³ãäœåã (
0
åã§ããã ) æŒãããšã§ãã£ã¹ãã¬ã€ã«è¡šç€ºãããŠããæŽæ°ã
t
ã«å€åããããã§ãã
ãããå¯èœãã©ããå€å®ããå¯èœãªå Žåã¯ãããéæããããã«å¿
èŠãªãã¿ã³ãæŒãåæ°ã®æå°å€ãæ±ããŠãã ããã | [
{
"input": "3\n1 8 13\n1 2 3 4 5 6\n0 1 3\n1 0 1 0 1 0\n123456789 634 998244353\n1 23 456 7890 123456789 987654321\n",
"output": "4\n-1\n164941630\n"
}
] |
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_o | å顿
ãç ã©ã³ãã«ã¯
N
åã®ã¢ãã©ã¯ã·ã§ã³ãããã
1
ãã
N
ãŸã§ã®çªå·ãã€ããããŠããŸãã
ãŸãããããã®ã¢ãã©ã¯ã·ã§ã³ãçµã¶éã
N - 1
æ¬ããã
1
ãã
N - 1
ãŸã§ã®çªå·ãã€ããããŠããŸãã
é
i
(1 \leq i \leq N - 1)
ã¯ã¢ãã©ã¯ã·ã§ã³
A_i
ãš ã¢ãã©ã¯ã·ã§ã³
B_i
ãåæ¹åã«çµãã§ããŸãã
ããã«ããç ã©ã³ãã®ããããã®éã«ã¯ã楜ããããšããå€ãèšå®ãããŠããŠãé
i
(1 \leq i \leq N - 1)
ã®æ¥œããã¯
C_i
ã§ãã
ãç ã©ã³ãã§ã®ã¢ãã©ã¯ã·ã§ã³éã®ç§»åãæ¥œãã¿ãã hiikunZ åã®ããã«ããã¹ãŠã®ã¢ãã©ã¯ã·ã§ã³
i
(1 \leq i \leq N)
ã«ã€ããŠã次ã®åé¡ãè§£ããŠãã ããã
hiikunZ åã¯ã¢ãã©ã¯ã·ã§ã³
i
ãããã¢ãã©ã¯ã·ã§ã³
i
ãšã¯ç°ãªãã¢ãã©ã¯ã·ã§ã³
j
(i \neq j,1 \leq j \leq N)
ã
1
ã€æ±ºããã¢ãã©ã¯ã·ã§ã³
i
ãã ã¢ãã©ã¯ã·ã§ã³
j
ã«éãéãåæ°ãæå°ã«ãªãããã«ç§»åããããšèããŠããŸãã
ã¢ãã©ã¯ã·ã§ã³
j
ãé©åã«éžãã ãšããhiikunZ åãéãéã®ã楜ãããã®å¹³åå€ãæå€§ã§ããã€ã«ã§ããããæ±ããŠãã ããã
ãã ããçãã¯æŽæ°ã§ã¯è¡šããªãå Žåãããã®ã§ãçãã®å°æ°ç¹ä»¥äžãåãæšãŠãå€ãåºåããŠãã ããã | [
{
"input": "3\n1 2 3\n2 3 6\n",
"output": "4\n6\n6\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_a | Problem Statement
You are given
N
strings
W_1,W_2,\dots,W_N
consisting of lowercase English letters.
If one or more of these strings equal
and
,
not
,
that
,
the
, or
you
, then print
Yes
; otherwise, print
No
. | [
{
"input": "10\nin that case you should print yes and not no\n",
"output": "Yes\n"
},
{
"input": "10\nin diesem fall sollten sie no und nicht yes ausgeben\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_b | Problem Statement
We have a board with
R
rows running horizontally and
C
columns running vertically. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
You are given characters
B_{i,j}
representing the current states of
(i,j)
.
.
represents an empty square;
#
represents a square with a wall;
1
,
2
,
\dots
,
9
represent a square with a bomb of power
1,2,\dots,9
, respectively.
At the next moment, all bombs will explode
simultaneously
.
When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square.
Here, the Manhattan distance from
(r_1,c_1)
to
(r_2,c_2)
is
|r_1-r_2|+|c_1-c_2|
.
Print the board after the explosions. | [
{
"input": "4 4\n.1.#\n###.\n.#2.\n#.##\n",
"output": "...#\n#...\n....\n#...\n"
},
{
"input": "2 5\n..#.#\n###.#\n",
"output": "..#.#\n###.#\n"
},
{
"input": "2 3\n11#\n###\n",
"output": "...\n..#\n"
},
{
"input": "4 6\n#.#3#.\n###.#.\n##.###\n#1..#.\n",
"output": "......\n#.....\n#....#\n....#.\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_c | Problem Statement
You have
N
socks. The color of the
i
-th sock is
A_i
.
You want to perform the following operation as many times as possible. How many times can it be performed at most?
Choose two same-colored socks that are not paired yet, and pair them. | [
{
"input": "6\n4 1 7 4 1 4\n",
"output": "2\n"
},
{
"input": "1\n158260522\n",
"output": "0\n"
},
{
"input": "10\n295 2 29 295 29 2 29 295 2 29\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_d | Problem Statement
The string
20230322
can be rearranged into
02320232
, which is a repetition of
0232
twice.
Similarly, a string consisting of digits is said to be
happy
when it can be rearranged into (or already is) a repetition of some string twice.
You are given a string
S
consisting of digits. Find the number of pairs of integers
(l,r)
satisfying all of the following conditions.
1 \le l \le r \le |S|
. (
|S|
is the length of
S
.)
The (contiguous) substring formed of the
l
-th through
r
-th characters of
S
is happy. | [
{
"input": "20230322\n",
"output": "4\n"
},
{
"input": "0112223333444445555556666666777777778888888889999999999\n",
"output": "185\n"
},
{
"input": "3141592653589793238462643383279502884197169399375105820974944\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_e | Problem Statement
We have a sequence of length
N
consisting of integers between
0
and
M
, inclusive:
A=(A_1,A_2,\dots,A_N)
.
Snuke will perform the following operations 1 and 2 in order.
For each
i
such that
A_i=0
, independently choose a uniform random integer between
1
and
M
, inclusive, and replace
A_i
with that integer.
Sort
A
in ascending order.
Print the expected value of
A_K
after the two operations, modulo
998244353
.
How to print a number modulo
998244353
?
It can be proved that the sought expected value is always rational.
Additionally, under the Constraints of this problem, when that value is represented as
\frac{P}{Q}
using two coprime integers
P
and
Q
, it can be proved that there is a unique integer
R
such that
R \times Q \equiv P\pmod{998244353}
and
0 \leq R \lt 998244353
. Print this
R
. | [
{
"input": "3 5 2\n2 0 4\n",
"output": "3\n"
},
{
"input": "2 3 1\n0 0\n",
"output": "221832080\n"
},
{
"input": "10 20 7\n6 5 0 2 0 0 0 15 0 0\n",
"output": "617586310\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_f | Problem Statement
You are given a string
S
consisting of digits and positive integers
L
and
R
for each of
T
test cases. Solve the following problem.
For a positive integer
x
, let us define
f(x)
as the number of contiguous substrings of the decimal representation of
x
(without leading zeros) that equal
S
.
For instance, if
S=
22
, we have
f(122) = 1
,
f(123) = 0
,
f(226) = 1
, and
f(222) = 2
.
Find
\displaystyle \sum_{k=L}^{R} f(k)
. | [
{
"input": "6\n22 23 234\n0295 295 295\n0 1 9999999999999999\n2718 998244353 9982443530000000\n869120 1234567890123456 2345678901234567\n2023032520230325 1 9999999999999999\n",
"output": "12\n0\n14888888888888889\n12982260572545\n10987664021\n1\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_g | Problem Statement
We have a directed graph
G_S
with
N
vertices numbered
1
to
N
.
It has
N-1
edges. The
i
-th edge
(1\leq i \leq N-1)
goes from vertex
p_i\ (1\leq p_i \leq i)
to vertex
i+1
.
We have another directed graph
G
with
N
vertices numbered
1
to
N
.
Initially,
G
equals
G_S
.
Process
Q
queries on
G
in the order they are given. There are two kinds of queries as follows.
1 u v
: Add an edge to
G
that goes from vertex
u
to vertex
v
.
It is guaranteed that the following conditions are satisfied.
u \neq v
.
On
G_S
, vertex
u
is reachable from vertex
v
via some edges.
2 x
: Print the smallest vertex number of a vertex reachable from vertex
x
via some edges on
G
(including vertex
x
). | [
{
"input": "5\n1 2 3 3\n5\n2 4\n1 4 2\n2 4\n1 5 1\n2 4\n",
"output": "4\n2\n1\n"
},
{
"input": "7\n1 1 2 2 3 3\n10\n2 5\n1 5 2\n2 5\n1 2 1\n1 7 1\n1 6 3\n2 5\n2 6\n2 1\n1 7 1\n",
"output": "5\n2\n1\n1\n1\n"
}
] |
https://atcoder.jp/contests/abc295/tasks/abc295_h | Problem Statement
We have a grid
A
with
N
rows and
M
columns. Initially,
0
is written on every square.
Let us perform the following operation.
For each integer
i
such that
1 \le i \le N
, in the
i
-th row, turn the digits in zero or more leftmost squares into
1
.
For each integer
j
such that
1 \le j \le M
, in the
j
-th column, turn the digits in zero or more topmost squares into
1
.
Let
S
be the set of grids that can be obtained in this way.
You are given a grid
X
with
N
rows and
M
columns consisting of
0
,
1
, and
?
.
There are
2^q
grids that can be obtained by replacing each
?
with
0
or
1
, where
q
is the number of
?
in
X
. How many of them are in
S
?
This count can be enormous, so find it modulo
998244353
. | [
{
"input": "2 3\n0?1\n?1?\n",
"output": "6\n"
},
{
"input": "5 3\n101\n010\n101\n010\n101\n",
"output": "0\n"
},
{
"input": "18 18\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n",
"output": "462237431\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_a | å顿
æ£æŽæ°
N
ã«å¯ŸããŠã
f(N)
ã以äžã§å®ããŸãã
N
ã®åæ¡ã®æ°åãäžŠã³æ¿ããŠåŸãããæŽæ°ã®éåã
S
ãšããããã ããäžŠã³æ¿ããçµæå
é ã«
0
ãç¶ãå Žå leading zero ãšããŠè§£éãããäŸãã°ã
N=102
ã®ãšã
S=\lbrace 12,21,102,120,201,210\rbrace
ã§ããã
S
ã®èŠçŽ å
šãŠãå²ãåãæå€§ã®æŽæ°ã
f(N)
ãšããã
10^{18}
以äžã®æ£æŽæ°
K
ãäžããããŸãã
f(N)=K
ãæºãããããª
10^{18}
以äžã®æ£æŽæ°
N
ãååšãããå€å®ããååšããå Žå
1
ã€æ±ããŠãã ããã
T
åã®ãã¹ãã±ãŒã¹ãäžããããã®ã§ãããããã«ã€ããŠçããŠãã ããã | [
{
"input": "2\n3\n10\n",
"output": "123\n-1\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_b | å顿
2
次å
å¹³é¢äžã« nok0 åãš
N
å¹ã®ã¹ã©ã€ã ãããŸããã¯ãã nok0 åã®åº§æšã¯
(0, 0)
ã
i\ (1\le i\le N)
çªç®ã®ã¹ã©ã€ã ã®åº§æšã¯
(X_i, Y_i)
ã§ãã
nok0 åã¯å¹³é¢äžã®ä»»æã®å°ç¹ã§äœåºŠã§ã以äžã®è¡åãã§ããŸãã
x
軞æ£è² æ¹åã
y
軞æ£è² æ¹åã®åèš
4
æ¹åã«åæã«ããŒã ãæã€ãnok0 åãšçãã
x
座æšãŸãã¯
y
座æšããã€ã¹ã©ã€ã ãæ¶æ»
ããã
nok0 åã¯å¹³é¢äžãä»»æã®æ¹åã«é£ç¶çã«ç§»åããããšãã§ããŸããnok0 åãå¹³é¢äžã«ãããã¹ãŠã®ã¹ã©ã€ã ãæ¶æ»
ãããã®ã«å¿
èŠãªç§»åè·é¢ã®æå°å€ãæ±ããŠãã ããã | [
{
"input": "3\n1 -1\n2 6\n8 3\n",
"output": "3.605551275463989\n"
},
{
"input": "1\n100000000 -100000000\n",
"output": "100000000.000000000000000\n"
},
{
"input": "18\n2092413 29557322\n-83061793 -86609930\n41750783 34587912\n94366440 62086679\n42714686 -18841496\n10264522 -60895144\n94721140 -72749181\n-68416594 -56662164\n85327102 82520146\n-97103434 30343456\n54136952 -27352836\n-38212546 92787647\n-72073444 28721824\n32088712 -55984481\n-38640098 22126296\n84969832 -72730101\n-4649799 14505075\n92214627 89508662\n",
"output": "225535157.051134686276782\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_c | å顿
UT åãš PC å㯠Nim ãšããã²ãŒã ã§éãã§ããŸãã
N
åã®æ£æŽæ°
A_1, A_2,\ldots, A_N
ã«å¯Ÿãã
\mathrm{Nim}(A_1, A_2, \ldots, A_N)
ãšã¯æ¬¡ã®ã²ãŒã ã®ããšãæããŸãã
ããã€ãã®ç³ãããªã
N
åã®å±±ããããã¯ãã
i\ (1\le i\le N)
çªç®ã®å±±ã«ã¯
A_i
åã®ç³ããããUT åããå§ããŠã
2
人ã¯äº€äºã«ä»¥äžã®æäœã
1
åãã€ç¹°ãè¿ãã
(æäœ)
ç³ã
1
åä»¥äžæ®ã£ãŠããå±±ã
1
ã€éžã¶ããã®å±±ããç³ã
1
å以äžåãé€ãã
ç³ãå
šãŠåãé€ãããæç¹ã§ã²ãŒã ãçµäºããæåŸã«æäœãè¡ã£ããã¬ã€ã€ãŒãåã¡ãããäžæ¹ã®ãã¬ã€ã€ãŒãè² ããšããã
ã²ãŒã éå§æç¹ããã²ãŒã çµäºæç¹ãŸã§ã«
2
人ãè¡ã£ãæäœã®åæ°ã®åèšã
T
ãšãããšããåã£ããã¬ã€ã€ãŒã
10^{100}-T
ç¹ãè² ãããã¬ã€ã€ãŒã
T-10^{100}
ç¹ãåŸãã
1 \le A_i \le M\ (1\le i\le N)
ãæºããé·ã
N
ã®æŽæ°å
(A_1, A_2, \ldots, A_N)
ã¯
M^N
éããããŸããããã®å
šãŠã«å¯ŸããŠã
2
人ã¯
1
åãã€
\mathrm{Nim}(A_1, A_2, \ldots, A_N)
ãéã³ãŸãã
ãããããå
šãŠã®ã²ãŒã ã§ç²åŸããç¹æ°ã®åèšãæå€§åããããã«è¡åãããšããããã
M^N
åã®ã²ãŒã ã®æäœåæ°ã®åèšã¯äœåã«ãªãã§ããããïŒçãã¯éåžžã«å€§ãããªãå¯èœæ§ãããã®ã§ã
998244353
ã§å²ã£ãäœããæ±ããŠãã ããã | [
{
"input": "2 2\n",
"output": "12\n"
},
{
"input": "4 5\n",
"output": "6748\n"
},
{
"input": "1 222\n",
"output": "222\n"
},
{
"input": "987654321 456\n",
"output": "897555885\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_d | å顿
ãã®åé¡ã¯
ã€ã³ã¿ã©ã¯ãã£ããªåé¡
ïŒããªãã®äœæããããã°ã©ã ãšãžã£ããžããã°ã©ã ãæšæºå
¥åºåãä»ããŠå¯Ÿè©±ãè¡ã圢åŒã®åé¡ïŒã§ãã
N
åã®ããããæå
ã«ãããŸãã
i
çªç®ã®ãããã®éãã
P_i
ãšãããšãã
(P_1, \dots, P_N)
ã¯
(1, \dots, N)
ã®é åãšãªãããšãåãã£ãŠããŸããã
P_i
ã®å
·äœçãªå€ã¯åãã£ãŠããŸããã ãŸãã
-2N
以äž
2N
以äžã®æŽæ°ã®ç®çããã€ããæ£ããäœçœ®
0
ã®ãšããã§ã€ããããŠããŸããç®çããã€ããŠããäœçœ®ã«ã¯ç©ŽãéããŠãããããããã®ç©Žã«ã¯
1
åãŸã§ããããã¶ãäžããããšãã§ããŸãã ã¯ããã¯ãããã
1
ã€ãã¶ãäžãã£ãŠããããæ£ã¯ã€ããã£ãŠããŸãã
zkou ããã¯æçµçã«ãæå
ã«ãã
N
åã®ãããããã¹ãŠæ£ã«ã¶ãäžããŠããªããã€æ£ãã€ããããããã§ãã
ããªã㯠zkou ããã«ä»¥äžã®ããããã®æäœãããããæç€ºã§ããŸãã
æå
ã«ãããããã
1
ã€éžã³ããããããŸã ã¶ãäžãã£ãŠããªã穎ã«ã¶ãäžããã
æ£ã«ã¶ãäžãã£ãŠãããããã
1
ã€éžã³ãæå
ã«æ»ãã
zkou
ããã¯æäœãçµãããã³ã«ãæ£ãå·Šå³ã©ã¡ãã«åŸãããããããã¯ã€ããã£ããããããªãã«äŒããŸãã
10000
å以äžã®æç€ºã§ãæå
ã«ãã
N
åã®ãããããã¹ãŠæ£ã«ã¶ãäžããŠããªããã€æ£ãã€ãããããŠãã ããã
ãªããå¶çŽäžã§åžžã«ã€ãããããæ¹æ³ãååšããããšã蚌æã§ããŸãã
æ£ã®åŸããšã€ãããã«ã€ããŠ
æ£ã«
k
åã®ããããã®ã£ãŠããŠã
j
çªç®ã®ããããéã
w_j
ã§äœçœ®
x_j
ã«ãããšããæ£ã®ã¢ãŒã¡ã³ã
M
ã
M = \sum_{j = 1}^{k} w_j x_j
ãšå®çŸ©ããŸãã
M > 0
ãªãæ£ãå³ã«åŸãã
M = 0
ãªãæ£ã¯ã€ãããã
M < 0
ãªãæ£ãå·Šã«åŸããŸãã | [] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_e | å顿
é·ã
N
ã®é å
P=(P_1,P_2,\ldots,P_N), Q=(Q_1,Q_2,\ldots,Q_N)
ããããŸããã¯ãã
P_i = Q_i = i
(1 \leq i \leq N)
ã§ãã
ãã®
2
ã€ã®é åã«å¯ŸããŠã以äžã®æäœã
0
å以äžå¥œããªã ãç¹°ãè¿ããŸãã
1 \le i \le M
ãæºããæŽæ°
i
ãéžã¶ã
P
ã®
a_i
çªç®ãš
b_i
çªç®ã®èŠçŽ ãå
¥ãæ¿ãã
Q
ã®
c_i
çªç®ãš
d_i
çªç®ã®èŠçŽ ãå
¥ãæ¿ããã
æäœåŸã®
P, Q
ã®ç¶æ
ã®çµãšããŠãããããã®ã®åæ°ã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããã | [
{
"input": "3 1\n1 2 2 3\n",
"output": "2\n"
},
{
"input": "4 3\n1 2 2 4\n2 3 1 2\n1 4 2 3\n",
"output": "288\n"
},
{
"input": "2 0\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_f | å顿
(1, 2, \ldots, N)
ã®é å
P = (P_1, P_2, \ldots, P_N)
ãšæŽæ°
K
ãäžããããŸãã
以äžã®ç䌌ã³ãŒãã§è¡šãããã¢ã«ãŽãªãºã ãå®è¡ããå Žåã(1) ã®åŒã¯äœåå®è¡ãããŸããïŒ
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N - i - K + 2; j++) {
if ((P[j], P[j + 1], ..., P[j + K - 1]) ãæé ã«äžŠãã§ããªã) {
(P[j], P[j + 1], ..., P[j + K - 1]) ãæé ã«äžŠã³æ¿ãã ... (1)
}
}
} | [
{
"input": "4 2\n1 3 4 2\n",
"output": "2\n"
},
{
"input": "6 3\n5 1 6 4 3 2\n",
"output": "6\n"
},
{
"input": "20 7\n10 17 8 1 16 13 14 5 20 19 4 15 18 3 11 2 12 9 7 6\n",
"output": "23\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_g | å顿
黿¿ã«
N
åã®æŽæ°
A_1, A_2, \ldots, A_N
ãæžãããŠããŸãã
ããªãã¯æ¬¡ã®æäœã
N - 1
åè¡ããŸãã
黿¿ã«æžãããŠããæ°ã
2
ã€éžãã§æ¶ããæ¶ããæ°ã
x
ãš
y
ãšããŠã
K - x - y
ãæ°ãã«é»æ¿ã«æžãã
N - 1
åã®æäœãçµããåŸã黿¿ã«ã¯ãã äžã€ã®æŽæ°ãæ®ããŸããããã®æŽæ°ãšããŠèããããæå€§å€ã¯ããã€ã§ããïŒ | [
{
"input": "4 3\n1 2 3 4\n",
"output": "7\n"
},
{
"input": "4 7\n1 2 3 4\n",
"output": "5\n"
},
{
"input": "10 3\n1 4 1 5 9 2 6 5 3 5\n",
"output": "32\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_h | å顿
æŽæ°
N
ãäžããããŸããããªãã¯ãæŽæ°
N
ã«å¯ŸããŠä»¥äžã®
æäœ
ã
1
åã ãè¡ããŸãã
æäœ
:
N
ã®æ¡ã®ãã¡ãããã€ãã®æ¡ãéžã³ïŒ
0
åã§ãè¯ãïŒãããããå
šãŠç¬ç«ã«
0
~
9
ã®ããããã«ç確çã§çœ®ãæããããã ããå
é ã«
0
ãç¶ãå Žå leading zero ãšããŠè§£éããã
ããªãã®ç®çã¯ãåºæ¥ãã ãé«ã確çã§
N
ã®å€ãæäœåããã倧ããããããšã§ããæé©ãªæŠç¥ããšã£ãå Žåã«æäœåã®
N
ããã倧ããæ°ãåŸããã確çã
\text{mod } 998244353
ã§æ±ããŠãã ããã
確ç
\text{mod } 998244353
ã®å®çŸ©
ãã®åé¡ã§æ±ãã確çã¯å¿
ãæçæ°ã«ãªãããšã蚌æã§ããŸãã
ãŸãããã®åé¡ã®å¶çŽäžã§ã¯ãæ±ãã確çãæ¢çŽåæ°
\frac{y}{x}
ã§è¡šãããšãã«
x
ã
998244353
ã§å²ãåããªãããšã蚌æã§ããŸãã
ãã®ãšã
xz \equiv y \pmod{998244353}
ãæºãããããª
0
以äž
998244352
以äžã®æŽæ°
z
ãäžæã«å®ãŸããŸãããã®
z
ãçããŠãã ããã | [
{
"input": "502\n",
"output": "509104621\n"
},
{
"input": "520\n",
"output": "698771048\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_i | å顿
(
,
)
ã®ã¿ãããªãæååã®ãã¡ã以äžã®ããããã«è©²åœãããã®ããæ£ããæ¬åŒ§åããšãããŸãã
空æåå
ãããæ£ããæ¬åŒ§åã
A
ãååšããŠ
(
,
A
,
)
ããã®é ã«ã€ãªããæåå
ãã空ã§ãªããæ£ããæ¬åŒ§åã
A,\ B
ãååšããŠ
A,\ B
ããã®é ã«ã€ãªããæåå
é·ã
4N
ã§
(
,
)
ã®ã¿ãããªãæåå
S
ãš
2N
åã®
2
æŽæ°ã®çµ
(L_i, R_i)\ (1\leq L_i < R_i \leq 4N)
ãäžããããŸããããã§ã
(L_1,L_2,\dots,L_{2N})
ã¯
(1,2,\dots,2N)
ã®ã
(R_1,R_2,\dots,R_{2N})
ã¯
(2N+1,2N+2,\dots,4N)
ã®é åã§ãã
i=1, 2,\dots,2N
ã®é ã«
S
ã®
L_i,\ R_i
æåç®ã®ããããã«å°ãã€ããåŸãå°ãã€ããæåã®ã¿ãå·Šããé ã«èªã¿ãé·ã
2N
ã®æååãšããŠè§£éãããã®ã
S'
ãšããŸãã
S'
ããæ£ããæ¬åŒ§åãã«ã§ãããå€å®ããŠãã ããã
T
åã®ãã¹ãã±ãŒã¹ã«ã€ããŠçããŠãã ããã | [
{
"input": "3\n1\n()()\n1 3\n2 4\n2\n))()((()\n1 6\n2 5\n3 7\n4 8\n8\n))()))))()())((((()))(()(()))(((\n8 26\n2 25\n1 18\n4 22\n7 17\n12 32\n10 31\n5 30\n15 27\n9 23\n13 19\n11 24\n14 29\n6 28\n16 20\n3 21\n",
"output": "Yes\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_j | å顿
(1,2,\ldots,N)
ã®é å
P = (P_1,P_2,\ldots,P_N)
ãäžããããŸããããªãã¯ä»¥äžã®æäœã
0
å以äž
15
å以äžè¡ãããšãã§ããŸãã
1\leq l \leq r \leq N
ãã€
r-l+1
ã奿°ã§ãããããªæŽæ°çµ
(l,r)
ãéžã³ãæ°å
(P_l,P_{l+1},\ldots,P_r)
ã®äžå€®å€ã
M
ãšããããã®ãšã
P_x = M
ãªãæŽæ°
x
ãäžæã«å®ãŸãã
P
ã®
l
çªç®ãã
x-1
çªç®ãïŒååšããã°ïŒæé ã«äžŠã³æ¿ãã
x+1
çªç®ãã
r
çªç®ãïŒååšããã°ïŒæé ã«äžŠã³æ¿ããã
æäœã«ãã£ãŠ
P
ãæé ã«äžŠã³æ¿ãããããå€å®ããå¯èœãªå Žåã¯ãã®ãããªæäœåãäžã€æ±ããŠãã ããã
äžå€®å€ãšã¯
é·ã
2n - 1
ã®æ°åã®äžå€®å€ã¯ãæ°åãæé ã«äžŠã³æ¿ãããšããåãã
n
çªç®ã®èŠçŽ ã®å€ãšããŠå®çŸ©ãããŸããäŸãã°ã
(5, 4,2)
ã®äžå€®å€ã¯
4
ã
(3,1,5,2,4)
ã®äžå€®å€ã¯
3
ã
(9)
ã®äžå€®å€ã¯
9
ã§ãã | [
{
"input": "5\n2 1 3 5 4\n",
"output": "1\n1 5\n"
},
{
"input": "4\n1 2 3 4\n",
"output": "2\n1 3\n2 4\n"
},
{
"input": "2\n2 1\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_k | å顿
2N\times 2M
ã®ã°ãªããç¶ã®ãã¹ç®ããããŸããäžãã
i
è¡ç®ãå·Šãã
j
åç®ã®ãã¹ç®ã
(i,j)
ã§è¡šããŸããã¯ãããåãã¹ã®è²ã¯ãã¹ãŠçœè²ã§ãã
ãããã以äžã®æ¡ä»¶ãæºããããã«
NM
åã®ãã¹ç®ãèµ€ãå¡ããŸãã
èµ€ãå¡ããããã¹ç®
(i,j)
ã«ã€ããŠ
i+j
ã¯å¶æ°ã§ããã
èµ€ãå¡ããããã¹ç®ã¯ç«¯ç¹ãå
±æããªããå³å¯ã«ã¯ãèµ€ãå¡ããã
2
ã€ã®ç°ãªããã¹ç®
(i,j),(k,l)
ã§ãã£ãŠã
|i-k|\leq 1
ãã€
|j-l| \leq 1
ãæºãããã®ãååšããªãã
K
åã®ãã¹ç®
(X_i,Y_i)
ã¯å¿
ãèµ€ãå¡ãã
æ¡ä»¶ãæºããããã«
NM
åã®ãã¹ç®ãèµ€ãå¡ãæ¹æ³ã®æ°ã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããã | [
{
"input": "2 2 1\n3 1\n",
"output": "3\n"
},
{
"input": "1 2 2\n1 1\n2 2\n",
"output": "0\n"
},
{
"input": "20 20 10\n26 26\n27 9\n7 21\n38 20\n30 34\n36 14\n17 7\n30 40\n19 3\n38 8\n",
"output": "908257345\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_l | å顿
N
人ãåå ããããããã倧äŒãéå¬ãããŸããåå è
ã¯ã人
1
ã人
2
ã
\ldots
ã人
N
ãšåŒã°ããŸããã©ã®åå è
ãããããåŸæãªæãæã£ãŠããŠãæ¯è©ŠååŸæãªæã®ã¿ãåºããŸãã
åå è
ã®åŸæãªæã¯ã
R
,
P
,
S
ãããªãé·ã
N
ã®æåå
S
ã«ãã£ãŠè¡šãããŸãã人
i
ã®åŸæãªæã¯ã
S
ã®
i
æåç®
S_i
ã§ããããã§æå
R
ã¯ã°ãŒãã
P
ã¯ããŒãã
S
ã¯ãã§ãã衚ããŸãã
倧äŒã§ã¯ã人
1
ã人
2
ã
\ldots
ã人
N
ããã®é ã«æšªäžåã«äžŠã¹ãåŸã
0
å以äžã®ã詊åããè¡ããŸããã詊åãã¯ã次ã®ããã«è¡ãããŸãã
åã§é£ãåã£ãŠãã
2
人ã§ãã£ãŠããããããããããšãã«ãããã«ãªããªããããª
2
人ãç¡äœçºã«éžã³ãããããããããããè² ããã»ãã®äººãåããæããããã
ã詊åããè¡ããªããªã£ãæç¹ã§ãåã«æ®ã£ãŠãã人å
šå¡ã®åªåãšãªããŸããç¹ã«ãåã«æ®ã£ãŠãã人ã
1
人ã ãã«ãªã£ãå Žåããã®äººã®åç¬åªåãšãªããŸãã
åç¬åªåããå¯èœæ§ã®ãã人ã®äººæ°ãæ±ããŠãã ããã
ãããããã®ã«ãŒã«
ãããããã®çµæã¯ã
2
人ã®åºããæã«å¿ããŠæ¬¡ã®ããã«æ±ºãŸããŸãã
äžæ¹ãã°ãŒã§ä»æ¹ããã§ãã®ãšããã°ãŒãåºãã人ãåã¡ããã§ããåºãã人ã¯è² ã
äžæ¹ããã§ãã§ä»æ¹ãããŒã®ãšãããã§ããåºãã人ãåã¡ãããŒãåºãã人ã¯è² ã
äžæ¹ãããŒã§ä»æ¹ãã°ãŒã®ãšããããŒãåºãã人ãåã¡ãã°ãŒãåºãã人ã¯è² ã
äž¡è
ãåãæãåºãããšãããããïŒåŒãåãïŒ | [
{
"input": "4\nRSPR\n",
"output": "2\n"
},
{
"input": "3\nRSR\n",
"output": "0\n"
},
{
"input": "6\nSRPPSR\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_m | å顿
é·ã
n
ã®éè² æŽæ°å
X=(X_1,X_2,\dots,X_n)
ã«å¯Ÿã
f(X)
ãã
Y_1+Y_2+\dots+Y_n=X_1+X_2+\dots+X_n
ãæºããé·ã
n
ã®éè² æŽæ°å
Y=(Y_1,Y_2,\dots,Y_n)
å
šãŠã«ããã
Y_1 \oplus Y_2 \oplus \dots \oplus Y_n
ã®æå°å€ãšããŸãããã ãããã§ã
\oplus
ã¯ãããåäœ
\mathrm{XOR}
æŒç®ã衚ããŸãã
é·ã
N
ã®éè² æŽæ°å
A=(A_1,A_2,\dots,A_N)
ãäžããããŸãã
A
ã®ç©ºã§ãªãéšåå
B
ã¯
2^N-1
åèããããŸãããããããã¹ãŠã«å¯Ÿãã
f(B)
ã®ç·åã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããã
ãããåäœ
\mathrm{XOR}
æŒç®ãšã¯
éè² æŽæ°
A, B
ã®ãããåäœ
\mathrm{XOR}
ã
A \oplus B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A \oplus B
ãäºé²è¡šèšããéã®
2^k
(
k \geq 0
) ã®äœã®æ°ã¯ã
A, B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡äžæ¹ã®ã¿ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3 \oplus 5 = 6
ãšãªããŸã (äºé²è¡šèšãããš:
011 \oplus 101 = 110
)ã
äžè¬ã«
k
åã®éè² æŽæ°
p_1, p_2, p_3, \dots, p_k
ã®ãããåäœ
\mathrm{XOR}
ã¯
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
ãšå®çŸ©ãããããã¯
p_1, p_2, p_3, \dots, p_k
ã®é çªã«ãããªãããšã蚌æã§ããŸãã | [
{
"input": "3\n0 1 2\n",
"output": "8\n"
},
{
"input": "15\n99412 355422 750910 993699 41414 435678 325371 637849 939332 512546 112254 175315 865362 459658 311661\n",
"output": "7032514\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_n | å顿
æŽæ°
N
ãšã
0
ãš
1
ã®ã¿ãããªãé·ã
N
ã®æåå
T
ãäžããããŸãã
0
ãš
1
ã®ã¿ãããªããé·ã
2N
ã®æåå
S = s_1 s_2 \ldots s_{2N}
ãš
T
ãçšããŠãAlice ãš Bob ãã²ãŒã ãããŸããäºäººã¯ Alice ããå§ããŠã
S
ã®å
šãŠã®æåã«å°ãã€ããŸã§äº€äºã«ä»¥äžã®æäœãããŸãã
1 \le i \le 2N
ãæºããæŽæ°
i
ã§ãã£ãŠã
s_i
ã«ãŸã å°ãã€ããŠããªããããªãã®ãéžã¶ããã®åŸã
Alice ã®æçªã§ããã°ããã®æ¡ã«
o
ã®å°ãã€ããã
Bob ã®æçªã§ããã°ããã®æ¡ã«
x
ã®å°ãã€ããã
ã²ãŒã ãçµäºããæã«ã
o
ã®å°ãã€ããŠããæ¡ã ããå·Šããèªã¿ã
N
æåã®æååãšããŠè§£éãããã®ããèŸæžé ã§
T
以äžã§ããã° Alice ã®åå©ãããã§ãªããã° Bob ã®åå©ã§ãã
éå§æã«çšããæåå
S
ãšããŠèãããããã®ã¯
2^{2N}
éããããŸãããã®ãã¡ãäž¡è
ãããããèªèº«ãåã€ããã«æé©ãªæŠç¥ããšãå Žåã«ã Alice ãåã€ãããªãã®ã®åæ°ã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããã | [
{
"input": "1\n0\n",
"output": "4\n"
},
{
"input": "1\n1\n",
"output": "3\n"
},
{
"input": "12\n011011000111\n",
"output": "13225655\n"
}
] |
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_o | å顿
é ç¹
1
ãæ ¹ãšããã
N
é ç¹ã®æ ¹ä»ãæšããããŸããé ç¹
i
(2 \le i \le N)
ã®èŠªã¯
P_i
ã§ããé ç¹
1
ã«ã¯æ€
åã
10^{100}
å眮ããŠããããã以å€ã®é ç¹ã«ã¯æ€
åã
1
åãã€çœ®ããŠãããŸããããããã®æ€
åã«ã¯ã人ã
1
人ãŸã§åº§ãããšãã§ããŸãã
ãããã
M
人ã®äººãã¡ãé çªã«ãã®æšã«äŒæ©ãã«èšªããŸãã
i = 1, 2, \dots, M
ã®é ã«ã
i
çªç®ã®äººã¯ä»¥äžã®è¡åããšããŸãã
é ç¹
A_i
ã«èšªããããã®åŸã空ããŠããæ€
åãããé ç¹ã«ãã©ãçããŸã§æ ¹ã®æ¹åã«åãã£ãŠé²ãã空ããŠããæ€
åãããé ç¹ã«ãã©ãçãããããã®æ€
åã«åº§ãè¡åãçµäºããã
å
šå¡ãè¡åãçµäºãããŸã§ã«
i
çªç®ã®äººãéãèŸºã®æ¬æ°ã
d_i
ãšãããšãã«ã
d_1 + d_2 + \dots + d_M
ã®å€ãæ±ããŠãã ããã | [
{
"input": "3\n1 1\n4\n1 2 3 2\n",
"output": "1\n"
},
{
"input": "7\n1 1 3 4 5 5\n6\n3 5 3 6 6 2\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_a | Problem Statement
You are given a sequence of
N
integers:
A=(A _ 1,A _ 2,\ldots,A _ N)
.
Print all even numbers in
A
without changing the order. | [
{
"input": "5\n1 2 3 5 6\n",
"output": "2 6\n"
},
{
"input": "5\n2 2 2 3 3\n",
"output": "2 2 2\n"
},
{
"input": "10\n22 3 17 8 30 15 12 14 11 17\n",
"output": "22 8 30 12 14\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_b | Problem Statement
You are given an
H
-by-
W
matrix
A
consisting of integers between
0
and
26
. The element at the
i
-th row from the top and
j
-th column from the left is
A_{i,j}
.
Let
S_1, S_2, \dots, S_H
be
H
strings of length
W
that satisfy the following.
The
j
-th character of
S_i
is a period (
.
) if
A_{i,j}
is
0
, and the
A_{i,j}
-th uppercase English letter otherwise. (For instance, the
4
-th letter is
D
.)
Print
S_1, S_2, \dots, S_H
in order. | [
{
"input": "2 3\n0 1 2\n0 0 3\n",
"output": ".AB\n..C\n"
},
{
"input": "3 3\n24 0 0\n0 25 0\n0 0 26\n",
"output": "X..\n.Y.\n..Z\n"
},
{
"input": "3 1\n2\n9\n4\n",
"output": "B\nI\nD\n"
},
{
"input": "24 60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 13 14 0 0 0 10 0 0 0 0 0 15 24 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 23 7 25 24 13 10 0 10 12 0 0 0 0 19 9 23 0 0 0 0 10 10 14 0 0 0 10 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 13 5 0 0 23 11 14 14 0 0 12 9 1 21 19 0 0 9 12 10 25 3 10 6 0 0 9 13 23 24 14 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 14 6 0 0 0 10 5 25 13 0 0 25 0 0 0 0 0 0 0 0 0 0 10 16 0 0 13 21 13 13 14 23 14 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 13 8 2 0 0 0 0 0 13 11 13 19 0 0 1 2 5 9 12 12 5 9 9 20 6 0 14 14 14 9 0 0 0 14 14 18 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 10 23 13 13 13 13 13 13 14 14 14 13 14 14 13 7 0 0 0 0 0 0 0 0 0 0 0 0 13 13 13 2 0 0 0 0 13 11 13 16 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 13 1 0 0 0 9 20 9 20 20 20 20 13 20 20 13 20 23 8 8 8 20 8 20 7 8 17 7 10 13 14 13 19 0 0 0 0 0 22 14 25 13 16 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 13 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 20 20 13 13 7 20 26 13 8 6 14 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 5 0 0 0 0 0 0 0 1 2 20 20 23 13 2 7 2 10 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 20 23 13 0 0 0 0 0 0 0 0 0\n0 0 0 0 13 0 0 0 0 0 0 0 0 1 0 0 0 13 12 9 14 13 13 9 9 20 12 0 0 0 0 0 0 0 0 0 0 0 1 9 9 9 9 12 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0\n0 0 0 2 0 0 0 0 0 0 0 0 0 0 19 0 0 14 13 14 14 13 13 0 0 9 5 16 0 0 0 0 0 0 5 20 20 13 2 2 20 9 13 14 14 20 12 12 0 0 0 0 9 13 0 0 0 0 0 0\n0 0 1 9 0 0 0 0 0 0 0 0 0 0 0 13 10 13 13 13 13 2 5 12 10 5 0 0 0 0 0 0 0 0 20 16 0 0 0 13 14 13 13 13 13 0 0 10 8 0 0 0 0 0 20 7 0 0 0 0\n0 0 4 2 0 0 0 0 0 0 0 0 0 0 0 0 9 7 14 10 10 14 13 5 0 0 0 0 0 0 0 0 0 0 0 23 13 12 13 13 13 13 13 9 13 0 14 4 0 0 0 0 0 0 0 9 16 0 0 0\n0 0 22 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 13 13 13 2 9 14 2 20 14 0 0 0 0 0 0 0 0 0 2 0 0 0\n0 0 0 5 13 0 0 0 2 7 13 13 13 13 13 13 13 2 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 20 20 9 0 0 0 0 0 0 0 0 0 0 0 0 0 19 0 0 0\n0 0 0 0 20 13 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 14 7 2 20 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 6 0 0 0\n0 0 0 0 0 0 9 14 14 0 0 20 20 13 13 20 13 9 0 0 10 0 0 0 0 0 0 9 23 13 9 0 0 0 0 0 0 0 10 6 0 0 7 0 0 9 20 13 13 14 2 0 0 0 0 5 0 0 0 0\n0 0 0 0 0 0 0 0 20 13 14 0 0 0 0 0 0 0 0 13 9 0 0 0 0 0 0 0 0 13 11 0 0 0 0 0 0 0 14 9 0 0 0 20 25 14 7 0 0 0 0 9 1 14 7 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 9 13 13 20 0 0 0 0 0 9 12 0 0 0 0 0 0 0 14 13 14 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 9 9 20 14 14 4 14 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 2 9 0 0 0 0 9 9 20 21 7 13 20 0 0 20 23 7 7 2 12 7 6 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 20 9 9 20 24 10 12 10 0 0 0 0 0 0 0 0 20 20 0 0 0 0 0 20 7 7 13 22 2 5 9 2 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 20 5 20 5 2 5 7 20 5 14 14 5 11 5 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "................................B...........................\n...................MMN...J.....OXN..........................\n.................MWGYXMJ.JL....SIW....JJN...JN..............\n...............IME..WKNN..LIAUS..ILJYCJF..IMWXN.............\n..............MNF...JEYM..Y..........JP..MUMMNWN............\n.............MHB.....MKMS..ABEILLEIITF.NNNI...NNR...........\n..........JWMMMMMMNNNMNNMG............MMMB....MKMP..........\n........MA...ITITTTTMTTMTWHHHTHTGHQGJMNMS.....VNYMP.........\n......MI...............................TTTMMGTZMHFN.........\n.....E.......ABTTWMBGBJL.......................TTWM.........\n....M........A...MLINMMIITL...........AIIIIL.......T........\n...B..........S..NMNNMM..IEP......ETTMBBTIMNNTLL....IM......\n..AI...........MJMMMMBELJE........TP...MNMMMM..JH.....TG....\n..DB............IGNJJNME...........WMLMMMMMIM.ND.......IP...\n..VM.................................TMMMBINBTN.........B...\n...EM...BGMMMMMMMBI....................ITTI.............S...\n....TML..................UNGBTX........................IF...\n......INN..TTMMTMI..J......IWMI.......JF..G..ITMMNB....E....\n........TMN........MI........MK.......NI...TYNG....IANG.....\n..........IMMT.....IL.......NMN.......F........IITNNDN......\n..............TBI....IITUGMT..TWGGBLGF............EE........\n.................TTIITXJLJ........TT.....TGGMVBEIB..........\n.........................ITETEBEGTENNEKEB...................\n............................................................\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_c | Problem Statement
You are given strictly increasing sequences of length
N
and
M
:
A=(A _ 1,A _ 2,\ldots,A _ N)
and
B=(B _ 1,B _ 2,\ldots,B _ M)
.
Here,
A _ i\neq B _ j
for every
i
and
j
(1\leq i\leq N,1\leq j\leq M)
.
Let
C=(C _ 1,C _ 2,\ldots,C _ {N+M})
be a strictly increasing sequence of length
N+M
that results from the following procedure.
Let
C
be the concatenation of
A
and
B
. Formally, let
C _ i=A _ i
for
i=1,2,\ldots,N
, and
C _ i=B _ {i-N}
for
i=N+1,N+2,\ldots,N+M
.
Sort
C
in ascending order.
For each of
A _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M
, find its position in
C
.
More formally, for each
i=1,2,\ldots,N
, find
k
such that
C _ k=A _ i
, and for each
j=1,2,\ldots,M
, find
k
such that
C _ k=B _ j
. | [
{
"input": "4 3\n3 14 15 92\n6 53 58\n",
"output": "1 3 4 7\n2 5 6\n"
},
{
"input": "4 4\n1 2 3 4\n100 200 300 400\n",
"output": "1 2 3 4\n5 6 7 8\n"
},
{
"input": "8 12\n3 4 10 15 17 18 22 30\n5 7 11 13 14 16 19 21 23 24 27 28\n",
"output": "1 2 5 9 11 12 15 20\n3 4 6 7 8 10 13 14 16 17 18 19\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_d | Problem Statement
N
people, with ID numbers
1
,
2
,
\dots
,
N
, are lining up in front of a bank.
There will be
Q
events. The following three kinds of events can happen.
1
: The teller calls the person with the smallest ID number who has not been called.
2 x
: The person with the ID number
x
comes to the teller for the first time. (Here, person
x
has already been called by the teller at least once.)
3
: The teller again calls the person with the smallest ID number who has already been called but has not come.
Print the ID numbers of the people called by the teller in events of the third kind. | [
{
"input": "4 10\n1\n1\n3\n2 1\n1\n2 3\n3\n1\n2 2\n3\n",
"output": "1\n2\n4\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_e | Problem Statement
We have a grid with
2
rows and
L
columns.
Let
(i,j)
denote the square at the
i
-th row from the top
(i\in\lbrace1,2\rbrace)
and
j
-th column from the left
(1\leq j\leq L)
.
(i,j)
has an integer
x _ {i,j}
written on it.
Find the number of integers
j
such that
x _ {1,j}=x _ {2,j}
.
Here, the description of
x _ {i,j}
is given to you as the run-length compressions of
(x _ {1,1},x _ {1,2},\ldots,x _ {1,L})
and
(x _ {2,1},x _ {2,2},\ldots,x _ {2,L})
into sequences of lengths
N _ 1
and
N _ 2
, respectively:
((v _ {1,1},l _ {1,1}),\ldots,(v _ {1,N _ 1},l _ {1,N _ 1}))
and
((v _ {2,1},l _ {2,1}),\ldots,(v _ {2,N _ 2},l _ {2,N _ 2}))
.
Here, the run-length compression of a sequence
A
is a sequence of pairs
(v _ i,l _ i)
of an element
v _ i
of
A
and a positive integer
l _ i
obtained as follows.
Split
A
between each pair of different adjacent elements.
For each sequence
B _ 1,B _ 2,\ldots,B _ k
after the split, let
v _ i
be the element of
B _ i
and
l _ i
be the length of
B _ i
. | [
{
"input": "8 4 3\n1 2\n3 2\n2 3\n3 1\n1 4\n2 1\n3 3\n",
"output": "4\n"
},
{
"input": "10000000000 1 1\n1 10000000000\n1 10000000000\n",
"output": "10000000000\n"
},
{
"input": "1000 4 7\n19 79\n33 463\n19 178\n33 280\n19 255\n33 92\n34 25\n19 96\n12 11\n19 490\n33 31\n",
"output": "380\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_f | Problem Statement
Takahashi and Aoki have
N
and
M
bottles of sugar water, respectively.
Takahashi's
i
-th sugar water is composed of
A_i
grams of sugar and
B_i
grams of water.
Aoki's
i
-th sugar water is composed of
C_i
grams of sugar and
D_i
grams of water.
There are
NM
ways to choose one from Takahashi's sugar waters and one from Aoki's and mix them. Among the
NM
sugar waters that can be obtained in this way, find the concentration of sugar in the sugar water with the
K
-th highest concentration of sugar.
Here, the concentration of sugar in sugar water composed of
x
grams of sugar and
y
grams of water is
\dfrac{100x}{x+y}
percent. We will ignore saturation. | [
{
"input": "3 1 1\n1 2\n4 1\n1 4\n1 4\n",
"output": "50.000000000000000\n"
},
{
"input": "2 2 2\n6 4\n10 1\n5 8\n9 6\n",
"output": "62.500000000000000\n"
},
{
"input": "4 5 10\n5 4\n1 6\n7 4\n9 8\n2 2\n5 6\n6 7\n5 3\n8 1\n",
"output": "54.166666666666664\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_g | Problem Statement
You are given a tree
T
with
N
vertices.
Edge
i
(1\leq i\leq N-1)
connects vertices
u _ i
and
v _ i
, and has a weight of
w _ i
.
Process
Q
queries in order. There are two kinds of queries as follows.
1 i w
: Change the weight of edge
i
to
w
.
2 u v
ïŒPrint the distance between vertex
u
and vertex
v
.
Here, the distance between two vertices
u
and
v
of a tree is the smallest total weight of edges in a path whose endpoints are
u
and
v
. | [
{
"input": "5\n1 2 3\n1 3 6\n1 4 9\n4 5 10\n4\n2 2 3\n2 1 5\n1 3 1\n2 1 5\n",
"output": "9\n19\n11\n"
},
{
"input": "7\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n3\n2 1 6\n1 1 294967296\n2 1 6\n",
"output": "5000000000\n4294967296\n"
},
{
"input": "1\n1\n2 1 1\n",
"output": "0\n"
},
{
"input": "8\n1 2 105\n1 3 103\n2 4 105\n2 5 100\n5 6 101\n3 7 106\n3 8 100\n18\n2 2 8\n2 3 6\n1 4 108\n2 3 4\n2 3 5\n2 5 5\n2 3 1\n2 4 3\n1 1 107\n2 3 1\n2 7 6\n2 3 8\n2 1 5\n2 7 6\n2 4 7\n2 1 7\n2 5 3\n2 8 6\n",
"output": "308\n409\n313\n316\n0\n103\n313\n103\n525\n100\n215\n525\n421\n209\n318\n519\n"
}
] |
https://atcoder.jp/contests/abc294/tasks/abc294_h | Problem Statement
You are given a simple undirected graph with
N
vertices numbered
1
to
N
and
M
edges numbered
1
to
M
. Edge
i
connects vertex
u_i
and vertex
v_i
.
Find the number, modulo
998244353
, of ways to write an integer between
1
and
K
, inclusive, on each vertex of this graph to satisfy the following condition:
two vertices connected by an edge always have different numbers written on them. | [
{
"input": "4 3 2\n1 2\n2 4\n2 3\n",
"output": "2\n"
},
{
"input": "4 0 10\n",
"output": "10000\n"
},
{
"input": "5 10 5\n3 5\n1 3\n1 2\n1 4\n3 4\n2 5\n4 5\n1 5\n2 3\n2 4\n",
"output": "120\n"
},
{
"input": "5 6 294\n1 2\n2 4\n1 3\n2 3\n4 5\n3 5\n",
"output": "838338733\n"
},
{
"input": "7 12 1000000000\n4 5\n2 7\n3 4\n6 7\n3 5\n5 6\n5 7\n1 3\n4 7\n1 5\n2 3\n3 6\n",
"output": "418104233\n"
}
] |
https://atcoder.jp/contests/ahc019/tasks/ahc019_a | Problem Statement
AtCoder is developing an educational toy that combines blocks to create a three-dimensional object with a specified silhouette.
The toy consists of a set of polycube-shaped blocks consisting of
1\times 1\times 1
cubes joined face to face and a pair of two 2D monochrome silhouette images.
You will win the game if you can construct a single 3D object by combining the blocks, so that the two silhouettes of the created object, viewed from the front and from the right side, completely match the given silhouette images.
In order to allow children to play for a long time, we want to prepare multiple pairs of silhouettes for a single set of blocks.
For example, the set of 6 blocks shown on the left figure can be used to create two pairs of silhouettes, as shown on the right.
As a toy designer, you are given two pairs of front/right silhouettes, and your task is to find a set of blocks from which you can construct two objects having the given pairs of silhouettes, and a way to construct them.
Because children may accidentally swallow small blocks, sets of blocks consisting only of a small number of large blocks are preferable.
Detailed puzzle rules
You don't have to use all the blocks (but you will get a better score if you do).
Each block can be rotated by 90 degrees around the x-axis, y-axis, and z-axis, but cannot be flipped.
The blocks must be arranged so that each vertex has integer coordinates, and different blocks must not have a positive common volume.
The constructed object do not have to be connected. For the sake of simplicity, we assume that a floating arrangement is also possible (you may interpret this as there are a large number of additional transparent blocks, which can be used to support blocks).
About silhouette
Take the x-axis from left to right, the y-axis from front to back, and the z-axis from top to bottom.
We assume that all blocks are within a cubic region that has
(0,0,0)
and
(D,D,D)
as diagonal corners.
We define a three-dimensional 01-array
b(x,y,z)
as
b(x,y,z)=1
if some block occupies the cubic region that has
(x,y,z)
and
(x+1,y+1,z+1)
as diagonal corners, and
b(x,y,z)=0
otherwise.
Then, the silhouette viewed from the front is a two-dimensional 01-array
f(z,x)
defined as follows.
\[
f(z,x)=\begin{cases}
1&(\sum_{y=0}^{D-1}b(x,y,z)\geq 1)\\
0&(\sum_{y=0}^{D-1}b(x,y,z)=0)
\end{cases}
\]
Similarly, the silhouette viewed from the right is a two-dimensional 01-array
r(z,y)
, defined as follows
\[
r(z,y)=\begin{cases}
1&(\sum_{x=0}^{D-1}b(x,y,z)\geq 1)\\
0&(\sum_{x=0}^{D-1}b(x,y,z)=0)
\end{cases}
\] | [
{
"input": "5\n10001\n11011\n11111\n10101\n10001\n01110\n11011\n10000\n11011\n01110\n11110\n00011\n01110\n11000\n11111\n11110\n00011\n01110\n00011\n11110\n",
"output": "19\n0 1 2 3 0 4 5 0 3 3 6 0 0 0 3 7 7 0 3 3 0 7 0 8 0 0 5 9 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 9 10 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 9 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 12 12 0 13 0 0 12 14 0 0 0 0 14 0 0 0 14 14 0 0 0 14 0\n15 0 0 0 3 14 0 0 0 3 0 0 0 0 9 16 0 0 9 9 0 0 0 17 0 0 0 0 0 0 14 0 10 0 3 14 0 10 0 9 0 0 0 18 0 0 0 0 0 0 0 0 0 0 3 0 0 12 0 3 14 0 12 0 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 12 0 0 14 0 7 0 0 0 7 7 0 5 0 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 7 0 0 5 0 0 0 0 0\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_a | å顿
N
è¡
M
åãããªãç€é¢ãããïŒåãã¹ç®ã«ã¯ row-major é ã«
1
ãã
N \times M
ãŸã§ã®æŽæ°ãæžãããŠããŸãïŒ
ã€ãŸãïŒäžãã
i
è¡ç®ïŒå·Šãã
j
åç®ã®ãã¹ã«æžãããŠããæŽæ°ã
A_{i,j}
ã§è¡šãããšã«ãããšïŒ
A_{i,j}=(i-1) \times M + j
ã§ãïŒ
ãã®ç€é¢ã®éšåé·æ¹åœ¢ã§ãã£ãŠïŒãã®å
éšã«æžãããå€ã®ç·åãã¡ããã©
V
ã«ãªããã®ã®åæ°ãæ°ããŠãã ããïŒ
ããå³å¯ã«èšãã°ïŒæŽæ°ã®
4
ã€çµ
(a,b,c,d)
(
1 \leq a \leq b \leq N
,
1 \leq c \leq d \leq M
) ã§ãã£ãŠïŒ
\sum_{a \leq i \leq b,\ c \leq j \leq d} A_{i,j}=V
ãæºãããã®ã®åæ°ãæ°ããŠãã ããïŒ | [
{
"input": "2 2 3\n",
"output": "2\n"
},
{
"input": "2 2 5\n",
"output": "0\n"
},
{
"input": "13 8 1032\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_b | å顿
1
ãã
N
ãŸã§ã®çªå·ãã€ãã
N
åã®ã¯ã€ãºãããïŒããªãã¯ãããã䜿ã£ãã²ãŒã ã«åå ããŸãïŒ
ãã®ã²ãŒã ã§ã¯ïŒããªãã¯ã¯ã€ãºã«
1
åãã€åçããŠãããŸãïŒ
ã¯ã€ãºã«åçããé çªã¯èªç±ã«éžã¶ããšãã§ããŸãïŒ
ã¯ã€ãº
i
ã«åçãããš
P_i
% ã®ç¢ºçã§æ£è§£ããŸãïŒ
æ£è§£ããå ŽåïŒããªãã¯
S_i
ç¹ãç²åŸãïŒïŒãŸã æªåçã®ã¯ã€ãºããããªãïŒæ¬¡ã®ã¯ã€ãºã®åçãžãšç§»ããŸãïŒ
æ£è§£ããªãã£ãå ŽåïŒå³åº§ã«ã²ãŒã ãçµäºãïŒæ®ãã®ã¯ã€ãºã«åçããããšãã§ããªããªããŸãïŒ
ããªãã¯ïŒç²åŸããåŸç¹ã®åèšã®æåŸ
å€ãæå€§åãããã§ãïŒ
ç®çãéæããããã®æŠç¥ïŒïŒã¯ã€ãºã«åçããé çªïŒãæ±ããŠãã ããïŒ
ãªãïŒåã¯ã€ãºã«æ£è§£ãããåŠãã®ç¢ºçã¯äºãã«ãã¹ãŠç¬ç«ã§ãããã®ãšããŸãïŒ | [
{
"input": "2\n1000 10\n300 50\n",
"output": "2 1\n"
},
{
"input": "6\n1 0\n1 20\n1 40\n1 60\n1 80\n1 100\n",
"output": "6 5 4 3 2 1\n"
},
{
"input": "9\n88994950 78\n405248480 35\n561113280 28\n22802150 2\n946582650 25\n201425280 52\n669650 41\n128877450 71\n1396050 25\n",
"output": "1 5 8 2 3 6 4 7 9\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_c | å顿
æŽæ°
L,R
ãäžããããŸãïŒ
以äžã®æ¡ä»¶ãæºããæŽæ°ã®çµ
(A,B)
ã®åæ°ãæ°ããŠãã ããïŒ
L \leq A < B \leq R
A
ã¯
A \oplus B
ã§å²ãåããïŒ
B
ã¯
A \oplus B
ã§å²ãåããïŒ
ãã ãããã§
\oplus
ã¯ãããåäœ
\mathrm{XOR}
æŒç®ã衚ããŸãïŒ
ãããåäœ
\mathrm{XOR}
æŒç®ãšã¯
éè² æŽæ°
A, B
ã®ãããåäœ
\mathrm{XOR}
ã
A \oplus B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A \oplus B
ãäºé²è¡šèšããéã®
2^k
(
k \geq 0
) ã®äœã®æ°ã¯ã
A, B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡äžæ¹ã®ã¿ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3 \oplus 5 = 6
ãšãªããŸã (äºé²è¡šèšãããš:
011 \oplus 101 = 110
)ã
äžè¬ã«
k
åã®éè² æŽæ°
p_1, p_2, p_3, \dots, p_k
ã®ãããåäœ
\mathrm{XOR}
ã¯
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
ãšå®çŸ©ãããããã¯
p_1, p_2, p_3, \dots, p_k
ã®é çªã«ãããªãããšã蚌æã§ããŸãã | [
{
"input": "3 6\n",
"output": "2\n"
},
{
"input": "1 100\n",
"output": "124\n"
},
{
"input": "999000000 1000000000\n",
"output": "1726239\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_d | å顿
(0,1,\cdots,N-1)
ã®é å
P=(P_0,P_1,\cdots,P_{N-1})
ãäžããããŸãïŒ
æŽæ°
a,b
(
0 \leq a,b \leq N-1
) ã«å¯ŸããŠïŒé å
f(a,b)
ãæ¬¡ã®ããã«å®çŸ©ããŸãïŒ
f(a,b)=(q_0,q_1,\cdots,q_{N-1})
ãšãããŠïŒ
q_{(i+a \pmod N)}=(P_i+b \pmod N)
(
0 \leq i \leq N-1
) ãšå®ããïŒ
ãã¹ãŠã®
a,b
ã«å¯Ÿã
f(a,b)
ãæ±ãããšïŒ
N^2
åã®é åãåŸãããŸãïŒ
ãããã®é åãèŸæžé ã§ãœãŒãããããšãèããŸãïŒ
ãœãŒãããããšïŒå
é ãã
K
çªç®ã«äœçœ®ããŠããé åãæ±ããŠãã ããïŒ
æ°åã®èŸæžé ãšã¯ïŒ
æ°å
S = (S_1,S_2,\ldots,S_{|S|})
ãæ°å
T = (T_1,T_2,\ldots,T_{|T|})
ãã
èŸæžé ã§å°ãã
ãšã¯ãäžèšã® 1. ãš 2. ã®ã©ã¡ãããæãç«ã€ããšãèšããŸãã
ããã§ã
|S|, |T|
ã¯ãããã
S, T
ã®é·ãã衚ããŸãã
|S| \lt |T|
ãã€
(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})
ã
ããæŽæ°
1 \leq i \leq \min\lbrace |S|, |T| \rbrace
ãååšããŠãäžèšã®
2
ã€ããšãã«æãç«ã€ã
(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
S_i
ã
T_i
ããïŒæ°ãšããŠïŒå°ããã | [
{
"input": "2 2\n0 1\n",
"output": "0 1\n"
},
{
"input": "4 6\n0 2 1 3\n",
"output": "1 2 0 3\n"
},
{
"input": "10 79\n6 5 9 8 7 1 3 2 0 4\n",
"output": "7 9 8 2 1 0 4 6 5 3\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_e | å顿
0
,
1
ãããªãé·ã
N
ã®æŽæ°å
A=(A_1,A_2,\cdots,A_N)
ãäžããããŸãïŒ
ä»ïŒäºæ¬¡å
å¹³é¢äžã®åº§æš
(0,0)
ã®ç¹ã«é§ããããŸãïŒ
ããªãã¯ããããïŒä»¥äžã®æäœã奜ããªåæ°ç¹°ãè¿ããŸãïŒ
æŽæ°
x,y
(
1 \leq x,y \leq N
) ãéžã³ïŒé§ã®
X
,
Y
座æšããããã
x
,
y
ãã€å¢ããïŒ
ãã ãããã§ïŒä»¥äžã®
2
ã€ã®æ¡ä»¶ãæºããå¿
èŠãããïŒ
A_x=1
ãæç«ïŒ
æäœåŸã®é§ã®åº§æšã
(p,q)
ãšãããšãïŒ
q \leq p
ãæç«ïŒ
æçµçã«é§ã座æš
(N,N)
ãžãšè³ããããªæäœæ¹æ³ãäœéããããã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããïŒ | [
{
"input": "2\n1 1\n",
"output": "2\n"
},
{
"input": "1\n0\n",
"output": "0\n"
},
{
"input": "4\n1 1 0 1\n",
"output": "10\n"
},
{
"input": "25\n1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 0\n",
"output": "934946952\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_f | å顿
A
,
B
ãããªãé·ã
N
ã®æåå
S
ãäžããããŸãïŒ
ããªãã¯ïŒä»¥äžã®æäœã
0
å以äžç¹°ãè¿ãããšãã§ããŸãïŒ
S
äžã®é£ç¶ãã
2
æåã§ãã£ãŠïŒ
AB
ã§
ãªã
ãã®ãéžã³ïŒæ¶ãïŒ
ãã®åŸïŒæ®ã£ãå·Šå³ã®ïŒç©ºãããããªãïŒæååãé£çµãïŒãããæ°ãã«
S
ãšããïŒ
æäœåŸã®
S
ãšããŠããåŸãæååãäœéããããã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããïŒ | [
{
"input": "3\nBBA\n",
"output": "3\n"
},
{
"input": "5\nABABA\n",
"output": "3\n"
},
{
"input": "9\nBABBAAAAB\n",
"output": "14\n"
},
{
"input": "48\nAABABBBAABAAABAAABBBAAABBBAABAABBABAABBAAAAABBBB\n",
"output": "3073910\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_g | å顿
ããã°ã©ãã³ã°åå¿è
ã®ãã¬ããããïŒä»¥äžã®ãããªã³ãŒããæžããŸããïŒ
N = read_integer()
parent = array(N, -1) //é·ã N ã®é
å parent ãäœãïŒãã¹ãŠã®èŠçŽ ã -1 ã§åæå
find(v):
if parent[v] == -1:
return v
else:
return find(parent[v])
union(a,b):
parent[find(b)] = find(a)
for i = 0 to N-2:
A_i = read_integer()
B_i = read_integer()
union(A_i,B_i)
ããã¯ïŒ
N
é ç¹ã®æšã®æ
å ±ãåããšãïŒUnion-Find ã§èŸºãçµã¶ã ãã®ããã°ã©ã ã§ãïŒ
ããã°ã©ãã³ã°ãã¹ã¿ãŒã®ãããããã¯ïŒãã®ããã°ã©ã ã®æ¬ é¥ã«æ°ãä»ããŸããïŒ
ããªãã¡ïŒUnion-Find ã«äžåã®é«éåãæœãããŠããªãã®ã§ãïŒ
ä»ïŒãããããã¯
N
é ç¹ãããªãæš
T
ãæã£ãŠããŸãïŒ
T
ã®é ç¹ã«ã¯
0
ãã
N-1
ãŸã§ã®çªå·ãïŒèŸºã«ã¯
0
ãã
N-2
ãŸã§ã®çªå·ãã€ããŠããŸãïŒ
蟺
i
ã¯é ç¹
A_i
ãšé ç¹
B_i
ãçµã¶èŸºã§ãïŒ
ãããããã¯ïŒãã¬ãããã®ããã°ã©ã ã«
T
ãå
¥åãšããŠäžããããšããŠããŸãïŒ
ãã ããã®åã«ïŒ
T
ã®èŸºã®çªå·ãšïŒèŸºã®ç«¯ç¹ã®é çªãèªç±ã«å
¥ãæ¿ããããšãã§ããŸãïŒ
ãããããã¯ïŒãã¬ãããã®ããã°ã©ã ãéå¹ççã§ããããšã瀺ãããã«ïŒ
find
颿°ãåŒã°ããåæ°ãæå€§åãããã§ãïŒ
find
颿°ãåŒã°ããåæ°ã®æå€§å€ãæ±ããŠãã ããïŒ | [
{
"input": "2\n0 1\n",
"output": "2\n"
},
{
"input": "3\n0 1\n0 2\n",
"output": "5\n"
},
{
"input": "5\n0 1\n0 2\n0 3\n3 4\n",
"output": "13\n"
},
{
"input": "20\n6 16\n10 6\n16 8\n1 5\n9 4\n5 3\n13 16\n19 10\n12 2\n14 10\n12 18\n0 2\n15 16\n12 7\n11 14\n1 10\n6 4\n17 8\n12 1\n",
"output": "148\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_a | å顿
N
è¡
M
åãããªãç€é¢ãããïŒåãã¹ç®ã«ã¯ row-major é ã«
1
ãã
N \times M
ãŸã§ã®æŽæ°ãæžãããŠããŸãïŒ
ã€ãŸãïŒäžãã
i
è¡ç®ïŒå·Šãã
j
åç®ã®ãã¹ã«æžãããŠããæŽæ°ã
A_{i,j}
ã§è¡šãããšã«ãããšïŒ
A_{i,j}=(i-1) \times M + j
ã§ãïŒ
ãã®ç€é¢ã®éšåé·æ¹åœ¢ã§ãã£ãŠïŒãã®å
éšã«æžãããå€ã®ç·åãã¡ããã©
V
ã«ãªããã®ã®åæ°ãæ°ããŠãã ããïŒ
ããå³å¯ã«èšãã°ïŒæŽæ°ã®
4
ã€çµ
(a,b,c,d)
(
1 \leq a \leq b \leq N
,
1 \leq c \leq d \leq M
) ã§ãã£ãŠïŒ
\sum_{a \leq i \leq b,\ c \leq j \leq d} A_{i,j}=V
ãæºãããã®ã®åæ°ãæ°ããŠãã ããïŒ | [
{
"input": "2 2 3\n",
"output": "2\n"
},
{
"input": "2 2 5\n",
"output": "0\n"
},
{
"input": "13 8 1032\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_b | å顿
1
ãã
N
ãŸã§ã®çªå·ãã€ãã
N
åã®ã¯ã€ãºãããïŒããªãã¯ãããã䜿ã£ãã²ãŒã ã«åå ããŸãïŒ
ãã®ã²ãŒã ã§ã¯ïŒããªãã¯ã¯ã€ãºã«
1
åãã€åçããŠãããŸãïŒ
ã¯ã€ãºã«åçããé çªã¯èªç±ã«éžã¶ããšãã§ããŸãïŒ
ã¯ã€ãº
i
ã«åçãããš
P_i
% ã®ç¢ºçã§æ£è§£ããŸãïŒ
æ£è§£ããå ŽåïŒããªãã¯
S_i
ç¹ãç²åŸãïŒïŒãŸã æªåçã®ã¯ã€ãºããããªãïŒæ¬¡ã®ã¯ã€ãºã®åçãžãšç§»ããŸãïŒ
æ£è§£ããªãã£ãå ŽåïŒå³åº§ã«ã²ãŒã ãçµäºãïŒæ®ãã®ã¯ã€ãºã«åçããããšãã§ããªããªããŸãïŒ
ããªãã¯ïŒç²åŸããåŸç¹ã®åèšã®æåŸ
å€ãæå€§åãããã§ãïŒ
ç®çãéæããããã®æŠç¥ïŒïŒã¯ã€ãºã«åçããé çªïŒãæ±ããŠãã ããïŒ
ãªãïŒåã¯ã€ãºã«æ£è§£ãããåŠãã®ç¢ºçã¯äºãã«ãã¹ãŠç¬ç«ã§ãããã®ãšããŸãïŒ | [
{
"input": "2\n1000 10\n300 50\n",
"output": "2 1\n"
},
{
"input": "6\n1 0\n1 20\n1 40\n1 60\n1 80\n1 100\n",
"output": "6 5 4 3 2 1\n"
},
{
"input": "9\n88994950 78\n405248480 35\n561113280 28\n22802150 2\n946582650 25\n201425280 52\n669650 41\n128877450 71\n1396050 25\n",
"output": "1 5 8 2 3 6 4 7 9\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_c | å顿
æŽæ°
L,R
ãäžããããŸãïŒ
以äžã®æ¡ä»¶ãæºããæŽæ°ã®çµ
(A,B)
ã®åæ°ãæ°ããŠãã ããïŒ
L \leq A < B \leq R
A
ã¯
A \oplus B
ã§å²ãåããïŒ
B
ã¯
A \oplus B
ã§å²ãåããïŒ
ãã ãããã§
\oplus
ã¯ãããåäœ
\mathrm{XOR}
æŒç®ã衚ããŸãïŒ
ãããåäœ
\mathrm{XOR}
æŒç®ãšã¯
éè² æŽæ°
A, B
ã®ãããåäœ
\mathrm{XOR}
ã
A \oplus B
ã¯ã以äžã®ããã«å®çŸ©ãããŸãã
A \oplus B
ãäºé²è¡šèšããéã®
2^k
(
k \geq 0
) ã®äœã®æ°ã¯ã
A, B
ãäºé²è¡šèšããéã®
2^k
ã®äœã®æ°ã®ãã¡äžæ¹ã®ã¿ã
1
ã§ããã°
1
ãããã§ãªããã°
0
ã§ããã
äŸãã°ã
3 \oplus 5 = 6
ãšãªããŸã (äºé²è¡šèšãããš:
011 \oplus 101 = 110
)ã
äžè¬ã«
k
åã®éè² æŽæ°
p_1, p_2, p_3, \dots, p_k
ã®ãããåäœ
\mathrm{XOR}
ã¯
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
ãšå®çŸ©ãããããã¯
p_1, p_2, p_3, \dots, p_k
ã®é çªã«ãããªãããšã蚌æã§ããŸãã | [
{
"input": "3 6\n",
"output": "2\n"
},
{
"input": "1 100\n",
"output": "124\n"
},
{
"input": "999000000 1000000000\n",
"output": "1726239\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_d | å顿
(0,1,\cdots,N-1)
ã®é å
P=(P_0,P_1,\cdots,P_{N-1})
ãäžããããŸãïŒ
æŽæ°
a,b
(
0 \leq a,b \leq N-1
) ã«å¯ŸããŠïŒé å
f(a,b)
ãæ¬¡ã®ããã«å®çŸ©ããŸãïŒ
f(a,b)=(q_0,q_1,\cdots,q_{N-1})
ãšãããŠïŒ
q_{(i+a \pmod N)}=(P_i+b \pmod N)
(
0 \leq i \leq N-1
) ãšå®ããïŒ
ãã¹ãŠã®
a,b
ã«å¯Ÿã
f(a,b)
ãæ±ãããšïŒ
N^2
åã®é åãåŸãããŸãïŒ
ãããã®é åãèŸæžé ã§ãœãŒãããããšãèããŸãïŒ
ãœãŒãããããšïŒå
é ãã
K
çªç®ã«äœçœ®ããŠããé åãæ±ããŠãã ããïŒ
æ°åã®èŸæžé ãšã¯ïŒ
æ°å
S = (S_1,S_2,\ldots,S_{|S|})
ãæ°å
T = (T_1,T_2,\ldots,T_{|T|})
ãã
èŸæžé ã§å°ãã
ãšã¯ãäžèšã® 1. ãš 2. ã®ã©ã¡ãããæãç«ã€ããšãèšããŸãã
ããã§ã
|S|, |T|
ã¯ãããã
S, T
ã®é·ãã衚ããŸãã
|S| \lt |T|
ãã€
(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})
ã
ããæŽæ°
1 \leq i \leq \min\lbrace |S|, |T| \rbrace
ãååšããŠãäžèšã®
2
ã€ããšãã«æãç«ã€ã
(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
S_i
ã
T_i
ããïŒæ°ãšããŠïŒå°ããã | [
{
"input": "2 2\n0 1\n",
"output": "0 1\n"
},
{
"input": "4 6\n0 2 1 3\n",
"output": "1 2 0 3\n"
},
{
"input": "10 79\n6 5 9 8 7 1 3 2 0 4\n",
"output": "7 9 8 2 1 0 4 6 5 3\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_e | å顿
0
,
1
ãããªãé·ã
N
ã®æŽæ°å
A=(A_1,A_2,\cdots,A_N)
ãäžããããŸãïŒ
ä»ïŒäºæ¬¡å
å¹³é¢äžã®åº§æš
(0,0)
ã®ç¹ã«é§ããããŸãïŒ
ããªãã¯ããããïŒä»¥äžã®æäœã奜ããªåæ°ç¹°ãè¿ããŸãïŒ
æŽæ°
x,y
(
1 \leq x,y \leq N
) ãéžã³ïŒé§ã®
X
,
Y
座æšããããã
x
,
y
ãã€å¢ããïŒ
ãã ãããã§ïŒä»¥äžã®
2
ã€ã®æ¡ä»¶ãæºããå¿
èŠãããïŒ
A_x=1
ãæç«ïŒ
æäœåŸã®é§ã®åº§æšã
(p,q)
ãšãããšãïŒ
q \leq p
ãæç«ïŒ
æçµçã«é§ã座æš
(N,N)
ãžãšè³ããããªæäœæ¹æ³ãäœéããããã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããïŒ | [
{
"input": "2\n1 1\n",
"output": "2\n"
},
{
"input": "1\n0\n",
"output": "0\n"
},
{
"input": "4\n1 1 0 1\n",
"output": "10\n"
},
{
"input": "25\n1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 0\n",
"output": "934946952\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_f | å顿
A
,
B
ãããªãé·ã
N
ã®æåå
S
ãäžããããŸãïŒ
ããªãã¯ïŒä»¥äžã®æäœã
0
å以äžç¹°ãè¿ãããšãã§ããŸãïŒ
S
äžã®é£ç¶ãã
2
æåã§ãã£ãŠïŒ
AB
ã§
ãªã
ãã®ãéžã³ïŒæ¶ãïŒ
ãã®åŸïŒæ®ã£ãå·Šå³ã®ïŒç©ºãããããªãïŒæååãé£çµãïŒãããæ°ãã«
S
ãšããïŒ
æäœåŸã®
S
ãšããŠããåŸãæååãäœéããããã
998244353
ã§å²ã£ãããŸããæ±ããŠãã ããïŒ | [
{
"input": "3\nBBA\n",
"output": "3\n"
},
{
"input": "5\nABABA\n",
"output": "3\n"
},
{
"input": "9\nBABBAAAAB\n",
"output": "14\n"
},
{
"input": "48\nAABABBBAABAAABAAABBBAAABBBAABAABBABAABBAAAAABBBB\n",
"output": "3073910\n"
}
] |
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_g | å顿
ããã°ã©ãã³ã°åå¿è
ã®ãã¬ããããïŒä»¥äžã®ãããªã³ãŒããæžããŸããïŒ
N = read_integer()
parent = array(N, -1) //é·ã N ã®é
å parent ãäœãïŒãã¹ãŠã®èŠçŽ ã -1 ã§åæå
find(v):
if parent[v] == -1:
return v
else:
return find(parent[v])
union(a,b):
parent[find(b)] = find(a)
for i = 0 to N-2:
A_i = read_integer()
B_i = read_integer()
union(A_i,B_i)
ããã¯ïŒ
N
é ç¹ã®æšã®æ
å ±ãåããšãïŒUnion-Find ã§èŸºãçµã¶ã ãã®ããã°ã©ã ã§ãïŒ
ããã°ã©ãã³ã°ãã¹ã¿ãŒã®ãããããã¯ïŒãã®ããã°ã©ã ã®æ¬ é¥ã«æ°ãä»ããŸããïŒ
ããªãã¡ïŒUnion-Find ã«äžåã®é«éåãæœãããŠããªãã®ã§ãïŒ
ä»ïŒãããããã¯
N
é ç¹ãããªãæš
T
ãæã£ãŠããŸãïŒ
T
ã®é ç¹ã«ã¯
0
ãã
N-1
ãŸã§ã®çªå·ãïŒèŸºã«ã¯
0
ãã
N-2
ãŸã§ã®çªå·ãã€ããŠããŸãïŒ
蟺
i
ã¯é ç¹
A_i
ãšé ç¹
B_i
ãçµã¶èŸºã§ãïŒ
ãããããã¯ïŒãã¬ãããã®ããã°ã©ã ã«
T
ãå
¥åãšããŠäžããããšããŠããŸãïŒ
ãã ããã®åã«ïŒ
T
ã®èŸºã®çªå·ãšïŒèŸºã®ç«¯ç¹ã®é çªãèªç±ã«å
¥ãæ¿ããããšãã§ããŸãïŒ
ãããããã¯ïŒãã¬ãããã®ããã°ã©ã ãéå¹ççã§ããããšã瀺ãããã«ïŒ
find
颿°ãåŒã°ããåæ°ãæå€§åãããã§ãïŒ
find
颿°ãåŒã°ããåæ°ã®æå€§å€ãæ±ããŠãã ããïŒ | [
{
"input": "2\n0 1\n",
"output": "2\n"
},
{
"input": "3\n0 1\n0 2\n",
"output": "5\n"
},
{
"input": "5\n0 1\n0 2\n0 3\n3 4\n",
"output": "13\n"
},
{
"input": "20\n6 16\n10 6\n16 8\n1 5\n9 4\n5 3\n13 16\n19 10\n12 2\n14 10\n12 18\n0 2\n15 16\n12 7\n11 14\n1 10\n6 4\n17 8\n12 1\n",
"output": "148\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.