url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/past202203-open/tasks/past202203_o
Problem Statement You are given M pairs (A_i,B_i) of distinct integers between 1 and N (inclusive). Determine whether there is a permutation P=(P_1, P_2,\ldots , P_N) of the integers 1 to N such that P_{A_i}+P_{B_i} is a multiple of 3 for all 1\leq i\leq M .
[ { "input": "5 2\n1 2\n2 3\n", "output": "Yes\n" }, { "input": "3 2\n1 2\n2 3\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_a
Problem Statement You are given a string S of length N consisting of A , B , C . You can do the following two kinds of operations on S any number of times in any order. Choose A in S , delete it, and insert BB at that position. Choose two adjacent characters that are BB in S , delete them, and insert A at that position...
[ { "input": "4\nCBAA\n", "output": "CAAB\n" }, { "input": "1\nA\n", "output": "A\n" }, { "input": "6\nBBBCBB\n", "output": "ABCA\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_b
Problem Statement You are given integer sequences of length N each: A=(A_1,A_2,\cdots,A_N) and B=(B_1,B_2,\cdots,B_N) . You can repeat the following operation any number of times. Choose an integer i ( 1 \leq i \leq N-2 ) and let x,y,z be the current values of A_i,A_{i+1},A_{i+2} , respectively. Then, replace the valu...
[ { "input": "4\n3 1 4 5\n4 1 5 3\n", "output": "Yes\n" }, { "input": "3\n1 2 2\n2 1 2\n", "output": "Yes\n" }, { "input": "3\n1 2 3\n2 3 4\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_c
Problem Statement We have an integer sequence of length N : x=(x_0,x_1,\cdots,x_{N-1}) (note that its index is 0 -based). Initially, all elements of x are 0 . You can repeat the following operation any number of times. Choose integers i,k ( 0 \leq i \leq N-1 , 1 \leq k \leq N ). Then, for every j such that i \leq j \...
[ { "input": "4\n1 2 1 2\n", "output": "2\n" }, { "input": "5\n3 1 4 1 5\n", "output": "7\n" }, { "input": "1\n1000000000\n", "output": "1000000000\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_d
Problem Statement You are given an integer sequence of length N : A=(A_1,A_2,\cdots,A_N) . Find the number of pairs of integers (i,j) ( 1 \leq i < j \leq N ) such that calculation of A_i+A_j by column addition does not involve carrying.
[ { "input": "4\n4 8 12 90\n", "output": "3\n" }, { "input": "20\n313923 246114 271842 371982 284858 10674 532090 593483 185123 364245 665161 241644 604914 645577 410849 387586 732231 952593 249651 36908\n", "output": "6\n" }, { "input": "5\n1 1 1 1 1\n", "output": "10\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_e
Problem Statement We have a directed graph G with N vertices numbered 1 to N . Between two vertices i,j ( 1 \leq i,j \leq N , i \neq j ), there is an edge i \to j if and only if both of the following conditions are satisfied. i<j \mathrm{gcd}(i,j)>1 Additionally, each vertex has an associated value: the value of Vertex...
[ { "input": "6\n1 1 1 1 1 1\n", "output": "4\n" }, { "input": "6\n1 2 1 3 1 6\n", "output": "8\n" }, { "input": "20\n40 39 31 54 27 31 80 3 62 66 15 72 21 38 74 49 15 24 44 3\n", "output": "343\n" } ]
https://atcoder.jp/contests/arc136/tasks/arc136_f
Problem Statement We have a checkerboard with H rows and W columns, where each square has a 0 or 1 written on it. The current state of checkerboard is represented by H strings S_1,S_2,\cdots,S_H : the j -th character of S_i represents the digit in the square at the i -th row from the top and j -th column from the left...
[ { "input": "1 2\n01\n0\n", "output": "3\n" }, { "input": "3 3\n000\n100\n110\n0 1 2\n", "output": "0\n" }, { "input": "2 2\n00\n01\n1 0\n", "output": "332748127\n" }, { "input": "5 4\n1101\n0000\n0010\n0100\n1111\n1 3 3 2 1\n", "output": "647836743\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_a
Problem Statement There is a device with a screen that shows a single-digit number, and a button. When the screen is showing a number k , pressing the button once changes the number on the screen to a_k . The device currently shows 0 . After pressing the button 3 times, what will be shown on the screen?
[ { "input": "9 0 1 2 3 4 5 6 7 8\n", "output": "7\n" }, { "input": "4 8 8 8 0 8 8 8 8 8\n", "output": "4\n" }, { "input": "0 0 0 0 0 0 0 0 0 0\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_b
Problem Statement There is pasta consisting of N noodles at Takahashi's home. The length of the i -th noodle is A_i . Takahashi has a meal plan for the next M days. On the i -th day, he is going to choose a pasta noodle of length exactly B_i and eat it. If no such noodle is available on any day, his plan fails. Additi...
[ { "input": "3 2\n1 1 3\n3 1\n", "output": "Yes\n" }, { "input": "1 1\n1000000000\n1\n", "output": "No\n" }, { "input": "5 2\n1 2 3 4 5\n5 5\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_c
Problem Statement There is a grid with N horizontal rows and N vertical columns, where each square is painted white or black. The state of the grid is represented by N strings, S_i . If the j -th character of S_i is # , the square at the i -th row from the top and the j -th column from the left is painted black. If the...
[ { "input": "8\n........\n........\n.#.##.#.\n........\n........\n........\n........\n........\n", "output": "Yes\n" }, { "input": "6\n######\n######\n######\n######\n######\n######\n", "output": "Yes\n" }, { "input": "10\n..........\n#..##.....\n..........\n..........\n....#.....\n....#....
https://atcoder.jp/contests/abc241/tasks/abc241_d
Problem Statement We have an empty sequence A . Given Q queries, process them in order. Each query is of one of the following three types. 1 x : Insert x to A . 2 x k : Among the elements of A that are less than or equal to x , print the k -th largest value. ( k is no more than \bf{5} ) If there are less than k elemen...
[ { "input": "11\n1 20\n1 10\n1 30\n1 20\n3 15 1\n3 15 2\n3 15 3\n3 15 4\n2 100 5\n1 1\n2 100 5\n", "output": "20\n20\n30\n-1\n-1\n1\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_e
Problem Statement You are given a sequence A=(A_0,A_1,\ldots,A_{N-1}) of length N . There is an initially empty dish. Takahashi is going to repeat the following operation K times. Let X be the number of candies on the dish. He puts A_{(X\bmod N)} more candies on the dish. Here, X\bmod N denotes the remainder when X ...
[ { "input": "5 3\n2 1 6 3 1\n", "output": "11\n" }, { "input": "10 1000000000000\n260522 914575 436426 979445 648772 690081 933447 190629 703497 47202\n", "output": "826617499998784056\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_f
Problem Statement There is a skating rink represented by a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i -th row from the top and j -th column from the left. The skating rink has N obstacles. The i -th obstacle is placed at (X_i,Y_i) . In a single move, Takahashi chooses on...
[ { "input": "7 8 7\n3 4\n5 6\n1 4\n2 1\n2 8\n4 5\n5 7\n6 2\n6 6\n", "output": "4\n" }, { "input": "4 6 2\n3 2\n3 5\n4 5\n2 5\n", "output": "-1\n" }, { "input": "1 10 1\n1 5\n1 1\n1 7\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_g
Problem Statement N players numbered 1 through N will participate in a round-robin tournament. Specifically, for every pair (i,j) (1\leq i \lt j \leq N) , Player i and Player j play a match against each other once, for a total of \frac{N(N-1)}{2} matches. In every match, one of the players will be a winner and the othe...
[ { "input": "4 2\n2 1\n2 3\n", "output": "2 4\n" }, { "input": "3 3\n1 2\n2 3\n3 1\n", "output": "\n" }, { "input": "7 9\n6 5\n1 2\n3 4\n5 3\n6 2\n1 5\n3 2\n6 4\n1 4\n", "output": "1 3 6 7\n" } ]
https://atcoder.jp/contests/abc241/tasks/abc241_h
Problem Statement There are some cards. Each card has one of N integers written on it. Specifically, there are B_i cards with A_i written on them. Next, for a combination of M cards chosen out of these (B_1+B_2\cdots +B_N) cards, we define the score of the combination by the product of the integers written on the M c...
[ { "input": "3 3\n3 1\n5 2\n6 3\n", "output": "819\n" }, { "input": "3 2\n1 1\n5 2\n25 1\n", "output": "180\n" }, { "input": "10 232657150901347497\n139547946 28316250877914575\n682142538 78223540024979445\n110643588 74859962623690081\n173455495 60713016476190629\n271056265 85335723211047...
https://atcoder.jp/contests/abc240/tasks/abc240_a
Problem Statement In the figure shown in the image below, are the points numbered a and b directly connected by a line segment?
[ { "input": "4 5\n", "output": "Yes\n" }, { "input": "3 5\n", "output": "No\n" }, { "input": "1 10\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_b
Problem Statement In a sequence of N positive integers a = (a_1, a_2, \dots, a_N) , how many different integers are there?
[ { "input": "6\n1 4 1 2 2 1\n", "output": "3\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "11\n3 1 4 1 5 9 2 6 5 3 5\n", "output": "7\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_c
Problem Statement Takahashi is standing at the coordinate 0 on a number line. He will now perform N jumps. In the i -th jump (1 \leq i \leq N) , he moves a_i or b_i in the positive direction. Is it possible for him to be at the coordinate X after N jumps?
[ { "input": "2 10\n3 6\n4 5\n", "output": "Yes\n" }, { "input": "2 10\n10 100\n10 100\n", "output": "No\n" }, { "input": "4 12\n1 8\n5 7\n3 4\n2 6\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_d
Problem Statement Takahashi has N balls. Each ball has an integer not less than 2 written on it. He will insert them in a cylinder one by one. The integer written on the i -th ball is a_i . The balls are made of special material. When k balls with k (k \geq 2) written on them line up in a row, all these k balls will di...
[ { "input": "5\n3 2 3 2 2\n", "output": "1\n2\n3\n4\n3\n" }, { "input": "10\n2 3 2 3 3 3 2 3 3 2\n", "output": "1\n2\n3\n4\n5\n3\n2\n3\n1\n0\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_e
Problem Statement You are given a rooted tree with N vertices. The root is Vertex 1 . For each i = 1, 2, \ldots, N-1 , the i -th edge connects Vertex u_i and Vertex v_i . For each i = 1, 2, \ldots, N , let S_i denote the set of all vertices in the subtree rooted at Vertex i . (Each vertex is in the subtree rooted at it...
[ { "input": "3\n2 1\n3 1\n", "output": "1 2\n2 2\n1 1\n" }, { "input": "5\n3 4\n5 4\n1 2\n1 4\n", "output": "1 3\n3 3\n2 2\n1 2\n1 1\n" }, { "input": "5\n4 5\n3 2\n5 2\n3 1\n", "output": "1 1\n1 1\n1 1\n1 1\n1 1\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_f
Problem Statement There are integer sequences A, B, C of length M each. C is represented by integers x_1, \dots, x_N, y_1, \dots, y_N . The first y_1 terms of C are x_1 , the subsequent y_2 terms are x_2 , \ldots , the last y_N terms are x_N . B is defined by B_i = \sum_{k = 1}^i C_k \, (1 \leq i \leq M) . A is defined...
[ { "input": "3\n3 7\n-1 2\n2 3\n-3 2\n10 472\n-4 12\n1 29\n2 77\n-1 86\n0 51\n3 81\n3 17\n-2 31\n-4 65\n4 23\n1 1000000000\n4 1000000000\n", "output": "4\n53910\n2000000002000000000\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_g
Problem Statement Takahashi is in the square (0, 0, 0) in an infinite three-dimensional grid. He can teleport between squares. From the square (x, y, z) , he can move to (x+1, y, z) , (x-1, y, z) , (x, y+1, z) , (x, y-1, z) , (x, y, z+1) , or (x, y, z-1) in one teleport. (Note that he cannot stay in the square (x, y, ...
[ { "input": "3 2 0 -1\n", "output": "3\n" }, { "input": "1 0 0 0\n", "output": "0\n" }, { "input": "314 15 92 65\n", "output": "106580952\n" } ]
https://atcoder.jp/contests/abc240/tasks/abc240_h
Problem Statement You are given a string S = s_1 s_2 \ldots s_N of length N consisting of 0 's and 1 's. Find the maximum integer K such that there is a sequence of K pairs of integers \big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big) that satisfy all three conditions below. 1 \leq L_i \leq R_i \leq N for each i = 1...
[ { "input": "7\n0101010\n", "output": "3\n" }, { "input": "30\n000011001110101001011110001001\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_a
Problem Statement Assuming that the horizon seen from a place x meters above the ground is \sqrt{x(12800000+x)} meters away, find how many meters away the horizon seen from a place H meters above the ground is.
[ { "input": "333\n", "output": "65287.907678222\n" }, { "input": "634\n", "output": "90086.635834623\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_b
Problem Statement Given an integer X between -10^{18} and 10^{18} (inclusive), print \left\lfloor \dfrac{X}{10} \right\rfloor .
[ { "input": "47\n", "output": "4\n" }, { "input": "-24\n", "output": "-3\n" }, { "input": "50\n", "output": "5\n" }, { "input": "-30\n", "output": "-3\n" }, { "input": "987654321987654321\n", "output": "98765432198765432\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_c
Problem Statement On an xy -coordinate plane, is there a lattice point whose distances from two lattice points (x_1, y_1) and (x_2, y_2) are both \sqrt{5} ?
[ { "input": "0 0 3 3\n", "output": "Yes\n" }, { "input": "0 1 2 3\n", "output": "No\n" }, { "input": "1000000000 1000000000 999999999 999999999\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_d
Problem Statement Takahashi and Aoki are playing a game. First, Takahashi chooses an integer between A and B (inclusive) and tells it to Aoki. Next, Aoki chooses an integer between C and D (inclusive). If the sum of these two integers is a prime, then Aoki wins; otherwise, Takahashi wins. When the two players play opti...
[ { "input": "2 3 3 4\n", "output": "Aoki\n" }, { "input": "1 100 50 60\n", "output": "Takahashi\n" }, { "input": "3 14 1 5\n", "output": "Aoki\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_e
Problem Statement We have a rooted tree with N vertices. The vertices are numbered 1 through N , and the root is Vertex 1 . The i -th edge connects Vertices A_i and B_i . Vertex i has an integer X_i written on it. You are given Q queries. For the i -th query, given a pair of integers (V_i,K_i) , answer the following ...
[ { "input": "5 2\n1 2 3 4 5\n1 4\n2 1\n2 5\n3 2\n1 2\n2 1\n", "output": "4\n5\n" }, { "input": "6 2\n10 10 10 9 8 8\n1 4\n2 1\n2 5\n3 2\n6 4\n1 4\n2 2\n", "output": "9\n10\n" }, { "input": "4 4\n1 10 100 1000\n1 2\n2 3\n3 4\n1 4\n2 3\n3 2\n4 1\n", "output": "1\n10\n100\n1000\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_f
Problem Statement The Republic of Atcoder has N towns numbered 1 through N , and M highways numbered 1 through M . Highway i connects Town A_i and Town B_i bidirectionally. King Takahashi is going to construct (N-M-1) new highways so that the following two conditions are satisfied: One can travel between every pair of ...
[ { "input": "6 2\n1 2 1 2 2 2\n2 3\n1 4\n", "output": "6 2\n5 6\n4 5\n" }, { "input": "5 1\n1 1 1 1 4\n2 3\n", "output": "-1\n" }, { "input": "4 0\n3 3 3 3\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc239/tasks/abc239_g
Problem Statement We have a simple connected undirected graph with N vertices and M edges. The vertices are numbered as Vertex 1 , Vertex 2 , \dots , Vertex N . The edges are numbered as Edge 1 , Edge 2 , \dots , Edge M . Edge i connects Vertex a_i and Vertex b_i bidirectionally. There is no edge that directly connec...
[ { "input": "5 5\n1 2\n2 3\n3 5\n2 4\n4 5\n0 8 3 4 0\n", "output": "7\n2\n3 4\n" }, { "input": "3 2\n1 2\n2 3\n0 1 0\n", "output": "1\n1\n2\n" }, { "input": "5 9\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n0 1000000000 1000000000 1000000000 0\n", "output": "3000000000\n3\n2 3 4\n" ...
https://atcoder.jp/contests/abc239/tasks/abc239_h
Problem Statement Snuke has a die (singular of dice) that shows integers from 1 through N with equal probability, and an integer 1 . He repeats the following operation while his integer is less than or equal to M . He rolls the die. If the die shows an integer x , he multiplies his integer by x . Find the expected val...
[ { "input": "2 1\n", "output": "2\n" }, { "input": "2 39\n", "output": "12\n" }, { "input": "3 2\n", "output": "250000004\n" }, { "input": "2392 39239\n", "output": "984914531\n" }, { "input": "1000000000 1000000000\n", "output": "776759630\n" } ]
https://atcoder.jp/contests/arc135/tasks/arc135_a
Problem Statement There is an integer X written on a blackboard. You can do the operation below any number of times (possibly zero). Choose an integer x written on the blackboard. Erase one x from the blackboard and write two new integers \lfloor \frac{x}{2}\rfloor and \lceil \frac{x}{2}\rceil . Find the maximum possib...
[ { "input": "15\n", "output": "192\n" }, { "input": "3\n", "output": "3\n" }, { "input": "100\n", "output": "824552442\n" } ]
https://atcoder.jp/contests/arc135/tasks/arc135_b
Problem Statement You are given a sequence of N integers S = (S_1, \ldots, S_N) . Determine whether there is a sequence of N+2 integers A = (A_1, \ldots, A_{N+2}) that satisfies the conditions below. 0\leq A_i for every i ( 1\leq i\leq N+2 ). S_i = A_{i} + A_{i+1} + A_{i+2} for every i ( 1\leq i\leq N ). If it exists,...
[ { "input": "5\n6 9 6 6 5\n", "output": "Yes\n0 4 2 3 1 2 2\n" }, { "input": "5\n0 1 2 1 0\n", "output": "No\n" }, { "input": "1\n10\n", "output": "Yes\n0 0 10\n" } ]
https://atcoder.jp/contests/arc135/tasks/arc135_c
Problem Statement You are given a sequence of non-negative integers A = (A_1, \ldots, A_N) . You can do the operation below any number of times (possibly zero). Choose an integer x\in \{A_1,\ldots,A_N\} . Replace A_i with A_i\oplus x for every i ( \oplus denotes the bitwise \mathrm{XOR} operation). Find the maximum po...
[ { "input": "5\n1 2 3 4 5\n", "output": "19\n" }, { "input": "5\n10 10 10 10 10\n", "output": "50\n" }, { "input": "5\n3 1 4 1 5\n", "output": "18\n" } ]
https://atcoder.jp/contests/arc135/tasks/arc135_d
Problem Statement We have an H \times W grid, where each square has one integer written on it. For 1\leq i\leq H and 1\leq j\leq W , let A_{i,j} denote the integer written on the square at the i -th row and j -th column. You can do the operation below any number of times (possibly zero). Choose integers i and j such t...
[ { "input": "2 3\n1 2 3\n4 5 6\n", "output": "9\n0 -3 -1\n3 0 2\n" }, { "input": "2 2\n1000000000 -1000000000\n-1000000000 1000000000\n", "output": "4000000000\n2000000000 0\n0 2000000000\n" }, { "input": "3 4\n0 2 0 -2\n-3 -1 2 0\n-3 -3 2 2\n", "output": "0\n0 0 0 0\n0 0 0 0\n0 0 0 0...
https://atcoder.jp/contests/arc135/tasks/arc135_e
Problem Statement You are given integers N and X . Assume that an integer sequence A = (A_1, \ldots, A_N) satisfies all of the conditions below. A_1 = X . For every i ( 1\leq i\leq N ), A_i is a multiple of i . A is strictly increasing. In other words, A_1 < \cdots < A_N holds. Find the minimum possible value of \sum_{...
[ { "input": "5\n5 100\n1 10\n10 1\n1000000000000000000 1\n100 100\n", "output": "525\n10\n55\n75433847\n61074\n" } ]
https://atcoder.jp/contests/arc135/tasks/arc135_f
Problem Statement You are given an integer N . On an integer sequence A = (1, 2, \ldots, N) , let us do the operation below exactly K times. Let n be the current number of terms in A . For all i such that 1\leq i \leq n and i\equiv 1\pmod{3} , delete the i -th term of A , simultaneously. Find the sum of the terms of A ...
[ { "input": "10 2\n", "output": "25\n" }, { "input": "10 10\n", "output": "0\n" }, { "input": "10000 10\n", "output": "862816\n" } ]
https://atcoder.jp/contests/loadchecking/tasks/loadchecking_a
問題文 高橋君は、長さ 20 の順列 A が好きです。ですが、高橋君の好きな順列は秘密です。 あなたが整数列 B (順列である必要はない) を出力すると、高橋君はどれだけ近いかを点数で答えてくれます。数列 B を出力してください。
[ { "input": "\n", "output": "2\n2\n17\n14\n1\n10\n16\n9\n3\n4\n5\n13\n12\n7\n18\n15\n19\n20\n11\n8\n" } ]
https://atcoder.jp/contests/joi2022ho/tasks/joi2022ho_a
問題文 時は \mathrm{30XX} 年.科学者・技術者のたゆまぬ努力により,異星間の交流が盛んに行われるようになっていた.ビーバーのビ太郎は異星人に地球の食べ物を紹介するアンバサダーを務めており,今日の午後 1 時に JOI 星へ向けて出発する予定である. 今回 JOI 星人に紹介する食べ物のひとつとして,切り分けたカステラが用意されている.カステラは小麦粉に鶏卵・砂糖・水あめを加え,スポンジ状にふっくらと焼いた菓子である. カステラは横長の直方体の形をしており,縦方向の切れ目に沿って N 個のピースに分割されている.左から i 番目 ( 1 \leqq i \leqq N ) のピースの長さは整数 A_i である. つい先ほ...
[ { "input": "4\n14\n9\n8\n12\n6\n2\n3\n5\n7\n11\n13\n", "output": "7\n9\n1\n1\n1\n3\n" }, { "input": "13\n1\n4\n1\n4\n2\n1\n3\n5\n6\n2\n3\n7\n3\n8\n2\n10\n11\n13\n15\n17\n18\n20\n", "output": "1\n1\n1\n1\n5\n3\n1\n3\n" }, { "input": "16\n536870912\n402653184\n536870912\n536870912\n1342177...