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 ...
[ { "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 ...
[]
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 ...
[]
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...
[ { "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 ...
[ { "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 ). N...
[ { "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 h...
[ { "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 4...
[ { "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 o...
[ { "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...
[ { "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 99...
[ { "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 , y...
[ { "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...
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 move...
[ { "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...
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...
[ { "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 48...
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...
[ { "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 consisti...
[ { "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_{\mathr...
[ { "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-...
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. F...
[ { "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...
[ { "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 vertic...
[ { "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) . ...
[ { "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 , wh...
[ { "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\...
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. Dele...
[ { "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 colum...
[ { "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#..#....
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 t...
[ { "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, ...
[ { "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 guarante...
[ { "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 we...
[ { "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): \displaysty...
[ { "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...
[ { "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 tr...
[ { "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 ma...
[ { "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 endpoi...
[ { "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 c...
[ { "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 neve...
[ { "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 s...
[ { "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 ar...
[ { "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...
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...
[ { "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...
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 . ...
[ { "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...
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 alternatin...
[ { "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\nm...
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 op...
[]
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 ...
[ { "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 ใจใชใ‚‹๏ผŽๅŒใ˜่‹ฑ...
[ { "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 ...
[ { "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 directi...
[ { "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 ...
[ { "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: verte...
[ { "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 ...
[ { "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 adjac...
[ { "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 grap...
[]
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...
[ { "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 permutati...
[ { "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 suc...
[ { "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 represen...
[ { "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 ...
[ { "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...
[ { "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 fol...
[ { "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,...
[ { "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}(...
[ { "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...
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, โ€ฆ...
[ { "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 ใพใง็งปๅ‹•...
[ { "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...
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 ใซใ„ใพใ™ใ€‚Fi...
[ { "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", "o...
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...
[ { "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 ...
[]
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 in...
[ { "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 ope...
[ { "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 num...
[ { "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...
[ { "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 deci...
[ { "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" } ]