url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/ahc011/tasks/ahc011_a
Problem Statement There are N^2-1 tiles on an N \times N board. Let (i, j) denote the coordinates of row i (0\leq i \leq N-1) from the top and column j (0\leq j\leq N-1) from the left. Each tile contains a figure with lines from its center towards one or more of four directions: up, down, left, and right. We represe...
[ { "input": "6 432\n62ce43\na068f9\na89da9\n5d93cb\n276253\n424ba8\n", "output": "RRRDLUULDDDDLUUUR\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_a
Problem Statement The ASCII values of the lowercase English letters a , b , \ldots , z are 97,98,\ldots,122 in this order. Given an integer N between 97 and 122 , print the letter whose ASCII value is N .
[ { "input": "97\n", "output": "a\n" }, { "input": "122\n", "output": "z\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_b
Problem Statement Takahashi has N foods in his house. The i -th food has the tastiness of A_i . He dislikes K of these foods: for each i=1,2,\ldots,K , he dislikes the B_i -th food. Out of the foods with the greatest tastiness among the N foods, Takahashi will randomly choose one and eat it. If he has a chance to eat s...
[ { "input": "5 3\n6 8 10 7 10\n2 3 4\n", "output": "Yes\n" }, { "input": "5 2\n100 100 100 1 1\n5 4\n", "output": "No\n" }, { "input": "2 1\n100 1\n2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_c
Problem Statement There is a slot machine with N reels. The placement of symbols on the i -th reel is represented by a string S_i of length 10 containing each of 0 , 1 , \ldots , 9 exactly once. Each reel has a corresponding button. For each non-negative integer t , Takahashi can press one of the buttons of his choice ...
[ { "input": "3\n1937458062\n8124690357\n2385760149\n", "output": "6\n" }, { "input": "5\n0123456789\n0123456789\n0123456789\n0123456789\n0123456789\n", "output": "40\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_d
Problem Statement You are given a sequence of length N : A=(A_1,A_2,\ldots,A_N) . Find the number of triples (i,j,k) that satisfy both of the following conditions. 1\leq i \lt j \lt k \leq N A_i , A_j , and A_k are distinct.
[ { "input": "4\n3 1 4 1\n", "output": "2\n" }, { "input": "10\n99999 99998 99997 99996 99995 99994 99993 99992 99991 99990\n", "output": "120\n" }, { "input": "15\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9\n", "output": "355\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_e
Problem Statement The Kingdom of AtCoder has N cities called City 1,2,\ldots,N and M roads called Road 1,2,\ldots,M . Road i connects Cities A_i and B_i bidirectionally and has a length of C_i . One can travel between any two cities using some roads. Under financial difficulties, the kingdom has decided to maintain onl...
[ { "input": "3 3\n1 2 1\n2 3 2\n1 3 10\n", "output": "1 2\n" }, { "input": "4 6\n1 2 1\n1 3 1\n1 4 1\n2 3 1\n2 4 1\n3 4 1\n", "output": "3 1 2\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_f
Problem Statement We have a loaf of bread of length L , which we will cut and distribute to N children. The i -th child (1\leq i\leq N) wants a loaf of length A_i . Now, Takahashi will repeat the operation below to cut the loaf into lengths A_1, A_2, \ldots, A_N for the children. Choose a loaf of length k and an intege...
[ { "input": "5 7\n1 2 1 2 1\n", "output": "16\n" }, { "input": "3 1000000000000000\n1000000000 1000000000 1000000000\n", "output": "1000005000000000\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_g
Problem Statement There is a rooted tree with N vertices called Vertex 1 , 2 , \ldots , N , rooted at Vertex 1 . We performed a depth-first search starting at the root and obtained a preorder traversal of the tree: P_1, P_2, \ldots, P_N . During the search, when the current vertex had multiple children, we chose the un...
[ { "input": "4\n1 2 4 3\n", "output": "3\n" }, { "input": "8\n1 2 3 5 6 7 8 4\n", "output": "202\n" } ]
https://atcoder.jp/contests/abc252/tasks/abc252_h
Problem Statement We have N gemstones. The color and beauty of the i -th gemstone are D_i and V_i , respectively. Here, the color of each gemstone is one of 1, 2, \ldots, C , and there is at least one gemstone of each color. Out of the N gemstones, we will choose C with distinct colors and use them to make a necklace. ...
[ { "input": "4 2 3\n2 4\n2 6\n1 2\n1 3\n", "output": "5\n" }, { "input": "3 1 2\n1 0\n1 0\n1 0\n", "output": "0\n" }, { "input": "10 3 11\n1 414213562373095048\n1 732050807568877293\n2 236067977499789696\n2 449489742783178098\n2 645751311064590590\n2 828427124746190097\n3 1622776601683793...
https://atcoder.jp/contests/arc140/tasks/arc140_a
Problem Statement For a string T consisting of lowercase English letters, consider the question below, and let f(T) be the answer. Find the number of different strings obtained by performing the following operation any number of times: delete the first character from T and append it to the end. You are given a string S...
[ { "input": "4 1\nabac\n", "output": "2\n" }, { "input": "10 0\naaaaaaaaaa\n", "output": "1\n" }, { "input": "6 1\nabcaba\n", "output": "3\n" } ]
https://atcoder.jp/contests/arc140/tasks/arc140_b
Problem Statement You are given a string S of length N consisting of A , R , C . As long as S contains three consecutive characters that are ARC , you can perform the operation below. In an odd-numbered ( 1 -st, 3 -rd, 5 -th, ...) operation, choose in S three consecutive characters that are ARC , and replace them with ...
[ { "input": "6\nAARCCC\n", "output": "2\n" }, { "input": "5\nAAAAA\n", "output": "0\n" }, { "input": "9\nARCARCARC\n", "output": "3\n" } ]
https://atcoder.jp/contests/arc140/tasks/arc140_c
Problem Statement The happiness of a permutation P=(P_1,P_2,\ldots,P_N) of (1,\dots,N) is defined as follows. Let A=(A_1,A_2,\ldots,A_{N-1}) be a sequence of length N-1 with A_i = |P_i-P_{i+1}|(1\leq i \leq N-1) . The happiness of P is the length of a longest strictly increasing subsequence of A . Print a permutation P...
[ { "input": "3 2\n", "output": "2 1 3\n" }, { "input": "3 1\n", "output": "1 2 3\n" } ]
https://atcoder.jp/contests/arc140/tasks/arc140_d
Problem Statement For an integer sequence X=(X_1,X_2,\dots,X_N) of length N whose elements are all between 1 and N (inclusive), consider the question below, and let f(X) be the answer. There is an undirected graph G with N vertices (and possibly multi-edges and self-loops). G has N edges, the i -th of which connects Ve...
[ { "input": "3\n-1 1 3\n", "output": "5\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "8\n-1 3 -1 -1 8 -1 -1 -1\n", "output": "433760\n" } ]
https://atcoder.jp/contests/arc140/tasks/arc140_e
Problem Statement We have a grid with N \times M squares. You will fill every square with an integer between 1 and 25 (inclusive). Let a_{i,j} be the integer to be written in the square at the i -th row from the top and j -th column from the left. Find a way to fill the squares to satisfy the condition below. It can be...
[ { "input": "2 3\n", "output": "1 1 1\n1 2 3\n" } ]
https://atcoder.jp/contests/arc140/tasks/arc140_f
Problem Statement Find the number of permutations P=(P_1,P_2,\dots,P_N) of (1,2,\dots,N) that satisfy the following, modulo 998244353 , for each K=0,1,2,\dots,N-1 . There are exactly K integers i such that 1 \le i \le N-1 and |P_i - P_{i+1}|=M .
[ { "input": "3 1\n", "output": "0 4 2 \n" }, { "input": "4 3\n", "output": "12 12 0 0 \n" }, { "input": "10 5\n", "output": "1263360 1401600 710400 211200 38400 3840 0 0 0 0 \n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_a
Problem Statement You are given a string S consisting of lowercase English characters. The length of S is between 1 and 3 , inclusive. Print the string of length 6 that is a repetition of S . It can be shown that there uniquely exists such a string under the Constraints of this problem.
[ { "input": "abc\n", "output": "abcabc\n" }, { "input": "zz\n", "output": "zzzzzz\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_b
Problem Statement There are N weights called Weight 1 , Weight 2 , \dots , Weight N . Weight i has a mass of A_i . Let us say a positive integer n is a good integer if the following condition is satisfied: We can choose at most 3 different weights so that they have a total mass of n . How many positive integers less t...
[ { "input": "2 10\n1 3\n", "output": "3\n" }, { "input": "2 1\n2 3\n", "output": "0\n" }, { "input": "4 12\n3 3 3 3\n", "output": "3\n" }, { "input": "7 251\n202 20 5 1 4 2 100\n", "output": "48\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_c
Problem Statement Poem Online Judge (POJ) is an online judge that gives scores to submitted strings. There were N submissions to POJ. In the i -th earliest submission, string S_i was submitted, and a score of T_i was given. (The same string may have been submitted multiple times.) Note that POJ may not necessarily gi...
[ { "input": "3\naaa 10\nbbb 20\naaa 30\n", "output": "2\n" }, { "input": "5\naaa 9\nbbb 10\nccc 10\nddd 10\nbbb 11\n", "output": "2\n" }, { "input": "10\nbb 3\nba 1\naa 4\nbb 1\nba 5\naa 9\naa 2\nab 6\nbb 5\nab 3\n", "output": "8\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_d
Problem Statement You are given an integer W . You are going to prepare some weights so that all of the conditions below are satisfied. The number of weights is between 1 and 300 , inclusive. Each weight has a mass of positive integer not exceeding 10^6 . Every integer between 1 and W , inclusive, is a good integer . ...
[ { "input": "6\n", "output": "3\n1 2 3\n" }, { "input": "12\n", "output": "6\n2 5 1 2 5 1\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_e
Problem Statement Takahashi is with N animals. The N animals are called Animal 1 , Animal 2 , \ldots , Animal N . Takahashi will perform the following N kinds of action. Each action can be performed any number of (possibly zero) times. Pay A_1 yen (the currency in Japan) to feed Animals 1 and 2 . Pay A_2 yen to feed ...
[ { "input": "5\n2 5 3 2 5\n", "output": "7\n" }, { "input": "20\n29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62\n", "output": "426\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_f
Problem Statement You are given an undirected graph G with N vertices and M edges. G is simple (it has no self-loops and multiple edges) and connected . For i = 1, 2, \ldots, M , the i -th edge is an undirected edge \lbrace u_i, v_i \rbrace connecting Vertices u_i and v_i . Construct two spanning trees T_1 and T_2 of G...
[ { "input": "6 8\n5 1\n4 3\n1 4\n3 5\n1 2\n2 6\n1 6\n4 2\n", "output": "1 4\n4 3\n5 3\n4 2\n6 2\n1 5\n5 3\n1 4\n2 1\n1 6\n" }, { "input": "4 3\n3 1\n1 2\n1 4\n", "output": "1 2\n1 3\n1 4\n1 4\n1 3\n1 2\n" } ]
https://atcoder.jp/contests/abc251/tasks/abc251_g
Problem Statement The vertices of a convex N -gon P in an xy -plane are given as (x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N) in the counterclockwise order. (Here, the positive direction of the x -axis is right, and the positive direction of the y -axis is up.) Based on this polygon P , we consider M convex N -gons P_1,...
[ { "input": "5\n-2 -3\n0 -2\n1 0\n0 2\n-2 1\n2\n0 1\n1 0\n6\n0 0\n1 0\n0 1\n1 1\n-1 -1\n-1 -2\n", "output": "Yes\nNo\nYes\nYes\nYes\nNo\n" }, { "input": "10\n45 100\n-60 98\n-95 62\n-95 28\n-78 -41\n-54 -92\n-8 -99\n87 -94\n98 23\n87 91\n5\n-57 -40\n-21 -67\n25 39\n-30 25\n39 -20\n16\n4 5\n-34 -8\n-6...
https://atcoder.jp/contests/abc251/tasks/abc251_h
Problem Statement Blocks are stacked in a triangle. The i -th column from the top has i blocks. You are given a sequence P = ((a_1, c_1), (a_2, c_2), ..., (a_M, c_M)) which is a result of the run-length compression of a sequence A = (A_1, A_2, ..., A_N) consisting of non-negative integers less than or equal to 6 . For...
[ { "input": "6 3 4\n2 3\n5 2\n1 1\n", "output": "1 4 3 2\n" }, { "input": "1 1 1\n6 1\n", "output": "6\n" }, { "input": "111111111 9 9\n0 1\n1 10\n2 100\n3 1000\n4 10000\n5 100000\n6 1000000\n0 10000000\n1 100000000\n", "output": "1 0 4 2 5 5 5 6 3\n" } ]
https://atcoder.jp/contests/abc250/tasks/abc250_a
Problem Statement There is 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 the j -th column from the left. Find the number of squares that share a side with Square (R, C) . Here, two squares (a,b) and (c,d) are said to share a side if and only if |a-c|...
[ { "input": "3 4\n2 2\n", "output": "4\n" }, { "input": "3 4\n1 3\n", "output": "3\n" }, { "input": "3 4\n3 4\n", "output": "2\n" }, { "input": "1 10\n1 5\n", "output": "2\n" }, { "input": "8 1\n8 1\n", "output": "1\n" }, { "input": "1 1\n1 1\n", "o...
https://atcoder.jp/contests/abc250/tasks/abc250_b
Problem Statement Tiles are aligned in N horizontal rows and N vertical columns. Each tile has a grid with A horizontal rows and B vertical columns. On the whole, the tiles form a grid X with (A\times N) horizontal rows and (B\times N) vertical columns. For 1\leq i,j \leq N , Tile (i,j) denotes the tile at the i -th ...
[ { "input": "4 3 2\n", "output": "..##..##\n..##..##\n..##..##\n##..##..\n##..##..\n##..##..\n..##..##\n..##..##\n..##..##\n##..##..\n##..##..\n##..##..\n" }, { "input": "5 1 5\n", "output": ".....#####.....#####.....\n#####.....#####.....#####\n.....#####.....#####.....\n#####.....#####.....####...
https://atcoder.jp/contests/abc250/tasks/abc250_c
Problem Statement N balls are lined up in a row from left to right. Initially, the i -th ( 1 \leq i \leq N ) ball from the left has an integer i written on it. Takahashi has performed Q operations. The i -th ( 1 \leq i \leq Q ) operation was as follows. Swap the ball with the integer x_i written on it with the next b...
[ { "input": "5 5\n1\n2\n3\n4\n5\n", "output": "1 2 3 5 4\n" }, { "input": "7 7\n7\n7\n7\n7\n7\n7\n7\n", "output": "1 2 3 4 5 7 6\n" }, { "input": "10 6\n1\n5\n2\n9\n6\n6\n", "output": "1 2 3 4 5 7 6 8 10 9\n" } ]
https://atcoder.jp/contests/abc250/tasks/abc250_d
Problem Statement Let us regard an integer k as "similar to 250 " if the following condition is satisfied: k is represented as k=p \times q^3 with primes p<q . How many integers less than or equal to N are "similar to 250 "?
[ { "input": "250\n", "output": "2\n" }, { "input": "1\n", "output": "0\n" }, { "input": "123456789012345\n", "output": "226863\n" } ]
https://atcoder.jp/contests/abc250/tasks/abc250_e
Problem Statement You are given integer sequences A = (a_1,\ldots,a_N) and B = (b_1,\ldots,b_N) , each of length N . For i=1,...,Q , answer the query in the following format. If the set of values contained in the first x_i terms of A , (a_1,\ldots,a_{x_i}) , and the set of values contained in the first y_i terms of B ,...
[ { "input": "5\n1 2 3 4 5\n1 2 2 4 3\n7\n1 1\n2 2\n2 3\n3 3\n4 4\n4 5\n5 5\n", "output": "Yes\nYes\nYes\nNo\nNo\nYes\nNo\n" } ]
https://atcoder.jp/contests/abc250/tasks/abc250_f
Problem Statement ABC 250 is a commemorable quarter milestone for Takahashi, who aims to hold ABC 1000, so he is going to celebrate this contest by eating as close to 1/4 of a pizza he bought as possible. The pizza that Takahashi bought has a planar shape of convex N -gon. When the pizza is placed on an xy -plane, th...
[ { "input": "5\n3 0\n2 3\n-1 3\n-3 1\n-1 -1\n", "output": "1\n" }, { "input": "4\n400000000 400000000\n-400000000 400000000\n-400000000 -400000000\n400000000 -400000000\n", "output": "1280000000000000000\n" }, { "input": "6\n-816 222\n-801 -757\n-165 -411\n733 131\n835 711\n-374 979\n", ...
https://atcoder.jp/contests/abc250/tasks/abc250_g
Problem Statement You are going to trade stocks of Company X for the next N days. As a precognitive, you know that the stock price on the i -th day of trading will be P_i yen (the currency in Japan) per unit. Every day, you can choose to do exactly one of the following. Buy one unit of stock for P_i yen. You will obtai...
[ { "input": "8\n2 5 4 3 7 1 8 6\n", "output": "16\n" }, { "input": "5\n10000 1000 100 10 1\n", "output": "0\n" }, { "input": "15\n300 1 4000 1 50000 900000000 20 600000 50000 300 50000 80000000 900000000 7000000 900000000\n", "output": "2787595378\n" } ]
https://atcoder.jp/contests/abc250/tasks/abc250_h
Problem Statement There are N points numbered 1 through N , and M roads. The i -th ( 1 \leq i \leq M ) road connects Point a_i and Point b_i bidirectionally and requires c_i minutes to pass through. One can travel from any point to any other point using some number of roads. There is a house on Points 1,\ldots, K . ...
[ { "input": "6 6 3\n1 4 1\n4 6 4\n2 5 2\n3 5 3\n5 6 5\n1 2 15\n3\n2 3 4\n2 3 5\n1 3 12\n", "output": "No\nYes\nYes\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_a
Problem Statement A set A of positive integers is said to be good when it satisfies the following condition. For any two distinct elements a, b \in A , the string representing a in base ten is not a substring of the string representing b in base ten. What is a substring? A substring of a string is its contiguous subseq...
[ { "input": "3\n3 8\n3 18\n1 1000\n", "output": "6\n10\n900\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_b
Problem Statement You are given a sequence A = (A_1, A_2, \ldots, A_N) of positive integers and a positive integer X . You can perform the operation below any number of times, possibly zero: Choose an index i ( 1\leq i\leq N ) and a non-negative integer x such that 0\leq x\leq X . Change A_i to 2A_i+x . Find the small...
[ { "input": "4 2\n5 8 12 20\n", "output": "6\n" }, { "input": "4 5\n24 25 26 27\n", "output": "0\n" }, { "input": "4 1\n24 25 26 27\n", "output": "3\n" }, { "input": "10 5\n39 23 3 7 16 19 40 16 33 6\n", "output": "13\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_c
Problem Statement You are given a positive integer N and a sequence A = (A_0, A_1, \ldots, A_{2^N-1}) of 2^N terms, where each A_i is an integer between 0 and 2^N-1 (inclusive) and A_i\neq A_j holds if i\neq j . You can perform the following two kinds of operations on A : Operation + : For every i , change A_i to (A_i ...
[ { "input": "3\n5 0 3 6 1 4 7 2\n", "output": "Yes\n4\n-1 6 -1 1\n" }, { "input": "3\n2 5 4 3 6 1 0 7\n", "output": "No\n" }, { "input": "3\n0 1 2 3 4 5 6 7\n", "output": "Yes\n0\n\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_d
Problem Statement You are given positive integers S and K . A sequence of positive integers A = (A_1, A_2, \ldots, A_N) is said to be a good sequence when satisfying the following two conditions. 1\leq A_1 < A_2 < \cdots < A_N \leq S - 1 holds. \sum_{i=1}^NA_ix_i\neq S holds for any sequence of non-negative integers (x...
[ { "input": "13\n3 1\n3 2\n7 1\n7 2\n7 3\n7 4\n10 1\n10 2\n10 3\n10 4\n10 5\n2022 507\n1000000000000000000 999999999999999999\n", "output": "2\n-1\n2\n4\n6\n-1\n3\n6\n8\n9\n-1\n1351\n-1\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_e
Problem Statement Consider the following operations on an H\times W matrix A = (A_{i,j}) ( 1\leq i\leq H, 1\leq j\leq W ). Row-sort : Sort every row in ascending order. That is, sort A_{i,1},\ldots,A_{i,W} in ascending order for every i . Column-sort : Sort every column in ascending order. That is, sort A_{1,j},\ldots,...
[ { "input": "2 2\n0 0\n1 2\n", "output": "4\n" }, { "input": "3 3\n0 1 3\n2 4 7\n5 6 8\n", "output": "576\n" }, { "input": "3 5\n0 0 0 1 1\n0 0 1 1 2\n0 1 1 2 2\n", "output": "10440\n" }, { "input": "1 7\n2 3 3 6 8 8 9\n", "output": "1260\n" } ]
https://atcoder.jp/contests/agc057/tasks/agc057_f
Problem Statement There are three indistinguishable stones at integer coordinates on a number line. Consider the following operation on these stones: Let A, B, C be the three stones in ascending order of coordinate (ties broken arbitrarily). Perform one of the following. Move A to the symmetric position with respect to...
[ { "input": "6\n1 3 5\n-2 -2 5\n0 1 3\n31 41 59\n-123456789 0 987654321\n-1000000000000000000 0 1000000000000000000\n", "output": "5\n2\n9\n70\n182333351\n5\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_a
問題文 長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) のうち、 B_i=(A_i+K)\bmod M と定義される数列 B が A の並び替えになっているようなものは存在しますか?
[ { "input": "15\n6 9\n", "output": "Yes\n" }, { "input": "2\n5 7\n", "output": "No\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_b
問題文 長さ N の整数列 A,B が与えられます。 1 \le l \le r \le N を満たす整数の組 (l,r) に対する (\max_{l \le i \le r} A_i) \times (\min_{l \le i \le r} B_i) の最小値を求めてください。
[ { "input": "3\n3 4 8\n4 2 5\n", "output": "8\n" }, { "input": "3\n-3 -5 8\n4 2 -5\n", "output": "-40\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_c
問題文 kentand君は爆弾処理をします。 H×W のマス目があり、上から i \lparen 1 \le i \le H \rparen 行目、左から j \lparen 1 \le j \le W \rparen 列目のマス \lparen i,j\rparen は G_{i,j} が # のとき壁で、 . のとき道です。 マス目上の道に爆弾が N 個あり、 k \lparen 1 \le k \le N \rparen 個目の爆弾はマス \lparen C_k, D_k \rparen にあります。 kentand君は時刻 0 にマス \lparen 1,1 \rparen におり、 1 単位時間ごとに、今いるマスに上下左...
[ { "input": "3 3 2\n1 3 2 5\n3 2 3 4\n.#.\n...\n#.#\n", "output": "1\n" }, { "input": "1 2 1\n1 2 1000000000 1000000000\n..\n", "output": "0\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_d
問題文 この問題はインタラクティブな問題です。 KoD 君は N 頂点の単純無向グラフを持っており、頂点には 1 から N の番号が付けられています。このグラフは連結とは限りません。 あなたの目標は、KoD 君が持っているグラフに閉路が存在するかどうか判定することです。そのために、以下の質問を行うことができます。 頂点集合を指定し、両端がその集合に属するような辺が何本あるかを聞く。 4500 回以下の質問回数で判定してください。
[]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_e
問題文 N 頂点の完全グラフがあります。頂点 i と頂点 j を結ぶ辺の長さは \min(|A_i-A_j|,|B_i-B_j|) です。 頂点 1 を出発し、頂点 2 から N をそれぞれ 1 回ずつ通り、頂点 1 に帰ってくるサイクル全てについて、サイクルの長さの総和を 998244353 で割った余りを求めてください。
[ { "input": "3\n1 2\n3 5\n4 2\n", "output": "6\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_f
問題文 N 個の給水機と 1 つの空のコップがあります。PCT 君はこのコップにできるだけ多くの水を入れたいです。 給水機 i\,(1 \leq i \leq N) は時刻 S_i から時刻 T_i のみ使えます。また、 1 秒あたりの給水量は A_i リットルで、蓄えている水の量は A_i\times B_i リットルです。つまり、合計 B_i 秒よりも長く給水することはできません。 適切に行動すると最大で何リットルの水をコップに入れることができますか?ただし、同時に 2 つ以上の給水機からコップに水を入れることはできません。
[ { "input": "3\n1 6 1 2\n2 4 3 1\n2 4 2 1\n", "output": "7\n" }, { "input": "1\n1 100 100 3\n", "output": "300\n" }, { "input": "4\n1 3 4 5\n1 4 3 4\n3 4 5 2\n4 6 2 2\n", "output": "17\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_g
問題文 長さ N の正整数列 A = (A_1, \dots, A_N), B = (B_1, \dots, B_N) が与えられます。 k = 1, \dots, M について、以下の条件を全て満たす正整数列 C = (C_1, \dots, C_N) の総数を 998244353 で割った余りを求めてください。 A_i \leq C_i \leq B_i \, (1 \leq i \leq N) \mathrm{gcd} (C_1, \dots, C_N) = k
[ { "input": "3 10\n1 9\n4 8\n7 10\n", "output": "151\n20\n3\n3\n1\n0\n1\n1\n0\n0\n" }, { "input": "1 1\n2 100000\n", "output": "0\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_h
問題文 N 頂点 M 辺の単純連結無向グラフが与えられます。 i \, (1 \leq i \leq M) 本目の辺は頂点 A_i, B_i を結びます。 1 \leq s \lt t \leq N を満たす整数の組 (s, t) に対し、以下の値を f(s, t) とおきます。 頂点 s を出発し、頂点 t に到達した後頂点 s に戻ってくるような経路における、 s 以外の頂点のうち 2 回以上通るものの個数の最小値 \displaystyle \sum_{s = 1}^{N - 1} \sum_{t = s + 1}^N f(s, t) を求めてください。
[ { "input": "4 4\n1 2\n2 3\n1 3\n3 4\n", "output": "2\n" }, { "input": "2 1\n1 2\n", "output": "0\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_i
問題文 長さ N の正整数列 A = (A_1, \dots, A_N) と N の正の約数 K が与えられます。 (1, 2,\dots, N) を並べ替えて得られる数列 P に対し、以下のように P の スコア を定めます。 i = 1, \dots, N に対し、 B_i = A_{P_i} と定める。 i = 1, \dots, \frac{N}{K} に対し、 G_i = \gcd(B_{(i - 1)K + 1}, B_{(i - 1)K + 2} \dots, B_{iK}) と定める。 \mathrm{lcm}(G_1, \dots, G_{\frac{N}{K}}) が P のスコアである。 P としてあり得るもの...
[ { "input": "4 2\n1 2 3 4\n", "output": "256\n" }, { "input": "9 3\n12 6 8 9 10 16 4 18 15\n", "output": "822906664\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_j
問題文 11 個の整数 c_0, \dots, c_{10} が与えられます。 f(x) = \sum_{n = 0}^{10} c_n x^n と定めます。 以下の条件を全て満たす整数列 A, B が存在するか判定し、存在するならばその一例を示してください。 A, B の長さは 1 以上 5000 以下 |A_i| \leq 5000 \, (1 \leq i \leq |A|) |B_i| \leq 5000 \, (1 \leq i \leq |B|) A_i \neq A_j \, (1 \leq i \lt j \leq |A|) B_i \neq B_j \, (1 \leq i \lt j \leq |B|) A_i ...
[ { "input": "5 -1 2 0 0 0 0 0 0 0 0\n", "output": "2 0 1\n1 2\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_k
問題文 NPCA 美術館では、東西方向にまっすぐに伸びる廊下に N 枚の絵が飾られています。絵 i (1\leq i\leq N) は廊下の西端から X_i メートルの位置に飾られており、その価値は V_i です。 館長の PCT 君は以下の条件を満たすように N-M 枚の絵を取り外し、 M 枚の絵だけを残すことにしました。 どの 2 つの絵についても、位置が D メートル以上離れている。 残った絵の価値の総和の最大値を求めてください。
[ { "input": "4 2 3\n0 2 4 5\n5 1 -4 3\n", "output": "8\n" }, { "input": "4 3 2\n0 1 2 3\n1 1 1 1\n", "output": "impossible\n" }, { "input": "5 2 4\n0 3 5 6 9\n-4 -8 3 -10 -6\n", "output": "-1\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_l
問題文 長さ N の整数列 A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N) が与えられます。 区間 [l,r] \,(1 \le l \le r \le N) のスコアを以下で定義します。 |\min(A_l,A_{l+1},\ldots,A_r)-\min(B_l,B_{l+1},\ldots,B_r)| k=0,1,\ldots,N-1 について、 r-l=k を満たす [l,r] を選んだときのスコアとしてあり得る最小値を求めてください。
[ { "input": "3\n1 3 4\n8 5 7\n", "output": "2\n2\n4\n" }, { "input": "1\n1\n1\n", "output": "0\n" }, { "input": "6\n3 1 4 1 5 9\n2 6 5 3 5 8\n", "output": "0\n0\n1\n1\n1\n1\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_m
問題文 以下のいずれかの条件を満たす文字列を 正しい括弧列 と定義します。 空文字列 ある正しい括弧列 A が存在して、 ( , A , ) をこの順に連結した文字列 ある空でない正しい括弧列 A , B が存在して、 A , B をこの順に連結した文字列 そして、正しい括弧列から末尾の文字を取り除くことを何回か繰り返すことで得られる文字列を 美しい括弧列 と定義します。 例えば、 (((() や ()() 、空文字列などは美しい括弧列であり、 ))() 、 ()) などは美しい括弧列ではありません。 文字列 S と整数 L が与えられます。 k=1,2,\ldots ,|S|-L+1 について独立に、以下の問いに答えてください。 ...
[ { "input": "))((\n2\n", "output": "2\n1\n0\n" }, { "input": "))())\n4\n", "output": "-1\n-1\n" }, { "input": "))()(()\n3\n", "output": "4\n2\n0\n1\n0\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_n
問題文 N 行 M 列のマス目に整数を書き込む方法のうち、以下が成り立つものが存在するか判定し、存在する場合は 1 個構築してください。 ここで、 A_{i,j} を上から i 番目、左から j 番目のマスに書かれた整数とします。 A_{i,j} は 0 以上 X-1 以下である。 A_{i,j} \equiv A_{i-1,j} + A_{i+1,j} + A_{i,j-1} + A_{i,j+1}\ (\bmod X) \displaystyle \sum_{i=1}^{N} \sum_{j=1}^{M} A_{i,j} > 0 ただし、 A_{0,i},A_{N+1,i},A_{i,0},A_{i,M+1} は全て 0 としま...
[ { "input": "3\n2 2 3\n2 2 2\n52 53 2\n", "output": "2 1 \n1 2 \n-1\n-1\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_o
問題文 長さ N の順列全てに対する転倒数の M 乗の総和を 998244353 で割ったあまりを求めてください。 T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
[ { "input": "4\n3 2\n4 1\n53 54\n1234 12\n", "output": "19\n72\n403070452\n49172397\n" } ]
https://atcoder.jp/contests/nadafes2022_day2/tasks/nadafes2022_day2_p
問題文 N 枚のカードがあり、 1 から N の番号が付けられており、全てのカードは初め裏を向けて並べられています。 PCT 君は全てのカードが表を向くまで以下の操作を繰り返します。 1 以上 N 以下の整数をランダムに 1 個選ぶ。選んだ整数を x とおく。カード x から x+M-1 のうち、 裏を向けているカードのみ をひっくり返す。ただし、カード i \, (i > N) はカード i-N のこととする。 操作回数の期待値 \bmod\ 998244353 を求めてください。
[ { "input": "3 3\n", "output": "1\n" }, { "input": "3 1\n", "output": "499122182\n" }, { "input": "20220 5253\n", "output": "134463961\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_a
問題文 長さ N の攪乱順列の転倒数の最大値を求めてください。 攪乱順列とは、 1 \le i \le N に対して P_i \neq i を満たす順列のことです。 転倒数とは、 1 \le i < j \le N かつ P_i > P_j を満たす整数の組 (i,j) の個数です。
[ { "input": "3\n", "output": "2\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_b
問題文 \lbrace 1,2,...,N \rbrace の部分集合 A のうち、以下の条件を全て満たすものの個数を 998244353 で割ったあまりを求めてください。 |A| = K 1 \le i \le N を満たす整数 i 全てに対し、 A の中に i の倍数が存在する。
[ { "input": "3 2\n", "output": "1\n" }, { "input": "100 53\n", "output": "19600\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_c
問題文 maguro君は文化祭の展示でとあるゲームを作りました。 そのゲームでは H \times W のグリッド型のダンジョンが使われます。上から i\ (1 \leq i \leq H) 番目、左から j\ (1 \leq j \leq W) 番目のマスを (i,j) とします。 (i,j) のスタート時の状態は、 A_{i,j} が . のとき道、 # のとき壁、 @ のときマグマです。 プレイヤーは最初 (1, 1) にいて、スタートから 1 秒ごとに上下左右に隣接する道のマスに 1 マス動きます(ただし、ダンジョンの外は壁となっており進めません)。しかし、スタートしてから K, 2K, 3K \dots 秒経ったタイミング...
[ { "input": "4 4 2\n..@#\n#.#.\n....\n@##.\n", "output": "Yes\n" }, { "input": "4 4 2\n...@\n.#.#\n....\n@##.\n", "output": "No\n" }, { "input": "4 4 2\n.#.#\n....\n###.\n@...\n", "output": "No\n" }, { "input": "4 4 2\n....\n#...\n@#.#\n..#.\n", "output": "No\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_d
問題文 正整数 N が与えられます。 (0,1, \dots, N - 1) を並べ替えて得られる数列 P = (P_1, \dots, P_N) であって、以下の条件を満たすものは存在しますか? 1 \leq i \leq N に対し Q_i = \left(\sum_{j = 1}^i P_j\right) \bmod N とおくと、 Q_1, \dots, Q_N は (0, 1,\dots, N - 1) を並べ替えて得られる。 存在するならばその一例を示し、存在しないならばそのことを報告してください。
[ { "input": "4\n", "output": "0 1 2 3\n" }, { "input": "3\n", "output": "-1\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_e
問題文 N 頂点 M 辺の単純無向グラフが与えられます。 頂点には 1, \dots, N の番号がつけられており、頂点 i \, (1 \leq i \leq N) には整数 A_i が書かれています。 また、 i \, (1 \leq i \leq M) 番目の辺は頂点 B_i と頂点 C_i を結びます。 KoD 君はグラフから好きな本数( 0 本でもよい)の辺を選んで取り除きます。 KoD 君が獲得する スコア を、操作後のグラフにおいて次数が偶数である頂点に書かれた整数の和として定めます。ただし、操作後に次数が偶数である頂点が存在しない場合、スコアは 0 です。 KoD 君が獲得するスコアとしてあり得る最大の値を求めてくだ...
[ { "input": "3 2\n-10 2 3\n1 2\n2 3\n", "output": "3\n" }, { "input": "4 2\n1 2 3 -100\n1 3\n2 3\n", "output": "-94\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_f
問題文 長さ N の順列 P_1,P_2,\dots,P_N のうち、以下を満たすものの個数を 998244353 で割ったあまりを求めてください。 整数 X=1 がある。 X を P_X で置き換える操作を M 回繰り返した後に X=K となっている。
[ { "input": "3 2 1\n", "output": "4\n" }, { "input": "2022 53 54\n", "output": "294327113\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_g
問題文 N 行 M 列のマス目があります。上から i 番目、左から j 番目のマス目を (i,j) で表します。 PCT 君は、 (1,1) から、右のマスか下のマスに移動することを繰り返し (N,M) に行こうとしています。 しかし、下のマスが存在する (N-1)M マスのうちいずれかでは下のマスに移動することができません。 下に移動することのできないマスの組は 2^{(N-1)M} 通りありますが、そのうち PCT 君が (1,1) から (N,M) に移動できるものの個数を 998244353 で割ったあまりを求めてください。
[ { "input": "2 2\n", "output": "3\n" }, { "input": "2022 5354\n", "output": "63679225\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_h
問題文 NPCA 王国には N 個の町と N-1 個の道があります。 i 番目の道は長さが 1 で、町 u_i と町 v_i を双方向に結んでいます。また、どの町からどの町へもいくつかの道路を通ることで移動することができます。 クエリが Q 個与えられます。 i 番目のクエリは以下です。 旅人の PCT 君が、好きな町を出発し、 K_i 個の町 A_{i,1},A_{i,2},\ldots,A_{i,K_i} を訪れ、好きな町で旅を終えるとき、移動する距離の最小値を求めよ。ただし、訪れる順番は何でもよい。 最短距離で移動したい PCT 君のために、 Q 個のクエリをすべて処理してください。
[ { "input": "3 2\n1 2\n2 3\n2 1 2\n3 1 2 3\n", "output": "1\n2\n" }, { "input": "2 1\n1 2\n2 1 2\n", "output": "1\n" }, { "input": "6 4\n2 5\n3 5\n1 4\n4 5\n4 6\n3 1 2 3\n3 2 4 5\n2 1 6\n6 1 2 3 4 5 6\n", "output": "5\n2\n2\n7\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_i
問題文 NPCA 王国は 2 次元平面上の N 個の町からなり、町 i\,(1 \leq i \leq N) の座標は (x_i,y_i) です。 次が成り立つとき、またこの時に限り、町 i と町 j を双方向に結ぶ長さ c_i+c_j の道があります。 \min(|x_i-x_j|,|y_i-y_j|) \leq K 町 1 から町 N への最短距離を求めてください。
[ { "input": "3 3\n1 3 10\n3 10 5\n7 13 5\n", "output": "25\n" }, { "input": "2 1\n1 1 10\n10 10 10\n", "output": "-1\n" }, { "input": "6 100\n105 203 115\n56 51 299\n47 85 234\n108 277 160\n260 237 25\n170 147 127\n", "output": "242\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_j
問題文 長さ N の正整数列 A = (A_1, \dots, A_N) が与えられます。 Q 個のクエリを処理してください。 i \, (1 \leq i \leq Q) 個目のクエリでは、 K_i 個の整数 p_{i, 1}, \dots, p_{i, K_i} が与えられるので、 A_1, \dots, A_N のうち A_{p_{i, 1}}, \dots, A_{p_{i, K_i}} を除いた N - K_i 個の整数の最小公倍数を 998244353 で割った余りを求めてください。
[ { "input": "4\n2 4 3 6\n3\n1 1\n3 1 3 4\n2 2 3\n", "output": "12\n4\n6\n" }, { "input": "10\n1000000 1000000 999999 999998 999997 999996 999995 999994 999993 999992\n1\n1 1\n", "output": "143975436\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_k
問題文 以下の図のタイル L を A 枚、タイル I を B 枚使い、 2 \times N の長方形を敷き詰める方法の個数を 998244353 で割った余りを求めてください。 ただし、同じタイルは区別がつかず、またタイルを回転や反転させて使ってもよいです。 回転や反転によって一致するタイルの敷き詰め方は異なるものとします。
[ { "input": "4 2 1\n", "output": "6\n" }, { "input": "250 100 100\n", "output": "174250488\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_l
問題文 N 頂点の木が与えられます。 i 番目の辺は長さが 1 で、頂点 u_i と頂点 v_i を結んでいます。 頂点 1 を出発し、全ての辺を 2 回ずつ通り、頂点 1 に戻ってくる移動方法を考えます。 i 番目の要素が i 番目に通った頂点の深さと定義される数列としてありうる辞書順最小のものを求めてください。ただし、頂点の深さとは頂点 1 との距離を指すとします。
[ { "input": "4\n1 2\n2 3\n1 4\n", "output": "0 1 0 1 2 1 0\n" }, { "input": "2\n1 2\n", "output": "0 1 0\n" }, { "input": "6\n2 5\n3 5\n1 4\n4 5\n4 6\n", "output": "0 1 2 1 2 3 2 3 2 1 0\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_m
問題文 N 枚のカードがあります。それぞれのカードには 1 から N の番号がつけられています。blackyuki 君と KoD 君はこのカードを使ってゲームをすることにしました。 blackyuki 君から初めて、全てのカードがなくなるまで交互に以下の操作を繰り返します。 残っているカードから 1 枚選ぶ、選んだカードの番号を i とする。 \frac{A_i}{B_i} の確率でカード i を手に入れ、操作の初めに戻る。 1-\frac{A_i}{B_i} の確率で、何もせず操作を終了する。 ゲーム終了時に blackyuki 君の持っているカードの枚数が KoD 君の持っているカードの枚数以上であれば blackyuki 君の...
[ { "input": "1\n1 2\n", "output": "665496236\n" }, { "input": "2\n1 1\n1 1\n", "output": "1\n" }, { "input": "8\n100660 113169\n10964 152336\n57329 77239\n98640 167660\n103515 136455\n98695 99571\n14421 149410\n12488 21041\n", "output": "743177673\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_n
問題文 長さ N の整数列 A = (A_1, \dots, A_N) があります。はじめ、全ての要素は 0 です。 \{(a, b) \, | \, a \in \mathbb{N}, b \in \mathbb{N}, 1 \leq a \leq b \leq N \} の部分集合 S であって、以下の条件を全て満たすものの総数を 998244353 で割った余りを求めてください。 |S| = M S の全ての要素 (l, r) に対して以下を行った後、全ての 1 \leq i \leq N について A_i = B_i が成り立つ。 l \leq i \leq r を満たす全ての i に対し、 A_i を 1 - A_i で置...
[ { "input": "3 2\n1 1 0\n", "output": "2\n" }, { "input": "3 1\n1 0 1\n", "output": "0\n" }, { "input": "10 20\n1 0 1 1 0 1 1 1 1 1\n", "output": "71696207\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_o
問題文 N 個の机が横一列に並んでいます。机 i\,(1 \leq i \leq N) は初期状態で左から i 番目にあり、重さは A_i です。PCT 君は以下の操作を任意回行うことができます。 隣り合っている 2 つの机を選ぶ。これらの重さの和が K 以下のとき、これらの場所を入れ替える。 Q 個の独立なクエリが与えられます。 i 番目のクエリでは、PCT 君が机 s_i を左から t_i 番目に移動させることができるか判定してください。
[ { "input": "3 3 4\n1 2 3\n1 3\n3 1\n2 3\n", "output": "Yes\nNo\nNo\n" }, { "input": "4 1 1\n100 100 100 100\n1 1\n", "output": "Yes\n" }, { "input": "8 3 10\n4 1 1 3 6 4 3 6\n5 7\n3 3\n1 1\n", "output": "Yes\nYes\nYes\n" } ]
https://atcoder.jp/contests/nadafes2022_day1/tasks/nadafes2022_day1_p
問題文 長さ N かつ全ての要素が 1 以上 M 以下である整数列 A に対する \max_{1 \le i < j \le N} (A_j - A_i) の総和を 998244353 で割った余りを求めてください。
[ { "input": "2 2\n", "output": "0\n" }, { "input": "3 4\n", "output": "76\n" }, { "input": "100 20000\n", "output": "388129947\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_a
Problem Statement For a positive integer x , let \mathrm{ctz}(x) be the number of trailing zeros in the binary representation of x . For example, we have \mathrm{ctz}(8)=3 because the binary representation of 8 is 1000 , and \mathrm{ctz}(5)=0 because the binary representation of 5 is 101 . You are given a sequence of n...
[ { "input": "4\n0 1 3 2\n", "output": "12\n" }, { "input": "5\n4 3 2 1 0\n", "output": "31\n" }, { "input": "1\n40\n", "output": "1099511627776\n" }, { "input": "8\n2 0 2 2 0 4 2 4\n", "output": "80\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_b
Problem Statement We have an integer P=0 . Find the minimum total cost to make P=N by doing the following three kinds of operations any number of times in any order. Increase P by 1 , at a cost of X . Increase P by A , at a cost of Y . Increase P by B , at a cost of Z . Solve each of the T test cases given to you.
[ { "input": "5\n10 3 5 2 3 6\n10 3 5 1 1000000000 1000000000\n139 2 139 1 1 1\n139 1 1 1 1 1\n139 7 10 3845 26982 30923\n", "output": "11\n10\n1\n139\n436604\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_c
Problem Statement You are given positive integers N and M . Let us call a sequence of pairs of integers ((X_1,Y_1),(X_2,Y_2),\dots,(X_K,Y_K)) wonderful when it satisfies the following. 1 \le X_i \le N 1 \le Y_i \le M X_i+3Y_i \neq X_j+3Y_j and 3X_i+Y_i \neq 3X_j+Y_j , if i \neq j . Make a wonderful sequence of pairs of...
[ { "input": "3 4\n", "output": "10\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n3 4\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_d
Problem Statement You are given a multiset of integers with N elements: A=\lbrace A_1,A_2,...,A_N \rbrace . It is guaranteed that every element of A is between 1 and M (inclusive). Let us repeat the following operation K times. Choose an integer between 1 and M (inclusive) and add it to A . Then, delete the X -th small...
[ { "input": "2 4 2 1\n1 3\n", "output": "99\n" }, { "input": "5 9 6 3\n3 7 1 9 9\n", "output": "15411789\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_e
Problem Statement We have 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. Assume that this grid is a torus; that is, in addition to the pairs of squares horizontally or vertically adjacent to each other, assume the following pairs of squares t...
[ { "input": "3 2\n", "output": "6\n" }, { "input": "139 424\n", "output": "148734121\n" }, { "input": "12345 1234567890\n", "output": "227996418\n" } ]
https://atcoder.jp/contests/arc139/tasks/arc139_f
Problem Statement PCT made the following problem. Xor Optimization Problem You are given a sequence of non-negative integers of length N : A_1,A_2,...,A_N . When it is allowed to choose any number of elements in A , what is the maximum possible \mathrm{XOR} of the chosen values? Nyaan thought it was too easy and revise...
[ { "input": "2 1\n", "output": "3\n" }, { "input": "3 4\n", "output": "52290\n" }, { "input": "1234 5678\n", "output": "495502261\n" } ]
https://atcoder.jp/contests/ahc010/tasks/ahc010_a
Problem Statement You are given tiles containing railroad lines arranged in a 30 x 30 square. There are 8 types of tiles by distinguishing rotations which are numbered as follows. 0 1 2 3 4 5 6 7 Tiles 0 to 3 contain one curved line, tiles 4 and 5 contain two curved lines, and tiles 6 and 7 contain one straight line. ...
[ { "input": "436204751575440756541724746755\n347475575404531645424640344414\n556644445442451553264555436757\n761235545455474254546631467555\n356447405421445153457656535564\n014274425356522445253477726464\n311765446655556346633757446600\n471744514426443445162555525455\n616053450444473274742055767455\n254124557527...
https://atcoder.jp/contests/abc249/tasks/abc249_a
Problem Statement Takahashi and Aoki decided to jog. Takahashi repeats the following: "walk at B meters a second for A seconds and take a rest for C seconds." Aoki repeats the following: "walk at E meters a second for D seconds and take a rest for F seconds." When X seconds have passed since they simultaneously started...
[ { "input": "4 3 3 6 2 5 10\n", "output": "Takahashi\n" }, { "input": "3 1 4 1 5 9 2\n", "output": "Aoki\n" }, { "input": "1 1 1 1 1 1 1\n", "output": "Draw\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_b
Problem Statement Let us call a string consisting of uppercase and lowercase English alphabets a wonderful string if all of the following conditions are satisfied: The string contains an uppercase English alphabet. The string contains a lowercase English alphabet. All characters in the string are pairwise distinct. For...
[ { "input": "AtCoder\n", "output": "Yes\n" }, { "input": "Aa\n", "output": "Yes\n" }, { "input": "atcoder\n", "output": "No\n" }, { "input": "Perfect\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_c
Problem Statement You are given N strings S_1,S_2,\dots,S_N consisting of lowercase English alphabets. Consider choosing some number of strings from S_1,S_2,\dots,S_N . Find the maximum number of distinct alphabets that satisfy the following condition: "the alphabet is contained in exactly K of the chosen strings."
[ { "input": "4 2\nabi\naef\nbc\nacg\n", "output": "3\n" }, { "input": "2 2\na\nb\n", "output": "0\n" }, { "input": "5 2\nabpqxyz\naz\npq\nbc\ncy\n", "output": "7\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_d
Problem Statement You are given an integer sequence A = (A_1, \dots, A_N) of length N . Find the number of triplets of integers (i, j, k) satisfying all of the conditions below. 1 \leq i, j, k \leq N \frac{A_i}{A_j} = A_k
[ { "input": "3\n6 2 3\n", "output": "2\n" }, { "input": "1\n2\n", "output": "0\n" }, { "input": "10\n1 3 2 4 6 8 2 2 3 7\n", "output": "62\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_e
Problem Statement Consider the following procedure of, given a string X consisting of lowercase English alphabets, obtaining a new string: Split the string X off at the positions where two different characters are adjacent to each other. For each string Y that has been split off, replace Y with a string consisting of t...
[ { "input": "3 998244353\n", "output": "26\n" }, { "input": "2 998244353\n", "output": "0\n" }, { "input": "5 998244353\n", "output": "2626\n" }, { "input": "3000 924844033\n", "output": "607425699\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_f
Problem Statement Takahashi has an integer x . Initially, x = 0 . There are N operations. The i -th operation (1 \leq i \leq N) is represented by two integers t_i and y_i as follows: If t_i = 1 , replace x with y_i . If t_i = 2 , replace x with x + y_i . Takahashi may skip any number between 0 and K (inclusive) of th...
[ { "input": "5 1\n2 4\n2 -3\n1 2\n2 1\n2 -3\n", "output": "3\n" }, { "input": "1 0\n2 -1000000000\n", "output": "-1000000000\n" }, { "input": "10 3\n2 3\n2 -1\n1 4\n2 -1\n2 5\n2 -9\n2 2\n1 -6\n2 5\n2 -3\n", "output": "15\n" } ]
https://atcoder.jp/contests/abc249/tasks/abc249_g
Problem Statement There are N cards numbered 1, \dots, N . Card i \, (1 \leq i \leq N) has an integer A_i written on the front and an integer B_i written on the back. Consider choosing one or more cards so that the exclusive logical sum of the integers written on the front of the chosen cards is at most K . Find the ...
[ { "input": "4 2\n1 1\n3 2\n2 2\n0 1\n", "output": "3\n" }, { "input": "1 2\n3 4\n", "output": "-1\n" }, { "input": "10 326872757\n487274679 568989827\n267359104 968688210\n669234369 189421955\n1044049637 253386228\n202278801 233212012\n436646715 769734012\n478066962 376960084\n491389944 ...
https://atcoder.jp/contests/abc249/tasks/abc249_h
Problem Statement There are N balls numbered 1 through N . Initially, Ball i is painted in Color A_i . Colors are represented by integers between 1 and N , inclusive. Consider repeating the following operation until all the colors of the balls become the same. There are 2^N subsets (including the empty set) of the set...
[ { "input": "2\n1 2\n", "output": "4\n" }, { "input": "3\n1 1 1\n", "output": "0\n" }, { "input": "10\n3 1 4 1 5 9 2 6 5 3\n", "output": "900221128\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_a
Problem Statement You are given a string S of length exactly 9 consisting of digits. One but all digits from 0 to 9 appear exactly once in S . Print the only digit missing in S .
[ { "input": "023456789\n", "output": "1\n" }, { "input": "459230781\n", "output": "6\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_b
Problem Statement There are A slimes. Each time Snuke shouts, the slimes multiply by K times. In order to have B or more slimes, at least how many times does Snuke need to shout?
[ { "input": "1 4 2\n", "output": "2\n" }, { "input": "7 7 10\n", "output": "0\n" }, { "input": "31 415926 5\n", "output": "6\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_c
Problem Statement How many integer sequences of length N , A=(A_1, \ldots, A_N) , satisfy all of the conditions below? 1\le A_i \le M (1 \le i \le N) \displaystyle\sum _{i=1}^N A_i \leq K Since the count can get enormous, find it modulo 998244353 .
[ { "input": "2 3 4\n", "output": "6\n" }, { "input": "31 41 592\n", "output": "798416518\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_d
Problem Statement You are given a sequence of length N : A=(A_1,\ldots,A_N) . Answer Q queries given in the following format. You are given integers L , R , and X . Find the number of elements among A_L, \ldots, A_R whose values are equal to X .
[ { "input": "5\n3 1 4 1 5\n4\n1 5 1\n2 4 3\n1 5 2\n1 3 3\n", "output": "2\n0\n0\n1\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_e
Problem Statement You are given N points in the coordinate plane. For each 1\leq i\leq N , the i -th point is at the coordinates (X_i, Y_i) . Find the number of lines in the plane that pass K or more of the N points. If there are infinitely many such lines, print Infinity .
[ { "input": "5 2\n0 0\n1 0\n0 1\n-1 0\n0 -1\n", "output": "6\n" }, { "input": "1 1\n0 0\n", "output": "Infinity\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_f
Problem Statement You are given an integer N greater than or equal to 2 and a prime P . Consider the graph G with 2N vertices and (3N-2) edges shown in the figure below. More specifically, the edges connect the vertices as follows, where the vertices are labeled as Vertex 1 , Vertex 2 , \ldots , Vertex 2N , and the edg...
[ { "input": "3 998244353\n", "output": "7 15\n" }, { "input": "16 999999937\n", "output": "46 1016 14288 143044 1079816 6349672 29622112 110569766 330377828 784245480 453609503 38603306 44981526 314279703 408855776\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_g
Problem Statement You are given an undirected tree with N vertices. Let us call the vertices Vertex 1 , Vertex 2 , \ldots , Vertex N . For each 1\leq i\leq N-1 , the i -th edge connects Vertex U_i and Vertex V_i . Additionally, each vertex is assigned a positive integer: Vertex i is assigned A_i . The cost between two ...
[ { "input": "4\n24 30 28 7\n1 2\n1 3\n3 4\n", "output": "47\n" }, { "input": "10\n180 168 120 144 192 200 198 160 156 150\n1 2\n2 3\n2 4\n2 5\n5 6\n4 7\n7 8\n7 9\n9 10\n", "output": "1184\n" } ]
https://atcoder.jp/contests/abc248/tasks/abc248_h
Problem Statement You are given a permutation P=(P_1,\ldots,P_N) of (1,\ldots,N) , and an integer K . Find the number of pairs of integers (L, R) that satisfy all of the following conditions: 1 \leq L \leq R \leq N \mathrm{max}(P_L,\ldots,P_R) - \mathrm{min}(P_L,\ldots,P_R) \leq R - L + K
[ { "input": "4 1\n1 4 2 3\n", "output": "9\n" }, { "input": "2 0\n2 1\n", "output": "3\n" }, { "input": "10 3\n3 7 10 1 9 5 4 8 6 2\n", "output": "37\n" } ]
https://atcoder.jp/contests/abc247/tasks/abc247_a
Problem Statement There are 4 squares lined up horizontally. You are given a string S of length 4 consisting of 0 and 1 . If the i -th character of S is 1 , there is a person in the i -th square from the left; if the i -th character of S is 0 , there is no person in the i -th square from the left. Now, everyone will mo...
[ { "input": "1011\n", "output": "0101\n" }, { "input": "0000\n", "output": "0000\n" }, { "input": "1111\n", "output": "0111\n" } ]
https://atcoder.jp/contests/abc247/tasks/abc247_f
Problem Statement There are N cards numbered 1,\ldots,N . Card i has P_i written on the front and Q_i written on the back. Here, P=(P_1,\ldots,P_N) and Q=(Q_1,\ldots,Q_N) are permutations of (1, 2, \dots, N) . How many ways are there to choose some of the N cards such that the following condition is satisfied? Find t...
[ { "input": "3\n1 2 3\n2 1 3\n", "output": "3\n" }, { "input": "5\n2 3 5 4 1\n4 2 1 3 5\n", "output": "12\n" }, { "input": "8\n1 2 3 4 5 6 7 8\n1 2 3 4 5 6 7 8\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc247/tasks/abc247_g
Problem Statement There are N competitive programmers. The i -th competitive programmer belongs to University A_i , is good at Subject B_i , and has a power of C_i . Consider a team consisting of some of the N people. Let us call such a team a dream team if both of the following conditions are satisfied: Any two peopl...
[ { "input": "3\n1 1 100\n1 20 10\n2 1 1\n", "output": "2\n100\n11\n" }, { "input": "10\n1 4 142135623\n2 6 457513110\n3 1 622776601\n5 1 961524227\n2 2 360679774\n2 4 494897427\n3 7 416573867\n5 2 915026221\n1 7 320508075\n5 3 851648071\n", "output": "4\n961524227\n1537802822\n2032700249\n2353208...
https://atcoder.jp/contests/abc247/tasks/abc247_h
Problem Statement There are N people called Person 1 , Person 2 , \dots , Person N , lined up in a row in the order of (1,2,\dots,N) from the front. Person i is wearing Color c_i . Takahashi repeated the following operation K times: choose two People i and j arbitrarily and swap the positions of Person i and Person j ...
[ { "input": "4 1\n1 1 2 1\n", "output": "3\n" }, { "input": "3 3\n1 1 2\n", "output": "1\n" }, { "input": "10 4\n2 7 1 8 2 8 1 8 2 8\n", "output": "132\n" } ]
https://atcoder.jp/contests/arc138/tasks/arc138_a
Problem Statement We have an integer sequence of length N : A=(A_1,A_2,\cdots,A_N) . Below in this problem, let the score of A be the sum of the first K terms of A . Additionally, let s be the score of the sequence A given in input. You can do the following operation any number of times. Choose two adjacent elements ...
[ { "input": "4 2\n2 1 1 2\n", "output": "2\n" }, { "input": "3 1\n3 2 1\n", "output": "-1\n" }, { "input": "20 13\n90699850 344821203 373822335 437633059 534203117 523743511 568996900 694866636 683864672 836230375 751240939 942020833 865334948 142779837 22252499 197049878 303376519 366683...
https://atcoder.jp/contests/arc138/tasks/arc138_b
Problem Statement Snuke is about to make an integer sequence of length N consisting of 0 and 1 . He starts with an empty sequence x and does the following two kinds of operations N times in total, in any order he likes. Operation A: Flip every element of x , that is, convert each 0 to 1 and vice versa. Then, add 0 to ...
[ { "input": "4\n0 1 1 0\n", "output": "Yes\n" }, { "input": "4\n1 0 0 0\n", "output": "No\n" }, { "input": "4\n0 0 0 1\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc138/tasks/arc138_c
Problem Statement There are N cards, indexed 1 to N . Card i has an integer A_i written on it. Here, N is even. Snuke and Mr. Min will play a game. The game consists of N turns, alternately taken by the two players, with Snuke going first. In each turn, the player does the following operation. In Snuke's turn: He t...
[ { "input": "4\n3 4 1 2\n", "output": "1 7\n" }, { "input": "2\n1 1\n", "output": "0 1\n" }, { "input": "10\n716893678 779607519 555600775 393111963 950925400 636571379 912411962 44228139 15366410 2063694\n", "output": "7 3996409938\n" } ]
https://atcoder.jp/contests/arc138/tasks/arc138_d
Problem Statement You are given integers N and K . Determine whether there exists a permutation P=(P_0,P_1,\cdots,P_{2^N-1}) of (0,1,\cdots,2^N-1) satisfying the condition below, and construct one such sequence if it exists. Note that P is 0 -indexed. For every i ( 0 \leq i \leq 2^N-1 ), P_i and P_{i+1 \mod 2^N} diffe...
[ { "input": "3 1\n", "output": "Yes\n0 1 3 2 6 7 5 4\n" }, { "input": "2 2\n", "output": "No\n" } ]