url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc349/tasks/abc349_e
Problem Statement There is a 3 \times 3 grid. Let (i, j) denote the cell at the i -th row from the top and j -th column from the left (1 \leq i, j \leq 3) . Cell (i, j) contains an integer A_{i,j} . It is guaranteed that \sum_{i=1}^3 \sum_{j=1}^3 A_{i,j} is odd. Additionally, all cells are initially painted white. Taka...
[ { "input": "0 0 0\n0 1 0\n0 0 0\n", "output": "Takahashi\n" }, { "input": "-1 1 0\n-4 -2 -5\n-4 -1 -5\n", "output": "Aoki\n" } ]
https://atcoder.jp/contests/abc349/tasks/abc349_f
Problem Statement You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer M . Find the number, modulo 998244353 , of non-empty and not necessarily contiguous subsequences of A such that the least common multiple (LCM) of the elements in the subsequence is M . Two subsequen...
[ { "input": "4 6\n2 3 4 6\n", "output": "5\n" }, { "input": "5 349\n1 1 1 1 349\n", "output": "16\n" }, { "input": "16 720720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n", "output": "2688\n" } ]
https://atcoder.jp/contests/abc349/tasks/abc349_g
Problem Statement A sequence of positive integers T=(T_1,T_2,\dots,T_M) of length M is a palindrome if and only if T_i=T_{M-i+1} for each i=1,2,\dots,M . You are given a sequence of non-negative integers A = (A_1,A_2,\dots,A_N) of length N . Determine if there is a sequence of positive integers S=(S_1,S_2,\dots,S_N) of...
[ { "input": "7\n0 0 2 0 2 0 0\n", "output": "Yes\n1 1 2 1 1 1 2\n" }, { "input": "7\n0 1 2 3 2 1 0\n", "output": "Yes\n1 1 1 1 1 1 1\n" }, { "input": "7\n0 1 2 0 2 1 0\n", "output": "No\n" } ]
https://atcoder.jp/contests/ahc032/tasks/ahc032_a
Problem Statement In a two-dimensional grid, let (0, 0) be the coordinates of the top-left square, and (i, j) be the coordinates of the square located i squares down and j squares to the right from there. There is an N \times N square board. Initially, each square (i, j) on the board is assigned an integer a_{i, j} . ...
[ { "input": "9 20 81\n24323530 980293589 859258684 185499104 894688371 236405725 111530575 250271104 495624658\n769596495 264300425 88876278 146578260 565437828 737999180 725732147 57726456 323844609\n40096771 928203404 501627737 804865949 814572382 849529199 189832922 910184599 467494517\n962420139 432607222 59...
https://atcoder.jp/contests/abc348/tasks/abc348_a
Problem Statement Takahashi will have N penalty kicks in a soccer match. For the i -th penalty kick, he will fail if i is a multiple of 3 , and succeed otherwise. Print the results of his penalty kicks.
[ { "input": "7\n", "output": "ooxooxo\n" }, { "input": "9\n", "output": "ooxooxoox\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_b
Problem Statement On the xy -plane, there are N points with ID numbers from 1 to N . Point i is located at coordinates (X_i, Y_i) , and no two points have the same coordinates. From each point, find the farthest point and print its ID number. If multiple points are the farthest, print the smallest of the ID numbers of...
[ { "input": "4\n0 0\n2 4\n5 0\n3 4\n", "output": "3\n3\n1\n1\n" }, { "input": "6\n3 2\n1 6\n4 5\n1 3\n5 5\n9 8\n", "output": "6\n6\n6\n6\n6\n4\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_c
Problem Statement There are N types of beans, one bean of each type. The i -th type of bean has a deliciousness of A_i and a color of C_i . The beans are mixed and can only be distinguished by color. You will choose one color of beans and eat one bean of that color. By selecting the optimal color, maximize the minimum ...
[ { "input": "4\n100 1\n20 5\n30 5\n40 1\n", "output": "40\n" }, { "input": "10\n68 3\n17 2\n99 2\n92 4\n82 4\n10 3\n100 2\n78 1\n3 1\n35 4\n", "output": "35\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_d
Problem Statement There is a grid with H rows and W columns. Let (i, j) denote the cell at the i -th row from the top and the j -th column from the left. The state of each cell is represented by the character A_{i,j} , which means the following: . : An empty cell. # : An obstacle. S : An empty cell and the start point....
[ { "input": "4 4\nS...\n#..#\n#...\n..#T\n4\n1 1 3\n1 3 5\n3 2 1\n2 3 1\n", "output": "Yes\n" }, { "input": "2 2\nS.\nT.\n1\n1 2 4\n", "output": "No\n" }, { "input": "4 5\n..#..\n.S##.\n.##T.\n.....\n3\n3 1 5\n1 2 3\n2 2 1\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_e
Problem Statement You are given a tree with N vertices. The vertices are numbered 1 to N , and the i -th edge connects vertices A_i and B_i . You are also given a sequence of positive integers C = (C_1, C_2, \ldots ,C_N) of length N . Let d(a, b) be the number of edges between vertices a and b , and for x = 1, 2, \ldot...
[ { "input": "4\n1 2\n1 3\n2 4\n1 1 1 2\n", "output": "5\n" }, { "input": "2\n2 1\n1 1000000000\n", "output": "1\n" }, { "input": "7\n7 3\n2 5\n2 4\n3 1\n3 6\n2 1\n2 7 6 9 3 4 6\n", "output": "56\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_f
Problem Statement There are N sequences of length M , denoted as A_1, A_2, \ldots, A_N . The i -th sequence is represented by M integers A_{i,1}, A_{i,2}, \ldots, A_{i,M} . Two sequences X and Y of length M are said to be similar if and only if the number of indices i (1 \leq i \leq M) such that X_i = Y_i is odd. Find ...
[ { "input": "3 3\n1 2 3\n1 3 4\n2 3 4\n", "output": "1\n" }, { "input": "6 5\n8 27 27 10 24\n27 8 2 4 5\n15 27 26 17 24\n27 27 27 27 27\n27 7 22 11 27\n19 27 27 27 27\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc348/tasks/abc348_g
Problem Statement You are given two integer sequences A and B of length N . For k = 1, 2, \ldots, N , solve the following problem: Consider choosing k distinct integers between 1 and N , inclusive. Let S be the set of chosen integers. Find the maximum value of \displaystyle (\sum_{i \in S} A_i) - \max_{i \in S} B_i .
[ { "input": "3\n4 1\n5 6\n3 2\n", "output": "3\n5\n6\n" }, { "input": "2\n0 1\n0 1\n", "output": "-1\n-1\n" }, { "input": "6\n9 7\n2 4\n7 1\n-1000 0\n3 4\n8 5\n", "output": "6\n10\n17\n20\n22\n-978\n" } ]
https://atcoder.jp/contests/agc066/tasks/agc066_a
Problem Statement There is a grid with N rows and N columns. Let (i, j) denote the cell at the i -th row from the top and the j -th column from the left. Each cell contains an integer. Initially, cell (i,j) contains the integer A_{i,j} . You can repeatedly perform the following operation: Choose integers i and j such t...
[ { "input": "3 5\n-2 1 3\n3 -4 -4\n0 1 3\n", "output": "-2 8 3\n3 -9 -4\n-2 8 3\n" }, { "input": "5 2\n1 5 5 0 3\n2 0 2 5 1\n5 2 0 5 5\n3 7 2 0 1\n6 0 4 3 6\n", "output": "0 4 6 1 3\n3 1 3 6 1\n5 3 0 3 5\n2 6 3 1 3\n4 0 5 3 6\n" } ]
https://atcoder.jp/contests/abc325/tasks/abc325_b
Problem Statement Keyence has N bases worldwide, numbered 1 to N . Base i has W_i employees, and at 0 o'clock in Coordinated Universal Time (UTC), it is X_i o'clock at base i . You want to hold a one-hour meeting across the entire company. Each employee can only participate in the meeting if the meeting time is compl...
[ { "input": "3\n5 0\n3 3\n2 18\n", "output": "8\n" }, { "input": "2\n1 10\n1000000 20\n", "output": "1000000\n" }, { "input": "6\n31 3\n20 8\n11 5\n4 3\n47 14\n1 18\n", "output": "67\n" } ]
https://atcoder.jp/contests/abc325/tasks/abc325_c
Problem Statement There are zero or more sensors placed on a grid of H rows and W columns. Let (i, j) denote the square in the i -th row from the top and the j -th column from the left. Whether each square contains a sensor is given by the strings S_1, S_2, \ldots, S_H , each of length W . (i, j) contains a sensor if a...
[ { "input": "5 6\n.##...\n...#..\n....##\n#.#...\n..#...\n", "output": "3\n" }, { "input": "3 3\n#.#\n.#.\n#.#\n", "output": "1\n" }, { "input": "4 2\n..\n..\n..\n..\n", "output": "0\n" }, { "input": "5 47\n.#..#..#####..#...#..#####..#...#...###...#####\n.#.#...#.......#.#......
https://atcoder.jp/contests/abc325/tasks/abc325_d
Problem Statement There are N products labeled 1 to N flowing on a conveyor belt. A Keyence printer is attached to the conveyor belt, and product i enters the range of the printer T_i microseconds from now and leaves it D_i microseconds later. The Keyence printer can instantly print on one product within the range of ...
[ { "input": "5\n1 1\n1 1\n2 1\n1 2\n1 4\n", "output": "4\n" }, { "input": "2\n1 1\n1000000000000000000 1000000000000000000\n", "output": "2\n" }, { "input": "10\n4 1\n1 2\n1 4\n3 2\n5 1\n5 1\n4 1\n2 1\n4 1\n2 4\n", "output": "6\n" } ]
https://atcoder.jp/contests/abc325/tasks/abc325_e
Problem Statement There are N cities in a certain country. You will travel from your office in city 1 to a destination in city N , via zero or more cities. Two types of transportation are available: company car and train. The time required to travel from city i to city j is as follows: D_{i,j} \times A minutes by compa...
[ { "input": "4 8 5 13\n0 6 2 15\n6 0 3 5\n2 3 0 13\n15 5 13 0\n", "output": "78\n" }, { "input": "3 1 1000000 1000000\n0 10 1\n10 0 10\n1 10 0\n", "output": "1\n" }, { "input": "5 954257 954213 814214\n0 84251 214529 10017 373342\n84251 0 91926 32336 164457\n214529 91926 0 108914 57762\n1...
https://atcoder.jp/contests/abc325/tasks/abc325_f
Problem Statement As the factory manager of Keyence, you want to monitor several sections on a conveyor belt. There are a total of N sections you want to monitor, and the length of the i -th section is D_i meters. There are two types of sensors to choose from, and below is some information about each sensor. Type- j se...
[ { "input": "3\n3 5 10\n4 3 3\n2 2 6\n", "output": "17\n" }, { "input": "3\n3 5 10\n4 3 3\n2 2 3\n", "output": "-1\n" }, { "input": "2\n4 8\n3 1 100\n4 10000 100\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc325/tasks/abc325_g
Problem Statement You are given a string S . Find the minimum length of a string that can be obtained by performing the following operation on the string S zero or more times. Choose a contiguous occurrence of of in the string and an integer i between 0 and K , inclusive. Then, remove the of and the following i charact...
[ { "input": "keyofscience\n3\n", "output": "7\n" }, { "input": "oofsifffence\n3\n", "output": "2\n" }, { "input": "ooofff\n5\n", "output": "0\n" }, { "input": "okeyencef\n4\n", "output": "9\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_a
Problem Statement We have N slices of toast and M plates. M is an integer between \frac{N}{2} and N , inclusive. The i -th slice of toast has a deliciousness of A_{i} . Let us put the N slices of toast on the M plates to satisfy the following two conditions. Each plate can have at most two slices of toast on it. Every ...
[ { "input": "5 3\n1 1 1 6 7\n", "output": "102\n" }, { "input": "2 1\n167 924\n", "output": "1190281\n" }, { "input": "12 9\n22847 98332 854 68844 81080 46058 40949 62493 76561 52907 88628 99740\n", "output": "61968950639\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_b
Problem Statement At most how many times can the product of all positive divisors of A^{B} be divided by A ? It can be shown from the constraints that this count is finite, so find it modulo 998244353 .
[ { "input": "2 3\n", "output": "6\n" }, { "input": "924 167\n", "output": "867046524\n" }, { "input": "167167167167 0\n", "output": "0\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_c
Problem Statement You are given positive integers N and K , and a sequence of N positive integers: A=(A_{1},A_{2},\dots,A_{N}) . For a permutation P=(P_{1},P_{2},\dots,P_{N}) of (1,2,\dots,N) , consider the following problem "MST on Line," and let f(P) the answer. Problem: MST on Line We have a weighted undirected grap...
[ { "input": "5 2\n3 4 5 2 1\n", "output": "1740\n" }, { "input": "2 1\n167 924\n", "output": "1848\n" }, { "input": "12 9\n22847 98332 854 68844 81080 46058 40949 62493 76561 52907 88628 99740\n", "output": "660459584\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_d
Problem Statement In this problem, when we say just a "permutation", it refers to a permutation of (1,2,\dots,N) . You are given a permutation P=(P_{1},P_{2},\dots,P_{N}) . A permutation Q=(Q_{1},Q_{2},\dots,Q_{N}) is said to be a good permutation when the following holds. For every integer 1\leq x\leq N , it is possib...
[ { "input": "5\n4\n2 1 4 3\n5\n2 1 3 4 5\n2\n1 2\n2\n2 1\n9\n4 3 6 2 7 1 9 8 5\n", "output": "2 3 4 1\n2 3 4 5 1\n2 1\n2 1\n4 3 5 2 7 1 8 9 6\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_e
Problem Statement A triangle ABC on the xy -plane is said to be a good triangle when it satisfies all of the following conditions. Each of the vertices A , B , and C is a lattice point whose x - and y -coordinates are between 0 and 10^{8} , inclusive. The triangle ABC ( including the perimeter and vertices) wholly cont...
[ { "input": "3\n1\n4\n15\n", "output": "No\nYes\n1 1 1 3 3 3\nYes\n5 1 7 8 4 5\n" } ]
https://atcoder.jp/contests/arc167/tasks/arc167_f
Problem Statement You are given integers N and K such that 2\leq K\leq N . Problem: potato We have a weighted rooted tree with N vertices numbered 1 to N . Vertex 1 is the root. For each 2\leq i\leq N , the parent of vertex i is p_{i}\;(1\leq p_{i}<i) , and the edge connecting i and p_{i} has a weight of q_{i-1} . Here...
[ { "input": "4 4\n", "output": "170\n170\n172\n" }, { "input": "3 2\n", "output": "20\n" }, { "input": "16 7\n", "output": "457991130\n457991130\n65525944\n418314090\n644126049\n676086428\n" } ]
https://atcoder.jp/contests/joi2024yo1b/tasks/joi2024_yo1b_a
問題文 1 個 A 円の飴を B 個と, C 円の袋を 1 つ買う.合計金額はいくらか求めよ.
[ { "input": "20\n3\n10\n", "output": "70\n" }, { "input": "70\n2\n100\n", "output": "240\n" }, { "input": "23\n10\n15\n", "output": "245\n" }, { "input": "100\n100\n100\n", "output": "10100\n" } ]
https://atcoder.jp/contests/joi2024yo1b/tasks/joi2024_yo1b_b
問題文 整数 X が与えられる. 今日は日曜日である.今日の X 日後が火曜日であるならば 1 を,そうでないならば 0 を出力せよ.
[ { "input": "2\n", "output": "1\n" }, { "input": "10\n", "output": "0\n" }, { "input": "100\n", "output": "1\n" } ]
https://atcoder.jp/contests/joi2024yo1b/tasks/joi2024_yo1b_c
問題文 文字 j の画数は 2 画,文字 o の画数は 1 画,文字 i の画数は 2 画である. 長さ N の文字列 S が与えられる. S の各文字は j , o , i のいずれかである. S の各文字の画数の合計を求めよ.
[ { "input": "6\njjooii\n", "output": "10\n" }, { "input": "1\ni\n", "output": "2\n" }, { "input": "13\njoiojiioijoio\n", "output": "21\n" } ]
https://atcoder.jp/contests/joi2024yo1b/tasks/joi2024_yo1b_d
問題文 正の整数 X , N が与えられる. 最初,黒板に整数 X が書かれている. JOI 君は,以下の 操作 を繰り返し行う. 操作: 今,黒板に書かれている数を x とする. x を 3 で割った余りを計算し, r とする. r の値に応じて,黒板に書かれている数を以下のように書き換える. r=0 のとき,黒板に書かれている数を, x に 1 を足した数に書き換える. r=1 のとき,黒板に書かれている数を, x に 2 を掛けた数に書き換える. r=2 のとき,黒板に書かれている数を, x に 3 を掛けた数に書き換える. 黒板に書かれている数が N 以上になるまでに必要な操作の回数を求めよ.
[ { "input": "2\n40\n", "output": "4\n" }, { "input": "3\n4\n", "output": "1\n" }, { "input": "20\n62\n", "output": "3\n" }, { "input": "1\n100000\n", "output": "19\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_a
Problem Statement You are given N integers A _ 1,A _ 2,\ldots,A _ N . If their values are all equal, print Yes ; otherwise, print No .
[ { "input": "3\n3 2 4\n", "output": "No\n" }, { "input": "4\n3 3 3 3\n", "output": "Yes\n" }, { "input": "10\n73 8 55 26 97 48 37 47 35 55\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_b
Problem Statement You are given a positive integer N . If there are integers x and y such that N=2^x3^y , print Yes ; otherwise, print No .
[ { "input": "324\n", "output": "Yes\n" }, { "input": "5\n", "output": "No\n" }, { "input": "32\n", "output": "Yes\n" }, { "input": "37748736\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_c
Problem Statement Takahashi sent a string T consisting of lowercase English letters to Aoki. As a result, Aoki received a string T' consisting of lowercase English letters. T' may have been altered from T . Specifically, exactly one of the following four conditions is known to hold. T' is equal to T . T' is a string ob...
[ { "input": "5 ababc\nababc\nbabc\nabacbc\nabdbc\nabbac\n", "output": "4\n1 2 3 4\n" }, { "input": "1 aoki\ntakahashi\n", "output": "0\n\n" }, { "input": "9 atcoder\natoder\natcode\nathqcoder\natcoder\ntacoder\njttcoder\natoder\natceoder\natcoer\n", "output": "6\n1 2 4 7 8 9\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_d
Problem Statement You are given a string S of length N consisting of digits. Find the number of square numbers that can be obtained by interpreting a permutation of S as a decimal integer. More formally, solve the following. Let s _ i be the number corresponding to the i -th digit (1\leq i\leq N) from the beginning of ...
[ { "input": "4\n4320\n", "output": "2\n" }, { "input": "3\n010\n", "output": "2\n" }, { "input": "13\n8694027811503\n", "output": "840\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_e
Problem Statement You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters, and a string T consisting of lowercase English letters. There are N^2 pairs (i, j) of integers between 1 and N , inclusive. Print the number of pairs among them that satisfy the following condition. The concatenatio...
[ { "input": "3 bac\nabba\nbcb\naaca\n", "output": "3\n" }, { "input": "5 xx\nx\nx\nx\nx\nx\n", "output": "25\n" }, { "input": "1 y\nx\n", "output": "0\n" }, { "input": "10 ms\nmkgn\nm\nhlms\nvmsle\nmxsm\nnnzdhi\numsavxlb\nffnsybomr\nyvmm\nnaouel\n", "output": "68\n" } ]
https://atcoder.jp/contests/abc324/tasks/abc324_f
Problem Statement There is a directed graph with N vertices and M edges. Each edge has two positive integer values: beauty and cost . For i = 1, 2, \ldots, M , the i -th edge is directed from vertex u_i to vertex v_i , with beauty b_i and cost c_i . Here, the constraints guarantee that u_i \lt v_i . Find the maximum v...
[ { "input": "5 7\n1 2 3 6\n1 3 9 5\n2 3 1 5\n2 4 5 3\n2 5 1 9\n3 4 4 8\n4 5 2 7\n", "output": "0.7500000000000000\n" }, { "input": "3 3\n1 3 1 1\n1 3 2 1\n1 3 3 1\n", "output": "3.0000000000000000\n" }, { "input": "10 20\n3 4 1 2\n7 9 4 5\n2 4 4 5\n4 5 1 4\n6 9 4 1\n9 10 3 2\n6 10 5 5\n5 ...
https://atcoder.jp/contests/abc324/tasks/abc324_g
Problem Statement Takahashi has a sequence of length N : A=(A _ 1,A _ 2,\ldots,A _ N) . A is a permutation of (1,2,\ldots,N) . He is going to perform Q operations to create 1+Q sequences. He lets A be the sequence numbered 0 , and then begins the series of operations. The i -th operation (1\leq i\leq Q) is represented ...
[ { "input": "10\n1 8 7 4 5 6 3 2 9 10\n5\n2 0 4\n1 1 2\n2 0 2\n2 2 5\n1 0 1\n", "output": "6\n4\n2\n3\n1\n" }, { "input": "8\n6 7 8 4 5 1 3 2\n5\n2 0 0\n1 1 0\n2 2 0\n1 3 8\n2 2 3\n", "output": "8\n8\n8\n0\n0\n" }, { "input": "30\n20 6 13 11 29 30 9 10 16 5 8 25 1 19 12 18 7 2 4 27 3 22 2...
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_a
問題文 選手 1, 2, \dots, N の N 人の選手が参加する大会が行われます。 会場には列 0, 1, \dots, N-1 の N 個の列が用意されており、列 i\ (0 \le i \le N - 1) に並んでいる選手はその時点で i 連勝中であることを表します。 大会開始時点では、選手は列 0 の先頭から順に選手 1, 2, \dots, N の順で並んでいます。 大会では、次の手順に従って各選手の順位を決めます。 どの列にもちょうど 1 人の選手が並んでいるとき、列 i に並んでいる選手の順位は N-i 位である。このとき手順を終了する。 2 人以上の選手が並んでいる列の中で最も番号の小さい列を列 l とする。 ...
[ { "input": "3\n", "output": "4\n" }, { "input": "5\n", "output": "26\n" }, { "input": "100000\n", "output": "538161387\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_b
問題文 大きさ N の非負整数の集合 S = \{S_1, S_2, \dots, S_N\} が与えられます。 変数 x があり、はじめ x = S_1 です。あなたは以下の操作を何度でも行うことができます。 y \in S を 1 つ選ぶ。 y が以下の 条件 を満たすとき、 x に y を代入する。 条件 : x と y をそれぞれ三進数表記したときの 3^j の位の数字を X_j と Y_j とする。このとき、 X_j \gt Y_j なる j の個数は 1 個以下である。 この操作を何回か行って x = S_N にできるかどうか判定してください。
[ { "input": "2\n21 14\n", "output": "Yes\n" }, { "input": "2\n12 1\n", "output": "No\n" }, { "input": "5\n5 15 45 135 405\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_c
問題文 整数 N が与えられます。次の 2 条件をともに満たす正整数の組 (a, b) の個数を求めてください。 1 \leq a, b \leq N ある正整数の組 (x, y) が存在して、 x + y^2 = a と x^2 + y = b がともに成り立つ T 個のテストケースが与えられるので、それぞれについて答えてください。
[ { "input": "3\n6\n1\n101\n", "output": "4\n0\n83\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_d
問題文 3 次元空間上の相異なる座標に N 個の星が輝いています。 i 番目の星は点 P_i(x_i,y_i,z_i) に存在します。また、半径 R の球状の宇宙船が原点を中心に浮かんでいます。 空間上の点 p が 素敵な点 であるとは、 i = 1, 2, \dots, N に対して次の条件が同時に成り立つことを言います。 点 p から i 番目の星が観測できる。すなわち、 p と P_i を端点とする線分が宇宙船の周及び内部を通らない。 素敵な点が存在する領域の連結成分の個数を求めてください。すなわち、素敵な点全体の集合を L としたとき、 L を以下の同値関係 \sim で割ったときの商集合の大きさを求めてください。 p_1,...
[ { "input": "3\n4 12\n13 0 0\n0 15 0\n0 -15 0\n0 0 15\n6 100\n0 0 101\n0 0 -101\n0 101 0\n0 -101 0\n101 0 0\n-101 0 0\n20 333\n328 -160 -572\n-165 417 -847\n-319 -45 271\n359 -467 -625\n-355 -451 658\n-280 -424 687\n-65 -224 573\n475 -371 373\n-246 -54 -903\n595 -196 -305\n622 -570 -250\n386 -541 -566\n647 455 -...
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_e
問題文 正整数 R に対し、以下の無限無向グラフの連結成分数を f(R) と定義します。 頂点集合は \mathbb Z^2 である。すなわち、任意の 2 つの整数 x, y に対し、頂点 (x, y) が存在する。 頂点 (x_1, y_1) と頂点 (x_2, y_2) の間には、 |x_1 - x_2|^2 + |y_1 - y_2|^2 = R であるとき、かつそのときに限り辺が存在する。 正整数 R が与えられるので、 f(R) を出力してください。ただし、 f(R) が有限でないときは、 inf を出力してください。 T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
[ { "input": "3\n1\n2\n3\n", "output": "1\n2\ninf\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_f
問題文 正の整数 N についての関数 F(N) が次の BNF 表記 の <expr> シンボルに従う文字列 F として与えられます。 <expr> ::= <term> | <expr> "+" <term> <term> ::= <factor> | <term> "*" <factor> <factor> ::= "N" | "N^" <number> | "log(" <expr> ")" | "log(" <expr> ")^" <number> | "(" <expr> ")" <number> ::= <non_zero_digit> | <non_zero_digit> <digit_string> <dig...
[ { "input": "N*log(N^2)*log(N)+N+log(N^1+N)^2*N\n", "output": "1 2\n" }, { "input": "N*log(log(N))\n", "output": "1 1\n" }, { "input": "(((N))*N^234567890+N^2)\n", "output": "234567891 0\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_g
問題文 Alice は (1,2,\dots,N) の順列 P=(P_{1},P_{2},\dots,P_{N}) がお気に入りです。 P を当てたら Alice からコーラがもらえることを知った Bob は、Alice に質問をして P を当てることにしました。 Bob は以下の質問を M 回まで行うことができます。 (1,2,\dots,N) の順列 Q=(Q_{1},Q_{2},\dots,Q_{N}) をひとつ決め、Alice にお気に入りの順列が Q であるかを聞く。 ここで M \leq N が成り立ちます。 Alice は Bob の質問に対して以下の行動を行います。 P = Q であるなら、Alice は Bob に...
[ { "input": "2 1\n", "output": "499122177\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "167 91\n", "output": "469117530\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_h
問題文 N 個の文字列 S_1, S_2, \dots, S_N が与えられます。空でない文字列 T であって、以下の条件を満たすものの個数を求めてください。 文字列 S_1, S_2, \dots, S_N のうち、 T を (連続する) 部分文字列として含むものはちょうど 1 個である。
[ { "input": "2\nabc\nca\n", "output": "5\n" }, { "input": "2\naab\naab\n", "output": "0\n" }, { "input": "1\naba\n", "output": "5\n" }, { "input": "3\ntokyoinstituteoftechnology\ntokyomedicalanddentaluniversity\ninstituteofsciencetokyo\n", "output": "905\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_i
問題文 H 行 W 列のマス目を図に示すような 4 マス分を占める T 字のタイルで敷き詰める方法の個数を 998244353 で割ったあまりを求めてください。 ただし、タイルをマス目に敷き詰めるとき、次の条件を満たす必要があります。 タイルはマス目に沿って置かれなければならない タイルはマス目からはみ出してはならない 異なるタイルが同じマスを覆ってはならない どのタイルにも覆われていないマスが存在してはならない また、タイルは回転させて使っても良いですが、裏表の区別はなく、タイル同士の区別もありません。 さらに、回転や反転によってはじめて一致するようなタイルの敷き詰め方は区別します。
[ { "input": "4 4\n", "output": "2\n" }, { "input": "2 8\n", "output": "0\n" }, { "input": "12 3456\n", "output": "491051233\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_j
問題文 2 以上の整数 N と、 2 以上 \frac{N(N+1)}{2} 以下の整数 M が与えられます。非負整数からなる集合 A であって、以下の条件をすべて満たすものが存在するので、それを 1 つ構築してください。 0 \in A 2^N - 1 \in A 集合 A の要素はすべて 0 以上 2^N - 1 以下の非負整数である(16:08 修正) x, y \in A ならば x ~ \mathrm{AND} ~ y \in A x, y \in A ならば x ~ \mathrm{OR} ~ y \in A A の要素数 |A| は M に等しい T 個のテストケースが与えられるので、それぞれについて答えてください。 ...
[ { "input": "3\n3 5\n4 8\n60 2\n", "output": "0 1 3 5 7\n0 1 3 7 8 9 11 15\n0 1152921504606846975\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_k
問題文 整数 K が与えられます。以下の条件を満たすできるだけ辺の少ない無向グラフを 1 つ構築してください。 頂点の数 N は 1 以上 100 以下 辺の数 M は 10^5 以下 辺はすべて区別できるものとしたとき、グラフの全域木がちょうど K 個存在する。すなわち、 M 本の辺からいくつかの辺を選ぶ方法 2^M 通りのうち、それら以外の辺を削除するとグラフが木になるようなものがちょうど K 通り存在する。
[ { "input": "11\n", "output": "3 6\n1 2\n1 3\n1 3\n2 3\n2 3\n2 3\n" }, { "input": "54\n", "output": "4 10\n1 2\n2 3\n2 3\n2 3\n3 4\n3 4\n3 4\n4 1\n4 1\n4 1\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_m
問題文 2N 個の正整数 (p_1,q_1,p_2,q_2,\dots ,p_N,q_N) が与えられます。 1\le l\le r\le N を満たす整数の組 (l,r) であって、次の条件を満たすものの個数を求めてください。 \displaystyle\sum_{i=l}^{r}\dfrac{p_i}{q_i} は整数である。
[ { "input": "4\n1 6\n1 3\n1 2\n1 2\n", "output": "2\n" }, { "input": "5\n1 1\n2 2\n3 3\n4 4\n5 5\n", "output": "15\n" }, { "input": "2\n1 99999\n99999 100000\n", "output": "0\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_n
問題文 正整数 N と素数 M が与えられます。 ( , ? , ) からなる文字列で以下の条件を満たすものを 良い文字列 と定義します。 文字列に含まれる ? をそれぞれ ( あるいは ) に置き換えることで バランスの取れた括弧列 にすることができる。 長さ 2N の良い文字列の個数を M で割ったあまりを求めてください。 ただし、 バランスの取れた括弧列 とは以下のいずれかの条件を満たす文字列のことです。 空文字列 あるバランスの取れた括弧列 A が存在して、 ( , A , ) をこの順に連結した文字列 ある空でないバランスの取れた括弧列 A,B が存在して、 A,B をこの順に連結した文字列
[ { "input": "1 998244353\n", "output": "4\n" }, { "input": "2 900000011\n", "output": "28\n" }, { "input": "999937 999999937\n", "output": "170733195\n" }, { "input": "167167924 924924167\n", "output": "596516682\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_o
問題文 2 次元平面上に開きカッコと閉じカッコがそれぞれ N 個ずつあります。 i 番目の開きカッコの座標は (x_{1, i}, y_{1, i}) 、 i 番目の閉じカッコの座標は (x_{2, i}, y_{2, i}) です。 x_{1, i} < x_{2, j} かつ y_{1, i} < y_{2, j} であるときに限り、 i 番目の開きカッコと j 番目の閉じカッコを平面上から削除し、代わりに 4 点 (x_{1, i}, y_{1, i}), (x_{1, i}, y_{2, j}), (x_{2, j}, y_{2, j}), (x_{2, j}, y_{1, i}) を頂点とする長方形を平面に配置することがで...
[ { "input": "3\n0 0\n2 -2\n1 1\n2 2\n3 1\n2 3\n", "output": "Yes\n3\n2\n1\n" }, { "input": "2\n1 0\n0 1\n2 3\n3 2\n", "output": "No\n" }, { "input": "1\n1 1\n0 0\n", "output": "No\n" } ]
https://atcoder.jp/contests/ttpc2023/tasks/ttpc2023_p
問題文 N 頂点の無向グラフがあります。このグラフの頂点には 1 から N までの番号がつけられており、頂点 i\ (1 \le i \le N) には整数 A_i が書かれています。このグラフには辺がありませんが、あなたが自由に辺を張ることができます。 このグラフが単純グラフとなるような辺の張り方は 2^{\frac{N(N-1)}{2}} 通り存在しますが、そのすべてについて以下の スコア を計算し、その総和を 998244353 で割った余りを求めてください。 グラフが連結でないとき、その スコア は 0 である。 グラフが連結なとき、グラフから橋である辺を取り除いたグラフを G とする。 G の各連結成分について頂点に書かれ...
[ { "input": "3\n8 5 9\n", "output": "1102\n" }, { "input": "5\n4 2 1 3 10\n", "output": "63860\n" }, { "input": "7\n229520041 118275986 281963154 784360383 478705114 655222915 970715006\n", "output": "35376232\n" } ]
https://atcoder.jp/contests/ahc025/tasks/ahc025_a
Problem Statement There are N items. The weight w_i of each item i is unknown. Using a balance that can compare the sum of the weights of two item sets, you repeat the following operations. Place as many items as you like on the left and right plates of the balance. Then you can see which side has the greater weight ...
[]
https://atcoder.jp/contests/arc166/tasks/arc166_a
Problem Statement You are given strings X and Y of length N each, consisting of A , B , and C . Determine if it is possible to make X coincide with Y by performing the following three kinds of operations on X any number of times, possibly zero. Operation (1) :Choose a character C in X and replace it with A . Operation ...
[ { "input": "6\n3 ABC ABC\n1 C B\n1 B C\n2 AB BA\n2 BA AB\n3 CCB ABA\n", "output": "Yes\nYes\nNo\nYes\nNo\nYes\n" }, { "input": "7\n5 ABABA BABAB\n5 ABCBC BBABA\n5 CCCCC CBABC\n5 BBAAA AAABB\n5 AAABB BBAAA\n5 ACACB BAACB\n5 ACACB BBACA\n", "output": "No\nYes\nYes\nNo\nYes\nYes\nNo\n" } ]
https://atcoder.jp/contests/arc166/tasks/arc166_b
Problem Statement You are given an integer sequence A=(A_1,\ldots,A_N) and positive integers a , b , and c . You can perform the following operation on this sequence any number of times, possibly zero. Choose an integer i such that 1\leq i\leq N . Replace A_i with A_i+1 . Your objective is to make the sequence A contai...
[ { "input": "3 3 4 5\n8 9 11\n", "output": "2\n" }, { "input": "3 3 4 5\n14 11 59\n", "output": "1\n" }, { "input": "6 10 20 30\n8 17 5 28 39 13\n", "output": "3\n" }, { "input": "1 999997 999998 999999\n123456789123456789\n", "output": "876537210887543205\n" } ]
https://atcoder.jp/contests/arc166/tasks/arc166_c
Problem Statement There is a grid with H rows and W columns. This grid has H(W+1) vertical edges and W(H+1) horizontal edges, for a total of H(W+1) + W(H+1) (see also the figures at Sample Input/Output). Consider marking these edges by the following two kinds of operations. Operation (1) : Choose a square whose left an...
[ { "input": "2\n1 1\n2 3\n", "output": "4\n800\n" }, { "input": "3\n123 456\n654 321\n1000000 1000000\n", "output": "60549740\n298307903\n656009181\n" } ]
https://atcoder.jp/contests/arc166/tasks/arc166_d
Problem Statement You are given positive integers x_1, \ldots, x_N such that x_1 < \cdots < x_N , and positive integers y_1, \ldots, y_N . Consider a tuple (M, L_1, R_1, \ldots, L_M, R_M) that satisfies all of the following conditions. M is a positive integer. For each j \ (1\leq j\leq M) , L_j and R_j are integers suc...
[ { "input": "3\n1 3 5\n1 3 1\n", "output": "2\n" }, { "input": "3\n1 10 100\n2 3 2\n", "output": "-1\n" }, { "input": "7\n10 31 47 55 68 73 90\n3 7 4 6 3 4 4\n", "output": "56\n" } ]
https://atcoder.jp/contests/arc166/tasks/arc166_e
Problem Statement You are given positive integers n , a , and b such that a<b . An integer pair (L,R) such that 1\leq L\leq R is said to be a good pair when the following condition holds. Let n_a and n_b be respectively the number of multiples of a and the number of multiples of b among the integers between L and R , i...
[ { "input": "1\n3 3 5\n", "output": "4 35\n" }, { "input": "5\n4 3 5\n6 2 4\n1 1 2\n123 456 789\n9876 54 321\n", "output": "10 50\n3 29\n2 4\n5473 140447\n163 641411\n" } ]
https://atcoder.jp/contests/arc166/tasks/arc166_f
Problem Statement You are given a prime number p and non-negative integers a and b . Determine if there is an infinite sequence of non-negative integers t = \bigl(t(0), t(1), t(2), \ldots) that satisfies all of the following conditions. 0\leq t(x) < p for every non-negative integer x . t(x+y)\bigl(1-t(x)t(y)\bigr)\equi...
[ { "input": "4\n11 1 0\n11 1 1\n11 1 3\n11 1 5\n", "output": "Yes\nNo\nNo\nYes\n" }, { "input": "5\n5 0 0\n5 1 1\n5 2 2\n5 3 3\n5 4 4\n", "output": "Yes\nNo\nYes\nYes\nNo\n" }, { "input": "7\n2 3 1\n2 5 0\n5 0 1\n5 0 2\n7 1 4\n11 12345 5\n13 12345 5\n", "output": "Yes\nYes\nNo\nYes\nN...
https://atcoder.jp/contests/abc323/tasks/abc323_a
Problem Statement You are given a string S of length 16 consisting of 0 and 1 . If the i -th character of S is 0 for every even number i from 2 through 16 , print Yes ; otherwise, print No .
[ { "input": "1001000000001010\n", "output": "No\n" }, { "input": "1010100000101000\n", "output": "Yes\n" }, { "input": "1111111111111111\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc323/tasks/abc323_b
Problem Statement There are N players numbered 1 to N , who have played a round-robin tournament. For every match in this tournament, one player won and the other lost. The results of the matches are given as N strings S_1,S_2,\ldots,S_N of length N each, in the following format: If i\neq j , the j -th character of S_i...
[ { "input": "3\n-xx\no-x\noo-\n", "output": "3 2 1\n" }, { "input": "7\n-oxoxox\nx-xxxox\noo-xoox\nxoo-ooo\nooxx-ox\nxxxxx-x\noooxoo-\n", "output": "4 7 3 1 5 2 6\n" } ]
https://atcoder.jp/contests/abc323/tasks/abc323_c
Problem Statement The programming contest World Tour Finals is underway, where N players are participating, and half of the competition time has passed. There are M problems in this contest, and the score A_i of problem i is a multiple of 100 between 500 and 2500 , inclusive. For each i = 1, \ldots, N , you are given a...
[ { "input": "3 4\n1000 500 700 2000\nxxxo\nooxx\noxox\n", "output": "0\n1\n1\n" }, { "input": "5 5\n1000 1500 2000 2000 2500\nxxxxx\noxxxx\nxxxxx\noxxxx\noxxxx\n", "output": "1\n1\n1\n1\n0\n" }, { "input": "7 8\n500 500 500 500 500 500 500 500\nxxxxxxxx\noxxxxxxx\nooxxxxxx\noooxxxxx\noooo...
https://atcoder.jp/contests/abc323/tasks/abc323_d
Problem Statement Initially, there are N sizes of slimes. Specifically, for each 1\leq i\leq N , there are C_i slimes of size S_i . Takahashi can repeat slime synthesis any number of times (possibly zero) in any order. Slime synthesis is performed as follows. Choose two slimes of the same size. Let this size be X , and...
[ { "input": "3\n3 3\n5 1\n6 1\n", "output": "3\n" }, { "input": "3\n1 1\n2 1\n3 1\n", "output": "3\n" }, { "input": "1\n1000000000 1000000000\n", "output": "13\n" } ]
https://atcoder.jp/contests/abc323/tasks/abc323_e
Problem Statement Takahashi has a playlist with N songs. Song i (1 \leq i \leq N) lasts T_i seconds. Takahashi has started random play of the playlist at time 0 . Random play repeats the following: choose one song from the N songs with equal probability and play that song to the end. Here, songs are played continuously...
[ { "input": "3 6\n3 5 6\n", "output": "369720131\n" }, { "input": "5 0\n1 2 1 2 1\n", "output": "598946612\n" }, { "input": "5 10000\n1 2 3 4 5\n", "output": "586965467\n" } ]
https://atcoder.jp/contests/abc323/tasks/abc323_f
Problem Statement Takahashi and a cargo are on a coordinate plane. Takahashi is currently at (X_A,Y_A) , and the cargo is at (X_B,Y_B) . He wants to move the cargo to (X_C,Y_C) . When he is at (x,y) , he can make one of the following moves in a single action. Move to (x+1,y) . If the cargo is at (x+1,y) before the move...
[ { "input": "1 2 3 3 0 5\n", "output": "9\n" }, { "input": "0 0 1 0 -1 0\n", "output": "6\n" }, { "input": "-100000000000000000 -100000000000000000 100000000000000000 100000000000000000 -100000000000000000 -100000000000000000\n", "output": "800000000000000003\n" } ]
https://atcoder.jp/contests/abc323/tasks/abc323_g
Problem Statement You are given a permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) . For each K=0,1,\ldots,N-1 , find the number, modulo 998244353 , of trees with N vertices numbered 1 to N that satisfy the following condition. Among the pairs of vertices (u_i,v_i)\ (u_i < v_i) that are directly connected by an edg...
[ { "input": "3\n1 3 2\n", "output": "1 2 0\n" }, { "input": "10\n3 1 4 10 8 6 9 2 7 5\n", "output": "294448 2989776 12112684 25422152 30002820 20184912 7484084 1397576 108908 2640\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_a
Problem Statement You are given a string S of length N consisting of A , B , and C . Find the position where ABC first appears as a (contiguous) substring in S . In other words, find the smallest integer n that satisfies all of the following conditions. 1 \leq n \leq N - 2 . The string obtained by extracting the n -th ...
[ { "input": "8\nABABCABC\n", "output": "3\n" }, { "input": "3\nACB\n", "output": "-1\n" }, { "input": "20\nBBAAABBACAACABCBABAB\n", "output": "13\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_b
Problem Statement You are given two strings S and T consisting of lowercase English letters. The lengths of S and T are N and M , respectively. (The constraints guarantee that N \leq M .) S is said to be a prefix of T when the first N characters of T coincide S . S is said to be a suffix of T when the last N characters...
[ { "input": "3 7\nabc\nabcdefg\n", "output": "1\n" }, { "input": "3 4\nabc\naabc\n", "output": "2\n" }, { "input": "3 3\nabc\nxyz\n", "output": "3\n" }, { "input": "3 3\naaa\naaa\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_c
Problem Statement The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1 -th, A_2 -th, \dots , A_M -th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.) For each i=1,2,\dots,N , solve...
[ { "input": "3 2\n2 3\n", "output": "1\n0\n0\n" }, { "input": "8 5\n1 3 4 7 8\n", "output": "0\n1\n0\n0\n2\n1\n0\n0\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_d
Problem Statement A polyomino is a puzzle piece in the shape of a connected polygon made by connecting several squares by their edges. There is a grid with four rows and four columns, and three polyominoes that fit within the grid. The shape of the i -th polyomino is represented by 16 characters P_{i,j,k} ( 1 \leq j, k...
[ { "input": "....\n###.\n.#..\n....\n....\n.###\n.##.\n....\n..#.\n.##.\n.##.\n.##.\n", "output": "Yes\n" }, { "input": "###.\n#.#.\n##..\n....\n....\n..#.\n....\n....\n####\n##..\n#...\n#...\n", "output": "Yes\n" }, { "input": "##..\n#..#\n####\n....\n....\n##..\n.##.\n....\n.#..\n.#..\n...
https://atcoder.jp/contests/abc322/tasks/abc322_e
Problem Statement AtCoder Inc. is planning to develop a product. The product has K parameters, whose values are currently all zero. The company aims to raise all parameter values to at least P . There are N development plans. Executing the i -th development plan ( 1 \le i \le N ) increases the value of the j -th parame...
[ { "input": "4 3 5\n5 3 0 2\n3 1 2 3\n3 2 4 0\n1 0 1 4\n", "output": "9\n" }, { "input": "7 3 5\n85 1 0 1\n37 1 1 0\n38 2 0 0\n45 0 2 2\n67 1 1 0\n12 2 2 0\n94 2 2 1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_f
Problem Statement You are given a string S of length N consisting of 0 and 1 . Let S_i denote the i -th character of S . Process Q queries in the order they are given. Each query is represented by a tuple of three integers (c, L, R) , where c represents the type of the query. When c=1 : For each integer i such that L \...
[ { "input": "7 6\n1101110\n2 1 7\n2 2 4\n1 3 6\n2 5 6\n1 4 7\n2 1 7\n", "output": "3\n1\n0\n7\n" } ]
https://atcoder.jp/contests/abc322/tasks/abc322_g
Problem Statement For a non-negative integer sequence S=(S_1,S_2,\dots,S_k) and an integer a , we define the function f(S,a) as follows: f(S,a) = \sum_{i=1}^{k} S_i \times a^{k - i} . For example, f((1,2,3),4) = 1 \times 4^2 + 2 \times 4^1 + 3 \times 4^0 = 27 , and f((1,1,1,1),10) = 1 \times 10^3 + 1 \times 10^2 + 1 \t...
[ { "input": "4 2\n", "output": "5\n" }, { "input": "9 30\n", "output": "31\n" }, { "input": "322322322 200000\n", "output": "140058961\n" } ]
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_a
問題文 1 から N までの番号のついた N 個のりんごがあります. りんご i のおいしさは A_i です. A_i が負であることもありえます. また,整数 K が与えられます. あなたは以下の操作を好きな回数 ( 0 回でもよい) 繰り返すことができます. 整数 i ( 1 \leq i \leq N-K+1 ) を選び,りんご i,i+1,\cdots,i+K-1 を食べる. なお,以前の操作ですでに食べていたりんごについては何もしない. 最終的にあなたが食べたりんごのおいしさの総和としてありうる最大値を求めてください.
[ { "input": "4 2\n2 -1 2 -2\n", "output": "3\n" }, { "input": "5 5\n3 1 4 1 5\n", "output": "14\n" }, { "input": "5 1\n-1 -2 -3 -4 -5\n", "output": "0\n" }, { "input": "20 4\n573641910 -499039319 421342458 893335602 -961457884 -190195710 -497364364 -954575123 41286305 -3106593...
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_b
問題文 1 から N までの番号のついた N 頂点からなる単純連結無向グラフ G があります. G は M 本の辺を持ち, i 番目の辺は頂点 A_i,B_i を結んでいます. 各 k=1,2,\cdots,N について,以下の問題に答えて下さい. G の全域木 T を 1 つ自由にとることを考える. このとき, T における頂点 1,2,\cdots,k の次数の総和としてあり得る最大値を求めよ.
[ { "input": "4 4\n1 2\n2 3\n3 1\n1 4\n", "output": "3\n4\n5\n6\n" }, { "input": "5 5\n4 3\n2 4\n5 2\n5 1\n1 3\n", "output": "2\n4\n5\n7\n8\n" }, { "input": "2 1\n2 1\n", "output": "1\n2\n" }, { "input": "10 13\n10 2\n7 1\n5 8\n3 8\n1 4\n2 5\n7 3\n2 9\n1 2\n9 6\n3 4\n2 6\n9 3\n...
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_c
問題文 整数 N が与えられます. 正整数 x に対し, f(x) を次のように定義します. 非負整数 k であって, x^k \equiv x^{k+1} \mod N が成り立つものを考える. このような k が存在する場合,その最小値を f(x) とする. 存在しない場合 f(x)=0 とする. \sum_{1 \leq x \leq N} f(x) を求めてください. 1 つの入力ファイルにつき, T 個のテストケースに答えて下さい.
[ { "input": "10\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", "output": "1\n1\n3\n1\n3\n1\n9\n5\n3\n1\n" }, { "input": "10\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n", "output": "3\n7\n3\n3\n3\n119\n1\n27\n11\n31\n" } ]
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_d
問題文 長さ N の非負整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. あなたは,次の操作を 高々 2 回 行うことができます. なお, \oplus はビット単位 \mathrm{XOR} 演算を表します. 非負整数 X を自由に選ぶ. その後,各 i=1,2,\cdots,N について, A_i の値を据え置くかもしくは A_i \oplus X で置き換える. 操作後の A の要素の最大値としてあり得る最小値を求めてください. ビット単位 \mathrm{XOR} 演算とは 非負整数 A, B のビット単位 \mathrm{XOR} 、 A \oplus B は、以下のように定義されます。 A \opl...
[ { "input": "4\n0 1 2 3\n", "output": "0\n" }, { "input": "3\n1 4 10\n", "output": "1\n" }, { "input": "5\n2023 2023 2023 2023 2023\n", "output": "0\n" }, { "input": "27\n206264 140501 79 66028 206233 140291 206082 140347 65912 140301 65824 140404 65851 65986 140497 140526 206...
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_e
問題文 長さ N の非負整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. あなたは以下の操作を好きな回数 ( 0 回でもよい) 繰り返すことができます. 整数 i ( 1 \leq i \leq N-1 ) を選ぶ. v=\min(A_i,A_{i+1}) とする. A_i の値を A_i-v で置き換え, A_{i+1} の値を A_{i+1}-v で置き換える. 操作後の A に含まれる 0 の個数の最大値を求めて下さい.
[ { "input": "4\n1 2 1 2\n", "output": "3\n" }, { "input": "5\n1 1 1 1 1\n", "output": "4\n" }, { "input": "6\n6 5 4 3 2 1\n", "output": "5\n" }, { "input": "20\n786820955 250480341 710671229 946667801 19271059 404902145 251317818 22712439 520643153 344670307 274195604 56103210...
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_f
問題文 整数 N,M,K が与えられます. 長さ N の非負整数列 A=(A_1,A_2,\cdots,A_N) であって,以下の条件を両方満たすものを よい数列 と呼ぶことにします. \sum_{1 \leq i \leq N}A_i=M A_1=K よい数列 A に対して, f(A) を次のように定義します. \[ f(A)=\prod_{1 \leq i \leq N-1} {A_i+A_{i+1} \choose A_i } \] すべてのよい数列に対する f(A) の総和を 998244353 で割った余りを求めてください.
[ { "input": "3 2 1\n", "output": "3\n" }, { "input": "5 10 3\n", "output": "27670\n" }, { "input": "100 0 0\n", "output": "1\n" }, { "input": "100 1000 10\n", "output": "75806874\n" } ]
https://atcoder.jp/contests/jsc2023-final/tasks/jsc2023_final_g
問題文 1 から N までの番号のついた N 頂点からなる木 T があります. i 番目の辺は頂点 A_i と B_i を結んでいます. また,各頂点には整数が書かれており,頂点 i に書かれている整数は V_i です. あなたは今から以下の操作を N-1 回行います. T の辺を 1 つ選び,縮約する. 縮約前の 2 つの頂点に書かれていた整数を x,y とおき,縮約後の頂点には x \times y+1 を書き込む. 操作を行う方法は (N-1)! 通りあります. 全ての方法について,最終的に残る 1 頂点に書かれた値を求めたとします. これら (N-1)! 個の値の総和を 998244353 で割った余りを求めてくださ...
[ { "input": "3\n1 2 3\n1 2\n3 2\n", "output": "18\n" }, { "input": "5\n1 1 1 1 1\n2 1\n3 1\n4 1\n5 3\n", "output": "136\n" }, { "input": "8\n3 1 4 1 5 9 2 6\n2 1\n3 2\n4 1\n5 2\n6 5\n7 3\n8 7\n", "output": "54388564\n" }, { "input": "20\n785439575 250040586 709423541 945005786...
https://atcoder.jp/contests/ahc024/tasks/ahc024_a
Problem Statement Given a map of Takahashi City represented on a grid of n\times n squares. Let (0,0) be the coordinates of the top-left square, and (i,j) be the coordinates of the square located i squares down and j squares to the right from there. The city consists of m wards, and the square of color c ( 1\leq c\le...
[]
https://atcoder.jp/contests/abc321/tasks/abc321_a
Problem Statement A positive integer x is called a 321-like Number when it satisfies the following condition. The digits of x are strictly decreasing from top to bottom. In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le i < d : (the i -th digit from the top of x ) > (the ...
[ { "input": "321\n", "output": "Yes\n" }, { "input": "123\n", "output": "No\n" }, { "input": "1\n", "output": "Yes\n" }, { "input": "86411\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc321/tasks/abc321_b
Problem Statement There is an exam structured as follows. The exam consists of N rounds called round 1 to N . In each round, you are given an integer score between 0 and 100 , inclusive. Your final grade is the sum of the N-2 of the scores earned in the rounds excluding the highest and lowest. Formally, let S=(S_1,S_2,...
[ { "input": "5 180\n40 60 80 50\n", "output": "70\n" }, { "input": "3 100\n100 100\n", "output": "0\n" }, { "input": "5 200\n0 0 99 99\n", "output": "-1\n" }, { "input": "10 480\n59 98 88 54 70 24 8 94 46\n", "output": "45\n" } ]
https://atcoder.jp/contests/abc321/tasks/abc321_c
Problem Statement A positive integer x is called a 321-like Number when it satisfies the following condition. This definition is the same as the one in Problem A. The digits of x are strictly decreasing from top to bottom. In other words, if x has d digits, it satisfies the following for every integer i such that 1 \le...
[ { "input": "15\n", "output": "32\n" }, { "input": "321\n", "output": "9610\n" }, { "input": "777\n", "output": "983210\n" } ]
https://atcoder.jp/contests/abc321/tasks/abc321_d
Problem Statement AtCoder cafeteria offers N main dishes and M side dishes. The price of the i -th main dish is A_i , and that of the j -th side dish is B_j . The cafeteria is considering introducing a new set meal menu. A set meal consists of one main dish and one side dish. Let s be the sum of the prices of the mai...
[ { "input": "2 2 7\n3 5\n6 1\n", "output": "24\n" }, { "input": "1 3 2\n1\n1 1 1\n", "output": "6\n" }, { "input": "7 12 25514963\n2436426 24979445 61648772 23690081 33933447 76190629 62703497\n11047202 71407775 28894325 31963982 22804784 50968417 30302156 82631932 61735902 80895728 23078...
https://atcoder.jp/contests/abc321/tasks/abc321_e
Problem Statement There is a tree with N vertices numbered 1 to N . For each i\ (2 \leq i \leq N) , there is an edge connecting vertex i and vertex \lfloor \frac{i}{2} \rfloor . There are no other edges. In this tree, find the number of vertices whose distance from vertex X is K . Here, the distance between two vert...
[ { "input": "5\n10 2 0\n10 2 1\n10 2 2\n10 2 3\n10 2 4\n", "output": "1\n3\n4\n2\n0\n" }, { "input": "10\n822981260158260522 52 20\n760713016476190629 2314654 57\n1312150450968417 1132551176249851 7\n1000000000000000000 1083770654 79\n234122432773361868 170290518806790 23\n536187734191890310 61862 14...
https://atcoder.jp/contests/abc321/tasks/abc321_f
Problem Statement We have a box, which is initially empty. Let us perform a total of Q operations of the following two types in the order they are given in the input. + x Type 1 : Put into the box a ball with the integer x written on it. - x Type 2 : Remove from the box a ball with the integer x written on it. It is gu...
[ { "input": "15 10\n+ 5\n+ 2\n+ 3\n- 2\n+ 5\n+ 10\n- 3\n+ 1\n+ 3\n+ 3\n- 5\n+ 1\n+ 7\n+ 4\n- 3\n", "output": "0\n0\n1\n0\n1\n2\n2\n2\n2\n2\n1\n3\n5\n8\n5\n" } ]
https://atcoder.jp/contests/abc321/tasks/abc321_g
Problem Statement You are creating an electrical circuit using N parts numbered 1 to N and M cables. These parts have a total of M red terminals and M blue terminals, with the i -th red terminal attached to part R_i and the i -th blue terminal attached to part B_i . Each cable connects one red terminal and one blue...
[ { "input": "3 2\n1 2\n3 2\n", "output": "499122178\n" }, { "input": "17 5\n1 1 1 1 1\n1 1 1 1 1\n", "output": "17\n" }, { "input": "8 10\n2 4 7 1 7 6 1 4 8 1\n5 1 5 2 5 8 4 6 1 3\n", "output": "608849831\n" } ]
https://atcoder.jp/contests/arc165/tasks/arc165_a
Problem Statement You are given a positive integer N . Determine if there are two or more (not necessarily distinct) positive integers A_1,A_2,\dots,A_n\ (2 \leq n) that satisfy all of the following conditions: A_1+A_2+\dots+A_n=N . The least common multiple of A_1,A_2,\dots,A_n is N . You have T test cases to solve.
[ { "input": "4\n6\n4\n998244353\n367291763\n", "output": "Yes\nNo\nNo\nYes\n" } ]
https://atcoder.jp/contests/arc165/tasks/arc165_b
Problem Statement You are given a permutation P=(P_1,P_2,\dots,P_N) of integers from 1 to N and an integer K . Consider the following operation on the permutation P . Choose an integer i such that 1 \leq i \leq N-K+1 , and sort P_i,P_{i+1},\dots,P_{i+K-1} in ascending order. That is, let (x_1,x_2,\dots,x_K) be the resu...
[ { "input": "4 3\n2 1 4 3\n", "output": "2 1 3 4\n" }, { "input": "5 1\n3 1 4 2 5\n", "output": "3 1 4 2 5\n" }, { "input": "20 7\n9 4 3 1 11 12 13 15 17 7 2 5 6 20 19 18 8 16 14 10\n", "output": "9 4 3 1 11 12 13 15 17 7 2 5 6 8 18 19 20 16 14 10\n" } ]
https://atcoder.jp/contests/arc165/tasks/arc165_c
Problem Statement There is a simple connected undirected graph with N vertices numbered 1 to N . The graph has M weighted edges, and the i -th edge connects vertices A_i and B_i with a weight of W_i . Additionally, let the weight of a simple path connecting two vertices be the sum of the weights of the edges contained ...
[ { "input": "3 3\n1 2 5\n2 3 6\n1 3 12\n", "output": "11\n" }, { "input": "10 20\n7 10 982219000\n3 10 968366179\n2 4 992330437\n5 6 984414664\n2 8 897295423\n7 9 155604979\n6 8 958833005\n2 3 973209957\n3 7 985173062\n6 10 963895817\n2 10 986243534\n4 5 721724794\n1 3 657562445\n1 6 566370694\n1 4 9...
https://atcoder.jp/contests/arc165/tasks/arc165_d
Problem Statement For an integer sequence X=(X_1,X_2,\dots,X_n) , let X[L,R] denote the integer sequence (X_L,X_{L+1},\dots,X_{R}) . You are given integers N and M , and M quadruples of integers (A_i,B_i,C_i,D_i) . Determine if there is an integer sequence X of length N that satisfies the following condition for every ...
[ { "input": "4 2\n1 3 3 4\n4 4 1 2\n", "output": "Yes\n" }, { "input": "3 2\n1 2 2 3\n2 2 1 1\n", "output": "No\n" }, { "input": "15 20\n2 5 6 14\n11 14 10 10\n13 15 6 10\n8 10 3 8\n7 8 1 9\n2 8 14 15\n14 14 5 12\n6 10 9 9\n1 4 10 14\n5 14 6 7\n8 10 5 8\n8 10 11 15\n4 8 4 11\n7 9 1 4\n8 1...
https://atcoder.jp/contests/arc165/tasks/arc165_e
Problem Statement There is a tree with N vertices numbered 1 to N . The i -th edge connects vertices A_i and B_i . Let us keep performing the following operation until each connected component of the graph has K or fewer vertices. From the N vertices, choose one uniformly at random that belongs to a connected component...
[ { "input": "4 2\n1 2\n2 3\n2 4\n", "output": "249561090\n" }, { "input": "20 10\n16 8\n6 2\n18 3\n3 12\n5 1\n13 9\n13 19\n3 11\n5 13\n17 6\n8 14\n1 16\n16 20\n11 15\n3 10\n15 4\n5 18\n1 7\n1 17\n", "output": "181196154\n" } ]
https://atcoder.jp/contests/arc165/tasks/arc165_f
Problem Statement An integer sequence of length 2n , X=(X_1,X_2,\dots,X_{2n}) , such that X_{2i-1}=X_{2i} for every i=1,2,\dots,n is called a good sequence . There is an integer sequence of length 2N , A=(A_1,A_2,\dots,A_{2N}) , which contains each integer i=1,2,\dots,N exactly twice. We want to make A a good sequence ...
[ { "input": "3\n3 2 1 2 3 1\n", "output": "2 2 3 3 1 1\n" }, { "input": "3\n1 1 2 2 3 3\n", "output": "1 1 2 2 3 3\n" }, { "input": "15\n15 12 11 10 5 11 13 2 6 14 3 6 5 14 10 15 1 2 13 9 7 4 9 1 3 8 12 4 8 7\n", "output": "11 11 5 5 6 6 10 10 14 14 15 15 2 2 12 12 13 13 1 1 3 3 9 9 4...
https://atcoder.jp/contests/abc320/tasks/abc320_a
Problem Statement You are given positive integers A and B . Print the value A^B+B^A .
[ { "input": "2 8\n", "output": "320\n" }, { "input": "9 9\n", "output": "774840978\n" }, { "input": "5 6\n", "output": "23401\n" } ]
https://atcoder.jp/contests/abc320/tasks/abc320_b
Problem Statement You are given a string S . Find the maximum length of a contiguous substring of S that is a palindrome. Note that there is always a contiguous substring of S that is a palindrome.
[ { "input": "TOYOTA\n", "output": "5\n" }, { "input": "ABCDEFG\n", "output": "1\n" }, { "input": "AAAAAAAAAA\n", "output": "10\n" } ]
https://atcoder.jp/contests/abc320/tasks/abc320_c
Problem Statement This problem is an easier version of Problem G. There is a slot machine with three reels. The arrangement of symbols on the i -th reel is represented by the string S_i . Here, S_i is a string of length M consisting of digits. Each reel has a corresponding button. For each non-negative integer t , Taka...
[ { "input": "10\n1937458062\n8124690357\n2385760149\n", "output": "6\n" }, { "input": "20\n01234567890123456789\n01234567890123456789\n01234567890123456789\n", "output": "20\n" }, { "input": "5\n11111\n22222\n33333\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc320/tasks/abc320_d
Problem Statement There are N people numbered 1 to N on a coordinate plane. Person 1 is at the origin. You are given M pieces of information in the following form: From person A_i 's perspective, person B_i is X_i units away in the positive x -direction and Y_i units away in the positive y -direction. Determine the coo...
[ { "input": "3 2\n1 2 2 1\n1 3 -1 -2\n", "output": "0 0\n2 1\n-1 -2\n" }, { "input": "3 2\n2 1 -2 -1\n2 3 -3 -3\n", "output": "0 0\n2 1\n-1 -2\n" }, { "input": "5 7\n1 2 0 0\n1 2 0 0\n2 3 0 0\n3 1 0 0\n2 1 0 0\n3 2 0 0\n4 5 0 0\n", "output": "0 0\n0 0\n0 0\nundecidable\nundecidable\n"...
https://atcoder.jp/contests/abc320/tasks/abc320_e
Problem Statement There are N people gathered for an event called Flowing Noodles. The people are lined up in a row, numbered 1 to N in order from front to back. During the event, the following occurrence happens M times: At time T_i , a quantity W_i of noodles is flown down. The person at the front of the row gets all...
[ { "input": "3 5\n1 1 3\n2 10 100\n4 100 10000\n10 1000 1000000000\n100 1000000000 1\n", "output": "101\n10\n1000\n" }, { "input": "3 1\n1 1 1\n", "output": "1\n0\n0\n" }, { "input": "1 8\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7\n8 8 8\n", "output": "15\n" } ]
https://atcoder.jp/contests/abc320/tasks/abc320_f
Problem Statement You are planning to travel from coordinate 0 to coordinate X_N on a number line, then turn around and return to coordinate 0 . Here, you can only move in the positive direction on the outbound trip and in the negative direction on the return trip. You will travel by car. The car consumes one liter of ...
[ { "input": "4 10\n2 5 9 11\n8 10\n5 8\n4 9\n", "output": "9\n" }, { "input": "1 1\n100000\n", "output": "-1\n" }, { "input": "5 20\n4 13 16 18 23\n1 16\n2 8\n4 11\n8 13\n", "output": "13\n" } ]
https://atcoder.jp/contests/abc320/tasks/abc320_g
Problem Statement This problem is a harder version of Problem C, with N reels instead of three and a greater upper limit for M . There is a slot machine with N reels. The arrangement of symbols on the i -th reel is represented by the string S_i . Here, S_i is a string of length M consisting of digits. Each reel has a c...
[ { "input": "3 10\n1937458062\n8124690357\n2385760149\n", "output": "6\n" }, { "input": "10 20\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n0123456...
https://atcoder.jp/contests/joi2024yo1a/tasks/joi2024_yo1a_a
問題文 リンゴが X 個,ミカンが Y 個,バナナが 3 個ある.リンゴとミカンとバナナが合わせて何個あるかを求めよ.
[ { "input": "2\n4\n", "output": "9\n" }, { "input": "15\n30\n", "output": "48\n" }, { "input": "0\n0\n", "output": "3\n" } ]