url stringlengths 49 92 | description stringlengths 22 4.78k | cases listlengths 0 6 |
|---|---|---|
https://atcoder.jp/contests/abc274/tasks/abc274_b | Problem Statement
There is a grid with
H
rows from top to bottom and
W
columns from left to right. Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
The squares are described by characters
C_{i,j}
. If
C_{i,j}
is
.
,
(i, j)
is empty; if it is
#
,
(i, j)
contains a box.
For integ... | [
{
"input": "3 4\n#..#\n.#.#\n.#.#\n",
"output": "1 2 0 3\n"
},
{
"input": "3 7\n.......\n.......\n.......\n",
"output": "0 0 0 0 0 0 0\n"
},
{
"input": "8 3\n.#.\n###\n.#.\n.#.\n.##\n..#\n##.\n.##\n",
"output": "2 7 4\n"
},
{
"input": "5 47\n.#..#..#####..#...#..#####..#...#.... |
https://atcoder.jp/contests/abc274/tasks/abc274_c | Problem Statement
You observed amoebae and kept some records.
Initially, there was one amoeba, numbered
1
.
You made
N
records. According to the
i
-th record, the amoeba numbered
A_i
disappeared by dividing itself into two new amoebae, which were then numbered
2i
and
2i+1
.
Here, amoeba
A_i
is said to be the parent of ... | [
{
"input": "2\n1 2\n",
"output": "0\n1\n1\n2\n2\n"
},
{
"input": "4\n1 3 5 2\n",
"output": "0\n1\n1\n2\n2\n3\n3\n2\n2\n"
}
] |
https://atcoder.jp/contests/abc274/tasks/abc274_d | Problem Statement
You are given a sequence
A = (A_1, A_2, \dots, A_N)
of length
N
consisting of positive integers, and integers
x
and
y
.
Determine whether it is possible to place
N+1
points
p_1, p_2, \dots, p_N, p_{N+1}
in the
xy
-coordinate plane to satisfy all of the following conditions. (It is allowed to place two... | [
{
"input": "3 -1 1\n2 1 3\n",
"output": "Yes\n"
},
{
"input": "5 2 0\n2 2 2 2 2\n",
"output": "Yes\n"
},
{
"input": "4 5 5\n1 2 3 4\n",
"output": "No\n"
},
{
"input": "3 2 7\n2 7 4\n",
"output": "No\n"
},
{
"input": "10 8 -7\n6 10 4 1 5 9 8 6 5 1\n",
"output":... |
https://atcoder.jp/contests/abc274/tasks/abc274_e | Problem Statement
In a two-dimensional plane, there are
N
towns and
M
chests. Town
i
is at the coordinates
(X_i,Y_i)
, and chest
i
is at the coordinates
(P_i,Q_i)
.
Takahashi will go on a trip where he starts at the origin, visits all
N
towns, and then returns to the origin.
It is not mandatory to visit chests, but eac... | [
{
"input": "2 1\n1 1\n0 1\n1 0\n",
"output": "2.5000000000\n"
},
{
"input": "2 1\n1 1\n0 1\n100 0\n",
"output": "3.4142135624\n"
},
{
"input": "1 2\n4 4\n1 0\n0 1\n",
"output": "4.3713203436\n"
}
] |
https://atcoder.jp/contests/abc274/tasks/abc274_f | Problem Statement
On a number line, there are
N
fish swimming.
Fish
i
, which has a weight of
W_i
, is at the coordinate
X_i
at time
0
and moves at a speed of
V_i
in the positive direction.
Takahashi will choose an arbitrary real number
t
greater than or equal to
0
and do the following action at time
t
just once.
Actio... | [
{
"input": "3 10\n100 0 100\n1 10 30\n10 20 10\n",
"output": "111\n"
},
{
"input": "3 10\n100 100 100\n1 10 30\n10 20 10\n",
"output": "100\n"
},
{
"input": "4 10\n1000 100 10\n100 99 1\n10 0 100\n1 1 1\n",
"output": "1110\n"
}
] |
https://atcoder.jp/contests/abc274/tasks/abc274_g | Problem Statement
There is a grid with
H
rows from top to bottom and
W
columns from left to right. Let
(i, j)
denote the square at the
i
-th row from the top and
j
-th column from the left.
Square
(i, j)
is occupied by an obstacle if
S_{i,j}=
#
, and is empty if
S_{i,j}=
.
.
Takahashi will install some surveillance cam... | [
{
"input": "3 3\n...\n.#.\n...\n",
"output": "4\n"
},
{
"input": "3 5\n...##\n.#...\n...#.\n",
"output": "5\n"
},
{
"input": "14 107\n...........................................................................................................\n................................................ |
https://atcoder.jp/contests/abc274/tasks/abc274_h | Problem Statement
For sequences
B=(B_1,B_2,\dots,B_M)
and
C=(C_1,C_2,\dots,C_M)
, each of length
M
, consisting of non-negative integers, let the
XOR sum
S(B,C)
of
B
and
C
be defined as the sequence
(B_1\oplus C_1, B_2\oplus C_2, ..., B_{M}\oplus C_{M})
of length
M
consisting of non-negative integers. Here,
\oplus
repr... | [
{
"input": "4 5\n1 2 3 1\n1 3 2 4 1 4\n1 2 2 3 3 4\n1 1 2 2 3 4\n1 2 2 3 3 3\n1 4 1 4 1 1\n",
"output": "No\nNo\nYes\nNo\nYes\n"
},
{
"input": "10 10\n725560240 9175925348 9627229768 7408031479 623321125 4845892509 8712345300 1026746010 4844359340 2169008582\n5 6 5 6 2 6\n5 6 1 2 1 1\n3 8 3 8 1 6\n5... |
https://atcoder.jp/contests/arc151/tasks/arc151_a | Problem Statement
Below, a
01
-sequence is a string consisting of
0
and
1
.
You are given two
01
-sequences
S
and
T
of length
N
each.
Print the lexicographically smallest
01
-sequence
U
of length
N
that satisfies the condition below.
The Hamming distance between
S
and
U
equals the Hamming distance between
T
and
U
.
If... | [
{
"input": "5\n00100\n10011\n",
"output": "00001\n"
},
{
"input": "1\n0\n1\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/arc151/tasks/arc151_b | Problem Statement
You are given a permutation
P = (P_1, P_2, \ldots, P_N)
of
(1, 2, \ldots, N)
.
Print the number of integer sequences
A = (A_1, A_2, \ldots, A_N)
of length
N
that satisfy both of the conditions below, modulo
998244353
.
1 \leq A_i \leq M
for every
i = 1, 2, \ldots, N
.
The integer sequence
A
is lexicog... | [
{
"input": "4 2\n4 1 3 2\n",
"output": "6\n"
},
{
"input": "1 1\n1\n",
"output": "0\n"
},
{
"input": "20 100000\n11 15 3 20 17 6 1 9 5 19 10 16 7 8 12 2 18 14 4 13\n",
"output": "55365742\n"
}
] |
https://atcoder.jp/contests/arc151/tasks/arc151_c | Problem Statement
There are
N
squares called square
1
, square
2
,
\ldots
, square
N
, where square
i
and square
i+1
are adjacent for each
i = 1, 2, \ldots, N-1
.
Initially,
M
of the squares have
0
or
1
written on them.
Specifically, for each
i = 1, 2, \ldots, M
,
Y_i
is written on square
X_i
.
The other
N-M
squares ... | [
{
"input": "7 2\n2 0\n4 1\n",
"output": "Takahashi\n"
},
{
"input": "3 3\n1 1\n2 0\n3 1\n",
"output": "Aoki\n"
},
{
"input": "1000000000000000000 0\n",
"output": "Aoki\n"
}
] |
https://atcoder.jp/contests/arc151/tasks/arc151_d | Problem Statement
You are given an integer sequence
A = (A_0, A_1, \ldots, A_{2^N-1})
of length
2^N
.
Additionally,
Q
queries are given.
For each
i = 1, 2, \ldots, Q
, the
i
-th query is represented by two integers
X_i
and
Y_i
and asks you to perform the operation below.
For each
j = 0, 1, 2, \ldots, 2^N-1
in this ord... | [
{
"input": "2 2\n0 1 2 3\n1 1\n0 0\n",
"output": "2 6 2 5\n"
},
{
"input": "3 10\n606248357 338306877 919152167 981537317 808873985 845549408 680941783 921035119\n1 1\n0 0\n0 0\n0 0\n0 1\n0 1\n0 1\n2 0\n2 0\n2 0\n",
"output": "246895115 904824001 157201385 744260759 973709546 964549010 61683812 ... |
https://atcoder.jp/contests/arc151/tasks/arc151_e | Problem Statement
You are given an integer sequence
A = (A_1, A_2, \ldots, A_N)
of length
N
.
Additionally, its contiguous subsequences of lengths
P
and
Q
are given:
X = (X_1, X_2, \ldots, X_P)
and
Y = (Y_1, Y_2, \ldots, Y_Q)
.
You can perform the four operations on
X
below any number of times (possibly zero) in any o... | [
{
"input": "7\n3 1 4 1 5 7 2\n2\n3 1\n3\n1 5 7\n",
"output": "3\n"
},
{
"input": "20\n2 5 1 2 7 7 4 5 3 7 7 4 5 5 5 4 6 5 6 1\n6\n1 2 7 7 4 5\n7\n7 4 5 5 5 4 6\n",
"output": "7\n"
}
] |
https://atcoder.jp/contests/arc151/tasks/arc151_f | Problem Statement
Takahashi and Aoki will play a game against each other using cards in three colors: red, green, and blue.
Initially, Takahashi has
R_1
red,
G_1
green, and
B_1
blue cards, and Aoki has
R_2
red,
G_2
green, and
B_2
blue cards in their hands.
Each player knows the hands of both players.
The game starts ... | [
{
"input": "10\n1 1 1 0 1 2\n1 2 3 4 5 6\n1 2 3 3 2 1\n1 0 1 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n711741968710511023 863182190136397525 935042422763027373 565732706644706921 453428280447672223 188382995979861200\n16602059... |
https://atcoder.jp/contests/joi2023yo1b/tasks/joi2023_yo1b_a | 問題文
1
日は
24
時間である.
整数
X
が与えられる.
X
日は何時間か求めよ. | [
{
"input": "3\n",
"output": "72\n"
},
{
"input": "100\n",
"output": "2400\n"
}
] |
https://atcoder.jp/contests/joi2023yo1b/tasks/joi2023_yo1b_b | 問題文
2
つの整数
A, B
が与えられる.
A
と
B
の大小を比較し,
A < B
ならば
-1
を,
A = B
ならば
0
を,
A > B
ならば
1
を出力せよ. | [
{
"input": "3\n7\n",
"output": "-1\n"
},
{
"input": "10\n10\n",
"output": "0\n"
},
{
"input": "1000\n1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/joi2023yo1b/tasks/joi2023_yo1b_c | 問題文
同じ文字列を
2
つつなげて得られる文字列を
繰り返し文字列
と呼ぶことにする.
例えば,
OIOI
や
JJJJJJ
,
JOIOIJOIOI
は繰り返し文字列であるが,
IOOI
や
JOIIOI
は繰り返し文字列ではない.
長さ
N
の文字列
S
が与えられる.
N
は偶数であり,
S
の各文字は
J
,
O
,
I
のいずれかである.
S
が繰り返し文字列である場合は
Yes
を,そうでない場合は
No
を出力せよ. | [
{
"input": "6\nJOIJOI\n",
"output": "Yes\n"
},
{
"input": "6\nIOIOIO\n",
"output": "No\n"
},
{
"input": "2\nOO\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/joi2023yo1b/tasks/joi2023_yo1b_d | 問題文
長さ
N
の整数列
A = (A_1, A_2, \ldots, A_N)
と長さ
M
の整数列
B = (B_1, B_2, \ldots, B_M)
が与えられる.
あなたはこれらの数列を用いてゲームを行う.最初,このゲームの点数は
0
である.
このゲームでは
N
回のラウンドを行う.
i
回目 (
1 \leqq i \leqq N
) のラウンドは以下のように進行する.
現在の点数に
A_i
を加算する.
もし加算後の点数が
B_1, B_2, \ldots, B_M
のいずれかと等しい場合,点数を
0
にする.
最後のラウンドが終了した時点でのこのゲームの点数を出力せよ. | [
{
"input": "4\n3 1 4 1\n4\n2 7 1 8\n",
"output": "0\n"
},
{
"input": "5\n1 4 1 4 2\n3\n1 3 5\n",
"output": "6\n"
},
{
"input": "2\n10 10\n3\n1 11 111\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_a | Problem Statement
A function
f(x)
defined for non-negative integer
x
satisfies the following conditions:
f(0) = 1
;
f(k) = k \times f(k-1)
for all positive integers
k
.
Find
f(N)
. | [
{
"input": "2\n",
"output": "2\n"
},
{
"input": "3\n",
"output": "6\n"
},
{
"input": "0\n",
"output": "1\n"
},
{
"input": "10\n",
"output": "3628800\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_b | Problem Statement
Given a non-negative integer
X
, perform the following operation for
i=1,2,\dots,K
in this order and find the resulting
X
.
Round
X
off to the nearest
10^i
.
Formally, replace
X
with
Y
that is "the largest multiple of
10^i
that minimizes
|Y-X|
."
Here are some examples:
Rounding
273
off to the nearest... | [
{
"input": "2048 2\n",
"output": "2100\n"
},
{
"input": "1 15\n",
"output": "0\n"
},
{
"input": "999 3\n",
"output": "1000\n"
},
{
"input": "314159265358979 12\n",
"output": "314000000000000\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_c | Problem Statement
You are given a sequence
A = (A_1, A_2, \ldots, A_N)
of length
N
.
For each
K = 0, 1, 2, \ldots, N-1
, solve the following problem.
Find the number of integers
i
between
1
and
N
(inclusive) such that:
A
contains exactly
K
distinct integers greater than
A_i
. | [
{
"input": "6\n2 7 1 8 2 8\n",
"output": "2\n1\n2\n1\n0\n0\n"
},
{
"input": "1\n1\n",
"output": "1\n"
},
{
"input": "10\n979861204 57882493 979861204 447672230 644706927 710511029 763027379 710511029 447672230 136397527\n",
"output": "2\n1\n2\n1\n2\n1\n1\n0\n0\n0\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_d | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns.
(i, j)
denotes the square at the
i
-th row from the top and
j
-th column from the left.
N
squares,
(r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N)
, have walls.
Takahashi is initially at square
(r_\mathrm{s}, c_\mathrm{s})
.
Q
instructions are ... | [
{
"input": "5 5 4 4\n3\n5 3\n2 2\n1 4\n4\nL 2\nU 3\nL 2\nR 4\n",
"output": "4 2\n3 2\n3 1\n3 5\n"
},
{
"input": "6 6 6 3\n7\n3 1\n4 3\n2 6\n3 4\n5 5\n1 1\n3 2\n10\nD 3\nU 3\nL 2\nD 2\nU 3\nD 3\nU 3\nR 3\nL 3\nD 1\n",
"output": "6 3\n5 3\n5 1\n6 1\n4 1\n6 1\n4 1\n4 2\n4 1\n5 1\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_e | Problem Statement
We have an integer sequence
A
and a notebook. The notebook has
10^9
pages.
You are given
Q
queries. Each query is of one of the following four kinds:
ADD
x
: append an integer
x
to the tail of
A
.
DELETE: remove the last term of
A
if
A
is not empty; do nothing otherwise.
SAVE
y
: erase the sequence ... | [
{
"input": "11\nADD 3\nSAVE 1\nADD 4\nSAVE 2\nLOAD 1\nDELETE\nDELETE\nLOAD 2\nSAVE 1\nLOAD 3\nLOAD 1\n",
"output": "3 3 4 4 3 -1 -1 4 4 -1 4\n"
},
{
"input": "21\nADD 4\nADD 3\nDELETE\nADD 10\nLOAD 7\nSAVE 5\nSAVE 5\nADD 4\nADD 4\nADD 5\nSAVE 5\nADD 2\nDELETE\nADD 1\nSAVE 5\nADD 7\nADD 8\nDELETE\nAD... |
https://atcoder.jp/contests/abc273/tasks/abc273_f | Problem Statement
Takahashi is at the origin of a number line. Takahashi wants to reach the goal at coordinate
X
.
Also, there are
N
walls and
N
hammers on the number line.
At coordinates
Y_1,Y_2,\dots,Y_N
are walls of types
1,2,\dots,N
, respectively.
Initially, Takahashi cannot get over the walls.
At coordinates
Z_1... | [
{
"input": "3 10\n-2 8 -5\n5 -10 3\n",
"output": "40\n"
},
{
"input": "5 -1\n10 -20 30 -40 50\n-10 20 -30 40 -50\n",
"output": "1\n"
},
{
"input": "1 100\n30\n60\n",
"output": "-1\n"
},
{
"input": "4 865942261\n703164879 -531670946 -874856231 -700164975\n-941120316 599462305 ... |
https://atcoder.jp/contests/abc273/tasks/abc273_g | Problem Statement
Find the number, modulo
998244353
, of square matrices of size
N
whose elements are non-negative integers, that satisfy both of the following two conditions:
for all
i = 1, 2, \ldots, N
, the sum of the elements in the
i
-th row is
R_i
;
for all
i = 1, 2, \ldots, N
, the sum of the elements in the
i
-... | [
{
"input": "3\n1 1 1\n0 1 2\n",
"output": "3\n"
},
{
"input": "3\n1 1 1\n2 2 2\n",
"output": "0\n"
},
{
"input": "18\n2 0 1 2 0 1 1 2 1 1 2 0 1 2 2 1 0 0\n1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 0 2 2\n",
"output": "968235177\n"
}
] |
https://atcoder.jp/contests/abc273/tasks/abc273_h | Problem Statement
We have a sequence
A
consisting of integer pairs. Initially,
A = ( (0, 1), (1, 0) )
.
You may perform the following operation on
A
as many (possibly zero) times as you want:
choose
adjacent
two integer pairs
(a, b)
and
(c, d)
, and insert
(a + c, b + d)
between them.
For a sequence
T
consisting of in... | [
{
"input": "7\n1 2\n3 7\n3 5\n0 0\n1000000000 1\n0 1\n6 3\n",
"output": "3511324\n"
}
] |
https://atcoder.jp/contests/arc150/tasks/arc150_a | Problem Statement
You are given a string of length
N
,
S=S_1S_2\dots S_N
, consisting of
0
,
1
, and
?
.
We like to replace every
?
with
0
or
1
so that all of the following conditions are satisfied.
S
contains exactly
K
occurrences of
1
.
These
K
occurrences of
1
are consecutive. That is, there is an
i\ (1 \leq i \le N... | [
{
"input": "4\n3 2\n1??\n4 2\n?1?0\n6 3\n011?1?\n10 5\n00?1???10?\n",
"output": "Yes\nNo\nNo\nYes\n"
}
] |
https://atcoder.jp/contests/arc150/tasks/arc150_b | Problem Statement
You are given positive integers
A
and
B
.
Find the minimum value of
X+Y
for non-negative integers
X
and
Y
such that
B+Y
is a multiple of
A+X
.
You have
T
test cases to solve. | [
{
"input": "5\n11 23\n8 16\n4394 993298361\n95392025 569922442\n8399283 10293\n",
"output": "2\n0\n65\n2429708\n8388990\n"
}
] |
https://atcoder.jp/contests/arc150/tasks/arc150_c | Problem Statement
We have a connected undirected graph
G
with
N
vertices and
M
edges. The vertices are numbered
1
to
N
. The
i
-th edge connects vertices
U_i
and
V_i
.
Additionally, we are given an integer sequence of length
N
,
A=(A_1,\ A_2, \dots,\ A_N)
, and an integer sequence of length
K
,
B=(B_1,\ B_2,\ \dots,\ B... | [
{
"input": "6 6 3\n1 2\n1 3\n2 4\n3 5\n4 6\n5 6\n1 2 4 5 2 6\n1 2 6\n",
"output": "Yes\n"
},
{
"input": "5 5 3\n1 2\n2 3\n3 4\n4 5\n2 5\n1 2 3 5 2\n1 3 2\n",
"output": "No\n"
},
{
"input": "10 20 3\n5 6\n5 10\n5 7\n3 5\n3 7\n2 6\n3 8\n4 5\n5 8\n7 10\n1 6\n1 9\n4 6\n1 2\n1 4\n6 7\n4 8\n2 ... |
https://atcoder.jp/contests/arc150/tasks/arc150_d | Problem Statement
We have a rooted tree with
N
vertices numbered
1
to
N
. Vertex
1
is the root of the tree, and the parent of vertex
i\ (2\leq i)
is vertex
p_i
.
Each vertex has a color: black or white. Initially, all vertices are white.
In this rooted tree, vertex
i
is said to be
good
when all vertices on the simple p... | [
{
"input": "4\n1 1 3\n",
"output": "831870300\n"
},
{
"input": "15\n1 2 1 1 4 5 3 3 5 10 3 6 3 13\n",
"output": "515759610\n"
}
] |
https://atcoder.jp/contests/arc150/tasks/arc150_e | Problem Statement
NK
people are standing in a line from left to right. Let us denote them as person
i
(0\leq i \leq NK-1)
from left to right.
Each person is always facing either left or right. The direction of each person at time
t=0
is represented by a string of length
N
,
S=S_0 S_1 \dots S_{N-1}
, consisting of
L
and... | [
{
"input": "7 1\nRRLRLLL\n",
"output": "9\n"
},
{
"input": "4 10\nLLRR\n",
"output": "0\n"
},
{
"input": "23 200\nRLRRRLLLLLLLLRRRLLRLRRR\n",
"output": "2207\n"
}
] |
https://atcoder.jp/contests/arc150/tasks/arc150_f | Problem Statement
We have a sequence of positive integers of length
N^2
,
A=(A_1,\ A_2,\ \dots,\ A_{N^2})
, and a positive integer
S
. For this sequence of positive integers,
A_i=A_{i+N}
holds for positive integers
i\ (1\leq i \leq N^2-N)
, and only
A_1,\ A_2,\ \dots,\ A_N
are given as the input.
Find the minimum integ... | [
{
"input": "6 4\n1 1 2 1 4 3\n",
"output": "9\n"
},
{
"input": "14 5\n1 1 1 2 3 1 2 4 5 1 1 2 3 1\n",
"output": "11\n"
},
{
"input": "19 10\n1 6 2 7 4 8 5 9 1 10 4 1 3 1 3 2 2 2 1\n",
"output": "39\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_a | Problem Statement
You are given
N
integers
A_1,A_2,\dots
, and
A_N
.
Find the sum of the
N
integers. | [
{
"input": "3\n2 7 2\n",
"output": "11\n"
},
{
"input": "1\n3\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_b | Problem Statement
There are
N
people numbered
1,2,\ldots,N
.
M
parties were held.
k_i
people attended the
i
-th
(1\leq i \leq M)
party, and they were People
x_{i,1},x_{i,2},\ldots,x_{i,k_i}
.
Determine if every two people attended the same party at least once. | [
{
"input": "3 3\n2 1 2\n2 2 3\n2 1 3\n",
"output": "Yes\n"
},
{
"input": "4 2\n3 1 2 4\n3 2 3 4\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_c | Problem Statement
You are given a sequence
A=(A_1,A_2,\ldots,A_N)
of length
N
consisting of non-negative integers.
Determine if there is an even number represented as the sum of two different elements of
A
. If it exists, find the maximum such number. | [
{
"input": "3\n2 3 4\n",
"output": "6\n"
},
{
"input": "2\n1 0\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_d | Problem Statement
There is a grid with
N \times N
squares. We denote by
(i, j)
the square at the
i
-th row from the top and
j
-th column from the left.
Initially, a piece is placed on
(1, 1)
. You may repeat the following operation any number of times:
Let
(i, j)
be the square the piece is currently on. Move the pie... | [
{
"input": "3 1\n",
"output": "0 1 2\n1 2 3\n2 3 4\n"
},
{
"input": "10 5\n",
"output": "0 3 2 3 2 3 4 5 4 5\n3 4 1 2 3 4 3 4 5 6\n2 1 4 3 2 3 4 5 4 5\n3 2 3 2 3 4 3 4 5 6\n2 3 2 3 4 3 4 5 4 5\n3 4 3 4 3 4 5 4 5 6\n4 3 4 3 4 5 4 5 6 5\n5 4 5 4 5 4 5 6 5 6\n4 5 4 5 4 5 6 5 6 7\n5 6 5 6 5 6 5 6 7 ... |
https://atcoder.jp/contests/abc272/tasks/abc272_e | Problem Statement
You are given an integer sequence
A=(A_1,A_2,\ldots,A_N)
of length
N
.
Perform the following operation
M
times:
For each
i\ (1\leq i \leq N)
, add
i
to
A_i
. Then, find the minimum non-negative integer not contained in
A
. | [
{
"input": "3 3\n-1 -1 -6\n",
"output": "2\n2\n0\n"
},
{
"input": "5 6\n-2 -2 -5 -7 -15\n",
"output": "1\n3\n2\n0\n0\n0\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_f | Problem Statement
You are given strings
S
and
T
of length
N
each, consisting of lowercase English letters.
For a string
X
and an integer
i
, let
f(X,i)
be the string obtained by performing on
X
the following operation
i
times:
Remove the first character of
X
and append the same character to the end of
X
.
Find the numb... | [
{
"input": "3\nadb\ncab\n",
"output": "4\n"
},
{
"input": "10\nwsiuhwijsl\npwqoketvun\n",
"output": "56\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_g | Problem Statement
You are given a sequence
A=(A_1,A_2,\dots,A_N)
of length
N
consisting of positive integers, where the elements of
A
are distinct.
You will choose a positive integer
M
between
3
and
10^9
(inclusive) to perform the following operation once:
For each integer
i
such that
1 \le i \le N
, replace
A_i
with
A... | [
{
"input": "5\n3 17 8 14 10\n",
"output": "7\n"
},
{
"input": "10\n822848257 553915718 220834133 692082894 567771297 176423255 25919724 849988238 85134228 235637759\n",
"output": "37\n"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc272/tasks/abc272_h | Problem Statement
N
coins numbered
0,1,\ldots,N-1
are arranged in a row. Initially, all coins are face up. Also, you are given a sequence
A
of length
N
consisting of integers between
0
and
N-1
.
Snuke will choose a permutation
p=(p_1,p_2,\ldots,p_N)
of
(1,\ldots,N)
at equal probability and perform
N
operations. In t... | [
{
"input": "2\n0 1\n",
"output": "1\n"
},
{
"input": "4\n3 1 1 2\n",
"output": "665496237\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_a | Problem Statement
You are given positive integers
N
and
M
. Find the maximum positive integer
X
that satisfies all of the following conditions.
X
is a positive integer less than
10^N
, and all digits in the decimal representation of
X
are the same.
X
is a multiple of
M
.
If no positive integer
X
satisfies the condition... | [
{
"input": "7 12\n",
"output": "888888\n"
},
{
"input": "9 12\n",
"output": "888888888\n"
},
{
"input": "1 3\n",
"output": "9\n"
},
{
"input": "1000 25\n",
"output": "-1\n"
},
{
"input": "30 1\n",
"output": "999999999999999999999999999999\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_b | Problem Statement
For a sequence
P = (P_1, \ldots, P_N)
, let
\mathrm{LIS}(P)
denote the length of a longest increasing subsequence.
You are given permutations
A = (A_1, \ldots, A_N)
and
B = (B_1, \ldots, B_N)
of integers from
1
through
N
. You may perform the following operation on these sequences any number of times ... | [
{
"input": "5\n5 2 1 4 3\n3 1 2 5 4\n",
"output": "8\n"
},
{
"input": "5\n1 2 3 4 5\n1 2 3 4 5\n",
"output": "10\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_c | Problem Statement
You are given a positive integer
N
.
Fill each square of a grid with
N
rows and
N
columns by writing a positive integer not greater than
N^2
so that all of the following conditions are satisfied.
Two positive integers written in horizontally or vertically adjacent squares never sum to a prime number.
... | [
{
"input": "4\n",
"output": "15 11 16 12\n13 3 6 9\n14 7 8 1\n4 2 10 5\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_d | Problem Statement
There are
N
pieces placed at integer coordinates on a number line. The coordinate of the
i
-th piece is
X_i
.
Let us move these pieces
M
times as follows.
In the
i
-th move, given a positive integer
D_i
, we move each piece as follows.
A piece whose coordinate is a negative integer is moved a distance... | [
{
"input": "6 4\n2 4 6 8 10 12\n8 2 5 7\n",
"output": "No -6\nNo -4\nYes 2\nYes 1\nYes 2\nNo 4\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_e | Problem Statement
You are given positive integers
N
,
M
, and
K
. Consider the following operation on a sequence of positive integers
A = (A_0, \ldots, A_{N-1})
.
Do the following for
k=0, 1, \ldots, K-1
in this order.
Sort
A_{k\bmod N}, A_{(k+1)\bmod N}, \ldots, A_{(k+M-1)\bmod N}
in ascending order. That is, replace
... | [
{
"input": "6 3 5\n6 4 2 3 1 5\n",
"output": "18\n"
},
{
"input": "6 3 5\n6 5 4 3 2 1\n",
"output": "0\n"
},
{
"input": "20 20 149\n13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12\n",
"output": "401576539\n"
}
] |
https://atcoder.jp/contests/arc149/tasks/arc149_f | Problem Statement
Let
r > 1
be a rational number, and
p
and
q
be the numerator and denominator of
r
, respectively. That is,
p
and
q
are positive integers such that
r = \frac{p}{q}
and
\gcd(p,q) = 1
.
Let the
base-
\boldsymbol{r}
expansion
of a positive integer
n
be the integer sequence
(a_1, \ldots, a_k)
that satisfie... | [
{
"input": "3 1 9 1 9\n",
"output": "1\n3\n9\n4\n5\n2\n6\n7\n8\n"
},
{
"input": "3 2 9 1 9\n",
"output": "1\n2\n3\n4\n6\n9\n7\n8\n5\n"
},
{
"input": "3 2 9 3 8\n",
"output": "3\n4\n6\n9\n7\n8\n"
},
{
"input": "10 9 1000000000000000000 123456789123456789 123456789123456799\n",... |
https://atcoder.jp/contests/abc271/tasks/abc271_a | Problem Statement
In the hexadecimal system, where the digits
ABCDEF
corresponding to
10,11,12,13,14
, and
15
are used in addition to
0123456789
, every integer between
0
and
255
is represented as a
1
- or
2
-digit numeral.
For example,
0
and
12
are represented as
1
-digit hexadecimal numerals
0
and
C
;
99
and
255
are ... | [
{
"input": "99\n",
"output": "63\n"
},
{
"input": "12\n",
"output": "0C\n"
},
{
"input": "0\n",
"output": "00\n"
},
{
"input": "255\n",
"output": "FF\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_b | Problem Statement
There are
N
sequences of integers.
The
i
-th
(1 \leq i \leq N)
sequence has
L_i
terms; the
j
-th
(1 \leq j \leq L_i)
term of the
i
-th sequence is
a_{i, j}
.
You are given
Q
queries. For the
k
-th
(1 \leq k \leq Q)
query, given integers
s_k
and
t_k
, find the
t_k
-th term of the
s_k
-th sequence. | [
{
"input": "2 2\n3 1 4 7\n2 5 9\n1 3\n2 1\n",
"output": "7\n5\n"
},
{
"input": "3 4\n4 128 741 239 901\n2 1 1\n3 314 159 26535\n1 1\n2 2\n3 3\n1 4\n",
"output": "128\n1\n26535\n901\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_c | Problem Statement
Takahashi is going to read a manga series "Snuke-kun" in
10^9
volumes.
Initially, Takahashi has
N
books of this series. The
i
-th book is Volume
a_i
.
Takahashi may repeat the following operation any number of (possibly zero) times
only before he begins to read
:
Do nothing if he has
1
or less books;... | [
{
"input": "6\n1 2 4 6 7 271\n",
"output": "4\n"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1\n",
"output": "5\n"
},
{
"input": "1\n5\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_d | Problem Statement
There are
N
cards with an integer written on each side. Card
i
(1 \leq i \leq N)
has an integer
a_i
written on the front and an integer
b_i
written on the back.
You may choose whether to place each card with its front or back side visible.
Determine if you can place the cards so that the sum of the v... | [
{
"input": "3 11\n1 4\n2 3\n5 7\n",
"output": "Yes\nTHH\n"
},
{
"input": "5 25\n2 8\n9 3\n4 11\n5 1\n12 6\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_e | Problem Statement
There are
N
towns numbered
1, \dots, N
, and
M
roads numbered
1, \dots, M
.
Every road is directed; road
i
(1 \leq i \leq M)
leads you from Town
A_i
to Town
B_i
. The length of road
i
is
C_i
.
You are given a sequence
E = (E_1, \dots, E_K)
of length
K
consisting of integers between
1
and
M
. A way o... | [
{
"input": "3 4 4\n1 2 2\n2 3 2\n1 3 3\n1 3 5\n4 2 1 2\n",
"output": "4\n"
},
{
"input": "3 2 3\n1 2 1\n2 3 1\n2 1 1\n",
"output": "-1\n"
},
{
"input": "4 4 5\n3 2 2\n1 3 5\n2 4 7\n3 4 10\n2 4 1 4 3\n",
"output": "14\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_f | Problem Statement
There is a grid with
N
rows and
N
columns. We denote by
(i, j)
the square at the
i
-th
(1 \leq i \leq N)
row from the top and
j
-th
(1 \leq j \leq N)
column from the left.
Square
(i, j)
has a non-negative integer
a_{i, j}
written on it.
When you are at square
(i, j)
, you can move to either square
(i... | [
{
"input": "3\n1 5 2\n7 0 5\n4 2 3\n",
"output": "2\n"
},
{
"input": "2\n1 2\n2 1\n",
"output": "0\n"
},
{
"input": "10\n1 0 1 0 0 1 0 0 0 1\n0 0 0 1 0 1 0 1 1 0\n1 0 0 0 1 0 1 0 0 0\n0 1 0 0 0 1 1 0 0 1\n0 0 1 1 0 1 1 0 1 0\n1 0 0 0 1 0 0 1 1 0\n1 1 1 0 0 0 1 1 0 0\n0 1 1 0 0 1 1 0 1 0\... |
https://atcoder.jp/contests/abc271/tasks/abc271_g | Problem Statement
Takahashi has decided to put a web counter on his webpage.
The accesses to his webpage are described as follows:
For
i=0,1,2,\ldots,23
, there is a possible access at
i
o'clock every day:
If
c_i=
T
, Takahashi accesses the webpage with a probability of
X
percent.
If
c_i=
A
, Aoki accesses the webpage ... | [
{
"input": "1 50 50\nATATATATATATATATATATATAT\n",
"output": "665496236\n"
},
{
"input": "271 95 1\nTTTTTTTTTTTTTTTTTTTTTTTT\n",
"output": "0\n"
},
{
"input": "10000000000000000 62 20\nATAATTATATTTAAAATATTATAT\n",
"output": "744124544\n"
}
] |
https://atcoder.jp/contests/abc271/tasks/abc271_h | Problem Statement
Solve the following problem for
T
test cases.
A piece is placed at the origin
(0, 0)
on an
xy
-plane. You may perform the following operation any number of (possibly zero) times:
Choose an integer
i
such that
1 \leq i \leq 8
and
s_i=
1
. Let
(x, y)
be the current coordinates where the piece is place... | [
{
"input": "7\n5 3 10101010\n5 3 01010101\n5 3 11111111\n5 3 00000000\n0 0 11111111\n0 1 10001111\n-1000000000 1000000000 10010011\n",
"output": "8\n5\n5\n-1\n0\n-1\n1000000000\n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_a | Problem Statement
There was an exam consisting of three problems worth
1
,
2
, and
4
points.
Takahashi, Aoki, and Snuke took this exam.
Takahashi scored
A
points, and Aoki scored
B
points.
Snuke solved all of the problems solved by at least one of Takahashi and Aoki, and failed to solve any of the problems solved by n... | [
{
"input": "1 2\n",
"output": "3\n"
},
{
"input": "5 3\n",
"output": "7\n"
},
{
"input": "0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_b | Problem Statement
Takahashi is at the origin of a number line. He wants to reach a goal at coordinate
X
.
There is a wall at coordinate
Y
, which Takahashi cannot go beyond at first.
However, after picking up a hammer at coordinate
Z
, he can destroy that wall and pass through.
Determine whether Takahashi can reach the... | [
{
"input": "10 -10 1\n",
"output": "10\n"
},
{
"input": "20 10 -10\n",
"output": "40\n"
},
{
"input": "100 1 1000\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_c | Problem Statement
There is a tree
T
with
N
vertices. The
i
-th edge
(1\leq i\leq N-1)
connects vertex
U_i
and vertex
V_i
.
You are given two different vertices
X
and
Y
in
T
.
List all vertices along the simple path from vertex
X
to vertex
Y
in order, including endpoints.
It can be proved that, for any two different ver... | [
{
"input": "5 2 5\n1 2\n1 3\n3 4\n3 5\n",
"output": "2 1 3 5\n"
},
{
"input": "6 1 2\n3 1\n2 5\n1 2\n4 1\n2 6\n",
"output": "1 2\n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_d | Problem Statement
Takahashi and Aoki will play a game of taking stones using a sequence
(A_1, \ldots, A_K)
.
There is a pile that initially contains
N
stones. The two players will alternately perform the following operation, with Takahashi going first.
Choose an
A_i
that is at most the current number of stones in the p... | [
{
"input": "10 2\n1 4\n",
"output": "5\n"
},
{
"input": "11 4\n1 2 3 6\n",
"output": "8\n"
},
{
"input": "10000 10\n1 2 4 8 16 32 64 128 256 512\n",
"output": "5136\n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_e | Problem Statement
There are
N
baskets numbered
1, 2, \ldots, N
arranged in a circle.
For each
1\leq i \leq N-1
, basket
i+1
is to the immediate right of basket
i
, and basket
1
is to the immediate right of basket
N
.
Basket
i
now contains
A_i
apples.
Takahashi starts in front of basket
1
and repeats the following actio... | [
{
"input": "3 3\n1 3 0\n",
"output": "0 1 0 \n"
},
{
"input": "2 1000000000000\n1000000000000 1000000000000\n",
"output": "500000000000 500000000000 \n"
}
] |
https://atcoder.jp/contests/abc270/tasks/abc270_h | Problem Statement
You are given a tuple of
N
non-negative integers
A=(A_1,A_2,\ldots,A_N)
such that
A_1=0
and
A_N>0
.
Takahashi has
N
counters. Initially, the values of all counters are
0
.
He will repeat the following operation until, for every
1\leq i\leq N
, the value of the
i
-th counter is at least
A_i
.
Choose on... | [
{
"input": "2\n0 2\n",
"output": "6\n"
},
{
"input": "5\n0 1 3 10 1000000000000000000\n",
"output": "874839568\n"
}
] |
https://atcoder.jp/contests/abc269/tasks/abc269_a | Problem Statement
You are given integers
a
,
b
,
c
, and
d
. Print two lines as follows.
The first line should contain the result of calculating
(a + b) \times (c - d)
as an integer.
The second line should contain
Takahashi
, regardless of the input. | [
{
"input": "1 2 5 3\n",
"output": "6\nTakahashi\n"
},
{
"input": "10 -20 30 -40\n",
"output": "-700\nTakahashi\n"
},
{
"input": "100 100 100 -100\n",
"output": "40000\nTakahashi\n"
}
] |
https://atcoder.jp/contests/abc269/tasks/abc269_b | Problem Statement
Takahashi generated
10
strings
S_1,S_2,\dots,S_{10}
as follows.
First, let
S_i (1 \le i \le 10)=
..........
(
10
.
s in a row).
Next, choose four integers
A
,
B
,
C
, and
D
satisfying all of the following.
1 \le A \le B \le 10
.
1 \le C \le D \le 10
.
Then, for every pair of integers
(i,j)
satisfying ... | [
{
"input": "..........\n..........\n..........\n..........\n...######.\n...######.\n...######.\n...######.\n..........\n..........\n",
"output": "5 8\n4 9\n"
},
{
"input": "..........\n..#.......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
... |
https://atcoder.jp/contests/abc269/tasks/abc269_c | Problem Statement
You are given a non-negative integer
N
. Print all non-negative integers
x
that satisfy the following condition in ascending order.
The set of the digit positions containing
1
in the binary representation of
x
is a subset of the set of the digit positions containing
1
in the binary representation of
N... | [
{
"input": "11\n",
"output": "0\n1\n2\n3\n8\n9\n10\n11\n"
},
{
"input": "0\n",
"output": "0\n"
},
{
"input": "576461302059761664\n",
"output": "0\n524288\n549755813888\n549756338176\n576460752303423488\n576460752303947776\n576461302059237376\n576461302059761664\n"
}
] |
https://atcoder.jp/contests/abc269/tasks/abc269_d | Problem Statement
We have an infinite hexagonal grid shown below. Initially, all squares are white.
A hexagonal cell is represented as
(i,j)
with two integers
i
and
j
.
Cell
(i,j)
is adjacent to the following six cells:
(i-1,j-1)
(i-1,j)
(i,j-1)
(i,j+1)
(i+1,j)
(i+1,j+1)
Takahashi has painted
N
cells
(X_1,Y_1),(X_2,Y_2... | [
{
"input": "6\n-1 -1\n0 1\n0 2\n1 0\n1 2\n2 0\n",
"output": "3\n"
},
{
"input": "4\n5 0\n4 1\n-3 -4\n-2 -5\n",
"output": "4\n"
},
{
"input": "5\n2 1\n2 -1\n1 0\n3 1\n1 -1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc269/tasks/abc269_e | Problem Statement
This is an interactive task
(where your program interacts with the judge's program via input and output).
We have an
N
-by-
N
chessboard and
N
rooks. Below, the square at the
i
-th row from the top and
j
-th column from the left is denoted by
(i, j)
.
Consider placing the rooks on squares of the chess... | [] |
https://atcoder.jp/contests/abc269/tasks/abc269_f | Problem Statement
We have a grid with
N
rows and
M
columns. The square
(i,j)
at the
i
-th row from the top and
j
-th column from the left has an integer
(i-1) \times M + j
written on it.
Let us perform the following operation on this grid.
For every square
(i,j)
such that
i+j
is odd, replace the integer on that square ... | [
{
"input": "5 4\n6\n1 3 2 4\n1 5 1 1\n5 5 1 4\n4 4 2 2\n5 5 4 4\n1 5 1 4\n",
"output": "28\n27\n36\n14\n0\n104\n"
},
{
"input": "1000000000 1000000000\n3\n1000000000 1000000000 1000000000 1000000000\n165997482 306594988 719483261 992306147\n1 1000000000 1 1000000000\n",
"output": "716070898\n240... |
https://atcoder.jp/contests/abc269/tasks/abc269_g | Problem Statement
We have
N
cards numbered
1
to
N
.
Card
i
has an integer
A_i
written on the front and an integer
B_i
written on the back. Here,
\sum_{i=1}^N (A_i + B_i) = M
.
For each
k=0,1,2,...,M
, solve the following problem.
The
N
cards are arranged so that their front sides are visible. You may choose between
0
a... | [
{
"input": "3 6\n0 2\n1 0\n0 3\n",
"output": "1\n0\n2\n1\n1\n3\n2\n"
},
{
"input": "2 3\n1 1\n0 1\n",
"output": "-1\n0\n1\n-1\n"
},
{
"input": "5 12\n0 1\n0 3\n1 0\n0 5\n0 2\n",
"output": "1\n0\n1\n1\n1\n2\n1\n2\n2\n2\n3\n3\n4\n"
}
] |
https://atcoder.jp/contests/abc269/tasks/abc269_h | Problem Statement
We have a rooted tree
T
with
N
vertices numbered
1
to
N
. Vertex
1
is the root, and the parent of vertex
i
(2 \leq i \leq N)
is vertex
P_i
.
A non-empty subset
S
of the vertex set
V = \lbrace 1, 2,\dots, N\rbrace
of
T
is said to be a
good vertex set
when it satisfies the following condition.
For every... | [
{
"input": "4\n1 2 1\n",
"output": "4\n2\n0\n0\n"
},
{
"input": "6\n1 1 2 2 5\n",
"output": "6\n6\n2\n0\n0\n0\n"
},
{
"input": "6\n1 1 1 1 1\n",
"output": "6\n10\n10\n5\n1\n0\n"
},
{
"input": "10\n1 2 1 2 1 1 2 6 9\n",
"output": "10\n30\n47\n38\n16\n3\n0\n0\n0\n0\n"
}
] |
https://atcoder.jp/contests/ahc014/tasks/ahc014_a | Problem Statement
RectJoin is the following single-player game played with square grid paper and pencil.
Let
(0, 0)
be the coordinates of the lower left corner of the grid paper, with the
x
-axis to the right and the
y
-axis to the top.
The coordinates of the upper right corner of the grid paper are
(N-1, N-1)
.
Init... | [
{
"input": "33 58\n13 24\n14 24\n15 24\n16 24\n17 24\n12 23\n18 23\n11 22\n19 22\n10 21\n20 21\n9 20\n21 20\n8 19\n15 19\n18 19\n22 19\n8 18\n12 18\n15 18\n18 18\n22 18\n8 17\n12 17\n15 17\n18 17\n22 17\n8 16\n12 16\n15 16\n18 16\n22 16\n8 15\n12 15\n15 15\n18 15\n22 15\n9 14\n12 14\n15 14\n18 14\n21 14\n10 13\... |
https://atcoder.jp/contests/joi2023yo1a/tasks/joi2023_yo1a_a | 問題文
整数
A, B
が与えられる.縦の辺の長さが
A\:\mathrm{cm}
,横の辺の長さが
B\:\mathrm{cm}
である下図のような長方形の面積は何
\mathrm{cm}^2
か求めよ. | [
{
"input": "2\n3\n",
"output": "6\n"
},
{
"input": "100\n1\n",
"output": "100\n"
},
{
"input": "4\n4\n",
"output": "16\n"
}
] |
https://atcoder.jp/contests/joi2023yo1a/tasks/joi2023_yo1a_b | 問題文
十進法で
2
桁の整数
N
が与えられる.
N
の十の位の数字と一の位の数字が同じである場合は
1
を,そうでない場合は
0
を出力せよ. | [
{
"input": "22\n",
"output": "1\n"
},
{
"input": "10\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/joi2023yo1a/tasks/joi2023_yo1a_c | 問題文
長さ
N
の文字列
S
が与えられる.
S
の各文字は
L
または
R
である.
1
つのボールと,ボールを入れることができる箱が
3
つある.箱には
1
,
2
,
3
と番号が付けられている.
最初,箱
1
にボールが入っていた.
ビーバーのビ太郎は,この状態から箱とボールに対して
N
回の操作を行った.
i
回目 (
1 \leqq i \leqq N
) の操作は,次のように行われた.
ボールが入っている箱を箱
x
とし,箱
x
からボールを取り出す.その後,文字列
S
の
i
文字目に従って,以下のいずれかを行う.
文字列
S
の
i
文字目が
L
の場合,箱
x-1
にボールを入れる.ただし,
x
が
1
である... | [
{
"input": "4\nLRRR\n",
"output": "2\n"
},
{
"input": "3\nLRL\n",
"output": "0\n"
},
{
"input": "7\nLRLRRRL\n",
"output": "2\n"
}
] |
https://atcoder.jp/contests/joi2023yo1a/tasks/joi2023_yo1a_d | 問題文
JOI 高校には
2N\,(=2 \times N)
人の生徒がおり,
1
から
2N
までの番号が付けられている.
来月 JOI 高校では運動会が開催され,その中の競技「二人三脚」では,
2N
人の生徒が
N
組の
2
人組に分かれレースを行う.
組には
1
から
N
までの番号が付けられており,生徒
i
(
1 \leqq i \leqq 2N
) は組
A_i
に属している.
あなたはどの生徒がどの組に属しているかの表を作ったが,どういうわけか,生徒
2N
がどの組に属しているか分からなくなってしまった.
A_1, A_2, \dots, A_{2N-1}
が与えられるので,生徒
2N
が属する組の番号
A_{2N}
... | [
{
"input": "4\n1 4 2 1 3 4 3\n",
"output": "2\n"
},
{
"input": "10\n5 7 1 9 8 8 2 9 6 5 1 3 6 4 7 3 10 2 4\n",
"output": "10\n"
},
{
"input": "1\n1\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_a | Problem Statement
You are given a sequence
A = (A_1, A_2, ..., A_N)
.
You may perform the following operation exactly once.
Choose an integer
M
at least
2
. Then, for every integer
i
(
1 \leq i \leq N
), replace
A_i
with the remainder when
A_i
is divided by
M
.
For instance, if
M = 4
is chosen when
A = (2, 7, 4)
,
A
be... | [
{
"input": "3\n1 4 8\n",
"output": "2\n"
},
{
"input": "4\n5 10 15 20\n",
"output": "1\n"
},
{
"input": "10\n3785 5176 10740 7744 3999 3143 9028 2822 4748 6888\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_b | Problem Statement
For a string
T
of length
L
consisting of
d
and
p
, let
f(T)
be
T
rotated
180
degrees. More formally, let
f(T)
be the string that satisfies the following conditions.
f(T)
is a string of length
L
consisting of
d
and
p
.
For every integer
i
such that
1 \leq i \leq L
, the
i
-th character of
f(T)
differs ... | [
{
"input": "6\ndpdppd\n",
"output": "dddpdd\n"
},
{
"input": "3\nddd\n",
"output": "ddd\n"
},
{
"input": "11\nddpdpdppddp\n",
"output": "ddddpdpdddp\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_c | Problem Statement
We have a rooted tree with
N
vertices numbered
1
to
N
. Vertex
1
is the root, and the parent of vertex
i
is vertex
P_i
.
There are
N
coins with heads and tails, one on each vertex.
Additionally, there are
N
buttons numbered
1
to
N
. Pressing button
n
flips all coins on the vertices in the subtree root... | [
{
"input": "6 6\n1 1 2 2 5\n6 1 2 3 4 5 6\n3 2 5 6\n1 3\n3 1 2 3\n3 4 5 6\n4 2 3 4 5\n",
"output": "1\n2\n1\n3\n2\n3\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_d | Problem Statement
There are
2N
integers
A_1, A_2, ..., A_{2N}
written on a blackboard, and an integer
M
at least
2
.
Alice and Bob will play a game.
They will alternately perform the following operation, with Alice going first, until there is no number on the blackboard.
Choose a number and delete it from the blackboa... | [
{
"input": "2 9\n1 4 8 5\n",
"output": "Alice\n"
},
{
"input": "3 998244353\n1 2 3 1 2 3\n",
"output": "Bob\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_e | Problem Statement
You are given a sequence of length
N
,
A = (A_1, ..., A_N)
, and an integer
K
.
How many permutations of
A
are there such that no two adjacent elements sum to less than
K
? Find the count modulo
998244353
. | [
{
"input": "4 5\n1 2 3 4\n",
"output": "4\n"
},
{
"input": "4 3\n1 2 3 3\n",
"output": "12\n"
},
{
"input": "10 7\n3 1 4 1 5 9 2 6 5 3\n",
"output": "108\n"
}
] |
https://atcoder.jp/contests/arc148/tasks/arc148_f | Problem Statement
This problem is output-only.
We have a programming language equipped with the following operations of unsigned 64-bit integers: addition, multiplication, and a modulo operation where the divisor is
998244353
.
Write a program that performs multiplication modulo
1000000007
in this language.
More formal... | [] |
https://atcoder.jp/contests/abc268/tasks/abc268_a | Problem Statement
Print how many distinct integers there are in given five integers
A, B, C, D
, and
E
. | [
{
"input": "31 9 24 31 24\n",
"output": "3\n"
},
{
"input": "0 0 0 0 0\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_b | Problem Statement
You are given two strings
S
and
T
consisting of lowercase English letters.
Determine if
S
is a prefix of
T
.
What is a prefix?
A prefix of a string
T_1T_2\ldots T_N
of length
N
is a string expressed as the first
i
characters of
T
,
T_1T_2\ldots T_i
, where
i
is an integer such that
0 \leq i \leq N
. ... | [
{
"input": "atco\natcoder\n",
"output": "Yes\n"
},
{
"input": "code\natcoder\n",
"output": "No\n"
},
{
"input": "abc\nabc\n",
"output": "Yes\n"
},
{
"input": "aaaa\naa\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_c | Problem Statement
Person
0
, Person
1
,
\ldots
, and Person
(N-1)
are sitting around a turntable in their counterclockwise order, evenly spaced. Dish
p_i
is in front of Person
i
on the table.
You may perform the following operation
0
or more times:
Rotate the turntable by one
N
-th of a counterclockwise turn. As a re... | [
{
"input": "4\n1 2 0 3\n",
"output": "4\n"
},
{
"input": "3\n0 1 2\n",
"output": "3\n"
},
{
"input": "10\n3 9 6 1 7 2 8 0 5 4\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_d | Problem Statement
Takahashi is having trouble with deciding a username for a service. Write a code to help him.
Find a string
X
that satisfies all of the following conditions:
X
is obtained by the following procedure:
Let
S_1', S_2', \ldots,S_N'
be a permutation of
S_1, S_2, \ldots,S_N
. Let
X
be the concatenation of... | [
{
"input": "1 1\nchokudai\nchokudai\n",
"output": "-1\n"
},
{
"input": "2 2\nchoku\ndai\nchokudai\nchoku_dai\n",
"output": "dai_choku\n"
},
{
"input": "2 2\nchokudai\natcoder\nchokudai_atcoder\natcoder_chokudai\n",
"output": "-1\n"
},
{
"input": "4 4\nab\ncd\nef\ngh\nhoge\nfu... |
https://atcoder.jp/contests/abc268/tasks/abc268_e | Problem Statement
Person
0
, Person
1
,
\ldots
, and Person
(N-1)
are sitting around a turntable in counterclockwise order, evenly spaced. Dish
p_i
is in front of Person
i
on the table.
You may perform the following operation
0
or more times:
Rotate the turntable by one
N
-th of a counterclockwise turn. The dish that... | [
{
"input": "4\n1 2 0 3\n",
"output": "2\n"
},
{
"input": "3\n0 1 2\n",
"output": "0\n"
},
{
"input": "10\n3 9 6 1 7 2 8 0 5 4\n",
"output": "20\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_f | Problem Statement
You are given
N
strings
S_1, S_2, \ldots, S_N
consisting of digits from
1
through
9
and the character
X
.
We will choose a permutation
P = (P_1, P_2, \ldots, P_N)
of
(1, 2, \ldots, N)
to construct a string
T = S_{P_1} + S_{P_2} + \cdots + S_{P_N}
, where
+
denotes a concatenation of strings.
Then, we ... | [
{
"input": "3\n1X3\n59\nXXX\n",
"output": "71\n"
},
{
"input": "10\nX63X395XX\nX2XX3X22X\n13\n3716XXX6\n45X\nX6XX\n9238\n281X92\n1XX4X4XX6\n54X9X711X1\n",
"output": "3010\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_g | Problem Statement
Takahashi Elementary School has
N
new students. For
i = 1, 2, \ldots, N
, the name of the
i
-th new student is
S_i
(which is a string consisting of lowercase English letters).
The names of the
N
new students are distinct.
The
N
students will be assigned a student ID
1, 2, 3, \ldots, N
in
ascending l... | [
{
"input": "3\na\naa\nab\n",
"output": "1\n499122179\n499122179\n"
},
{
"input": "3\na\naa\naaa\n",
"output": "1\n2\n3\n"
}
] |
https://atcoder.jp/contests/abc268/tasks/abc268_h | Problem Statement
You are given a string
S
. Takahashi may perform the following operation
0
or more times:
Choose an integer
i
such that
1 \leq i \leq |S|
and change the
i
-th character of
S
to
*
.
Takahashi's objective is to make
S
not contain any of
N
strings
T_1,T_2,\ldots,T_N
as a substring
.
Find the minimum num... | [
{
"input": "abcdefghijklmn\n3\nabcd\nijk\nghi\n",
"output": "2\n"
},
{
"input": "atcoderbeginnercontest\n1\nabc\n",
"output": "0\n"
},
{
"input": "aaaaaaaaa\n2\naa\nxyz\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_a | Problem Statement
You are given a sequence of
N
positive integers:
A=(A_1,A_2,\dots,A_N)
.
You will repeat the following operation until the length of
A
becomes
1
.
Let
k
be the length of
A
before this operation.
Choose integers
i
and
j
such that
\max(\{A_1,A_2,\dots,A_{k}\})=A_i,\min(\{A_1,A_2,\dots,A_{k}\})=A_j
, an... | [
{
"input": "3\n2 3 6\n",
"output": "3\n"
},
{
"input": "6\n1232 452 23491 34099 57341 21488\n",
"output": "12\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_b | Problem Statement
You are given a permutation
P=(P_1,P_2,\ldots,P_N)
of
(1,2,\ldots,N)
.
You can repeat the following two kinds of operations in any order to make
P
sorted in increasing order.
Operation
A
: Choose an integer
i
such that
1 \leq i \leq N-1
, and swap
P_i
and
P_{i+1}
.
Operation
B
: Choose an integer
i
su... | [
{
"input": "4\n3 2 4 1\n",
"output": "4\nA 3\nB 1\nB 2\nB 2\n"
},
{
"input": "3\n1 2 3\n",
"output": "0\n"
},
{
"input": "6\n2 1 4 3 6 5\n",
"output": "3\nA 1\nA 3\nA 5\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_c | Problem Statement
N
people, numbered
1,2,\ldots ,N
, are going to stand on the number line.
Let's denote by
x_i
the coordinate the Person
i
stands at.
Then,
x_i
should be an integer satisfying
L_i \leq x_i \leq R_i
.
Multiple people can occupy the same coordinate.
We define the
dissatisfaction level
as the following... | [
{
"input": "3\n1 3\n2 4\n5 6\n",
"output": "4\n"
},
{
"input": "3\n1 1\n1 1\n1 1\n",
"output": "0\n"
},
{
"input": "6\n1 5\n2 4\n1 1\n4 4\n3 6\n3 3\n",
"output": "15\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_d | Problem Statement
Consider a sequence of integer sets of length
N
:
S=(S_1,S_2,\dots,S_N)
.
We call a sequence
brilliant
if it satisfies all of the following conditions:
S_i
is a (possibly empty) integer set, and its elements are in the range
[1,M]
.
(1 \le i \le N)
The number of integers that is included in exactly o... | [
{
"input": "2 3\n",
"output": "24\n"
},
{
"input": "12 34\n",
"output": "786334067\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_e | Problem Statement
N
students, numbered
1,2,\ldots,N
, took an examination.
Student
i\,(1 \leq i \leq N)
had to score at least
B_i
points to graduate, where they actually scored
A_i
points.
You can repeat the following operation any number of times (possibly zero):
Choose two students, and swap their scores.
Your goal ... | [
{
"input": "3\n1 2\n3 1\n3 3\n",
"output": "1\n"
},
{
"input": "2\n100 1\n100 1\n",
"output": "2\n"
},
{
"input": "6\n3 2\n1 6\n4 5\n1 3\n5 5\n9 8\n",
"output": "-1\n"
},
{
"input": "6\n3 1\n4 5\n5 2\n2 3\n5 4\n5 1\n",
"output": "3\n"
}
] |
https://atcoder.jp/contests/arc147/tasks/arc147_f | Problem Statement
Consider strings of length
N
consisting of
A
,
B
, and
C
.
Among them, find the number of strings that satisfy the following condition,
modulo
2
:
Let
S_i
be the string formed by the first
i
characters of
S
.
Also let
A_i
,
B_i
, and
C_i
be the numbers of
A
's,
B
's, and
C
's in
S_i
, respectively.
... | [
{
"input": "1\n3 2 1 0\n",
"output": "0\n"
},
{
"input": "10\n1 22 9 92\n14 7 74 39\n23 50 8 6\n93 40 9 60\n68 8 47 64\n11 68 18 24\n3 26 54 8\n46 17 90 86\n86 76 45 55\n80 68 79 62\n",
"output": "1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_a | Problem Statement
One day, tired from going to school, Takahashi wanted to know how many days there were until Saturday.
We know that the day was a weekday, and the name of the day of the week was
S
in English.
How many days were there until the first Saturday after that day (including Saturday but not the starting day... | [
{
"input": "Wednesday\n",
"output": "3\n"
},
{
"input": "Monday\n",
"output": "5\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_b | Problem Statement
Bowling pins are numbered
1
through
10
. The following figure is a top view of the arrangement of the pins:
Let us call each part between two dotted lines in the figure a
column
.
For example, Pins
1
and
5
belong to the same column, and so do Pin
3
and
9
.
When some of the pins are knocked down, a sp... | [
{
"input": "0101110101\n",
"output": "Yes\n"
},
{
"input": "0100101001\n",
"output": "Yes\n"
},
{
"input": "0000100110\n",
"output": "No\n"
},
{
"input": "1101110101\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_c | Problem Statement
You are given an integer sequence
A=(A_1,A_2,\dots,A_N)
of length
N
.
Find the maximum value of
\displaystyle \sum_{i=1}^{M} i \times B_i
for a contiguous subarray
B=(B_1,B_2,\dots,B_M)
of
A
of length
M
. | [
{
"input": "4 2\n5 4 -1 8\n",
"output": "15\n"
},
{
"input": "10 4\n-3 1 -4 1 -5 9 -2 6 -5 3\n",
"output": "31\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_d | Problem Statement
You are given an integer sequence
A=(A_1,A_2,\dots,A_N)
of length
N
.
Find the maximum value of
\displaystyle \sum_{i=1}^{M} i \times B_i
for a (not necessarily contiguous) subsequence
B=(B_1,B_2,\dots,B_M)
of length
M
of
A
. | [
{
"input": "4 2\n5 4 -1 8\n",
"output": "21\n"
},
{
"input": "10 4\n-3 1 -4 1 -5 9 -2 6 -5 3\n",
"output": "54\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_e | Problem Statement
You are given a simple undirected graph with
N
vertices and
M
edges. The
i
-th edge connects Vertices
U_i
and
V_i
. Vertex
i
has a positive integer
A_i
written on it.
You will repeat the following operation
N
times.
Choose a Vertex
x
that is not removed yet, and remove Vertex
x
and all edges inciden... | [
{
"input": "4 3\n3 1 4 2\n1 2\n1 3\n4 1\n",
"output": "3\n"
},
{
"input": "7 13\n464 661 847 514 74 200 188\n5 1\n7 1\n5 7\n4 1\n4 5\n2 4\n5 2\n1 3\n1 6\n3 5\n1 2\n4 6\n2 7\n",
"output": "1199\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_f | Problem Statement
You are given a tree with
N
vertices. The vertices are numbered
1, \dots, N
, and the
i
-th (
1 \leq i \leq N - 1
) edge connects Vertices
A_i
and
B_i
.
We define the
distance
between Vertices
u
and
v
on this tree by the number of edges in the shortest path from Vertex
u
to Vertex
v
.
You are given
Q... | [
{
"input": "5\n1 2\n2 3\n3 4\n3 5\n3\n2 2\n5 3\n3 3\n",
"output": "4\n1\n-1\n"
},
{
"input": "10\n1 2\n2 3\n3 5\n2 8\n3 4\n4 6\n4 9\n5 7\n9 10\n5\n1 1\n2 2\n3 3\n4 4\n5 5\n",
"output": "2\n4\n10\n-1\n-1\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_g | Problem Statement
You are given an integer sequence
A = (A_1, \dots, A_N)
of length
N
.
Find the number, modulo
998244353
, of permutations
P = (P_1, \dots, P_N)
of
(1, 2, \dots, N)
such that:
there exist exactly
K
integers
i
between
1
and
(N-1)
(inclusive) such that
A_{P_i} \lt A_{P_{i + 1}}
. | [
{
"input": "4 2\n1 1 2 2\n",
"output": "4\n"
},
{
"input": "10 3\n3 1 4 1 5 9 2 6 5 3\n",
"output": "697112\n"
}
] |
https://atcoder.jp/contests/abc267/tasks/abc267_h | Problem Statement
You are given a sequence
A=(A_1,A_2,\dots,A_N)
of length
N
.
Find the number, modulo
998244353
, of ways to choose an odd number of elements from
A
so that the sum of the chosen elements equals
M
.
Two choices are said to be different if there exists an integer
i (1 \le i \le N)
such that one chooses
... | [
{
"input": "5 6\n1 2 3 3 6\n",
"output": "3\n"
},
{
"input": "10 23\n1 2 3 4 5 6 7 8 9 10\n",
"output": "18\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.