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. Takahashi and Aoki will play a game using this grid. Takahashi goes first, and they take turns performing the following operation: Choose a cell (i, j) (1\leq i, j \leq 3) that is still painted white (it can be shown that such a cell always exists at the time of the operation). The player performing the operation scores A_{i,j} points. Then, if the player is Takahashi, he paints the cell (i, j) red; if the player is Aoki, he paints it blue. After each operation, the following checks are made: Check if there are three consecutive cells painted the same color (red or blue) in any row, column, or diagonal. If such a sequence exists, the game ends immediately, and the player whose color forms the sequence wins. Check if there are white cells left. If no white cells remain, the game ends, and the player with the higher total score wins. It can be shown that the game will always end after a finite number of moves, and either Takahashi or Aoki will win. Determine which player wins if both play optimally for victory.
[ { "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 subsequences are distinguished if they are taken from different positions in the sequence, even if they coincide as sequences. Also, the LCM of a sequence with a single element is that element itself.
[ { "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 length N that satisfies the following condition, and if it exists, find the lexicographically smallest such sequence. For each i=1,2,\dots,N , both of the following hold: The sequence (S_{i-A_i},S_{i-A_i+1},\dots,S_{i+A_i}) is a palindrome. If 2 \leq i-A_i and i+A_i \leq N-1 , the sequence (S_{i-A_i-1},S_{i-A_i},\dots,S_{i+A_i+1}) is not a palindrome.
[ { "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} . There are M stamps, each with 3 \times 3 squares. On stamp m (0 \leq m \leq M - 1) , an integer s_{m,i,j} is written in each square (i, j) . You can perform the following operation at most K times. Select a stamp m and a square (p, q) (0 \leq p, q \leq N - 3) on the board. Press the stamp in such a way that its coordinates (0, 0) align with the square (p, q) on the board. This operation increases the value of the square (p + i, q + j) on the board by s_{m,i,j} for each square (i, j) (0 \leq i, j \leq 2) on the stamp. You cannot press a stamp beyond the bounds of the board, nor can you rotate stamps. You can use the same stamp multiple times or have stamps that are not used at all. It is also acceptable to press stamps multiple times on the same square. Please maximize the sum of the remainders obtained by dividing the values of each square on the final board by 998244353 .
[ { "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 59818053 858072870 914485919 446805915 138548911 345246064 245004268\n477044564 12166358 931360092 799278793 865992483 339109407 614502753 736626962 801948371\n281576446 640350568 771040910 823574138 350308411 930294372 585808288 700370699 426021090\n289960346 566527193 119082954 148354804 902944838 516738876 930961873 812731496 172242940\n921564237 662077279 49476329 593121834 377147282 862136854 791213996 686329230 7403815\n501340655 979965930 839183331 303883398 490179686 492481098 160122974 114672637 82049594\n975741402 918762324 476374754\n906657349 359110092 978536040\n84599745 368692094 744129488\n261705356 216870728 556481274\n317767465 457532475 532110106\n125703669 839188333 425571806\n291667039 37052662 1276219\n305291998 653050074 220563016\n332525785 400712871 520185762\n393148157 178758620 933441647\n205044518 579917402 498932315\n411369672 664953833 274696537\n654712800 802006144 682742340\n864455037 533661060 207561332\n605472509 577911453 942938903\n576270626 688256275 33493069\n481710779 902547317 817131623\n291465541 863597953 772086608\n417987422 136453150 615090472\n760882895 841541285 914039365\n359505208 780663578 774735965\n188919347 431579412 464452916\n854985721 70294202 663019966\n157776983 3557297 439447307\n621014939 759908222 932643321\n184225959 884108948 693640679\n361651737 846036661 975413204\n479224933 700946167 622558051\n495003914 325785117 513339213\n70238660 857642866 297571112\n374937799 48000646 849682071\n528095305 232520890 469018467\n952599070 610262715 232403912\n316958602 24859140 385411996\n304561106 853230688 859071983\n266806117 99442261 881952734\n708824083 752081152 915353520\n261135036 48934653 945657700\n255395109 742827901 445178710\n906120195 565840603 316740986\n736297599 447489530 680619574\n654670835 694926131 897183420\n958993686 813942152 196144122\n324334792 928014325 852381591\n194958307 642660824 128931372\n303306950 687790222 930130148\n591510740 614681348 113389792\n160195595 683240268 555351204\n218729338 196609467 724290289\n47413572 552092134 337674489\n410209863 549012244 186533965\n452647000 449090484 733453206\n106059177 888943736 940915649\n692940521 382797569 893532614\n52383100 783583840 634565824\n168433778 751831139 356971915\n870682287 872212766 75893565\n262231629 844472478 843213274\n499286296 502562654 725538734\n467780532 720085509 907848638\n", "output": "4\n0 1 6\n6 6 6\n18 6 1\n16 1 5\n" } ]
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 those points. Here, we use the Euclidean distance: for two points (x_1,y_1) and (x_2,y_2) , the distance between them is \sqrt{(x_1-x_2)^{2}+(y_1-y_2)^{2}} .
[ { "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 possible deliciousness of the bean you eat.
[ { "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. T : An empty cell and the goal point. Takahashi can move from his current cell to a vertically or horizontally adjacent empty cell by consuming 1 energy. He cannot move if his energy is 0 , nor can he exit the grid. There are N medicines in the grid. The i -th medicine is at the empty cell (R_i, C_i) and can be used to set the energy to E_i . Note that the energy does not necessarily increase. He can use the medicine in his current cell. The used medicine will disappear. Takahashi starts at the start point with 0 energy and wants to reach the goal point. Determine if this is possible.
[ { "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, \ldots, N , let \displaystyle f(x) = \sum_{i=1}^{N} (C_i \times d(x, i)) . Find \displaystyle \min_{1 \leq v \leq N} f(v) .
[ { "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 the number of pairs of integers (i,j) satisfying 1 \leq i < j \leq N such that A_i and A_j are similar.
[ { "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 that 1\leq i, j\leq N and an integer x , and add x to A_{i,j} . The cost of this operation is |x| . You are given a positive integer d . Your goal is to satisfy the following condition: The difference between the integers written in any two cells that are vertically or horizontally adjacent is at least d . More formally, the following two conditions are satisfied: |A_{i,j}-A_{i+1,j}|\geq d for all integers i and j such that 1\leq i\leq N-1 and 1\leq j\leq N . |A_{i,j}-A_{i,j+1}|\geq d for all integers i and j such that 1\leq i\leq N and 1\leq j\leq N-1 . Achieve this goal with a total cost of \frac12 dN^2 or less.
[ { "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 completely within the 9:00-18:00 time slot at their base. Find the maximum number of employees who can participate when deciding the meeting time to allow as many employees as possible to participate.
[ { "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 and only if the j -th character of S_i is # . These sensors interact with other sensors in the squares horizontally, vertically, or diagonally adjacent to them and operate as one sensor. Here, a cell (x, y) and a cell (x', y') are said to be horizontally, vertically, or diagonally adjacent if and only if \max(|x-x'|,|y-y'|) = 1 . Note that if sensor A interacts with sensor B and sensor A interacts with sensor C , then sensor B and sensor C also interact. Considering the interacting sensors as one sensor, find the number of sensors on this grid.
[ { "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.#.#...#.......#.#...#......##..#..#...#..#....\n.##....#####....#....#####..#.#.#..#......#####\n.#.#...#........#....#......#..##..#...#..#....\n.#..#..#####....#....#####..#...#...###...#####\n", "output": "7\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 the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer). However, after printing once, it requires a charge time of 1 microseconds before it can print again. What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?
[ { "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 company car, and D_{i,j} \times B + C minutes by train. You can switch from company car to train, but not vice versa. You can do so without spending time, but only in a city. What is the minimum time in minutes to travel from city 1 to city N ?
[ { "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\n10017 32336 108914 0 234705\n373342 164457 57762 234705 0\n", "output": "168604826785\n" } ]
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 sensor (1\leq j \leq 2) : Can monitor a section of length L_j meters. The price is C_j per sensor, and you can use at most K_j sensors of this type in total. You can divide one section into several sections for monitoring. It is fine if the sections monitored by the sensors overlap, or if they monitor more than the length of the section you want to monitor. For example, when L_1=4 and L_2=2 , you can use one type- 1 sensor to monitor a section of length 3 meters, or use one type- 1 and one type- 2 sensor to monitor a section of length 5 meters. Determine whether it is possible to monitor all N sections, and if it is possible, find the minimum total cost of the necessary sensors.
[ { "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 characters from the string.
[ { "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 slice of toast is on some plate. Let B_{j} be the sum of the deliciousness of the toast on the j -th plate ( 0 if the plate has no toast on it). Then, let the unbalancedness be \sum_{j=1}^{M} B_{j}^{2} . Find the minimum possible value of the unbalancedness.
[ { "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 graph G with N vertices numbered 1 to N . For every integer pair (i,j) such that 1\leq i\lt j\leq N , the following holds for G . If j-i\leq K , there is an edge between vertex i and vertex j , whose weight is \max(A_{P_{i}},A_{P_{j}}) . If j-i\gt K , there is no edge between vertex i and vertex j . Find the total weight of the edges of a minimum spanning tree of G . Find the sum, modulo 998244353 , of f(P) over all permutations P=(P_{1},P_{2},\dots ,P_{N}) of (1,2,\dots,N) .
[ { "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 possible to make x equal 1 by repeating the substitution x\leftarrow Q_{x} some number of times. You want to make P a good permutation by performing the following operation on P zero or more times. Choose integers i and j such that 1\leq i\lt j \leq N , and swap P_{i} and P_{j} . Let M be the minimum number of times you must perform the operation to make P a good permutation. Find the lexicographically smallest good permutation that can be obtained by performing the operation M times on P . For each input file, you have T test cases to solve. What is lexicographical order on sequences? A sequence S = (S_1,S_2,\ldots,S_{|S|}) is said to be lexicographically smaller than a sequence T = (T_1,T_2,\ldots,T_{|T|}) when one of the following 1. or 2. holds. Here, |S| and |T| denote the lengths of S and T , respectively. |S| \lt |T| and (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}) . There is an integer 1 \leq i \leq \min\lbrace |S|, |T| \rbrace that satisfies both of the following. (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1}) . S_i is smaller than T_i (as a number).
[ { "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 contains exactly one square of area 1 whose vertices are all lattice points. You are given a positive integer S . Determine if there is a good triangle of area \frac{S}{2} , and construct one if it exists. For each input file, you have T test cases to solve.
[ { "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, q=(q_{1},q_{2},\dots,q_{N-1}) is a permutation of (1,2,\dots,N-1) . Let cost(u,v) be the maximum weight of an edge in the simple path connecting vertices u and v . Find \sum_{u=1}^{N} \sum_{v=u+1}^{N} cost(u,v) . Problem: tomato You are given an integer a such that 1\leq a\lt K . There are \frac{((N-1)!)^{2}}{K-1} possible pairs of p and q in the problem "potato" such that p_{K}=a . Find the sum, modulo 998244353 , of the answers to the problem over all those pairs. For each a=1,\dots,K-1 , find the answer to the problem "tomato".
[ { "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 obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in T . T' is a string obtained by deleting one character from T . T' is a string obtained by changing one character in T to another lowercase English letter. You are given the string T' received by Aoki and N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S_1, S_2, \ldots, S_N that could equal the string T sent by Takahashi.
[ { "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 S . Find the number of square numbers that can be represented as \displaystyle \sum _ {i=1} ^ N s _ {p _ i}10 ^ {N-i} with a permutation P=(p _ 1,p _ 2,\ldots,p _ N) of (1, \dots, N) .
[ { "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 concatenation of S_i and S_j in this order contains T as a (not necessarily contiguous) subsequence.
[ { "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 value of the following for a path P from vertex 1 to vertex N . The total beauty of all edges on P divided by the total cost of all edges on P . Here, the constraints guarantee that the given graph has at least one path from vertex 1 to vertex N .
[ { "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 6 1 2\n5 6 5 2\n2 3 2 3\n6 10 4 4\n4 6 3 4\n4 8 4 1\n3 5 3 2\n2 4 3 2\n3 5 4 2\n1 5 3 4\n1 2 4 2\n3 7 2 2\n7 8 1 3\n", "output": "1.8333333333333333\n" } ]
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 by a triple of integers (t _ i,s _ i,x _ i) and corresponds to the following operation (see also the explanations in Sample Input/Output). When t _ i=1 , he removes the elements following the x _ i -th element from the sequence numbered s _ i (0\leq s _ i\lt i) , and creates a new sequence numbered i with the removed elements, keeping their order. When t _ i=2 , he removes the elements greater than x _ i from the sequence numbered s _ i (0\leq s _ i\lt i) , and creates a new sequence numbered i with the removed elements, keeping their order. For a sequence X of length L , every element of X is among "the elements following the 0 -th element." Also, for any l such that L\leq l , no element of X is among "the elements following the l -th element." For i=1,2,\ldots,Q , find the length of the sequence numbered i immediately after the i -th operation.
[ { "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 23 24 28 21 14 26 15 17\n10\n1 0 22\n1 0 21\n2 0 15\n1 0 9\n1 3 6\n2 3 18\n1 6 2\n1 0 1\n2 5 20\n2 7 26\n", "output": "8\n1\n8\n4\n2\n5\n3\n8\n1\n1\n" } ]
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 とする。 列 l の先頭 2 人は列から抜け、その 2 人で試合を行う。試合に勝った方は列 l+1 の後ろに並び、負けた方は列 0 の後ろに並ぶ。 手順 1. に戻る。 この大会で行われる試合の回数を 998244353 で割ったあまりを求めてください。 ただし、試合に引き分けはないものとします。また、各試合の結果に依らず答えは一意に定まることが証明できます。
[ { "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, p_2 \in L に対し、 p_1 と p_2 を端点とする L 上の曲線が存在するとき、かつそのときに限り p_1 \sim p_2 である。 なお、この値は 10^{18} 以下の整数になることが証明できます。 T 個のテストケースが与えられるので、それぞれについて答えてください。
[ { "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 -424\n734 117 -405\n830 -10 -393\n-334 137 154\n74 459 -92\n-651 -93 -131\n879 148 45\n-48 126 -660\n", "output": "1\n0\n3\n" } ]
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> <digit_string> ::= <digit> | <digit> <digit_string> <non_zero_digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" <digit> ::= "0" | <non_zero_digit> 記号はそれぞれ以下の意味を表します。 N : N + : 足し算 + * : 掛け算 \times log : 自然対数 \log ( , ) : 括弧、ただし足し算 + や掛け算 * よりも先に計算される ^ : 累乗、ただし足し算 + や掛け算 * よりも先に計算される <number> は十進表記の整数を表し、 1 以上 10^9 以下であることが保証されます。また、 "log(" <expr> ")^" <number> は (\log( \text{<expr>} ))^{ \text{<number>} } を表すものとします。 例えば、以下の文字列は <expr> シンボルになり得ます。 N+log(N)*N N + \log(N) \times N を表します。 N^1+N^2+log(N)+log(N)^1000000000 N^1 + N^2 + \log(N) + (\log(N))^{1000000000} を表します。 N*(N+(log(N+N)^2*N))+(((N))) N \times (N + (\log(N+N))^2 \times N) +(((N))) を表します。 (log((N))) (\log((N))) を表します。 また、以下の文字列は <expr> シンボルになり得ません。 (log(N)+N)^2 <factor> において、 "(" <expr> ")^" <number> は使われません。 (log(N))^2 (N )N( N^1000000001 N^02 N^0 N^N 2 log(3) N-log(N) log(N)/N 正の整数 N によっては F(N) が定義されるとは限りませんが、どのような入力でも、ある正の整数 N_0 が存在して、 N \geq N_0 を満たす全ての正の整数 N で F(N) が定義されることが証明できます。 そこで、極限 \[ \lim_{N \to \infty} \frac{F(N)}{N^a(\log N)^b} \] が有限の値( 0 を含む)に収束するような非負整数の組 (a, b) 全体の集合を S とします。 S の 辞書順最小の組 を出力してください。 ただし、非負整数の組 (a, b) が S の辞書順最小の組であるとは、 (a, b) が S に属し、さらに S に属する任意の組 (a', b') について次のいずれかが成り立つこととします。 a < a' a = a' かつ b \le b' ここで、 S は空集合でなく、さらに S の辞書順最小の組が存在することが証明されます。
[ { "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 にコーラをあげる。 P \neq Q であるなら、Alice は P_{i}\neq Q_{i} となる最小の i を Bob に教える。 例えば、 P=(4,3,2,1) であるときに Q=(4,3,1,2) として質問すると、Alice は Bob に「 P_{i}\neq Q_{i} となる i が存在して、その i のうち最も小さいものは 3 である」ことを教えます。 M 回目の質問の後に P を特定したとしてもコーラはもらえないことに注意してください。 はじめ、Bob は P についての情報を持っていません。Bob が Alice からコーラをもらえる確率を最大化したときのその確率を \text{mod} \;998244353 で求めてください。 確率 \text{mod} \;998244353 の定義 この問題で求める確率は必ず有理数になることが証明できます。また、この問題の制約化では、求める確率を既約分数 \frac{y}{x} で表したときに x が 998244353 で割り切れないことが保証されます。このとき、 y \equiv xz \pmod{998244353} を満たす 0\leq z\lt 998244353 がただ一つ存在するので、 z を出力してください。
[ { "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 個のテストケースが与えられるので、それぞれについて答えてください。 \mathrm{AND} とは 非負整数 n, m の bit ごとの論理積 n ~ \mathrm{AND} ~ m は、以下のように定義されます。 n ~ \mathrm{AND} ~ m を二進表記した際の 2^k ~ (k \geq 0) の位の数は、 n,m を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1 、そうでなければ 0 である。 \mathrm{OR} とは 非負整数 n, m の bit ごとの論理和 n ~ \mathrm{OR} ~ m は、以下のように定義されます。 n ~ \mathrm{OR} ~ m を二進表記した際の 2^k ~ (k \geq 0) の位の数は、 n,m を二進表記した際の 2^k の位の数のうちいずれか(両方でもよい)が 1 であれば 1 、そうでなければ 0 である。
[ { "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}) を頂点とする長方形を平面に配置することができます。 任意の異なる 2 つの長方形の共通部分が、面積が 0 となるか、または一方の長方形に一致するように N 個の長方形を平面に配置することができるかを判定し、できるならばそのような配置の方法を 1 つ求めてください。
[ { "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 or they have equal weights. After repeating this operation Q times, divide the items into D sets of equal total weight as much as possible.
[]
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 (2) :Choose a character C in X and replace it with B . Operation (3) :Choose a substring AB in X and replace it with BA . More formally, choose an i such that the i -th and (i+1) -th characters of X are A and B , respectively, and replace the former with B and the latter with A . You have T test cases to solve.
[ { "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 contain at least one multiple of a , at least one multiple of b , and at least one multiple of c . Find the minimum number of operations required to achieve this objective.
[ { "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 and upper edges are unmarked when performing this operation. Mark the left and upper edges of that square. Operation (2) : Choose a square whose right and lower edges are unmarked when performing this operation. Mark the right and lower edges of that square. Find the number, modulo 998244353 , of possible sets of edges that are eventually marked when Operations (1) and (2) can be performed any number of times, possibly zero. You have T test cases to solve.
[ { "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 such that L_j\leq R_j . For each i \ (1\leq i\leq N) , exactly y_i integers j \ (1\leq j\leq M) satisfy L_j\leq x_i\leq R_j . It can be proved that such a tuple always exists. Find the maximum value of \min \lbrace R_j-L_j\mid 1\leq j\leq M\rbrace for such a tuple. If there is no maximum value, print -1 .
[ { "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 , inclusive. Then, n_a - n_b = n . It can be proved that a good pair always exists. Report the good pair with the largest value of R-L . If multiple such pairs exist, report the one with the smallest L (from 1\leq L , the sought (L, R) with the smallest L exists and is unique). You have T test cases to solve.
[ { "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)\equiv t(x)+t(y)\pmod{p} for all non-negative integers x and y . t(a)=b . You have T test cases to solve.
[ { "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\nNo\nNo\nYes\n" } ]
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 is o or x . o means that player i won against player j , and x means that player i lost to player j . If i=j , the j -th character of S_i is - . The player with more wins ranks higher. If two players have the same number of wins, the player with the smaller player number ranks higher. Report the player numbers of the N players in descending order of rank.
[ { "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 string S_i that indicates which problems player i has already solved. S_i is a string of length M consisting of o and x , where the j -th character of S_i is o if player i has already solved problem j , and x if they have not yet solved it. Here, none of the players have solved all the problems yet. The total score of player i is calculated as the sum of the scores of the problems they have solved, plus a bonus score of i points. For each i = 1, \ldots, N , answer the following question. At least how many of the problems that player i has not yet solved must player i solve to exceed all other players' current total scores? Note that under the conditions in this statement and the constraints, it can be proved that player i can exceed all other players' current total scores by solving all the problems, so the answer is always defined.
[ { "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\nooooxxxx\noooooxxx\nooooooxx\n", "output": "7\n6\n5\n4\n3\n2\n0\n" } ]
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 a new slime of size 2X appears. Then, the two original slimes disappear. Takahashi wants to minimize the number of slimes. What is the minimum number of slimes he can end up with by an optimal sequence of syntheses?
[ { "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: once a song ends, the next chosen song starts immediately. The same song can be chosen consecutively. Find the probability that song 1 is being played (X + 0.5) seconds after time 0 , modulo 998244353 . How to print a probability modulo 998244353 It can be proved that the probability to be found in this problem is always a rational number. Also, the constraints of this problem guarantee that when the probability to be found is expressed as an irreducible fraction \frac{y}{x} , x is not divisible by 998244353 . Then, there is a unique integer z between 0 and 998244352 , inclusive, such that xz \equiv y \pmod{998244353} . Report this z .
[ { "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, move it to (x+2,y) . Move to (x-1,y) . If the cargo is at (x-1,y) before the move, move it to (x-2,y) . Move to (x,y+1) . If the cargo is at (x,y+1) before the move, move it to (x,y+2) . Move to (x,y-1) . If the cargo is at (x,y-1) before the move, move it to (x,y-2) . Find the minimum number of actions required to move the cargo to (X_C,Y_C) .
[ { "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 edge in the tree, exactly K pairs satisfy P_{u_i}>P_{v_i} .
[ { "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 through (n+2) -th characters of S is ABC . If ABC does not appear in S , print -1 .
[ { "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 of T coincide S . If S is both a prefix and a suffix of T , print 0 ; If S is a prefix of T but not a suffix, print 1 ; If S is a suffix of T but not a prefix, print 2 ; If S is neither a prefix nor a suffix of T , print 3 .
[ { "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 the following problem. How many days later from the i -th day will fireworks be launched for the first time on or after the i -th day? If fireworks are launched on the i -th day, it is considered to be 0 days later.
[ { "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 \leq 4 ). They describe the state of the grid when the i -th polyomino is placed on it. If P_{i, j, k} is # , the square at the j -th row from the top and k -th column from the left is occupied by the polyomino; if it is . , the square is not occupied. (Refer to the figures at Sample Input/Output 1 .) You want to fill the grid with all three polyominoes so that all of the following conditions are satisfied. All squares of the grid are covered by the polyominoes. The polyominoes must not overlap each other. The polyominoes must not stick out of the grid. The polyominoes may be freely translated and rotated but may not be flipped over. Can the grid be filled with the polyominoes to satisfy these conditions?
[ { "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.#..\n.#..\n", "output": "No\n" }, { "input": "....\n..#.\n....\n....\n....\n..#.\n....\n....\n....\n..#.\n....\n....\n", "output": "No\n" }, { "input": "....\n####\n#...\n#...\n....\n####\n...#\n..##\n....\n..##\n..#.\n..##\n", "output": "No\n" }, { "input": "###.\n.##.\n..#.\n.###\n....\n...#\n..##\n...#\n....\n#...\n#...\n#...\n", "output": "Yes\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 parameter by A_{i,j} for every integer j such that 1 \le j \le K , at the cost of C_i . A development plan cannot be executed more than once. Determine whether the company can achieve its goal, and if it can, find the minimum total cost required to achieve the goal.
[ { "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 \leq i \leq R , if S_i is 1 , change it to 0 ; if it is 0 , change it to 1 . When c=2 : Let T be the string obtained by extracting the L -th through R -th characters of S . Print the maximum number of consecutive 1 s in T .
[ { "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 \times 10^1 + 1 \times 10^0 = 1111 . You are given positive integers N and X . Find the number, modulo 998244353 , of triples (S,a,b) of a sequence of non-negative integers S=(S_1,S_2,\dots,S_k) and positive integers a and b that satisfy all of the following conditions. k \ge 1 a,b \le N S_1 \neq 0 S_i < \min(10,a,b)(1 \le i \le k) f(S,a) - f(S,b) = X
[ { "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 -310659388 -451608793 122064200 -719921087 87712135 43831420 714154567 -451280 -161259952 488561040 -501663741\n", "output": "2561828581\n" } ]
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", "output": "3\n8\n10\n12\n13\n14\n15\n16\n17\n18\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 \oplus B を二進表記した際の 2^k ( k \geq 0 ) の位の数は、 A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1 、そうでなければ 0 である。 例えば、 3 \oplus 5 = 6 となります (二進表記すると: 011 \oplus 101 = 110 )。 一般に k 個の非負整数 p_1, p_2, p_3, \dots, p_k のビット単位 \mathrm{XOR} は (\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k) と定義され、これは p_1, p_2, p_3, \dots, p_k の順番によらないことが証明できます。
[ { "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 206162 140513 66031 206294 206085 186 206157 66019 140407 65923 65806\n", "output": "192\n" } ]
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 561032101 140039457 543856068 521915711 857077284 499774361 419370025 744280520 249168130\n", "output": "13\n" } ]
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 で割った余りを求めてください. 辺の縮約とは グラフ G について,辺 (u,v) を縮約する操作とは,頂点 u,v を 1 つの頂点にまとめる操作です. より正確には,縮約とは G を以下のように変化させる操作です. G から辺 (u,v) および頂点 u,v を削除し,新しい頂点 (これを w と呼ぶ) を追加する. u に接続する各辺 (u,x) を削除し,変わりに辺 (w,x) を追加する. v に接続する各辺 (v,x) を削除し,変わりに辺 (w,x) を追加する.
[ { "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 19237226 404191280 250876593 22672564 519729087 344065187 273714213 560047126 139793597 542901248 520999410 855572558 498896933 418633758 742973826 248730679\n12 9\n19 18\n9 5\n6 20\n8 16\n3 6\n4 14\n6 12\n16 12\n3 17\n14 19\n15 16\n17 13\n11 14\n17 2\n9 7\n18 10\n19 3\n1 18\n", "output": "768399804\n" } ]
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\leq m ) corresponds to the c -th ward. The outside of the n\times n squares correspond to the outside of the city and is colored 0 . Two squares are defined as "adjacent" if they share an edge, and a set of squares is defined as "connected" if any two squares can reach each other via adjacent squares. In the given map, for each color c, the set of squares of color c is guaranteed to be connected. Your task is to create a map represented on a grid of n\times n squares that satisfies all of the following conditions. For every color c ( 0\leq c\leq m ), squares of color c must be connected. Note that since the outside of the n\times n squares is colored 0 , squares of color 0 can be connected through the outside squares. For every pair of colors c and d ( 0\leq c<d\leq m ), the adjacency of a set of squares of color c and a set of squares of color d in the original map and the created map must be identical. That is, if and only if there exist adjacent squares of color c and d in the original map, there exist adjacent squares of color c and d in the created map. Note that since the outside of the n\times n squares is colored 0 , the squares on the boundary are considered to be adjacent to squares of color 0 .
[]
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 (i+1) -th digit from the top of x ). Note that all one-digit positive integers are 321-like Numbers. For example, 321 , 96410 , and 1 are 321-like Numbers, but 123 , 2109 , and 86411 are not. You are given N as input. Print Yes if N is a 321-like Number, and No otherwise.
[ { "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,\dots,S_N) be the sequence of the scores earned in the rounds sorted in ascending order, then the final grade is S_2+S_3+\dots+S_{N-1} . Now, N-1 rounds of the exam have ended, and your score in round i was A_i . Print the minimum score you must earn in round N for a final grade of X or higher. If your final grade will never be X or higher no matter what score you earn in round N , print -1 instead. Note that your score in round N can only be an integer between 0 and 100 .
[ { "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 i < d : (the i -th digit from the top of x ) > (the (i+1) -th digit from the top of x ). Note that all one-digit positive integers are 321-like Numbers. For example, 321 , 96410 , and 1 are 321-like Numbers, but 123 , 2109 , and 86411 are not. Find the K -th smallest 321-like Number.
[ { "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 main dish and the side dish, then the price of the set meal is \min(s,P) . Here, P is a constant given in the input. There are NM ways to choose a main dish and a side dish for a set meal. Find the total price of all these set meals.
[ { "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 23078537 7723857\n", "output": "2115597124\n" } ]
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 vertices u and v is defined as the number of edges in the simple path connecting vertices u and v . You have T test cases to solve.
[ { "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\n594688604155374934 53288633578 39\n1000000000000000000 120160810 78\n89013034180999835 14853481725739 94\n463213054346948152 825589 73\n", "output": "1556480\n140703128616960\n8\n17732923532771328\n65536\n24576\n2147483640\n33776997205278720\n7881299347898368\n27021597764222976\n" } ]
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 guaranteed that the box contains a ball with the integer x written on it before the operation. For the box after each operation, solve the following problem. Find the number, modulo 998244353 , to pick up some number of balls from the box so that the integers written on them sum to K . All balls in the box are distinguishable.
[ { "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 terminal. In particular, it is allowed to connect two terminals attached to the same part. You cannot connect two or more cables to a terminal. Therefore, there are M! ways in total to connect the M cables (the cables are not distinguished from each other). Let s be the number of connected components when seeing this circuit as a graph with parts as vertices and cables as edges. Find the expected value, modulo 998244353 , of s when randomly choosing the way to connect the M cables out of the M! ways. What does it mean to find an expected value modulo 998244353 ? It can be proved that the sought expected value is always a rational number. Also, under the constraints of this problem, it can be proved that when this value is expressed as \frac{P}{Q} using two coprime integers P and Q , there is exactly one integer R that satisfies R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353 . Find this R .
[ { "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 result of arranging P_i,P_{i+1},\dots,P_{i+K-1} in order from smallest to largest, and replace P_{i+j-1} with x_j for each 1 \leq j \leq K . Find the lexicographically largest permutation that can be obtained by performing the above operation on P exactly once. What is lexicographical order on sequences? A sequence S = (S_1,S_2,\ldots,S_{|S|}) is lexicographically smaller than T = (T_1,T_2,\ldots,T_{|T|}) when 1. or 2. below holds. Here, |S| and |T| denotes the lengths of S and T , respectively. |S| \lt |T| and (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}) . There is an integer 1 \leq i \leq \min\lbrace |S|, |T| \rbrace that satisfy both of the following: (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1}) . S_i is smaller than T_i (as a number).
[ { "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 in the simple path. Let us paint each vertex red or blue. Find the maximum value of the integer X for which there is a coloring that satisfies the following condition: For every simple path connecting two different vertices painted in the same color, the weight of the simple path is at least X . What is a simple path? For vertices X and Y in a graph G , a sequence of vertices v_1,v_2, \ldots, v_k such that v_1=X , v_k=Y , and v_i and v_{i+1} are connected by an edge for each 1\leq i\leq k-1 is called a walk from vertex X to vertex Y . Furthermore, if v_1,v_2, \ldots, v_k are all different, the walk is called a simple path (or just path ).
[ { "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 988050146\n1 9 967817807\n4 9 796531581\n5 9 983960054\n1 10 964450079\n8 9 959369491\n", "output": "952136560\n" }, { "input": "10 20\n5 6 871895994\n8 10 873709822\n3 5 454175869\n6 10 980782191\n2 6 901290987\n1 8 298092290\n4 8 693116157\n4 5 947939338\n7 8 934395075\n7 9 759563833\n5 8 779870031\n4 6 919637355\n2 9 822858749\n4 10 855497285\n3 7 954942051\n1 2 950411658\n4 7 665939990\n3 4 634533617\n5 7 908372507\n1 9 591466693\n", "output": "759563833\n" } ]
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 i=1,2,\dots,M : X[A_i,B_i] is lexicographically smaller than X[C_i,D_i] . What is lexicographical order on sequences? A sequence S = (S_1,S_2,\ldots,S_{|S|}) is lexicographically smaller than T = (T_1,T_2,\ldots,T_{|T|}) when 1. or 2. below holds. Here, |S| and |T| denotes the lengths of S and T , respectively. |S| \lt |T| and (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}) . There is an integer 1 \leq i \leq \min\lbrace |S|, |T| \rbrace that satisfy both of the following: (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1}) . S_i is smaller than T_i (as a number).
[ { "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 10 3 3\n11 13 8 14\n6 13 4 15\n4 7 6 11\n2 5 1 2\n8 14 6 8\n", "output": "No\n" } ]
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 with K+1 or more vertices. Delete all edges with the chosen vertex as an endpoint. Find the expected value of the number of times the operation is performed, modulo 998244353 . How to print an expected value modulo \text{mod }{998244353} It can be proved that the sought expected value is always a rational number. Additionally, under the constraints of this problem, it can also be proved that when that value is represented as an irreducible fraction \frac{P}{Q} , we have Q \not \equiv 0 \pmod{998244353} . Thus, there is a unique integer R such that R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 . Report this R .
[ { "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 by performing the operation of swapping the values of two adjacent terms zero or more times. Let K be the minimum number of operations we must perform the operation to make A a good sequence . Find the lexicographically smallest good sequence that can be obtained by performing the operations K times on A . What is lexicographical order on sequences? A sequence S = (S_1,S_2,\ldots,S_{|S|}) is lexicographically smaller than T = (T_1,T_2,\ldots,T_{|T|}) when 1. or 2. below holds. Here, |S| and |T| denotes the lengths of S and T , respectively. |S| \lt |T| and (S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}) . There is an integer 1 \leq i \leq \min\lbrace |S|, |T| \rbrace that satisfy both of the following: (S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1}) . S_i is smaller than T_i (as a number).
[ { "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 4 7 7 8 8\n" } ]
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 , Takahashi can either choose and press one button or do nothing exactly t seconds after the reels start spinning. If he presses the button corresponding to the i -th reel exactly t seconds after the reels start spinning, the i -th reel will stop and display the ((t \bmod M)+1) -th character of S_i . Here, t \bmod M denotes the remainder when t is divided by M . Takahashi wants to stop all the reels so that all the displayed characters are the same. Find the minimum possible number of seconds from the start of the spin until all the reels are stopped so that his goal is achieved. If this is impossible, report that fact.
[ { "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 coordinates of each person. If the coordinates of a person cannot be uniquely determined, report that fact.
[ { "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 of it (if no one is in the row, no one gets it). That person then steps out of the row and returns to their original position in the row at time T_i+S_i . A person who returns to the row at time X is considered to be in the row at time X . After all the M occurrences, report the total amount of noodles each person has got.
[ { "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 fuel for every unit distance it travels. You can carry up to H liters of fuel and cannot move without fuel. For each i = 1, 2, \ldots, N-1 , there is a gas station at coordinate X_i , where you can get F_i liters of fuel for P_i yen. However, you cannot carry more than H liters of fuel. More precisely, if you have x liters of fuel and use the gas station at coordinate X_i , you must pay P_i yen, and your amount of fuel becomes \min(x + F_i, H) liters. Each gas station can be used at most once in total during the round trip . Determine if you can achieve this plan when you initially have H liters of fuel, and if it is possible, find the minimum amount of money required.
[ { "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 corresponding button. For each non-negative integer t , Takahashi can either choose and press one button or do nothing exactly t seconds after the reels start spinning. If he presses the button corresponding to the i -th reel exactly t seconds after the reels start spinning, the i -th reel will stop and display the ((t \bmod M)+1) -th character of S_i . Here, t \bmod M denotes the remainder when t is divided by M . Takahashi wants to stop all the reels so that all the displayed characters are the same. Find the minimum possible number of seconds from the start of the spin until all the reels are stopped so that his goal is achieved. If this is impossible, report that fact.
[ { "input": "3 10\n1937458062\n8124690357\n2385760149\n", "output": "6\n" }, { "input": "10 20\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n01234567890123456789\n", "output": "90\n" }, { "input": "5 10\n0000000000\n1111111111\n2222222222\n3333333333\n4444444444\n", "output": "-1\n" }, { "input": "10 20\n14159265358979323846\n26433832795028841971\n69399375105820974944\n59230781640628620899\n86280348253421170679\n82148086513282306647\n09384460955058223172\n53594081284811174502\n84102701938521105559\n64462294895493038196\n", "output": "11\n" } ]
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" } ]