url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc281/tasks/abc281_h
Problem Statement Takahashi has A kinds of level- 1 gems, and 10^{10^{100}} gems of each of those kinds. For an integer n greater than or equal to 2 , he can put n gems that satisfy all of the following conditions into a cauldron to generate a level- n gem in return. No two gems are of the same kind. Every gem's level is less than n . For every integer x greater than or equal to 2 , there is at most one level- x gem. Find the number of kinds of level- N gems that Takahashi can obtain, modulo 998244353 . Here, two level- 2 or higher gems are considered to be of the same kind if and only if they are generated from the same set of gems. Two sets of gems are distinguished if and only if there is a gem in one of those sets such that the other set does not contain a gem of the same kind. Any level- 1 gem and any level- 2 or higher gem are of different kinds.
[ { "input": "3 3\n", "output": "10\n" }, { "input": "1 100\n", "output": "100\n" }, { "input": "200000 1000000000\n", "output": "797585162\n" } ]
https://atcoder.jp/contests/future-contest-2023-final-open/tasks/future_contest_2023_final_a
Problem Statement A psychic, Takahashi, has discovered a treasure map. According to the map, there are 50 buried treasures under the ground of an uninhabited island. The island has a circular shape with a radius of R=10^9 . Unfortunately, the map does not indicate the locations of the buried treasures. Since it is impossible to dig up all the ground, he decided to use his psychic powers to search for the treasures in the following way. Choose a desired location and stand a wooden rod. If there is a treasure within a radius of D=10^6 from the chosen location, the rod will remain standing, and he can find the treasure by digging all the area within the radius D . If there are no treasures within a radius of D from the chosen location, the rod will fall in a certain direction according to the rule described below, providing a clue to the location of the treasures. By repeating this process up to 1000 times, find as many treasures as possible, as quickly as possible. The law of the falling direction of the rod Let q=(qx, qy) be the coordinates at which the rod stands, then the falling direction \theta (0\leq \theta<2\pi) is calculated as follows, using a constant \sigma given as an input. Among the treasures that have not yet been dug up, one is chosen with probability proportional to the inverse of the squared Euclidean distance to q . Let p=(px,py) be the coordinates of the chosen treasure, and calculate the direction \hat{\theta}=\mathrm{atan2}(py-qy,px-qx) of p-q . Sample a value from Gaussian distribution with mean \hat{\theta} and standard deviation \sigma and let \theta be its remainder divided by 2\pi .
[]
https://atcoder.jp/contests/future-contest-2023-final/tasks/future_contest_2023_final_a
Problem Statement A psychic, Takahashi, has discovered a treasure map. According to the map, there are 50 buried treasures under the ground of an uninhabited island. The island has a circular shape with a radius of R=10^9 . Unfortunately, the map does not indicate the locations of the buried treasures. Since it is impossible to dig up all the ground, he decided to use his psychic powers to search for the treasures in the following way. Choose a desired location and stand a wooden rod. If there is a treasure within a radius of D=10^6 from the chosen location, the rod will remain standing, and he can find the treasure by digging all the area within the radius D . If there are no treasures within a radius of D from the chosen location, the rod will fall in a certain direction according to the rule described below, providing a clue to the location of the treasures. By repeating this process up to 1000 times, find as many treasures as possible, as quickly as possible. The law of the falling direction of the rod Let q=(qx, qy) be the coordinates at which the rod stands, then the falling direction \theta (0\leq \theta<2\pi) is calculated as follows, using a constant \sigma given as an input. Among the treasures that have not yet been dug up, one is chosen with probability proportional to the inverse of the squared Euclidean distance to q . Let p=(px,py) be the coordinates of the chosen treasure, and calculate the direction \hat{\theta}=\mathrm{atan2}(py-qy,px-qx) of p-q . Sample a value from Gaussian distribution with mean \hat{\theta} and standard deviation \sigma and let \theta be its remainder divided by 2\pi .
[]
https://atcoder.jp/contests/agc059/tasks/agc059_a
Problem Statement Consider a string t consisting only of characters A , B , and C . We can do the following operation with it: Choose any substring t[l:r] and any permutation (X, Y, Z) of characters ( A , B , C ) . Here, t[l:r] denotes the substring formed by the l -th through the r -th characters of t , where l and r are of your choice. Then, replace each character A , B , and C in t[l:r] by X , Y , and Z , respectively. For example, for a string t = ACBAAC , we can choose a substring t[3:6] and (X,Y,Z)=( C , B , A ) . After this operation, the string will become ACBCCA . Alina likes strings in which all characters are the same. She defines the beauty of a string t as the minimum number of operations required to make all its characters equal. You are given a string S of length N consisting only of characters A , B , and C . Answer Q queries. The i -th query is the following: Given integers L_i and R_i , find the beauty of the substring t=S[L_i:R_i] .
[ { "input": "6 4\nABCCCA\n3 5\n2 3\n1 3\n1 6\n", "output": "0\n1\n2\n2\n" } ]
https://atcoder.jp/contests/agc059/tasks/agc059_b
Problem Statement You have N balls of colors C_1, C_2, \ldots, C_N . Here, all colors are represented by an integer between 1 and N inclusive. You want to arrange the balls on a circle. After you do that, you will count the number of pairs of colors (X, Y) such that X < Y and there exist two adjacent balls of colors X and Y . Find an arrangement that minimizes the number of such pairs. If there are many such arrangements, find any of them. For example, for balls of colors 1, 1, 2, 3 , if we arrange them as 1, 1, 2, 3 , we get 3 pairs: (1, 2), (2, 3), (1, 3) . If we arrange them as 1, 2, 1, 3 , we get only 2 pairs: (1, 2), (1, 3) . Solve T test cases for each input file.
[ { "input": "3\n3\n1 2 3\n4\n1 2 1 3\n5\n2 2 5 3 3\n", "output": "1 2 3 \n2 1 3 1 \n3 3 2 5 2 \n" } ]
https://atcoder.jp/contests/agc059/tasks/agc059_c
Problem Statement A teacher has a hidden permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\cdots,N) . You are going to determine it. To do this, you prepared a sequence of pairs of integers (A_1,B_1),(A_2,B_2),\ldots,(A_{N(N-1)/2},B_{N(N-1)/2}) ; this is a permutation of all pairs of the form (a,b) ( 1 \le a < b \le N ). Now, you will go over the pairs from the beginning. For a pair (A_i, B_i) , you will ask if P_{A_i}<P_{B_i} , and the teacher will tell you the answer. However, you will skip this question if you can already determine the answer to it from previous answers. Find the number of permutations P , for which with your algorithm you will have to ask all \frac{N(N-1)}{2} questions, modulo 10^9+7 .
[ { "input": "2\n1 2\n", "output": "2\n" }, { "input": "4\n1 2\n1 3\n2 3\n2 4\n3 4\n1 4\n", "output": "4\n" }, { "input": "5\n1 2\n2 3\n3 4\n4 5\n1 5\n1 3\n2 4\n3 5\n1 4\n2 5\n", "output": "0\n" } ]
https://atcoder.jp/contests/agc059/tasks/agc059_d
Problem Statement For an integer array A=(A_1, A_2, \ldots, A_{N + K-1}) ( 1 \leq A_i \leq N+K-1 ), let's construct an array B=(B_1, B_2, \ldots, B_N) , where B_i is the number of distinct elements in A_i,A_{i+1},\ldots,A_{i+K-1} . You are given B_1, B_2, \ldots, B_N . Determine if there exists an array A which could have produced such an array B , and if yes, construct one. Solve T test cases for each input file.
[ { "input": "3\n3 3\n1 2 1\n4 3\n1 2 2 1\n6 4\n3 3 3 3 3 3\n", "output": "NO\nYES\n1 1 1 2 2 2 \nYES\n1 2 3 1 2 3 1 2 3 \n" } ]
https://atcoder.jp/contests/agc059/tasks/agc059_e
Problem Statement You have an N \times N grid board. You want to color all cells in 3 colors so that no two adjacent (edge-sharing) cells have the same color. You have already painted the border of the board. Determine if you can color the rest of the board properly. More precisely, you are given a string S of length 4N-4 consisting of characters 1 , 2 , and 3 . The string denotes the colors of the cells on the border, starting from the cell (1, 1) , in clockwise order. Strictly speaking, the i -th character of S denotes the color of the cell: (1, i) for 1 \le i \le N-1 (i - (N-1), N) for N \le i \le 2N-2 (N, 3N - 1 - i) for 2N-1 \le i \le 3N-3 (4N-2 - i, 1) for 3N-2 \le i \le 4N-4 . Here, (r,c) denotes the cell in the r -th row and the c -th column. It is guaranteed that no two adjacent cells on the border have the same color. Solve T test cases for each input file.
[ { "input": "4\n3\n12312312\n4\n121212121212\n7\n321312312312121212121321\n7\n321312312312121312121321\n", "output": "NO\nYES\nNO\nYES\n" } ]
https://atcoder.jp/contests/agc059/tasks/agc059_f
Problem Statement Given N, pos, val , find the number of permutations P=(P_1, P_2, \ldots, P_N) of (1,2,\ldots,N) that satisfy all of the following conditions, modulo 10^9+7 : LIS(P) + LDS(P) = N+1 P_{pos} = val Here, LIS(P) denotes the length of the longest increasing subsequence of P , and LDS(P) denotes the length of the longest decreasing subsequence of P .
[ { "input": "3 2 2\n", "output": "2\n" }, { "input": "4 1 1\n", "output": "6\n" }, { "input": "5 2 5\n", "output": "11\n" }, { "input": "2022 69 420\n", "output": "128873576\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_a
Problem Statement There is a grid with H rows from top to bottom and W columns from left to right. Each square has a piece placed on it or is empty. The state of the grid is represented by H strings S_1, S_2, \ldots, S_H , each of length W . If the j -th character of S_i is # , the square at the i -th row from the top and j -th column from the left has a piece on it; if the j -th character of S_i is . , the square at the i -th row from the top and j -th column from the left is empty. How many squares in the grid have pieces on them?
[ { "input": "3 5\n#....\n.....\n.##..\n", "output": "3\n" }, { "input": "1 10\n..........\n", "output": "0\n" }, { "input": "6 5\n#.#.#\n....#\n..##.\n####.\n..#..\n#####\n", "output": "16\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_b
Problem Statement You are given an integer N and a sequence S=(S_1,\ldots,S_N) of length N . Find a sequence A=(A_1,\ldots,A_N) of length N that satisfies the following condition for all k=1,\ldots,N : A_1+A_2+\ldots+A_k = S_k . Such a sequence A always exists and is unique.
[ { "input": "3\n3 4 8\n", "output": "3 1 4\n" }, { "input": "10\n314159265 358979323 846264338 -327950288 419716939 -937510582 97494459 230781640 628620899 -862803482\n", "output": "314159265 44820058 487285015 -1174214626 747667227 -1357227521 1035005041 133287181 397839259 -1491424381\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_c
Problem Statement You are given strings S and T . S consists of lowercase English letters, and T is obtained by inserting a lowercase English letter into S . Find the position of the inserted character in T . If there are multiple candidates, find any of them.
[ { "input": "atcoder\natcorder\n", "output": "5\n" }, { "input": "million\nmilllion\n", "output": "5\n" }, { "input": "vvwvw\nvvvwvw\n", "output": "3\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_d
Problem Statement You are given an integer K greater than or equal to 2 . Find the minimum positive integer N such that N! is a multiple of K . Here, N! denotes the factorial of N . Under the Constraints of this problem, we can prove that such an N always exists.
[ { "input": "30\n", "output": "5\n" }, { "input": "123456789011\n", "output": "123456789011\n" }, { "input": "280\n", "output": "7\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_e
Problem Statement There is a monster with initial stamina N . Takahashi repeatedly attacks the monster while the monster's stamina remains 1 or greater. An attack by Takahashi reduces the monster's stamina by 2 with probability \frac{P}{100} and by 1 with probability 1-\frac{P}{100} . Find the expected value, modulo 998244353 (see Notes), of the number of attacks before the monster's stamina becomes 0 or less.
[ { "input": "3 10\n", "output": "229596204\n" }, { "input": "5 100\n", "output": "3\n" }, { "input": "280 59\n", "output": "567484387\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_f
Problem Statement There are N towns numbered 1,\ldots,N and M roads numbered 1,\ldots,M . Road i connects towns A_i and B_i . When you use a road, your score changes as follows: when you move from town A_i to town B_i using road i , your score increases by C_i ; when you move from town B_i to town A_i using road i , your score decreases by C_i . Your score may become negative. Answer the following Q questions. If you start traveling from town X_i with initial score 0 , find the maximum possible score when you are at town Y_i . Here, if you cannot get from town X_i to town Y_i , print nan instead; if you can have as large a score as you want when you are at town Y_i , print inf instead.
[ { "input": "5 5 3\n1 2 1\n1 2 2\n3 4 1\n4 5 1\n3 5 2\n5 3\n1 2\n3 1\n", "output": "-2\ninf\nnan\n" }, { "input": "2 1 1\n1 1 1\n1 1\n", "output": "inf\n" }, { "input": "9 7 5\n3 1 4\n1 5 9\n2 6 5\n3 5 8\n9 7 9\n3 2 3\n8 4 6\n2 6\n4 3\n3 8\n3 2\n7 9\n", "output": "inf\nnan\nnan\ninf\n-9\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_g
Problem Statement We have an infinite hexagonal grid shown below. A hexagonal cell is represented as (i,j) with two integers i and j . Cell (i,j) is adjacent to the following six cells: (i-1,j-1) (i-1,j) (i,j-1) (i,j+1) (i+1,j) (i+1,j+1) Let us define the distance between two cells X and Y by the minimum number of moves required to travel from cell X to cell Y by repeatedly moving to an adjacent cell. For example, the distance between cells (0,0) and (1,1) is 1 , and the distance between cells (2,1) and (-1,-1) is 3 . You are given N cells (X_1,Y_1),\ldots,(X_N,Y_N) . How many ways are there to choose one or more from these N cells so that the distance between any two of the chosen cells is at most D ? Find the count modulo 998244353 .
[ { "input": "3 1\n0 0\n0 1\n1 0\n", "output": "5\n" }, { "input": "9 1\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n", "output": "33\n" }, { "input": "5 10000000000\n314159265 358979323\n846264338 -327950288\n-419716939 937510582\n-97494459 -230781640\n628620899 862803482\n", "output": "31\n" } ]
https://atcoder.jp/contests/abc280/tasks/abc280_h
Problem Statement You are given N strings S_1,S_2,\ldots, S_N . Let M = \displaystyle\sum_{i=1}^N \frac{|S_i|(|S_i|+1)}{2} . For a string S and integers L and R , let us denote by S[L, R] the substring consisting of the L -th through R -th characters of S . A sequence of triples of integers ((K_1, L_1, R_1), (K_2, L_2, R_2), \ldots, (K_M, L_M, R_M)) of length M satisfies the following conditions: The M elements are pairwise distinct. For all 1 \leq i \leq M , it holds that 1 \leq K_i \leq N and 1 \leq L_i \leq R_i \leq |S_{K_i}| . For all 1 \leq i \leq j \leq M , it holds that S_{K_i}[L_i, R_i] \leq S_{K_j}[L_j, R_j] in the lexicographical order. You are given Q integers x_1,x_2,\ldots, x_Q between 1 and M , inclusive. For each 1 \leq i \leq Q , find a possible instance of (K_{x_i}, L_{x_i}, R_{x_i}) . We can prove that there always exists a sequence of triples that satisfies the conditions. If multiple triples satisfy the conditions, print any of them. In addition, among different x_i 's, the conforming sequence of triples does not have to be common. What is the lexicographical order? Two strings S and T are said to be S \leq T in the lexicographical order if and only if one of the following conditions is satisfied: |S| \leq |T| and S = T[1, |S|] . There exists 1\leq k\leq \min(|S|, |T|) such that the i -th characters of S and T are the same for all 1\leq i\leq k-1 , and the k -th character of S is alphabetically strictly smaller than that of T .
[ { "input": "2\nabab\ncab\n2\n5 14\n", "output": "1 3 4\n2 1 1\n" }, { "input": "3\na\na\nba\n2\n1 2\n", "output": "1 1 1\n1 1 1\n" }, { "input": "10\ngxgpuamkx\nszhkbpphykin\nezplvfja\nmopodotkrj\nrimlvumuar\nnexcfyce\neurgvjyos\ndhvuyfvt\nnrdyluacvra\nggwnpnzij\n6\n74 268 310 380 455 489\n", "output": "3 1 2\n4 4 5\n4 3 7\n9 6 6\n6 6 6\n2 2 12\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_a
Problem Statement Takahashi has come to an amusement arcade with N yen (Japanese currency) in his pocket. In the arcade, he can pay X yen for Y tokens any number of times (possibly zero). Find the maximum total number of tokens that he can get.
[ { "input": "12 5 3\n", "output": "6\n" }, { "input": "4 5 3\n", "output": "0\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_b
Problem Statement You are given integers A and C , and non-negative integers B and D . If \frac{A}{B}<\frac{C}{D} , print < ; if \frac{A}{B}>\frac{C}{D} , print > ; if \frac{A}{B}=\frac{C}{D} , print = .
[ { "input": "1 2 1 3\n", "output": ">\n" }, { "input": "-3 -6 1 2\n", "output": "=\n" }, { "input": "-1 3 1 -4\n", "output": "<\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_c
Problem Statement You are given an integer sequence of length N : A = (A_1, \dots, A_N) . Find the number of integers X that satisfy the following condition. There are integers i , j , and k such that A_i \times A_j \times A_k = X and 1 \leq i \lt j \lt k \leq N .
[ { "input": "4\n2 1 3 2\n", "output": "3\n" }, { "input": "10\n3 1 4 1 5 9 2 6 5 3\n", "output": "37\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_d
Problem Statement N players will play a game using cards. Initially, the first pile contains M cards, the second pile contains 0 cards, and each player has 0 cards. Each card has one of the symbols + , 0 , and - written on it. The symbol on the i -th card from the top of the initial first pile is S_i . In the game, the players take turns doing the following, in this order: player 1 , player 2 , \ldots , player N-1 , player N , player 1 , player 2 , \dots If the first pile contains 0 cards, end the game. Otherwise, the current player draws the top card from the first pile, and adds it to the player's hand. Then, according to the symbol written on that card, the player does the following. If + is written, add all cards in the second pile to the player's hand. If 0 is written, do nohing. If - is written, move all cards in the player's hand to the second pile. Find the number of cards in each player's hand at the end of the game.
[ { "input": "3 6\n000--+\n", "output": "0\n0\n6\n" }, { "input": "2 6\n++++++\n", "output": "3\n3\n" }, { "input": "7 20\n++-0+-0++-++0-+0-0-0\n", "output": "6\n3\n0\n4\n0\n2\n0\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_e
Problem Statement A string consisting of ( and ) is said to be a correct bracket sequence if it can be made empty by erasing a contiguous occurrence of () zero or more times. For instance, () , (()) , and (()())() are correct bracket sequences, while )( , ()) , and (()()))(() are not. You are given a string S consisting of ( and ) . Determine whether S is a correct bracket sequence.
[ { "input": "(())\n", "output": "Yes\n" }, { "input": "())(\n", "output": "No\n" }, { "input": "(\n", "output": "No\n" }, { "input": "((())()()())()()\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_f
Problem Statement Snuke played N matches of a 4 -player game, and ranked 1 -st A times, 2 -nd B times, 3 -rd C times, and 4 -th D times. Snuke is happy if the value of his average rank is at most X . At least how many additional matches must be played to make him happy?
[ { "input": "4\n1 1 1 1\n1.600\n", "output": "6\n" }, { "input": "10\n0 0 0 10\n4.000\n", "output": "0\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_g
Problem Statement You are given an integer sequence of length N : A = (A_1, A_2, \ldots, A_N) . Print the maximum possible value of A_l + A_{l+1} + \cdots + A_r for a pair (l, r) such that 1 \leq l \leq r \leq N .
[ { "input": "10\n-6 5 -3 3 -1 4 -1 5 -9 2\n", "output": "12\n" }, { "input": "3\n-1 -2 -3\n", "output": "-1\n" }, { "input": "20\n-14 74 -48 38 -51 43 5 37 -39 -29 80 -44 -55 59 17 89 -37 -68 38 -16\n", "output": "176\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_h
Problem Statement You are given a positive integer N that has D digits when written in base 10 . For 1\leq k\leq D , let A_k be the k -th digit from the top when N is written in base 10 . Find the value \displaystyle\sum_{i=1}^{D-1}\sum_{j=i+1}^D \lvert A_i-A_j \rvert .
[ { "input": "3\n287\n", "output": "12\n" }, { "input": "2\n11\n", "output": "0\n" }, { "input": "20\n12345678901234567890\n", "output": "660\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_i
Problem Statement There are N people numbered 1 to N . You are given N pieces of information, each in this form: person A_i is taller than person B_i . Determine whether they are consistent.
[ { "input": "3 3\n1 2\n2 3\n3 1\n", "output": "No\n" }, { "input": "4 9\n1 3\n1 3\n1 3\n1 3\n2 4\n1 4\n3 4\n2 3\n1 2\n", "output": "Yes\n" }, { "input": "3 3\n1 2\n2 1\n1 3\n", "output": "No\n" }, { "input": "100 0\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_j
Problem Statement You are given points S(x_{\mathrm{s}}, y_{\mathrm{s}}) and T(x_{\mathrm{t}}, y_{\mathrm{t}}) in the xy -plane. You are also given N four-tuples (P_i, Q_i, R_i, W_i)(1 \leq i \leq N) . Consider the following procedure. First, choose an arbitrary (directed) curve C from point S(x_{\mathrm{s}}, y_{\mathrm{s}}) to T(x_{\mathrm{t}}, y_{\mathrm{t}}) Next, choose arbitrary K distinct integers A_1, A_2, \ldots, A_K between 1 and N . Then, for each i = 1, 2, \ldots, K , do the following: If the curve C has one or more common points with the line P_{A_i} x + Q_{A_i} y = R_{A_i} , you pay W_{A_i} yen (the currency in Japan). Print the minimum possible amount of money you pay in total in the procedure above.
[ { "input": "4 3\n-2 0 2 0\n2 1 2 7\n0 1 10 10\n1 0 -1 3\n-1 1 0 5\n", "output": "8\n" }, { "input": "2 2\n0 0 0 0\n1 2 3 4\n2 4 6 8\n", "output": "0\n" }, { "input": "20 17\n-6 -77 40 99\n-14 74 -48 27\n-51 43 5 89\n-39 -29 80 75\n-55 59 17 39\n-37 -68 38 62\n14 31 43 49\n49 -7 -65 13\n-40 -45 36 32\n-54 -43 99 77\n-94 57 -22 12\n-85 67 -46 72\n95 68 55 67\n-56 51 -38 22\n32 -19 65 46\n76 66 -53 8\n35 -78 -41 30\n-51 -85 24 64\n45 -53 82 12\n39 19 -52 86\n-11 -67 -33 100\n", "output": "694\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_k
Problem Statement Takahashi wants an integer, so he goes to an integer shop. The integer shop sells every integer between 1 and 10^9 , inclusive. The integer n is sold for A \times n + B \times d(n) yen (the currency in Japan), where d(n) denotes the sum of digits in the decimal notation of n . Takahashi has X yen. Find the maximum integer he can buy.
[ { "input": "3 4 50\n", "output": "12\n" }, { "input": "199 211 10000000000\n", "output": "50251233\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_l
Problem Statement You are given N segments [L_1, R_1], [L_2, R_2], \ldots, [L_N, R_N] on a number line. A subset S of the set \lbrace 1, 2, \ldots, N \rbrace is said to be a good set if: for all i, j \in S , at least one of the following two conditions is satisfied: the segment [L_i, R_i] contains the segment [L_j, R_j] ; the segment [L_j, R_j] contains the segment [L_i, R_i] . Here, a segment [L, R] is said to contain another segment [L', R'] if and only if L \leq L' and R' \leq R . Find the maximum possible size of a good set.
[ { "input": "4\n1 3\n2 4\n3 4\n1 4\n", "output": "3\n" }, { "input": "3\n0 1\n0 1\n0 1\n", "output": "3\n" }, { "input": "9\n1 6\n1 3\n3 6\n4 6\n2 5\n1 2\n3 4\n3 5\n2 7\n", "output": "4\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_m
Problem Statement There is a tree with N vertices, whose vertices are numbered 1, \dots, N and edges are numbered 1, \dots, N-1 . Edge i \, (1 \leq i \leq N - 1) connects vertices U_i and V_i . Find the sum of the following value over all integer pairs (l, r) such that 1 \leq l \leq r \leq N - 1 : the number of vertices that are reachable from vertex 1 using zero or more edges numbered between l and r , inclusive.
[ { "input": "5\n2 3\n1 2\n2 4\n3 5\n", "output": "24\n" }, { "input": "2\n1 2\n", "output": "2\n" }, { "input": "7\n1 2\n2 7\n4 6\n3 6\n4 5\n1 5\n", "output": "49\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_n
Problem Statement For an integer sequence X = (X_1, X_2, \dots, X_k) , let us define a function f(X) as follows: Let Y = (Y_1, Y_2, \dots, Y_k) be the sequence obtained by sorting X in ascending order. Then, \displaystyle f(X) = \sum_{i=1}^{k-1}(Y_{i+1}-Y_i)^2 . We have an integer sequence A = (A_1, A_2, \dots, A_N) . Given Q queries in the following format, process them in order. Given integers l and r , find f(B) , where B = (A_l, A_{l + 1}, \dots, A_r) .
[ { "input": "3\n3 1 4\n4\n1 1\n1 2\n2 3\n1 3\n", "output": "0\n4\n9\n5\n" }, { "input": "10\n19 70 14 11 85 75 72 35 14 50\n10\n1 1\n3 8\n5 7\n1 3\n5 8\n5 5\n2 10\n2 5\n1 5\n2 9\n", "output": "0\n1928\n109\n2626\n1478\n0\n1188\n3370\n2860\n1788\n" } ]
https://atcoder.jp/contests/past202212-open/tasks/past202212_o
Problem Statement You are given an integer sequence A = (A_1, A_2, \ldots, A_N) of length N . Each element A_1, A_2, \ldots, A_N of A is a D -digit integer (without leading zeros) in the decimal notation, and none of its digits are 0 . You are given Q queries. Each query is of one of type 1 , type 2 , and type 3 , which are described below. Process the given Q queries in the order given in the input. [ Type 1 ] 1 x Apply a left cyclic shift x times to the sequence A . In other words, if A = (a_1, a_2, \ldots, a_N) , let A = (a_{x+1}, a_{x+2}, \ldots, a_N, a_1, a_2, \ldots, a_x) . [ Type 2 ] 2 l r y Do the following for i = l, l+1, \ldots, r : Let d_1 d_2 \ldots d_D be the decimal notation of A_i . Replace A_i with the integer d_{y+1} d_{y+2} \ldots d_D d_1 d_2 \ldots d_y , which is obtained by applying a left cyclic shift y times to the digits of A_i . [ Type 3 ] 3 l r Print A_l \oplus A_{l+1} \oplus \cdots \oplus A_r , where \oplus denotes the bitwise exclusive logical sum.
[ { "input": "5 3\n123 234 345 456 567\n5\n3 2 4\n1 3\n3 2 4\n2 3 5 2\n3 2 4\n", "output": "123\n678\n680\n" }, { "input": "20 6\n318153 438943 474719 114997 373645 598458 427319 171794 653644 463294 123454 842368 264537 215892 467783 121159 836368 946718 889644 865849\n20\n2 6 9 3\n2 8 13 5\n2 1 6 3\n2 14 20 5\n1 7\n2 14 15 4\n3 8 8\n2 4 5 3\n2 7 17 2\n1 19\n2 13 16 4\n2 4 9 2\n3 11 14\n1 8\n2 2 17 3\n3 6 9\n3 6 16\n2 16 17 2\n1 1\n3 3 20\n", "output": "346778\n710529\n89337\n796525\n709076\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_a
Problem Statement You are given a string S consisting of v and w . Print the number of "bottoms" in the string S (see the figure at Sample Input/Output).
[ { "input": "vvwvw\n", "output": "7\n" }, { "input": "v\n", "output": "1\n" }, { "input": "wwwvvvvvv\n", "output": "12\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_b
Problem Statement You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S . A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times. Do one of the following. Delete the first character in X . Delete the last character in X . For instance, tag is a (contiguous) substring of voltage , while ace is not a (contiguous) substring of atcoder .
[ { "input": "voltage\ntag\n", "output": "Yes\n" }, { "input": "atcoder\nace\n", "output": "No\n" }, { "input": "gorilla\ngorillagorillagorilla\n", "output": "No\n" }, { "input": "toyotasystems\ntoyotasystems\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_c
Problem Statement You are given patterns S and T consisting of # and . , each with H rows and W columns. The pattern S is given as H strings, and the j -th character of S_i represents the element at the i -th row and j -th column. The same goes for T . Determine whether S can be made equal to T by rearranging the columns of S . Here, rearranging the columns of a pattern X is done as follows. Choose a permutation P=(P_1,P_2,\dots,P_W) of (1,2,\dots,W) . Then, for every integer i such that 1 \le i \le H , simultaneously do the following. For every integer j such that 1 \le j \le W , simultaneously replace the element at the i -th row and j -th column of X with the element at the i -th row and P_j -th column.
[ { "input": "3 4\n##.#\n##..\n#...\n.###\n..##\n...#\n", "output": "Yes\n" }, { "input": "3 3\n#.#\n.#.\n#.#\n##.\n##.\n.#.\n", "output": "No\n" }, { "input": "2 1\n#\n.\n#\n.\n", "output": "Yes\n" }, { "input": "8 7\n#..#..#\n.##.##.\n#..#..#\n.##.##.\n#..#..#\n.##.##.\n#..#..#\n.##.##.\n....###\n####...\n....###\n####...\n....###\n####...\n....###\n####...\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_d
Problem Statement A superman, Takahashi, is about to jump off the roof of a building to help a person in trouble on the ground. Takahashi's planet has a constant value g that represents the strength of gravity, and the time it takes for him to reach the ground after starting to fall is \frac{A}{\sqrt{g}} . It is now time 0 , and g = 1 . Takahashi will perform the following operation as many times as he wants (possibly zero). Use a superpower to increase the value of g by 1 . This takes a time of B . Then, he will jump off the building. After starting to fall, he cannot change the value of g . Additionally, we only consider the time it takes to perform the operation and fall. Find the earliest time Takahashi can reach the ground.
[ { "input": "10 1\n", "output": "7.7735026919\n" }, { "input": "5 10\n", "output": "5.0000000000\n" }, { "input": "1000000000000000000 100\n", "output": "8772053214538.5976562500\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_e
Problem Statement You are given a sequence of length M consisting of integers between 1 and N-1 , inclusive: A=(A_1,A_2,\dots,A_M) . Answer the following question for i=1, 2, \dots, M . There is a sequence B=(B_1,B_2,\dots,B_N) . Initially, we have B_j=j for each j . Let us perform the following operation for k=1, 2, \dots, i-1, i+1, \dots, M in this order (in other words, for integers k between 1 and M except i in ascending order). Swap the values of B_{A_k} and B_{A_k+1} . After all the operations, let S_i be the value of j such that B_j=1 . Find S_i .
[ { "input": "5 4\n1 2 3 2\n", "output": "1\n3\n2\n4\n" }, { "input": "3 3\n2 2 2\n", "output": "1\n1\n1\n" }, { "input": "10 10\n1 1 1 9 4 4 2 1 3 3\n", "output": "2\n2\n2\n3\n3\n3\n1\n3\n4\n4\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_f
Problem Statement There are N boxes numbered 1,2,\ldots,N , and 10^{100} balls numbered 1,2,\dots,10^{100} . Initially, box i contains just ball i . Process a total of Q operations that will be performed. There are three types of operations: 1 , 2 , and 3 . Type 1 : Put all contents of box Y into box X . It is guaranteed that X \neq Y . 1 X Y Type 2 : Put ball k+1 into box X , where k is the current total number of balls contained in the boxes. 2 X Type 3 : Report the number of the box that contains ball X . 3 X
[ { "input": "5 10\n3 5\n1 1 4\n2 1\n2 4\n3 7\n1 3 1\n3 4\n1 1 4\n3 7\n3 6\n", "output": "5\n4\n3\n1\n3\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_g
Problem Statement There is a grid with 1 \times N squares, numbered 1,2,\dots,N from left to right. Takahashi prepared paints of C colors and painted each square in one of the C colors. Then, there were at most two colors in any consecutive K squares. Formally, for every integer i such that 1 \le i \le N-K+1 , there were at most two colors in squares i,i+1,\dots,i+K-1 . In how many ways could Takahashi paint the squares? Since this number can be enormous, find it modulo 998244353 .
[ { "input": "3 3 3\n", "output": "21\n" }, { "input": "10 5 2\n", "output": "1024\n" }, { "input": "998 244 353\n", "output": "952364159\n" } ]
https://atcoder.jp/contests/abc279/tasks/abc279_h
Problem Statement You are given positive integers N and M . Here, it is guaranteed that N\leq M \leq 2N . Print the sum, modulo 200\ 003 (a prime), of the following value over all sequences of positive integers S=(S_1,S_2,\dots,S_N) such that \displaystyle \sum_{i=1}^{N} S_i = M (notice the unusual modulo): \displaystyle \prod_{k=1}^{N} \min(k,S_k) .
[ { "input": "3 5\n", "output": "14\n" }, { "input": "1126 2022\n", "output": "40166\n" }, { "input": "1000000000000 1500000000000\n", "output": "180030\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_a
Problem Statement There is a row of L chairs. Now, N groups of people will come and take seats in order. Each group consists of one or two people, and the i -th group to come consists of a_i people. The total number of people equals L . Each group will randomly choose unoccupied chairs where all group members can sit consecutively, and occupy those chairs. However, if there are not enough consecutive unoccupied chairs, they will leave without taking seats. Determine whether it is guaranteed that all N groups can take seats.
[ { "input": "2 4\n2 2\n", "output": "No\n" }, { "input": "3 4\n1 2 1\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_b
Problem Statement There is a narrow straight road of length L stretching east to west. Two travelers will visit this road. Along the road, there are N rest areas. The distance from the west end of the road to the i -th rest area is a_i (no rest area is at either end of the road). The road is so narrow that the two travelers cannot pass each other or walk side by side except at the rest areas. The two travelers will take a trip along the road as follows. At time 0 , each traveler starts at a rest area of their choice (the two may start at the same rest area). Then, each visits both ends of the road, and returns to their own starting rest area. During the trip, they can walk along the road at a speed of at most 1 , or rest at a rest area. As long as they only pass each other at the rest areas, it is always allowed to change direction. What is the smallest number of seconds needed for both travelers to visit both ends of the road and return to their starting rest areas? It can be proved that the answer is always an integer under the Constraints of this problem.
[ { "input": "2 6\n2 5\n", "output": "14\n" }, { "input": "2 3\n1 2\n", "output": "6\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_c
Problem Statement We have a sequence of N terms: a_1,a_2,\ldots,a_N . You can perform the following operation on this sequence any number of times (possibly zero). Choose a term of the sequence at that point, and let s be its value. Then, for every 1\leq i\leq N , replace a_i with 2s-a_i . However, this operation may not be performed in a way that produces a term with a negative value. You want to make the greatest value among the terms of the sequence as small as possible. What will this value be after an optimal sequence of operations for this objective?
[ { "input": "3\n1 3 6\n", "output": "5\n" }, { "input": "5\n400 500 600 700 800\n", "output": "400\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_d
Problem Statement We have an undirected graph with N vertices numbered 0 through N-1 and no edges at first. You may add edges to this graph as you like. When you are done with adding edges, the following operation will be performed once using a given integer K . For each edge you have added, let u and v be its endpoints, and an edge will be added between two vertices (u+K) \mathrm{mod} N and (v+K) \mathrm{mod} N . This edge will be added even if there is already an edge between these vertices, resulting in multi-edges. For the given N and K , find a set of edges that you should add so that the graph will be a tree after the operation. If there is no such set of edges, indicate that fact.
[ { "input": "5 2\n", "output": "2\n2 3\n2 4\n" }, { "input": "2 1\n", "output": "-1\n" }, { "input": "7 1\n", "output": "3\n0 1\n2 3\n4 5\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_e
Problem Statement On a number line, there are 2^N-1 balls at the coordinates x=1,2,3,...,2^N-1 , and the ball at x=i has a weight of w_i . Here, w_1, w_2,...,w_{2^N-1} is a permutation of the integers from 1 through 2^N-1 . You will choose a non-negative integer Z at most 2^N-1 and attach a weight of Z at each of the coordinates x=\pm 100^{100^{100}} . Then, the balls will simultaneously start moving as follows. At each time, let R be the total \mathrm{XOR} of the weights of the balls and attached weights that are strictly to the right of the coordinate of a ball, and L be the total \mathrm{XOR} of the weights of the balls and attached weights that are strictly to the left. If R>L , the ball moves to the right at a speed of 1 per second; if L>R , the ball moves to the left at a speed of 1 per second; if L=R , the ball stands still. If multiple balls exist at the same coordinate (when, for instance, two balls coming from the left and right reach there), the balls combine into one whose weight is the total \mathrm{XOR} of their former weights. For how many values of Z will all balls come to rest within 100^{100} seconds? What is \mathrm{XOR} ? The bitwise \mathrm{XOR} of non-negative integers A and B , A \oplus B , is defined as follows. When A \oplus B is written in binary, the k -th lowest bit ( k \geq 0 ) is 1 if exactly one of the k -th lowest bits of A and B is 1 , and 0 otherwise. For instance, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110 ). Generally, the bitwise \mathrm{XOR} of k non-negative integers p_1, p_2, p_3, \dots, p_k is defined as (\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k) , which can be proved to be independent of the order of p_1, p_2, p_3, \dots, p_k .
[ { "input": "2\n1 2 3\n", "output": "1\n" }, { "input": "3\n7 1 2 3 4 5 6\n", "output": "2\n" } ]
https://atcoder.jp/contests/arc152/tasks/arc152_f
Problem Statement You are given a tree with N vertices numbered 1 to N . The i -th edge connects two vertices a_i and b_i (1\leq i\leq N-1) . Initially, a piece is placed at vertex 1 . You will perform the following operation exactly N times. Choose a vertex that is not occupied by the piece at that moment and is never chosen in the previous operations, and move the piece one vertex toward the chosen vertex. A way to perform the operation N times is called a good procedure if the piece ends up at vertex N . Additionally, a good procedure is called an ideal procedure if the number of vertices visited by the piece at least once during the procedure (including vertices 1 and N ) is the minimum possible. Find the number of vertices visited by the piece at least once during an ideal procedure. If there is no good procedure, print -1 instead.
[ { "input": "4\n1 2\n2 4\n3 4\n", "output": "3\n" }, { "input": "6\n1 6\n2 6\n2 3\n3 4\n4 5\n", "output": "-1\n" }, { "input": "14\n1 2\n1 3\n3 4\n3 5\n5 6\n6 7\n5 8\n8 9\n8 14\n14 10\n10 11\n14 12\n12 13\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_a
Problem Statement You are given a sequence A = (A_1, A_2, \dots, A_N) of length N . You perform the following operation exactly K times: remove the initial element of A and append a 0 to the tail of A . Print all the elements of A after the operations.
[ { "input": "3 2\n2 7 8\n", "output": "8 0 0\n" }, { "input": "3 4\n9 9 9\n", "output": "0 0 0\n" }, { "input": "9 5\n1 2 3 4 5 6 7 8 9\n", "output": "6 7 8 9 0 0 0 0 0\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_b
Problem Statement Takahashi bought a table clock. The clock shows the time as shown in Figure 1 at \mathrm{AB} : \mathrm{CD} in the 24 -hour system. For example, the clock in Figure 2 shows 7:58. The format of the time is formally described as follows. Suppose that the current time is m minutes past h in the 24 -hour system. Here, the 24 -hour system represents the hour by an integer between 0 and 23 (inclusive), and the minute by an integer between 0 and 59 (inclusive). Let A be the tens digit of h , B be the ones digit of h , C be the tens digit of m , and D be the ones digit of m . (Here, if h has only one digit, we consider that it has a leading zero; the same applies to m .) Then, the clock shows A in its top-left, B in its bottom-left, C in its top-right, and D in its bottom-right. Takahashi has decided to call a time a confusing time if it satisfies the following condition: after swapping the top-right and bottom-left digits on the clock, it still reads a valid time in the 24 -hour system. For example, the clock in Figure 3 shows 20:13. After swapping its top-right and bottom-left digits, it reads 21:03. Thus, 20:13 is a confusing time. The clock now shows H : M . Find the next confusing time (including now) in the 24 -hour system.
[ { "input": "1 23\n", "output": "1 23\n" }, { "input": "19 57\n", "output": "20 0\n" }, { "input": "20 40\n", "output": "21 0\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_c
Problem Statement Takahashi runs an SNS "Twidai," which has N users from user 1 through user N . In Twidai, users can follow or unfollow other users. Q operations have been performed since Twidai was launched. The i -th (1\leq i\leq Q) operation is represented by three integers T_i , A_i , and B_i , whose meanings are as follows: If T_i = 1 : it means that user A_i follows user B_i . If user A_i is already following user B_i at the time of this operation, it does not make any change. If T_i = 2 : it means that user A_i unfollows user B_i . If user A_i is not following user B_i at the time of this operation, it does not make any change. If T_i = 3 : it means that you are asked to determine if users A_i and B_i are following each other. You need to print Yes if user A_i is following user B_i and user B_i is following user A_i , and No otherwise. When the service was launched, no users were following any users. Print the correct answers for all operations such that T_i = 3 in ascending order of i .
[ { "input": "3 9\n1 1 2\n3 1 2\n1 2 1\n3 1 2\n1 2 3\n1 3 2\n3 1 3\n2 1 2\n3 1 2\n", "output": "No\nYes\nNo\nNo\n" }, { "input": "2 8\n1 1 2\n1 2 1\n3 1 2\n1 1 2\n1 1 2\n1 1 2\n2 1 2\n3 1 2\n", "output": "Yes\nNo\n" }, { "input": "10 30\n3 1 6\n3 5 4\n1 6 1\n3 1 7\n3 8 4\n1 1 6\n2 4 3\n1 6 5\n1 5 6\n1 1 8\n1 8 1\n2 3 10\n1 7 6\n3 5 6\n1 6 7\n3 6 7\n1 9 5\n3 8 6\n3 3 8\n2 6 9\n1 7 1\n3 10 8\n2 9 2\n1 10 9\n2 6 10\n2 6 8\n3 1 6\n3 1 8\n2 8 5\n1 9 10\n", "output": "No\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nYes\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_d
Problem Statement You are given a sequence A = (A_1, A_2, \dots, A_N) of length N . Given Q queries, process all of them in order. The q -th (1\leq q\leq Q) query is in one of the following three formats, which represents the following queries: 1\ x _ q : assign x_q to every element of A . 2\ i _ q\ x _ q : add x_q to A _ {i _ q} . 3\ i _ q : print the value of A _ {i _ q} .
[ { "input": "5\n3 1 4 1 5\n6\n3 2\n2 3 4\n3 3\n1 1\n2 3 4\n3 3\n", "output": "1\n8\n5\n" }, { "input": "1\n1000000000\n8\n2 1 1000000000\n2 1 1000000000\n2 1 1000000000\n2 1 1000000000\n2 1 1000000000\n2 1 1000000000\n2 1 1000000000\n3 1\n", "output": "8000000000\n" }, { "input": "10\n1 8 4 15 7 5 7 5 8 0\n20\n2 7 0\n3 7\n3 8\n1 7\n3 3\n2 4 4\n2 4 9\n2 10 5\n1 10\n2 4 2\n1 10\n2 3 1\n2 8 11\n2 3 14\n2 1 9\n3 8\n3 8\n3 1\n2 6 5\n3 7\n", "output": "7\n5\n7\n21\n21\n19\n10\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_e
Problem Statement You have a grid with H rows from top to bottom and W columns from left to right. We denote by (i, j) the square at the i -th row from the top and j -th column from the left. (i,j)\ (1\leq i\leq H,1\leq j\leq W) has an integer A _ {i,j} between 1 and N written on it. You are given integers h and w . For all pairs (k,l) such that 0\leq k\leq H-h and 0\leq l\leq W-w , solve the following problem: If you black out the squares (i,j) such that k\lt i\leq k+h and l\lt j\leq l+w , how many distinct integers are written on the squares that are not blacked out? Note, however, that you do not actually black out the squares (that is, the problems are independent).
[ { "input": "3 4 5 2 2\n2 2 1 1\n3 2 5 3\n3 4 4 3\n", "output": "4 4 3\n5 3 4\n" }, { "input": "5 6 9 3 4\n7 1 5 3 9 5\n4 5 4 5 1 2\n6 1 6 2 9 7\n4 7 1 5 8 8\n3 4 3 3 5 3\n", "output": "8 8 7\n8 9 7\n8 9 8\n" }, { "input": "9 12 30 4 7\n2 2 2 2 2 2 2 2 2 2 2 2\n2 2 20 20 2 2 5 9 10 9 9 23\n2 29 29 29 29 29 28 28 26 26 26 15\n2 29 29 29 29 29 25 25 26 26 26 15\n2 29 29 29 29 29 25 25 8 25 15 15\n2 18 18 18 18 1 27 27 25 25 16 16\n2 19 22 1 1 1 7 3 7 7 7 7\n2 19 22 22 6 6 21 21 21 7 7 7\n2 19 22 22 22 22 21 21 21 24 24 24\n", "output": "21 20 19 20 18 17\n20 19 18 19 17 15\n21 19 20 19 18 16\n21 19 19 18 19 18\n20 18 18 18 19 18\n18 16 17 18 19 17\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_f
Problem Statement You are given N strings S _ 1,S _ 2,\ldots,S _ N . S _ i\ (1\leq i\leq N) is a non-empty string of length at most 10 consisting of lowercase English letters, and the strings are pairwise distinct. Taro the First and Jiro the Second play a word-chain game. In this game, the two players take alternating turns, with Taro the First going first. In each player's turn, the player chooses an integer i\ (1\leq i\leq N) , which should satisfy the following two conditions: i is different from any integer chosen by the two players so far since the game started; the current turn is the first turn of the game, or the last character of S_j equals the first character of S_i , where j is the last integer chosen. The player who is unable to choose a conforming i loses; the other player wins. Determine which player will win if the two players play optimally.
[ { "input": "6\nenum\nfloat\nif\nmodint\ntakahashi\ntemplate\n", "output": "First\n" }, { "input": "10\ncatch\nchokudai\nclass\ncontinue\ncopy\nexec\nhavoc\nintrinsic\nstatic\nyucatec\n", "output": "Second\n" }, { "input": "16\nmnofcmzsdx\nlgeowlxuqm\nouimgdjxlo\njhwttcycwl\njbcuioqbsj\nmdjfikdwix\njhvdpuxfil\npeekycgxco\nsbvxszools\nxuuqebcrzp\njsciwvdqzl\nobblxzjhco\nptobhnpfpo\nmuizaqtpgx\njtgjnbtzcl\nsivwidaszs\n", "output": "First\n" } ]
https://atcoder.jp/contests/abc278/tasks/abc278_g
Problem Statement This is an interactive task (where your program interacts with the judge's program via Standard Input and Output). You are given integers N , L , and R . You play the following game against the judge: There are N cards numbered 1 through N on the table. The players alternately perform the following operation: choose an integer pair (x, y) satisfying 1 \leq x \leq N , L \leq y \leq R such that all of the y cards x, x+1, \dots, x+y-1 remain on the table, and remove cards x, x+1, \dots, x+y-1 from the table. The first player to become unable to perform the operation loses, and the other player wins. Choose whether to go first or second, and play the game against the judge to win.
[]
https://atcoder.jp/contests/abc278/tasks/abc278_h
Problem Statement A sequence S of non-negative integers is said to be a good sequence if: there exists a non-empty (not necessarily contiguous) subsequence T of S such that the bitwise XOR of all elements in T is 1 . There are an empty sequence A , and 2^B cards with each of the integers between 0 and 2^B-1 written on them. You repeat the following operation until A becomes a good sequence: You freely choose a card and append the integer written on it to the tail of A . Then, you eat the card. (Once eaten, the card cannot be chosen anymore.) How many sequences of length N can be the final A after the operations? Find the count modulo 998244353 . What is bitwise XOR? The bitwise \mathrm{XOR} of non-negative integers A and B , A \oplus B , is defined as follows. When A \oplus B is written in binary, the k -th lowest bit ( k \geq 0 ) is 1 if exactly one of the k -th lowest bits of A and B is 1 , and 0 otherwise. For instance, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110 ).
[ { "input": "2 2\n", "output": "5\n" }, { "input": "2022 1119\n", "output": "293184537\n" }, { "input": "200000 10000000\n", "output": "383948354\n" } ]
https://atcoder.jp/contests/joi2023yo1c/tasks/joi2023_yo1c_a
ๅ•้กŒๆ–‡ 2 ใคใฎๆ•ฐๅญ— A, B ใŒไธŽใˆใ‚‰ใ‚Œใ‚‹๏ผŽ ๅใฎไฝใŒ A ใงใ‚ใ‚Š๏ผŒไธ€ใฎไฝใŒ B ใงใ‚ใ‚‹ 2 ๆกใฎๆญฃใฎๆ•ดๆ•ฐใ‚’ๅ‡บๅŠ›ใ›ใ‚ˆ๏ผŽ
[ { "input": "2\n2\n", "output": "22\n" }, { "input": "1\n0\n", "output": "10\n" }, { "input": "1\n9\n", "output": "19\n" } ]
https://atcoder.jp/contests/joi2023yo1c/tasks/joi2023_yo1c_b
ๅ•้กŒๆ–‡ 2 ใคใฎๆ•ดๆ•ฐ A, B ใŒไธŽใˆใ‚‰ใ‚Œใ‚‹๏ผŽ 2022 ๅนด 11 ๆœˆ A ๆ—ฅใฎ B ้€ฑ้–“ๅพŒใฎๆ—ฅใŒ 2022 ๅนด 11 ๆœˆใชใ‚‰ใฐ 1 ใ‚’๏ผŒ 2022 ๅนด 11 ๆœˆใงใชใ„ใชใ‚‰ใฐ 0 ใ‚’ๅ‡บๅŠ›ใ›ใ‚ˆ๏ผŽ ใŸใ ใ—๏ผŒ 2022 ๅนด 11 ๆœˆใฏ 2022 ๅนด 11 ๆœˆ 1 ๆ—ฅใ‹ใ‚‰ 2022 ๅนด 11 ๆœˆ 30 ๆ—ฅใพใงใฎ 30 ๆ—ฅ้–“ใงใ‚ใ‚Š๏ผŒ x ้€ฑ้–“ๅพŒใฎๆ—ฅใจใฏ (7\times x) ๆ—ฅๅพŒใฎๆ—ฅใฎใ“ใจใ‚’ๆŒ‡ใ™๏ผŽ
[ { "input": "19\n1\n", "output": "1\n" }, { "input": "3\n4\n", "output": "0\n" }, { "input": "8\n3\n", "output": "1\n" } ]
https://atcoder.jp/contests/joi2023yo1c/tasks/joi2023_yo1c_c
ๅ•้กŒๆ–‡ ใŸใ ๅฅ‡ๅฆ™ใช็™บๆ˜Žใง็Ÿฅใ‚‰ใ‚Œใ‚‹ JOI ็คพใฏ๏ผŒๆœ€่ฟ‘ JOI Editor ใจใ„ใ†ใƒ†ใ‚ญใ‚นใƒˆใ‚จใƒ‡ใ‚ฃใ‚ฟใ‚’้–‹็™บใ—ใŸ๏ผŽ ใ“ใฎใƒ†ใ‚ญใ‚นใƒˆใ‚จใƒ‡ใ‚ฃใ‚ฟใฏ๏ผŒ j ๏ผŒ o ๏ผŒ i ใฎ 3 ใคใฎใ‚ญใƒผใงๆ“ไฝœใ™ใ‚‹ใ“ใจใŒใงใใ‚‹๏ผŽ j ๏ผŒ o ๏ผŒ i ใฎใ„ใšใ‚Œใ‹ใฎใ‚ญใƒผใ‚’ๆŠผใ™ใจ๏ผŒใใฎใ‚ญใƒผใซๆ›ธใ‹ใ‚Œใฆใ„ใ‚‹่‹ฑๅฐๆ–‡ๅญ—ใŒๅ…ฅๅŠ›ใ•ใ‚Œใ‚‹ใŒ๏ผŒๅŒใ˜่‹ฑๅฐๆ–‡ๅญ—ใŒ 2 ใค้šฃๆŽฅใ™ใ‚‹ใจ๏ผŒใŸใ ใกใซใใฎ 2 ๆ–‡ๅญ—ใŒๅฏพๅฟœใ™ใ‚‹่‹ฑๅคงๆ–‡ๅญ—ใซ็ฝฎๆ›ใ•ใ‚Œใ‚‹๏ผŽใ™ใชใ‚ใก๏ผŒ jj ใฏ JJ ใซ๏ผŒ oo ใฏ OO ใซ๏ผŒ ii ใฏ II ใซ็ฝฎๆ›ใ•ใ‚Œใ‚‹๏ผŽ ไพ‹ใˆใฐ๏ผŒ j ๏ผŒ o ๏ผŒ o ๏ผŒ o ๏ผŒ i ใฎใ‚ญใƒผใ‚’ใ“ใฎ้ †็•ชใงๆŠผใ™ใจ๏ผŒ j ๏ผŒ o ๏ผŒ o ใพใงใ‚ญใƒผใ‚’ๆŠผใ—ใŸ็›ดๅพŒ๏ผŒ 2 ๆ–‡ๅญ—็›ฎใจ 3 ๆ–‡ๅญ—็›ฎใฎไธฆใณใŒ oo ใจใชใ‚‹๏ผŽๅŒใ˜่‹ฑๅฐๆ–‡ๅญ—ใŒ 2 ใค้šฃๆŽฅใ—ใฆใ„ใ‚‹ใฎใง๏ผŒใ“ใฎ 2 ๆ–‡ๅญ—ใŒใŸใ ใกใซ OO ใซ็ฝฎๆ›ใ•ใ‚Œใ‚‹๏ผŽๆœ€็ต‚็š„ใซ JOI Editor ใซๆ›ธใ‹ใ‚Œใฆใ„ใ‚‹ๆ–‡ๅญ—ๅˆ—ใฏ jOOoi ใจใชใ‚‹๏ผŽ joOOi ใ‚„ jOOOi ใจใฏใชใ‚‰ใชใ„ใ“ใจใซๆณจๆ„ใ›ใ‚ˆ๏ผŽ ้•ทใ• N ใฎๆ–‡ๅญ—ๅˆ— S ใŒไธŽใˆใ‚‰ใ‚Œใ‚‹๏ผŽ S ใฎๅ„ๆ–‡ๅญ—ใฏ j ๏ผŒ o ๏ผŒ i ใฎใ„ใšใ‚Œใ‹ใงใ‚ใ‚‹๏ผŽ N ๅ›žใ‚ญใƒผใ‚’ๆŠผใ™๏ผŽ S ใฎ i ๆ–‡ๅญ—็›ฎ ( 1 \leqq i \leqq N ) ใฏ i ๅ›ž็›ฎใซๆŠผใ™ใ‚ญใƒผใ‚’่กจใ™๏ผŽๆœ€็ต‚็š„ใซ JOI Editor ใซๆ›ธใ‹ใ‚Œใฆใ„ใ‚‹ๆ–‡ๅญ—ๅˆ—ใ‚’ๅ‡บๅŠ›ใ›ใ‚ˆ๏ผŽ
[ { "input": "6\njjoiii\n", "output": "JJoIIi\n" }, { "input": "6\njoijoi\n", "output": "joijoi\n" }, { "input": "7\nooooooo\n", "output": "OOOOOOo\n" } ]
https://atcoder.jp/contests/joi2023yo1c/tasks/joi2023_yo1c_d
ๅ•้กŒๆ–‡ JOI ้ซ˜ๆ กใซใฏ N ไบบใฎ็”Ÿๅพ’ใŒใŠใ‚Š๏ผŒ 1 ใ‹ใ‚‰ N ใพใงใฎ็•ชๅทใŒไป˜ใ‘ใ‚‰ใ‚Œใฆใ„ใ‚‹๏ผŽ ๅ…ˆๆœˆ JOI ้ซ˜ๆ กใงใฏใƒžใƒฉใ‚ฝใƒณๅคงไผšใŒ้–‹ๅ‚ฌใ•ใ‚Œ๏ผŒ็”Ÿๅพ’ๅ…จๅ“กใŒใ“ใ‚Œใซๅ‚ๅŠ ใ—ใŸ๏ผŽ็”Ÿๅพ’ i ( 1 \leqq i \leqq N ) ใฎ่จ˜้Œฒใฏ A_i ๅˆ†ใงใ‚ใฃใŸ๏ผŽ ใƒžใƒฉใ‚ฝใƒณๅคงไผšใซใŠใ‘ใ‚‹ๅ„็”Ÿๅพ’ใฎ้ †ไฝใ‚’ๆฑ‚ใ‚ใ‚ˆ๏ผŽใŸใ ใ—๏ผŒ็”Ÿๅพ’ i ( 1 \leqq i \leqq N ) ใฎ้ †ไฝใฏ๏ผŒ(่จ˜้ŒฒใŒ A_i ๅˆ†ๆœชๆบ€ใฎ็”Ÿๅพ’ใฎไบบๆ•ฐ) {} + 1 ใง่จˆ็ฎ—ใ•ใ‚Œใ‚‹๏ผŽ
[ { "input": "3\n44 42 69\n", "output": "2\n1\n3\n" }, { "input": "4\n40 60 40 60\n", "output": "1\n3\n1\n3\n" }, { "input": "10\n766 152 595 926 663 509 368 595 175 622\n", "output": "9\n1\n5\n10\n8\n4\n3\n5\n2\n7\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_a
Problem Statement You are given a sequence P that is a permutation of (1,2,โ€ฆ,N) , and an integer X . The i -th term of P has a value of P_i . Print k such that P_k = X .
[ { "input": "4 3\n2 3 1 4\n", "output": "2\n" }, { "input": "5 2\n3 5 1 4 2\n", "output": "5\n" }, { "input": "6 6\n1 2 3 4 5 6\n", "output": "6\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_b
Problem Statement You are given N strings, each of length 2 , consisting of uppercase English letters and digits. The i -th string is S_i . Determine whether the following three conditions are all satisfied. ใƒปFor every string, the first character is one of H , D , C , and S . ใƒปFor every string, the second character is one of A , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , T , J , Q , K . ใƒปAll strings are pairwise different. That is, if i \neq j , then S_i \neq S_j .
[ { "input": "4\nH3\nDA\nD3\nSK\n", "output": "Yes\n" }, { "input": "5\nH3\nDA\nCK\nH3\nS7\n", "output": "No\n" }, { "input": "4\n3H\nAD\n3D\nKS\n", "output": "No\n" }, { "input": "5\n00\nAA\nXX\nYY\nZZ\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_c
Problem Statement There is a 10^9 -story building with N ladders. Takahashi, who is on the 1 -st (lowest) floor, wants to reach the highest floor possible by using ladders (possibly none). The ladders are numbered from 1 to N , and ladder i connects the A_i -th and B_i -th floors. One can use ladder i in either direction to move from the A_i -th floor to the B_i -th floor or vice versa, but not between other floors. Takahashi can freely move within the same floor, but cannot move between floors without using ladders. What is the highest floor Takahashi can reach?
[ { "input": "4\n1 4\n4 3\n4 10\n8 3\n", "output": "10\n" }, { "input": "6\n1 3\n1 5\n1 12\n3 5\n3 12\n5 12\n", "output": "12\n" }, { "input": "3\n500000000 600000000\n600000000 700000000\n700000000 800000000\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_d
Problem Statement Takahashi has N cards in his hand. For i = 1, 2, \ldots, N , the i -th card has an non-negative integer A_i written on it. First, Takahashi will freely choose a card from his hand and put it on a table. Then, he will repeat the following operation as many times as he wants (possibly zero). Let X be the integer written on the last card put on the table. If his hand contains cards with the integer X or the integer (X+1)\bmod M written on them, freely choose one of those cards and put it on the table. Here, (X+1)\bmod M denotes the remainder when (X+1) is divided by M . Print the smallest possible sum of the integers written on the cards that end up remaining in his hand.
[ { "input": "9 7\n3 0 2 5 5 3 0 6 3\n", "output": "11\n" }, { "input": "1 10\n4\n", "output": "0\n" }, { "input": "20 20\n18 16 15 9 8 8 17 1 3 17 11 9 12 11 7 3 2 14 3 12\n", "output": "99\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_e
Problem Statement You are given an undirected graph consisting of N vertices and M edges. For i = 1, 2, \ldots, M , the i -th edge is an undirected edge connecting vertex u_i and v_i that is initially passable if a_i = 1 and initially impassable if a_i = 0 . Additionally, there are switches on K of the vertices: vertex s_1 , vertex s_2 , \ldots , vertex s_K . Takahashi is initially on vertex 1 , and will repeat performing one of the two actions below, Move or Hit Switch , which he may choose each time, as many times as he wants. Move : Choose a vertex adjacent to the vertex he is currently on via an edge, and move to that vertex. Hit Switch : If there is a switch on the vertex he is currently on, hit it. This will invert the passability of every edge in the graph. That is, a passable edge will become impassable, and vice versa. Determine whether Takahashi can reach vertex N , and if he can, print the minimum possible number of times he performs Move before reaching vertex N .
[ { "input": "5 5 2\n1 3 0\n2 3 1\n5 4 1\n2 1 1\n1 4 0\n3 4\n", "output": "5\n" }, { "input": "4 4 2\n4 3 0\n1 2 1\n1 2 0\n2 1 1\n2 4\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_f
Problem Statement You are given a matrix A whose elements are non-negative integers. For a pair of integers (i, j) such that 1 \leq i \leq H and 1 \leq j \leq W , let A_{i, j} denote the element at the i -th row and j -th column of A . Let us perform the following procedure on A . First, replace each element of A that is 0 with an arbitrary positive integer (if multiple elements are 0 , they may be replaced with different positive integers). Then, repeat performing one of the two operations below, which may be chosen each time, as many times as desired (possibly zero). Choose a pair of integers (i, j) such that 1 \leq i \lt j \leq H and swap the i -th and j -th rows of A . Choose a pair of integers (i, j) such that 1 \leq i \lt j \leq W and swap the i -th and j -th columns of A . Determine whether A can be made to satisfy the following condition. A_{1, 1} \leq A_{1, 2} \leq \cdots \leq A_{1, W} \leq A_{2, 1} \leq A_{2, 2} \leq \cdots \leq A_{2, W} \leq A_{3, 1} \leq \cdots \leq A_{H, 1} \leq A_{H, 2} \leq \cdots \leq A_{H, W} . In other words, for every two pairs of integers (i, j) and (i', j') such that 1 \leq i, i' \leq H and 1 \leq j, j' \leq W , both of the following conditions are satisfied. If i \lt i' , then A_{i, j} \leq A_{i', j'} . If i = i' and j \lt j' , then A_{i, j} \leq A_{i', j'} .
[ { "input": "3 3\n9 6 0\n0 4 0\n3 0 3\n", "output": "Yes\n" }, { "input": "2 2\n2 1\n1 2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_g
Problem Statement You are given a connected simple undirected graph consisting of N vertices and M edges. For i = 1, 2, \ldots, M , the i -th edge connects vertex u_i and vertex v_i . Takahashi starts at Level 0 on vertex 1 , and will perform the following action exactly K times. First, choose one of the vertices adjacent to the vertex he is currently on, uniformly at random, and move to the chosen vertex. Then, the following happens according to the vertex v he has moved to. If C_v = 0 : Takahashi's Level increases by 1 . If C_v = 1 : Takahashi receives a money of X^2 yen, where X is his current Level. Print the expected value of the total amount of money Takahashi receives during the K actions above, modulo 998244353 (see Notes).
[ { "input": "5 4 8\n4 5\n2 3\n2 4\n1 2\n0 0 1 1 0\n", "output": "89349064\n" }, { "input": "8 12 20\n7 6\n2 6\n6 4\n2 1\n8 5\n7 2\n7 5\n3 7\n3 5\n1 8\n6 3\n1 4\n0 0 1 1 0 0 0 0\n", "output": "139119094\n" } ]
https://atcoder.jp/contests/abc277/tasks/abc277_h
Problem Statement Determine whether there is a sequence of N integers X = (X_1, X_2, \ldots ,X_N) that satisfies all of the following conditions, and construct one such sequence if it exists. 0 \leq X_i \leq M for every 1 \leq i \leq N . L_i \leq X_{A_i} + X_{B_i} \leq R_i for every 1 \leq i \leq Q .
[ { "input": "4 5 3\n1 3 5 7\n1 4 1 2\n2 2 3 8\n", "output": "2 4 3 0\n" }, { "input": "3 7 3\n1 2 3 4\n3 1 9 12\n2 3 2 4\n", "output": "-1\n" } ]
https://atcoder.jp/contests/ahc016/tasks/ahc016_a
Problem Statement Given an integer M and an error rate \epsilon , determine an integer N satisfying 4\leq N\leq 100 and output N -vertex undirected graphs G_0,G_1,\cdots,G_{M-1} . The graphs may be disconnected. Then process the following query 100 times. In the k -th query, you are given an N -vertex undirected graph H_k . H_k is a graph generated from some G_{s_k} as follows. Initialize H_k=G_{s_k} . For each (i,j) with 0\leq i<j\leq N-1 , flip whether or not H_k contains edge (i,j) with probability \epsilon . Randomly shuffle the order of the vertices in H_k . After receiving H_k , predict from which graph G_{s_k} it was generated, and output the predicted value t_k of s_k .
[]
https://atcoder.jp/contests/abc276/tasks/abc276_a
Problem Statement You are given a string S consisting of lowercase English letters. If a appears in S , print the last index at which it appears; otherwise, print -1 . (The index starts at 1 .)
[ { "input": "abcdaxayz\n", "output": "7\n" }, { "input": "bcbbbz\n", "output": "-1\n" }, { "input": "aaaaa\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_b
Problem Statement There are N cities numbered 1, \dots, N , and M roads connecting cities. The i -th road (1 \leq i \leq M) connects city A_i and city B_i . Print N lines as follows. Let d_i be the number of cities directly connected to city i \, (1 \leq i \leq N) , and those cities be city a_{i, 1} , \dots , city a_{i, d_i} , in ascending order . The i -th line (1 \leq i \leq N) should contain d_i + 1 integers d_i, a_{i, 1}, \dots, a_{i, d_i} in this order, separated by spaces.
[ { "input": "6 6\n3 6\n1 3\n5 6\n2 5\n1 2\n1 6\n", "output": "3 2 3 6\n2 1 5\n2 1 6\n0\n2 2 6\n3 1 3 5\n" }, { "input": "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n", "output": "4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_c
Problem Statement You are given a permutation P = (P_1, \dots, P_N) of (1, \dots, N) , where (P_1, \dots, P_N) \neq (1, \dots, N) . Assume that P is the K -th lexicographically smallest among all permutations of (1 \dots, N) . Find the (K-1) -th lexicographically smallest permutation. What are permutations? A permutation of (1, \dots, N) is an arrangement of (1, \dots, N) into a sequence. What is lexicographical order? For sequences of length N , A = (A_1, \dots, A_N) and B = (B_1, \dots, B_N) , A is said to be strictly lexicographically smaller than B if and only if there is an integer 1 \leq i \leq N that satisfies both of the following. (A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1}). A_i < B_i .
[ { "input": "3\n3 1 2\n", "output": "2 3 1\n" }, { "input": "10\n9 8 6 5 10 3 1 2 4 7\n", "output": "9 8 6 5 10 2 7 4 3 1\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_d
Problem Statement You are given a sequence of positive integers: A=(a_1,a_2,\ldots,a_N) . You can choose and perform one of the following operations any number of times, possibly zero. Choose an integer i such that 1 \leq i \leq N and a_i is a multiple of 2 , and replace a_i with \frac{a_i}{2} . Choose an integer i such that 1 \leq i \leq N and a_i is a multiple of 3 , and replace a_i with \frac{a_i}{3} . Your objective is to make A satisfy a_1=a_2=\ldots=a_N . Find the minimum total number of times you need to perform an operation to achieve the objective. If there is no way to achieve the objective, print -1 instead.
[ { "input": "3\n1 4 3\n", "output": "3\n" }, { "input": "3\n2 7 6\n", "output": "-1\n" }, { "input": "6\n1 1 1 1 1 1\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_e
Problem Statement We have a grid with H rows from top to bottom and W columns from left to right. Let (i, j) denote the i -th row from the top (1 \leq i \leq H) and j -th column from the left (1 \leq j \leq W) . Each square is one of the following: the initial point, a road, and an obstacle. A square (i, j) is represented by a character C_{i, j} . The square is the initial point if C_{i, j} = S , a road if C_{i, j} = . , and an obstacle if C_{i, j} = # . There is exactly one initial point. Determine whether there is a path of length 4 or greater that starts at the initial point, repeats moving vertically or horizontally to an adjacent square, and returns to the initial point without going through an obstacle or visiting the same square multiple times except at the beginning and the end. More formally, determine whether there are an integer n and a sequence of squares (x_0, y_0), (x_1, y_1), \dots, (x_n, y_n) that satisfy the following conditions. n \geq 4 . C_{x_0, y_0} = C_{x_n, y_n} = S . If 1 \leq i \leq n - 1 , then C_{x_i, y_i} = . . If 1 \leq i \lt j \leq n - 1 , then (x_i, y_i) \neq (x_j, y_j) . If 0 \leq i \leq n - 1 , then square (x_i, y_i) and square (x_{i+1}, y_{i+1}) are vertically or horizontally adjacent to each other.
[ { "input": "4 4\n....\n#.#.\n.S..\n.##.\n", "output": "Yes\n" }, { "input": "2 2\nS.\n.#\n", "output": "No\n" }, { "input": "5 7\n.#...#.\n..#.#..\n...S...\n..#.#..\n.#...#.\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_f
Problem Statement There are N cards called card 1 , card 2 , \ldots , card N . On card i (1\leq i\leq N) , an integer A_i is written. For K=1, 2, \ldots, N , solve the following problem. We have a bag that contains K cards: card 1 , card 2 , \ldots , card K . Let us perform the following operation twice, and let x and y be the numbers recorded, in the recorded order. Draw a card from the bag uniformly at random, and record the number written on that card. Then, return the card to the bag . Print the expected value of \max(x,y) , modulo 998244353 (see Notes). Here, \max(x,y) denotes the value of the greater of x and y (or x if they are equal).
[ { "input": "3\n5 7 5\n", "output": "5\n499122183\n443664163\n" }, { "input": "7\n22 75 26 45 72 81 47\n", "output": "22\n249561150\n110916092\n873463862\n279508479\n360477194\n529680742\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_g
Problem Statement Find the number of sequences of integers with N terms, A=(a_1,a_2,\ldots,a_N) , that satisfy the following conditions, modulo 998244353 . 0 \leq a_1 \leq a_2 \leq \ldots \leq a_N \leq M . For each i=1,2,\ldots,N-1 , the remainder when a_i is divided by 3 is different from the remainder when a_{i+1} is divided by 3 .
[ { "input": "3 4\n", "output": "8\n" }, { "input": "276 10000000\n", "output": "909213205\n" } ]
https://atcoder.jp/contests/abc276/tasks/abc276_h
Problem Statement Determine whether there is an N -by- N matrix X that satisfies the following conditions, and present one such matrix if it exists. (Let x_{i,j} denote the element of X at the i -th row from the top and j -th column from the left.) x_{i,j} \in \{ 0,1,2 \} for every i and j (1 \leq i,j \leq N) . The following holds for each i=1,2,\ldots,Q . Let P = \prod_{a_i \leq j \leq b_i} \prod_{c_i \leq k \leq d_i} x_{j,k} . Then, P is congruent to e_i modulo 3 .
[ { "input": "2 3\n1 1 1 2 0\n1 2 2 2 1\n2 2 1 2 2\n", "output": "Yes\n0 2\n1 2\n" }, { "input": "4 4\n1 4 1 4 0\n1 4 1 4 1\n1 4 1 4 2\n1 4 1 4 0\n", "output": "No\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_a
ๅ•้กŒๆ–‡ TTPC (Tottemo Tanoshii Programming Contest) ใฏใ€ 2015 ๅนดใซ 1 ๅ›ž็›ฎใŒ้–‹ๅ‚ฌใ•ใ‚Œใ€ใใฎๅพŒ A ๅนดใ”ใจ ( A ใฏๆญฃใฎๆ•ดๆ•ฐ) ใซ้–‹ๅ‚ฌใ•ใ‚Œใ‚‹ใ‚ณใƒณใƒ†ใ‚นใƒˆใงใ™ใ€‚ ใ‚ˆใ‚Šๆญฃ็ขบใซใฏใ€TTPC ใฏ 2015 + A \times n ( n ใฏ้ž่ฒ ๆ•ดๆ•ฐ) ใจ่กจใ™ใ“ใจใŒใงใใ‚‹ๅนดใซ้–‹ๅ‚ฌใ•ใ‚Œใ€ใใ‚Œไปฅๅค–ใฎๅนดใซใฏ้–‹ๅ‚ฌใ•ใ‚Œใพใ›ใ‚“ใ€‚ ใพใŸใ€TTPC ใฏใ€ 2015 ๅนดใฎไป–ใซใ‚‚ X ๅนดใจ Y ๅนดใซ้–‹ๅ‚ฌใ•ใ‚Œใ‚‹ใ“ใจใŒๅˆ†ใ‹ใฃใฆใ„ใพใ™ใ€‚ ใ“ใฎใจใใ€ A ใจใ—ใฆใ‚ใ‚Šๅพ—ใ‚‹ๆ•ดๆ•ฐใ‚’ ๆ˜‡้ †ใซ ๅ…จใฆๅ‡บๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚
[ { "input": "2019 2023\n", "output": "1\n2\n4\n" }, { "input": "999999999995 1000000000000\n", "output": "1\n5\n" }, { "input": "2019 2022\n", "output": "1\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_b
ๅ•้กŒๆ–‡ ใ‚ใชใŸใฏ X ๅ††ใŒๅ…ฅใฃใŸ้ญ”ๆณ•ใฎ่ฒกๅธƒใ‚’ๆŒใฃใฆใ„ใพใ™ใ€‚ ใ“ใฎ่ฒกๅธƒใซ้ญ”ๆณ•ใ‚’ไฝฟใ†ใจใ€ใ‚ใชใŸใฏ่ฒกๅธƒใซๅ…ฅใฃใฆใ„ใ‚‹้‡‘้กใ‚’ 10 ้€ฒใฎๆ–‡ๅญ—ๅˆ—ใจ่ฆ‹ใฆไปปๆ„ใซไธฆใณๆ›ฟใˆใ‚‹ใ“ใจใŒใงใใพใ™ใ€‚ ไพ‹ใˆใฐใ€ 120 ๅ††ใŒๅ…ฅใฃใŸ้ญ”ๆณ•ใฎ่ฒกๅธƒใซ้ญ”ๆณ•ใ‚’ไฝฟใ†ใจใ€ๅ…ฅใฃใฆใ„ใ‚‹้‡‘้กใ‚’ 12 ๅ††ใ€ 21 ๅ††ใ€ 102 ๅ††ใ€ 120 ๅ††ใ€ 201 ๅ††ใ€ 210 ๅ††ใฎใ„ใšใ‚Œใ‹ใซๅค‰ใˆใ‚‹ใ“ใจใŒใงใใพใ™(ๅ…ˆ้ ญใฎ 0 ใฏ็„ก่ฆ–ใ•ใ‚Œใพใ™)ใ€‚ ใ‚ใชใŸใฏใ“ใ‚Œใ‹ใ‚‰้ญ”ๆณ•ใฎ่ฒกๅธƒใ‚’ๆŒใฃใฆ N ๅ€‹ใฎใŠๅบ—ใ‚’ ้ †็•ชใซ ่จชใ‚Œใพใ™ใ€‚ i ็•ช็›ฎใฎใŠๅบ— ( 1 โ‰ค i โ‰ค N ) ใงใฏ A_i ๅ††ใฎๅ•†ๅ“ใŒ 1 ใคๅฃฒใฃใฆใŠใ‚Šใ€ใ‚‚ใ—้ญ”ๆณ•ใฎ่ฒกๅธƒใซ A_i ๅ††ไปฅไธŠๅ…ฅใฃใฆใ„ใ‚Œใฐใ€้ญ”ๆณ•ใฎ่ฒกๅธƒใ‹ใ‚‰ A_i ๅ††ใ‚’ๆ”ฏๆ‰•ใฃใฆใใฎๅ•†ๅ“ใ‚’่ฒทใ†ใ“ใจใŒใงใใพใ™ใ€‚ ้ญ”ๆณ•ใฏๅฅฝใใชใจใใซๅฅฝใใชใ ใ‘ไฝฟใ†ใ“ใจใŒใงใใพใ™ใ€‚ใ‚ใชใŸใฏๆœ€ๅคงใงๅ•†ๅ“ใ‚’ใ„ใใค่ฒทใ†ใ“ใจใŒใงใใพใ™ใ‹๏ผŸ
[ { "input": "2 120\n142 90\n", "output": "2\n" }, { "input": "1 119\n911\n", "output": "1\n" }, { "input": "5 1000\n900 90 900 9 900\n", "output": "3\n" }, { "input": "7 1171\n6328 2419 8302 7503 1744 8495 1522\n", "output": "5\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_c
ๅ•้กŒๆ–‡ ้•ทใ• N ใฎๆ•ดๆ•ฐๅˆ— A = (A_1, \dots, A_N), B = (B_1, \dots, B_N), C = (C_1, \dots, C_N), D = (D_1, \dots, D_N), E = (E_1, \dots, E_N) ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ ไปฅไธ‹ใฎๅ€คใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ \displaystyle\sum_{i=1}^{N}\sum_{j=1}^{N}\sum_{k=1}^{N}\sum_{l=1}^{N}\sum_{m=1}^{N}\mathrm{med}(A_i,B_j,C_k,D_l,E_m) ใŸใ ใ—ใ€ \mathrm{med}(a,b,c,d,e) ใฏ a,b,c,d,e ใฎไธญๅคฎๅ€คใ‚’่กจใ—ใพใ™ใ€‚
[ { "input": "1\n1\n2\n3\n4\n5\n", "output": "3\n" }, { "input": "3\n1 2 3\n1 3 2\n2 1 3\n2 3 1\n3 1 2\n", "output": "486\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_d
ๅ•้กŒๆ–‡ ้ ‚็‚นใซ 1, 2, \dots, N ใฎ็•ชๅทใŒไป˜ใ„ใŸใ€้ ‚็‚น 1 ใ‚’ๆ นใจใ™ใ‚‹ N ้ ‚็‚นใฎๆ นไป˜ใๆœจใŒใ‚ใ‚Šใพใ™ใ€‚ i ็•ช็›ฎใฎ่พบ ( 1 โ‰ค i โ‰ค N - 1 ) ใฏ้ ‚็‚น U_i ใจ้ ‚็‚น V_i ใ‚’็ตใ‚“ใงใ„ใพใ™ใ€‚ ๆœจใฎๅ„้ ‚็‚นใฏ็™ฝใ‹้ป’ใงๅก—ใ‚‰ใ‚ŒใฆใŠใ‚Šใ€้ ‚็‚น i ( 1 โ‰ค i โ‰ค N ) ใฏ A_i = 0 ใฎใจใ็™ฝใงใ€ A_i = 1 ใฎใจใ้ป’ใงๅก—ใ‚‰ใ‚Œใฆใ„ใพใ™ใ€‚ ๆœจใ‚’้ป’ใใ—ใŸใ„้ป’ๆœจใ•ใ‚“ใฏใ€ไปฅไธ‹ใฎๆ“ไฝœใ‚’ 0 ๅ›žไปฅไธŠใฎไปปๆ„ใฎๅ›žๆ•ฐ่กŒใฃใฆใ€ ้ป’ ใงๅก—ใ‚‰ใ‚Œใฆใ„ใ‚‹้ ‚็‚นใฎๆ•ฐใ‚’ๆœ€ๅคงๅŒ–ใ—ใพใ™ใ€‚ ่‘‰ ใงใ‚ใ‚‹้ ‚็‚น x ใ‚’ 1 ใค้ธใณใ€ๆ นใ‹ใ‚‰ x ใพใงใฎใƒ‘ใ‚นใซๅซใพใ‚Œใ‚‹้ ‚็‚น (ไธก็ซฏใ‚’ๅซใ‚€) ใฎ่‰ฒใ‚’ๅ่ปขใ•ใ›ใ‚‹ (็™ฝใงๅก—ใ‚‰ใ‚Œใฆใ„ใ‚‹ๅ ดๅˆใฏ้ป’ใซใ€้ป’ใงๅก—ใ‚‰ใ‚Œใฆใ„ใ‚‹ๅ ดๅˆใฏ็™ฝใซๅก—ใ‚Š็›ดใ™)ใ€‚ ้ป’ๆœจใ•ใ‚“ใฏไฝ•ๅ€‹ใฎ้ ‚็‚นใŒ้ป’ใซๅก—ใ‚‰ใ‚ŒใŸๆœจใ‚’ๅพ—ใ‚‹ใ“ใจใŒใงใใ‚‹ใงใ—ใ‚‡ใ†ใ‹๏ผŸ
[ { "input": "5\n1 0 0 1 0\n1 2\n1 3\n3 4\n3 5\n", "output": "5\n" }, { "input": "6\n1 1 0 0 1 0\n3 1\n2 5\n1 2\n4 1\n2 6\n", "output": "5\n" }, { "input": "9\n1 0 1 0 1 0 1 0 1\n2 9\n1 2\n6 9\n3 8\n4 5\n5 9\n2 8\n7 8\n", "output": "6\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_e
ๅ•้กŒๆ–‡ ๅคงๅญฆ A ใจๅคงๅญฆ B ใฏ็ตฑๅˆใ™ใ‚‹ใ“ใจใซใชใ‚Šใพใ—ใŸใ€‚ๅคงๅญฆ A ใฎๅคงๅญฆๅใฏ A ใ€ๅคงๅญฆ B ใฎๅคงๅญฆๅใฏ B ใงใ™ใ€‚็ตฑๅˆๅพŒใฎๆ–ฐใ—ใ„ๅคงๅญฆๅ C ใ‚’่€ƒใˆใพใ—ใ‚‡ใ†ใ€‚ๅ…ทไฝ“็š„ใซใฏใ€ไปฅไธ‹ใฎใ‚ˆใ†ใซใ—ใฆ C ใ‚’ๅฎšใ‚ใพใ™ใ€‚ A ใฎ็ฉบใงใชใ„้ƒจๅˆ†ๅˆ—ใ‚’ 1 ใคใจใฃใฆ a ใจใ™ใ‚‹ใ€‚ B ใฎ็ฉบใงใชใ„้ƒจๅˆ†ๅˆ—ใ‚’ 1 ใคใจใฃใฆ b ใจใ™ใ‚‹ใ€‚ C ใ‚’ a ใจ b ใ‚’ใ“ใฎ้ †ใง้€ฃ็ตใ—ใŸๆ–‡ๅญ—ๅˆ—ใจใ™ใ‚‹ใ€‚ Q ๅ€‹ใฎๆ–‡ๅญ—ๅˆ— S_1, S_2, \dots, S_Q ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ใใ‚Œใžใ‚Œใฎๆ–‡ๅญ—ๅˆ—ใŒ C ใจใ—ใฆใ‚ใ‚Šๅพ—ใ‚‹ใ‹ใฉใ†ใ‹ๅˆคๅฎšใ—ใ€ใ‚ใ‚Šๅพ—ใ‚‹ๅ ดๅˆใฏใ€ |\text{len}(a) - \text{len}(b)| ใจใ—ใฆใ‚ใ‚Šๅพ—ใ‚‹ๆœ€ๅฐๅ€คใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚( \text{len}(x) ใฏ x ใฎ้•ทใ•ใ‚’่กจใ™) ้ƒจๅˆ†ๅˆ—ใจใฏ๏ผŸ ๆ–‡ๅญ—ๅˆ— X ใซๅฏพใ—ใ€ใใฎๆ–‡ๅญ—ๅˆ—ใ‚’ๆง‹ๆˆใ™ใ‚‹ๆ–‡ๅญ—ใ‚’ 0 ๆ–‡ๅญ—ไปฅไธŠๅ–ใ‚Š้™คใใ€ๆฎ‹ใฃใŸๆ–‡ๅญ—ใ‚’ๅ…ƒใฎ้ †็•ชใงไธฆในใฆๅพ—ใ‚‰ใ‚Œใ‚‹ๆ–‡ๅญ—ๅˆ—ใ‚’ S ใฎ้ƒจๅˆ†ๅˆ—ใจๅ‘ผใณใพใ™ใ€‚ไพ‹ใˆใฐใ€ ac ใ‚„ abc ใฏ abc ใฎ้ƒจๅˆ†ๅˆ—ใงใ™ใŒใ€ ca ใฏ abc ใฎ้ƒจๅˆ†ๅˆ—ใงใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚
[ { "input": "Tokyo Institute of Technology\nTokyo Medical and Dental University\n10\nThe University\nTokyo University\nkyoto University\nTokyo Tech\nTMDU\nKyoto University\nThe University of Tokyo\nTokyo Technology and Medical and Dental University\n Tehnoooorsty\nTokyo\n", "output": "10\n4\n4\n-1\n2\n-1\n-1\n-1\n3\n1\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_f
ๅ•้กŒๆ–‡ ๆ•ดๆ•ฐๅˆ— L = (L_1, L_2, \dots, L_N) ใจ R = (R_1, R_2, \dots, R_N) ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ ไปฅไธ‹ใฎๆกไปถใ‚’ๆบ€ใŸใ™ ๅฎŸๆ•ฐ ๅˆ— A = (A_1, A_2, \dots, A_N) ใŒๅญ˜ๅœจใ™ใ‚‹ใ‹ๅˆคๅฎšใ—ใฆใใ ใ•ใ„ใ€‚ 1 \leq i \leq N ใ‚’ๆบ€ใŸใ™ใ™ในใฆใฎๆ•ดๆ•ฐ i ใซๅฏพใ—ใฆ L_i \leq A_i \leq R_i ใŒๆˆใ‚Š็ซ‹ใคใ€‚ 2 \leq i \leq N-1 ใ‚’ๆบ€ใŸใ™ใ™ในใฆใฎๆ•ดๆ•ฐ i ใซๅฏพใ—ใฆ A_{i-1} + A_{i+1} \geq 2 A_i ใŒๆˆใ‚Š็ซ‹ใคใ€‚
[ { "input": "4\n2 1 2 5\n4 6 5 8\n", "output": "Yes\n" }, { "input": "3\n1 4 2\n3 7 4\n", "output": "No\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_g
ๅ•้กŒๆ–‡ ๆ•ดๆ•ฐๅˆ— L = (L_1, L_2, \dots, L_N) ใจ R = (R_1, R_2, \dots, R_N) ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ ไปฅไธ‹ใฎๆกไปถใ‚’ๆบ€ใŸใ™ๆ•ดๆ•ฐๅˆ— A = (A_1, A_2, \dots, A_N) ใฎๅ€‹ๆ•ฐใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ 1 \leq i \leq N ใ‚’ๆบ€ใŸใ™ใ™ในใฆใฎๆ•ดๆ•ฐ i ใซๅฏพใ—ใฆ L_i \leq A_i \leq R_i ใŒๆˆใ‚Š็ซ‹ใคใ€‚ ใ‚ใ‚‹ๆ•ดๆ•ฐ d ใŒๅญ˜ๅœจใ—ใฆใ€ 1 \leq i \leq N-1 ใ‚’ๆบ€ใŸใ™ใ™ในใฆใฎๆ•ดๆ•ฐ i ใซๅฏพใ—ใฆ A_{i+1} - A_i = d ใŒๆˆใ‚Š็ซ‹ใคใ€‚
[ { "input": "3\n5 5 2\n7 6 7\n", "output": "6\n" }, { "input": "4\n2 3 1 6\n5 6 4 8\n", "output": "0\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_h
ๅ•้กŒๆ–‡ N ้ ‚็‚น M ่พบใฎๆœ‰ๅ‘ใ‚ฐใƒฉใƒ•ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚้ ‚็‚นใซใฏ 1 ใ‹ใ‚‰ N ใฎ็•ชๅทใŒใ€่พบใซใฏ 1 ใ‹ใ‚‰ M ใฎ็•ชๅทใŒใคใ„ใฆใ„ใพใ™ใ€‚่พบ i ( 1 โ‰ค i โ‰ค M ) ใฏ้ ‚็‚น A_i ใ‹ใ‚‰้ ‚็‚น B_i ใซๅ‘ใ‹ใ†่พบใงใ™ใ€‚ ใ‚ใชใŸใฏใ€ใ“ใฎใ‚ฐใƒฉใƒ•ใฎๅ„้ ‚็‚นใ‚’่‰ฒ 1, โ€ฆ, N ใฎใ„ใšใ‚Œใ‹ใงๅก—ใ‚Šใพใ™ใ€‚ใŸใ ใ—ใ€้ ‚็‚น i ( 1 โ‰ค i โ‰ค N ) ใซๅก—ใ‚‹่‰ฒใ‚’ c_i ใจใ—ใŸใจใใ€ไปฅไธ‹ใฎๆกไปถใ‚’ๆบ€ใŸใ™ๅฟ…่ฆใŒใ‚ใ‚Šใพใ™ใ€‚ ไปปๆ„ใฎ็ต„ (i, j) ( 1 โ‰ค i < j โ‰ค N ) ใซใคใ„ใฆใ€ c_i = c_j ใชใ‚‰ใฐใ€้ ‚็‚น i ใ‹ใ‚‰้ ‚็‚น j ใธใฎใƒ‘ใ‚นใ‹ใ€้ ‚็‚น j ใ‹ใ‚‰้ ‚็‚น i ใธใฎใƒ‘ใ‚นใฎใ„ใšใ‚Œใ‹ (ไธกๆ–นใงใ‚‚ใ‚ˆใ„) ใŒๅญ˜ๅœจใ™ใ‚‹ใ€‚ \max\{c_1, โ€ฆ, c_N\} ใŒๆœ€ๅฐใซใชใ‚‹ๅก—ใ‚Šๆ–นใ‚’ 1 ใคๆง‹็ฏ‰ใ—ใฆใใ ใ•ใ„ใ€‚
[ { "input": "5 5\n1 4\n2 3\n1 3\n2 5\n5 1\n", "output": "1 1 1 2 1\n" }, { "input": "5 7\n1 2\n2 1\n4 3\n5 1\n5 4\n4 1\n4 5\n", "output": "2 2 1 1 1\n" }, { "input": "8 6\n6 1\n3 4\n3 6\n2 3\n4 1\n6 4\n", "output": "4 4 4 4 3 4 2 1\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_i
ๅ•้กŒๆ–‡ ๆ•ดๆ•ฐ N,M,K ใจ N ้ ‚็‚น M ่พบใฎ็„กๅ‘ใ‚ฐใƒฉใƒ•ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ใ‚ฐใƒฉใƒ•ใฎ้ ‚็‚นใซใฏ 1 ใ‹ใ‚‰ N ใฎ็•ชๅทใŒใ€่พบใซใฏ 1 ใ‹ใ‚‰ M ใฎ็•ชๅทใŒไป˜ใ‘ใ‚‰ใ‚Œใฆใ„ใพใ™ใ€‚่พบ i ( 1 โ‰ค i โ‰ค M ) ใฏ้ ‚็‚น A_i ใจ้ ‚็‚น B_i ใฎ้–“ใ‚’ใคใชใ„ใงใ„ใฆใ€่พบไธŠใซใฏ้ž่ฒ ๆ•ดๆ•ฐ C_i ใŒ็ฝฎใ‹ใ‚Œใฆใ„ใพใ™ใ€‚ Q ๅ€‹ใฎใ‚ฏใ‚จใƒชใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ i ็•ช็›ฎ ( 1 โ‰ค i โ‰ค Q ) ใฎใ‚ฏใ‚จใƒชใงใฏใ€ๆ•ดๆ•ฐ D_{i} ใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใฎใงใ€ๆฌกใฎๆกไปถใ‚’ๅ…จใฆๆบ€ใŸใ™ๆ•ดๆ•ฐใฎ็ต„ (u,v) ใฎๅ€‹ๆ•ฐใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ 1\le u\lt v\le N (C_{j} \oplus D_{i})\lt K ใ‚’ๆบ€ใŸใ™ใ‚ˆใ†ใช่พบ j ใฎใฟใ‚’้€šใฃใฆใ€้ ‚็‚น u ใ‹ใ‚‰้ ‚็‚น v ใพใง็งปๅ‹•ใ™ใ‚‹ใ“ใจใŒๅฏ่ƒฝ ใŸใ ใ— \oplus ใฏใƒ“ใƒƒใƒˆๅ˜ไฝ \text{XOR} ๆผ”็ฎ—ใ‚’่กจใ—ใพใ™ใ€‚ ใƒ“ใƒƒใƒˆๅ˜ไฝ \text{XOR} ๆผ”็ฎ—ใจใฏ ้ž่ฒ ๆ•ดๆ•ฐ X,Y ใฎใƒ“ใƒƒใƒˆๅ˜ไฝ \text{XOR} ๆผ”็ฎ—ใ€ X\oplus Y ใฏไปฅไธ‹ใฎใ‚ˆใ†ใซๅฎš็พฉใ•ใ‚Œใพใ™ใ€‚ X\oplus Y ใ‚’ไบŒ้€ฒ่กจ่จ˜ใ—ใŸใจใใฎ 2^{k} ใฎไฝ ( 0\le k ) ใฏใ€ A,B ใ‚’ไบŒ้€ฒ่กจ่จ˜ใ—ใŸใจใใฎ 2^{k} ใฎไฝใŒ็•ฐใชใ‚‹ใชใ‚‰ 1 ใ€ใใ†ใงใชใ„ใชใ‚‰ 0 ใจใ™ใ‚‹ใ€‚ ไพ‹ใˆใฐใ€ 3\oplus 5=6 ใจใชใ‚Šใพใ™ใ€‚(ไบŒ้€ฒ่กจ่จ˜ใ™ใ‚‹ใจ 011\oplus 101=110 )
[ { "input": "4 5 5\n1 2 17\n1 3 4\n2 3 20\n2 4 3\n3 4 5\n4\n0\n7\n16\n167\n", "output": "2\n6\n3\n0\n" }, { "input": "9 13 488888932\n2 7 771479959\n3 8 783850182\n5 7 430673756\n6 8 350738034\n4 9 400768807\n2 3 83653266\n1 2 829786563\n5 8 357613791\n7 9 579696618\n3 7 423191200\n3 5 867380255\n1 9 907715012\n6 9 1033650694\n8\n498260055\n144262908\n117665696\n848664012\n983408133\n32610599\n478007408\n134182829\n", "output": "16\n7\n5\n13\n13\n16\n16\n5\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_j
ๅ•้กŒๆ–‡ N ้ ‚็‚น M ่พบใฎๆœ‰ๅ‘ใ‚ฐใƒฉใƒ•ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚้ ‚็‚นใซใฏ 1 ใ‹ใ‚‰ N ใฎ็•ชๅทใŒใ€่พบใซใฏ 1 ใ‹ใ‚‰ M ใฎ็•ชๅทใŒไป˜ใ‘ใ‚‰ใ‚Œใฆใ„ใฆใ€่พบ i ( 1 โ‰ค i โ‰ค M ) ใฏ้ ‚็‚น A_i ใ‹ใ‚‰้ ‚็‚น B_i ใธใฎ่พบใงใ™ใ€‚ใ“ใฎใ‚ฐใƒฉใƒ•ใซ่‡ชๅทฑใƒซใƒผใƒ—ใฏๅญ˜ๅœจใ™ใ‚‹ใ‹ใ‚‚ใ—ใ‚Œใพใ›ใ‚“ใŒใ€ๅคš้‡่พบใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚ใฉใฎ้ ‚็‚นใ‹ใ‚‰ใ‚‚่พบใŒ 1 ๆœฌไปฅไธŠๅ‡บใฆใ„ใ‚‹ใ“ใจใŒไฟ่จผใ•ใ‚Œใพใ™ใ€‚ ้ ‚็‚นใฎใ†ใก K ๅ€‹ใซใฏๅฎ็ŸณใŒ็ฝฎใ‹ใ‚Œใฆใ„ใพใ™ใ€‚ i ็•ช็›ฎ ( 1 โ‰ค i โ‰ค K ) ใฎๅฎ็Ÿณใฏ้ ‚็‚น V_i ใซใ‚ใ‚Šใ€ไพกๅ€คใฏ W_i ใงใ™ใ€‚ ใ“ใฎใ‚ฐใƒฉใƒ•ใ‚’ไฝฟใฃใฆ First ๅ›ใจ Second ๅ›ใŒใ‚ฒใƒผใƒ ใ‚’ใ—ใพใ™ใ€‚ใ‚ฒใƒผใƒ ้–‹ๅง‹ๆ™‚ใ€First ๅ›ใฏ้ ‚็‚น F ใซใ€Second ๅ›ใฏ้ ‚็‚น S ใซใ„ใพใ™ใ€‚First ๅ›ใ‹ใ‚‰ๅง‹ใ‚ใฆใ€First ๅ›ใจ Second ๅ›ใŒไบคไบ’ใซไปฅไธ‹ใฎๆ“ไฝœใ‚’่กŒใ„ใพใ™ใ€‚ ่‡ชๅˆ†ใŒไปŠใ„ใ‚‹้ ‚็‚นใ‹ใ‚‰ๅ‡บใฆใ„ใ‚‹่พบใ‚’ 1 ใค้ธใณใ€ใใฎ่พบใซๆฒฟใฃใฆๆฌกใฎ้ ‚็‚นใพใง็งปๅ‹•ใ™ใ‚‹ใ€‚็งปๅ‹•ใ—ใŸ้ ‚็‚นใซๅฎ็ŸณใŒใ‚ใ‚Œใฐใใ‚Œใ‚’ๆ‰‹ใซๅ…ฅใ‚Œใ€ใใฎๅฎ็Ÿณใฏใ‚ฐใƒฉใƒ•ไธŠใ‹ใ‚‰ๅ–ใ‚Š้™คใ‹ใ‚Œใ‚‹ใ€‚ ๅ…จใฆใฎๅฎ็Ÿณใ‚’ๅ–ใ‚‹ใ‹ใ€ใ‚ฒใƒผใƒ ไธญใซใ‚ใฃใŸ็›ค้ขใจๅŒใ˜็›ค้ข (ๆ‰‹็•ชใ€ๅ„ใƒ—ใƒฌใ‚คใƒคใƒผใฎไฝ็ฝฎใ€ๆฎ‹ใฃใฆใ„ใ‚‹ๅฎ็ŸณใŒๅ…จใๅŒใ˜็Šถๆ…‹) ใŒๅ†ใณ็™ปๅ ดใ™ใ‚‹ใจใ‚ฒใƒผใƒ ใฏ็ต‚ไบ†ใ—ใพใ™ใ€‚ ใŠไบ’ใ„ใซใ€(่‡ชๅˆ†ใฎๅ–ใ‚‹ๅฎ็Ÿณใฎไพกๅ€คใฎๅˆ่จˆ) - (็›ธๆ‰‹ใฎๅ–ใ‚‹ๅฎ็Ÿณใฎไพกๅ€คใฎๅˆ่จˆ) ใŒใงใใ‚‹ใ ใ‘ๅคงใใใชใ‚‹ใ‚ˆใ†ใซ่กŒๅ‹•ใ™ใ‚‹ใจใใ€ใ‚ฒใƒผใƒ ็ต‚ไบ†ๆ™‚ใฎ (First ๅ›ใฎๅ–ใ‚‹ๅฎ็Ÿณใฎไพกๅ€คใฎๅˆ่จˆ) - (Second ๅ›ใฎๅ–ใ‚‹ๅฎ็Ÿณใฎไพกๅ€คใฎๅˆ่จˆ) ใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚
[ { "input": "5 16 1 1\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 2\n3 4\n3 5\n4 2\n4 3\n4 5\n5 2\n5 3\n5 4\n4\n2 4\n3 84\n4 38\n5 96\n", "output": "46\n" }, { "input": "8 16 8 4\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 1\n1 5\n2 6\n3 7\n4 8\n5 1\n6 2\n7 3\n8 4\n6\n1 29\n2 34\n3 41\n5 7\n6 26\n7 94\n", "output": "-23\n" }, { "input": "5 5 2 1\n1 1\n2 3\n3 4\n4 5\n5 2\n2\n4 1000000\n5 100000\n", "output": "1100000\n" }, { "input": "10 20 1 2\n1 4\n1 7\n2 2\n2 4\n3 6\n3 3\n4 8\n4 7\n5 7\n5 1\n6 9\n6 2\n7 9\n7 3\n8 8\n8 6\n9 7\n9 8\n10 10\n10 2\n8\n3 92067840\n4 2874502\n5 36253165\n6 70758738\n7 4768969\n8 16029185\n9 16207515\n10 44912151\n", "output": "132484345\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_k
ๅ•้กŒๆ–‡ Alice ใจ Bob ใจ Chris ใฏใ“ใ‚Œใ‹ใ‚‰ N ๅ›žใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใ‚’ใ—ใพใ™ใ€‚ ใŸใ ใ—ใ€ๅ„ใ€…ใŒๅ‡บใ™ๆ‰‹ใซใฏๆฌกใฎใ‚ˆใ†ใชๅˆถ้™ใŒใ‚ใ‚Šใพใ™ใ€‚ Alice ใฏ ใ‚ฐใƒผ ใ‚’ใกใ‚‡ใ†ใฉ A_R ๅ›žใ€ ใƒ‘ใƒผ ใ‚’ใกใ‚‡ใ†ใฉ A_P ๅ›žใ€ ใƒใƒงใ‚ญ ใ‚’ใกใ‚‡ใ†ใฉ A_S ๅ›ž ๅ‡บใ™ใ€‚ Bob ใฏ ใ‚ฐใƒผ ใ‚’ใกใ‚‡ใ†ใฉ B_R ๅ›žใ€ ใƒ‘ใƒผ ใ‚’ใกใ‚‡ใ†ใฉ B_P ๅ›žใ€ ใƒใƒงใ‚ญ ใ‚’ใกใ‚‡ใ†ใฉ B_S ๅ›ž ๅ‡บใ™ใ€‚ Chris ใฏ ใ‚ฐใƒผ ใ‚’ใกใ‚‡ใ†ใฉ C_R ๅ›žใ€ ใƒ‘ใƒผ ใ‚’ใกใ‚‡ใ†ใฉ C_P ๅ›žใ€ ใƒใƒงใ‚ญ ใ‚’ใกใ‚‡ใ†ใฉ C_S ๅ›ž ๅ‡บใ™ใ€‚ Alice ใจ Bob ใจ Chris ใฏใจใฆใ‚‚ไปฒ่‰ฏใ—ใชใฎใงใ€ N ๅ›žใ™ในใฆใง ใ‚ใ„ใ“ ใซใชใ‚‹ใ‚ˆใ†ใซใ—ใŸใ„ใงใ™ใ€‚ N ๅ›žใฎใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใซใ‚ใŸใ‚‹ 3 ไบบใฎๆ‰‹ใฎๅ‡บใ—ๆ–นใงใ‚ใฃใฆใ“ใ‚Œใ‚’้”ๆˆใ™ใ‚‹ๆ–นๆณ•ใฎๆ•ฐใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ ใ‚ใ„ใ“ใจใฏ 1 ๅ›žใฎใ˜ใ‚ƒใ‚“ใ‘ใ‚“ใง 3 ไบบใฎๅ‡บใ™ๆ‰‹ใŒใ™ในใฆๅŒใ˜ใจใใ€ ใพใŸใฏใ™ในใฆ็•ฐใชใ‚‹ใจใใ€ ใ‚ใ„ใ“ ใจใชใ‚Šใพใ™ใ€‚
[ { "input": "2\n2 0 0 1 1 0 1 0 1\n", "output": "2\n" }, { "input": "3\n0 1 2 3 0 0 1 1 1\n", "output": "0\n" }, { "input": "333333\n111111 111111 111111 111111 111111 111111 111111 111111 111111\n", "output": "383902959\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_l
ๅ•้กŒๆ–‡ ๆญฃๆ•ดๆ•ฐ N,M ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ (0,1,...,NM-1) ใฎ้ †ๅˆ— P=(P_{0},P_{1},...,P_{NM-1}) ใฎใ†ใกใ€ไปฅไธ‹ใฎๆกไปถใ‚’ๆบ€ใŸใ™ใ‚‚ใฎใฎๅ€‹ๆ•ฐใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚ 0\le i\lt NM ใ‚’ๆบ€ใŸใ™ๅ…จใฆใฎๆ•ดๆ•ฐ i ใซใคใ„ใฆใ€ \left\lfloor \frac{i}{M} \right\rfloor \neq \left\lfloor \frac{P_{i}}{M}\right\rfloor ใŒๆˆใ‚Š็ซ‹ใคใ€‚ ใŸใ ใ—ใ€ \left\lfloor X \right\rfloor ใฏ X ไปฅไธ‹ใฎๆœ€ๅคงใฎๆ•ดๆ•ฐใ‚’่กจใ—ใพใ™ใ€‚
[ { "input": "2 2\n", "output": "4\n" }, { "input": "5 1\n", "output": "44\n" }, { "input": "167 91\n", "output": "284830080\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_m
ๅ•้กŒๆ–‡ ๆญฃๆ•ดๆ•ฐ N, M ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ N ๅ€‹ใฎๆญฃๆ•ดๆ•ฐใฎ็ต„ (x_1,x_2,\dots ,x_N) ใงใ‚ใฃใฆ \displaystyle\prod_{i=1}^{N}x_i=M ใ‚’ๆบ€ใŸใ™ใ‚‚ใฎใ™ในใฆใฎ้›†ๅˆใ‚’ \bm{X} ใจใ—ใพใ™ใ€‚ \displaystyle\sum_{(x_1,x_2,\dots ,x_N)\in \bm{X}}\prod_{i=1}^{N} (x_i+A_i) ใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚
[ { "input": "2 3\n0 1\n", "output": "10\n" }, { "input": "5 1\n0 1 2 3 4\n", "output": "120\n" }, { "input": "10 314159265358\n0 1 2 3 4 5 6 7 8 9\n", "output": "658270849\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_n
ๅ•้กŒๆ–‡ ๆ•ดๆ•ฐ K ใจ 3 ๆฌกๅ…ƒไธŠใฎ N ๅ€‹ใฎ็‚น (x_1,y_1,z_1), \dots, (x_N,y_N,z_N) ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚ N ็‚น (K x_1,K y_1,K z_1), \dots, (K x_N,K y_N,K z_N) ใฎๅ‡ธๅŒ…ใฎๅ†…้ƒจใพใŸใฏๅขƒ็•Œใซๅซใพใ‚Œใ‚‹็‚นใงใ‚ใฃใฆๅบงๆจ™ใŒใ™ในใฆๆ•ดๆ•ฐใงใ‚ใ‚‹ใ‚ˆใ†ใชใ‚‚ใฎใฎๅ€‹ๆ•ฐใ‚’ 998244353 ใงๅ‰ฒใฃใŸใ‚ใพใ‚Šใ‚’ๆฑ‚ใ‚ใฆใใ ใ•ใ„ใ€‚
[ { "input": "4 2\n0 0 0\n1 0 0\n0 1 0\n0 0 1\n", "output": "10\n" }, { "input": "4 10000\n0 0 0\n1 0 0\n0 1 0\n0 0 1\n", "output": "59878050\n" }, { "input": "8 314159265358979\n5 -3 -3\n-5 -3 -3\n0 5 -3\n0 0 10\n4 2 6\n-4 2 6\n0 -5 6\n0 0 -5\n", "output": "152811018\n" } ]
https://atcoder.jp/contests/ttpc2022/tasks/ttpc2022_o
็ฐกๅ˜ใชๅ•้กŒๆ–‡ ่ฌŽใฎใƒขใƒŽใ‚คใƒ‰ (M, \oplus) ใจใ€ใ“ใ‚Œใ‚’่จˆ็ฎ—ใ™ใ‚‹ CPU ใŒ 4 ๅ€‹ใ‚ใ‚Šใพใ™ใ€‚ ๆ•ดๆ•ฐ N ใŒไธŽใˆใ‚‰ใ‚Œใ‚‹ใฎใงใ€ M ใฎๅˆ— A = (A_1, A_2, โ€ฆ, A_N) ใ‹ใ‚‰ A ใฎ็ดฏ็ฉ \oplus ใ‚’ 4 ไธฆๅˆ—ใง่จˆ็ฎ—ใ—ใฆใใ ใ•ใ„ใ€‚ ใใฎ้š›ใ€ๆ“ไฝœๅ›žๆ•ฐใ‚’ๆœ€ๅฐๅŒ–ใ—ใฆใใ ใ•ใ„ใ€‚
[ { "input": "2\n", "output": "1\n2 1 2\n2000 2000 2000\n2000 2000 2000\n2000 2000 2000\n" }, { "input": "4\n", "output": "2\n2 1 2\n4 3 4\n2000 2000 2000\n2000 2000 2000\n3 2 3\n4 2 4\n2000 2000 2000\n2000 2000 2000\n" } ]
https://atcoder.jp/contests/ahc015/tasks/ahc015_a
Problem Statement There is a box that can contain 10\times 10 pieces of candy in a grid pattern. The box is initially empty, and 100 pieces of candy will be placed in order. There are 3 flavors of candy, and we know in advance the flavor f_t (1\leq f_t\leq 3) of the t -th candy. On the other hand, we do not know in advance to which cell each candy will be placed, and it will be chosen uniformly at random among the empty cells. You cannot change the order in which the pieces of candy are received. Each time you receive one piece of candy, you must tilt the box forward, backward, left, or right exactly once. When you tilt the box, each piece of candy moves in that direction simultaneously until it reaches the edge or hits another candy. For example, if you tilt the box forward in the state shown in the left figure, the box will be in the state shown in the right figure.
[]
https://atcoder.jp/contests/abc275/tasks/abc275_a
Problem Statement There are N bridges in AtCoder Village. The height of the bridge numbered i is H_i ( i is an integer between 1 and N ). Every two different bridges in the village have different heights. Print the number representing the highest bridge in the village.
[ { "input": "3\n50 80 70\n", "output": "2\n" }, { "input": "1\n1000000000\n", "output": "1\n" }, { "input": "10\n22 75 26 45 72 81 47 29 97 2\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_b
Problem Statement There are non-negative integers A , B , C , D , E , and F , which satisfy A\times B\times C\geq D\times E\times F . Find the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353 .
[ { "input": "2 3 5 1 2 4\n", "output": "22\n" }, { "input": "1 1 1000000000 0 0 0\n", "output": "1755647\n" }, { "input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_c
Problem Statement There is a two-dimensional plane. For integers r and c between 1 and 9 , there is a pawn at the coordinates (r,c) if the c -th character of S_{r} is # , and nothing if the c -th character of S_{r} is . . Find the number of squares in this plane with pawns placed at all four vertices.
[ { "input": "##.......\n##.......\n.........\n.......#.\n.....#...\n........#\n......#..\n.........\n.........\n", "output": "2\n" }, { "input": ".#.......\n#.#......\n.#.......\n.........\n....#.#.#\n.........\n....#.#.#\n........#\n.........\n", "output": "3\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_d
Problem Statement A function f(x) defined for non-negative integers x satisfies the following conditions. f(0) = 1 . f(k) = f(\lfloor \frac{k}{2}\rfloor) + f(\lfloor \frac{k}{3}\rfloor) for any positive integer k . Here, \lfloor A \rfloor denotes the value of A rounded down to an integer. Find f(N) .
[ { "input": "2\n", "output": "3\n" }, { "input": "0\n", "output": "1\n" }, { "input": "100\n", "output": "55\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_e
Problem Statement Takahashi is playing sugoroku, a board game. The board has N+1 squares, numbered 0 to N . Takahashi starts at square 0 and goes for square N . The game uses a roulette wheel with M numbers from 1 to M that appear with equal probability. Takahashi spins the wheel and moves by the number of squares indicated by the wheel. If this would send him beyond square N , he turns around at square N and goes back by the excessive number of squares. For instance, assume that N=4 and Takahashi is at square 3 . If the wheel shows 4 , the excessive number of squares beyond square 4 is 3+4-4=3 . Thus, he goes back by three squares from square 4 and arrives at square 1 . When Takahashi arrives at square N , he wins and the game ends. Find the probability, modulo 998244353 , that Takahashi wins when he may spin the wheel at most K times. How to print a probability modulo 998244353 It can be proved that the sought probability is always a rational number. Additionally, under the Constraints of this problem, when the sought probability is represented as an irreducible fraction \frac{y}{x} , it is guaranteed that x is not divisible by 998244353 . Here, there is a unique integer z between 0 and 998244352 such that xz \equiv y \pmod{998244353} . Print this z .
[ { "input": "2 2 1\n", "output": "499122177\n" }, { "input": "10 5 6\n", "output": "184124175\n" }, { "input": "100 1 99\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_f
Problem Statement You are given an integer array A=(a_1,a_2,\ldots,a_N) . You may perform the following operation any number of times (possibly zero). Choose a nonempty contiguous subarray of A , and delete it from the array. For each x=1,2,\ldots,M , solve the following problem: Find the minimum possible number of operations to make the sum of elements of A equal x . If it is impossible to make the sum of elements of A equal x , print -1 instead. Note that the sum of elements of an empty array is 0 .
[ { "input": "4 5\n1 2 3 4\n", "output": "1\n2\n1\n1\n1\n" }, { "input": "1 5\n3\n", "output": "-1\n-1\n0\n-1\n-1\n" }, { "input": "12 20\n2 5 6 5 2 1 7 9 7 2 5 5\n", "output": "2\n1\n2\n2\n1\n2\n1\n2\n2\n1\n2\n1\n1\n1\n2\n2\n1\n1\n1\n1\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_g
Problem Statement There are N kinds of items, each with infinitely many copies. The i -th kind of item has a weight of A_i , a volume of B_i , and a value of C_i . Level X Takahashi can carry items whose total weight is at most X and whose total volume is at most X . Under this condition, it is allowed to carry any number of items of the same kind, or omit some kinds of items. Let f(X) be the maximum total value of items Level X Takahashi can carry. It can be proved that the limit \displaystyle\lim_{X\to \infty} \frac{f(X)}{X} exists. Find this limit.
[ { "input": "2\n100000000 200000000 100000000\n200000000 100000000 100000000\n", "output": "0.6666666666666667\n" }, { "input": "1\n500000000 300000000 123456789\n", "output": "0.2469135780000000\n" } ]
https://atcoder.jp/contests/abc275/tasks/abc275_h
Problem Statement There are N monsters along a number line. At the coordinate i (1\leq i\leq N) is a monster with a stamina of A_i . Additionally, at the coordinate i , there is a permanent shield of a strength B_i . This shield persists even when the monster at the same coordinate has a health of 0 or below. Takahashi, a magician, can perform the following operation any number of times. Choose integers l and r satisfying 1\leq l\leq r\leq N . Then, consume \max(B_l, B_{l+1}, \ldots, B_r) MP (magic points) to decrease by 1 the stamina of each of the monsters at the coordinates l,l+1,\ldots,r . When choosing l and r , it is fine if some of the monsters at the coordinates l,l+1,\ldots,r already have a stamina of 0 or below. Note, however, that the shields at all those coordinates still exist. Takahashi wants to make the stamina of every monster 0 or below. Find the minimum total MP needed to achieve his objective.
[ { "input": "5\n4 3 5 1 2\n10 40 20 60 50\n", "output": "210\n" }, { "input": "1\n1000000000\n1000000000\n", "output": "1000000000000000000\n" }, { "input": "10\n522 4575 6426 9445 8772 81 3447 629 3497 7202\n7775 4325 3982 4784 8417 2156 1932 5902 5728 8537\n", "output": "77917796\n" } ]
https://atcoder.jp/contests/abc274/tasks/abc274_a
Problem Statement Takahashi is making a computer baseball game. He will write a program that shows a batter's batting average with a specified number of digits. There are integers A and B , which satisfy 1 \leq A \leq 10 and 0 \leq B \leq A . Let S be the string obtained as follows. Round off \dfrac{B}{A} to three decimal digits, then write the integer part ( 1 digit), . (the decimal point), and the decimal part ( 3 digits) in this order, with trailing zeros. For example, if A=7 and B=4 , then \dfrac{B}{A} = \dfrac{4}{7} = 0.571428\dots rounded off to three decimal digits is 0.571 . Thus, S is 0.571 . You are given A and B as the input and asked to print S .
[ { "input": "7 4\n", "output": "0.571\n" }, { "input": "7 3\n", "output": "0.429\n" }, { "input": "2 1\n", "output": "0.500\n" }, { "input": "10 10\n", "output": "1.000\n" }, { "input": "1 0\n", "output": "0.000\n" } ]