url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc288/tasks/abc288_h
Problem Statement Print the number of integer sequences of length N , A = (A_1, A_2, \ldots, A_N) , that satisfy both of the following conditions, modulo 998244353 . 0 \leq A_1 \leq A_2 \leq \cdots \leq A_N \leq M A_1 \oplus A_2 \oplus \cdots \oplus A_N = X Here, \oplus denotes bitwise XOR. What is bitwise XOR? The bitwise 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": "3 3 2\n", "output": "5\n" }, { "input": "200 900606388 317329110\n", "output": "788002104\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_a
Problem Statement You are given a string S of length N consisting of lowercase English letters, and a positive integer K . Determine whether there is a string S' of length K that satisfies the following conditions. The concatenation of S and S' in this order is a palindrome. The concatenation of S' and S in this order is a palindrome. You have T test cases to solve.
[ { "input": "2\n6 2\nabbaab\n5 3\nabcbb\n", "output": "Yes\nNo\n" }, { "input": "3\n12 400378271514996652\nnjvhhvjnnjvh\n10 884633988115575508\nrrhiyvrrur\n36 71630165869626180\nvsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh\n", "output": "Yes\nNo\nYes\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_b
Problem Statement For a set S of pairs of non-negative integers, and a non-negative integer x , let f_S(x) defined as \displaystyle f_S(x)=\min_{(a, b) \in S} \left| \left| x-a \right| - b \right| . We have a set T of pairs of non-negative integers. Initially, T=\lbrace (A, B)\rbrace . Process Q queries. The i -th query gives you three non-negative integers t_i , a_i , and b_i , and asks you to do the following. If t_i=1 , add to T the pair (a_i, b_i) of non-negative integers. If t_i=2 , print the minimum value of f_{T}(x) for a non-negative integer x such that a_i \leq x \leq b_i .
[ { "input": "4 0 5\n1 3 11\n2 7 8\n1 8 2\n2 8 9\n", "output": "2\n1\n" }, { "input": "2 1 2\n1 2 3\n2 2 6\n", "output": "0\n" }, { "input": "20 795629912 123625148\n2 860243184 892786970\n2 645778367 668513124\n1 531411849 174630323\n1 635062977 195695960\n2 382061637 411843651\n1 585964296 589553566\n1 310118888 68936560\n1 525351160 858166280\n2 395304415 429823333\n2 583145399 703645715\n2 97768492 218377432\n1 707220749 459967102\n1 210842017 363390878\n2 489541834 553583525\n2 731279777 811513313\n1 549864943 493384741\n1 815378318 826084592\n2 369622093 374205455\n1 78240781 821999998\n2 241667193 243982581\n", "output": "26468090\n3491640\n25280111\n9543684\n0\n22804896\n20649370\n19245624\n4849993\n484865\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_c
Problem Statement You are given integer sequences of length N : A=(A_1, A_2, \dots, A_N) and B=(B_1, B_2, \dots, B_N) . You may perform the following operation any number of times: Choose an integer i\ (1 \leq i \leq N-2) such that A_i+A_{i+1}+A_{i+2} is even. Then, rearrange A_i , A_{i+1} , A_{i+2} as you like. Determine whether it is possible to make A equal B .
[ { "input": "5\n1 2 3 4 5\n3 1 2 4 5\n", "output": "Yes\n" }, { "input": "5\n1 2 4 6 5\n5 1 4 2 6\n", "output": "No\n" }, { "input": "9\n2 10 4 3 6 2 6 8 5\n2 4 10 3 8 6 6 2 5\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_d
Problem Statement For two non-negative integers x and y , let \gcd(x,y) be the greatest common divisor of x and y (for x=0 , let \gcd(x,y)=\gcd(y,x)=y ). There are N integers on the blackboard, and the i -th integer is A_i . The greatest common divisor of these N integers is 1 . Takahashi and Aoki will play a game against each other. After initializing an integer G to 0 , they will take turns performing the following operation, with Takahashi going first. Choose a number a on the blackboard such that \gcd(G,a)\neq 1 , erase it, and replace G with \gcd(G,a) . The first player unable to play loses. For each i\ (1\leq i \leq N) , determine the winner when Takahashi chooses the i -th integer on the blackboard in his first turn, and then both players play optimally.
[ { "input": "4\n2 3 4 6\n", "output": "Takahashi\nAoki\nTakahashi\nAoki\n" }, { "input": "4\n2 155 155 155\n", "output": "Takahashi\nTakahashi\nTakahashi\nTakahashi\n" }, { "input": "20\n2579 25823 32197 55685 73127 73393 74033 95252 104289 114619 139903 144912 147663 149390 155806 169494 175264 181477 189686 196663\n", "output": "Takahashi\nAoki\nTakahashi\nAoki\nTakahashi\nTakahashi\nTakahashi\nTakahashi\nAoki\nTakahashi\nTakahashi\nAoki\nAoki\nAoki\nAoki\nAoki\nTakahashi\nTakahashi\nAoki\nTakahashi\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_e
Problem Statement For a set X of non-negative integers, let f(X) denote the set of non-negative integers that can be represented as the bitwise \mathrm{XOR} of two integers (possibly the same) in X . As an example, for X=\lbrace 1, 2, 4\rbrace , we have f(X)=\lbrace 0, 3, 5, 6\rbrace . You are given a set of N non-negative integers less than 2^M : S=\lbrace A_1, A_2, \dots, A_N\rbrace . You may perform the following operation any number of times. Divide S into two sets T_1 and T_2 (one of them may be empty). Then, replace S with the union of f(T_1) and f(T_2) . Find the minimum number of operations needed to make S=\lbrace 0\rbrace . What is bitwise \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": "4 2\n00\n01\n10\n11\n", "output": "2\n" }, { "input": "1 8\n10011011\n", "output": "1\n" }, { "input": "1 2\n00\n", "output": "0\n" }, { "input": "20 20\n10011011111101101111\n10100111100001111100\n10100111100110001111\n10011011100011011111\n11001000001110011010\n10100111111011000101\n11110100001001110010\n10011011100010111001\n11110100001000011010\n01010011101011010011\n11110100010000111100\n01010011101101101111\n10011011100010110111\n01101111101110001110\n00111100000101111010\n01010011101111010100\n10011011100010110100\n01010011110010010011\n10100111111111000001\n10100111111000010101\n", "output": "10\n" } ]
https://atcoder.jp/contests/arc155/tasks/arc155_f
Problem Statement You are given a sequence of N non-negative integers: D=(D_1, D_2, \dots, D_N) . Find the number of labeled trees with N vertices numbered 1 to N that satisfy the following condition, modulo 998244353 . There is a way to direct the N-1 edges so that the outdegree of each vertex i\ (1\leq i \leq N) is D_i .
[ { "input": "4\n0 1 0 2\n", "output": "5\n" }, { "input": "5\n0 1 1 1 1\n", "output": "125\n" }, { "input": "15\n0 0 0 0 0 0 0 1 1 1 1 1 2 3 4\n", "output": "63282877\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_a
Problem Statement There are N people. Each of them agrees or disagrees with a proposal. Here, N is an odd number. The i -th (i = 1, 2, \dots, N) person's opinion is represented by a string S_i : the person agrees if S_i = For and disagrees if S_i = Against . Determine whether the majority agrees with the proposal.
[ { "input": "3\nFor\nAgainst\nFor\n", "output": "Yes\n" }, { "input": "5\nAgainst\nAgainst\nFor\nAgainst\nFor\n", "output": "No\n" }, { "input": "1\nFor\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_b
Problem Statement You are given N strings of length six each, consisting of digits. Let S_i be the i -th (i = 1, 2, \dots, N) of them. You are also given M strings of length three each, consisting of digits. Let T_j be the j -th (j = 1, 2, \dots, M) of them. Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M .
[ { "input": "3 3\n142857\n004159\n071028\n159\n287\n857\n", "output": "2\n" }, { "input": "5 4\n235983\n109467\n823476\n592801\n000333\n333\n108\n467\n983\n", "output": "3\n" }, { "input": "4 4\n000000\n123456\n987111\n000000\n000\n111\n999\n111\n", "output": "3\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_c
Problem Statement You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, 2, \dots, N , and the edges are numbered 1, 2, \dots, M . Edge i \, (i = 1, 2, \dots, M) connects vertices u_i and v_i . Determine if this graph is a path graph. What is a simple undirected graph? A simple undirected graph is a graph without self-loops or multiple edges whose edges do not have a direction. What is a path graph? A graph with N vertices numbered 1, 2, \dots, N is said to be a path graph if and only if there is a sequence (v_1, v_2, \dots, v_N) that is a permutation of (1, 2, \dots, N) and satisfies the following conditions: For all i = 1, 2, \dots, N-1 , there is an edge connecting vertices v_i and v_{i+1} . If integers i and j satisfies 1 \leq i, j \leq N and |i - j| \geq 2 , then there is no edge that connects vertices v_i and v_j .
[ { "input": "4 3\n1 3\n4 2\n3 2\n", "output": "Yes\n" }, { "input": "2 0\n", "output": "No\n" }, { "input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_d
Problem Statement You are given strings S and T consisting of lowercase English letters and ? . Here, |S| \gt |T| holds (for a string X , |X| denotes the length of X ). Two strings X and Y such that |X|=|Y| is said to match if and only if: one can make X equal Y by replacing each ? in X and Y with any English letter independently. Solve the following problem for each x=0,1,\ldots,|T| : Let S' be the string of length |T| obtained by concatenating the first x characters and the last (|T|-x) characters of S without changing the order. Print Yes if S' and T match, and No otherwise.
[ { "input": "a?c\nb?\n", "output": "Yes\nNo\nNo\n" }, { "input": "atcoder\n?????\n", "output": "Yes\nYes\nYes\nYes\nYes\nYes\n" }, { "input": "beginner\ncontest\n", "output": "No\nNo\nNo\nNo\nNo\nNo\nNo\nNo\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_e
Problem Statement You are given N strings consisting of lowercase English letters. Let S_i be the i -th (i = 1, 2, \dots, N) of them. For two strings x and y , \mathrm{LCP}(x, y) is defined to be the maximum integer n that satisfies all of the following conditions: The lengths of x and y are both at least n . For all integers i between 1 and n , inclusive, the i -th character of x and that of y are equal. Find the following value for all i = 1, 2, \dots, N : \displaystyle \max_{i \neq j} \mathrm{LCP}(S_i, S_j)
[ { "input": "3\nabc\nabb\naac\n", "output": "2\n2\n1\n" }, { "input": "11\nabracadabra\nbracadabra\nracadabra\nacadabra\ncadabra\nadabra\ndabra\nabra\nbra\nra\na\n", "output": "4\n3\n2\n1\n0\n1\n0\n4\n3\n2\n1\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_f
Problem Statement You are given a tree with N vertices. The vertices are numbered 1 through N , and the i -th edge connects vertex a_i and vertex b_i . Solve the following problem for each x=1,2,\ldots,N : There are (2^N-1) non-empty subsets V of the tree's vertices. Find the number, modulo 998244353 , of such V that the subgraph induced by V has exactly x connected components. What is an induced subgraph? Let S be the subset of the vertices of a graph G ; then the subgraph of G induced by S is a graph whose vertex set is S and whose edge set consists of all edges of G whose both ends are contained in S .
[ { "input": "4\n1 2\n2 3\n3 4\n", "output": "10\n5\n0\n0\n" }, { "input": "2\n1 2\n", "output": "3\n0\n" }, { "input": "10\n3 4\n3 6\n6 9\n1 3\n2 4\n5 6\n6 10\n1 8\n5 7\n", "output": "140\n281\n352\n195\n52\n3\n0\n0\n0\n0\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_g
Problem Statement Takahashi has 10^{100} cards of each of N kinds. Initially, the score and quota of the i -th kind of card are set to a_i and b_i , respectively. Given Q queries in the following formats, process them in order. 1 x y : set the score of the x -th kind of card to y . 2 x y : set the quota of the x -th kind of card to y . 3 x : if one can choose x cards subject to the following condition, print the maximum possible sum of the scores of the chosen cards; print -1 otherwise. The number of chosen cards of each kind does not exceed its quota.
[ { "input": "3\n1 1\n2 2\n3 3\n7\n3 4\n1 1 10\n3 4\n2 1 0\n2 3 0\n3 4\n3 2\n", "output": "11\n19\n-1\n4\n" } ]
https://atcoder.jp/contests/abc287/tasks/abc287_h
Problem Statement There is a directed graph with N vertices and M edges. The vertices are numbered 1 through N , and the i -th directed edge goes from vertex a_i to vertex b_i . The cost of a path on this graph is defined as: the maximum index of a vertex on the path (including the initial and final vertices). Solve the following problem for each x=1,2,\ldots,Q . Find the minimum cost of a path from vertex s_x to vertex t_x . If there is no such path, print -1 instead. The use of fast input and output methods is recommended because of potentially large input and output.
[ { "input": "4 4\n1 2\n2 3\n3 1\n4 3\n3\n1 2\n2 1\n1 4\n", "output": "2\n3\n-1\n" } ]
https://atcoder.jp/contests/ahc017/tasks/ahc017_a
Problem Statement Given an edge-weighted undirected planar graph with N vertices, we want to perform repair work on each edge exactly once in D days. We can complete the repair work on each edge in a single day, and at most K edges can be repaired simultaneously on the same day. Edges that are not under repair work are passable in both directions, and the weight of an edge represents the distance it takes to move on that edge. Let d(i,j) be the shortest distance from vertex i to vertex j in the original graph. Let d_k(i,j) be the shortest distance from vertex i to vertex j in the graph obtained by removing the edges to be repaired on day k from the original graph. If j is unreachable from i , we define d_k(i,j)=10^9 . The frustration level f_k for the repair work on day k is defined as the expected increase in the shortest distance between two different vertices, as follows. \[ f_k = \frac{\sum_{i\neq j}(d_k(i,j)-d(i,j))}{N(N-1)} \] Using the average of the frustration levels for each day, the frustration level for the whole repair work is defined as \[ \mathrm{round}\left(10^3\times \frac{1}{D}\sum_{k=1}^D f_k\right) \] Find a repair schedule that causes as little frustration as possible.
[]
https://atcoder.jp/contests/arc154/tasks/arc154_a
Problem Statement You are given N -digit positive integers A and B whose topmost digits are not 0 . You can repeat the following operation any number of times (possibly zero). Choose an integer i such that 1 \le i \le N and swap the i -th lowest digits of A and B . Find the smallest possible value of A \times B after your operations, modulo 998244353 . Note that you are not asked to minimize the remainder when A \times B is divided by 998244353 .
[ { "input": "2\n13\n22\n", "output": "276\n" }, { "input": "8\n20220122\n21002300\n", "output": "54558365\n" } ]
https://atcoder.jp/contests/arc154/tasks/arc154_b
Problem Statement You are given strings S and T of length N consisting of lowercase English letters. You can repeat the following operation any number of times (possibly zero). Erase the first character of S and insert the same character at any position of S . Determine whether it is possible to make S equal T , and if it is possible, find the minimum number of operations needed.
[ { "input": "4\nabab\nabba\n", "output": "2\n" }, { "input": "3\narc\ncra\n", "output": "2\n" } ]
https://atcoder.jp/contests/arc154/tasks/arc154_c
Problem Statement You are given sequences of positive integers of length N : A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_N) . You can repeat the following operation any number of times (possibly zero). Choose an integer i such that 1 \le i \le N and replace A_i with A_{i+1} . Here, regard A_{N+1} as A_1 . Determine whether it is possible to make A equal B . You have T test cases to solve.
[ { "input": "3\n2\n1 2\n2 2\n4\n2 3 1 1\n2 1 1 2\n2\n1 1\n2 2\n", "output": "Yes\nYes\nNo\n" } ]
https://atcoder.jp/contests/arc154/tasks/arc154_d
Problem Statement PCT has a permutation (P_1,P_2,\dots,P_N) of (1,2,\dots,N) . You are only informed of N . You can ask him at most 25000 questions of the following form. Specify a triple of integers (i,j,k) such that 1 \le i,j,k \le N and ask whether P_i + P_j > P_k . Find all of P_1,P_2,\dots,P_N .
[]
https://atcoder.jp/contests/arc154/tasks/arc154_e
Problem Statement For a permutation Q=(Q_1,Q_2,\dots,Q_N) of (1,2,\dots,N) , let f(Q) be the following value: the sum of j-i over all pairs of integers (i,j) such that 1 \le i < j \le N and Q_i > Q_j . You are given a permutation P=(P_1,P_2,\dots,P_N) of (1,2,\dots,N) . Let us repeat the following operation M times. Choose a pair of integers (i,j) such that 1 \le i \le j \le N . Reverse P_i,P_{i+1},\dots,P_j . Formally, replace the values of P_i,P_{i+1},\dots,P_j with P_j,P_{j-1},\dots,P_i simultaneously. There are \left(\frac{N(N+1)}{2}\right)^{M} ways to repeat the operation. Assume that we have computed f(P) for all those ways. Find the sum of these \left(\frac{N(N+1)}{2}\right)^{M} values, modulo 998244353 .
[ { "input": "2 1\n1 2\n", "output": "1\n" }, { "input": "3 2\n3 2 1\n", "output": "90\n" }, { "input": "10 2023\n5 8 1 9 3 10 4 7 2 6\n", "output": "543960046\n" } ]
https://atcoder.jp/contests/arc154/tasks/arc154_f
Problem Statement We have an N -sided die where all sides have the same probability to show up. Let us repeat rolling this die until every side has shown up. For integers i such that 1 \le i \le M , find the expected value, modulo 998244353 , of the i -th power of the number of times we roll the die. Definition of expected value modulo 998244353 It can be proved that the sought expected values are always rational numbers. Additionally, under the constraints of this problem, when such a value is represented as an irreducible fraction \frac{P}{Q} , it can be proved that Q \neq 0 \pmod{998244353} . Thus, there is a unique integer R such that R \times Q = P \pmod{998244353} and 0 \le R < 998244353 . Print this R .
[ { "input": "3 3\n", "output": "499122182\n37\n748683574\n" }, { "input": "7 8\n", "output": "449209977\n705980975\n631316005\n119321168\n62397541\n596241562\n584585746\n378338599\n" }, { "input": "2023 7\n", "output": "442614988\n884066164\n757979000\n548628857\n593993207\n780067557\n524115712\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_a
問題文 JOI 高校の生埒である葵は文字列 JOIG が文字列 JOI の末尟に文字 G を付け加えおできるこずに気が付いた そこから葵は様々な文字列に぀いお末尟に文字 G を付け加えたり末尟の文字 G を取り陀いお遊ぶようになった 具䜓的には葵は文字列を芋るず次のように遊ぶ 芋た文字列の末尟の文字が G のずき末尟の文字 G を取り陀いた文字列を思い浮かべる取り陀く文字は末尟の 1 文字のみである 芋た文字列の末尟の文字が G でないずき文字列の末尟に文字 G を付け加えた文字列を思い浮かべる 長さ N の文字列 S が䞎えられる葵が文字列 S を芋たずき思い浮かべる文字列を求めるプログラムを䜜成せよ
[ { "input": "4\nJOIG\n", "output": "JOI\n" }, { "input": "3\nJOI\n", "output": "JOIG\n" }, { "input": "3\nEGG\n", "output": "EG\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_b
問題文 JOI 高校の葵さんは数列に察しお隣り合う各項の差の絶察倀を順に䞊べた数列を考えるのが奜きである はじめ黒板には長さ N の数列 A_1,A_2,\ldots,A_N が曞かれおいる 葵さんは以䞋の操䜜を N-1 回繰り返す 黒板に曞かれおいる数列の長さが m でありその数列が b_1,b_2,\ldots,b_m であるずする 黒板に曞かれおいる数列 b_1,b_2,\ldots,b_m を消し長さ m-1 の数列 |b_1-b_2|,|b_2-b_3|,\ldots,|b_{m-1}-b_m| を新たに黒板に曞くただし |x| は x の絶察倀を衚す N-1 回の操䜜が終了した埌黒板には 1 ぀の倀長さ 1 の数列が曞かれおいる はじめ黒板に曞かれおいた数列の情報が䞎えられるので N-1 回の操䜜が終了した埌黒板に曞かれおいる倀を求めるプログラムを䜜成せよ
[ { "input": "4\n3 1 4 1\n", "output": "1\n" }, { "input": "2\n2 4\n", "output": "2\n" }, { "input": "6\n2 7 5 3 3 11\n", "output": "3\n" }, { "input": "10\n3 1 4 1 5 9 2 6 5 3\n", "output": "0\n" }, { "input": "2\n0 0\n", "output": "0\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_c
問題文 JOI 垂には 1 本の十分に長い道路があるこの道路は数盎線ずみなすこずができ各地点は 1 個の実数による座暙で衚される たたJOI 垂にはこの道路に沿っお N 個の鐘があり座暙の小さい順に 1 から N たでの番号が付けられおいる鐘 i ( 1 ≩ i ≩ N ) は座暙 A_i にある JOI 垂では 1 幎の終わりにこれらの鐘を䞀斉に鳎らすのが䞀倧むベントずなっおいる どの鐘も鳎らすずその鐘ず同じ地点では匷さ K の音で聞こえるが距離が 1 離れるごずに聞こえる音の匷さは 1 小さくなり距離が K 以䞊離れるず 0 になるすなわち鐘 i を鳎らしたずき座暙 x で聞こえる鐘 i の音の匷さは \max\{K - |x - A_i|, 0\} であるただし |t| は t の絶察倀を衚す すべおの鐘を鳎らしたずき座暙 x で聞こえる鐘の音の匷さは座暙 x で聞こえるそれぞれの鐘の音の匷さの最倧倀である JOI 垂にはこの道路に沿っお M 個の家があり叀い方から順に 1 から M たでの番号が付けられおいる家 j ( 1 ≩ j ≩ M ) は座暙 B_j にある JOI 垂の垂長であるあなたはすべおの鐘を鳎らしたずきそれぞれの家で聞こえる鐘の音の匷さを知りたい JOI 垂の鐘ず家の情報が䞎えられたずきすべおの鐘を鳎らしたずきに座暙 B_1, B_2, 
, B_M で聞こえる鐘の音の匷さを求めるプログラムを䜜成せよ
[ { "input": "1 5 10\n20\n20 15 28 10 32\n", "output": "10\n5\n2\n0\n0\n" }, { "input": "3 4 100\n116 194 258\n57 155 222 360\n", "output": "41\n61\n72\n0\n" }, { "input": "10 10 10000\n589 2398 6567 28817 29177 31636 45468 66751 82282 97509\n2196 54498 80474 61644 18007 38759 85590 72172 79533 69959\n", "output": "9798\n970\n8192\n4893\n0\n3291\n6692\n4579\n7251\n6792\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_d
問題文 机の䞊に瞊 H 行暪 W 列の長方圢状にコむンが䞊べられおいる 最初䞊から i 行目 ( 1 \leqq i \leqq H )巊から j 列目 ( 1 \leqq j \leqq W ) のコむンは S_{i,j}= # のずき衚面 S_{i,j}= . のずき裏面が芋えおいる状態である 葵ず凛はこれらのコむンを甚いおゲヌムを行うこずにしたゲヌムは以䞋のような流れで行われる 葵がどれか 1 ぀の行を遞びその行のコむンをすべおひっくり返す 凛がどれか 1 ぀の列を遞びその列のコむンをすべおひっくり返す 葵が衚面が芋えるコむンをすべお獲埗するたた凛が裏面が芋えるコむンをすべお獲埗する 葵ず凛はそれぞれできるだけ倚くのコむンを獲埗したい ゲヌム開始時のコむンの状態が䞎えられたずき 䞡者が最善を尜くした堎合にそれぞれが獲埗できるコむンの枚数を求めるプログラムを䜜成せよ
[ { "input": "1 1\n#\n", "output": "1 0\n" }, { "input": "5 5\n#####\n####.\n###..\n##...\n#....\n", "output": "13 12\n" }, { "input": "1 40\n..........##########..........##########\n", "output": "19 21\n" }, { "input": "7 1\n#\n#\n#\n#\n#\n#\n#\n", "output": "1 6\n" }, { "input": "5 5\n.###.\n...##\n..##.\n.##..\n##...\n", "output": "11 14\n" }, { "input": "10 40\n........................................\n..######.....####.....#####.....####....\n.....#......#....#......#......#........\n.....#......#....#......#......#........\n.....#......#....#......#......#........\n.....#......#....#......#......#..####..\n..#..#......#....#......#......#....#...\n..#..#......#....#......#......#....#...\n...##........####.....#####.....####....\n........................................\n", "output": "104 296\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_e
問題文 JOIG 王囜は H 行 W 列のマス目に区切られた長方圢の圢をしおいる䞊から i 行目 ( 1 \leqq i \leqq H )巊から j 列目 ( 1 \leqq j \leqq W ) のマスをマス (i,j) ず呌ぶ 各マスには暙高ず呌ばれる敎数が定たっおいるマス (i,j) の暙高は A_{i,j} である JOIG 王囜では王囜を瞊断する運河を建蚭するこずにした運河の建蚭は以䞋のように行われる ある敎数 k ( 1 \leqq k < W ) を定める巊から k 列目ず k+1 列目の間に王囜の䞊端から䞋端たで瞊断する運河を建蚭する 運河を暪切らず蟺で接しおいる暙高が同じマスぞの移動を繰り返すこずで盞互に移動できるマスの集たりをここでは 平地 ず呌ぶ囜土を管理しやすくするため平地の個数ができるだけ少なくなるように運河の建蚭䜍眮を決めたい JOIG 王囜の地圢の情報が䞎えられたずき運河を建蚭した埌の JOIG 王囜内の平地の個数ずしおありうる最小倀を求めるプログラムを䜜成せよ
[ { "input": "4 4\n1 1 1 3\n2 2 1 3\n2 1 1 3\n2 2 2 2\n", "output": "4\n" }, { "input": "5 8\n1 2 2 5 5 5 5 5\n1 1 2 2 5 6 5 6\n1 1 1 1 6 6 5 6\n1 1 3 1 1 6 7 6\n1 4 1 1 1 6 6 6\n", "output": "8\n" }, { "input": "1 6\n1 1 2 2 3 3\n", "output": "3\n" }, { "input": "2 10\n1 1 1 1 1 3 3 3 3 4\n1 2 1 3 3 3 1 1 3 3\n", "output": "6\n" } ]
https://atcoder.jp/contests/joig2023-open/tasks/joig2023_f
問題文 JOIG 囜では JOIG 語が䜿甚されおおりJOIG 語では文字 A , B , C , D , E , F , G , H , I , J , K , L , M , N , O の 15 皮類の文字が甚いられる 来月 JOIG 囜で開催されるタむピング倧䌚ではJOIG 語で甚いられる 15 皮類の文字からなる長さ N の文字列 S を入力するのにかかる時間を競うこの倧䌚では参加者は以䞋の条件でタむピングを行う 参加者は 1 本の指を䜿っおタむピングをする 参加者は 15 皮類の文字のキヌ 1 ぀ず぀を 1 列に䞊べた巊右に现長いキヌボヌドを䜿甚するなおどの䜍眮にどの文字のキヌを配眮するかは各参加者が自由に決めるこずができる 参加者は文字列 S の 1, 2, \dots, N 文字目のキヌをこの順に打぀こずによっお文字列 S を入力する この倧䌚には Q 人が参加する予定である参加者によっおタむピングの胜力は様々である i 番目 ( 1 \leqq i \leqq Q ) の参加者はタむピングに際しお以䞋のような時間がかかる 指の真䞋にあるキヌを 1 回打぀のに A_i ミリ秒かかる 指を 1 ぀巊のキヌの䞊に移動させるのに L_i ミリ秒かかる 指を 1 ぀右のキヌの䞊に移動させるのに R_i ミリ秒かかる 文字列 S および各参加者の情報が䞎えられるので各参加者に察しお文字列 S の最初の文字を打ち始めおから最埌の文字を打ち終わるたでに最短䜕ミリ秒かかるかを求めるプログラムを䜜成せよ
[ { "input": "6\nABAABB\n1\n100 150 210\n", "output": "1110\n" }, { "input": "6\nCBACAB\n1\n150 240 220\n", "output": "2260\n" }, { "input": "20\nAAAAAAAAAAAAAAAAAAAA\n1\n230000000 80000000 80000000\n", "output": "4600000000\n" }, { "input": "7\nEACHBAG\n5\n130 104 162\n107 219 45\n144 168 157\n213 79 257\n100000000000 100000000000 100000000000\n", "output": "2078\n1766\n2465\n2894\n1600000000000\n" }, { "input": "19\nJOIGCODINGCHALLENGE\n5\n1 1 1\n100 200 200\n225 111 111\n123456789 987654321 987654321\n31415926535 27182818284 27182818284\n", "output": "48\n7700\n7494\n30987654300\n1385204334401\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_a
Problem Statement You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N and positive integers P,Q,R , and S . Here, P,Q,R , and S satisfy 1\leq P\leq Q<R\leq S \leq N and Q-P=S-R . Let B=(B_1, B_2,\ldots, B_N) be the sequence obtained by swapping the P -th through Q -th terms and the R -th through S -th terms of A . Print the sequence B .
[ { "input": "8 1 3 5 7\n1 2 3 4 5 6 7 8\n", "output": "5 6 7 4 1 2 3 8\n" }, { "input": "5 2 3 4 5\n2 2 1 1 1\n", "output": "2 1 1 2 1\n" }, { "input": "2 1 1 2 2\n50 100\n", "output": "100 50\n" }, { "input": "10 2 4 7 9\n22 75 26 45 72 81 47 29 97 2\n", "output": "22 47 29 97 72 81 75 26 45 2\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_b
Problem Statement You are given a string S of length N . Find the string obtained by replacing all contiguous occurrences of na in S with nya .
[ { "input": "4\nnaan\n", "output": "nyaan\n" }, { "input": "4\nnear\n", "output": "near\n" }, { "input": "8\nnational\n", "output": "nyationyal\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_c
Problem Statement You are given a string S of length N . Let S_i\ (1\leq i \leq N) be the i -th character of S from the left. You may perform the following two kinds of operations zero or more times in any order: Pay A yen (the currency in Japan). Move the leftmost character of S to the right end. In other words, change S_1S_2\ldots S_N to S_2\ldots S_NS_1 . Pay B yen. Choose an integer i between 1 and N , and replace S_i with any lowercase English letter. How many yen do you need to pay to make S a palindrome? What is a palindrome? A string T is a palindrome if and only if the i -th character from the left and the i -th character from the right are the same for all integers i ( 1 \le i \le |T| ), where |T| is the length of T .
[ { "input": "5 1 2\nrrefa\n", "output": "3\n" }, { "input": "8 1000000000 1000000000\nbcdfcgaa\n", "output": "4000000000\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_d
Problem Statement Takahashi has N kinds of coins; specifically, for 1\leq i\leq N , he has B_i coins worth A_i yen (the currency in Japan) each. Determine if Takahashi can pay exactly X yen (without change) with the coins he currently has.
[ { "input": "2 19\n2 3\n5 6\n", "output": "Yes\n" }, { "input": "2 18\n2 3\n5 6\n", "output": "No\n" }, { "input": "3 1001\n1 1\n2 1\n100 10\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_e
Problem Statement There are N cities. There are also one-way direct flights that connect different cities. The availability of direct flights is represented by N strings S_1,S_2,\ldots,S_N of length N each. If the j -th character of S_i is Y , there is a direct flight from city i to city j ; if it is N , there is not. Each city sells a souvenir; city i sells a souvenir of value A_i . Consider the following problem: Takahashi is currently at city S and wants to get to city T (that is different from city S ) using some direct flights. Every time he visits a city (including S and T ), he buys a souvenir there. If there are multiple routes from city S to city T , Takahashi decides the route as follows: He tries to minimize the number of direct flights in the route from city S to city T . Then he tries to maximize the total value of the souvenirs he buys. Determine if he can travel from city S to city T using the direct flights. If he can, find the "number of direct flights" and "total value of souvenirs" in the route that satisfies the conditions above. You are given Q pairs (U_i,V_i) of distinct cities. For each 1\leq i\leq Q , print the answer to the problem above when S=U_i and T=V_i .
[ { "input": "5\n30 50 70 20 60\nNYYNN\nNNYNN\nNNNYY\nYNNNN\nYNNNN\n3\n1 3\n3 1\n4 5\n", "output": "1 100\n2 160\n3 180\n" }, { "input": "2\n100 100\nNN\nNN\n1\n1 2\n", "output": "Impossible\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_f
Problem Statement This is an interactive task , where your and the judge's programs interact via Standard Input and Output. You and the judge will follow the procedure below. The procedure consists of phases 1 and 2 ; phase 1 is immediately followed by phase 2 . (Phase 1 ) The judge decides an integer N between 1 and 10^9 (inclusive), which is hidden. You print an integer M between 1 and 110 (inclusive). You also print an integer sequence A=(A_1,A_2,\ldots,A_M) of length M such that 1 \leq A_i \leq M for all i = 1, 2, \ldots, M . (Phase 2 ) The judge gives you an integer sequence B=(B_1,B_2,\ldots,B_M) of length M . Here, B_i = f^N(i) . f(i) is defined by f(i)=A_i for all integers i between 1 and M (inclusive), and f^N(i) is the integer resulting from replacing i with f(i) N times. Based on the given B , you identify the integer N that the judge has decided, and print N . After the procedure above, terminate the program immediately to be judged correct.
[]
https://atcoder.jp/contests/abc286/tasks/abc286_g
Problem Statement You are given a simple connected undirected graph G with N vertices and M edges. The vertices of G are numbered vertex 1 , vertex 2 , \ldots , and vertex N , and its edges are numbered edge 1 , edge 2 , \ldots , and edge M . Edge i connects vertex U_i and vertex V_i . You are also given a subset of the edges: S=\{x_1,x_2,\ldots,x_K\} . Determine if there is a walk on G that contains edge x exactly once for all x \in S . The walk may contain an edge not in S any number of times (possibly zero). What is a walk? A walk on an undirected graph G is a sequence consisting of k vertices ( k is a positive integer) and (k-1) edges occurring alternately, v_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k , such that edge e_i connects vertex v_i and vertex v_{i+1} . The sequence may contain the same edge or vertex multiple times. A walk is said to contain an edge x exactly once if and only if there is exactly one 1\leq i\leq k-1 such that e_i=x .
[ { "input": "6 6\n1 3\n2 3\n3 4\n4 5\n4 6\n5 6\n4\n1 2 4 5\n", "output": "Yes\n" }, { "input": "6 5\n1 2\n1 3\n1 4\n1 5\n1 6\n3\n1 2 3\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc286/tasks/abc286_h
Problem Statement On a two-dimensional plane, there is a convex polygon C with N vertices, and points S=(s_x, s_y) and T=(t_x,t_y) . The vertices of C are (x_1,y_1),(x_2,y_2),\ldots , and (x_N,y_N) in counterclockwise order. It is guaranteed that S and T are outside the polygon. Find the shortest distance that needs to be traveled to get from point S to point T without entering the interior of C except for its circumference.
[ { "input": "4\n1 1\n3 1\n3 3\n1 3\n0 2\n5 2\n", "output": "5.65028153987288474496\n" }, { "input": "3\n0 0\n2 0\n1 10\n3 7\n10 3\n", "output": "8.06225774829854965279\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_a
Problem Statement Determine if there is a segment that directly connects the points numbered a and b in the figure below.
[ { "input": "1 2\n", "output": "Yes\n" }, { "input": "2 8\n", "output": "No\n" }, { "input": "14 15\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_b
Problem Statement You are given a string S of length N consisting of lowercase English letters. The x -th (1 \le x \le N) character of S is S_x . For each i=1,2,\dots,N-1 , find the maximum non-negative integer l that satisfies all of the following conditions: l+i \le N , and for all integers k such that 1 \le k \le l , it holds that S_{k} \neq S_{k+i} . Note that l=0 always satisfies the conditions.
[ { "input": "6\nabcbac\n", "output": "5\n1\n2\n0\n1\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_c
Problem Statement In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once. The IDs of the problems are as follows, from the 1 -st problem in order: A , B , ..., Z , AA , AB , ..., ZZ , AAA , ... In other words, the IDs are given in the following order: the strings of length 1 consisting of uppercase English letters, in lexicographical order; the strings of length 2 consisting of uppercase English letters, in lexicographical order; the strings of length 3 consisting of uppercase English letters, in lexicographical order; ... Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)
[ { "input": "AB\n", "output": "28\n" }, { "input": "C\n", "output": "3\n" }, { "input": "BRUTMHYHIIZP\n", "output": "10000000000000000\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_d
Problem Statement You run a web service with N users. The i -th user with a current handle S_i wants to change it to T_i . Here, S_1,\ldots , and S_N are pairwise distinct, and so are T_1,\ldots , and T_N . Determine if there is an appropriate order to change their handles to fulfill all of their requests subject to the following conditions: you change only one user's handle at a time; you change each user's handle only once; when changing the handle, the new handle should not be used by other users at that point.
[ { "input": "2\nb m\nm d\n", "output": "Yes\n" }, { "input": "3\na b\nb c\nc a\n", "output": "No\n" }, { "input": "5\naaa bbb\nyyy zzz\nccc ddd\nxxx yyy\nbbb ccc\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_e
Problem Statement In the world where Takahashi lives, a week has N days. Takahashi, the king of the Kingdom of AtCoder, assigns "weekday" or "holiday" to each day of week. The assignments should be the same for all weeks. At least one day of week should be assigned "holiday". Under such conditions, the productivity of the i -th day of week is defined by a sequence A of length N as follows: if the i -th day of week is "holiday", its productivity is 0 ; if the i -th day of week is "weekday", its productivity is A_{\min(x,y)} , if the last holiday is x days before and the next one is y days after. Note that the last/next holiday may belong to a different week due to the periodic assignments. For details, see the Samples. Find the maximum productivity per week when the assignments are chosen optimally. Here, the productivity per week refers to the sum of the productivities of the 1 -st, 2 -nd, \dots , and N -th day of week.
[ { "input": "7\n10 10 1 1 1 1 1\n", "output": "50\n" }, { "input": "10\n200000000 500000000 1000000000 800000000 100000000 80000000 600000 900000000 1 20\n", "output": "5100000000\n" }, { "input": "20\n38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 1142 281 20537 15921 8945 26285 2997 14680\n", "output": "236980\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_f
Problem Statement You are given a string S of length N consisting of lowercase English letters, and Q queries. Process the queries in order. Each query is of one of the following two kinds: 1 x c : replace the x -th character of S by the character c . 2 l r : let T be the string obtained by sorting the characters of S in ascending order. Print Yes if the string consisting of the l -th through r -th characters of S is a substring of T ; print No otherwise. What is a substring? A substring of S is a string obtained by removing 0 or more initial characters and 0 or more final characters of S . For example, ab is a substring of abc , while ac is not a substring of abc .
[ { "input": "6\nabcdcf\n4\n2 1 3\n2 2 6\n1 5 e\n2 2 6\n", "output": "Yes\nNo\nYes\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_g
Problem Statement We have a grid with H horizontal rows and W vertical columns. We denote by square (i,j) the square at the i -th row from the top and j -th column from the left. We want to cover this grid with 1 \times 1 tiles and 1 \times 2 tiles so that no tiles overlap and everywhere is covered by a tile. (A tile can be rotated.) Each square has 1 , 2 , or ? written on it. The character written on square (i, j) is c_{i,j} . A square with 1 written on it must be covered by a 1 \times 1 tile, and a square with 2 by a 1 \times 2 tile. A square with ? may be covered by any kind of tile. Determine if there is such a placement of tiles.
[ { "input": "3 4\n2221\n?1??\n2?21\n", "output": "Yes\n" }, { "input": "3 4\n2?21\n??1?\n2?21\n", "output": "No\n" }, { "input": "5 5\n11111\n11111\n11211\n11111\n11111\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc285/tasks/abc285_h
Problem Statement You are given integers N and K , and a sequence E of length K . Find the number, modulo \color{red}{10^9+7} , of sequences of length N consisting of positive integers that satisfy the following conditions: no element is a square number; the product of all elements is \displaystyle \prod_{i=1}^{K} p_i^{E_i} . Here, p_i denotes the i -th smallest prime. Two sequences A and B of the same length consisting of positive integers are considered different if and only if there exists an integer i such that the i -th terms of A and B are different.
[ { "input": "3 2\n3 2\n", "output": "15\n" }, { "input": "285 10\n3141 5926 5358 9793 2384 6264 3383 279 5028 8419\n", "output": "672860525\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_a
Problem Statement A positive integer x is said to be a beautiful integer if and only if x is a 9 -digit integer whose decimal notation S_1\ldots S_9 ( S_i is the i -th character) satisfies all of the following conditions: S_1 is not 0 , S_1 = S_2 , S_5 = S_6 , and S_7 = S_9 . For instance, 998244353 and 333333333 are beautiful integers, while 111112222 is not, since S_5 \neq S_6 . You are given a positive integer N . Print the N -th smallest beautiful integer.
[ { "input": "3\n", "output": "110000020\n" }, { "input": "882436\n", "output": "998244353\n" }, { "input": "2023\n", "output": "110200222\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_b
Problem Statement We have a grid with H rows from top to bottom and W columns from left and right. Initially, the square at the i -th row from the top and j -th column from the left has a lowercase English letter A_{i,j} . Let us perform Q operations on this grid. In the i -th operation, we are given integers a_i and b_i such that 1\leq a_i \leq H-1 and 1\leq b_i\leq W-1 , and do the following. Let R_1 , R_2 , R_3 , and R_4 be rectangular regions within the grid defined as follows: R_1 is the intersection of the top a_i rows and leftmost b_i columns; R_2 is the intersection of the top a_i rows and rightmost W-b_i columns; R_3 is the intersection of the bottom H-a_i rows and leftmost b_i columns; R_4 is the intersection of the bottom H-a_i rows and rightmost W-b_i columns. Rotate 180 degrees each of R_1 , R_2 , R_3 , and R_4 . Here, a 180 -degree rotation of a rectangular region R within the grid moves the character on the square at the i -th from the top and j -th column from the left in R to the square at the i -th from the bottom and j -th column from the right in R . See also the figures for the samples. Print the grid after all Q operations.
[ { "input": "4 5\nabcde\nfghij\nklmno\npqrst\n1\n3 3\n", "output": "mlkon\nhgfji\ncbaed\nrqpts\n" }, { "input": "3 7\natcoder\nregular\ncontest\n2\n1 1\n2 5\n", "output": "testcon\noderatc\nularreg\n" }, { "input": "2 2\nac\nwa\n3\n1 1\n1 1\n1 1\n", "output": "ac\nwa\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_c
Problem Statement You are given a sequence of length N , A = (A_1, \ldots, A_N) , consisting of 1 and -1 . Determine whether there is an integer sequence x = (x_1, \ldots, x_N) that satisfies all of the following conditions, and print one such sequence if it exists. |x_i| \leq 10^{12} for every i ( 1\leq i\leq N ). x is strictly increasing. That is, x_1 < \cdots < x_N . \sum_{i=1}^N A_ix_i = 0 .
[ { "input": "5\n-1 1 -1 -1 1\n", "output": "Yes\n-3 -1 4 5 7\n" }, { "input": "1\n-1\n", "output": "Yes\n0\n" }, { "input": "2\n1 -1\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_d
Problem Statement For a positive integer x , let f(x) denote the sum of its digits. For instance, we have f(153) = 1 + 5 + 3 = 9 , f(2023) = 2 + 0 + 2 + 3 = 7 , and f(1) = 1 . You are given a sequence of positive integers A = (A_1, \ldots, A_N) . Find the minimum possible value of \sum_{i=1}^N f(A_i + x) where x is a non-negative integer.
[ { "input": "4\n4 13 8 6\n", "output": "14\n" }, { "input": "4\n123 45 678 90\n", "output": "34\n" }, { "input": "3\n1 10 100\n", "output": "3\n" }, { "input": "1\n153153153\n", "output": "1\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_e
Problem Statement For a positive integer X none of whose digits is 0 , consider obtaining a positive integer Y as follows. Initialize S as an empty string. Let N be the number of digits in X . For i = 1, \ldots, N in this order, do the following: insert the i -th character in the decimal notation of X at the beginning or end of S . Let Y be the positive integer represented by the string S . Let f(X) denote the minimum positive integer that can be obtained from X in this way. You are given a positive integer Y none of whose digits is 0 . Print the number, modulo 998244353 , of positive integers X none of whose digits is 0 such that f(X) = Y .
[ { "input": "1332\n", "output": "3\n" }, { "input": "3312\n", "output": "0\n" }, { "input": "12234433442\n", "output": "153\n" } ]
https://atcoder.jp/contests/arc153/tasks/arc153_f
Problem Statement You are given a simple connected undirected graph G with N vertices and M edges. The vertices are numbered 1 to N , and the i -th edge connects vertices A_i and B_i . Find the number of ways to paint each edge of G in color 1 , 2 , or 3 so that the following condition is satisfied, modulo 998244353 . There is a simple path in G that contains an edge in color 1 , an edge in color 2 , and an edge in color 3 . What is a simple path? A simple path is a pair of a sequence of vertices (v_1, \ldots, v_{k+1}) and a sequence of edges (e_1, \ldots, e_k) that satisfies the following: i\neq j \implies v_i\neq v_j ; edge e_i connects vertices v_i and v_{i+1} .
[ { "input": "3 3\n1 2\n1 3\n3 2\n", "output": "0\n" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "534\n" }, { "input": "6 5\n1 3\n4 3\n5 4\n4 2\n1 6\n", "output": "144\n" }, { "input": "6 7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n1 6\n", "output": "1794\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_a
Problem Statement You are given N strings S_1,S_2,\ldots,S_N in this order. Print S_N,S_{N-1},\ldots,S_1 in this order.
[ { "input": "3\nTakahashi\nAoki\nSnuke\n", "output": "Snuke\nAoki\nTakahashi\n" }, { "input": "4\n2023\nYear\nNew\nHappy\n", "output": "Happy\nNew\nYear\n2023\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_b
Problem Statement In this problem, an input file contains multiple test cases. You are first given an integer T . Solve the following problem for T test cases. We have N positive integers A_1, A_2, ..., A_N . How many of them are odd?
[ { "input": "4\n3\n1 2 3\n2\n20 23\n10\n6 10 4 1 5 9 8 6 5 1\n1\n1000000000\n", "output": "2\n1\n5\n0\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_c
Problem Statement You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M . Edge i connects vertex u_i and vertex v_i . Find the number of connected components in this graph.
[ { "input": "5 3\n1 2\n1 3\n4 5\n", "output": "2\n" }, { "input": "5 0\n", "output": "5\n" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "1\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_d
Problem Statement You are given a positive integer N . It is known that N can be represented as N=p^2q using two different prime numbers p and q . Find p and q . You have T test cases to solve.
[ { "input": "3\n2023\n63\n1059872604593911\n", "output": "17 7\n3 7\n104149 97711\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_e
Problem Statement You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M . Edge i connects vertex u_i and vertex v_i . The degree of each vertex is at most 10 . Let K be the number of simple paths (paths without repeated vertices) starting from vertex 1 . Print \min(K, 10^6) .
[ { "input": "4 2\n1 2\n2 3\n", "output": "3\n" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "16\n" }, { "input": "8 21\n2 6\n1 3\n5 6\n3 8\n3 6\n4 7\n4 6\n3 4\n1 5\n2 4\n1 2\n2 7\n1 4\n3 5\n2 5\n2 3\n4 5\n3 7\n6 7\n5 7\n2 8\n", "output": "2023\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_f
Problem Statement For a string S of length N and an integer i\ (0\leq i\leq N) , let us define the string f_i(S) as the concatenation of: the first i characters of S , the reversal of S , and the last (N-i) characters of S , in this order. For instance, if S= abc and i=2 , we have f_i(S)= abcbac . You are given a string T of length 2N . Find a pair of a string S of length N and an integer i\ (0\leq i\leq N) such that f_i(S)=T . If no such pair of S and i exists, report that fact.
[ { "input": "3\nabcbac\n", "output": "abc\n2\n" }, { "input": "4\nabababab\n", "output": "abab\n1\n" }, { "input": "3\nagccga\n", "output": "cga\n0\n" }, { "input": "4\natcodeer\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_g
Problem Statement For a sequence of length N , A = (A_1,A_2,\dots,A_N) , consisting of integers between 1 and N , inclusive, and an integer i\ (1\leq i \leq N) , let us define a sequence of length 10^{100} , B_i=(B_{i,1},B_{i,2},\dots,B_{i,10^{100}}) , as follows. B_{i,1}=i . B_{i,j+1}=A_{B_{i,j}}\ (1\leq j<10^{100}) . Additionally, let us define S_i as the number of distinct integers that occur exactly once in the sequence B_i . More formally, S_i is the number of values k such that exactly one index j\ (1\leq j\leq 10^{100}) satisfies B_{i,j}=k . You are given an integer N . There are N^N sequences that can be A . Find the sum of \displaystyle \sum_{i=1}^{N} S_i over all of them, modulo M .
[ { "input": "4 100000000\n", "output": "624\n" }, { "input": "7 1000000000\n", "output": "5817084\n" }, { "input": "2023 998244353\n", "output": "737481389\n" }, { "input": "100000 353442899\n", "output": "271798911\n" } ]
https://atcoder.jp/contests/abc284/tasks/abc284_h
Problem Statement You are to generate a graph by the following procedure. Choose a simple undirected graph with N unlabeled vertices. Write a positive integer at most K in each vertex in the graph. Here, there must not be a positive integer at most K that is not written in any vertex. Find the number of possible graphs that can be obtained, modulo P . ( P is a prime .) Two graphs are considered the same if and only if one can label the vertices in each graph as v_1, v_2, \dots, v_N to satisfy the following conditions. For every i such that 1 \leq i \leq N , the numbers written in vertex v_i in the two graphs are the same. For every i and j such that 1 \leq i \lt j \leq N , there is an edge between v_i and v_j in one of the graphs if and only if there is an edge between v_i and v_j in the other graph.
[ { "input": "3 1 998244353\n", "output": "4\n" }, { "input": "3 2 998244353\n", "output": "12\n" }, { "input": "5 5 998244353\n", "output": "1024\n" }, { "input": "30 15 202300013\n", "output": "62712469\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_a
Problem Statement A string x consisting of lowercase English letters is said to be good if and only if the following condition is satisfied. Every (contiguous) substring of x whose length is 2 or greater satisfies the following: no character occupies the majority of that substring. For example, acbca is not good because c occupies the majority of the substring cbc . You are given a string S of length N consisting of lowercase English letters and ? . You want to replace each ? with a lowercase English letter of your choice to make S a good string. Find the number of ways to make S a good string, modulo 998244353 .
[ { "input": "3\na?b\n", "output": "24\n" }, { "input": "3\na?a\n", "output": "0\n" }, { "input": "20\nugsyakganihodnwmktgi\n", "output": "1\n" }, { "input": "20\n??a???h?m?y?ts???tl?\n", "output": "444225229\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_b
Problem Statement We have a grid with N rows and M columns. You want to write an integer between 0 and 2^K-1 in each square in the grid to satisfy the following condition. Consider a path that starts at the top-left square, repeatedly moves right or down to an adjacent square, and ends at the bottom-right square. Such a path is said to be good if and only if the total \mathrm{XOR} of the integers written on the squares visited (including the starting and ending points) is 0 . There is exactly one good path, which is the path represented by a string S . The path represented by the string S is a path that, for each i ( 1 \leq i \leq N+M-2 ), the i -th move is right if the i -th character of S is R and down if that character is D . Determine whether there is a way to write integers that satisfies the condition. For each input file, solve T test cases. What is bitwise \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": "4\n2 2 1\nRD\n4 3 1\nRDDDR\n15 20 18\nDDRRRRRRRDDDDRRDDRDRRRRDDRDRDDRRR\n20 15 7\nDRRDDDDDRDDDRRDDRRRDRRRDDDDDRRRDD\n", "output": "Yes\nNo\nYes\nNo\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_c
Problem Statement Consider a permutation P=(P_1,P_2,\cdots,P_{2^N-1}) of (1,2,\cdots,2^N-1) . P is said to be heaplike if and only if all of the following conditions are satisfied. P_i < P_{2i} ( 1 \leq i \leq 2^{N-1}-1 ) P_i < P_{2i+1} ( 1 \leq i \leq 2^{N-1}-1 ) You are given integers A and B . Let U=2^A and V=2^{B+1}-1 . Find the probability, modulo 998244353 , that P_U<P_V for a heaplike permutation chosen uniformly at random. Definition of probability modulo 998244353 It can be proved that the sought probability is always rational. Additionally, under the constraints of this problem, when the sought rational number is represented as an irreducible fraction \frac{P}{Q} , it can be proved that Q \neq 0 \pmod{998244353} . Therefore, there is a unique integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R \lt 998244353 . Print this R .
[ { "input": "2 1 1\n", "output": "499122177\n" }, { "input": "3 1 2\n", "output": "124780545\n" }, { "input": "4 3 2\n", "output": "260479386\n" }, { "input": "2022 12 25\n", "output": "741532295\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_d
Problem Statement Find the number of pairs (P,Q)=((P_1,P_2,\cdots,P_N),(Q_1,Q_2,\cdots,Q_N)) of permutations of (1,2,\cdots,N) that satisfy the following condition, modulo 998244353 . For every i ( 1 \leq i \leq N-1 ), one of the two conditions below holds. P_i < P_{i+1} and Q_i < Q_{i+1} . P_i > P_{i+1} and Q_i > Q_{i+1} .
[ { "input": "2\n", "output": "2\n" }, { "input": "3\n", "output": "10\n" }, { "input": "4\n", "output": "88\n" }, { "input": "10\n", "output": "286574791\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_e
Problem Statement In this problem, a permutation of (1,2,\cdots,N) is occasionally called just a permutation. For a permutation a=(a_1,a_2,\cdots,a_N) , let f(a) be the number of cycles in a . More accurately, the value of f(a) is defined as follows. Consider an undirected graph consisting of N vertices numbered 1 to N . For each 1 \leq i \leq N , add an edge connecting vertex i and vertex a_i . Then, let f(a) be the number of connected components in this graph. You are given a permutation P=(P_1,P_2,\cdots,P_N) and an integer K . Determine whether there is a permutation x that satisfies the following condition, and construct one if it exists. Let y_i=P_{x_i} to define a permutation y . Then, f(x)+f(y)=K holds. For each input file, solve T test cases.
[ { "input": "3\n3 3\n1 3 2\n2 2\n2 1\n4 8\n1 2 3 4\n", "output": "Yes\n2 1 3\nNo\nYes\n1 2 3 4\n" } ]
https://atcoder.jp/contests/agc060/tasks/agc060_f
Problem Statement You have a simple undirected graph. Each vertex in this graph has an integer interval written on it, and there are C_{i,j} vertices with the interval [i,j] ( 1 \leq i \leq j \leq N ). There are no vertices with other intervals. For any two vertices, there is an undirected edge between them if and only if the written intervals intersect. Here, an interval [a,b] and an interval [c,d] intersect if and only if \max(a,c) \leq \min(b,d) . Find the number of spanning trees of this graph, modulo 998244353 . Here, all vertices are pairwise distinguishable.
[ { "input": "2\n1 2\n1\n", "output": "8\n" }, { "input": "3\n1 1 1\n1 1\n1\n", "output": "99\n" }, { "input": "4\n8 3 8 10\n1 5 3\n1 6\n4\n", "output": "971555314\n" }, { "input": "10\n2742 5611 1401 5439 5220 8571 4998 4194 7443 2492\n2393 3201 9106 1649 2456 1984 7159 9679 7695\n808 4600 2573 7771 5839 9504 4381 3223\n5325 2564 456 5050 6963 913 9072\n310 1521 9816 6205 2988 3614\n4810 2979 2852 9242 6290\n7551 7139 7228 699\n4869 889 7597\n4239 5970\n865\n", "output": "234850531\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_a
Problem Statement Given integers A and B , print the value A^B .
[ { "input": "4 3\n", "output": "64\n" }, { "input": "5 5\n", "output": "3125\n" }, { "input": "8 1\n", "output": "8\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_b
Problem Statement You are given an integer N and a sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N . Given Q queries, process them in the given order. Each query is of one of the following two kinds: 1 k x : set the value A _ k to x . 2 k : print the value A _ k .
[ { "input": "3\n1 3 5\n7\n2 2\n2 3\n1 3 0\n2 3\n1 2 8\n2 2\n2 1\n", "output": "3\n5\n0\n8\n1\n" }, { "input": "5\n22 2 16 7 30\n10\n1 4 0\n1 5 0\n2 2\n2 3\n2 4\n2 5\n1 4 100\n1 5 100\n2 3\n2 4\n", "output": "2\n16\n0\n0\n16\n100\n" }, { "input": "7\n478 369 466 343 541 42 165\n20\n2 1\n1 7 729\n1 6 61\n1 6 838\n1 3 319\n1 4 317\n2 4\n1 1 673\n1 3 176\n1 5 250\n1 1 468\n2 6\n1 7 478\n1 5 595\n2 6\n1 6 599\n1 6 505\n2 3\n2 5\n2 1\n", "output": "478\n317\n838\n838\n176\n595\n468\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_c
Problem Statement Takahashi is a cashier. There is a cash register with 11 keys: 00 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , and 9 . The cash register initially displays 0 . Whenever he types the key 00 , the displayed number is multiplied by 100 ; whenever he types one of the others, the displayed number is multiplied by 10 , and then added by the number written on the key. Takahashi wants the cash register to display an integer S . At least how many keystrokes are required to make it display S ?
[ { "input": "40004\n", "output": "4\n" }, { "input": "1355506027\n", "output": "10\n" }, { "input": "10888869450418352160768000001\n", "output": "27\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_d
Problem Statement A string consisting of lowercase English letters, ( , and ) is said to be a good string if you can make it an empty string by the following procedure: First, remove all lowercase English letters. Then, repeatedly remove consecutive () while possible. For example, ((a)ba) is a good string, because removing all lowercase English letters yields (()) , from which we can remove consecutive () at the 2 -nd and 3 -rd characters to obtain () , which in turn ends up in an empty string. You are given a good string S . We denote by S_i the i -th character of S . For each lowercase English letter a , b , \ldots , and z , we have a ball with the letter written on it. Additionally, we have an empty box. For each i = 1,2, \ldots ,|S| in this order, Takahashi performs the following operation unless he faints. If S_i is a lowercase English letter, put the ball with the letter written on it into the box. If the ball is already in the box, he faints. If S_i is ( , do nothing. If S_i is ) , take the maximum integer j less than i such that the j -th through i -th characters of S form a good string. (We can prove that such an integer j always exists.) Take out from the box all the balls that he has put in the j -th through i -th operations. Determine if Takahashi can complete the sequence of operations without fainting.
[ { "input": "((a)ba)\n", "output": "Yes\n" }, { "input": "(a(ba))\n", "output": "No\n" }, { "input": "(((())))\n", "output": "Yes\n" }, { "input": "abca\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_e
Problem Statement You are given a matrix A with H rows and W columns. The value of each of its elements is 0 or 1 . For an integer pair (i, j) such that 1 \leq i \leq H and 1 \leq j \leq W , we denote by A_{i,j} the element at the i -th row and j -th column. You can perform the following operation on the matrix A any number of times (possibly zero): Choose an integer i such that 1 \leq i \leq H . For every integer j such that 1 \leq j \leq W , replace the value of A_{i,j} with 1-A_{i,j} . A_{i,j} is said to be isolated if and only if there is no adjacent element with the same value; in other words, if and only if none of the four integer pairs (x,y) = (i-1,j),(i+1,j),(i,j-1),(i,j+1) satisfies 1 \leq x \leq H, 1 \leq y \leq W , and A_{i,j} = A_{x,y} . Determine if you can make the matrix A in such a state that no element is isolated by repeating the operation. If it is possible, find the minimum number of operations required to do so.
[ { "input": "3 3\n1 1 0\n1 0 1\n1 0 0\n", "output": "1\n" }, { "input": "4 4\n1 0 0 0\n0 1 1 1\n0 0 1 0\n1 1 0 1\n", "output": "2\n" }, { "input": "2 3\n0 1 0\n0 1 1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_f
Problem Statement You are given a permutation P=(P _ 1,P _ 2,\ldots,P _ N) of (1,2,\ldots,N) . Find the following value for all i\ (1\leq i\leq N) : D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen . What is a permutation? A permutation of (1,2,\ldots,N) is a sequence that is obtained by rearranging (1,2,\ldots,N) . In other words, a sequence A of length N is a permutation of (1,2,\ldots,N) if and only if each i\ (1\leq i\leq N) occurs in A exactly once.
[ { "input": "4\n3 2 4 1\n", "output": "2 2 3 3 \n" }, { "input": "7\n1 2 3 4 5 6 7\n", "output": "2 2 2 2 2 2 2 \n" }, { "input": "16\n12 10 7 14 8 3 11 13 2 5 6 16 4 1 15 9\n", "output": "3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7 \n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_g
Problem Statement For a sequence of non-negative integers (a _ 1,a _ 2,\ldots,a _ n) , let us define its \operatorname{xor} as the integer X such that, for all non-negative integer j : the 2^j s place of X is 1 if and only if there is an odd number of elements among a _ 1,\ldots,a _ n whose 2^j s place is 1 . You are given a sequence of non-negative integers A=(A _ 1,A _ 2,\ldots,A _ N) of length N . Let \lbrace s _ 1,s _ 2,\ldots,s _ k\rbrace\ (s _ 1\lt s _ 2\lt\cdots\lt s _ k) be the set of all non-negative integers that can be the \operatorname{xor} of a not-necessarily-contiguous (possibly empty) subsequence of A . Given integers L and R , print s _ L,s _ {L+1},\ldots,s _ R in this order.
[ { "input": "4 1 8\n2 21 17 21\n", "output": "0 2 4 6 17 19 21 23\n" }, { "input": "4 3 7\n2 21 17 21\n", "output": "4 6 17 19 21\n" }, { "input": "5 1 1\n0 0 0 0 0\n", "output": "0\n" }, { "input": "6 21 21\n88 44 82 110 121 80\n", "output": "41\n" }, { "input": "12 26 48\n19629557415 14220078328 11340722069 30701452525 22333517481 720413777 11883028647 20926361028 24376768297 720413777 27999065315 13558621130\n", "output": "13558621130 14220078328 14586054825 15518998043 15970974282 16379590008 17091531049 17412316967 17836964726 18263536708 18965057557 19629557415 20282860278 20926361028 21302757781 21908867832 22333517481 22893781403 23595304394 23723463544 24376768297 24885524507 25261923402\n" } ]
https://atcoder.jp/contests/abc283/tasks/abc283_h
Problem Statement Find the sum of popcounts of all integers between 1 and N , inclusive, such that the remainder when divided by M equals R . Here, the popcount of a positive integer X is the number of 1 s in the binary notation of X , that is, the number of non-negative integers k such that the 2^k s place is 1 . For each input, process T test cases.
[ { "input": "2\n12 5 1\n6 1 0\n", "output": "6\n9\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_a
問題文 マヌブリングの操䜜を高々 500 回行うこずで以䞋の画像に近い画像を䜜り䞊げよ 埌述の達成条件を満たしおいればカラフルな画像にしおもよい
[]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_b
問題文 敎数 N, K, P および文字 A , B からなる長さ N の文字列 S が䞎えられる各 k = 1, 2, \ldots, K に察しお以䞋の問に答えよ (各 k に関する問は別々に考えよ) くろうさずしろうさが問題の速解き競争を行う問題は 1 問ず぀出題され i 問目 ( i = 1, 2, \ldots ) は以䞋のようになる i \le N か぀ S の i 文字目が A である堎合確率 \frac{P}{100} でくろうさが先に解き確率 1 - \frac{P}{100} でしろうさが先に解く i \le N か぀ S の i 文字目が B である堎合確率 1 - \frac{P}{100} でくろうさが先に解き確率 \frac{P}{100} でしろうさが先に解く i > N の堎合確率 \frac{1}{2} でくろうさが先に解き確率 \frac{1}{2} でしろうさが先に解く 「 i 問目をくろうさが先に解く」ずいう事象たちは互いに独立である 「先に解いた問題」が k 問に到達したうさぎが珟れた時点で競争を終了しそのうさぎの優勝ずするくろうさが優勝する確率ず \frac{1}{2} の 倧小を比范せよ
[ { "input": "2 2 25\nAB\n", "output": "-0\n" }, { "input": "10 4 99\nAABBBAABBB\n", "output": "++-+\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_c
問題文 (1,2,\ldots,N) の順列 P=(P_1,P_2,\ldots,P_N) ず Q=(Q_1,Q_2,\ldots,Q_N) が䞎えられる以䞋の操䜜を高々 N^2 回行っお P を Q に䞀臎させられるか刀定し可胜な堎合はそのような操䜜列を 1 通り求めよ 次の条件のうち少なくずも䞀方を満たす敎数 i を遞び P_i ず P_{i+1} の倀を入れ替える 1 \leq i \leq N-2 か぀ \min(P_i,P_{i+1}) < P_{i+2} < \max(P_i,P_{i+1}) 2 \leq i \leq N-1 か぀ \min(P_i,P_{i+1}) < P_{i-1} < \max(P_i,P_{i+1})
[ { "input": "3\n2 1 3\n2 3 1\n", "output": "1\n2\n" }, { "input": "3\n1 2 3\n1 3 2\n", "output": "-1\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_d
問題文 非負敎数 N, A, B, C が䞎えられる æ­£ 敎数列 (x_0, x_1, \ldots, x_N) であっお以䞋の条件をすべお満たすものの個数を 998244353 で割った䜙りを求めよ x_0 = 2^A \times 2^B  x_N = ((2^A + 1) \times 2^C) - 1  各 i = 0, 1, \ldots, N - 1 に察し x_{i+1} \in \{ \lfloor x_i/2 \rfloor, 2 x_i, 2 x_i + 1 \} 
[ { "input": "4 1 1 1\n", "output": "7\n" }, { "input": "9 2 0 1\n", "output": "1164\n" }, { "input": "1 0 2 4\n", "output": "0\n" }, { "input": "2022 12 24 14\n", "output": "426021617\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_e
問題文 敎数 P_1, P_2, \ldots, P_N が䞎えられる N 枚のコむンがありそれぞれ 1, 2, \ldots, N の番号が付いおいるどの 2 枚のコむンも区別できるうさぎがこれからある特殊な方法でこれらのコむンを䞀斉に投げ各コむンが衚たたは裏のいずれか䞀方になる コむン i は確率 \frac{P_i}{100} で衚になり確率 1 - \frac{P_i}{100} で裏になるこずがわかっおいる ( 1 \le i \le N )たたどの異なる 2 枚のコむン i, j に぀いおもコむン i が衚になる事象ずコむン j が衚になる事象は独立であるこずがわかっおいる ( 1 \le i, j \le N  i \ne j ) このずきすべおのコむンが衚になる確率ずしお考えられる最小倀を求めよこの問題の制玄䞋で最小倀が存圚するこずが蚌明できる
[ { "input": "2\n13 77\n", "output": "0.1001\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_f
問題文 無向グラフ G は 1, 2, \ldots, N を頂点ずし頂点 u ず頂点 v を結ぶ蟺はちょうど A_{u,v} 本ある ( 1 \le u, v \le N )すべおの蟺は区別される 各 k = 0, 1, \ldots, \lfloor N/2 \rfloor に察し G の倧きさ k のマッチングの個数を 2^{64} で割った䜙りを求めよ ( G の倧きさ k のマッチングずは G の蟺 k 本からなる集合であっおそれらの端点 2 k 個が盞異なるようなものを指す)
[ { "input": "4\n0 10 300 0\n10 0 5 400\n300 5 0 20\n0 400 20 0\n", "output": "1 735 120200\n" }, { "input": "7\n0 1 1 1 1 1 1\n1 0 1 1 1 1 1\n1 1 0 1 1 1 1\n1 1 1 0 1 1 1\n1 1 1 1 0 1 1\n1 1 1 1 1 0 1\n1 1 1 1 1 1 0\n", "output": "1 21 105 105\n" }, { "input": "10\n0 8629318490492529455 16934461172002342162 16689922355946803515 6532726440738276996 1194408499640297875 15866676155001669889 6498797546467110859 16876940315014902410 12387509481131737340\n8629318490492529455 0 11507224725899007093 8715646015311805917 10082055328422634515 11661112510609506937 5671467989936109679 9958089075065687029 1044511129638713462 9641449008999128869\n16934461172002342162 11507224725899007093 0 9017212196119468141 8742031656924741889 16712732165713258491 12486619021854068086 8079880079267306335 7411259632269635598 847494329973810398\n16689922355946803515 8715646015311805917 9017212196119468141 0 16283252096557152371 8615030617835929416 17667878928797645683 18446439882335127774 11475081586957078864 15537196317840490094\n6532726440738276996 10082055328422634515 8742031656924741889 16283252096557152371 0 2328769271400341339 5743580703459253102 13482125554117518013 8310663885706538154 15657502149293391713\n1194408499640297875 11661112510609506937 16712732165713258491 8615030617835929416 2328769271400341339 0 13134573721194912427 3260072811817230082 12647757802949221999 15331084503094140917\n15866676155001669889 5671467989936109679 12486619021854068086 17667878928797645683 5743580703459253102 13134573721194912427 0 5011674754910118042 4293452480892783480 12853153721226986708\n6498797546467110859 9958089075065687029 8079880079267306335 18446439882335127774 13482125554117518013 3260072811817230082 5011674754910118042 0 8466317684966562639 13151347917827920992\n16876940315014902410 1044511129638713462 7411259632269635598 11475081586957078864 8310663885706538154 12647757802949221999 4293452480892783480 8466317684966562639 0 1834230013668150904\n12387509481131737340 9641449008999128869 847494329973810398 15537196317840490094 15657502149293391713 15331084503094140917 12853153721226986708 13151347917827920992 1834230013668150904 0\n", "output": "1 13998873960259808869 16134958027077044128 15075909322183550749 13815169532537848652 14625654317779811048\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_g
問題文 1 個の入力ファむルに぀き T 個のテストケヌスが䞎えられる各テストケヌスで敎数 N, S が䞎えられるので以䞋の問に答えよ 敎数 A_0, A_1, \ldots, A_{4N-1} を以䞋のように定める数匏および C++ コヌド片で瀺す 倉数 s を s \gets S ずする i = 0, 1, \ldots, 4 N - 1 に察しこの順で A_i \gets \lfloor i/4 \rfloor + 1 ずする i = 0, 1, \ldots, 4 N - 1 に察しこの順で s \gets (s \times 2022) \bmod 998244353 ずしおから s \not\equiv 0 \pmod{2} ならば A_i \gets -A_i ずする i = 0, 1, \ldots, 4 N - 1 に察しこの順で s \gets (s \times 2022) \bmod 998244353 ずしおから A_{s \bmod (i+1)} ず A_i の倀を入れ替える #include <vector> std::vector<int> Generate(int N, long long S) { long long s = S; std::vector<int> A(4 * N); for (int i = 0; i < 4 * N; ++i) { A[i] = i / 4 + 1; } for (int i = 0; i < 4 * N; ++i) { s = (s * 2022) % 998244353; if (s % 2 != 0) { A[i] = -A[i]; } } for (int i = 0; i < 4 * N; ++i) { s = (s * 2022) % 998244353; int j = s % (i + 1); int t = A[j]; A[j] = A[i]; A[i] = t; } return A; } 各 j = 1, 2, \ldots, N に察しお +j ず -j のいずれかちょうど䞀方を「良い敎数」ず決める方法 2^N 通りのうち以䞋の N 個の条件をすべお満たすものが存圚するかどうか刀定し存圚する堎合はそのような方法を 1 通り求めよ A_0, A_1, A_2, A_3 のうち少なくずも 1 個は良い敎数である A_4, A_5, A_6, A_7 のうち少なくずも 1 個は良い敎数である \cdots A_{4N-4}, A_{4N-3}, A_{4N-2}, A_{4N-1} のうち少なくずも 1 個は良い敎数である
[ { "input": "2\n3 1\n4 20221224\n", "output": "++-\n+--+\n" } ]
https://atcoder.jp/contests/xmascon22/tasks/xmascon22_h
問題文 1 個の入力ファむルに぀き T 個のテストケヌスが䞎えられる各テストケヌスで次のようなグラフ G が䞎えられるので以䞋の問に答えよ G は N 頂点 M 蟺からなる連結な単玔無向グラフである頂点には 1 から N たでの番号が぀いおおり i 番目の蟺は頂点 A_i ず B_i を結んでいる ( 1 \le i \le M ) 今 G の頂点はすべお癜色で塗られおいるこれからくろうさずしろうさが次のゲヌムを行う たずくろうさが奜きな頂点を 1 個遞び黒色で塗る その埌癜色に塗られおいる頂点が存圚する限りしろうさが以䞋の操䜜を繰り返す 黒色で塗られおいる頂点に隣接しおいるような頂点を 1 個たたは 2 個遞ぶ遞んだ頂点をすべお黒色で塗る しろうさの操䜜回数を スコア ず呌ぶくろうさの目的はスコアの最倧化でありしろうさの目的は最小化である䞡者が最適に行動した堎合のゲヌムのスコアを求めよ
[ { "input": "2\n3 2\n1 2\n2 3\n4 4\n1 2\n2 3\n3 4\n4 1\n", "output": "2\n2\n" }, { "input": "2\n5 8\n5 1\n2 3\n2 4\n5 2\n1 3\n3 5\n1 4\n4 5\n20 40\n13 10\n13 19\n12 15\n14 7\n1 17\n8 17\n13 7\n10 7\n16 2\n5 20\n12 1\n3 12\n19 7\n8 20\n20 16\n2 5\n14 13\n3 9\n13 6\n5 16\n4 1\n2 4\n8 16\n14 10\n8 2\n11 8\n15 3\n18 5\n17 20\n11 17\n6 10\n16 11\n15 1\n9 6\n19 6\n8 4\n2 11\n20 11\n10 19\n16 18\n", "output": "2\n11\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_a
Problem Statement You are given an integer K . Print a string that is a concatenation of the first K uppercase English letters in ascending order, starting from A .
[ { "input": "3\n", "output": "ABC\n" }, { "input": "1\n", "output": "A\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_b
Problem Statement N participants, numbered 1 to N , will participate in a contest with M problems, numbered 1 to M . For an integer i between 1 and N and an integer j between 1 and M , participant i can solve problem j if the j -th character of S_i is o , and cannot solve it if that character is x . The participants must be in pairs. Print the number of ways to form a pair of participants who can collectively solve all the M problems. More formally, print the number of pairs (x,y) of integers satisfying 1\leq x < y\leq N such that for any integer j between 1 and M , at least one of participant x and participant y can solve problem j .
[ { "input": "5 5\nooooo\noooxx\nxxooo\noxoxo\nxxxxx\n", "output": "5\n" }, { "input": "3 2\nox\nxo\nxx\n", "output": "1\n" }, { "input": "2 4\nxxxx\noxox\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_c
Problem Statement You are given a string S of length N consisting of lowercase English letters, , , and " . It is guaranteed that S contains an even number of " . Let 2K be the number of " in S . For each i=1,2,\ldots,K , the characters from the (2i-1) -th " through the (2i) -th " are said to be enclosed . Your task is to replace each , in S that is not an enclosed character with . and print the resulting string.
[ { "input": "8\n\"a,b\"c,d\n", "output": "\"a,b\"c.d\n" }, { "input": "5\n,,,,,\n", "output": ".....\n" }, { "input": "20\na,\"t,\"c,\"o,\"d,\"e,\"r,\n", "output": "a.\"t,\"c.\"o,\"d.\"e,\"r.\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_d
Problem Statement You are given a simple undirected graph G with N vertices and M edges (a simple graph does not contain self-loops or multi-edges). For i = 1, 2, \ldots, M , the i -th edge connects vertex u_i and vertex v_i . Print the number of pairs of integers (u, v) that satisfy 1 \leq u \lt v \leq N and both of the following conditions. The graph G does not have an edge connecting vertex u and vertex v . Adding an edge connecting vertex u and vertex v in the graph G results in a bipartite graph. What is a bipartite graph? An undirected graph is said to be bipartite if and only if one can paint each vertex black or white to satisfy the following condition. No edge connects vertices painted in the same color.
[ { "input": "5 4\n4 2\n3 1\n5 2\n3 2\n", "output": "2\n" }, { "input": "4 3\n3 1\n3 2\n1 2\n", "output": "0\n" }, { "input": "9 11\n4 9\n9 1\n8 2\n8 3\n9 2\n8 4\n6 7\n4 6\n7 5\n4 5\n7 8\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_e
Problem Statement A box contains N balls, each with an integer between 1 and M-1 written on it. For i = 1, 2, \ldots, N , the integer written on the i -th ball is A_i . While the box has two or more balls remaining, Takahashi will repeat the following. First, choose two balls arbitrarily. Then, get a score equal to the remainder when x^y + y^x is divided by M , where x and y are the integers written on the two balls. Finally, choose one of the two balls arbitrarily, eat it, and return the other to the box. Print the maximum possible total score Takahashi will get.
[ { "input": "4 10\n4 2 3 2\n", "output": "20\n" }, { "input": "20 100\n29 31 68 20 83 66 23 84 69 96 41 61 83 37 52 71 18 55 40 8\n", "output": "1733\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_f
Problem Statement This is an interactive task , where your and the judge's programs interact via Standard Input and Output. You and the judge will follow the procedure below. The procedure consists of phases 1 and 2 ; phase 1 is immediately followed by phase 2 . (Phase 1 ) The judge gives you an integer N . You print an integer M between 1 and 50000 , inclusive. You also print M pairs of integers (l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M) such that 1 \leq l_i \leq r_i \leq N for every i = 1, 2, \ldots, M (the M pairs do not have to be distinct). (Phase 2 ) The judge gives you an integer Q . You and the judge repeats the following Q times. The judge gives you two integers L and R as a query. You respond with two integers a and b between 1 and M , inclusive (possibly with a = b ). Here, a and b must satisfy the condition below. Otherwise, your submission will be judged incorrect. The union of the set \lbrace l_a, l_a+1, \ldots, r_a\rbrace and the set \lbrace l_b, l_b+1, \ldots, r_b\rbrace equals the set \lbrace L, L+1, \ldots, R\rbrace . After the procedure above, terminate the program immediately to be judged correct.
[]
https://atcoder.jp/contests/abc282/tasks/abc282_g
Problem Statement Below, a permutation of (1,2,\ldots,N) is simply called a permutation. For two permutations A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N) , let us define their similarity as the number of integers i between 1 and N-1 such that: (A_{i+1}-A_i)(B_{i+1}-B_i)>0 . Find the number, modulo a prime number P , of pairs of permutations (A,B) whose similarity is K .
[ { "input": "3 1 282282277\n", "output": "16\n" }, { "input": "50 25 998244353\n", "output": "131276976\n" } ]
https://atcoder.jp/contests/abc282/tasks/abc282_h
Problem Statement You are given two sequences of integers of length N : A = (A_1, A_2, \ldots, A_N) and B = (B_1, B_2, \ldots, B_N) . Print the number of pairs of integers (l, r) that satisfy 1 \leq l \leq r \leq N and the following condition. \min\lbrace A_l, A_{l+1}, \ldots, A_r \rbrace + (B_l + B_{l+1} + \cdots + B_r) \leq S
[ { "input": "4 15\n9 2 6 5\n3 5 8 9\n", "output": "6\n" }, { "input": "15 100\n39 9 36 94 40 26 12 26 28 66 73 85 62 5 20\n0 0 7 7 0 5 5 0 7 9 9 4 2 5 2\n", "output": "119\n" } ]
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_a
問題文 JOI 垂には 1 から N たでの番号が付けられた N 人の䜏民がおり䜏民 i ( 1 \leqq i \leqq N ) の幎霢は A_i 歳である JOI 垂の䜏民の幎霢 A_1, A_2, \dots, A_N が䞎えられる i = 1, 2, \dots, N に察しお䜏民 i ず他の䜏民ずの幎霢の差の最倧倀を求めるプログラムを䜜成せよ
[ { "input": "3\n13 15 20\n", "output": "7\n5\n7\n" }, { "input": "2\n100 100\n", "output": "0\n0\n" }, { "input": "10\n440894064 101089692 556439322 34369336 98417847 216265879 623843484 554560874 247445405 718003331\n", "output": "406524728\n616913639\n522069986\n683633995\n619585484\n501737452\n589474148\n520191538\n470557926\n683633995\n" } ]
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_b
問題文 JOI 䞭孊校には 4N 人の䞀幎生が圚籍しおおり 4 ぀のクラスに分かれおいる各クラスの情報は以䞋の通りである 1 幎 A 組 N 人の生埒がいるそれぞれの生埒の身長は A_1, A_2, \ldots, A_N である 1 幎 B 組 N 人の生埒がいるそれぞれの生埒の身長は B_1, B_2, \ldots, B_N である 1 幎 C 組 N 人の生埒がいるそれぞれの生埒の身長は C_1, C_2, \ldots, C_N である 1 幎 D 組 N 人の生埒がいるそれぞれの生埒の身長は D_1, D_2, \ldots, D_N である 来月JOI 䞭孊校では䜓育祭が開催されるこずになった䜓育祭にはリレヌ階銬戊棒倒しなどの様々な皮目があるが各孊幎が螊るダンスは「䜓育祭の華」ずも呌ばれる泚目の皮目である ここで䞀幎生は各クラスから代衚を 1 人ず぀遞び 4 人でダンスをするこずになったダンスの芋栄えをできるだけ良くするため身長の差ができるだけ小さくなるように 4 人組を遞ぶこずにした 䞀幎生の身長が䞎えられるずき「 4 人の身長の最倧倀」ず「 4 人の身長の最小倀」の差ずしお考えられる最小の倀を求めるプログラムを䜜成せよ
[ { "input": "1\n169\n173\n152\n200\n", "output": "48\n" }, { "input": "7\n7 9 9 4 6 3 5\n1 1 1 1 1 1 1\n1 1 1 1 1 1 1\n1 1 1 1 1 1 1\n", "output": "2\n" }, { "input": "7\n1 1 1 1 2 1 1\n1 2 1 1 1 1 1\n1 1 1 1 2 1 1\n1 1 1 1 1 1 2\n", "output": "0\n" }, { "input": "5\n287 690 413 420 138\n813 873 223 415 907\n261 330 361 747 787\n958 672 544 126 345\n", "output": "70\n" }, { "input": "10\n1682 2008 1135 1576 2450 1362 1518 1925 2212 1275\n1993 1945 1312 1401 2027 1705 1086 2333 1787 1654\n2257 1548 1219 1031 2613 2171 1866 1532 2800 1497\n1062 1175 1984 1870 2059 1639 2107 1335 1289 2494\n", "output": "79\n" } ]
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_c
問題文 JOI くんはお絵かき゜フトで遊んでいる お絵かき゜フトでは瞊 H 行暪 W 列の長方圢のマス目に絵を描くこずができるそれぞれのマスには色が定められおおり色は 1 以䞊 10^9 以䞋の敎数で衚される 䞊から i 行目 ( 1 \leqq i \leqq H )巊から j 列目 ( 1 \leqq j \leqq W ) のマスをマス (i,j) ず呌ぶ珟圚マス (i,j) の色は A_{i,j} である マス (i,j) から蟺で接しおいるマスぞの移動を繰り返しマス (i,j) ず色が異なるマスに入るこずなく移動できるマスの集たりをここでは マス (i,j) の領域 ず呌ぶ お絵かき゜フトには 塗り぀ぶし ずいう機胜があるこの機胜ではあるマス (x,y) ( 1 \leqq x \leqq H  1 \leqq y \leqq W ) ず色 c ( 1 \leqq c \leqq 10^9 ) を指定するずマス (x,y) の領域に含たれるマスの色がすべお c に倉化する JOI くんはあるマス (x,y) ず色 c を遞びそのマスず色を指定しお塗り぀ぶしをちょうど 1 回䜿う塗り぀ぶしを䜿った埌のマス (x,y) の領域に含たれるマスの個数が JOI くんの埗点ずなる JOI くんの埗点ずしお達成可胜な最倧倀を求めるプログラムを䜜成せよ
[ { "input": "4 4\n1 2 3 1\n2 2 3 1\n1 2 3 1\n3 3 2 2\n", "output": "9\n" }, { "input": "2 10\n1 2 2 1 3 3 3 3 1 1\n1 1 1 1 1 1 1 3 3 3\n", "output": "18\n" }, { "input": "5 5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "output": "25\n" } ]
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_d
問題文 IOI 鉄道は 1 本の鉄道路線を運営しおいるIOI 鉄道線には䞀盎線䞊に䞊んだ N 個の駅があり順に 1 から N たでの番号が付けられおいる各 i ( 1 \leqq i \leqq N - 1 ) に察しお駅 i ず駅 i + 1 の間は線路で結ばれおおりその長さは 1 である IOI 鉄道は貚物を取り扱っおいる駅 2, 3, \ldots, N には貚物が 1 ぀ず぀眮かれおおり駅 i ( 2 \leqq i \leqq N ) に眮かれおいる貚物の䟡倀は A_i である IOI 鉄道は貚物列車を 1 線成所有しおいるこの列車は最初駅 1 におりIOI 鉄道線䞊を双方向に走行できるそれぞれの駅ではその駅に眮いおある貚物を列車に積むこずや列車に積たれおいる貚物を䞋ろしその駅に眮いおおくこずができる この貚物列車を甚いお 駅 2, 3, \ldots, N に眮かれおいる貚物を駅 1 に茞送したいただしこの列車には貚物を W 個以䞋しか茉せるこずができないすなわちどの時点においおも列車に貚物が W + 1 個以䞊茉っおいるこずは蚱されないたたこの列車は燃料の郜合䞊最倧でも総距離 D しか走行するこずができないそのためすべおの貚物を駅 1 に茞送するこずはできないかもしれない IOI 鉄道の瀟長である JOI くんはこの条件のもず適切に貚物列車を走行させるこずで最終的に駅 1 に眮かれおいる貚物の䟡倀の合蚈をなるべく倧きくしたい 貚物列車の情報ず各駅に眮かれおいる貚物の情報が䞎えられたずき最終的に駅 1 に眮かれおいる貚物の䟡倀の合蚈ずしお達成可胜な最倧倀を求めるプログラムを䜜成せよ
[ { "input": "4 1 10\n1 1 1\n", "output": "2\n" }, { "input": "7 3 16\n1 1 1 1 1 1\n", "output": "5\n" }, { "input": "5 2 12\n40 30 20 10\n", "output": "100\n" }, { "input": "5 1 11\n2 7 1 8\n", "output": "10\n" }, { "input": "9 3 14\n54640 754112 604290 105866 591907 801383 502975 379373\n", "output": "2214425\n" } ]
https://atcoder.jp/contests/joi2023yo2/tasks/joi2023_yo2_e
問題文 日本列島は東西に现長い列島である日本列島は南北方向の境界線により N 個の区画に分けられおいる区画には西から順に 1 から N たでの番号が付けられおいる珟圚区画 i ( 1 \leqq i \leqq N ) の暙高は A_i \: \mathrm{m} である 日本列島ではたびたび嵐が起きおいる嵐が起きるず波による浞食で各区画の暙高が以䞋のように枛少する 匷さ x の 西颚の 嵐では西から数えお x 個以内の区画のうち「それより西に自身より暙高の高い区画が存圚しない」ようなすべおの区画の暙高が 1 \: \mathrm{m} 枛少するすなわち嵐の前の区画 i の暙高を a_i で衚すず i \leqq x か぀ 1 \leqq k \lt i ずなるすべおの k に察しお a_k \leqq a_i ずなる堎合に区画 i の暙高は 1 \: \mathrm{m} 枛りそれ以倖の堎合には倉わらない 匷さ x の 東颚の 嵐では東から数えお x 個以内の区画のうち「それより東に自身より暙高の高い区画が存圚しない」ようなすべおの区画の暙高が 1 \: \mathrm{m} 枛少するすなわち嵐の前の区画 i の暙高を a_i で衚すず i \geqq N - x + 1 か぀ i \lt k \leqq N ずなるすべおの k に察しお a_k \leqq a_i ずなる堎合に区画 i の暙高は 1 \: \mathrm{m} 枛りそれ以倖の堎合には倉わらない あなたは今埌 Q 日間の出来事をシミュレヌションしなければならない j 日目 ( 1 \leqq j \leqq Q ) には次のような出来事が起きる T_j = 1 のずき匷さ X_j の西颚の嵐が起きる T_j = 2 のずき匷さ X_j の東颚の嵐が起きる T_j = 3 のずきその時点での区画 X_j の暙高を報告する なお制玄よりどの区画の暙高も負にならないこずが保蚌される 珟圚の各区画の暙高および今埌 Q 日間の出来事が䞎えられるので T_j = 3 である日に察しお指定された区画の暙高を求めるプログラムを䜜成せよ
[ { "input": "5 7\n7 7 7 7 7\n1 3\n1 1\n3 1\n2 1\n2 5\n3 2\n3 4\n", "output": "5\n6\n6\n" }, { "input": "5 7\n10 13 14 7 12\n1 5\n2 5\n3 3\n3 4\n2 5\n3 1\n3 2\n", "output": "12\n7\n9\n11\n" }, { "input": "5 6\n8 6 7 8 9\n1 1\n3 1\n3 5\n1 3\n3 2\n3 3\n", "output": "7\n9\n6\n6\n" }, { "input": "5 6\n6 8 6 9 7\n2 1\n2 4\n3 5\n1 5\n3 4\n3 3\n", "output": "5\n7\n6\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_a
Problem Statement Print all non-negative integers less than or equal to N in descending order.
[ { "input": "3\n", "output": "3\n2\n1\n0\n" }, { "input": "22\n", "output": "22\n21\n20\n19\n18\n17\n16\n15\n14\n13\n12\n11\n10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n0\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_b
Problem Statement You are given a string S consisting of uppercase English letters and digits. Determine whether S satisfies the following condition. S is a concatenation of the following characters and string in the order listed. An uppercase English letter A string of length 6 that is a decimal representation of an integer between 100000 and 999999 , inclusive An uppercase English letter
[ { "input": "Q142857Z\n", "output": "Yes\n" }, { "input": "AB912278C\n", "output": "No\n" }, { "input": "X900000\n", "output": "No\n" }, { "input": "K012345K\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_c
Problem Statement We have a playlist with N songs numbered 1, \dots, N . Song i lasts A_i seconds. When the playlist is played, song 1 , song 2 , \ldots , and song N play in this order. When song N ends, the playlist repeats itself, starting from song 1 again. While a song is playing, the next song does not play; when a song ends, the next song starts immediately. At exactly T seconds after the playlist starts playing, which song is playing? Also, how many seconds have passed since the start of that song? There is no input where the playlist changes songs at exactly T seconds after it starts playing.
[ { "input": "3 600\n180 240 120\n", "output": "1 60\n" }, { "input": "3 281\n94 94 94\n", "output": "3 93\n" }, { "input": "10 5678912340\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "6 678912340\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_d
Problem Statement You are given a sequence of non-negative integers A=(a_1,a_2,\ldots,a_N) . Let S be the set of non-negative integers that can be the sum of K terms in A (with distinct indices). Find the greatest multiple of D in S . If there is no multiple of D in S , print -1 instead.
[ { "input": "4 2 2\n1 2 3 4\n", "output": "6\n" }, { "input": "3 1 2\n1 3 5\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_e
Problem Statement You are given an integer sequence A = (A_1, \dots, A_N) of length N , and integers M and K . For each i = 1, \dots, N - M + 1 , solve the following independent problem. Find the sum of the first K values in the sorted list of the M integers A_i, A_{i + 1}, \dots, A_{i + M - 1} in ascending order.
[ { "input": "6 4 3\n3 1 4 1 5 9\n", "output": "5 6 10\n" }, { "input": "10 6 3\n12 2 17 11 19 8 4 3 6 20\n", "output": "21 14 15 13 13\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_f
Problem Statement You are given a sequence of non-negative integers A=(a_1,\ldots,a_N) . Let us perform the following operation on A just once. Choose a non-negative integer x . Then, for every i=1, \ldots, N , replace the value of a_i with the bitwise XOR of a_i and x . Let M be the maximum value in A after the operation. Find the minimum possible value of M . What is bitwise XOR? The bitwise 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": "3\n12 18 11\n", "output": "16\n" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\n", "output": "0\n" }, { "input": "5\n324097321 555675086 304655177 991244276 9980291\n", "output": "805306368\n" } ]
https://atcoder.jp/contests/abc281/tasks/abc281_g
Problem Statement You are given positive integers N and M . Find the number, modulo M , of simple connected undirected graphs with N vertices numbered 1, \dots, N that satisfy the following condition. For every u = 2, \dots, N-1 , the shortest distance from vertex 1 to vertex u is strictly smaller than the shortest distance from vertex 1 to vertex N . Here, the shortest distance from vertex u to vertex v is the minimum number of edges in a simple path connecting vertices u and v . Two graphs are considered different if and only if there are two vertices u and v that are connected by an edge in exactly one of those graphs.
[ { "input": "4 1000000000\n", "output": "8\n" }, { "input": "3 100000000\n", "output": "1\n" }, { "input": "500 987654321\n", "output": "610860515\n" } ]