url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc260/tasks/abc260_e
Problem Statement You are given an integer M and N pairs of integers (A_1, B_1), (A_2, B_2), \dots, (A_N, B_N) . For all i , it holds that 1 \leq A_i \lt B_i \leq M . A sequence S is said to be a good sequence if the following conditions are satisfied: S is a contiguous subsequence of the sequence (1,2,3,..., M) . For ...
[ { "input": "3 5\n1 3\n1 4\n2 5\n", "output": "0 1 3 2 1\n" }, { "input": "1 2\n1 2\n", "output": "2 1\n" }, { "input": "5 9\n1 5\n1 7\n5 6\n5 8\n2 6\n", "output": "0 0 1 2 4 4 3 2 1\n" } ]
https://atcoder.jp/contests/abc260/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/abc260/tasks/abc260_g
Problem Statement We have an N \times N grid. The square at the i -th row from the top and j -th column from the left in this grid is called (i,j) . Each square of the grid has at most one piece. The state of the grid is given by N strings S_i : if the j -th character of S_i is O , then (i,j) has a piece on it; if the...
[ { "input": "4 2\nOXXX\nXXXX\nXXXX\nXXXX\n6\n1 1\n1 4\n2 2\n2 3\n3 1\n4 4\n", "output": "1\n1\n1\n0\n0\n0\n" }, { "input": "5 10\nOOOOO\nOOOOO\nOOOOO\nOOOOO\nOOOOO\n5\n1 1\n2 3\n3 4\n4 2\n5 5\n", "output": "1\n6\n12\n8\n25\n" }, { "input": "8 5\nOXXOXXOX\nXOXXOXOX\nXOOXOOXO\nOXOOXOXO\nOXX...
https://atcoder.jp/contests/abc260/tasks/abc260_h
Problem Statement There are N balls numbered 1 through N . Ball i is painted in Color a_i . For a permutation P = (P_1, P_2, \dots, P_N) of (1, 2, \dots, N) , let us define C(P) as follows: The number of pairs of adjacent balls with different colors when Balls P_1, P_2, \dots, P_N are lined up in a row in this order. ...
[ { "input": "3 4\n1 1 2\n", "output": "8 12 20 36\n" }, { "input": "2 1\n1 1\n", "output": "0\n" }, { "input": "10 5\n3 1 4 1 5 9 2 6 5 3\n", "output": "30481920 257886720 199419134 838462446 196874334\n" } ]
https://atcoder.jp/contests/arc144/tasks/arc144_a
Problem Statement For a positive integer x , let f(x) be the sum of its digit. For example, f(144) = 1+4+4 = 9 and f(1)=1 . You are given a positive integer N . Find the following positive integers M and x : The maximum positive integer M for which there exists a positive integer x such that f(x)=N and f(2x)=M . The mi...
[ { "input": "3\n", "output": "6\n3\n" }, { "input": "6\n", "output": "12\n24\n" }, { "input": "100\n", "output": "200\n4444444444444444444444444\n" } ]
https://atcoder.jp/contests/arc144/tasks/arc144_b
Problem Statement You are given positive integers a and b such that a\leq b , and a sequence of positive integers A = (A_1, A_2, \ldots, A_N) . On this sequence, you can perform the following operation any number of times (possibly zero): Choose distinct indices i, j ( 1\leq i, j \leq N ). Add a to A_i and subtract b f...
[ { "input": "3 2 2\n1 5 9\n", "output": "5\n" }, { "input": "3 2 3\n11 1 2\n", "output": "3\n" }, { "input": "3 1 100\n8 5 6\n", "output": "5\n" }, { "input": "6 123 321\n10 100 1000 10000 100000 1000000\n", "output": "90688\n" } ]
https://atcoder.jp/contests/arc144/tasks/arc144_c
Problem Statement You are given positive integers N and K . Find the lexicographically smallest permutation A = (A_1, A_2, \ldots, A_N) of the integers from 1 through N that satisfies the following condition: \lvert A_i - i\rvert \geq K for all i ( 1\leq i\leq N ). If there is no such permutation, print -1 . What is l...
[ { "input": "3 1\n", "output": "2 3 1\n" }, { "input": "8 3\n", "output": "4 5 6 7 8 1 2 3\n" }, { "input": "8 6\n", "output": "-1\n" } ]
https://atcoder.jp/contests/arc144/tasks/arc144_d
Problem Statement You are given positive integers N and K . Find the number, modulo 998244353 , of integer sequences \bigl(f(0), f(1), \ldots, f(2^N-1)\bigr) that satisfy all of the following conditions: 0\leq f(x)\leq K for all non-negative integers x ( 0\leq x \leq 2^N-1 ). f(x) + f(y) = f(x \,\mathrm{AND}\, y) + f(x...
[ { "input": "2 1\n", "output": "6\n" }, { "input": "2 2\n", "output": "19\n" }, { "input": "100 123456789123456789\n", "output": "34663745\n" } ]
https://atcoder.jp/contests/arc144/tasks/arc144_e
Problem Statement You are given a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N . The i -th edge is directed from Vertex a_i to Vertex b_i , where a_i < b_i . The beautifulness of a sequence of positive integers W = (W_1, W_2, \ldots, W_N) is defined as the maximum positive int...
[ { "input": "4 4\n1 2\n1 3\n2 4\n3 4\n-1 3 7 -1\n", "output": "4\n" }, { "input": "4 5\n1 2\n1 3\n2 4\n3 4\n1 4\n-1 3 7 -1\n", "output": "1\n" }, { "input": "4 4\n1 2\n1 3\n2 4\n3 4\n3 -1 -1 7\n", "output": "-1\n" }, { "input": "5 5\n1 3\n3 5\n2 3\n3 4\n1 4\n2 -1 3 -1 4\n", ...
https://atcoder.jp/contests/arc144/tasks/arc144_f
Problem Statement You are given a positive integer m , a non-negative integer a ( 0\leq a < m ), and a sequence of positive integers A = (A_1, \ldots, A_N) . A set X of positive integers is defined as X = \{x>0\mid x\equiv a \pmod{m}\} . Alice and Bob will play a game against each other. They will alternate turns perfo...
[ { "input": "3 1 0\n5 6 7\n", "output": "3\n" }, { "input": "5 10 3\n5 9 18 23 27\n", "output": "3\n" }, { "input": "4 10 8\n100 101 102 103\n", "output": "0\n" }, { "input": "5 2 1\n111111111111111 222222222222222 333333333333333 444444444444444 555555555555555\n", "outpu...
https://atcoder.jp/contests/abc259/tasks/abc259_a
Problem Statement Takahashi had his N -th birthday, when he was T centimeters tall. Additionally, we know the following facts: In each year between Takahashi's birth ( 0 -th birthday) and his X -th birthday, his height increased by D centimeters. More formally, for each i = 1, 2, \ldots, X , his height increased by D c...
[ { "input": "38 20 17 168 3\n", "output": "168\n" }, { "input": "1 0 1 3 2\n", "output": "1\n" }, { "input": "100 10 100 180 1\n", "output": "90\n" } ]
https://atcoder.jp/contests/abc259/tasks/abc259_b
Problem Statement In an xy -coordinate plane whose x -axis is oriented to the right and whose y -axis is oriented upwards, rotate a point (a, b) around the origin d degrees counterclockwise and find the new coordinates of the point.
[ { "input": "2 2 180\n", "output": "-2 -2\n" }, { "input": "5 0 120\n", "output": "-2.49999999999999911182 4.33012701892219364908\n" }, { "input": "0 0 11\n", "output": "0.00000000000000000000 0.00000000000000000000\n" }, { "input": "15 5 360\n", "output": "15.000000000000...
https://atcoder.jp/contests/abc259/tasks/abc259_c
Problem Statement You are given two strings S and T . Determine whether it is possible to make S equal T by performing the following operation some number of times (possibly zero). Between two consecutive equal characters in S , insert a character equal to these characters. That is, take the following three steps. Le...
[ { "input": "abbaac\nabbbbaaac\n", "output": "Yes\n" }, { "input": "xyzz\nxyyzz\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc259/tasks/abc259_d
Problem Statement You are given N circles on the xy -coordinate plane. For each i = 1, 2, \ldots, N , the i -th circle is centered at (x_i, y_i) and has a radius of r_i . Determine whether it is possible to get from (s_x, s_y) to (t_x, t_y) by only passing through points that lie on the circumference of at least one of...
[ { "input": "4\n0 -2 3 3\n0 0 2\n2 0 2\n2 3 1\n-3 3 3\n", "output": "Yes\n" }, { "input": "3\n0 1 0 3\n0 0 1\n0 0 2\n0 0 3\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc259/tasks/abc259_e
Problem Statement There are N integers a_1,\ldots,a_N written on a whiteboard. Here, a_i can be represented as a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}} using m_i prime numbers p_{i,1} \lt \ldots \lt p_{i,m_i} and positive integers e_{i,1},\ldots,e_{i,m_i} . You will choose one of the N integer...
[ { "input": "4\n1\n7 2\n2\n2 2\n5 1\n1\n5 1\n2\n2 1\n7 1\n", "output": "3\n" }, { "input": "1\n1\n998244353 1000000000\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc259/tasks/abc259_f
Problem Statement You are given a tree with N vertices. For each i = 1, 2, \ldots, N-1 , the i -th edge connects Vertex u_i and Vertex v_i and has a weight w_i . Consider choosing some of the N-1 edges (possibly none or all). Here, for each i = 1, 2, \ldots, N , one may choose at most d_i edges incident to Vertex i ....
[ { "input": "7\n1 2 1 0 2 1 1\n1 2 8\n2 3 9\n2 4 10\n2 5 -3\n5 6 8\n5 7 3\n", "output": "28\n" }, { "input": "20\n0 2 0 1 2 1 0 0 3 0 1 1 1 1 0 0 3 0 1 2\n4 9 583\n4 6 -431\n5 9 325\n17 6 131\n17 2 -520\n2 16 696\n5 7 662\n17 15 845\n7 8 307\n13 7 849\n9 19 242\n20 6 909\n7 11 -775\n17 18 557\n14 20 ...
https://atcoder.jp/contests/abc259/tasks/abc259_g
Problem Statement There are H \times W cards on a grid of squares with H rows and W columns. For each pair of integers (i, j) such that 1 \leq i \leq H, 1 \leq j \leq W , the card at the i -th row and j -th column has an integer A_{i, j} written on it. Takahashi and Aoki will cooperate to play a game, which consists o...
[ { "input": "2 3\n-9 5 1\n6 -2 4\n", "output": "9\n" }, { "input": "15 20\n-14 74 -48 38 -51 43 5 37 -39 -29 80 -44 -55 59 17 89 -37 -68 38 -16\n14 31 43 -73 49 -7 -65 13 -40 -45 36 88 -54 -43 99 87 -94 57 -22 31\n-85 67 -46 23 95 68 55 17 -56 51 -38 64 32 -19 65 -62 76 66 -53 -16\n35 -78 -41 35 -51 ...
https://atcoder.jp/contests/abc259/tasks/abc259_h
Problem Statement We have a grid of squares with N rows arranged vertically and N columns arranged horizontally. The square at the i -th row from the top and j -th column from the left has an integer label a_{i,j} . Consider paths obtained by starting on one of the squares and going right or down to an adjacent square ...
[ { "input": "2\n1 3\n3 1\n", "output": "6\n" } ]
https://atcoder.jp/contests/ahc012/tasks/ahc012_a
Problem Statement There is a circular cake with a radius of 10^4 centered at the origin and N strawberries on top of it. The center of the i -th strawberry is at the coordinates (x_i, y_i) and satisfies x_i^2+y_i^2<10^8 . Takahashi can cut the cake in at most K straight lines (not segments), which may intersect each ...
[ { "input": "2835 100\n51 3 44 99 1 87 83 19 10 90\n484 -7595\n606 -4986\n-70 3067\n3481 -4705\n-3464 -3044\n1329 -4256\n-3512 -5340\n-2544 6126\n3435 7021\n-7712 -6197\n-3097 569\n7192 1127\n-1048 1879\n4813 -3083\n-5549 6929\n-442 2382\n2945 3994\n6014 -7099\n7351 -3206\n957 2312\n4759 3636\n5006 2830\n1295 -3...
https://atcoder.jp/contests/abc258/tasks/abc258_a
Problem Statement AtCoder Beginner Contest usually starts at 21:00 JST and lasts for 100 minutes. You are given an integer K between 0 and 100 (inclusive). Print the time K minutes after 21:00 in the HH:MM format, where HH denotes the hour on the 24 -hour clock and MM denotes the minute. If the hour or the minute has j...
[ { "input": "63\n", "output": "22:03\n" }, { "input": "45\n", "output": "21:45\n" }, { "input": "100\n", "output": "22:40\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_b
Problem Statement You are given a positive integer N . We have a grid with N rows and N columns, where the square at the i -th row from the top and j -th column from the left has a digit A_{i,j} written on it. Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In othe...
[ { "input": "4\n1161\n1119\n7111\n1811\n", "output": "9786\n" }, { "input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n", "output": "1111111111\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_c
Problem Statement You are given positive integers N and Q , and a string S of length N consisting of lowercase English letters. Process Q queries. Each query is of one of the following two types. 1 x : Perform the following x times in a row: delete the last character of S and append it to the beginning. 2 x : Print the...
[ { "input": "3 3\nabc\n2 2\n1 1\n2 2\n", "output": "b\na\n" }, { "input": "10 8\ndsuccxulnl\n2 4\n2 7\n1 2\n2 7\n1 1\n1 2\n1 3\n2 5\n", "output": "c\nu\nc\nu\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_d
Problem Statement We have a video game consisting of N stages. The i -th stage (1 \leq i \leq N) is composed of a movie lasting A_i minutes and gameplay lasting B_i minutes. To clear the i -th stage for the first time, one must watch the movie and do the gameplay for that stage. For the second and subsequent times, one...
[ { "input": "3 4\n3 4\n2 3\n4 2\n", "output": "18\n" }, { "input": "10 1000000000\n3 3\n1 6\n4 7\n1 8\n5 7\n9 9\n2 4\n6 4\n5 1\n3 1\n", "output": "1000000076\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_e
Problem Statement 10^{100} potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence W = (W_0, \dots, W_{N-1}) of length N : the weight of the i -th potato coming is W_{(i-1) \bmod N} , where (i-1) \bmod N denotes the remainder when i - 1 is divided by N . Takahashi wi...
[ { "input": "3 2 5\n3 4 1\n1\n2\n", "output": "2\n3\n" }, { "input": "10 5 20\n5 8 5 9 8 7 4 4 8 2\n1\n1000\n1000000\n1000000000\n1000000000000\n", "output": "4\n5\n5\n5\n5\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_f
Problem Statement The roads in the Kingdom of AtCoder, which lies on the xy-plane, are the lines x=n and y=n for all integers n . Among them, the lines x=Bn and y=Bn for all integers n are main roads. When Takahashi is at (x,y) , he can move to (x,y-1) , (x,y+1) , (x+1,y) , or (x-1,y) . Each move takes 1 second along a...
[ { "input": "4\n3 4 2 2 4 4\n5 6 2 3 2 3\n1 1000000000 0 0 1000000000 1000000000\n1000000000 1000000000 500000000 500000000 1000000000 1000000000\n", "output": "10\n0\n2000000000\n500000000500000000\n" }, { "input": "10\n928184439 674654465 203937094 186855052 851783856 805293696\n55480262 448852233 ...
https://atcoder.jp/contests/abc258/tasks/abc258_g
Problem Statement You are given a simple undirected graph G with N vertices. G is given as the N \times N adjacency matrix A . That is, there is an edge between Vertices i and j if A_{i,j} is 1 , and there is not if A_{i,j} is 0 . Find the number of triples of integers (i,j,k) satisfying 1 \le i < j < k \le N such that...
[ { "input": "4\n0011\n0011\n1101\n1110\n", "output": "2\n" }, { "input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc258/tasks/abc258_h
Problem Statement Find the number, modulo 998244353 , of sequences X that satisfy all of the following conditions. Every term in X is a positive odd number . The sum of the terms in X is S . The prefix sums of X contain none of A_1, \dots, A_N . Formally, if we define Y_i = X_1 + \dots + X_i for each i , then Y_i \neq ...
[ { "input": "3 7\n2 4 5\n", "output": "3\n" }, { "input": "5 60\n10 20 30 40 50\n", "output": "37634180\n" }, { "input": "10 1000000000000000000\n1 2 4 8 16 32 64 128 256 512\n", "output": "75326268\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_a
Problem Statement Three non-negative integers A , B , and C are written on a blackboard. You can perform the following two operations any number of times in any order. Subtract 1 from two of the written integers of your choice. Subtract 1 from all of the written integers. Your objective is to make all the numbers on t...
[ { "input": "2 2 3\n", "output": "3\n" }, { "input": "0 0 1\n", "output": "-1\n" }, { "input": "0 0 0\n", "output": "0\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_b
Problem Statement Find the number of ways, modulo 998244353 , to fill the squares of an N \times N grid using each integer from 1 to N^2 once so that every square satisfies at least one of the following conditions. In the same column, there is a square containing a number greater than that of the concerned square. In t...
[ { "input": "2\n", "output": "8\n" }, { "input": "5\n", "output": "704332752\n" }, { "input": "100\n", "output": "927703658\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_c
Problem Statement There are N piles of pebbles. Initially, the i -th pile has A_i pebbles. Takahashi and Aoki will play a game using these piles. They will alternately perform the following operation, with Takahashi going first, and the one who becomes unable to do so loses the game. Choose one or more piles, and remo...
[ { "input": "2 1 1\n3 3\n", "output": "First\n" }, { "input": "2 1 2\n3 3\n", "output": "Second\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_d
Problem Statement We have two sequences A_1,\ldots, A_M and B_1,\ldots,B_M consisting of intgers between 1 and N (inclusive). For a string of length M consisting of 0 and 1 , consider the following undirected graph with 2N vertices and (M+N) edges corresponding to that string. If the i -th character of the string is 0 ...
[ { "input": "2 2\n1 1\n2 2\n", "output": "01\n" }, { "input": "6 7\n1 1 2 3 4 4 5\n2 3 3 4 5 6 6\n", "output": "0100010\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_e
Problem Statement We have a tree with N vertices. The vertices are numbered 1 to N , and the i -th edge connects Vertex A_i and Vertex B_i . Additionally, each vertex has a reversi piece on it. The status of the piece on each vertex is given by a string S : if the i -th character of S is B , the piece on Vertex i ...
[ { "input": "4\n1 2\n2 3\n3 4\nWBWW\n", "output": "1 2 4 3 \n" }, { "input": "4\n1 2\n2 3\n3 4\nBBBB\n", "output": "-1\n" } ]
https://atcoder.jp/contests/arc143/tasks/arc143_f
Problem Statement Given a positive integer N , find the number, modulo 998244353 , of subsets S of \{1, 2, \ldots, N\} that satisfy the following condition. Every positive integer at most N can be represented as the sum of some distinct elements of S , and there are at most two such representations.
[ { "input": "3\n", "output": "2\n" }, { "input": "5\n", "output": "5\n" }, { "input": "1000\n", "output": "742952024\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_a
Problem Statement Find the X -th character from the beginning of the string that is obtained by concatenating these characters: N copies of A 's, N copies of B 's, …, and N copies of Z 's, in this order.
[ { "input": "1 3\n", "output": "C\n" }, { "input": "2 12\n", "output": "F\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_b
Problem Statement There are N squares, indexed Square 1 , Square 2 , …, Square N , arranged in a row from left to right. Also, there are K pieces. The i -th piece from the left is initially placed on Square A_i . Now, we will perform Q operations against them. The i -th operation is as follows: If the L_i -th piece f...
[ { "input": "5 3 5\n1 3 4\n3 3 1 1 2\n", "output": "2 4 5\n" }, { "input": "2 2 2\n1 2\n1 2\n", "output": "1 2\n" }, { "input": "10 6 9\n1 3 5 7 8 9\n1 2 3 4 5 6 5 6 2\n", "output": "2 5 6 7 9 10\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_c
Problem Statement There are N people, each of whom is either a child or an adult. The i -th person has a weight of W_i . Whether each person is a child or an adult is specified by a string S of length N consisting of 0 and 1 . If the i -th character of S is 0 , then the i -th person is a child; if it is 1 , then the i...
[ { "input": "5\n10101\n60 45 30 40 80\n", "output": "4\n" }, { "input": "3\n000\n1 2 3\n", "output": "3\n" }, { "input": "5\n10101\n60 50 50 50 60\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_d
Problem Statement There are N trampolines on a two-dimensional planar town where Takahashi lives. The i -th trampoline is located at the point (x_i, y_i) and has a power of P_i . Takahashi's jumping ability is denoted by S . Initially, S=0 . Every time Takahashi trains, S increases by 1 . Takahashi can jump from th...
[ { "input": "4\n-10 0 1\n0 0 5\n10 0 1\n11 0 1\n", "output": "2\n" }, { "input": "7\n20 31 1\n13 4 3\n-10 -15 2\n34 26 5\n-2 39 4\n0 -50 1\n5 -20 2\n", "output": "18\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_e
Problem Statement Takahashi has an integer x . Initially, x=0 . Takahashi may do the following operation any number of times. Choose an integer i\ (1\leq i \leq 9) . Pay C_i yen (the currency in Japan) to replace x with 10x + i . Takahashi has a budget of N yen. Find the maximum possible value of the final x resulti...
[ { "input": "5\n5 4 3 3 2 5 3 5 3\n", "output": "95\n" }, { "input": "20\n1 1 1 1 1 1 1 1 1\n", "output": "99999999999999999999\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_f
Problem Statement There are N towns numbered Town 1 , Town 2 , \ldots , Town N . There are also M Teleporters , each of which connects two towns bidirectionally so that a person can travel from one to the other in one minute. The i -th Teleporter connects Town U_i and Town V_i bidirectionally. However, for some of th...
[ { "input": "3 2\n0 2\n1 2\n", "output": "-1 -1 2\n" }, { "input": "5 5\n1 2\n1 3\n3 4\n4 5\n0 2\n", "output": "3 3 3 3 2\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_g
Problem Statement You are given two strings S and T consisting of lowercase English letters. Find the minimum positive integer k such that you can choose (not necessarily distinct) k prefixes of S so that their concatenation coincides with T . In other words, find the minimum positive integer k such that there exists ...
[ { "input": "aba\nababaab\n", "output": "3\n" }, { "input": "atcoder\nac\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc257/tasks/abc257_h
Problem Statement The six-sided dice speciality shop "Saikoroya" sells N dice. The i -th die (singular of dice) has A_{i,1},A_{i,2},\ldots,A_{i,6} written on its each side, and has a price of C_i . Takahashi is going to choose exactly K of them and buy them. Currently, "Saikoroya" is conducting a promotion: Takahashi ...
[ { "input": "3 2\n1 2 3\n1 1 1 1 1 1\n2 2 2 2 2 2\n3 3 3 3 3 3\n", "output": "20\n" }, { "input": "10 5\n2 5 6 5 2 1 7 9 7 2\n5 5 2 4 7 6\n2 2 8 7 7 9\n8 1 9 6 10 8\n8 6 10 3 3 9\n1 10 5 8 1 10\n7 8 4 8 6 5\n1 10 2 5 1 7\n7 4 1 4 5 4\n5 10 1 5 1 2\n5 1 2 3 6 2\n", "output": "1014\n" } ]
https://atcoder.jp/contests/arc142/tasks/arc142_a
Problem Statement For a positive integer x , let f(x) be the answer to the question below. The following operation on x can be performed zero or more times. Let x' be the integer obtained by reversing the decimal notation of x . Then, replace x with x' . If x now has one or more leading zeros, delete them so that it be...
[ { "input": "1420 142\n", "output": "3\n" }, { "input": "1419 142\n", "output": "2\n" }, { "input": "6 19\n", "output": "0\n" } ]
https://atcoder.jp/contests/arc142/tasks/arc142_b
Problem Statement We have an N \times N grid. Let (i,j) denote the square at the i -th row from the top and j -th column from the left in this grid. Find one way to write an integer on every square to satisfy the conditions below. Each integer between 1 and N^2 is written exactly once. For every pair of integers i,j\, ...
[ { "input": "2\n", "output": "1 2\n3 4\n" }, { "input": "3\n", "output": "1 2 3\n5 4 6\n7 8 9\n" } ]
https://atcoder.jp/contests/arc142/tasks/arc142_c
Problem Statement There is a tree with N vertices, numbered 1, \ldots, N . For each pair of integers u,v\, (1 \leq u,v \leq N) , the distance d_{u,v} between Vertices u, v is defined as the following. The number of edges contained in the shortest path connecting Vertices u and v . You are allowed to ask between 0 and 2...
[]
https://atcoder.jp/contests/arc142/tasks/arc142_d
Problem Statement We have a tree with N vertices, numbered 1, \ldots, N . For each i=1,\ldots,N-1 , the i -th edge connects Vertex a_i and Vertex b_i . An operation on this tree when at most one piece is put on each vertex is defined as follows. Simultaneously move every piece to one of the vertices adjacent to the on...
[ { "input": "3\n1 2\n1 3\n", "output": "2\n" }, { "input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "output": "0\n" }, { "input": "19\n9 14\n2 13\n1 3\n17 19\n13 18\n12 19\n4 5\n2 10\n4 9\n8 11\n3 15\n6 8\n8 10\n6 19\n9 13\n11 15\n7 17\n16 17\n", "output": "100\n" } ]
https://atcoder.jp/contests/arc142/tasks/arc142_e
Problem Statement There are N wizards, numbered 1, \ldots, N . Wizard i has a strength of a_i and plans to defeat a monster with a strength of b_i . You can perform the following operation any number of times. Increase the strength of any wizard of your choice by 1 . A pair of Wizard i and Wizard j (let us call this pa...
[ { "input": "5\n1 5\n2 4\n3 3\n4 2\n5 1\n3\n1 4\n2 5\n3 5\n", "output": "2\n" }, { "input": "4\n1 1\n1 1\n1 1\n1 1\n3\n1 2\n2 3\n3 4\n", "output": "0\n" }, { "input": "9\n1 1\n2 4\n5 5\n7 10\n9 3\n9 13\n10 9\n3 9\n2 9\n7\n1 5\n2 5\n1 6\n2 4\n3 4\n4 9\n8 9\n", "output": "22\n" } ]
https://atcoder.jp/contests/arc142/tasks/arc142_f
Problem Statement Two wizards, X and Y , are fighting with a monster. Initially, each of the wizards has a magic power of 0 . They know the following two spells. Spell 1 : Increases the caster's magic power by 1 . Spell 2 : Deals damage equal to the caster's magic power to the monster. After each wizard uses a spell N ...
[ { "input": "3\n1 1 2 2\n2 1 2 2\n2 1 1 1\n", "output": "3\n" }, { "input": "5\n2 2 2 2\n2 2 2 2\n2 2 2 2\n2 2 2 2\n2 2 2 2\n", "output": "0\n" }, { "input": "8\n1 1 2 2\n2 2 2 1\n1 1 2 1\n1 1 2 2\n2 1 1 1\n1 2 1 2\n2 1 1 2\n2 1 2 1\n", "output": "20\n" }, { "input": "20\n2 1 ...
https://atcoder.jp/contests/abc256/tasks/abc256_a
Problem Statement Given N , print 2^N .
[ { "input": "3\n", "output": "8\n" }, { "input": "30\n", "output": "1073741824\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_b
Problem Statement Takahashi is trying to create a game inspired by baseball, but he is having difficulty writing the code. Write a program for Takahashi that solves the following problem. There are 4 squares called Square 0 , Square 1 , Square 2 , and Square 3 . Initially, all squares are empty. There is also an integ...
[ { "input": "4\n1 1 3 2\n", "output": "3\n" }, { "input": "3\n1 1 1\n", "output": "0\n" }, { "input": "10\n2 2 4 1 1 1 4 2 2 1\n", "output": "8\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_c
Problem Statement You are given six integers: h_1, h_2, h_3, w_1, w_2 , and w_3 . Consider writing a positive integer on each square of a 3 \times 3 grid so that all of the following conditions are satisfied: For i=1,2,3 , the sum of numbers written in the i -th row from the top is h_i . For j=1,2,3 , the sum of number...
[ { "input": "3 4 6 3 3 7\n", "output": "1\n" }, { "input": "3 4 5 6 7 8\n", "output": "0\n" }, { "input": "5 13 10 6 13 9\n", "output": "120\n" }, { "input": "20 25 30 22 29 24\n", "output": "30613\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_d
Problem Statement For real numbers L and R , let us denote by [L,R) the set of real numbers greater than or equal to L and less than R . Such a set is called a right half-open interval. You are given N right half-open intervals [L_i,R_i) . Let S be their union. Represent S as a union of the minimum number of right h...
[ { "input": "3\n10 20\n20 30\n40 50\n", "output": "10 30\n40 50\n" }, { "input": "3\n10 40\n30 60\n20 50\n", "output": "10 60\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_e
Problem Statement There are N people numbered 1 through N . Takahashi has decided to choose a sequence P = (P_1, P_2, \dots, P_N) that is a permutation of integers from 1 through N , and give a candy to Person P_1 , Person P_2 , \dots , and Person P_N , in this order. Since Person i dislikes Person X_i , if Takahashi g...
[ { "input": "3\n2 3 2\n1 10 100\n", "output": "10\n" }, { "input": "8\n7 3 5 5 8 4 1 2\n36 49 73 38 30 85 27 45\n", "output": "57\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_f
Problem Statement You are given N , Q , and A=(A_1,\ldots,A_N) . Process Q queries, each of which is of one of the following two kinds: 1 x v : update A_x to v . 2 x : let B_i=\sum_{j=1}^{i}A_j , C_i=\sum_{j=1}^{i}B_j , and D_i=\sum_{j=1}^{i}C_j . Print D_x modulo 998244353 .
[ { "input": "3 3\n1 2 3\n2 3\n1 2 0\n2 3\n", "output": "15\n9\n" }, { "input": "2 1\n998244353 998244353\n2 1\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_g
Problem Statement There is a regular N -gon with side length D . Starting from a vertex, we place black or white stones on the circumference at intervals of 1 . As a result, each edge of the N -gon will have (D+1) stones on it, for a total of ND stones. How many ways are there to place stones so that all edges have th...
[ { "input": "3 2\n", "output": "10\n" }, { "input": "299792458 3141\n", "output": "138897974\n" } ]
https://atcoder.jp/contests/abc256/tasks/abc256_h
Problem Statement You are given N , Q , and A=(a_1,\ldots,a_N) . Process Q queries described below. Each query is of one of the following three kinds: 1 L R x : for i=L,L+1,\dots,R , update the value of a_i to \displaystyle \left\lfloor \frac{a_i}{x} \right\rfloor . 2 L R y : for i=L,L+1,\dots,R , update the value of ...
[ { "input": "3 5\n2 5 6\n3 1 3\n1 2 3 2\n3 1 2\n2 1 2 3\n3 1 3\n", "output": "13\n4\n9\n" }, { "input": "6 11\n10 3 5 20 6 7\n3 1 6\n1 2 4 3\n3 1 3\n2 1 4 10\n3 3 6\n1 3 6 2\n2 1 4 5\n3 1 6\n2 1 3 100\n1 2 5 6\n3 1 4\n", "output": "51\n12\n33\n26\n132\n" } ]
https://atcoder.jp/contests/abc255/tasks/abc255_a
Problem Statement Given integers R , C , and a 2 \times 2 matrix A , print A_{R,C} .
[ { "input": "1 2\n1 0\n0 1\n", "output": "0\n" }, { "input": "2 2\n1 2\n3 4\n", "output": "4\n" }, { "input": "2 1\n90 80\n70 60\n", "output": "70\n" } ]
https://atcoder.jp/contests/abc255/tasks/abc255_b
Problem Statement There are N people numbered 1, 2, \dots, N in the xy -plane. Person i is at the coordinates (X_i, Y_i) . K of these people, Persons A_1, A_2, \dots, A_K , will receive lights of the same strength. When a person at coordinates (x, y) has a light of strength R , it lights up the interior of a circle of ...
[ { "input": "4 2\n2 3\n0 0\n0 1\n1 2\n2 0\n", "output": "2.23606797749978969\n" }, { "input": "2 1\n2\n-100000 -100000\n100000 100000\n", "output": "282842.712474619009\n" }, { "input": "8 3\n2 6 8\n-17683 17993\n93038 47074\n58079 -57520\n-41515 -89802\n-72739 68805\n24324 -73073\n71049 ...
https://atcoder.jp/contests/abc255/tasks/abc255_c
Problem Statement You are given an integer X . The following action on this integer is called an operation . Choose and do one of the following. Add 1 to X . Subtract 1 from X . The terms in the arithmetic progression S with N terms whose initial term is A and whose common difference is D are called good numbers . Cons...
[ { "input": "6 2 3 3\n", "output": "1\n" }, { "input": "0 0 0 1\n", "output": "0\n" }, { "input": "998244353 -10 -20 30\n", "output": "998244363\n" }, { "input": "-555555555555555555 -1000000000000000000 1000000 1000000000000\n", "output": "444445\n" } ]
https://atcoder.jp/contests/abc255/tasks/abc255_d
Problem Statement You are given a sequence of length N : A=(A_1,A_2,\dots,A_N) . The following action on this sequence is called an operation . First, choose an integer i such that 1 \le i \le N . Next, choose and do one of the following. Add 1 to A_i . Subtract 1 from A_i . Answer Q questions. The i -th question is th...
[ { "input": "5 3\n6 11 2 5 5\n5\n20\n0\n", "output": "10\n71\n29\n" }, { "input": "10 5\n1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353\n555555555\n321654987\n1000000000\n789456123\n0\n", "output": "3316905982\n2811735560\n5542639502\n4275864946\n4457...
https://atcoder.jp/contests/abc255/tasks/abc255_e
Problem Statement You are given a sequence of N-1 integers S = (S_1, S_2, \ldots, S_{N-1}) , and M distinct integers X_1, X_2, \ldots, X_M , which are called lucky numbers . A sequence of N integers A = (A_1, A_2, \ldots, A_N) satisfying the following condition is called a good sequence . A_i + A_{i+1} = S_i holds for ...
[ { "input": "9 2\n2 3 3 4 -4 -7 -4 -1\n-1 5\n", "output": "4\n" }, { "input": "20 10\n-183260318 206417795 409343217 238245886 138964265 -415224774 -499400499 -313180261 283784093 498751662 668946791 965735441 382033304 177367159 31017484 27914238 757966050 878978971 73210901\n-470019195 -379631053 -...
https://atcoder.jp/contests/abc255/tasks/abc255_f
Problem Statement Consider a binary tree with N vertices numbered 1, 2, \ldots, N . Here, a binary tree is a rooted tree where each vertex has at most two children. Specifically, each vertex in a binary tree has at most one left child and at most one right child . Determine whether there exists a binary tree rooted at ...
[ { "input": "6\n1 3 5 6 4 2\n3 5 1 4 6 2\n", "output": "3 6\n0 0\n0 5\n0 0\n0 0\n4 2\n" }, { "input": "2\n2 1\n1 2\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc255/tasks/abc255_g
Problem Statement Takahashi and Aoki will play a game against each other using N piles of stones. Initially, for each i = 1, 2, \ldots, N , the i -th pile is composed of A_i stones. The players alternately perform the following action, with Takahashi going first. Choose a pile with at least one stone remaining, and re...
[ { "input": "3 4\n1 2 4\n2 1\n3 3\n3 1\n1 1\n", "output": "Takahashi\n" }, { "input": "1 5\n5\n5 1\n5 2\n5 3\n5 4\n5 5\n", "output": "Aoki\n" } ]
https://atcoder.jp/contests/abc255/tasks/abc255_h
Problem Statement There are N trees. On Day 0 , each tree bears no fruits. On the morning of Day 1 and subsequent days, the i -th tree bears i new fruits for each i = 1, 2, \ldots, N . Takahashi will perform Q harvesting. For each i = 1, 2, \ldots, Q , the i -th harvesting takes place on the night of Day D_i , collect...
[ { "input": "5 3\n2 2 3\n3 3 4\n5 1 5\n", "output": "10\n15\n50\n" }, { "input": "711741968710511029 1\n82803157126515475 516874290286751784 588060532191410838\n", "output": "603657470\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_a
Problem Statement You are given an integer N at least 100 . Print the last two digits of N . Strictly speaking, print the tens and ones digits of N in this order.
[ { "input": "254\n", "output": "54\n" }, { "input": "101\n", "output": "01\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_b
Problem Statement Find the N integer sequences A_0,\ldots,A_{N-1} defined as follows. For each i (0\leq i \leq N-1) , the length of A_i is i+1 . For each i and j (0\leq i \leq N-1, 0 \leq j \leq i) , the (j+1) -th term of A_i , denoted by a_{i,j} , is defined as follows. a_{i,j}=1 , if j=0 or j=i . a_{i,j} = a_{i-1,j-1...
[ { "input": "3\n", "output": "1\n1 1\n1 2 1\n" }, { "input": "10\n", "output": "1\n1 1\n1 2 1\n1 3 3 1\n1 4 6 4 1\n1 5 10 10 5 1\n1 6 15 20 15 6 1\n1 7 21 35 35 21 7 1\n1 8 28 56 70 56 28 8 1\n1 9 36 84 126 126 84 36 9 1\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_c
Problem Statement We have a sequence of length N : A=(a_1,\ldots,a_N) . Additionally, you are given an integer K . You can perform the following operation zero or more times. Choose an integer i such that 1 \leq i \leq N-K , then swap the values of a_i and a_{i+K} . Determine whether it is possible to sort A in ascendi...
[ { "input": "5 2\n3 4 1 3 4\n", "output": "Yes\n" }, { "input": "5 3\n3 4 1 3 4\n", "output": "No\n" }, { "input": "7 5\n1 2 3 4 5 5 10\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_d
Problem Statement You are given an integer N . Find the number of pairs (i,j) of positive integers at most N that satisfy the following condition: i \times j is a square number.
[ { "input": "4\n", "output": "6\n" }, { "input": "254\n", "output": "896\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_e
Problem Statement We have a simple undirected graph with N vertices and M edges. The vertices are numbered 1,\ldots,N . For each i=1,\ldots,M , the i -th edge connects Vertex a_i and Vertex b_i . Additionally, the degree of each vertex is at most 3 . For each i=1,\ldots,Q , answer the following query. Find the sum of i...
[ { "input": "6 5\n2 3\n3 4\n3 5\n5 6\n2 6\n7\n1 1\n2 2\n2 0\n2 3\n4 1\n6 0\n4 3\n", "output": "1\n20\n2\n20\n7\n6\n20\n" } ]
https://atcoder.jp/contests/abc254/tasks/abc254_f
Problem Statement You are given a positive integer N and sequences of N positive integers each: A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_N) . We have an N \times N grid. The square at the i -th row from the top and the j -th column from the left is called the square (i,j) . For each pair of integers (i,j) such that...
[ { "input": "3 5\n3 5 2\n8 1 3\n1 2 2 3\n1 3 1 3\n1 1 1 1\n2 2 2 2\n3 3 1 1\n", "output": "2\n1\n11\n6\n10\n" }, { "input": "1 1\n9\n100\n1 1 1 1\n", "output": "109\n" } ]
https://atcoder.jp/contests/abc254/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/abc254/tasks/abc254_h
Problem Statement You are given multisets with N non-negative integers each: A=\{ a_1,\ldots,a_N \} and B=\{ b_1,\ldots,b_N \} . You can perform the operations below any number of times in any order. Choose a non-negative integer x in A . Delete one instance of x from A and add one instance of 2x instead. Choose a non-...
[ { "input": "3\n3 4 5\n2 4 6\n", "output": "2\n" }, { "input": "1\n0\n1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_a
Problem Statement A hare and a tortoise are in a race. The first to run X meters wins. The hare runs A meters per second, and the tortoise runs B meters per second. However, at \frac{X}{2} meters from the start, the hare stops running and sleeps for C seconds. Then, it wakes up and continues running A meters per second...
[ { "input": "100 5 3 15\n", "output": "Tortoise\n" }, { "input": "240 6 2 80\n", "output": "Tie\n" }, { "input": "10000 100 1 1000\n", "output": "Hare\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_b
Problem Statement You are given a string S consisting of lowercase English letters. Now you will write, for every integer i such that 1 \le i \le |S|-1 , a two-letter string obtained by concatenating the i -th and the (i+1) -th characters of S . Find the string that you will write the most times. If there are multiple...
[ { "input": "abcab\n", "output": "ab\n" }, { "input": "zyxwv\n", "output": "wv\n" }, { "input": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n", "output": "ii\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_c
Problem Statement For integers N and M , let us define S_{N,M} as follows. S_{N,M} is a string of length M consisting of o and x . The k -th character from the beginning of S_{N,M} is o if N^k≤10^9 and x otherwise. Given the integers N and M , print S_{N,M} .
[ { "input": "1000 5\n", "output": "oooxx\n" }, { "input": "2 30\n", "output": "ooooooooooooooooooooooooooooox\n" }, { "input": "31622 30\n", "output": "ooxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_d
Problem Statement We have pairs of lowercase English letters (a_1,b_1),(a_2,b_2),\dots,(a_N,b_N) . Two lowercase English letters u and v are said to be similar if there exists i such that (u,v)=(a_i,b_i) or (u,v)=(b_i,a_i) . Two strings U and V with the same length are said to be similar if U and V satisfy the followin...
[ { "input": "1\nm n\nman\nnan\n", "output": "Yes\n" }, { "input": "1\nm n\nman\nmen\n", "output": "No\n" }, { "input": "3\na b\na e\nd e\nabc\nedc\n", "output": "Yes\n" }, { "input": "1\na b\nxyz\nxyz\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_e
Problem Statement Find the N -th term of the sequence A constructed as follows. Initially, A is empty. For every integer i from 1 through 10^{100} in ascending order, do the following. If i \ge 2 , append i,i-1,\dots,2 in this order to the end of A . Then, append 1,2,\dots,i in this order to the end of A .
[ { "input": "10\n", "output": "4\n" }, { "input": "1\n", "output": "1\n" }, { "input": "123456789012345678\n", "output": "268452372\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_f
Problem Statement Takahashi is playing with a shooter video game. The game screen has a grid with H horizontal rows and W vertical columns. The square at the i -th (1 \leq i \leq H) row from the top and j -th (1 \leq j \leq W) column from the left in the grid is called (i, j) . Each square is either an empty square ...
[ { "input": "3 3\n0 1 0\n1 2 0\n3 4 4\n1\n3 2\n", "output": "0 0 0\n1 1 0\n3 2 4\n" }, { "input": "1 1\n1\n1\n1 1\n", "output": "0\n" }, { "input": "2 3\n18459 0 35959\n150312 573935 612940\n3\n2 3\n1 2\n1 1\n", "output": "0 0 0\n150312 573935 35959\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_g
Problem Statement You are given an undirected graph with N vertices and N-1 edges. The i -th (1 \leq i \leq N-1) edge connects Vertex A_i and Vertex B_i . Determine whether the given graph is a tree.
[ { "input": "4\n1 3\n3 4\n2 3\n", "output": "Yes\n" }, { "input": "4\n1 2\n2 3\n1 3\n", "output": "No\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_h
Problem Statement Takahashi has N snacks. For i = 1, 2, \ldots, N , the i -th snack has a weight of w_i and a tastiness of v_i . Takahashi is going to choose any number (possibly 0 ) of the N snacks to take on tomorrow's school trip. Takahashi has two knapsacks. Every snack he takes on the school trip should fit in ...
[ { "input": "6 8 9\n2 6\n4 1\n5 9\n3 1\n5 3\n5 8\n", "output": "24\n" }, { "input": "20 70 60\n7 94\n18 33\n14 26\n10 1\n9 57\n2 80\n19 74\n16 10\n15 18\n10 38\n13 90\n12 23\n3 3\n8 11\n18 10\n3 42\n3 66\n3 90\n10 2\n5 45\n", "output": "772\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_i
Problem Statement You are given a rectangular grid with H horizontal rows and W vertical columns. The square at the i -th row from the top and the j -th column from the left is called Sqaure (i, j) . Each square is either a "square without a wall" or a "square with a wall". The initial state of Square (i, j) is repre...
[ { "input": "3 3\ns..\n.a.\n..g\n", "output": "5\n" }, { "input": "4 4\ns...\n.a#.\n....\n###g\n", "output": "13\n" }, { "input": "4 4\n...a\n.s..\n..g.\n....\n", "output": "-1\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_j
Problem Statement You eat an apple every Saturday and Sunday. You do not eat one any other day. Given two dates S and T in YYYY-MM-DD format, find the number of apples you eat between S and T (inclusive). Here are some facts that may be useful. January 1 , 2022 is Saturday. The year X is a leap year if and only if one ...
[ { "input": "2022-01-01\n2022-01-08\n", "output": "3\n" }, { "input": "2024-02-26\n2024-03-02\n", "output": "1\n" }, { "input": "2022-01-01\n9999-12-31\n", "output": "832544\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_k
Problem Statement You are given two strings S and T . Find the number of strings that are subsequences of at least one of S and T , modulo 998244353 . Here, a string A is said to be a subsequence of string B when the length of A is at least 1 and A can result from removing zero or more characters from B . For example, ...
[ { "input": "abc\nbca\n", "output": "10\n" }, { "input": "aa\naaaaa\n", "output": "5\n" }, { "input": "xzyyzxxzyy\nyzxyzyxzyx\n", "output": "758\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_l
Problem Statement You are given strings S and T consisting of lowercase English letters. You can do the following operation between 0 and K times: choose one of the characters of S and replace it with any lowercase English letter. What is the length of the longest possible string that is a subsequence of S after the r...
[ { "input": "strength\nslang\n1\n", "output": "4\n" }, { "input": "asdbvaklwebjkalhakslhgweqwbq\nobqweogkmawgjkoanboebeoqejkazxcnmvqse\n10\n", "output": "19\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_m
Problem Statement Takahashi and Aoki will play a match where the first to win N games wins. The two players are equally skilled, and each of them wins a game with probability \frac{1}{2} , independently of the outcomes of the other games. There are no draws. A reversal is said to occur when the player with more wins ch...
[ { "input": "2\n", "output": "748683265\n" }, { "input": "4\n", "output": "405536769\n" }, { "input": "621998\n", "output": "76706976\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_n
Problem Statement There is a grid with H horizontal rows and W vertical columns. The square at the i -th row from the top and the j -th column from the left is called (i, j) . The state of each square is either an "empty square" or a "square with a wall". Initially, every square is an empty square. Ms. A wants to tr...
[ { "input": "2 3\n0 6 4\n2 3 0\n", "output": "7\n..#\n.#.\n" }, { "input": "4 3\n0 9 2\n9 3 9\n2 3 9\n3 9 0\n", "output": "7\n..#\n.#.\n#..\n...\n" }, { "input": "2 2\n0 1000000000\n1000000000 0\n", "output": "2000000000\n.#\n#.\n" } ]
https://atcoder.jp/contests/past202206-open/tasks/past202206_o
Problem Statement There is a coordinate plane P . Consider performing operations of plotting points in this plane and deleting them. Initially, no points are plotted in P . Process a total of Q queries in the following forms in the given order. + x y Plot a point at (x,y) in P . - x y Delete a point plotted at (x,y) in...
[ { "input": "5\n+ 2 3\n+ -1 2\n+ 1 -2\n- -1 2\n+ -1 -1\n", "output": "0\n7\n14\n7\n11\n" }, { "input": "10\n+ 100000 100000\n+ 100000 -100000\n+ 100000 100000\n+ 100000 -100000\n+ 100000 100000\n- 100000 100000\n- 100000 -100000\n- 100000 100000\n- 100000 -100000\n- 100000 100000\n", "output": "0...
https://atcoder.jp/contests/arc141/tasks/arc141_a
Problem Statement For a positive integer n , let \mathrm{str}(n) be the string representing n in decimal. We say that a positive integer n is periodic when there exists a positive integer m such that \mathrm{str}(n) is the concatenation of two or more copies of \mathrm{str}(m) . For example, 11 , 1212 , and 123123123 a...
[ { "input": "3\n1412\n23\n498650499498649123\n", "output": "1313\n22\n498650498650498650\n" } ]
https://atcoder.jp/contests/arc141/tasks/arc141_b
Problem Statement You are given positive integers N and M . Find the number of sequences A=(A_1,\ A_2,\ \dots,\ A_N) of N positive integers that satisfy the following conditions, modulo 998244353 . 1 \leq A_1 < A_2 < \dots < A_N \leq M . B_1 < B_2 < \dots < B_N , where B_i = A_1 \oplus A_2 \oplus \dots \oplus A_i . Her...
[ { "input": "2 4\n", "output": "5\n" }, { "input": "4 4\n", "output": "0\n" }, { "input": "10 123456789\n", "output": "205695670\n" } ]
https://atcoder.jp/contests/arc141/tasks/arc141_c
Problem Statement A string of length 2N , S=S_1S_2\dots S_{2N} , is said to be a parenthesis sequence when S is composed of N ( s and N ) s. Additionally, a parenthesis sequence S is said to be correct when it is one of the following. An empty string. The concatenation of ( , A , ) in this order, where A is a correct p...
[ { "input": "2\n1 2 4 3\n4 3 1 2\n", "output": "())(\n" }, { "input": "2\n1 3 2 4\n4 3 2 1\n", "output": "-1\n" }, { "input": "3\n2 1 5 3 4 6\n6 5 3 4 2 1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/arc141/tasks/arc141_d
Problem Statement We say that a set S of positive integers is good when, for any a,\ b \in S\ (a\neq b) , b is not a multiple of a . You are given a set of N integers between 1 and 2M (inclusive): S=\lbrace A_1,\ A_2,\ \dots,\ A_N\rbrace . For each i=1,\ 2,\ \dots,\ N , determine whether there exists a good set with M ...
[ { "input": "5 3\n1 2 3 4 5\n", "output": "No\nYes\nYes\nYes\nYes\n" }, { "input": "4 4\n2 4 6 8\n", "output": "No\nNo\nNo\nNo\n" }, { "input": "13 10\n2 3 4 6 7 9 10 11 13 15 17 19 20\n", "output": "No\nNo\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo\n" } ]
https://atcoder.jp/contests/arc141/tasks/arc141_e
Problem Statement There is an undirected graph with N^2 vertices. Initially, it has no edges. For each pair of integers (i,\ j) such that 0 \leq i,\ j < N , the graph has a corresponding vertex called (i,\ j) . You will get Q queries, which should be processed in order. The i -th query, which gives you four integers a_...
[ { "input": "3 3\n0 0 1 2\n2 0 0 0\n1 1 2 2\n", "output": "6\n4\n4\n" }, { "input": "4 3\n0 0 2 2\n2 3 1 2\n1 1 3 3\n", "output": "14\n11\n11\n" }, { "input": "6 5\n0 0 1 1\n1 2 3 4\n1 1 5 3\n2 0 1 5\n5 0 3 3\n", "output": "31\n27\n21\n21\n19\n" } ]
https://atcoder.jp/contests/arc141/tasks/arc141_f
Problem Statement You are given N srings S_i\ (1\le i \le N) consisting of A , B , C , D . Consider the operation below on a string T consisting of A , B , C , D . Repeat the following until T contains none of the strings S_i as a substring. Choose an S_i and one of its occurrences in T , remove that occurrence from T ...
[ { "input": "3\nA\nB\nC\n", "output": "No\n" }, { "input": "1\nABA\n", "output": "Yes\n" }, { "input": "4\nCBA\nACB\nAD\nCAB\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_a
Problem Statement Given integers a , b , and c , determine if b is the median of these integers.
[ { "input": "5 3 2\n", "output": "Yes\n" }, { "input": "2 5 3\n", "output": "No\n" }, { "input": "100 100 100\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_b
Problem Statement There is a grid with H horizontal rows and W vertical columns, in which two distinct squares have a piece. The state of the squares is represented by H strings S_1, \dots, S_H of length W . S_{i, j} = o means that there is a piece in the square at the i -th row from the top and j -th column from the l...
[ { "input": "2 3\n--o\no--\n", "output": "3\n" }, { "input": "5 4\n-o--\n----\n----\n----\n-o--\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_c
Problem Statement We have a multiset of integers S , which is initially empty. Given Q queries, process them in order. Each query is of one of the following types. 1 x : Insert an x into S . 2 x c : Remove an x from S m times, where m = \mathrm{min}(c,( the number of x 's contained in S)) . 3 : Print ( maximum value o...
[ { "input": "8\n1 3\n1 2\n3\n1 2\n1 7\n3\n2 2 3\n3\n", "output": "1\n5\n4\n" }, { "input": "4\n1 10000\n1 1000\n2 100 3\n1 10\n", "output": "\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_d
Problem Statement Find the sum of integers between 1 and N (inclusive) that are not multiples of A or B .
[ { "input": "10 3 5\n", "output": "22\n" }, { "input": "1000000000 314 159\n", "output": "495273003954006262\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_e
Problem Statement How many integer sequences A=(A_1,\ldots,A_N) of length N satisfy all the conditions below? 1\le A_i \le M (1 \le i \le N) |A_i - A_{i+1}| \geq K (1 \le i \le N - 1) Since the count can be enormous, find it modulo 998244353 .
[ { "input": "2 3 1\n", "output": "6\n" }, { "input": "3 3 2\n", "output": "2\n" }, { "input": "100 1000 500\n", "output": "657064711\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_f
Problem Statement We have an N \times M matrix, whose elements are initially all 0 . Process Q given queries. Each query is in one of the following formats. 1 l r x : Add x to every element in the l -th, (l+1) -th, \ldots , and r -th column. 2 i x : Replace every element in the i -th row with x . 3 i j : Print the (i,...
[ { "input": "3 3 9\n1 1 2 1\n3 2 2\n2 3 2\n3 3 3\n3 3 1\n1 2 3 3\n3 3 2\n3 2 3\n3 1 2\n", "output": "1\n2\n2\n5\n3\n4\n" }, { "input": "1 1 10\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000...
https://atcoder.jp/contests/abc253/tasks/abc253_g
Problem Statement For an integer N greater than or equal to 2 , there are \frac{N(N - 1)}{2} pairs of integers (x, y) such that 1 \leq x \lt y \leq N . Consider the sequence of these pairs sorted in the increasing lexicographical order. Let (x_1, y_1), \dots, (x_{R - L + 1}, y_{R - L + 1}) be its L -th, (L+1) -th, \ld...
[ { "input": "5 3 6\n", "output": "5 1 2 3 4\n" }, { "input": "10 12 36\n", "output": "1 10 9 8 7 4 3 2 5 6\n" } ]
https://atcoder.jp/contests/abc253/tasks/abc253_h
Problem Statement We have a graph G with N vertices numbered 1 through N and 0 edges. You are given sequences u=(u_1,u_2,\ldots,u_M),v=(v_1,v_2,\ldots,v_M) of length M . You will perform the following operation (N-1) times. Choose i (1 \leq i \leq M) uniformly at random. Add to G an undirected edge connecting Vertice...
[ { "input": "3 2\n1 2\n2 3\n", "output": "1\n499122177\n" }, { "input": "4 5\n1 2\n1 2\n1 4\n2 3\n2 4\n", "output": "1\n758665709\n918384805\n" } ]