url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc260_f
Problem Statement We have a simple undirected graph G with (S+T) vertices and M edges. The vertices are numbered 1 through (S+T) , and the edges are numbered 1 through M . Edge i connects Vertices u_i and v_i . Here, vertex sets V_1 = \lbrace 1, 2,\dots, S\rbrace and V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace are bot...
[ { "input": "2 3 5\n1 3\n1 4\n1 5\n2 4\n2 5\n", "output": "1 2 4 5\n" }, { "input": "3 2 4\n1 4\n1 5\n2 5\n3 5\n", "output": "-1\n" }, { "input": "4 5 9\n3 5\n1 8\n3 7\n1 9\n4 6\n2 7\n4 8\n1 7\n2 9\n", "output": "1 7 2 9\n" } ]
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc254_g
Problem Statement There is a complex composed of N 10^9 -story skyscrapers. The skyscrapers are numbered 1 to N , and the floors are numbered 1 to 10^9 . From any floor of any skyscraper, one can use a skybridge to get to the same floor of any other skyscraper in one minute. Additionally, there are M elevators. The i -...
[ { "input": "3 4 3\n1 2 10\n2 3 7\n3 9 14\n3 1 3\n1 3 3 14\n3 1 2 7\n1 100 1 101\n", "output": "12\n7\n-1\n" }, { "input": "1 1 1\n1 1 2\n1 1 1 2\n", "output": "1\n" } ]
https://atcoder.jp/contests/newjudge-2308-algorithm/tasks/abc294_h
Problem Statement You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M . Edge i connects vertex u_i and vertex v_i . Find the number, modulo 998244353 , of ways to write an integer between 1 and K , inclusive, on each vertex of this graph to satisfy the following condition...
[ { "input": "4 3 2\n1 2\n2 4\n2 3\n", "output": "2\n" }, { "input": "4 0 10\n", "output": "10000\n" }, { "input": "5 10 5\n3 5\n1 3\n1 2\n1 4\n3 4\n2 5\n4 5\n1 5\n2 3\n2 4\n", "output": "120\n" }, { "input": "5 6 294\n1 2\n2 4\n1 3\n2 3\n4 5\n3 5\n", "output": "838338733\n...
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_a
問題文 文字列 S と文字 c が与えられます。 文字列 S のすべての文字 x に対して、以下の操作を同時に一度だけ行ってできる文字列を出力してください。 x が c と等しいとき、 x を xx に置き換える。そうでないときは何もしない。
[ { "input": "quen\ne\n", "output": "queen\n" }, { "input": "kenkoo\no\n", "output": "kenkoooo\n" }, { "input": "abracadabra\na\n", "output": "aabraacaadaabraa\n" } ]
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_b
問題文 縦に N マス、横に N マスからなる、マス目状に区切られた盤面があります。上から i 番目 (1 \leq i \leq N) 、左から j 番目 (1 \leq j \leq N) のマスを、マス (i, j) と呼ぶことにします。 盤面には N-1 個のクイーンが配置されており、 i 番目のクイーンはマス (r_i, c_i) にあります。 ここで、盤面が次の条件を満たすとき、盤面は 良い状態 です。 盤面上のどの縦・横・斜め 45 度のマス目の列を見ても、クイーンが 2 つ以上存在しない。 また、与えられる盤面は 良い状態 であることが保証されます。 この盤面に対して、 良い状態 を保ちつつクイーンを追加で 1 個配...
[ { "input": "5\n5 5\n3 1\n1 2\n4 3\n", "output": "2 4\n" }, { "input": "5\n2 5\n3 1\n1 2\n4 4\n", "output": "-1\n" } ]
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_c
問題文 頂点に 1, 2, \ldots, N の番号がついた N 頂点の木と、頂点の番号 S, T が与えられます。 i = 1, 2, \ldots, N-1 について、 i 番目の辺は頂点 u_i と頂点 v_i を結んでいます。 木のそれぞれの頂点 j について、以下の質問に答えてください。 頂点 S から頂点 j までの最短経路に含まれる頂点集合(頂点 S や頂点 j を含む)と、頂点 T から頂点 j までの最短経路に含まれる頂点集合(頂点 T や頂点 j を含む)の両方に属する頂点の数はいくつでしょうか?
[ { "input": "11 1 4\n1 2\n2 3\n3 5\n3 6\n2 4\n4 7\n1 8\n8 9\n8 10\n9 11\n", "output": "1\n1\n2\n1\n3\n3\n2\n2\n3\n3\n4\n" } ]
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_d
問題文 縦に R マス、横に C マスからなる、マス目状に区切られた盤面があります。上から i 番目 (1 \leq i \leq R) 、左から j 番目 (1 \leq j \leq C) のマスを、マス (i, j) と呼ぶことにします。 現在マス (r_s, c_s) に 1 個のクイーンが配置されています。 以下の行動を 三回 繰り返した時、 クイーンが (r_t, c_t) にある様な動き方は何通りありますか。 クイーンを盤面上の現在配置されているマスを含む縦・横・斜め 45 度のマス目の列上の 他のマス に移動する(現在配置されているマスに留まることはできない)
[ { "input": "3 3 1 1 3 3\n", "output": "29\n" }, { "input": "3 3 2 2 2 2\n", "output": "40\n" }, { "input": "100000 100000 1 1 100000 100000\n", "output": "10001499973\n" } ]
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_e
問題文 長さ N の数列 A = \left( a_1, a_2, \ldots, a_N \right) が与えられます。 この数列を、いくつかの連続する空でない部分列 B_1, B_2, \ldots, B_K に分割することを考えます。たとえば、 A = (5, -3, 6, 2, 4) のとき、 A の分割の例は以下のとおりです。 B_1 = (5), B_2 = (-3, 6, 2), B_3 = (4) B_1 = (5, -3), B_2 = (6, 2, 4) B_1 = (5, -3, 6, 2, 4) 部分列 B_i の スコア S \left( B_i \right) を、 B_i に含まれる項の最大値と最小値...
[ { "input": "9\n1 2 2 4 5 2 3 4 1\n", "output": "9\n" }, { "input": "12\n3 -1 4 1 5 -9 2 6 5 -3 5 9\n", "output": "37\n" } ]
https://atcoder.jp/contests/codequeen2023-final-open/tasks/codequeen2023_final_f
問題文 以下の条件を満たす様に二次元平面上に N 個の点 P_1 , P_2 , \ldots , P_N を置きます。この条件の元、 N 角形 P_1 P_2 \dots P_N の面積の最大値を求めてください。ただし、原点と点 P_i を結ぶ直線の x 軸正の向きとのなす角を \theta_i\ \mathrm{rad} とします。 i 番目の点 P_i は原点を中心とする半径 R_i の円周上に存在する 与えられる R は、 \displaystyle R_1 = R_N かつ \displaystyle R_1, R_N \leq R_i (1 \leq i \leq N) を満たすことが保証されます \displaysty...
[ { "input": "3\n1 1 1\n", "output": "0.433012701892219\n" }, { "input": "7\n1 2 1 3 1 2 1\n", "output": "2.147031208123904\n" } ]
https://atcoder.jp/contests/abc313/tasks/abc313_a
Problem Statement There are N people numbered 1 through N . Each person has a integer score called programming ability; person i 's programming ability is P_i points. How many more points does person 1 need, so that person 1 becomes the strongest? In other words, what is the minimum non-negative integer x such that P_1...
[ { "input": "4\n5 15 2 10\n", "output": "11\n" }, { "input": "4\n15 5 2 10\n", "output": "0\n" }, { "input": "3\n100 100 100\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc313/tasks/abc313_b
Problem Statement There are N competitive programmers numbered person 1 , person 2 , \ldots , and person N . There is a relation called superiority between the programmers. For all pairs of distinct programmers ( person X , person Y ) , exactly one of the following two relations holds: "person X is stronger than perso...
[ { "input": "3 2\n1 2\n2 3\n", "output": "1\n" }, { "input": "3 2\n1 3\n2 3\n", "output": "-1\n" }, { "input": "6 6\n1 6\n6 5\n6 2\n2 3\n4 3\n4 2\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc313/tasks/abc313_c
Problem Statement You are given an integer sequence A=(A_1,A_2,\dots,A_N) . You can perform the following operation any number of times (possibly zero). Choose integers i and j with 1\leq i,j \leq N . Decrease A_i by one and increase A_j by one. Find the minimum number of operations required to make the difference be...
[ { "input": "4\n4 7 3 7\n", "output": "3\n" }, { "input": "1\n313\n", "output": "0\n" }, { "input": "10\n999999997 999999999 4 3 2 4 999999990 8 999999991 999999993\n", "output": "2499999974\n" } ]
https://atcoder.jp/contests/abc313/tasks/abc313_d
Problem Statement This is an interactive task (where your program and the judge interact via Standard Input and Output). You are given an integer N and an odd number K . The judge has a hidden length- N sequence A = (A_1, A_2, \dots, A_N) consisting of 0 and 1 . While you cannot directly access the elements of sequence...
[]
https://atcoder.jp/contests/abc313/tasks/abc313_e
Problem Statement For a string S consisting of digits from 1 through 9 , let f(S) be the string T obtained by the following procedure. ( S_i denotes the i -th character of S .) Let T be an initially empty string. For i=1, 2, \dots, |S| - 1 , perform the following operation: Append n copies of S_i to the tail of T , wh...
[ { "input": "3\n313\n", "output": "4\n" }, { "input": "9\n123456789\n", "output": "-1\n" }, { "input": "2\n11\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc313/tasks/abc313_f
Problem Statement There are N cards numbered 1 through N . Each face of a card has an integer written on it; card i has A_i on its front and B_i on its back. Initially, all cards are face up. There are M machines numbered 1 through M . Machine j has two (not necessarily distinct) integers X_j and Y_j between 1 and N...
[ { "input": "3 1\n3 10\n10 6\n5 2\n1 2\n", "output": "19.500000\n" }, { "input": "1 3\n5 100\n1 1\n1 1\n1 1\n", "output": "100.000000\n" }, { "input": "8 10\n6918 9211\n16 1868\n3857 8537\n3340 8506\n6263 7940\n1449 4593\n5902 1932\n310 6991\n4 4\n8 6\n3 5\n1 1\n4 2\n5 6\n7 5\n3 3\n1 5\n3...
https://atcoder.jp/contests/abc313/tasks/abc313_g
Problem Statement There are N plates numbered 1 through N . Dish i has a_i stones on it. There is also an empty bag. You can perform the following two kinds of operations any number of times (possibly zero) in any order. Remove one stone from each plate with one or more stones. Put the removed stones into the bag. T...
[ { "input": "3\n3 1 3\n", "output": "7\n" }, { "input": "1\n0\n", "output": "1\n" }, { "input": "5\n1 3 5 7 9\n", "output": "36\n" }, { "input": "10\n766294629 440423913 59187619 725560240 585990756 965580535 623321125 550925213 122410708 549392044\n", "output": "666174028...
https://atcoder.jp/contests/abc313/tasks/abc313_h
Problem Statement (2N+1) people are forming two rows to take a group photograph. There are N people in the front row; the i -th of them has a height of A_i . There are (N+1) people in the back row; the i -th of them has a height of B_i . It is guaranteed that the heights of the (2N+1) people are distinct. Within ea...
[ { "input": "3\n1 12 6\n4 3 10 9\n", "output": "2\n" }, { "input": "1\n5\n1 10\n", "output": "0\n" }, { "input": "10\n189330739 910286918 802329211 923078537 492686568 404539679 822804784 303238506 650287940 1\n125660016 430302156 982631932 773361868 161735902 731963982 317063340 88089572...
https://atcoder.jp/contests/agc063/tasks/agc063_a
Problem Statement You are given a string of length N+1 consisting of A and B : S = S_0\cdots S_N . For each k=1, \ldots, N , solve the following problem. Alice and Bob will play a game using a set X , which is initially empty. For t=1,\ldots, k in this order, they will do the following action: if t is odd, Alice will ...
[ { "input": "2\nABB\n", "output": "Alice\nBob\n" }, { "input": "4\nAAAAA\n", "output": "Alice\nAlice\nAlice\nAlice\n" }, { "input": "7\nBBAABABA\n", "output": "Bob\nBob\nAlice\nBob\nAlice\nBob\nAlice\n" } ]
https://atcoder.jp/contests/agc063/tasks/agc063_b
Problem Statement A sequence a = (a_1, \ldots, a_n) consisting of positive integers is said to be generatable when one can obtain a by repeating the following operation on an empty sequence. Operation: Choose a positive integer k , and insert (1, 2, \ldots, k-1, k) into some position in the sequence. More formally, for...
[ { "input": "6\n1 2 1 2 1 3\n", "output": "11\n" }, { "input": "5\n1 1 1 1 1\n", "output": "15\n" }, { "input": "7\n1 2 1 2 1 3 4\n", "output": "13\n" } ]
https://atcoder.jp/contests/agc063/tasks/agc063_c
Problem Statement You are given sequences of non-negative integers: A = (A_1, \ldots, A_N) and B=(B_1, \ldots, B_N) . Determine whether one can make A equal B by performing the following operation between 0 and N times, inclusive. Operation: Choose integers x,y such that 0\leq x < y\leq 10^{18} . For every i , replace ...
[ { "input": "4\n7 2 4 5\n3 3 5 0\n", "output": "Yes\n2\n3 5\n3 6\n" }, { "input": "1\n5\n3\n", "output": "Yes\n1\n2 4\n" }, { "input": "2\n3 1\n3 1\n", "output": "Yes\n0\n" }, { "input": "2\n0 0\n1 2\n", "output": "No\n" } ]
https://atcoder.jp/contests/agc063/tasks/agc063_d
Problem Statement You are given positive integers N, a, b, c, d . Determine whether there is a non-negative integer x such that x\equiv a+kb \pmod{c+kd} for every k=0,1,\ldots,N-1 . If it exists, find the smallest such x modulo 998244353 .
[ { "input": "2 1 2 3 4\n", "output": "10\n" }, { "input": "2 1 1 10 10\n", "output": "-1\n" }, { "input": "100 20 30 2 3\n", "output": "0\n" }, { "input": "9 12 34 56 78\n", "output": "827501367\n" } ]
https://atcoder.jp/contests/agc063/tasks/agc063_e
Problem Statement There is 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 P_i . You are given a non-negative integer r and a sequence of non-negative integers A = (A_1, \ldots, A_N) . You can perform the following operation on the sequence any numbe...
[ { "input": "3\n1 1\n2\n1 1 1\n", "output": "4\n" }, { "input": "3\n1 2\n1\n1 1 1\n", "output": "5\n" }, { "input": "3\n1 2\n2\n1 1 1\n", "output": "6\n" }, { "input": "5\n1 1 3 3\n2\n0 1 0 1 2\n", "output": "48\n" }, { "input": "5\n1 1 3 3\n123456789\n1 2 3 4 5\n"...
https://atcoder.jp/contests/agc063/tasks/agc063_f
Problem Statement You are given pairs of non-negative integers a = (a_1,a_2) and b = (b_1,b_2) . You can perform the following operation on the pair a any number of times, possibly zero. Operation: Choose a positive real number x . Replace a = (a_1,a_2) with (\lfloor a_1x\rfloor, \lfloor a_2x\rfloor) . Your objective ...
[ { "input": "7\n2 3 1 1\n1 1 2 3\n3 2 9 8\n12 34 56 78\n56 78 12 34\n87 65 43 21\n43 21 87 65\n", "output": "1\n-1\n3\n-1\n4\n2\n-1\n" }, { "input": "9\n5 5 5 5\n5 5 3 3\n3 9 0 2\n3 9 0 3\n0 3 3 9\n3 0 2 0\n5 2 0 0\n0 0 5 2\n0 0 0 0\n", "output": "0\n1\n1\n2\n-1\n1\n1\n-1\n0\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_a
Problem Statement Given a length- 3 string S consisting of uppercase English letters, print Yes if S equals one of ACE , BDF , CEG , DFA , EGB , FAC , and GBD ; print No otherwise.
[ { "input": "ABC\n", "output": "No\n" }, { "input": "FAC\n", "output": "Yes\n" }, { "input": "XYX\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_b
Problem Statement Takahashi invented Tak Code, a two-dimensional code. A TaK Code satisfies all of the following conditions: It is a region consisting of nine horizontal rows and nine vertical columns. All the 18 cells in the top-left and bottom-right three-by-three regions are black. All the 14 cells that are adjacen...
[ { "input": "19 18\n###......###......\n###......###......\n###..#...###..#...\n..............#...\n..................\n..................\n......###......###\n......###......###\n......###......###\n.###..............\n.###......##......\n.###..............\n............###...\n...##.......###...\n...##.......#...
https://atcoder.jp/contests/abc312/tasks/abc312_c
Problem Statement There are N sellers and M buyers in an apple market. The i -th seller may sell an apple for A_i yen or more (yen is the currency in Japan). The i -th buyer may buy an apple for B_i yen or less. Find the minimum integer X that satisfies the following condition. Condition: The number of people who may s...
[ { "input": "3 4\n110 90 120\n100 80 120 10000\n", "output": "110\n" }, { "input": "5 2\n100000 100000 100000 100000 100000\n100 200\n", "output": "201\n" }, { "input": "3 2\n100 100 100\n80 120\n", "output": "100\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_d
Problem Statement You are given a non-empty string S consisting of ( , ) , and ? . There are 2^x ways to obtain a new string by replacing each ? in S with ( and ) , where x is the number of occurrences of ? in S . Among them, find the number, modulo 998244353 , of ways that yield a parenthesis string . A string is sai...
[ { "input": "(???(?\n", "output": "2\n" }, { "input": ")))))\n", "output": "0\n" }, { "input": "??????????????(????????(??????)?????????(?(??)\n", "output": "603032273\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_e
Problem Statement There are N rectangular cuboids in a three-dimensional space. These cuboids do not overlap. Formally, for any two different cuboids among them, their intersection has a volume of 0 . The diagonal of the i -th cuboid is a segment that connects two points (X_{i,1},Y_{i,1},Z_{i,1}) and (X_{i,2},Y_{i,2},...
[ { "input": "4\n0 0 0 1 1 1\n0 0 1 1 1 2\n1 1 1 2 2 2\n3 3 3 4 4 4\n", "output": "1\n1\n0\n0\n" }, { "input": "3\n0 0 10 10 10 20\n3 4 1 15 6 10\n0 9 6 1 20 10\n", "output": "2\n1\n1\n" }, { "input": "8\n0 0 0 1 1 1\n0 0 1 1 1 2\n0 1 0 1 2 1\n0 1 1 1 2 2\n1 0 0 2 1 1\n1 0 1 2 1 2\n1 1 0 2...
https://atcoder.jp/contests/abc312/tasks/abc312_f
Problem Statement There are N items. Each of these is one of a pull-tab can, a regular can, or a can opener. The i -th item is described by an integer pair (T_i, X_i) as follows: If T_i = 0 , the i -th item is a pull-tab can; if you obtain it, you get a happiness of X_i . If T_i = 1 , the i -th item is a regular can; i...
[ { "input": "8 4\n0 6\n0 6\n1 3\n1 5\n1 15\n2 1\n2 10\n2 100\n", "output": "27\n" }, { "input": "5 5\n1 5\n1 5\n1 5\n1 5\n1 5\n", "output": "0\n" }, { "input": "12 6\n2 2\n0 1\n0 9\n1 3\n1 5\n1 3\n0 4\n2 1\n1 8\n2 1\n0 1\n0 4\n", "output": "30\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_g
Problem Statement You are given a tree with N vertices. The vertices are numbered from 1 through N , and the i -th edge connects vertex A_i and vertex B_i . Find the number of tuples of integers (i,j,k) such that: 1 \leq i < j < k \leq N ; and the given tree does not contain a simple path that contains all of vertices...
[ { "input": "5\n1 2\n2 3\n2 4\n1 5\n", "output": "2\n" }, { "input": "6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "output": "0\n" }, { "input": "12\n1 6\n3 4\n10 4\n5 9\n3 1\n2 3\n7 2\n2 12\n1 5\n6 8\n4 11\n", "output": "91\n" } ]
https://atcoder.jp/contests/abc312/tasks/abc312_h
Problem Statement Takahashi is going to decide nicknames of N people, person 1,\ldots,N . Person i wants a nickname S_i . To avoid giving the same nickname to multiple people, he is going to decide their nicknames as follows: For each i=1,\ldots,N in order, decide person i 's nickname as follows: Initialize a variable...
[ { "input": "3\nsnuke\nsnuke\nrng\n", "output": "1 2 1\n" }, { "input": "4\naa\na\na\naaa\n", "output": "1 1 3 2\n" }, { "input": "5\nx\nx\nx\nx\nx\n", "output": "1 2 3 4 5\n" } ]
https://atcoder.jp/contests/abc311/tasks/abc311_a
Problem Statement You are given a string S consisting of A , B , and C . S is guaranteed to contain all of A , B , and C . If the characters of S are checked one by one from the left, how many characters will have been checked when the following condition is satisfied for the first time? All of A , B , and C have appea...
[ { "input": "5\nACABB\n", "output": "4\n" }, { "input": "4\nCABC\n", "output": "3\n" }, { "input": "30\nAABABBBABABBABABCABACAABCBACCA\n", "output": "17\n" } ]
https://atcoder.jp/contests/abc311/tasks/abc311_b
Problem Statement There are N people numbered 1 to N . You are given their schedule for the following D days. The schedule for person i is represented by a string S_i of length D . If the j -th character of S_i is o , person i is free on the j -th day; if it is x , they are occupied that day. From these D days, conside...
[ { "input": "3 5\nxooox\noooxx\noooxo\n", "output": "2\n" }, { "input": "3 3\noxo\noxo\noxo\n", "output": "1\n" }, { "input": "3 3\noox\noxo\nxoo\n", "output": "0\n" }, { "input": "1 7\nooooooo\n", "output": "7\n" }, { "input": "5 15\noxooooooooooooo\noxooxoooooooo...
https://atcoder.jp/contests/abc311/tasks/abc311_c
Problem Statement There is a directed graph with N vertices and N edges. The i -th edge goes from vertex i to vertex A_i . (The constraints guarantee that i \neq A_i .) Find a directed cycle without the same vertex appearing multiple times. It can be shown that a solution exists under the constraints of this problem. N...
[ { "input": "7\n6 7 2 1 3 4 5\n", "output": "4\n7 5 3 2\n" }, { "input": "2\n2 1\n", "output": "2\n1 2\n" }, { "input": "8\n3 7 4 7 3 3 8 2\n", "output": "3\n2 7 8\n" } ]
https://atcoder.jp/contests/abc311/tasks/abc311_d
Problem Statement There is an N \times M grid and a player standing on it. Let (i,j) denote the square at the i -th row from the top and j -th column from the left of this grid. Each square of this grid is ice or rock, which is represented by N strings S_1,S_2,\dots,S_N of length M as follows: if the j -th character of...
[ { "input": "6 6\n######\n#....#\n#.#..#\n#..#.#\n#....#\n######\n", "output": "12\n" }, { "input": "21 25\n#########################\n#..............###...####\n#..............#..#...###\n#........###...#...#...##\n#........#..#..#........#\n#...##...#..#..#...#....#\n#..#..#..###...#..#.....#\n#..#...
https://atcoder.jp/contests/abc311/tasks/abc311_e
Problem Statement There is a grid with H rows and W columns. Let (i, j) denote the square at the i -th row from the top and j -th column from the left of the grid. Each square of the grid is holed or not. There are exactly N holed squares: (a_1, b_1), (a_2, b_2), \dots, (a_N, b_N) . When the triple of positive integers...
[ { "input": "2 3 1\n2 3\n", "output": "6\n" }, { "input": "3 2 6\n1 1\n1 2\n2 1\n2 2\n3 1\n3 2\n", "output": "0\n" }, { "input": "1 1 0\n", "output": "1\n" }, { "input": "3000 3000 0\n", "output": "9004500500\n" } ]
https://atcoder.jp/contests/abc311/tasks/abc311_f
Problem Statement There is an N \times M grid and a player standing on it. Let (i,j) denote the square at the i -th row from the top and j -th column from the left of this grid. Each square of this grid is black or white, which is represented by N strings S_1,S_2,\dots,S_N of length M as follows: if the j -th character...
[ { "input": "2 2\n.#\n..\n", "output": "3\n" }, { "input": "5 5\n....#\n...#.\n..#..\n.#.#.\n#...#\n", "output": "92\n" }, { "input": "25 25\n.........................\n.........................\n.........................\n.........................\n.........................\n...............
https://atcoder.jp/contests/abc311/tasks/abc311_g
Problem Statement There is an N \times M grid, where the square at the i -th row from the top and j -th column from the left has a non-negative integer A_{i,j} written on it. Let us choose a rectangular region R . Formally, the region is chosen as follows. Choose integers l_x, r_x, l_y, r_y such that 1 \le l_x \le r_x ...
[ { "input": "3 3\n5 4 3\n4 3 2\n3 2 1\n", "output": "48\n" }, { "input": "4 5\n3 1 4 1 5\n9 2 6 5 3\n5 8 9 7 9\n3 2 3 8 4\n", "output": "231\n" }, { "input": "6 6\n1 300 300 300 300 300\n300 1 300 300 300 300\n300 300 1 300 300 300\n300 300 300 1 300 300\n300 300 300 300 1 300\n300 300 30...
https://atcoder.jp/contests/abc311/tasks/abc311_h
Problem Statement There is a rooted tree T with N vertices numbered 1 to N . The root is vertex 1 , and the parent of vertex i (2 \leq i \leq N) is P_i . Each vertex has two non-negative integer values called beauty and weight . The beauty and weight of vertex i are B_i and W_i , respectively. Additionally, each vertex...
[ { "input": "4 10\n1 2 2\n2 1 0\n4 2 1\n6 8 0\n7 4 1\n", "output": "9\n10\n6\n7\n" }, { "input": "5 5\n1 2 2 3\n1 1 0\n10 1 1\n100 1 0\n1000 1 1\n10000 1 1\n", "output": "11001\n10110\n10100\n1000\n10000\n" }, { "input": "20 100\n1 2 1 1 1 6 6 5 1 7 9 4 6 4 15 16 8 2 5\n887945036308847 12...
https://atcoder.jp/contests/abc310/tasks/abc310_a
Problem Statement Takahashi wants a beverage called AtCoder Drink in a restaurant. It can be ordered at a regular price of P yen. He also has a discount coupon that allows him to order it at a lower price of Q yen. However, he must additionally order one of the restaurant's N dishes to use that coupon. For each i = ...
[ { "input": "3 100 50\n60 20 40\n", "output": "70\n" }, { "input": "3 100 50\n60000 20000 40000\n", "output": "100\n" } ]
https://atcoder.jp/contests/abc310/tasks/abc310_b
Problem Statement AtCoder Shop has N products. The price of the i -th product (1\leq i\leq N) is P _ i . The i -th product (1\leq i\leq N) has C_i functions. The j -th function (1\leq j\leq C _ i) of the i -th product (1\leq i\leq N) is represented as an integer F _ {i,j} between 1 and M , inclusive. Takahashi wonder...
[ { "input": "5 6\n10000 2 1 3\n15000 3 1 2 4\n30000 3 1 3 5\n35000 2 1 5\n100000 6 1 2 3 4 5 6\n", "output": "Yes\n" }, { "input": "4 4\n3 1 1\n3 1 2\n3 1 2\n4 2 2 3\n", "output": "No\n" }, { "input": "20 10\n72036 3 3 4 9\n7716 4 1 2 3 6\n54093 5 1 6 7 8 10\n25517 7 3 4 5 6 7 9 10\n96930...
https://atcoder.jp/contests/abc310/tasks/abc310_c
Problem Statement There are N sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it. For each i = 1, 2, \ldots, N , the letters written on the balls stuck onto the i -th stick are represented by a string S_i . Specifically, the number of balls stuck onto the i -th stick is t...
[ { "input": "6\na\nabc\nde\ncba\nde\nabc\n", "output": "3\n" } ]
https://atcoder.jp/contests/abc310/tasks/abc310_d
Problem Statement There are N sports players. Among them, there are M incompatible pairs. The i -th incompatible pair (1\leq i\leq M) is the A_i -th and B_i -th players. You will divide the players into T teams. Every player must belong to exactly one team, and every team must have one or more players. Additionally, ...
[ { "input": "5 2 2\n1 3\n3 4\n", "output": "4\n" }, { "input": "5 1 2\n1 3\n3 4\n", "output": "0\n" }, { "input": "6 4 0\n", "output": "65\n" }, { "input": "10 6 8\n5 9\n1 4\n3 8\n1 6\n4 10\n5 7\n5 6\n3 7\n", "output": "8001\n" } ]
https://atcoder.jp/contests/abc310/tasks/abc310_e
Problem Statement You are given a string S of length N consisting of 0 and 1 . It describes a length- N sequence A=(A _ 1,A _ 2,\ldots,A _ N) . If the i -th character of S (1\leq i\leq N) is 0 , then A _ i=0 ; if it is 1 , then A _ i=1 . Find the following: \[\sum _ {1\leq i\leq j\leq N}(\cdots((A _ i\barwedge A _ {i+...
[ { "input": "5\n00110\n", "output": "9\n" }, { "input": "30\n101010000100101011010011000010\n", "output": "326\n" } ]
https://atcoder.jp/contests/abc310/tasks/abc310_f
Problem Statement We have N dice. For each i = 1, 2, \ldots, N , when the i -th die is thrown, it shows a random integer between 1 and A_i , inclusive, with equal probability. Find the probability, modulo 998244353 , that the following condition is satisfied when the N dice are thrown simultaneously. There is a way to...
[ { "input": "4\n1 7 2 9\n", "output": "942786334\n" }, { "input": "7\n1 10 100 1000 10000 100000 1000000\n", "output": "996117877\n" } ]
https://atcoder.jp/contests/abc310/tasks/abc310_g
Problem Statement There are N Takahashi. The i -th Takahashi has an integer A_i and B_i balls. An integer x between 1 and K , inclusive, will be chosen uniformly at random, and they will repeat the following operation x times. For every i , the i -th Takahashi gives all his balls to the A_i -th Takahashi. Beware that a...
[ { "input": "5 2\n3 1 4 1 5\n1 1 2 3 5\n", "output": "3 0 499122179 499122178 5\n" }, { "input": "3 1000\n1 1 1\n1 10 100\n", "output": "111 0 0\n" }, { "input": "16 1000007\n16 12 6 12 1 8 14 14 5 7 6 5 9 6 10 9\n719092922 77021920 539975779 254719514 967592487 476893866 368936979 465399...
https://atcoder.jp/contests/abc310/tasks/abc310_h
Problem Statement A monster with health H has appeared right in front of you. Your magic power is now 0 . You can use N moves called move 1 , move 2 , \ldots , move N , any number of times in any order. For each i = 1, 2, \ldots, N , move i can only be used when your magic power is at least C_i , and its use will decr...
[ { "input": "3 48\n3 20\n-4 2\n1 5\n", "output": "5\n" }, { "input": "20 583988303060450752\n-64 273760634\n-238 960719353\n-114 191410838\n-250 357733867\n232 304621362\n-286 644706927\n210 37849132\n-230 556412112\n-142 136397527\n101 380675202\n-140 152300688\n190 442931589\n-187 940659077\n-12 31...
https://atcoder.jp/contests/arc164/tasks/arc164_a
Problem Statement You are given integers N and K . Is it possible to express N as the sum of exactly K numbers of the form 3^m ( m is a non-negative integer)? In other words, is there a sequence of non-negative integers (m_1, m_2,\ldots, m_K) such that: N= 3^{m_1}+3^{m_2}+...+3^{m_K} ? You are given T test cases. Ans...
[ { "input": "4\n5 3\n17 2\n163 79\n1000000000000000000 1000000000000000000\n", "output": "Yes\nNo\nYes\nYes\n" } ]
https://atcoder.jp/contests/arc164/tasks/arc164_b
Problem Statement There is a simple connected undirected graph with N vertices numbered from 1 to N . This graph has M edges, and the i -th edge connects two vertices a_i and b_i . Each vertex has a color, either white or black, and the initial state is given by c_i . c_i is either 0 or 1 , where c_i=0 means that vert...
[ { "input": "4 4\n1 2\n2 3\n3 4\n4 2\n0 1 0 1\n", "output": "Yes\n" }, { "input": "5 6\n1 2\n2 3\n3 4\n4 5\n1 4\n2 5\n0 1 0 1 0\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc164/tasks/arc164_c
Problem Statement There are N cards, each with a number written on both sides. On the i -th card, the number A_i is written in red on one side, and the number B_i is written in blue on the other side. Initially, all cards are placed with the red number side facing up. Alice and Bob play a game in which they repeat the ...
[ { "input": "3\n6 4\n2 1\n5 3\n", "output": "12\n" }, { "input": "5\n166971716 552987438\n219878198 619875818\n918378176 518975015\n610749017 285601372\n701849287 307601390\n", "output": "3078692091\n" } ]
https://atcoder.jp/contests/arc164/tasks/arc164_d
Problem Statement Consider the following problem for a string s of length 2N formed by N + and N - , and let p(s) denote the answer. There are 2N balls lined up at positions x=1,2,3,\ldots , 2N on a number line, of which N have a charge of +1 and the remaining N have a charge of -1 . The arrangement of the charges of t...
[ { "input": "2\n+??-\n", "output": "6\n" }, { "input": "17\n??????????????????????????????????\n", "output": "285212526\n" } ]
https://atcoder.jp/contests/arc164/tasks/arc164_e
Problem Statement There is a sequence of N terms, and Q queries will be given on this sequence. The i -th query is for the interval [L_i, R_i] (the interval [a,b] is a set of integers between a and b , inclusive). You will answer this problem using a binary tree that satisfies the following conditions. Here, i,j,k repr...
[ { "input": "6 4\n2 3\n3 4\n2 4\n3 3\n", "output": "3 4\n" }, { "input": "12 6\n1 10\n2 7\n3 6\n4 9\n5 8\n11 12\n", "output": "4 4\n" } ]
https://atcoder.jp/contests/arc164/tasks/arc164_f
Problem Statement You are given a rooted tree with N vertices numbered from 1 to N , rooted at vertex 1 . The parent of vertex i is vertex p_i ( 2\leq i\leq N ). Alice and Bob play a game using this tree as follows. Alice goes first, and Bob goes second. They take turns placing a stone, with a white side and a black si...
[ { "input": "4\n1 1 2\n", "output": "2\n" }, { "input": "7\n1 1 2 4 4 4\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_a
Problem Statement We have the following 3 \times 3 board with integers from 1 through 9 written on it. You are given two integers A and B between 1 and 9 , where A < B . Determine if the two squares with A and B written on them are adjacent horizontally.
[ { "input": "7 8\n", "output": "Yes\n" }, { "input": "1 9\n", "output": "No\n" }, { "input": "3 4\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_b
Problem Statement You are given a grid with N rows and N columns. An integer A_{i, j} is written on the square at the i -th row from the top and j -th column from the left. Here, it is guaranteed that A_{i,j} is either 0 or 1 . Shift the integers written on the outer squares clockwise by one square each, and print th...
[ { "input": "4\n0101\n1101\n1111\n0000\n", "output": "1010\n1101\n0111\n0001\n" }, { "input": "2\n11\n11\n", "output": "11\n11\n" }, { "input": "5\n01010\n01001\n10110\n00110\n01010\n", "output": "00101\n11000\n00111\n00110\n10100\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_c
Problem Statement Snuke the doctor prescribed N kinds of medicine for Takahashi. For the next a_i days (including the day of the prescription), he has to take b_i pills of the i -th medicine. He does not have to take any other medicine. Let the day of the prescription be day 1 . On or after day 1 , when is the first...
[ { "input": "4 8\n6 3\n2 5\n1 9\n4 2\n", "output": "3\n" }, { "input": "4 100\n6 3\n2 5\n1 9\n4 2\n", "output": "1\n" }, { "input": "15 158260522\n877914575 2436426\n24979445 61648772\n623690081 33933447\n476190629 62703497\n211047202 71407775\n628894325 31963982\n822804784 50968417\n4303...
https://atcoder.jp/contests/abc309/tasks/abc309_d
Problem Statement We have an undirected graph with (N_1+N_2) vertices and M edges. For i=1,2,\ldots,M , the i -th edge connects vertex a_i and vertex b_i . The following properties are guaranteed: Vertex u and vertex v are connected, for all integers u and v with 1 \leq u,v \leq N_1 . Vertex u and vertex v are connect...
[ { "input": "3 4 6\n1 2\n2 3\n4 5\n4 6\n1 3\n6 7\n", "output": "5\n" }, { "input": "7 5 20\n10 11\n4 5\n10 12\n1 2\n1 5\n5 6\n2 4\n3 5\n9 10\n2 5\n1 4\n11 12\n9 12\n8 9\n5 7\n3 7\n3 6\n3 4\n8 12\n9 11\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_e
Problem Statement There is a family consisting of person 1 , person 2 , \ldots , and person N . For i\geq 2 , person i 's parent is person p_i . They bought insurance M times. For i=1,2,\ldots,M , person x_i bought the i -th insurance, which covers that person and their descendants in the next y_i generations. How ma...
[ { "input": "7 3\n1 2 1 3 3 3\n1 1\n1 2\n4 3\n", "output": "4\n" }, { "input": "10 10\n1 1 3 1 2 3 3 5 7\n2 1\n5 1\n4 3\n6 3\n2 1\n7 3\n9 2\n1 2\n6 2\n8 1\n", "output": "10\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_f
Problem Statement There are N boxes. The i -th box has a shape of a rectangular cuboid whose height, width, and depth are h_i,w_i , and d_i , respectively. Determine if there are two boxes such that one's height, width, and depth are strictly greater than those of the other after rotating them if necessary.
[ { "input": "3\n19 8 22\n10 24 12\n15 25 11\n", "output": "Yes\n" }, { "input": "3\n19 8 22\n10 25 12\n15 24 11\n", "output": "No\n" }, { "input": "2\n1 1 2\n1 2 2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_g
Problem Statement Find the number, modulo 998244353 , of permutations P=(P_1,P_2,\dots,P_N) of (1,2,\dots,N) such that: |P_i - i| \ge X for all integers i with 1 \le i \le N .
[ { "input": "3 1\n", "output": "2\n" }, { "input": "5 2\n", "output": "4\n" }, { "input": "98 5\n", "output": "809422418\n" } ]
https://atcoder.jp/contests/abc309/tasks/abc309_h
Problem Statement We have a grid with N rows and M columns. We denote by (i,j) the cell in the i -th row from the top and j -th column from the left. You are given integer sequences A=(A_1,A_2,\dots,A_K) and B=(B_1,B_2,\dots,B_L) of lengths K and L , respectively. Find the sum, modulo 998244353 , of the answers to the...
[ { "input": "3 4 1 2\n1\n1 2\n", "output": "4\n" }, { "input": "5 8 4 5\n3 1 4 1\n2 7 1 8 2\n", "output": "137\n" }, { "input": "883671387 87719 10 12\n86879 64174 47274 41688 17713 50897 53989 7210 30894 5714\n60358 28835 48036 48450 67149 36558 35929 69025 77539 19195 60762 60721\n", ...
https://atcoder.jp/contests/arc163/tasks/arc163_a
Problem Statement You are given a string S of length N consisting of lowercase English letters. Determine whether it is possible to divide S into two or more consecutive substrings so that they are strictly increasing in lexicographical order. To be precise, determine whether there is a sequence of strings t=(t_1,t_2,\...
[ { "input": "5\n4\nabac\n3\ncac\n2\nab\n12\nabababababab\n5\nedcba\n", "output": "Yes\nNo\nYes\nYes\nNo\n" } ]
https://atcoder.jp/contests/arc163/tasks/arc163_b
Problem Statement You are given an integer sequence of length N : A=(A_1,A_2,\dots,A_N) . You can perform the following operation any number of times (possibly zero). Choose an integer i such that 1 \le i \le N , and increase or decrease A_i by 1 . Your goal is to make at least M integers i(3 \le i \le N) satisfy A_1 \...
[ { "input": "3 1\n2 3 5\n", "output": "2\n" }, { "input": "5 2\n1 4 2 3 5\n", "output": "0\n" }, { "input": "8 5\n15 59 64 96 31 17 88 9\n", "output": "35\n" } ]
https://atcoder.jp/contests/arc163/tasks/arc163_c
Problem Statement Determine whether there is a length- N sequence of positive integers A=(A_1,A_2,\dots,A_N) that satisfies all of the following conditions, and if it exists, construct one. \sum_{i=1}^{N} \frac{1}{A_i} = 1 All elements of A are distinct. 1 \le A_i \le 10^9(1 \le i \le N) You are given T test cases. Fin...
[ { "input": "2\n3\n5\n", "output": "Yes\n2 3 6 \nYes\n3 4 5 6 20 \n" } ]
https://atcoder.jp/contests/arc163/tasks/arc163_d
Problem Statement Consider a directed graph G with N vertices numbered 1 to N that satisfies all of the following conditions. G is a tournament. In other words, G has no multi-edges or self-loops, and for any two vertices u,v of G , exactly one of the edges u \rightarrow v and v \rightarrow u exists. Among the edges of...
[ { "input": "3 1\n", "output": "7\n" }, { "input": "6 2\n", "output": "300\n" }, { "input": "25 156\n", "output": "902739687\n" } ]
https://atcoder.jp/contests/arc163/tasks/arc163_e
Problem Statement Alice and Bob are playing a game using a length- N sequence of non-negative integers A=(A_1,A_2,\dots,A_N) . Starting with Alice, they take turns performing the following operation. The player who cannot make a move first loses. Choose a non-negative integer X such that there is an integer i satisfyin...
[ { "input": "5\n2\n3 1\n5\n1 1 1 1 1\n4\n0 0 0 0\n4\n8 1 6 4\n5\n3 8 7 12 15\n", "output": "Bob\nAlice\nBob\nBob\nAlice\n" } ]
https://atcoder.jp/contests/arc163/tasks/arc163_f
Problem Statement PCT-kun created the following problem. Increasing Problem You are given a length- N sequence of non-negative integers A_1,A_2,\dots,A_N . You can perform the following operation any number of times (possibly zero). Choose an integer i such that 1 \le i \le N , and increase or decrease A_i by 1 . Your ...
[ { "input": "2 2\n", "output": "1\n" }, { "input": "6 4\n", "output": "14668\n" }, { "input": "163 702\n", "output": "20728656\n" }, { "input": "98765 99887\n", "output": "103564942\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_a
Problem Statement Given eight integers S_1,S_2,\dots , and S_8 , print Yes if they satisfy all of the following three conditions, and No otherwise. The sequence (S_1,S_2,\dots,S_8) is monotonically non-decreasing. In other words, S_1 \leq S_2 \leq \dots \leq S_8 . S_1,S_2,\dots , and S_8 are all between 100 and 675 ,...
[ { "input": "125 175 250 300 400 525 600 650\n", "output": "Yes\n" }, { "input": "100 250 300 400 325 575 625 675\n", "output": "No\n" }, { "input": "0 23 24 145 301 413 631 632\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_b
Problem Statement Takahashi ate N plates of sushi at a sushi restaurant. The color of the i -th plate is represented by a string C_i . The price of a sushi corresponds to the color of the plate. For each i=1,\ldots,M , the sushi on a plate whose color is represented by a string D_i is worth P_i yen a plate (yen is th...
[ { "input": "3 2\nred green blue\nblue red\n800 1600 2800\n", "output": "5200\n" }, { "input": "3 2\ncode queen atcoder\nking queen\n10 1 1\n", "output": "21\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_c
Problem Statement N people numbered 1 through N tossed a coin several times. We know that person i 's tosses resulted in A_i heads and B_i tails. Person i 's success rate of the tosses is defined by \displaystyle\frac{A_i}{A_i+B_i} . Sort people 1,\ldots,N in descending order of their success rates, with ties broken ...
[ { "input": "3\n1 3\n3 1\n2 2\n", "output": "2 3 1\n" }, { "input": "2\n1 3\n2 6\n", "output": "1 2\n" }, { "input": "4\n999999999 1000000000\n333333333 999999999\n1000000000 999999997\n999999998 1000000000\n", "output": "3 1 4 2\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_d
Problem Statement We have a grid with H horizontal rows and W vertical columns. We denote by (i,j) the cell at the i -th row from the top and j -th column from the left. Each cell in the grid has a lowercase English letter written on it. The letter written on (i,j) equals the j -th character of a given string S_i . ...
[ { "input": "2 3\nsns\neuk\n", "output": "Yes\n" }, { "input": "2 2\nab\ncd\n", "output": "No\n" }, { "input": "5 7\nskunsek\nnukesnu\nukeseku\nnsnnesn\nuekukku\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_e
Problem Statement You are given a length- N sequence A=(A_1,A_2,\dots,A_N) consisting of 0 , 1 , and 2 , and a length- N string S=S_1S_2\dots S_N consisting of M , E , and X . Find the sum of \text{mex}(A_i,A_j,A_k) over all tuples of integers (i,j,k) such that 1 \leq i < j < k \leq N and S_iS_jS_k= MEX . Here, \text...
[ { "input": "4\n1 1 0 2\nMEEX\n", "output": "3\n" }, { "input": "3\n0 0 0\nXXX\n", "output": "0\n" }, { "input": "15\n1 1 2 0 0 2 0 2 0 0 0 0 0 2 2\nEXMMXXXEMEXEXMM\n", "output": "13\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_f
Problem Statement You are in a store to buy N items. The regular price of the i -th item is P_i yen (the currency in Japan). You have M coupons. You can use the i -th coupon to buy an item whose regular price is at least L_i yen at a D_i -yen discount. Here, each coupon can be used only once. Besides, multiple coupo...
[ { "input": "3 3\n4 3 1\n4 4 2\n2 3 1\n", "output": "4\n" }, { "input": "10 5\n9 7 1 5 2 2 5 5 7 6\n7 2 7 8 2\n3 2 4 1 2\n", "output": "37\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_g
Problem Statement There is a blackboard on which you can write integers. Initially, no integer is written on the blackboard. Given Q queries, process them in order. The query is of one of the following three kinds: 1 x : write an x on the blackboard. 2 x : erase an x from the blackboard. At the point this query is g...
[ { "input": "9\n1 2\n1 10\n3\n1 3\n3\n2 2\n3\n1 10\n3\n", "output": "8\n1\n9\n0\n" } ]
https://atcoder.jp/contests/abc308/tasks/abc308_h
Problem Statement There is a simple undirected graph with N vertices and M edges. The edges are initially painted white. The vertices are numbered 1 through N , and the edges are numbered 1 through M . Edge i connects vertex A_i and vertex B_i , and the cost required to paint it black is C_i . "Making a Q" means pai...
[ { "input": "5 6\n1 2 6\n2 3 4\n1 3 5\n2 4 3\n4 5 2\n3 5 1\n", "output": "15\n" }, { "input": "4 4\n1 2 1\n2 3 1\n3 4 1\n1 4 1\n", "output": "-1\n" }, { "input": "6 15\n2 6 48772\n2 4 36426\n1 6 94325\n3 6 3497\n2 3 60522\n4 5 63982\n4 6 4784\n1 2 14575\n5 6 68417\n1 5 7775\n3 4 33447\n3 ...
https://atcoder.jp/contests/ahc021/tasks/ahc021_a
Problem Statement There are N(N+1)/2 balls arranged in an N -tiered pyramid as shown in the figure below. Let (0, 0) be the coordinates of the ball at the top of the pyramid, and let (x,y) be the coordinates of the y (0\leq y\leq x) -th ball from the left in the x (0\leq x-1) -th tier from the top. Each ball is labele...
[ { "input": "236\n11 200\n453 2 378\n85 410 239 54\n50 240 113 25 294\n303 231 146 65 155 252\n368 327 321 251 451 182 142\n101 17 43 403 217 161 347 398\n350 287 363 48 80 447 385 233 197\n438 424 439 121 357 380 51 245 57 304\n141 91 100 344 194 250 432 322 58 281 219\n412 266 26 318 269 111 59 450 99 301 36 3...
https://atcoder.jp/contests/abc307/tasks/abc307_a
Problem Statement Takahashi has recorded the number of steps he walked for N weeks. He walked A_i steps on the i -th day. Find the total number of steps Takahashi walked each week. More precisely, find the sum of the steps for the first week (the 1 -st through 7 -th day), the sum of the steps for the second week (the 8...
[ { "input": "2\n1000 2000 3000 4000 5000 6000 7000 2000 3000 4000 5000 6000 7000 8000\n", "output": "28000 35000\n" }, { "input": "3\n14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 6286 20899 86280 34825 34211 70679 82148\n", "output": "314333 419427 335328\n"...
https://atcoder.jp/contests/abc307/tasks/abc307_b
Problem Statement You are given N strings S_1,S_2,\ldots,S_N consisting of lowercase English letters. Determine if there are distinct integers i and j between 1 and N , inclusive, such that the concatenation of S_i and S_j in this order is a palindrome. A string T of length M is a palindrome if and only if the i -th ch...
[ { "input": "5\nab\nccef\nda\na\nfe\n", "output": "Yes\n" }, { "input": "3\na\nb\naba\n", "output": "No\n" }, { "input": "2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc307/tasks/abc307_c
Problem Statement Takahashi has two sheets A and B , each composed of black squares and transparent squares, and an infinitely large sheet C composed of transparent squares. There is also an ideal sheet X for Takahashi composed of black squares and transparent squares. The sizes of sheets A , B , and X are H_A rows \ti...
[ { "input": "3 5\n#.#..\n.....\n.#...\n2 2\n#.\n.#\n5 3\n...\n#.#\n.#.\n.#.\n...\n", "output": "Yes\n" }, { "input": "2 2\n#.\n.#\n2 2\n#.\n.#\n2 2\n##\n##\n", "output": "No\n" }, { "input": "1 1\n#\n1 2\n##\n1 1\n#\n", "output": "No\n" }, { "input": "3 3\n###\n...\n...\n3 3\n...
https://atcoder.jp/contests/abc307/tasks/abc307_d
Problem Statement You are given a string S of length N consisting of lowercase English letters and the characters ( and ) . Print the string S after performing the following operation as many times as possible. Choose and delete a contiguous substring of S that starts with ( , ends with ) , and does not contain ( or ) ...
[ { "input": "8\na(b(d))c\n", "output": "ac\n" }, { "input": "5\na(b)(\n", "output": "a(\n" }, { "input": "2\n()\n", "output": "\n" }, { "input": "6\n)))(((\n", "output": ")))(((\n" } ]
https://atcoder.jp/contests/abc307/tasks/abc307_e
Problem Statement There are N people numbered from 1 to N standing in a circle. Person 1 is to the right of person 2 , person 2 is to the right of person 3 , ..., and person N is to the right of person 1 . We will give each of the N people an integer between 0 and M-1 , inclusive. Among the M^N ways to distribute integ...
[ { "input": "3 3\n", "output": "6\n" }, { "input": "4 2\n", "output": "2\n" }, { "input": "987654 456789\n", "output": "778634319\n" } ]
https://atcoder.jp/contests/abc307/tasks/abc307_f
Problem Statement There are N rooms numbered 1 , 2 , \ldots , N , each with one person living in it, and M corridors connecting two different rooms. The i -th corridor connects room U_i and room V_i with a length of W_i . One day (we call this day 0 ), the K people living in rooms A_1, A_2, \ldots, A_K got (newly) infe...
[ { "input": "4 4\n1 2 2\n2 3 1\n2 4 3\n3 4 2\n1\n1\n2\n3 3\n", "output": "0\n1\n1\n2\n" }, { "input": "7 7\n1 2 2\n2 3 3\n3 4 1\n4 5 1\n5 6 3\n3 7 1\n4 7 1\n2\n1 6\n2\n2 3\n", "output": "0\n1\n2\n-1\n2\n0\n-1\n" }, { "input": "5 1\n1 2 5\n2\n1 3\n3\n3 7 5\n", "output": "0\n2\n0\n-1\n-...
https://atcoder.jp/contests/abc307/tasks/abc307_g
Problem Statement You are given an integer sequence of length N : A=(A_1,A_2,\ldots,A_N) . Takahashi can perform the following two operations any number of times, possibly zero, in any order. Choose an integer i such that 1\leq i\leq N-1 , and decrease A_i by 1 and increase A_{i+1} by 1 . Choose an integer i such that ...
[ { "input": "3\n2 7 6\n", "output": "4\n" }, { "input": "3\n-2 -5 -2\n", "output": "2\n" }, { "input": "5\n1 1 1 1 -7\n", "output": "13\n" } ]
https://atcoder.jp/contests/abc307/tasks/abc307_h
Problem Statement There is a length L string S consisting of uppercase and lowercase English letters displayed on an electronic bulletin board with a width of W . The string S scrolls from right to left by a width of one character at a time. The display repeats a cycle of L+W-1 states, with the first character of S app...
[ { "input": "3 5\nABC\n..___\n", "output": "3\n" }, { "input": "11 15\nabracadabra\n__.._________ab\n", "output": "2\n" }, { "input": "20 30\nabaababbbabaabababba\n__a____b_____a________________\n", "output": "2\n" }, { "input": "1 1\na\n_\n", "output": "1\n" } ]
https://atcoder.jp/contests/atcoder11live/tasks/atcoder11live_a
問題文 n \times n マスの盤面がある。 一番左上のマスの座標を (0, 0) とし、そこから下方向に i マス、右方向に j マス進んだ先のマスの座標を (i, j) とする。 初期状態で (si, sj) の位置に右向きの状態で車のおもちゃが置かれている。 いくつかのマスには初期状態で障害物が設置されており、これらの障害物は取り除いたり他のマスに移動させたりすることは出来ない。 また、 n\times n の範囲外のマスは全て障害物が置かれているものとして扱う。 残りの空きマスに好きなように障害物を設置せよ。 ただし、車のおもちゃの初期位置には障害物は設置されていないことが保証されており、新たに障害物を設置する...
[ { "input": "20\n10 8\n....................\n........#...........\n....................\n....................\n....................\n.....#.............#\n....................\n...................#\n....................\n....................\n....................\n....................\n....................\n.......
https://atcoder.jp/contests/arc162/tasks/arc162_a
Problem Statement There are N people, numbered from 1 to N , who participated in a round-trip race between two points. The following information is recorded about this race. The outward times of any two people were different, and person i (1 \leq i \leq N) had the i -th fastest outward time. The round-trip times (the s...
[ { "input": "3\n2\n2 1\n4\n1 2 3 4\n20\n13 2 7 1 5 9 3 4 12 10 15 6 8 14 20 16 19 18 11 17\n", "output": "1\n4\n7\n" } ]
https://atcoder.jp/contests/arc162/tasks/arc162_b
Problem Statement A permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) is given. Determine whether it is possible to rearrange P in ascending order by performing the following operation at most 2\times 10^3 times, and if possible, show one such sequence of operations. Choose integers i and j such that 1\leq i \leq N-...
[ { "input": "5\n1 4 2 3 5\n", "output": "Yes\n1\n3 1\n" }, { "input": "2\n2 1\n", "output": "No\n" }, { "input": "4\n3 4 1 2\n", "output": "Yes\n3\n3 0\n1 2\n3 0\n" } ]
https://atcoder.jp/contests/arc162/tasks/arc162_c
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 P_i . Some vertices of the rooted tree have non-negative integers from 0 to N written on them. This information is given by the sequence A=(A_1,A_2,\ldots,A_N) . If A_i \...
[ { "input": "2\n4 2\n1 1 2\n-1 -1 3 1\n6 4\n1 2 2 1 3\n-1 -1 -1 -1 -1 -1\n", "output": "Alice\nBob\n" } ]
https://atcoder.jp/contests/arc162/tasks/arc162_d
Problem Statement In this problem, a rooted directed tree is a rooted tree where all edges are directed from the root to the leaves. You are given a sequence of non-negative integers d=(d_1,d_2,\ldots,d_N) with a sum of N-1 . Among the N -vertex rooted directed trees with vertex numbered 1 to N and vertex 1 as the root...
[ { "input": "4\n2 0 1 0\n", "output": "7\n" }, { "input": "10\n3 1 0 0 2 0 1 2 0 0\n", "output": "37542\n" } ]
https://atcoder.jp/contests/arc162/tasks/arc162_e
Problem Statement You are given a sequence of length N consisting of integers from 1 to N , A=(A_1,A_2,\ldots,A_N) . Find the number, modulo 998244353 , of sequences of length N consisting of integers from 1 to N , B=(B_1,B_2,\ldots,B_N) , that satisfy the following conditions for all i=1,2,\ldots,N . The number of occ...
[ { "input": "3\n1 2 3\n", "output": "10\n" }, { "input": "4\n4 4 4 4\n", "output": "256\n" }, { "input": "5\n1 1 1 1 1\n", "output": "120\n" }, { "input": "14\n6 5 14 3 6 7 3 11 11 2 3 7 8 10\n", "output": "628377683\n" } ]
https://atcoder.jp/contests/arc162/tasks/arc162_f
Problem Statement You are given positive integers N and M . Among the 2^{NM} matrices A with N rows and M columns where each element is 0 or 1 , find the number, modulo 998244353 , of ones that satisfy the following condition: A_{a, b} \times A_{c, d} \leq A_{a, d} \times A_{c, b} for every quadruple of integers (a, b,...
[ { "input": "2 2\n", "output": "13\n" }, { "input": "1 30\n", "output": "75497471\n" }, { "input": "400 400\n", "output": "412670892\n" } ]
https://atcoder.jp/contests/abc306/tasks/abc306_a
Problem Statement You are given a string S of length N consisting of lowercase English letters. We denote the i -th character of S by S_i . Print the string of length 2N obtained by concatenating S_1,S_1,S_2,S_2,\dots,S_N , and S_N in this order. For example, if S is beginner , print bbeeggiinnnneerr .
[ { "input": "8\nbeginner\n", "output": "bbeeggiinnnneerr\n" }, { "input": "3\naaa\n", "output": "aaaaaa\n" } ]
https://atcoder.jp/contests/abc306/tasks/abc306_b
Problem Statement You are given a sequence A=(A_0,A_1,\dots,A_{63}) of length 64 consisting of 0 and 1 . Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} .
[ { "input": "1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "13\n" }, { "input": "1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 ...
https://atcoder.jp/contests/abc306/tasks/abc306_c
Problem Statement You are given a sequence A=(A_1,A_2,\dots,A_{3N}) of length 3N where each of 1,2,\dots , and N occurs exactly three times. For i=1,2,\dots,N , let f(i) be the index of the middle occurrence of i in A . Sort 1,2,\dots,N in ascending order of f(i) . Formally, f(i) is defined as follows. Suppose that tho...
[ { "input": "3\n1 1 3 2 3 2 2 3 1\n", "output": "1 3 2\n" }, { "input": "1\n1 1 1\n", "output": "1\n" }, { "input": "4\n2 3 4 3 4 1 3 1 1 4 2 2\n", "output": "3 4 1 2\n" } ]
https://atcoder.jp/contests/abc306/tasks/abc306_d
Problem Statement Takahashi has decided to enjoy a wired full-course meal consisting of N courses in a restaurant. The i -th course is: if X_i=0 , an antidotal course with a tastiness of Y_i ; if X_i=1 , a poisonous course with a tastiness of Y_i . When Takahashi eats a course, his state changes as follows: Initially, ...
[ { "input": "5\n1 100\n1 300\n0 -200\n1 500\n1 300\n", "output": "600\n" }, { "input": "4\n0 -1\n1 -2\n0 -3\n1 -4\n", "output": "0\n" }, { "input": "15\n1 900000000\n0 600000000\n1 -300000000\n0 -700000000\n1 200000000\n1 300000000\n0 -600000000\n1 -900000000\n1 600000000\n1 -100000000\n1...
https://atcoder.jp/contests/abc306/tasks/abc306_e
Problem Statement We have a sequence A=(A_1,A_2,\dots,A_N) of length N . Initially, all the terms are 0 . Using an integer K given in the input, we define a function f(A) as follows: Let B be the sequence obtained by sorting A in descending order (so that it becomes monotonically non-increasing). Then, let f(A)=B_1 + ...
[ { "input": "4 2 10\n1 5\n2 1\n3 3\n4 2\n2 10\n1 0\n4 0\n3 1\n2 0\n3 0\n", "output": "5\n6\n8\n8\n15\n13\n13\n11\n1\n0\n" } ]
https://atcoder.jp/contests/abc306/tasks/abc306_f
Problem Statement For two sets of integers, A and B , such that A \cap B = \emptyset , we define f(A,B) as follows. Let C=(C_1,C_2,\dots,C_{|A|+|B|}) be a sequence consisting of the elements of A \cup B , sorted in ascending order. Take k_1,k_2,\dots,k_{|A|} such that A=\lbrace C_{k_1},C_{k_2},\dots,C_{k_{|A|}}\rbrace ...
[ { "input": "3 2\n1 3\n2 8\n4 6\n", "output": "12\n" }, { "input": "1 1\n306\n", "output": "0\n" }, { "input": "4 4\n155374934 164163676 576823355 954291757\n797829355 404011431 353195922 138996221\n191890310 782177068 818008580 384836991\n160449218 545531545 840594328 501899080\n", "...
https://atcoder.jp/contests/abc306/tasks/abc306_g
Problem Statement We have a directed graph with N vertices and M edges. The vertices are numbered from 1 through N , and the i -th edge goes from vertex U_i to vertex V_i . You are currently at vertex 1 . Determine if you can make the following move 10^{10^{100}} times to end up at vertex 1 : choose an edge going from ...
[ { "input": "4\n2 2\n1 2\n2 1\n3 3\n1 2\n2 3\n3 1\n7 10\n1 6\n6 3\n1 4\n5 1\n7 1\n4 5\n2 1\n4 7\n2 7\n4 3\n7 11\n1 6\n6 3\n1 4\n5 1\n7 1\n4 5\n2 1\n4 7\n2 7\n4 3\n3 7\n", "output": "Yes\nNo\nNo\nYes\n" } ]
https://atcoder.jp/contests/abc306/tasks/abc306_h
Problem Statement There are N weights numbered 1,2, \dots,N . Using a balance, we will compare weights M times. Before the comparisons, prepare an empty string S . For the i -th comparison, put just weight A_i to the left bowl, and just weight B_i to the right. Then, one of the following three results is obtained. If w...
[ { "input": "3 3\n1 2\n1 3\n2 3\n", "output": "13\n" }, { "input": "4 4\n1 4\n2 3\n1 3\n3 4\n", "output": "39\n" }, { "input": "14 15\n1 2\n1 3\n2 4\n2 5\n2 6\n4 8\n5 6\n6 8\n7 8\n9 10\n9 12\n9 13\n10 11\n11 12\n11 13\n", "output": "1613763\n" } ]
https://atcoder.jp/contests/ahc020/tasks/ahc020_a
Problem Statement You are given a weighted planar undirected graph G with N vertices and M edges. The coordinates of vertex i are (x_i, y_i) . The j -th edge connects vertices u_j and v_j with the weight w_j . Let D_j=\mathrm{round}\left(\sqrt{(x_{u_j}-x_{v_j})^2+(y_{u_j}-y_{v_j})^2}\right) be the rounded Euclidean ...
[ { "input": "100 284 5000\n0 0\n957 -6517\n-412 -5500\n-299 4489\n-8357 6534\n1974 -6619\n1410 -8691\n8833 -9829\n7785 2682\n-9839 443\n-5084 6063\n8064 4821\n7008 1946\n2894 -5980\n-3445 9927\n-1403 3591\n5030 5758\n3178 1199\n-9263 -3926\n-3126 -2879\n4179 4360\n5715 595\n7209 -8569\n823 1184\n-746 749\n-3409 ...