url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc357/tasks/abc357_c
Problem Statement For a non-negative integer K , we define a level- K carpet as follows: A level- 0 carpet is a 1 \times 1 grid consisting of a single black cell. For K > 0 , a level- K carpet is a 3^K \times 3^K grid. When this grid is divided into nine 3^{K-1} \times 3^{K-1} blocks: The central block consists entirel...
[ { "input": "1\n", "output": "###\n#.#\n###\n" }, { "input": "2\n", "output": "#########\n#.##.##.#\n#########\n###...###\n#.#...#.#\n###...###\n#########\n#.##.##.#\n#########\n" } ]
https://atcoder.jp/contests/abc357/tasks/abc357_d
Problem Statement For a positive integer N , let V_N be the integer formed by concatenating N exactly N times. More precisely, consider N as a string, concatenate N copies of it, and treat the result as an integer to get V_N . For example, V_3=333 and V_{10}=10101010101010101010 . Find the remainder when V_N is divided...
[ { "input": "5\n", "output": "55555\n" }, { "input": "9\n", "output": "1755646\n" }, { "input": "10000000000\n", "output": "468086693\n" } ]
https://atcoder.jp/contests/abc357/tasks/abc357_e
Problem Statement There is a directed graph with N vertices numbered 1 to N and N edges. The out-degree of every vertex is 1 , and the edge from vertex i points to vertex a_i . Count the number of pairs of vertices (u, v) such that vertex v is reachable from vertex u . Here, vertex v is reachable from vertex u if there...
[ { "input": "4\n2 1 1 4\n", "output": "8\n" }, { "input": "5\n2 4 3 1 2\n", "output": "14\n" }, { "input": "10\n6 10 4 1 5 9 8 6 5 1\n", "output": "41\n" } ]
https://atcoder.jp/contests/abc357/tasks/abc357_f
Problem Statement You are given sequences of length N , A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N) . You are also given Q queries to process in order. There are three types of queries: 1 l r x : Add x to each of A_l, A_{l+1}, \ldots, A_r . 2 l r x : Add x to each of B_l, B_{l+1}, \ldots, B_r . 3 l r : Print the ...
[ { "input": "5 6\n1 3 5 6 8\n3 1 2 1 2\n3 1 3\n1 2 5 3\n3 1 3\n1 1 3 1\n2 5 5 2\n3 1 5\n", "output": "16\n25\n84\n" }, { "input": "2 3\n1000000000 1000000000\n1000000000 1000000000\n3 1 1\n1 2 2 1000000000\n3 1 2\n", "output": "716070898\n151723988\n" } ]
https://atcoder.jp/contests/abc357/tasks/abc357_g
Problem Statement There is a special grid with N rows. ( N is even.) The i -th row from the top has \left \lceil \frac{i}{2} \right \rceil \times 2 cells from the left end. For example, when N = 6 , the grid looks like the following: Let (i, j) denote the cell at the i -th row from the top and j -th column from the lef...
[ { "input": "4 2\n2 1\n4 2\n", "output": "2\n" }, { "input": "6 3\n2 1\n3 3\n4 2\n", "output": "0\n" }, { "input": "100 10\n36 9\n38 5\n38 30\n45 1\n48 40\n71 52\n85 27\n86 52\n92 34\n98 37\n", "output": "619611437\n" }, { "input": "100000 10\n552 24\n4817 255\n7800 954\n23347...
https://atcoder.jp/contests/arc179/tasks/arc179_a
Problem Statement You are given integers N and K . The cumulative sums of an integer sequence X=(X_1,X_2,\dots ,X_N) of length N is defined as a sequence Y=(Y_0,Y_1,\dots ,Y_N) of length N+1 as follows: Y_0=0 Y_i=\displaystyle\sum_{j=1}^{i}X_j\ (i=1,2,\dots ,N) An integer sequence X=(X_1,X_2,\dots ,X_N) of length N is ...
[ { "input": "4 1\n-1 2 -3 4\n", "output": "Yes\n-3 -1 2 4\n" }, { "input": "4 -1\n1 -2 3 -4\n", "output": "No\n" }, { "input": "10 1000000000\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "Yes\n-100000...
https://atcoder.jp/contests/arc179/tasks/arc179_b
Problem Statement You are given a sequence (X_1, X_2, \dots, X_M) of length M consisting of integers between 1 and M , inclusive. Find the number, modulo 998244353 , of sequences A = (A_1, A_2, \dots, A_N) of length N consisting of integers between 1 and M , inclusive, that satisfy the following condition: For each B =...
[ { "input": "3 4\n2 1 2\n", "output": "14\n" }, { "input": "4 8\n1 2 3 4\n", "output": "65536\n" }, { "input": "4 9\n2 3 4 1\n", "output": "628\n" } ]
https://atcoder.jp/contests/arc179/tasks/arc179_c
Problem Statement This is an interactive problem (where your program interacts with the judge via input and output). You are given a positive integer N . The judge has a hidden positive integer R and N integers A_1, A_2, \dots, A_N . It is guaranteed that |A_i|\le R and \left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R...
[]
https://atcoder.jp/contests/arc179/tasks/arc179_d
Problem Statement You are given a tree with N vertices numbered 1, 2, \dots, N . The i -th edge connects vertices u_i and v_i bidirectionally. Initially, all vertices are painted white. To efficiently visit all vertices of this tree, Alice has invented a magical gate. She uses one piece and one gate to travel according...
[ { "input": "4\n1 2\n1 3\n1 4\n", "output": "3\n" }, { "input": "10\n1 7\n7 10\n10 8\n8 3\n8 4\n10 9\n9 6\n9 5\n7 2\n", "output": "10\n" } ]
https://atcoder.jp/contests/arc179/tasks/arc179_e
Problem Statement For positive integers h and w , let (h,w) denote a rectangle with height h and width w . In this problem, we do not consider rotating the rectangles, and the rectangles (h,w) and (w,h) are distinguished when h \neq w . A sequence of rectangles ((h_1,w_1),(h_2,w_2),\dots ,(h_n,w_n)) is called a rectang...
[ { "input": "4\n1 2\n1 3\n2 3\n3 1\n", "output": "7\n" }, { "input": "5\n2 1\n2 1\n1 2\n3 2\n1 4\n", "output": "10\n" }, { "input": "1\n1000000 1000000\n", "output": "1\n" }, { "input": "10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "55\n" } ]
https://atcoder.jp/contests/arc179/tasks/arc179_f
Problem Statement You are given a string S of length N consisting of the characters A and B . For a string X of length N consisting of the characters 1 , 2 , and 3 , the score is determined by the following procedure: First, initialize the variables h_1, h_2, h_3, P to 0 . Then, for i = 1, 2, \dots, N in this order, pe...
[ { "input": "5\n4\nABBA\n5\nAAAAA\n6\nBBBBBB\n7\nABABABA\n20\nAAABBBBBBBBAAABBBABA\n", "output": "1333\n12321\n333333\n1313212\n33311111133121111311\n" } ]
https://atcoder.jp/contests/abc356/tasks/abc356_a
Problem Statement You are given positive integers N , L , and R . For a sequence A = (1, 2, \dots, N) of length N , an operation of reversing the L -th through R -th elements was performed once. Print the sequence after this operation.
[ { "input": "5 2 3\n", "output": "1 3 2 4 5\n" }, { "input": "7 1 1\n", "output": "1 2 3 4 5 6 7\n" }, { "input": "10 1 10\n", "output": "10 9 8 7 6 5 4 3 2 1\n" } ]
https://atcoder.jp/contests/abc356/tasks/abc356_b
Problem Statement Takahashi is health-conscious and concerned about whether he is getting enough of M types of nutrients from his diet. For the i -th nutrient, his goal is to take at least A_i units per day. Today, he ate N foods, and from the i -th food, he took X_{i,j} units of nutrient j . Determine whether he has m...
[ { "input": "2 3\n10 20 30\n20 0 10\n0 100 100\n", "output": "Yes\n" }, { "input": "2 4\n10 20 30 40\n20 0 10 30\n0 100 100 0\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc356/tasks/abc356_c
Problem Statement You have N keys numbered 1, 2, \dots, N . Some of these are real keys, while the others are dummies. There is a door, Door X, into which you can insert any number of keys. Door X will open if and only if at least K real keys are inserted. You have conducted M tests on these keys. The i -th test went a...
[ { "input": "3 2 2\n3 1 2 3 o\n2 2 3 x\n", "output": "2\n" }, { "input": "4 5 3\n3 1 2 3 o\n3 2 3 4 o\n3 3 4 1 o\n3 4 1 2 o\n4 1 2 3 4 x\n", "output": "0\n" }, { "input": "11 4 9\n10 1 2 3 4 5 6 7 8 9 10 o\n11 1 2 3 4 5 6 7 8 9 10 11 o\n10 11 10 9 8 7 6 5 4 3 2 x\n10 11 9 1 4 3 7 5 6 2 10...
https://atcoder.jp/contests/abc356/tasks/abc356_d
Problem Statement Given integers N and M , compute the sum \displaystyle \sum_{k=0}^{N} \rm{popcount} (k \mathbin{\&} M) , modulo 998244353 . Here, \mathbin{\&} represents the bitwise \rm{AND} operation. What is the bitwise \rm{AND} operation? The result x = a \mathbin{\&} b of the bitwise \rm{AND} operation between no...
[ { "input": "4 3\n", "output": "4\n" }, { "input": "0 0\n", "output": "0\n" }, { "input": "1152921504606846975 1152921504606846975\n", "output": "499791890\n" } ]
https://atcoder.jp/contests/abc356/tasks/abc356_e
Problem Statement You are given a sequence A=(A_1,\ldots,A_N) of length N . Find \displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^{N}\left\lfloor\frac{\max(A_i,A_j)}{\min(A_i,A_j)}\right\rfloor . Here, \lfloor x \rfloor represents the greatest integer not greater than x . For example, \lfloor 3.14 \rfloor=3 and \lfloor 2 \rf...
[ { "input": "3\n3 1 4\n", "output": "8\n" }, { "input": "6\n2 7 1 8 2 8\n", "output": "53\n" }, { "input": "12\n3 31 314 3141 31415 314159 2 27 271 2718 27182 271828\n", "output": "592622\n" } ]
https://atcoder.jp/contests/abc356/tasks/abc356_f
Problem Statement You are given an integer K . For a set S that is initially empty, process Q queries of the following two types in order: 1 x : An integer x is given. If x is in S , remove x from S . Otherwise, add x to S . 2 x : An integer x that is in S is given. Consider a graph where the vertices are the numbers i...
[ { "input": "7 5\n1 3\n1 10\n2 3\n1 7\n2 3\n1 10\n2 3\n", "output": "1\n3\n2\n" }, { "input": "11 1000000000000000000\n1 1\n1 100\n1 10000\n1 1000000\n1 100000000\n1 10000000000\n1 1000000000000\n1 100000000000000\n1 10000000000000000\n1 1000000000000000000\n2 1\n", "output": "10\n" }, { ...
https://atcoder.jp/contests/abc356/tasks/abc356_g
Problem Statement Takahashi can swim in N different styles. When he swims in the i -th style, he consumes A_i stamina per second and advances B_i meters per second. Answer Q queries. The i -th query is as follows: Determine if it is possible to advance D_i meters while keeping the total stamina consumption at most C_i ...
[ { "input": "4\n1 2\n2 3\n3 3\n4 4\n5\n4 7\n7 7\n49 100\n1000 500\n4 5\n", "output": "3.000000000000000000\n1.750000000000000000\n-1\n125.000000000000000000\n1.500000000000000000\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_a
Problem Statement There is a bus stop where buses depart at X minutes past each hour. For example, if X=10 , buses depart at 0:10 , 1:10 , \ldots , and 23:10 . No buses depart at any other time. It is currently M minutes past H ( M\neq X ). How many minutes are left before the next bus departs?
[ { "input": "30 14 10\n", "output": "20\n" }, { "input": "12 23 30\n", "output": "42\n" }, { "input": "1 17 34\n", "output": "27\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_b
Problem Statement Takahashi made (N - 1) transactions at a bank. The transactions are described by integers A_1, A_2, \ldots, A_N . The i -th transaction is a deposit of (A_{i + 1} - A_i) yen if A_i < A_{i + 1} , and a withdrawal of (A_i - A_{i + 1}) yen if A_i > A_{i + 1} . (Yen is a currency of Japan.) Here, it is gu...
[ { "input": "4\n2 9 5 8\n", "output": "10 4\n" }, { "input": "5\n10 8 6 4 2\n", "output": "0 8\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_c
Problem Statement A good number is defined as follows. A positive integer x is said to be a good number if and only if: every pair of adjacent digits in x has a difference of 1 or less. Formally, if x has k digits and its decimal representation is d_1d_2 \dots d_k , then |d_i - d_{i+1}| \le 1 for all integers i with 1 ...
[ { "input": "7176\n", "output": "Yes\n" }, { "input": "2020\n", "output": "No\n" }, { "input": "3728\n", "output": "No\n" }, { "input": "987654321012345678\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_d
Problem Statement N teams competed in a programming contest. The contest lasted T minutes. Team i solved A_i problems, and the last acceptance time was B_i . In this contest, the ranks are determined as follows: Those who solved more problems rank higher. Among those with the same number of solved problems, those with ...
[ { "input": "6 120\n3 80\n4 90\n5 120\n5 100\n3 110\n4 70\n", "output": "220\n110\n20\n0\n250\n90\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_e
Problem Statement You want to implement a C-like comment-out system. You are given a length- N string S consisting of / , * , and lowercase English letters. You are asked to perform the following procedure against S . Prepare a variable x that takes on an integer value. x is initialized with 1 . Seek for an n such that...
[ { "input": "7\na/*b*/c\n", "output": "ac\n" }, { "input": "10\n/*a*//*b*/\n", "output": "\n" }, { "input": "18\n/*/a/*b*/c/*d*/e*/\n", "output": "ce*/\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_f
Problem Statement You are lining up dominoes. N clues are given: for each 1 \leq i \leq N , if domino S_i falls, then domino T_i will also fall. Determine if the given clues imply that if domino X falls, then domino Y will also fall.
[ { "input": "5\nsecond fourth\nfirst second\nsecond third\nthird fourth\nfourth fifth\nfifth sixth\n", "output": "Yes\n" }, { "input": "5\nfourth second\nfirst second\nsecond third\nthird fourth\nfourth fifth\nfifth sixth\n", "output": "No\n" }, { "input": "6\ne d\na b\nb a\na c\nc d\nd e...
https://atcoder.jp/contests/past19-open/tasks/past19_g
Problem Statement You are given an N -by- N matrix A . The element in the i -th row and j -th column of A is denoted by A(i,j) . Exactly one element of A is 0 , and each of the other (N^2-1) elements is an integer between 1 and N . How many ways are there to replace the only element 0 in A with an integer between 1 and...
[ { "input": "3\n1 2 3\n2 0 1\n3 1 2\n", "output": "1\n" }, { "input": "3\n2 1 0\n1 2 3\n1 3 2\n", "output": "0\n" }, { "input": "6\n4 5 5 2 4 2\n5 2 2 4 5 4\n5 2 0 4 5 4\n2 4 4 5 2 5\n4 5 5 2 4 2\n2 4 4 5 2 5\n", "output": "2\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_h
Problem Statement You are given an integer S , and N integers a_1,a_2,\dots,a_N . Can you construct a mathematical expression that evaluates to S using + , \times , and the N integers? Here, use each of the N integers exactly once. You can freely rearrange the integers. You may not use parentheses. You may not join int...
[ { "input": "3 11\n1 2 5\n", "output": "Yes\n1+2x5\n" }, { "input": "5 2\n1 1 1 1 1\n", "output": "Yes\n1+1x1x1x1\n" }, { "input": "2 12\n1 2\n", "output": "No\n" }, { "input": "6 302934\n614 490 585 613 420 945\n", "output": "Yes\n420+490x613+585+614+945\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_i
Problem Statement AtCoderLand has N islands: island 1 , island 2 , \ldots , and island N , and M roads: road 1 , road 2 , \ldots , and road M . Road i connects island A_i and island B_i bidirectionally. Road i\ (1\leq i\leq M) will be submerged on day D_i , so it will not be available on or after day D_i . The islands...
[ { "input": "5 6\n1 2 10\n1 3 25\n2 3 35\n2 4 15\n3 4 30\n4 5 40\n", "output": "25\n" }, { "input": "3 4\n1 2 31\n2 3 4\n2 3 15\n3 3 9\n", "output": "15\n" }, { "input": "15 20\n6 7 54\n5 15 63\n8 14 30\n5 8 52\n5 9 96\n1 13 51\n8 13 89\n4 15 81\n12 12 80\n4 10 48\n1 11 63\n1 9 72\n10 14 ...
https://atcoder.jp/contests/past19-open/tasks/past19_j
Problem Statement There are 3N people numbered from 1 to 3N . Person i has A_i yen (currency in Japan). You are going to group the 3N people into N groups of three people each. Let S_i be the total amount of yen in the i -th group. Find the minimum possible \displaystyle \max_{1 \leq k \leq N} S_k - \min_{1 \leq k \l...
[ { "input": "2\n1 3 4 6 2 9\n", "output": "1\n" }, { "input": "2\n0 0 0 0 0 100000000\n", "output": "100000000\n" }, { "input": "5\n614 490 420 945 613 585 760 38 926 725 667 685 449 455 873\n", "output": "35\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_k
Problem Statement There is an N -vertex tree whose vertices are numbered 1 through N . The i -th edge connects vertex u_i and vertex v_i bidirectionally. Vertex i has an integer A_i written on it. Determine if there is a way to choose K vertices among the N so that no pair of chosen vertices are adjacent. If there i...
[ { "input": "5 2\n1 2\n2 3\n1 4\n2 5\n3 1 4 1 5\n", "output": "9\n" }, { "input": "10 6\n7 3\n3 8\n5 1\n3 9\n2 5\n6 1\n5 4\n10 7\n7 1\n1 3 10 6 7 9 2 2 10 4\n", "output": "34\n" }, { "input": "10 6\n2 10\n1 10\n7 4\n8 9\n8 7\n4 3\n1 4\n6 7\n5 3\n2 5 1 2 3 6 2 9 9 7\n", "output": "-1\n...
https://atcoder.jp/contests/past19-open/tasks/past19_l
Problem Statement A length- k sequence A=(A_1,\ldots,A_k) is a zigzag sequence if: A_1 < A_2> A_3 < A_4 > \ldots , or A_1 > A_2 < A_3 > A_4 <\ldots . More formally, a sequence is said to be a zigzag sequence if and only if: A_i \neq A_{i+1}\ (1\leq i \leq k-1) , and (A_{i+1}-A_i)(A_i-A_{i-1}) < 0\ (2\leq i \leq k-1) . ...
[ { "input": "7\n5 1 2 3 4 3 3\n", "output": "4\n" }, { "input": "5\n1 2 3 4 5\n", "output": "2\n" } ]
https://atcoder.jp/contests/past19-open/tasks/past19_m
Problem Statement You are given an N -vertex M -edge simple directed graph. The vertices are numbered 1 through N , and the edges are numbered 1 through M . Edge j directs from vertex U_j to vertex V_j . Each vertex has an integer attribute point : the point of vertex i is P_i . Also, each edge has a real attribute...
[ { "input": "4 4\n2 5 3 1\n1 3 0.500000\n1 2 0.250000\n2 3 0.250000\n3 4 0.500000\n", "output": "3.7500000000\n" }, { "input": "3 1\n1 1 1\n1 2 0.000000\n", "output": "-1\n" }, { "input": "6 12\n22 75 26 45 72 81\n4 6 0.185514\n3 6 0.758252\n2 3 0.622989\n2 4 0.984614\n1 3 0.465086\n1 5 0...
https://atcoder.jp/contests/past19-open/tasks/past19_n
Problem Statement You are given a length- N sequence A=(A _ 1,A _ 2,\ldots,A _ N) of non-negative integers, and a real value x strictly greater than 0 and less than or equal to 1 . For an integer pair (l,r)\ (1\leq l\leq r\leq N) , we define f(l,r) as follows: \begin{aligned}f(l,r)&=A _ l+A _ {l+1}x+A _ {l+2}x ^ 2+\cdo...
[ { "input": "7\n3 1 4 1 5 9 2\n0.25\n4\n1 3\n3 6\n1 7\n2 2\n", "output": "3.5\n4.703125\n3.54443359375\n1\n" }, { "input": "15\n6 45 81 83 28 40 31 30 51 31 59 50 94 36 0\n0.998244353\n20\n1 2\n1 5\n1 10\n2 5\n2 10\n3 3\n3 8\n3 12\n4 4\n4 14\n5 5\n5 11\n5 13\n5 14\n6 7\n7 7\n8 10\n10 13\n10 14\n12 14...
https://atcoder.jp/contests/past19-open/tasks/past19_o
Problem Statement A 4\times 4 grid is said to be good if it is in the following state: For every integer i between 1 and 15 , inclusive, there is exactly one cell with that integer written on it. No other cell has something written on it. In other words, there is exactly one cell with nothing written on it. You are gi...
[ { "input": "1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 -1\n1 2 3 4\n5 6 -1 8\n9 10 7 11\n13 14 15 12\n", "output": "3\n" }, { "input": "-1 11 10 9\n1 12 15 8\n2 13 14 7\n3 4 5 6\n6 5 4 3\n7 12 15 2\n8 13 14 1\n9 10 11 -1\n", "output": "-1\n" }, { "input": "1 12 11 10\n2 13 -1 9\n3 14 15 8\n4...
https://atcoder.jp/contests/abc355/tasks/abc355_a
Problem Statement Takahashi's cake has been eaten by someone. There are three suspects: person 1 , person 2 , and person 3 . There are two witnesses, Ringo and Snuke. Ringo remembers that person A is not the culprit, and Snuke remembers that person B is not the culprit. Determine if the culprit can be uniquely identifi...
[ { "input": "1 2\n", "output": "3\n" }, { "input": "1 1\n", "output": "-1\n" }, { "input": "3 1\n", "output": "2\n" } ]
https://atcoder.jp/contests/abc355/tasks/abc355_b
Problem Statement You are given a sequence A=(A_1,A_2,\dots,A_N) of length N and a sequence B=(B_1,B_2,\dots,B_M) of length M . Here, all elements of A and B are pairwise distinct. Determine whether the sequence C=(C_1,C_2,\dots,C_{N+M}) formed by sorting all elements of A and B in ascending order contains two consecut...
[ { "input": "3 2\n3 2 5\n4 1\n", "output": "Yes\n" }, { "input": "3 2\n3 1 5\n4 2\n", "output": "No\n" }, { "input": "1 1\n1\n2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc355/tasks/abc355_c
Problem Statement There is an N \times N grid, where the cell at the i -th row from the top and the j -th column from the left contains the integer N \times (i-1) + j . Over T turns, integers will be announced. On Turn i , the integer A_i is announced, and the cell containing A_i is marked. Determine the turn on which ...
[ { "input": "3 5\n5 1 8 9 7\n", "output": "4\n" }, { "input": "3 5\n4 2 9 7 5\n", "output": "-1\n" }, { "input": "4 12\n13 9 6 5 2 7 16 14 8 3 10 11\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc355/tasks/abc355_d
Problem Statement You are given N intervals of real numbers. The i -th (1 \leq i \leq N) interval is [l_i, r_i] . Find the number of pairs (i, j)\,(1 \leq i < j \leq N) such that the i -th and j -th intervals intersect.
[ { "input": "3\n1 5\n7 8\n3 7\n", "output": "2\n" }, { "input": "3\n3 4\n2 5\n1 6\n", "output": "3\n" }, { "input": "2\n1 2\n3 4\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc355/tasks/abc355_e
Problem Statement This is an interactive problem (where your program interacts with the judge via input and output). You are given a positive integer N and integers L and R such that 0 \leq L \leq R < 2^N . The judge has a hidden sequence A = (A_0, A_1, \dots, A_{2^N-1}) consisting of integers between 0 and 99 , inclus...
[]
https://atcoder.jp/contests/abc355/tasks/abc355_f
Problem Statement You are given a weighted undirected connected graph G with N vertices and N-1 edges, where vertices are numbered 1 to N and edges are numbered 1 to N-1 . Edge i connects vertices a_i and b_i with a weight of c_i . You are given Q queries to process sequentially. The i -th query is described as follows...
[ { "input": "4 4\n1 2 6\n2 3 5\n2 4 4\n1 3 3\n1 2 3\n1 4 10\n3 4 1\n", "output": "12\n10\n10\n7\n" }, { "input": "8 6\n1 8 8\n1 6 10\n1 5 8\n2 6 6\n6 7 6\n1 3 9\n2 4 7\n1 3 4\n1 6 7\n3 4 6\n1 5 1\n7 8 4\n3 5 3\n", "output": "49\n46\n45\n38\n34\n33\n" } ]
https://atcoder.jp/contests/abc355/tasks/abc355_g
Problem Statement You are given a sequence P=(P_1,P_2,\dots,P_N) of length N . Takahashi and Aoki will play a game using the sequence P . First, Takahashi will choose K distinct integers x_1,x_2,\dots,x_K from 1,2,\dots,N . Next, Aoki will choose an integer y from 1,2,\dots,N with a probability proportional to P_y . Th...
[ { "input": "5 2\n1 1 1 1 1\n", "output": "3\n" }, { "input": "5 1\n0 0 1 0 0\n", "output": "0\n" }, { "input": "1 1\n100\n", "output": "0\n" }, { "input": "20 7\n4262 9522 2426 3823 7364 964 2743 2423 1955 5274 3684 847 363 35 278 3220 203 2904 6304 1928\n", "output": "22...
https://atcoder.jp/contests/arc178/tasks/arc178_a
Problem Statement You are given a positive integer N and a sequence of M positive integers A = (A_{1}, A_{2}, \dots, A_{M}) . Here, all elements of A are distinct integers between 1 and N , inclusive. A permutation P = (P_{1}, P_{2}, \dots, P_{N}) of (1, 2, \dots, N) is called a good permutation when it satisfies the f...
[ { "input": "4 1\n2\n", "output": "1 3 2 4\n" }, { "input": "5 3\n4 3 2\n", "output": "1 3 4 5 2\n" }, { "input": "92 4\n16 7 1 67\n", "output": "-1\n" }, { "input": "43 2\n43 2\n", "output": "-1\n" } ]
https://atcoder.jp/contests/arc178/tasks/arc178_b
Problem Statement You are given positive integers A_{1}, A_{2}, A_{3} . Find the number, modulo 998244353 , of tuples of positive integers (X_{1}, X_{2}, X_{3}) that satisfy all of the following conditions. X_{1} is a positive integer with A_{1} digits in decimal notation. X_{2} is a positive integer with A_{2} digits ...
[ { "input": "4\n1 1 1\n1 6 7\n167 167 167\n111 666 777\n", "output": "36\n45\n731780675\n0\n" } ]
https://atcoder.jp/contests/arc178/tasks/arc178_c
Problem Statement You are given positive integers N and L , and a sequence of positive integers A = (A_{1}, A_{2}, \dots , A_{N}) of length N . For each i = 1, 2, \dots , N , answer the following question: Determine if there exists a sequence of L non-negative integers B = (B_{1}, B_{2}, \dots, B_{L}) such that \displa...
[ { "input": "2 4\n10 5\n", "output": "3\n-1\n" }, { "input": "6 8\n167 924 167167 167924 116677 154308\n", "output": "11\n58\n10448\n10496\n7293\n9645\n" } ]
https://atcoder.jp/contests/arc178/tasks/arc178_d
Problem Statement You are given a positive integer N and a sequence of M non-negative integers A = (A_{1}, A_{2}, \dots, A_{M}) . Here, all elements of A are distinct integers between 0 and N-1 , inclusive. Find the number, modulo 998244353 , of permutations P of (0, 1, \dots, N-1) that satisfy the following condition....
[ { "input": "4 2\n1 3\n", "output": "8\n" }, { "input": "4 4\n0 3 2 1\n", "output": "1\n" }, { "input": "16 7\n9 2 4 0 1 6 7\n", "output": "3520\n" }, { "input": "92 4\n1 67 16 7\n", "output": "726870122\n" } ]
https://atcoder.jp/contests/arc178/tasks/arc178_e
Problem Statement There are N servals on a bridge of length L . The i -th serval is located at position A_{i} from the left end of the bridge. Here, 0 < A_{1} < A_{2} < \cdots < A_{N} < L holds. For each i = 1, 2, \dots, N , answer the following question: The servals will perform the following three actions in order: A...
[ { "input": "2 167\n9 24\n", "output": "182\n301\n" }, { "input": "1 924\n167\n", "output": "757\n" }, { "input": "10 924924167\n46001560 235529797 272749755 301863061 359726177 470023587 667800476 696193062 741860924 809211293\n", "output": "112048251\n409175578\n167800512\n997730745...
https://atcoder.jp/contests/arc178/tasks/arc178_f
Problem Statement You are given positive integers N , M , and K , and a sequence of M non-negative integers A = (A_{0}, A_{1}, \dots, A_{M-1}) . Here, 2^{N - 1} \leq K < 2^{N} holds. In the input, K is given as an N -digit number in binary notation, while the other integers are given in decimal notation. Additionally, ...
[ { "input": "2 4\n11\n1 0\n2 0 1\n0\n1 1\n", "output": "9\n" }, { "input": "3 3\n101\n2 1 2\n2 0 1\n1 0\n", "output": "23\n" }, { "input": "16 7\n1101010000100110\n11 0 1 2 3 7 10 11 12 13 14 15\n7 4 6 8 10 11 12 13\n6 0 1 6 8 10 12\n8 0 3 5 6 10 11 12 13\n10 0 1 2 3 4 5 6 8 12 13\n9 3 4 ...
https://atcoder.jp/contests/abc354/tasks/abc354_a
Problem Statement Takahashi is growing a plant. Its height at the time of germination is 0\,\mathrm{cm} . Considering the day of germination as day 0 , its height increases by 2^i\,\mathrm{cm} day i 's night (0 \le i) . Takahashi's height is H\,\mathrm{cm} . Every morning, Takahashi measures his height against this pla...
[ { "input": "54\n", "output": "6\n" }, { "input": "7\n", "output": "4\n" }, { "input": "262144\n", "output": "19\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_b
Problem Statement N AtCoder users have gathered to play AtCoder RPS 2 . The i -th user's name is S_i and their rating is C_i . AtCoder RPS 2 is played as follows: Assign the numbers 0, 1, \dots, N - 1 to the users in lexicographical order of their usernames. Let T be the sum of the ratings of the N users. The user assi...
[ { "input": "3\ntakahashi 2\naoki 6\nsnuke 5\n", "output": "snuke\n" }, { "input": "3\ntakahashi 2813\ntakahashixx 1086\ntakahashix 4229\n", "output": "takahashix\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_c
Problem Statement Takahashi has N cards from the card game "AtCoder Magics." The i -th card will be called card i . Each card has two parameters: strength and cost. Card i has a strength of A_i and a cost of C_i . He does not like weak cards, so he will discard them. Specifically, he will repeat the following operation...
[ { "input": "3\n2 4\n1 1\n3 2\n", "output": "2\n2 3\n" }, { "input": "5\n1 1\n10 2\n100 3\n1000 4\n10000 5\n", "output": "5\n1 2 3 4 5\n" }, { "input": "6\n32 101\n65 78\n2 29\n46 55\n103 130\n52 40\n", "output": "4\n2 3 5 6\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_d
Problem Statement The pattern of AtCoder's wallpaper can be represented on the xy -plane as follows: The plane is divided by the following three types of lines: x = n (where n is an integer) y = n (where n is an even number) x + y = n (where n is an even number) Each region is painted black or white. Any two regions ad...
[ { "input": "0 0 3 3\n", "output": "10\n" }, { "input": "-1 -2 1 3\n", "output": "11\n" }, { "input": "-1000000000 -1000000000 1000000000 1000000000\n", "output": "4000000000000000000\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_e
Problem Statement Takahashi and Aoki are playing a game using N cards. The front side of the i -th card has A_i written on it, and the back side has B_i written on it. Initially, the N cards are laid out on the table. With Takahashi going first, the two players take turns performing the following operation: Choose a pa...
[ { "input": "5\n1 9\n2 5\n4 9\n1 4\n2 5\n", "output": "Aoki\n" }, { "input": "9\n3 2\n1 7\n4 1\n1 8\n5 2\n9 8\n2 1\n6 8\n5 2\n", "output": "Takahashi\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_f
Problem Statement You are given an integer sequence A of length N . For each t = 1, 2, \dots, N , determine whether A_t is included in a longest increasing subsequence of A . Here, A_t is included in a longest increasing subsequence of A if and only if the following holds: Let L be the length of a longest increasing su...
[ { "input": "1\n5\n2 1 4 5 3\n", "output": "4\n1 2 3 4\n" }, { "input": "2\n6\n2 5 3 4 3 4\n5\n10000 1000 100 1 10\n", "output": "5\n1 3 4 5 6\n2\n4 5\n" } ]
https://atcoder.jp/contests/abc354/tasks/abc354_g
Problem Statement You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters and N positive integers A_1, A_2, \ldots, A_N . A subset T of \lbrace 1, 2, \ldots, N \rbrace is called a good set if there is no pair i, j \in T (i \neq j) such that S_i is a substring of S_j . Find the maximum poss...
[ { "input": "4\natcoder\nat\ncoder\ncode\n5 2 3 4\n", "output": "6\n" }, { "input": "10\nabcd\nabc\nab\na\nb\nc\nd\nab\nbc\ncd\n100 10 50 30 60 90 80 70 40 20\n", "output": "260\n" } ]
https://atcoder.jp/contests/ahc033/tasks/ahc033_a
Problem Statement There is a container terminal with an N \times N grid. Let (0,0) be the coordinates of the top-left square and (i,j) be the coordinates of the square located i squares down and j squares to the right from there. N^2 containers, numbered from 0 to N^2-1 , will be brought into the terminal. Using N cra...
[ { "input": "5\n24 10 17 15 13\n14 11 2 1 5\n7 9 6 21 20\n8 4 19 3 16\n18 23 22 0 12\n", "output": "PRDDDDRRRQLLLUUPRRRUQ\nB\nPRQB\nPRRRRUUQB\nPRRRRQB\n" } ]
https://atcoder.jp/contests/arc177/tasks/arc177_a
Problem Statement In Japan, there are six types of coins in circulation: 1 yen, 5 yen, 10 yen, 50 yen, 100 yen, and 500 yen. Answer the following question regarding these coins. Mr. AtCoder's wallet contains A 1 -yen coins, B 5 -yen coins, C 10 -yen coins, D 50 -yen coins, E 100 -yen coins, and F 500 -yen coins. He is ...
[ { "input": "0 0 6 3 4 1\n3\n700 250 160\n", "output": "Yes\n" }, { "input": "0 0 0 2 4 0\n3\n100 200 300\n", "output": "No\n" }, { "input": "0 0 0 0 8 8\n1\n250\n", "output": "No\n" }, { "input": "20 5 9 7 10 6\n5\n177 177 177 177 177\n", "output": "Yes\n" }, { "i...
https://atcoder.jp/contests/arc177/tasks/arc177_b
Problem Statement Mr. AtCoder has created a device consisting of N small light bulbs arranged in a row from left to right, and two switches A and B. Each light bulb can be in one of two states: 0 (OFF) and 1 (ON). Pressing each switch causes the following: Pressing switch A turns the leftmost light bulb in the 0 state ...
[ { "input": "5\n01100\n", "output": "4\nAAAB\n" } ]
https://atcoder.jp/contests/arc177/tasks/arc177_c
Problem Statement There is a grid with N rows and N columns. Let (i, j) (1 \leq i \leq N, 1 \leq j \leq N) denote the cell at the i -th row from the top and the j -th column from the left. Each cell is initially painted red or blue, with cell (i, j) being red if c_{i,j}= R and blue if c_{i,j}= B . You want to change th...
[ { "input": "5\nRBRBB\nRBRRR\nRRRBR\nRBBRB\nBBRBR\n", "output": "3\n" }, { "input": "5\nRBBBB\nBBBBB\nBBBBB\nBBBBB\nBBBBR\n", "output": "7\n" }, { "input": "10\nRRBBBBBBBB\nBRRBBBBBBB\nBBRRBBBBBB\nBBBRRBBBBB\nBBBBRRBBBB\nBBBBBRRBBB\nBBBBBBRRBB\nBBBBBBBRRB\nBBBBBBBBRR\nBBBBBBBBBR\n", "...
https://atcoder.jp/contests/arc177/tasks/arc177_d
Problem Statement AtCoder Street is a road represented by a straight line on flat ground. There are N utility poles of height H standing on this road. The poles are numbered 1, 2, \dots, N in chronological order. Pole i ( 1 \leq i \leq N ) is vertically positioned at coordinate X_i . The base of each pole is fixed to t...
[ { "input": "3 2\n0 3 1\n", "output": "4 2 2\n" }, { "input": "4 10\n10 55 20 45\n", "output": "0 4 4 8\n" }, { "input": "8 1\n5 0 6 3 8 1 7 2\n", "output": "0 64 32 48 24 28 28 32\n" }, { "input": "40 20\n695 793 11 502 114 861 559 4 212 609 894 435 429 94 91 258 161 45 33 60...
https://atcoder.jp/contests/arc177/tasks/arc177_e
Problem Statement In the AtCoder World Tour Finals 2800, N contestants participated, and a total of five problems were presented. Each problem is assigned an integer score of at least 1 point, and the problems are numbered so that the scores are non-decreasing from problem 1 to problem 5 . There are no partial points. ...
[ { "input": "6\n4\n0 1 1 0 0\n1 0 0 1 0\n1 1 0 1 0\n1 0 1 0 0\n1 2 3 4\n8\n0 1 0 0 0\n1 1 0 1 0\n0 1 1 0 1\n1 0 0 0 0\n1 1 0 1 0\n0 1 0 0 0\n0 0 0 1 0\n0 1 1 1 1\n7 4 2 8 3 6 5 1\n6\n1 1 0 0 0\n0 0 1 0 0\n1 1 1 0 0\n0 0 0 1 0\n1 1 1 1 0\n0 0 0 0 1\n1 2 3 4 5 6\n6\n1 1 0 0 0\n0 0 1 0 0\n1 1 1 0 0\n0 0 0 1 0\n1 1 ...
https://atcoder.jp/contests/arc177/tasks/arc177_f
Problem Statement The Republic of AtCoder consists of L+1 islands aligned east-west, numbered 0 to L from west to east. The islands are connected by air routes, where for each 1 \leq i \leq L , there is a bidirectional air route between islands i-1 and i , as shown in the figure below. Each air route is owned by comp...
[ { "input": "4 3\nAAJJ\n3 A\n1 J\n1 J\n", "output": "2\n" }, { "input": "8 3\nJJAAJJAJ\n2 A\n6 A\n8 J\n", "output": "6\n" }, { "input": "8 6\nJJAAJJAJ\n2 A\n6 A\n8 J\n8 J\n8 J\n8 J\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_a
Problem Statement There are N buildings aligned in a row. The i -th building from the left has a height of H_i . Determine if there is a building taller than the first one from the left. If such a building exists, find the position of the leftmost such building from the left.
[ { "input": "4\n3 2 5 2\n", "output": "3\n" }, { "input": "3\n4 3 2\n", "output": "-1\n" }, { "input": "7\n10 5 10 2 10 13 15\n", "output": "6\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_b
Problem Statement The AtCoder amusement park has an attraction that can accommodate K people. Now, there are N groups lined up in the queue for this attraction. The i -th group from the front (1\leq i\leq N) consists of A_i people. For all i (1\leq i\leq N) , it holds that A_i \leq K . Takahashi, as a staff member of t...
[ { "input": "7 6\n2 5 1 4 1 2 3\n", "output": "4\n" }, { "input": "7 10\n1 10 1 10 1 10 1\n", "output": "7\n" }, { "input": "15 100\n73 8 55 26 97 48 37 47 35 55 5 17 62 2 60\n", "output": "8\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_c
Problem Statement For positive integers x and y , define f(x, y) as the remainder of (x + y) divided by 10^8 . You are given a sequence of positive integers A = (A_1, \ldots, A_N) of length N . Find the value of the following expression: \displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(A_i,A_j) .
[ { "input": "3\n3 50000001 50000002\n", "output": "100000012\n" }, { "input": "5\n1 3 99999999 99999994 1000000\n", "output": "303999988\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_d
Problem Statement For positive integers x and y , define f(x, y) as follows: Interpret the decimal representations of x and y as strings and concatenate them in this order to obtain a string z . The value of f(x, y) is the value of z when interpreted as a decimal integer. For example, f(3, 14) = 314 and f(100, 1) = 100...
[ { "input": "3\n3 14 15\n", "output": "2044\n" }, { "input": "5\n1001 5 1000000 1000000000 100000\n", "output": "625549048\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_e
Problem Statement For strings x and y , define f(x, y) as follows: f(x, y) is the length of the longest common prefix of x and y . You are given N strings (S_1, \ldots, S_N) consisting of lowercase English letters. Find the value of the following expression: \displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(S_i,S_j) .
[ { "input": "3\nab abc arc\n", "output": "4\n" }, { "input": "11\nab bb aaa bba baba babb aaaba aabbb a a b\n", "output": "32\n" } ]
https://atcoder.jp/contests/abc353/tasks/abc353_f
Problem Statement Tiles are laid out on a coordinate plane. There are two types of tiles: small tiles of size 1\times1 and large tiles of size K\times K , laid out according to the following rules: For each pair of integers (i,j) , the square \lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace is contained wi...
[ { "input": "3\n7 2\n1 6\n", "output": "5\n" }, { "input": "1\n41 42\n13 56\n", "output": "42\n" }, { "input": "100\n100 99\n199 1\n", "output": "0\n" }, { "input": "96929423\n5105216413055191 10822465733465225\n1543712011036057 14412421458305526\n", "output": "79154049\n"...
https://atcoder.jp/contests/abc353/tasks/abc353_g
Problem Statement The Kingdom of AtCoder has N towns: towns 1 , 2 , \ldots , N . To move from town i to town j , you must pay a toll of C \times |i-j| yen. Takahashi, a merchant, is considering participating in zero or more of M upcoming markets. The i -th market (1 \leq i \leq M) is described by the pair of integers ...
[ { "input": "6 3\n4\n5 30\n2 10\n4 25\n2 15\n", "output": "49\n" }, { "input": "6 1000000000\n4\n5 30\n2 10\n4 25\n2 15\n", "output": "0\n" }, { "input": "50 10\n15\n37 261\n28 404\n49 582\n19 573\n18 633\n3 332\n31 213\n30 377\n50 783\n17 798\n4 561\n41 871\n15 525\n16 444\n26 453\n", ...
https://atcoder.jp/contests/abc352/tasks/abc352_a
Problem Statement The AtCoder railway line has N stations, numbered 1, 2, \ldots, N . On this line, there are inbound trains that start at station 1 and stop at the stations 2, 3, \ldots, N in order, and outbound trains that start at station N and stop at the stations N - 1, N - 2, \ldots, 1 in order. Takahashi is abou...
[ { "input": "7 6 1 3\n", "output": "Yes\n" }, { "input": "10 3 2 9\n", "output": "No\n" }, { "input": "100 23 67 45\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc352/tasks/abc352_b
Problem Statement Takahashi tried to type a string S consisting of lowercase English letters using a keyboard. He was typing while looking only at the keyboard, not the screen. Whenever he mistakenly typed a different lowercase English letter, he immediately pressed the backspace key. However, the backspace key was bro...
[ { "input": "abc\naxbxyc\n", "output": "1 3 6\n" }, { "input": "aaaa\nbbbbaaaa\n", "output": "5 6 7 8\n" }, { "input": "atcoder\natcoder\n", "output": "1 2 3 4 5 6 7\n" } ]
https://atcoder.jp/contests/abc352/tasks/abc352_c
Problem Statement There are N giants, named 1 to N . When giant i stands on the ground, their shoulder height is A_i , and their head height is B_i . You can choose a permutation (P_1, P_2, \ldots, P_N) of (1, 2, \ldots, N) and stack the N giants according to the following rules: First, place giant P_1 on the ground. T...
[ { "input": "3\n4 10\n5 8\n2 9\n", "output": "18\n" }, { "input": "5\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "5\n" }, { "input": "10\n690830957 868532399\n741145463 930111470\n612846445 948344128\n540375785 925723427\n723092548 925021315\n928915367 973970164\n563314352 832796216\n562681294...
https://atcoder.jp/contests/abc352/tasks/abc352_d
Problem Statement You are given a permutation P = (P_1, P_2, \dots, P_N) of (1, 2, \dots, N) . A length- K sequence of indices (i_1, i_2, \dots, i_K) is called a good index sequence if it satisfies both of the following conditions: 1 \leq i_1 < i_2 < \dots < i_K \leq N . The subsequence (P_{i_1}, P_{i_2}, \dots, P_{i_K...
[ { "input": "4 2\n2 3 1 4\n", "output": "1\n" }, { "input": "4 1\n2 3 1 4\n", "output": "0\n" }, { "input": "10 5\n10 1 6 8 7 2 5 9 3 4\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc352/tasks/abc352_e
Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N . Initially, G has no edges. You will perform M operations to add edges to G . The i -th operation (1 \leq i \leq M) is as follows: You are given a subset of vertices S_i=\lbrace A_{i,1},A_{i,2},\dots,A_{i,K_i}\rbrace consist...
[ { "input": "4 3\n3 3\n1 2 3\n2 2\n1 2\n3 4\n1 3 4\n", "output": "9\n" }, { "input": "3 2\n2 1\n1 2\n2 1\n1 2\n", "output": "-1\n" }, { "input": "10 5\n6 158260522\n1 3 6 8 9 10\n10 877914575\n1 2 3 4 5 6 7 8 9 10\n4 602436426\n2 6 7 9\n6 24979445\n2 3 4 5 8 10\n4 861648772\n2 4 8 9\n", ...
https://atcoder.jp/contests/abc352/tasks/abc352_f
Problem Statement There are N people, numbered 1 to N . A competition was held among these N people, and they were ranked accordingly. The following information is given about their ranks: Each person has a unique rank. For each 1 \leq i \leq M , if person A_i is ranked x -th and person B_i is ranked y -th, then x - y ...
[ { "input": "5 2\n2 3 3\n5 4 3\n", "output": "3 -1 -1 -1 -1\n" }, { "input": "3 0\n", "output": "-1 -1 -1\n" }, { "input": "8 5\n6 7 3\n8 1 7\n4 5 1\n7 2 1\n6 2 4\n", "output": "1 -1 -1 -1 -1 -1 -1 8\n" } ]
https://atcoder.jp/contests/abc352/tasks/abc352_g
Problem Statement Takahashi has various colors of socks in his chest of drawers. The colors of the socks are represented by integers from 1 to N , and there are A_i\ (\geq 2) socks of color i . He is about to choose which socks to wear today by performing the following operation: Continue to randomly draw one sock at a...
[ { "input": "2\n2 2\n", "output": "665496238\n" }, { "input": "1\n352\n", "output": "2\n" }, { "input": "6\n1796 905 2768 253 2713 1448\n", "output": "887165507\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_a
Problem Statement Team Takahashi and Team Aoki are playing a baseball game, with Team Takahashi batting first. Currently, the game has finished through the top of the ninth inning, and the bottom of the ninth is about to begin. Team Takahashi scored A_i runs in the top of the i -th inning (1\leq i\leq 9) , and Team Aok...
[ { "input": "0 1 0 1 2 2 0 0 1\n1 1 0 0 0 0 1 0\n", "output": "5\n" }, { "input": "0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_b
Problem Statement You are given two grids, each with N rows and N columns, referred to as grid A and grid B . Each cell in the grids contains a lowercase English letter. The character at the i -th row and j -th column of grid A is A_{i, j} . The character at the i -th row and j -th column of grid B is B_{i, j} . The tw...
[ { "input": "3\nabc\ndef\nghi\nabc\nbef\nghi\n", "output": "2 1\n" }, { "input": "1\nf\nq\n", "output": "1 1\n" }, { "input": "10\neixfumagit\nvtophbepfe\npxbfgsqcug\nugpugtsxzq\nbvfhxyehfk\nuqyfwtmglr\njaitenfqiq\nacwvufpfvv\njhaddglpva\naacxsyqvoj\neixfumagit\nvtophbepfe\npxbfgsqcug\nug...
https://atcoder.jp/contests/abc351/tasks/abc351_c
Problem Statement You have an empty sequence and N balls. The size of the i -th ball (1 \leq i \leq N) is 2^{A_i} . You will perform N operations. In the i -th operation, you add the i -th ball to the right end of the sequence, and repeat the following steps: If the sequence has one or fewer balls, end the operation. I...
[ { "input": "7\n2 1 1 3 5 3 3\n", "output": "3\n" }, { "input": "5\n0 0 0 1 2\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_d
Problem Statement There is a grid of H rows and W columns. Some cells (possibly zero) contain magnets. The state of the grid is represented by H strings S_1, S_2, \ldots, S_H of length W . If the j -th character of S_i is # , it indicates that there is a magnet in the cell at the i -th row from the top and j -th column...
[ { "input": "3 5\n.#...\n.....\n.#..#\n", "output": "9\n" }, { "input": "3 3\n..#\n#..\n..#\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_e
Problem Statement On a coordinate plane, there are N points P_1, P_2, \ldots, P_N , where point P_i has coordinates (X_i, Y_i) . The distance \text{dist}(A, B) between two points A and B is defined as follows: A rabbit is initially at point A . A rabbit at position (x, y) can jump to (x+1, y+1) , (x+1, y-1) , (x-1, y+1...
[ { "input": "3\n0 0\n1 3\n5 6\n", "output": "3\n" }, { "input": "5\n0 5\n1 7\n2 9\n3 8\n4 6\n", "output": "11\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_f
Problem Statement You are given an integer sequence A = (A_1, A_2, \dots, A_N) . Calculate the following expression: \displaystyle \sum_{i=1}^N \sum_{j=i+1}^N \max(A_j - A_i, 0) The constraints guarantee that the answer is less than 2^{63} .
[ { "input": "3\n2 5 3\n", "output": "4\n" }, { "input": "10\n5 9 3 0 4 8 7 5 4 0\n", "output": "58\n" } ]
https://atcoder.jp/contests/abc351/tasks/abc351_g
Problem Statement You are given a rooted tree 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 (p_i < i) . Additionally, there is a sequence A = (A_1, A_2, \dots, A_N) . The hash value of the rooted tree is calculated as follows: Define f(n) (1 \leq n \l...
[ { "input": "3 2\n1 1\n3 5 1\n3 4\n2 1\n", "output": "23\n7\n" }, { "input": "5 4\n1 1 2 2\n2 5 4 4 1\n3 3\n5 0\n4 5\n5 2\n", "output": "29\n17\n17\n47\n" }, { "input": "10 10\n1 2 1 2 5 6 3 5 1\n766294629 440423913 59187619 725560240 585990756 965580535 623321125 550925213 122410708 5493...
https://atcoder.jp/contests/arc176/tasks/arc176_a
Problem Statement There is an N \times N grid. Let (i, j) denote the cell at the i -th row from the top and the j -th column from the left. You are to fill each cell with 0 or 1 . Construct one method to fill the grid that satisfies all of the following conditions: The cells (A_1,B_1), (A_2,B_2), \dots, (A_M,B_M) conta...
[ { "input": "4 2\n1 4\n3 2\n", "output": "8\n1 2\n1 4\n2 1\n2 4\n3 2\n3 3\n4 1\n4 3\n" }, { "input": "3 3\n3 1\n2 3\n1 3\n", "output": "9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n" }, { "input": "7 3\n1 7\n7 6\n6 1\n", "output": "21\n1 6\n2 4\n4 1\n7 3\n3 6\n4 5\n6 1\n1 7\n7 6\n3...
https://atcoder.jp/contests/arc176/tasks/arc176_b
Problem Statement Find the last digit of the remainder when 2^N is divided by 2^M - 2^K . You are given T test cases, each of which must be solved.
[ { "input": "5\n9 6 2\n123 84 50\n95 127 79\n1000000007 998244353 924844033\n473234053352300580 254411431220543632 62658522328486675\n", "output": "2\n8\n8\n8\n4\n" } ]
https://atcoder.jp/contests/arc176/tasks/arc176_c
Problem Statement Print the number, modulo 998244353 , of permutations P=(P_1,P_2,\dots,P_N) of (1,2,\dots,N) that satisfy all of the following conditions: \max(P_{A_i},P_{B_i}) = C_i\ (1 \le i \le M) .
[ { "input": "4 2\n1 2 4\n2 3 2\n", "output": "2\n" }, { "input": "6 3\n1 4 3\n2 5 6\n3 4 2\n", "output": "8\n" }, { "input": "20 17\n9 16 13\n5 14 20\n15 20 14\n5 13 17\n18 20 14\n14 20 20\n6 13 11\n12 16 19\n2 15 10\n6 17 11\n7 18 7\n8 18 12\n8 16 13\n6 16 13\n2 18 10\n9 10 15\n7 14 20\n...
https://atcoder.jp/contests/arc176/tasks/arc176_d
Problem Statement You are given a permutation P=(P_1,P_2,\dots,P_N) of (1,2,\dots,N) . You will perform the following operation M times: Choose a pair of integers (i, j) such that 1 \le i < j \le N , and swap P_i and P_j . There are \left(\frac{N(N-1)}{2}\right)^M possible sequences of operations. For each of them, con...
[ { "input": "3 1\n1 3 2\n", "output": "8\n" }, { "input": "2 5\n2 1\n", "output": "1\n" }, { "input": "5 2\n3 5 1 4 2\n", "output": "833\n" }, { "input": "20 24\n14 1 20 6 11 3 19 2 7 10 9 18 13 12 17 8 15 5 4 16\n", "output": "203984325\n" } ]
https://atcoder.jp/contests/arc176/tasks/arc176_e
Problem Statement You are given two length- N sequences of positive integers: X=(X_1,X_2,\dots,X_N) and Y=(Y_1,Y_2,\dots,Y_N) . Additionally, you are given M length- N sequences of positive integers. The i -th sequence is A_i = (A_{i,1},A_{i,2},\dots,A_{i,N}) . For each i = 1,2,\dots,M , you must perform one of the fol...
[ { "input": "3 2\n4 4 2\n3 1 5\n2 5 2\n1 2 4\n", "output": "21\n" }, { "input": "3 5\n4 13 10\n14 9 4\n4 6 4\n13 18 16\n8 13 5\n7 18 17\n20 20 14\n", "output": "84\n" }, { "input": "5 12\n330 68 248 387 491\n295 366 376 262 192\n280 121 17 168 455\n288 179 210 378 490\n150 275 165 264 287...
https://atcoder.jp/contests/arc176/tasks/arc176_f
Problem Statement There is a tree with NM+1 vertices numbered 0 to NM . The i -th edge ( 1 \le i \le NM ) connects vertices i and \max(i-N,0) . Initially, vertex i is colored with color i \bmod N . You can perform the following operation zero or more times: Choose two vertices u and v connected by an edge. Repaint the ...
[ { "input": "3 1\n", "output": "42\n" }, { "input": "4 2\n", "output": "219100\n" }, { "input": "20 24\n", "output": "984288778\n" }, { "input": "123456 112233\n", "output": "764098676\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_a
Problem Statement You are given a string S of length 6 . It is guaranteed that the first three characters of S are ABC and the last three characters are digits. Determine if S is the abbreviation of a contest held and concluded on AtCoder before the start of this contest. Here, a string T is "the abbreviation of a cont...
[ { "input": "ABC349\n", "output": "Yes\n" }, { "input": "ABC350\n", "output": "No\n" }, { "input": "ABC316\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_b
Problem Statement Takahashi has N teeth, one in each of the holes numbered 1, 2, \dots, N . Dentist Aoki will perform Q treatments on these teeth and holes. In the i -th treatment, hole T_i is treated as follows: If there is a tooth in hole T_i , remove the tooth from hole T_i . If there is no tooth in hole T_i (i.e., ...
[ { "input": "30 6\n2 9 18 27 18 9\n", "output": "28\n" }, { "input": "1 7\n1 1 1 1 1 1 1\n", "output": "0\n" }, { "input": "9 20\n9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_c
Problem Statement You are given a permutation A=(A_1,\ldots,A_N) of (1,2,\ldots,N) . Transform A into (1,2,\ldots,N) by performing the following operation between 0 and N-1 times, inclusive: Operation: Choose any pair of integers (i,j) such that 1\leq i < j \leq N . Swap the elements at the i -th and j -th positions of...
[ { "input": "5\n3 4 1 2 5\n", "output": "2\n1 3\n2 4\n" }, { "input": "4\n1 2 3 4\n", "output": "0\n" }, { "input": "3\n3 1 2\n", "output": "2\n1 2\n2 3\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_d
Problem Statement There is an SNS used by N users, labeled with numbers from 1 to N . In this SNS, two users can become friends with each other. Friendship is bidirectional; if user X is a friend of user Y, user Y is always a friend of user X. Currently, there are M pairs of friendships on the SNS, with the i -th pair ...
[ { "input": "4 3\n1 2\n2 3\n1 4\n", "output": "3\n" }, { "input": "3 0\n", "output": "0\n" }, { "input": "10 8\n1 2\n2 3\n3 4\n4 5\n6 7\n7 8\n8 9\n9 10\n", "output": "12\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_e
Problem Statement You are given an integer N . You can perform the following two types of operations: Pay X yen to replace N with \displaystyle\left\lfloor\frac{N}{A}\right\rfloor . Pay Y yen to roll a die (dice) that shows an integer between 1 and 6 , inclusive, with equal probability. Let b be the outcome of the die,...
[ { "input": "3 2 10 20\n", "output": "20.000000000000000\n" }, { "input": "3 2 20 20\n", "output": "32.000000000000000\n" }, { "input": "314159265358979323 4 223606797 173205080\n", "output": "6418410657.7408381\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_f
Problem Statement You are given a string S = S_1 S_2 S_3 \dots S_{|S|} consisting of uppercase and lowercase English letters, ( , and ) . The parentheses in the string S are properly matched. Repeat the following operation until no more operations can be performed: First, select one pair of integers (l, r) that satisfi...
[ { "input": "((A)y)x\n", "output": "YAx\n" }, { "input": "((XYZ)n(X(y)Z))\n", "output": "XYZNXYZ\n" }, { "input": "(((()))(()))(())\n", "output": "\n" }, { "input": "dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve\n", "output": "dFGsdccCrFNNnplCtQPOKjsiIwwEysAve\n" } ]
https://atcoder.jp/contests/abc350/tasks/abc350_g
Problem Statement Beware the special input format and the smaller memory limit than usual. There is an undirected graph with vertices 1, 2, \dots, N , initially without edges. You need to process the following Q queries on this graph: 1 u v Type 1 : Add an edge between vertices u and v . Before adding the edge, u and v...
[ { "input": "6 12\n143209915 123840720 97293110\n89822758 207184717 689046893\n67757230 270920641 26993265\n952858464 221010240 871605818\n730183361 147726243 445163345\n963432357 295317852 195433903\n120904472 106195318 615645575\n817920568 27584394 770578609\n38727673 250957656 506822697\n139174867 566158852 4...
https://atcoder.jp/contests/masters2024-final-open/tasks/masters2024_final_a
Problem Statement Takahashi wants to operate a flying drone on a two-dimensional plane and visit N destinations in arbitrary order. Let x -axis be east-west and y -axis be north-south. The drone's flight area is a 2\cdot 10^5\times 2\cdot 10^5 square surrounded by four walls with x=-10^5,x=+10^5,y=-10^5,y=+10^5 . Fu...
[]
https://atcoder.jp/contests/masters2024-final/tasks/masters2024_final_a
Problem Statement Takahashi wants to operate a flying drone on a two-dimensional plane and visit N destinations in arbitrary order. Let x -axis be east-west and y -axis be north-south. The drone's flight area is a 2\cdot 10^5\times 2\cdot 10^5 square surrounded by four walls with x=-10^5,x=+10^5,y=-10^5,y=+10^5 . Fu...
[]
https://atcoder.jp/contests/abc349/tasks/abc349_a
Problem Statement There are N people labeled 1 to N , who have played several one-on-one games without draws. Initially, each person started with 0 points. In each game, the winner's score increased by 1 and the loser's score decreased by 1 (scores can become negative). Determine the final score of person N if the fina...
[ { "input": "4\n1 -2 -1\n", "output": "2\n" }, { "input": "3\n0 0\n", "output": "0\n" }, { "input": "6\n10 20 30 40 50\n", "output": "-150\n" } ]
https://atcoder.jp/contests/abc349/tasks/abc349_b
Problem Statement A string S consisting of lowercase English letters is a good string if and only if it satisfies the following property for all integers i not less than 1 : There are exactly zero or exactly two different letters that appear exactly i times in S . Given a string S , determine if it is a good string.
[ { "input": "commencement\n", "output": "Yes\n" }, { "input": "banana\n", "output": "No\n" }, { "input": "ab\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc349/tasks/abc349_c
Problem Statement A string T of length 3 consisting of uppercase English letters is an airport code for a string S of lowercase English letters if and only if T can be derived from S by one of the following methods: Take a subsequence of length 3 from S (not necessarily contiguous) and convert it to uppercase letters t...
[ { "input": "narita\nNRT\n", "output": "Yes\n" }, { "input": "losangeles\nLAX\n", "output": "Yes\n" }, { "input": "snuke\nRNG\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc349/tasks/abc349_d
Problem Statement For non-negative integers l and r (l < r) , let S(l, r) denote the sequence (l, l+1, \ldots, r-2, r-1) formed by arranging integers from l through r-1 in order. Furthermore, a sequence is called a good sequence if and only if it can be represented as S(2^i j, 2^i (j+1)) using non-negative integers i a...
[ { "input": "3 19\n", "output": "5\n3 4\n4 8\n8 16\n16 18\n18 19\n" }, { "input": "0 1024\n", "output": "1\n0 1024\n" }, { "input": "3940649673945088 11549545024454656\n", "output": "8\n3940649673945088 3940649673949184\n3940649673949184 4503599627370496\n4503599627370496 900719925474...