url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/past202209-open/tasks/past202209_a
Problem Statement There is a traffic light with a button. In principle, if you press the button when the light is red, it turns green X seconds later. However, if it would turn green earlier than Y seconds after it turned red last time, it turns green Y seconds after it turned red last time instead. Now, the button has just been pressed Z seconds after it turned red last time. How many seconds will pass before it turns green since it turned red last time?
[ { "input": "10 20 5\n", "output": "20\n" }, { "input": "10 20 15\n", "output": "25\n" }, { "input": "36 49 73\n", "output": "109\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_b
Problem Statement You are given an integer N . Truncate \displaystyle\frac{N}{100} by discarding the fractional part and print the resulting integer.
[ { "input": "9876\n", "output": "98\n" }, { "input": "99\n", "output": "0\n" }, { "input": "31415926535897932384626433832795028841971693993\n", "output": "314159265358979323846264338327950288419716939\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_c
Problem Statement We have three six-sided dice. When the i -th die is thrown, it shows the number j with the probability \frac{P_{i,j}} {100} . If we throw these three dice, what is the probability that the sum of the numbers shown is K , for each K=1,2,\ldots,18 ?
[ { "input": "10 10 20 20 20 20\n10 10 20 20 20 20\n10 10 20 20 20 20\n", "output": "0.000000\n0.000000\n0.001000\n0.003000\n0.009000\n0.019000\n0.036000\n0.060000\n0.086000\n0.114000\n0.132000\n0.140000\n0.132000\n0.108000\n0.080000\n0.048000\n0.024000\n0.008000\n" }, { "input": "100 0 0 0 0 0\n100 0 0 0 0 0\n100 0 0 0 0 0\n", "output": "0.000000\n0.000000\n1.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n0.000000\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_d
Problem Statement Mr. Aoki gave Takahashi, his student, an assignment that asked him to make a simple undirected graph. An undirected graph is simple when both of the following conditions are satisfied. There are no multi-edges . That is, for any two vertices u and v , there is at most one edge connecting u and v . There are no self-loops . That is, for any vertex v , there is no edge connecting v and v itself. Takahashi writes his undirected graph G in the following format in his notebook and submits it to his teacher. N M u_1 v_1 u_2 v_2 \vdots u_M v_M Here, N and M are the numbers of vertices and edges in G , respectively, and u_i and v_i for each i = 1, 2, \ldots, M means that the i -th edge connects Vertex u_i and Vertex v_i . Mr. Aoki will check whether Takahashi's writing correctly describes a simple undirected graph. More accurately, the teacher will check whether both of the following are satisfied. 1 \leq u_i \leq N and 1 \leq v_i \leq N , for every i = 1, 2, \ldots, M . The undirected graph described is simple. Put yourself in Mr. Aoki's shoes and check whether Takahashi's writing satisfies both conditions above.
[ { "input": "3 3\n1 2\n2 3\n3 4\n", "output": "No\n" }, { "input": "2 2\n1 2\n2 1\n", "output": "No\n" }, { "input": "1 1\n1 1\n", "output": "No\n" }, { "input": "5 4\n1 3\n3 4\n4 1\n2 5\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_e
Problem Statement Let us play a game of bowling consisting of R rounds. Each round goes as follows. Place N pins. Repeat the following procedure M times. Throw a ball toward them, and record the number of pins knocked down as the score. Remove the pins knocked down. If all N pins have been removed, end the round even if this procedure is not repeated M times. You are given a sequence of L integers: s=(s_1,s_2,\ldots,s_L) . Determine whether this can be a sequence of scores recorded in order in the whole game.
[ { "input": "3 10 5 9\n7 3 0 2 4 0 1 0 10\n", "output": "Yes\n" }, { "input": "1 100 3 2\n10 20\n", "output": "No\n" }, { "input": "2 100 3 5\n100 10 20 30 40\n", "output": "No\n" }, { "input": "3 30 100 5\n20 20 15 15 30\n", "output": "No\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_f
Problem Statement We have N kinds of drugs numbered 1 to N . The efficiency of a drug is represented by an integer from 1 to 100 ; the greater, the more efficient. The efficiency of Drug i is A_i . (All A_i are distinct.) The drugs also contain allergens (substances that cause allergic reactions). Allergens are represented by integers from 1 to 2 \times 10^5 , and Drug i contains C_i allergens X_{i,1}, X_{i,2}, \dots, X_{i,C_i} . You are given Q queries, which should be processed according to the instruction. The p -th query is the following: Person p has allergies to D_p allergens Y_{p,1}, Y_{p,2}, \dots, Y_{p,D_p} , and may not be given a drug containing one or more of those allergens. Consider giving Person p one of the drugs from Drug 1 to Drug N . Print the number representing the most efficient drug that may be given to Person p . If no drug may be given, print -1 .
[ { "input": "3\n10 9 8\n3\n1 2 3\n1\n1\n2\n2 3\n4\n0\n\n1\n1\n1\n2\n2\n1 2\n", "output": "1\n3\n2\n-1\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_g
Problem Statement Let S be a string consisting of lowercase English letters and T be a string consisting of lowercase English letters and ? . S is said to be obtainable from T when one can replace each occurrence of ? in T with some lowercase English letter so that T equals S . For example, abcd and addd are obtainable from a??d , while bcdd is not. You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters. All of these strings have a length of L : |S_1| = |S_2| = \cdots = |S_N| = L . A string T of length L consisting of lowercase English letters is arbitrarily chosen so that it contains exactly K ? s . Find the maximum possible number of strings among S_1, S_2, \ldots, S_N that are obtainable from T .
[ { "input": "5 4 2\naabc\nbbaa\nabbc\ncccc\nacba\n", "output": "3\n" }, { "input": "5 4 4\naabc\nbbaa\nabbc\ncccc\nacba\n", "output": "5\n" }, { "input": "5 4 0\naabc\nbbaa\nabbc\ncccc\nacba\n", "output": "1\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_h
Problem Statement Takahashi has 0 gold coins, 10^9 silver coins, and X bronze coins. A shop sells N bags. For i = 1, 2, \ldots, N , the i -th bag can be bought by paying A_i silver coins and B_i bronze coins. The i -th bag contains C_i gold coins; by buying the bag, he obtains the gold coins in it. A gold coin is worth 10^{100^{100}} yen (the currency in Japan), a silver coin is worth 10^{100} yen, and a bronze coin is worth 1 yen. Takahashi wants to buy some (possibly zero) of the N bags and maximize the resulting total value of the gold, silver, and bronze coins he has. Print the numbers of gold, silver, and bronze coins, when the resulting total value of the gold, silver, and bronze coins is maximized. The bronze and silver coins required for buying a bag cannot be substituted by another kind of coin. For example, a silver coin is worth 10^{100} bronze coins when converted into yen, but it does not mean you can pay a silver coin instead of paying bronze coins.
[ { "input": "5 4\n2 2 3\n2 2 2\n3 1 2\n1 3 1\n1 2 2\n", "output": "5 999999997 0\n" }, { "input": "20 50\n4 3 7\n2 0 8\n7 2 4\n9 0 9\n6 5 8\n4 7 1\n3 9 2\n3 9 2\n7 4 4\n2 7 3\n6 3 2\n4 10 8\n2 2 10\n8 1 5\n3 2 6\n3 8 5\n8 1 9\n3 7 4\n9 6 2\n5 6 7\n", "output": "92 999999930 0\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_i
Problem Statement Solve the following problem for T test cases. Takahashi has 10^{100} coupons, each worth M yen, available in Lunlun Mart. The shop does not give change on these coupons where the price of the purchased item is less than the value of the coupons. On the i -th day, Takahashi will buy an apple worth A \times i yen using only the coupons. Here, the sadness of Takahashi increases by k \times M - A \times i , where k is the minimum number of ( M -yen) coupons needed to pay at least A \times i yen. In N days of shopping, how much total sadness will Takahashi accumulate?
[ { "input": "10\n4 5 8\n8 9 10\n4 10 7\n10 1 5\n6 4 9\n304607 77 89\n291969 231 9\n424790 216 294\n76881 213 111\n312895 58 1\n", "output": "14\n36\n12\n20\n24\n13402703\n875907\n61169622\n4151490\n0\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_j
Problem Statement There is a rectangular garden that is H meters long and W meters wide. At the center of the garden is a sprinkler, which sprays water within a radius of D meters from it. Find the proportion of the area sprayed by the sprinkler in the garden.
[ { "input": "10 15 3\n", "output": "0.1884955592\n" }, { "input": "10 15 6\n", "output": "0.6939614954\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_k
Problem Statement There is an undirected graph with N vertices and M edges. Initially, the i -th edge connects Vertex a_i and Vertex b_i . Process Q queries. The i -th query is represented by t_i , x_i , and y_i as follows. If t_i=1 , add an edge connecting Vertex x_i and Vertex y_i . There are at most 10 queries of this kind in a single test case. If t_i=2 , delete the edge connecting Vertex x_i and Vertex y_i . If t_i=3 , print Yes if Vertex x_i and Vertex y_i belong to the same connected component, and No otherwise.
[ { "input": "5 3\n1 3\n2 3\n4 5\n4\n1 1 4\n3 1 5\n2 2 3\n3 1 5\n", "output": "Yes\nYes\n" }, { "input": "5 2\n1 3\n2 4\n2\n2 2 4\n2 1 3\n", "output": "\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_l
Problem Statement There are N paintings numbered 1, \dots, N . We are going to choose some of them to display in an exhibition. Takahashi the critic has decided to score the exhibition as follows: For i = 1, \dots, N , add A_i points if Painting i is exhibited. Additionally, for j = 1 \dots, M , add P_j points if all of the following conditions are satisfied: The number of exhibited paintings with indices strictly less than Q_j is congruent to L_j modulo 3 . The number of exhibited paintings with indices greater than or equal to Q_j is congruent to R_j modulo 3 . Print the maximum possible score of the exhibition.
[ { "input": "3 2\n1 2 3\n4 3 2 0\n5 2 0 1\n", "output": "8\n" }, { "input": "1 1\n1\n10 1 0 0\n", "output": "10\n" }, { "input": "4 1\n3 1 4 1\n5 3 1 1\n", "output": "12\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_m
Problem Statement There is a series of manga consisting of N books. The i -th ( 1 \leq i \leq N ) book is sold for A_i yen. These books are also sold in sets. There are M sets, the j -th ( 1 \leq j \leq M ) of which is sold for B_j yen and contains the L_j -th, (L_j + 1) -th, \ldots , R_j -th books of the series. At least how many yen does one have to pay to get at least one of each of the N books?
[ { "input": "5 3\n5 4 6 2 3\n4 1 2\n7 2 4\n14 2 5\n", "output": "14\n" }, { "input": "6 3\n3 1 4 1 5 9\n3 1 2\n12 4 6\n10 3 4\n", "output": "19\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_n
Problem Statement We have a grid with H horizontal rows and W vertical columns. The square at the i -th row from the top and j -th column from the left has a lowercase English character a_{i,j} written on it. Additionally, we have an empty string S . Process Q queries in the order given by the input, and print the resulting S after processing the Q queries. Each query is of one of the following two kinds. 1 p c :Append the character a_{p,W} to the tail of the string S . Then, set a_{p,1}=c,a_{p,2}=a_{p,1},a_{p,3}=a_{p,2},\dots,a_{p,W}=a_{p,W-1} simultaneously. 2 p c :Append the character a_{H,p} to the tail of the string S . Then, set a_{1,p}=c,a_{2,p}=a_{1,p},a_{3,p}=a_{2,p},\dots,a_{H,p}=a_{H-1,p} simultaneously.
[ { "input": "2 2 2\nab\ncd\n1 2 x\n2 1 y\n", "output": "dx\n" }, { "input": "3 4 8\nabcd\ndefg\nghij\n1 2 a\n1 2 b\n1 2 c\n1 2 d\n2 3 x\n2 3 y\n2 3 y\n2 3 y\n", "output": "gfedibcx\n" } ]
https://atcoder.jp/contests/past202209-open/tasks/past202209_o
Problem Statement There are two boxes A and B that contain balls with integers between 0 and 2^N-1 written on them. Box A contains A_i balls with the integer i (0 \leq i \lt 2^N) , and Box B contains B_i balls with the integer i (0 \leq i \lt 2^N) . All balls are distinguishable. Consider picking up one ball from each of Box A and Box B . Among the (number of balls in Box A ) \times (number of balls in Box B ) ways to do so, let f(x, y) be the number of ones that satisfy the following condition. Here we denote by \mathrm{popcount}(x) the number of 1 s in the binary notation of x . Let a and b be the integers written on the balls from A and B , respectively. Then, the bitwise OR of a and b is x , and \mathrm{popcount}(a) + \mathrm{popcount}(b) is y . You are given sequences X and Y of length Q each. Compute f(X_i, Y_i) modulo 998244353 for every i (1 \leq i \leq Q) .
[ { "input": "2 3\n3 1 4 1\n5 9 2 6\n1 1\n3 2\n2 0\n", "output": "32\n61\n0\n" }, { "input": "1 1\n0 0\n1 2\n1 1\n", "output": "0\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_a
問題文 N 頂点 M 辺からなる単純で連結な無向グラフがあります. 頂点には 1 から N までの番号がついており, i 番目の辺は頂点 A_i と頂点 B_i を結んでいます. (1,2,\cdots,N) の順列 P=(P_1,P_2,\cdots,P_N) であって,以下の条件を満たすものの個数を 998244353 で割った余りを求めてください. 頂点集合の(非空な)部分集合 S であって, S による誘導部分グラフが連結になるものを考える. この時, S に含まれる頂点 v のうち,番号が最大であるものは, P_v の値も最大である. つまり, \max\{v|v \in S\}=\argmax\{P_v|v \in S\} である. 誘導部分グラフとは S をグラフ G の頂点の部分集合とします. このとき, G の S による誘導部分グラフとは,頂点集合が S で,辺集合が「 G の辺であって両端が S に含まれるものすべて」であるようなグラフです.
[ { "input": "4 4\n1 2\n2 4\n4 1\n3 4\n", "output": "3\n" }, { "input": "10 10\n4 8\n1 3\n6 10\n6 7\n8 7\n1 5\n4 2\n5 2\n3 9\n9 10\n", "output": "126\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_b
問題文 長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. あなたは以下の 2 種類の操作を好きな順序で好きな回数 ( 0 回でもよい) 繰り返すことができます. 操作 1 : A の先頭の要素に 1 を足す.つまり, A_1:=A_1+1 とする. 操作 2 : A の先頭の要素を末尾に移動する.つまり, A:=(A_2,A_3,\cdots,A_N,A_1) とする. あなたの目標は, A を広義単調増加 ( A_1 \leq A_2 \leq \cdots \leq A_N ) にすることです. 目標達成のために必要な操作回数の最小値を求めてください.
[ { "input": "4\n2 4 1 3\n", "output": "3\n" }, { "input": "20\n786820955 250480341 710671230 946667801 19271059 404902145 251317818 22712439 520643153 344670307 274195604 561032101 140039457 543856068 521915711 857077284 499774361 419370025 744280521 249168130\n", "output": "3774454944\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_c
問題文 1 と 2 からなる長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. A を K 個の連続部分列に分割することを考えます. この時,各部分列について,その値の総和が 3 で割り切れないようにしたいです. このような分割が可能かどうか判定し,可能な場合は分割の方法を一つ示してください.
[ { "input": "4 2\n1 2 2 1\n", "output": "Yes\n1 3\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_d
問題文 整数 N が与えられます. 非負整数列 A=(A_1,A_2,\cdots,A_k) であって,以下の条件を満たすものが存在するか判定してください. また,存在するならば実際に一つ示してください. A の長さ k は 1 以上 100 以下である. A の各要素は 0 以上 2^{20}-1 以下の整数である. A の非空な(連続するとは限らない)部分列であって,その値のビット単位 \mathrm{AND} が 0 になるものを考える. そのような部分列の個数はちょうど N 個である. ただしここで,取り出す位置が異なる 2 つの部分列は,値が同じであったとしても異なるものとして扱う. ビット単位 \mathrm{AND} 演算とは 整数 A, B のビット単位 \mathrm{AND} 、 A\ \mathrm{AND}\ B は以下のように定義されます。 A\ \mathrm{AND}\ B を二進表記した際の 2^k ( k \geq 0 ) の位の数は、 A, B を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1 、そうでなければ 0 である。 例えば、 3\ \mathrm{AND}\ 5 = 1 となります (二進表記すると: 011\ \mathrm{AND}\ 101 = 001 )。 一般に k 個の整数 p_1, p_2, p_3, \dots, p_k のビット単位 \mathrm{AND} は (\dots ((p_1\ \mathrm{AND}\ p_2)\ \mathrm{AND}\ p_3)\ \mathrm{AND}\ \dots\ \mathrm{AND}\ p_k) と定義され、これは p_1, p_2, p_3, \dots p_k の順番によらないことが証明できます。
[ { "input": "3\n", "output": "3\n2 1 1\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_e
問題文 長さ 2^L の円周があります. 円周上のある点から距離 x 時計回りに進んだ点を,座標 x の点と呼ぶことにします. 円周上で N 個の寿司が動いています. i 番目の寿司は時刻 0 に座標 A_i にあり,時計回りに速度 V_i で動いています. また, i 番目の寿司の価値は W_i です. あなたはこれから非負 実数 t を選びます. そして,時刻 t に座標 0 に存在するすべての寿司を獲得します. あなたが獲得する寿司の価値の総和としてありうる最大値を求めてください.
[ { "input": "3 2\n3 1 1\n2 2 2\n1 1 3\n", "output": "5\n" }, { "input": "20 4\n12 10 946667801\n0 2 520643153\n5 2 543856068\n8 8 419370025\n11 5 910500853\n2 3 715892722\n15 8 459924868\n4 8 950300099\n7 2 504976377\n11 1 152036485\n15 4 361324668\n7 14 628902494\n12 12 69837030\n7 7 596982638\n1 10 222135106\n3 14 210989591\n13 6 935147464\n13 2 362117198\n11 4 909241708\n1 8 487330736\n", "output": "1705145758\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_f
問題文 1 から N までの番号のついた N 台のサーバーがあります. すぬけくんは,秘伝のレシピをサーバー 1 に保存しました. 他のサーバーにはレシピは保存されていません. これから N(N-1)/2 回,すぬけくんは以下の操作を行います. 相異なる 2 つのサーバーを選ぶ. ただし,選ぶサーバーの組は,今まで選んだことのない組でなければならない. なお,組 (x,y) は組 (y,x) と同一とみなす. 操作前の段階で少なくとも一方のサーバーがレシピを保存している場合,操作後には両方のサーバーにレシピが保存される. 操作を行う方法は, (N(N-1)/2)! 通りあります. このうち,以下の条件を満たす方法が何通りあるかを 998244353 で割った余りを求めてください. 各 i=2,3,\cdots,N について, A_i 回目の操作が終わった段階で,サーバー i にレシピが保存されている.
[ { "input": "3\n1 3\n", "output": "2\n" }, { "input": "3\n1 1\n", "output": "0\n" }, { "input": "4\n1 2 6\n", "output": "48\n" }, { "input": "13\n62 20 56 74 2 32 20 2 41 27 22 44\n", "output": "665691201\n" } ]
https://atcoder.jp/contests/jsc2022-final-open/tasks/jsc2022_final_g
問題文 整数 N が与えられます. 1 から N までの番号のついた N 頂点からなる無向グラフ G を考えます. 以下の条件をすべて満たすグラフ G の個数を 998244353 で割った余りを求めてください. G は多重辺や自己ループを含まない. G は連結である. G の頂点集合の分割 \{S_1,S_2,\cdots\} であって,以下の条件をみたすものが存在する. 各 S_i について, |S_i| \geq 2 である. 各 S_i について, S_i による誘導部分グラフは,連結な二部グラフである. 誘導部分グラフとは S をグラフ G の頂点の部分集合とします. このとき, G の S による誘導部分グラフとは,頂点集合が S で,辺集合が「 G の辺であって両端が S に含まれるものすべて」であるようなグラフです.
[ { "input": "2\n", "output": "1\n" }, { "input": "3\n", "output": "3\n" }, { "input": "4\n", "output": "38\n" }, { "input": "5\n", "output": "712\n" }, { "input": "12345\n", "output": "503682022\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_a
問題文 N 頂点 M 辺からなる単純で連結な無向グラフがあります. 頂点には 1 から N までの番号がついており, i 番目の辺は頂点 A_i と頂点 B_i を結んでいます. (1,2,\cdots,N) の順列 P=(P_1,P_2,\cdots,P_N) であって,以下の条件を満たすものの個数を 998244353 で割った余りを求めてください. 頂点集合の(非空な)部分集合 S であって, S による誘導部分グラフが連結になるものを考える. この時, S に含まれる頂点 v のうち,番号が最大であるものは, P_v の値も最大である. つまり, \max\{v|v \in S\}=\argmax\{P_v|v \in S\} である. 誘導部分グラフとは S をグラフ G の頂点の部分集合とします. このとき, G の S による誘導部分グラフとは,頂点集合が S で,辺集合が「 G の辺であって両端が S に含まれるものすべて」であるようなグラフです.
[ { "input": "4 4\n1 2\n2 4\n4 1\n3 4\n", "output": "3\n" }, { "input": "10 10\n4 8\n1 3\n6 10\n6 7\n8 7\n1 5\n4 2\n5 2\n3 9\n9 10\n", "output": "126\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_b
問題文 長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. あなたは以下の 2 種類の操作を好きな順序で好きな回数 ( 0 回でもよい) 繰り返すことができます. 操作 1 : A の先頭の要素に 1 を足す.つまり, A_1:=A_1+1 とする. 操作 2 : A の先頭の要素を末尾に移動する.つまり, A:=(A_2,A_3,\cdots,A_N,A_1) とする. あなたの目標は, A を広義単調増加 ( A_1 \leq A_2 \leq \cdots \leq A_N ) にすることです. 目標達成のために必要な操作回数の最小値を求めてください.
[ { "input": "4\n2 4 1 3\n", "output": "3\n" }, { "input": "20\n786820955 250480341 710671230 946667801 19271059 404902145 251317818 22712439 520643153 344670307 274195604 561032101 140039457 543856068 521915711 857077284 499774361 419370025 744280521 249168130\n", "output": "3774454944\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_c
問題文 1 と 2 からなる長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. A を K 個の連続部分列に分割することを考えます. この時,各部分列について,その値の総和が 3 で割り切れないようにしたいです. このような分割が可能かどうか判定し,可能な場合は分割の方法を一つ示してください.
[ { "input": "4 2\n1 2 2 1\n", "output": "Yes\n1 3\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_d
問題文 整数 N が与えられます. 非負整数列 A=(A_1,A_2,\cdots,A_k) であって,以下の条件を満たすものが存在するか判定してください. また,存在するならば実際に一つ示してください. A の長さ k は 1 以上 100 以下である. A の各要素は 0 以上 2^{20}-1 以下の整数である. A の非空な(連続するとは限らない)部分列であって,その値のビット単位 \mathrm{AND} が 0 になるものを考える. そのような部分列の個数はちょうど N 個である. ただしここで,取り出す位置が異なる 2 つの部分列は,値が同じであったとしても異なるものとして扱う. ビット単位 \mathrm{AND} 演算とは 整数 A, B のビット単位 \mathrm{AND} 、 A\ \mathrm{AND}\ B は以下のように定義されます。 A\ \mathrm{AND}\ B を二進表記した際の 2^k ( k \geq 0 ) の位の数は、 A, B を二進表記した際の 2^k の位の数のうち両方が 1 であれば 1 、そうでなければ 0 である。 例えば、 3\ \mathrm{AND}\ 5 = 1 となります (二進表記すると: 011\ \mathrm{AND}\ 101 = 001 )。 一般に k 個の整数 p_1, p_2, p_3, \dots, p_k のビット単位 \mathrm{AND} は (\dots ((p_1\ \mathrm{AND}\ p_2)\ \mathrm{AND}\ p_3)\ \mathrm{AND}\ \dots\ \mathrm{AND}\ p_k) と定義され、これは p_1, p_2, p_3, \dots p_k の順番によらないことが証明できます。
[ { "input": "3\n", "output": "3\n2 1 1\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_e
問題文 長さ 2^L の円周があります. 円周上のある点から距離 x 時計回りに進んだ点を,座標 x の点と呼ぶことにします. 円周上で N 個の寿司が動いています. i 番目の寿司は時刻 0 に座標 A_i にあり,時計回りに速度 V_i で動いています. また, i 番目の寿司の価値は W_i です. あなたはこれから非負 実数 t を選びます. そして,時刻 t に座標 0 に存在するすべての寿司を獲得します. あなたが獲得する寿司の価値の総和としてありうる最大値を求めてください.
[ { "input": "3 2\n3 1 1\n2 2 2\n1 1 3\n", "output": "5\n" }, { "input": "20 4\n12 10 946667801\n0 2 520643153\n5 2 543856068\n8 8 419370025\n11 5 910500853\n2 3 715892722\n15 8 459924868\n4 8 950300099\n7 2 504976377\n11 1 152036485\n15 4 361324668\n7 14 628902494\n12 12 69837030\n7 7 596982638\n1 10 222135106\n3 14 210989591\n13 6 935147464\n13 2 362117198\n11 4 909241708\n1 8 487330736\n", "output": "1705145758\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_f
問題文 1 から N までの番号のついた N 台のサーバーがあります. すぬけくんは,秘伝のレシピをサーバー 1 に保存しました. 他のサーバーにはレシピは保存されていません. これから N(N-1)/2 回,すぬけくんは以下の操作を行います. 相異なる 2 つのサーバーを選ぶ. ただし,選ぶサーバーの組は,今まで選んだことのない組でなければならない. なお,組 (x,y) は組 (y,x) と同一とみなす. 操作前の段階で少なくとも一方のサーバーがレシピを保存している場合,操作後には両方のサーバーにレシピが保存される. 操作を行う方法は, (N(N-1)/2)! 通りあります. このうち,以下の条件を満たす方法が何通りあるかを 998244353 で割った余りを求めてください. 各 i=2,3,\cdots,N について, A_i 回目の操作が終わった段階で,サーバー i にレシピが保存されている.
[ { "input": "3\n1 3\n", "output": "2\n" }, { "input": "3\n1 1\n", "output": "0\n" }, { "input": "4\n1 2 6\n", "output": "48\n" }, { "input": "13\n62 20 56 74 2 32 20 2 41 27 22 44\n", "output": "665691201\n" } ]
https://atcoder.jp/contests/jsc2022-final/tasks/jsc2022_final_g
問題文 整数 N が与えられます. 1 から N までの番号のついた N 頂点からなる無向グラフ G を考えます. 以下の条件をすべて満たすグラフ G の個数を 998244353 で割った余りを求めてください. G は多重辺や自己ループを含まない. G は連結である. G の頂点集合の分割 \{S_1,S_2,\cdots\} であって,以下の条件をみたすものが存在する. 各 S_i について, |S_i| \geq 2 である. 各 S_i について, S_i による誘導部分グラフは,連結な二部グラフである. 誘導部分グラフとは S をグラフ G の頂点の部分集合とします. このとき, G の S による誘導部分グラフとは,頂点集合が S で,辺集合が「 G の辺であって両端が S に含まれるものすべて」であるようなグラフです.
[ { "input": "2\n", "output": "1\n" }, { "input": "3\n", "output": "3\n" }, { "input": "4\n", "output": "38\n" }, { "input": "5\n", "output": "712\n" }, { "input": "12345\n", "output": "503682022\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_a
Problem Statement You are given an odd-length string S consisting of lowercase English letters. Print the central character of S . What is the central character? For an odd-length string T , its central character is the \frac{|T|+1}{2} -th character from the beginning, where |T| is the length of T .
[ { "input": "atcoder\n", "output": "o\n" }, { "input": "a\n", "output": "a\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_b
Problem Statement You are given an integer N between -10^{18} and 10^{18} (inclusive). Find an integer x between 0 and 998244353 - 1 (inclusive) that satisfies the following condition. It can be proved that such an integer is unique. N-x is a multiple of 998244353 .
[ { "input": "998244354\n", "output": "1\n" }, { "input": "-9982443534\n", "output": "998244349\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_c
Problem Statement Consider a two-dimensional coordinate plane, where the x -axis is oriented to the right, and the y -axis is oriented upward. In this plane, there is a quadrilateral without self-intersection. The coordinates of the four vertices are (A_x,A_y) , (B_x,B_y) , (C_x,C_y) , and (D_x,D_y) , in counter-clockwise order. Determine whether this quadrilateral is convex. Here, a quadrilateral is convex if and only if all four interior angles are less than 180 degrees.
[ { "input": "0 0\n1 0\n1 1\n0 1\n", "output": "Yes\n" }, { "input": "0 0\n1 1\n-1 0\n1 -1\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_d
Problem Statement Takahashi is trying to catch many Snuke. There are five pits at coordinates 0 , 1 , 2 , 3 , and 4 on a number line, connected to Snuke's nest. Now, N Snuke will appear from the pits. It is known that the i -th Snuke will appear from the pit at coordinate X_i at time T_i , and its size is A_i . Takahashi is at coordinate 0 at time 0 and can move on the line at a speed of at most 1 . He can catch a Snuke appearing from a pit if and only if he is at the coordinate of that pit exactly when it appears. The time it takes to catch a Snuke is negligible. Find the maximum sum of the sizes of Snuke that Takahashi can catch by moving optimally.
[ { "input": "3\n1 0 100\n3 3 10\n5 4 1\n", "output": "101\n" }, { "input": "3\n1 4 1\n2 4 1\n3 4 1\n", "output": "0\n" }, { "input": "10\n1 4 602436426\n2 1 623690081\n3 3 262703497\n4 4 628894325\n5 3 450968417\n6 1 161735902\n7 1 707723857\n8 2 802329211\n9 0 317063340\n10 2 125660016\n", "output": "2978279323\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_e
Problem Statement Let us play a game using a die. The game consists of at most N turns, each of which goes as follows. Throw a 6 -sided die that shows 1,\ldots,6 with equal probability, and let X be the number shown (each throw is independent of the others). If it is the N -th turn now, your score is X , and the game ends. Otherwise, choose whether to continue or end the game. If you end the game, your score is X , and there is no more turn. Find the expected value of your score when you play the game to maximize this expected value.
[ { "input": "1\n", "output": "3.5000000000\n" }, { "input": "2\n", "output": "4.2500000000\n" }, { "input": "10\n", "output": "5.6502176688\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_f
Problem Statement You are given a connected simple undirected graph G with N vertices numbered 1 to N and N edges. The i -th edge connects Vertex u_i and Vertex v_i bidirectionally. Answer the following Q queries. Determine whether there is a unique simple path from Vertex x_i to Vertex y_i (a simple path is a path without repetition of vertices).
[ { "input": "5\n1 2\n2 3\n1 3\n1 4\n2 5\n3\n1 2\n1 4\n1 5\n", "output": "No\nYes\nNo\n" }, { "input": "10\n3 5\n5 7\n4 8\n2 9\n1 2\n7 9\n1 6\n4 10\n2 5\n2 10\n10\n1 8\n6 9\n8 10\n6 8\n3 10\n3 9\n1 10\n5 8\n1 10\n7 8\n", "output": "Yes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_g
Problem Statement You are given integers R , G , B , and K . How many strings S consisting of R , G , and B satisfy all of the conditions below? Find the count modulo 998244353 . The number of occurrences of R , G , and B in S are R , G , and B , respectively. The number of occurrences of RG as (contiguous) substrings in S is K .
[ { "input": "2 1 1 1\n", "output": "6\n" }, { "input": "1000000 1000000 1000000 1000000\n", "output": "80957240\n" } ]
https://atcoder.jp/contests/abc266/tasks/abc266_h
Problem Statement Takahashi is trying to catch many Snuke. There are some pits in a two-dimensional coordinate plane, connected to Snuke's nest. Now, N Snuke will appear from the pits. It is known that the i -th Snuke will appear from the pit at coordinates (X_i,Y_i) at time T_i , and its size is A_i . Takahashi is at coordinates (0,0) at time 0 and can do the following two kinds of moves. Move at a speed of at most 1 in the x -direction (positive or negative). Move at a speed of at most 1 in the positive y -direction. Moving in the negative y -direction is not allowed. He can catch a Snuke appearing from a pit if and only if he is at the coordinates of that pit exactly when it appears. The time it takes to catch a Snuke is negligible. Find the maximum sum of the sizes of Snuke that Takahashi can catch by moving optimally.
[ { "input": "3\n1 0 0 100\n3 2 1 10\n5 3 1 1\n", "output": "101\n" }, { "input": "2\n100 0 1 1\n200 1 0 10\n", "output": "10\n" }, { "input": "10\n797829355 595605750 185676190 353195922\n913575467 388876063 395940406 533206504\n810900084 201398242 159760440 87027328\n889089200 220046203 85488350 325976483\n277429832 161055688 73308100 940778720\n927999455 429014248 477195779 174616807\n673419335 415891345 81019893 286986530\n989248231 147792453 417536200 219371588\n909664305 22150727 414107912 317441890\n988670052 140275628 468278658 67181740\n", "output": "1553741733\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_a
Problem Statement A fruit store sells apples. You may perform the following operations as many times as you want in any order: Buy one apple for X yen (the currency in Japan). Buy three apples for Y yen. How much yen do you need to pay to obtain exactly N apples?
[ { "input": "10 25 10\n", "output": "85\n" }, { "input": "10 40 10\n", "output": "100\n" }, { "input": "100 100 2\n", "output": "200\n" }, { "input": "100 100 100\n", "output": "3400\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_b
Problem Statement Takahashi is exploring a cave in a video game. The cave consists of N rooms arranged in a row. The rooms are numbered Room 1,2,\ldots,N from the entrance. Takahashi is initially in Room 1 , and the time limit is T . For each 1 \leq i \leq N-1 , he may consume a time of A_i to move from Room i to Room (i+1) . There is no other way to move between rooms. He cannot make a move that makes the time limit 0 or less. There are M bonus rooms in the cave. The i -th bonus room is Room X_i ; when he arrives at the room, the time limit increases by Y_i . Can Takahashi reach Room N ?
[ { "input": "4 1 10\n5 7 5\n2 10\n", "output": "Yes\n" }, { "input": "4 1 10\n10 7 5\n2 10\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_c
Problem Statement We have a grid with H horizontal rows and W vertical columns. (i, j) denotes the square at the i -th row from the top and j -th column from the left. (i,j) has a character G_{i,j} written on it. G_{i,j} is U , D , L , or R . You are initially at (1,1) . You repeat the following operation until you cannot make a move. Let (i,j) be the square you are currently at. If G_{i,j} is U and i \neq 1 , move to (i-1,j) . If G_{i,j} is D and i \neq H , move to (i+1,j) . If G_{i,j} is L and j \neq 1 , move to (i,j-1) . If G_{i,j} is R and j \neq W , move to (i,j+1) . Otherwise, you cannot make a move. Print the square you end up at when you cannot make a move. If you indefinitely repeat moving, print -1 instead.
[ { "input": "2 3\nRDU\nLRU\n", "output": "1 3\n" }, { "input": "2 3\nRRD\nULL\n", "output": "-1\n" }, { "input": "9 44\nRRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR\nRRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD\nDRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR\nDDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD\nRDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR\nRDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR\nRDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR\nRDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR\nRRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR\n", "output": "9 5\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_d
Problem Statement There is a sequence A=(A_0,\ldots,A_{N-1}) of length N . Determine if there exists a tuple of integers (x,y,z,w) that satisfies all of the following conditions: 0 \leq x < y < z < w \leq N A_x + A_{x+1} + \ldots + A_{y-1} = P A_y + A_{y+1} + \ldots + A_{z-1} = Q A_z + A_{z+1} + \ldots + A_{w-1} = R
[ { "input": "10 5 7 5\n1 3 2 2 2 3 1 4 3 2\n", "output": "Yes\n" }, { "input": "9 100 101 100\n31 41 59 26 53 58 97 93 23\n", "output": "No\n" }, { "input": "7 1 1 1\n1 1 1 1 1 1 1\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_e
Problem Statement Takahashi is at the origin of a two-dimensional plane. Takahashi will repeat teleporting N times. In each teleportation, he makes one of the following moves: Move from the current coordinates (x,y) to (x+A,y+B) Move from the current coordinates (x,y) to (x+C,y+D) Move from the current coordinates (x,y) to (x+E,y+F) There are obstacles on M points (X_1,Y_1),\ldots,(X_M,Y_M) on the plane; he cannot teleport to these coordinates. How many paths are there resulting from the N teleportations? Find the count modulo 998244353 .
[ { "input": "2 2\n1 1 1 2 1 3\n1 2\n2 2\n", "output": "5\n" }, { "input": "10 3\n-1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000\n-1000000000 -1000000000\n1000000000 1000000000\n-1000000000 1000000000\n", "output": "0\n" }, { "input": "300 0\n0 0 1 0 0 1\n", "output": "292172978\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_f
Problem Statement In an N -dimensional space, the Manhattan distance d(x,y) between two points x=(x_1, x_2, \dots, x_N) and y = (y_1, y_2, \dots, y_N) is defined by: \displaystyle d(x,y)=\sum_{i=1}^n \vert x_i - y_i \vert. A point x=(x_1, x_2, \dots, x_N) is said to be a lattice point if the components x_1, x_2, \dots, x_N are all integers. You are given lattice points p=(p_1, p_2, \dots, p_N) and q = (q_1, q_2, \dots, q_N) in an N -dimensional space. How many lattice points r satisfy d(p,r) \leq D and d(q,r) \leq D ? Find the count modulo 998244353 .
[ { "input": "1 5\n0\n3\n", "output": "8\n" }, { "input": "3 10\n2 6 5\n2 1 2\n", "output": "632\n" }, { "input": "10 100\n3 1 4 1 5 9 2 6 5 3\n2 7 1 8 2 8 1 8 2 8\n", "output": "145428186\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_g
Problem Statement You are given a sequence A=(A_1,\ldots,A_N) of length N . Each element is 0 , 1 , or 2 . Process Q queries in order. Each query is of one of the following kinds: 1 L R : print the inversion number of the sequence (A_L,\ldots,A_R) . 2 L R S T U : for each i such that L\leq i \leq R , if A_i is 0 , replace it with S ; if A_i is 1 , replace it with T ; if A_i is 2 , replace it with U . What is the inversion number? The inversion number of a sequence B = (B_1, \ldots, B_M) is the number of pairs of integers (i, j) (1 \leq i < j \leq M) such that B_i > B_j .
[ { "input": "5 3\n2 0 2 1 0\n1 2 5\n2 2 4 2 1 0\n1 2 5\n", "output": "3\n4\n" }, { "input": "3 3\n0 1 2\n1 1 1\n2 1 3 0 0 0\n1 1 3\n", "output": "0\n0\n" } ]
https://atcoder.jp/contests/abc265/tasks/abc265_h
Problem Statement There is a grid with H horizontal rows and W vertical columns, and (2 \times H) pieces. We consider the following game using them. Two players take alternating turns. The game progresses as follows. In the initial state, every row contains one piece of the first player facing left and one piece of the second player facing right. The two players alternately advance one of their pieces. The player who is first to be unable to make a move loses, and the other player wins. Let (i, j) denote the square at the i -th row from the top and j -th column from the left. The following moves are allowed: The first player can move a piece at (i,j) to (i,k) if k \lt j and none of (i,k),(i,k+1),\dots,(i,j-1) contains a piece of either player. The second player can move a piece at (i,j) to (i,k) if k \gt j and none of (i,j+1),(i,j+2),\dots,(i,k) contains a piece of either player. For example, in the figure below, on a 3\times 9 grid, the first player's pieces are at (1,7),(2,1),(3,4) , and the second player's pieces are at (1,3),(2,7),(3,5) . The first player can move the piece at (1,7) to (1,4),(1,5) , or (1,6) , and the piece at (3,4) to (3,1),(3,2) , or (3,3) . The first player cannot move the piece at (2,1) . Currently, there is no piece on the grid. There are \left\lbrace W(W-1)\right\rbrace^H ways to place one piece of the first player and one piece of the second player in each row, so that no two pieces are placed at the same square. How many of them satisfy the following condition? Find the count modulo 998244353 . When they play the game optimally from that initial state, the first player wins.
[ { "input": "1 3\n", "output": "2\n" }, { "input": "9 9\n", "output": "583962987\n" }, { "input": "265 30\n", "output": "366114675\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_a
Problem Statement There are N cards, numbered 1 to N . Card i has a positive integer A_i written on it. You can choose three of these cards and concatenate the integers written on them in any order you like to make a new integer. For example, if you choose cards with 1 , 23 , and 4 written on them, you can make integers such as 1234 and 4231 . Find the maximum integer you can make.
[ { "input": "5\n1 4 3 5 8\n", "output": "854\n" }, { "input": "8\n813 921 481 282 120 900 555 409\n", "output": "921900813\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_b
Problem Statement You are given a sequence of N non-negative integers: A=(A_1,A_2,\dots,A_N) . You may perform the following operation at most M times (possibly zero): choose an integer i such that 1 \le i \le N and add 1 to A_i . Then, you will choose K of the elements of A . Find the maximum possible value of the bitwise \mathrm{AND} of the elements you choose. What is bitwise {\rm AND} ? The bitwise {\rm AND} of non-negative integers A and B , A\ \mathrm{AND}\ B , is defined as follows: When A\ {\rm AND}\ B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if both of the digits in that place of A and B are 1 , and 0 otherwise. For example, 3\ {\rm AND}\ 5 = 1 . (In base two, 011\ {\rm AND}\ 101 = 001 .) Generally, the bitwise {\rm AND} of k non-negative integers p_1, p_2, p_3, \dots, p_k is defined as (\dots ((p_1\ \mathrm{AND}\ p_2)\ \mathrm{AND}\ p_3)\ \mathrm{AND}\ \dots\ \mathrm{AND}\ p_k) . We can prove that this value does not depend on the order of p_1, p_2, p_3, \dots, p_k . ​
[ { "input": "4 8 2\n1 2 4 8\n", "output": "10\n" }, { "input": "5 345 3\n111 192 421 390 229\n", "output": "461\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_c
Problem Statement How many sets S consisting of non-negative integers between 0 and 2^N-1 (inclusive) satisfy the following condition? Print the count modulo 998244353 . Every non-empty subset T of S satisfies at least one of the following: The number of elements in T is odd. The \mathrm{XOR} of the elements in T is not zero. What is \mathrm{XOR} ? The bitwise \mathrm{XOR} of non-negative integers A and B , A \oplus B , is defined as follows: When A \oplus B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if exactly one of the digits in that place of A and B is 1 , and 0 otherwise. For example, we have 3 \oplus 5 = 6 (in base two: 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) . We can prove that this value does not depend on the order of p_1, p_2, p_3, \dots, p_k .
[ { "input": "2\n", "output": "15\n" }, { "input": "146\n", "output": "743874490\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_d
Problem Statement A fantastic IS is an integer sequence of length N whose every element is between 1 and M (inclusive) that satisfies the following condition. For every integer i such that 1 \le i \le K , one of the following holds. A_{P_i} < X_i and A_{Q_i} < Y_i ; A_{P_i} = X_i and A_{Q_i} = Y_i ; A_{P_i} > X_i and A_{Q_i} > Y_i . Determine whether a fantastic IS exists. If it does, find the minimum possible sum of the elements in a fantastic IS.
[ { "input": "3 4 3\n3 1 1 2\n1 1 2 2\n3 4 1 4\n", "output": "6\n" }, { "input": "2 2 2\n1 1 2 2\n2 1 1 2\n", "output": "-1\n" }, { "input": "5 10 10\n4 1 2 7\n5 1 3 2\n2 9 4 4\n5 4 2 9\n2 9 1 9\n4 8 3 10\n5 7 1 5\n3 5 1 2\n3 8 2 10\n2 9 4 8\n", "output": "12\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_e
Problem Statement You are given a sequence of N positive integers: A=(A_1,A_2,\dots,A_N) . How many integer sequences B consisting of integers between 1 and N (inclusive) satisfy all of the following conditions? Print the count modulo 998244353 . For each integer i such that 1 \le i \le N , there are exactly A_i occurrences of i in B . For each integer i such that 1 \le i \le |B|-1 , it holds that |B_i - B_{i+1}|=1 .
[ { "input": "3\n2 3 1\n", "output": "6\n" }, { "input": "1\n200000\n", "output": "0\n" }, { "input": "6\n12100 31602 41387 41498 31863 12250\n", "output": "750337372\n" } ]
https://atcoder.jp/contests/arc146/tasks/arc146_f
Problem Statement The following process is carried out on a permutation P of (1,2,\dots,N) . We have N cards, numbered 1 to N . Card i has the integer P_i written on it. There are an integer X=1 and a boy called PCT, who initially has nothing. PCT does the following procedure for each i=1,2,\dots,N in this order. Get Card i . Then, repeat the following action as long as he has a card with X written on it: eat the card with X written on it, and then add 1 to X . If PCT currently has M or more cards, throw away all cards he has and terminate the process, without performing any more procedures. Here, let us define the score of the permutation P as follows: if the process is terminated by throwing away cards, the score of P is 0 ; if the process is carried out through the end without throwing away cards, the score of P is \prod_{i=1}^{N-1} ( the number of cards PCT has at the end of the i -th procedure ) . There are N! permutations P of (1,2,\dots,N) . Find the sum of the scores of all those permutations, modulo 998244353 .
[ { "input": "3 2\n", "output": "1\n" }, { "input": "3 3\n", "output": "5\n" }, { "input": "146146 146\n", "output": "103537573\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_a
Problem Statement You are given a permutation P=(P_1,P_2,\cdots,P_{2N}) of (1,2,\cdots,2N) . The following operation may be performed between 0 and N times (inclusive). Choose an integer x ( 1 \leq x \leq 2N-1 ). Swap the values of P_x and P_{x+1} . Present a sequence of operations that make P satisfy the following conditions. P_i<P_{i+1} for each i=1,3,5,\cdots,2N-1 ; P_i>P_{i+1} for each i=2,4,6,\cdots,2N-2 . It can be proved that such a sequence of operations always exists.
[ { "input": "2\n4 3 2 1\n", "output": "2\n1 3\n" }, { "input": "1\n1 2\n", "output": "0\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_b
Problem Statement You are given a permutation P=(P_1,P_2,\cdots,P_N) of (1,2,\cdots,N) . You may perform the following operation zero or more times. Choose an integer i ( 1 \leq i \leq N-1 ). Let v=\max(P_i,P_{i+1}) and replace the values of P_i and P_{i+1} with v . How many sequences are there that P can be after your operations? Find the count modulo 998244353 .
[ { "input": "3\n1 3 2\n", "output": "4\n" }, { "input": "4\n2 1 3 4\n", "output": "11\n" }, { "input": "10\n4 9 6 3 8 10 1 2 7 5\n", "output": "855\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_c
Problem Statement There are N vertices on a circumference. The vertices are numbered 1 to N in clockwise order, and Vertex i has an integer A_i written on it, where A_i is 1 , 2 , 3 , or 4 . Here, A contains each of 1 , 2 , 3 , and 4 at least once. Consider making a tree by adding N-1 edges connecting these N vertices. Here, the following conditions must be satisfied. If Vertices x and y are directly connected by an edge, |A_x-A_y|=1 . When the edges are drawn as segments, no two of them intersect except at an endpoint. For instance, the figure below shows a tree that satisfies the conditions: Determine whether it is possible to construct a tree that satisfies the conditions. Solve T test cases for each input file.
[ { "input": "3\n4\n1 2 3 4\n4\n1 3 4 2\n4\n1 4 2 3\n", "output": "Yes\nYes\nNo\n" }, { "input": "3\n8\n4 2 3 4 1 2 2 1\n8\n3 2 2 3 1 3 3 4\n8\n2 3 3 2 1 4 1 4\n", "output": "Yes\nYes\nNo\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_d
Problem Statement You are given integers A , B , and C . How many strings S consisting of A , B , and C satisfy all of the following conditions? Find the count modulo 998244353 . The number of occurrences of A , B , and C in S are A , B , and C , respectively. S contains none of ABC , BCA , and CAB as a (contiguous) substring.
[ { "input": "1 1 1\n", "output": "3\n" }, { "input": "2 2 2\n", "output": "42\n" }, { "input": "96 11 46\n", "output": "818015722\n" }, { "input": "125132 102271 152064\n", "output": "128086069\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_e
Problem Statement In this problem, a "permutation" always means a permutation of (1,2,\cdots,N) . For two permutations p and q , let us define the distance between them, d(p,q) , as follows. Consider making p equal q by repeatedly swapping two adjacent terms in p . Let d(p,q) be the minimum number of swaps required here. Additionally, for a permutation x , let us define another permutation f(x) as follows. Let y=(1,2,\cdots,N) . Consider permutations z such that d(x,z) \leq d(y,z) . Let f(x) be the lexicographically smallest of those permutations. For example, when x=(2,3,1) , the permutations z such that d(x,z) \leq d(y,z) are z=(2,1,3),(2,3,1),(3,1,2),(3,2,1) . The lexicographically smallest of them is (2,1,3) , so we have f(x)=(2,1,3) . You are given a permutation A=(A_1,A_2,\cdots,A_N) . Determine whether there is a permutation x such that f(x)=A . Solve T test cases for each input file. What is lexicographical order on sequences? The algorithm described here determines the lexicographical order between distinct sequences S and T . Below, let S_i denote the i -th element of S . Additionally, let S \lt T and S \gt T mean " S is lexicographical smaller than T " and " S is lexicographical larger than T ," respectively. Let L be the length of the shorter of S and T . For each i=1,2,\dots,L , let us check whether S_i and T_i are equal. If there is i such that S_i \neq T_i , let j be the smallest such i , and compare S_j and T_j . If S_j is smaller than T_j (as a number), we conclude S \lt T and exit; if S_j is larger than T_j , we conclude S \gt T and exit. If there is no i such that S_i \neq T_i , compare the lengths of S and T . If S is shorter than T , we conclude S \lt T and exit; if S is longer than T , we conclude S \gt T and exit.
[ { "input": "2\n2\n1 2\n2\n2 1\n", "output": "Yes\nYes\n" }, { "input": "6\n3\n1 2 3\n3\n1 3 2\n3\n2 1 3\n3\n2 3 1\n3\n3 1 2\n3\n3 2 1\n", "output": "Yes\nYes\nYes\nYes\nNo\nNo\n" }, { "input": "24\n4\n1 2 3 4\n4\n1 2 4 3\n4\n1 3 2 4\n4\n1 3 4 2\n4\n1 4 2 3\n4\n1 4 3 2\n4\n2 1 3 4\n4\n2 1 4 3\n4\n2 3 1 4\n4\n2 3 4 1\n4\n2 4 1 3\n4\n2 4 3 1\n4\n3 1 2 4\n4\n3 1 4 2\n4\n3 2 1 4\n4\n3 2 4 1\n4\n3 4 1 2\n4\n3 4 2 1\n4\n4 1 2 3\n4\n4 1 3 2\n4\n4 2 1 3\n4\n4 2 3 1\n4\n4 3 1 2\n4\n4 3 2 1\n", "output": "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\n" } ]
https://atcoder.jp/contests/agc058/tasks/agc058_f
Problem Statement For an undirected tree t , let us define a rational number f(t) as follows. Let n be the number of vertices in t . If n=1 : Let f(t)=1 . If n \geq 2 : For an edge e in t , we denote by t_x(e) and t_y(e) the two trees that result from deleting e from t (in arbitrary order). Let f(t)=(\sum_{e \in t} f(t_x(e)) \times f(t_y(e)))/n . You are given a tree T with N vertices numbered 1 to N . The i -th edge connects Vertex A_i and Vertex B_i . Find the value f(T) \text{mod }{998244353} . What is a rational number \text{mod }{998244353} ? Under the Constraints of this problem, when the sought rational number is represented as \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}, 0 \leq R < 998244353 . Find this R .
[ { "input": "2\n1 2\n", "output": "499122177\n" }, { "input": "3\n1 2\n2 3\n", "output": "332748118\n" }, { "input": "4\n1 2\n2 3\n3 4\n", "output": "103983787\n" }, { "input": "10\n4 5\n1 9\n6 1\n8 4\n5 9\n4 7\n3 10\n5 2\n4 3\n", "output": "462781191\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_a
Problem Statement Print the L -th through R -th characters of the string atcoder .
[ { "input": "3 6\n", "output": "code\n" }, { "input": "4 4\n", "output": "o\n" }, { "input": "1 7\n", "output": "atcoder\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_b
Problem Statement Print the color of the cell at the R -th row from the top and C -th column from the left in the following grid with 15 vertical rows and 15 horizontal columns.
[ { "input": "3 5\n", "output": "black\n" }, { "input": "4 5\n", "output": "white\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_c
Problem Statement You are given a matrix A with H_1 rows and W_1 columns, and a matrix B with H_2 rows and W_2 columns. For all integer pairs (i, j) such that 1 \leq i \leq H_1 and 1 \leq j \leq W_1 , the element at the i -th row and j -th column of matrix A is A_{i, j} . For all integer pairs (i, j) such that 1 \leq i \leq H_2 and 1 \leq j \leq W_2 , the element at the i -th row and j -th column of matrix B is B_{i, j} . You may perform the following operations on the matrix A any number of (possibly 0 ) times in any order: Choose an arbitrary row of A and remove it. Choose an arbitrary column of A and remove it. Determine if it is possible to make the matrix A equal the matrix B .
[ { "input": "4 5\n1 2 3 4 5\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n2 3\n6 8 9\n16 18 19\n", "output": "Yes\n" }, { "input": "3 3\n1 1 1\n1 1 1\n1 1 1\n1 1\n2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_d
Problem Statement You are given a string S that is a permutation of atcoder . On this string S , you will perform the following operation 0 or more times: Choose two adjacent characters of S and swap them. Find the minimum number of operations required to make S equal atcoder .
[ { "input": "catredo\n", "output": "8\n" }, { "input": "atcoder\n", "output": "0\n" }, { "input": "redocta\n", "output": "21\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_e
Problem Statement A country has N cities and M power plants, which we collectively call places. The places are numbered 1,2,\dots,N+M , among which Places 1,2,\dots,N are the cities and Places N+1,N+2,\dots,N+M are the power plants. This country has E power lines. Power Line i ( 1 \le i \le E ) connects Place U_i and Place V_i bidirectionally. A city is said to be electrified if one can reach at least one of the power plants from the city using some power lines. Now, Q events will happen. In the i -th ( 1 \le i \le Q ) event, Power Line X_i breaks, making it unusable. Once a power line breaks, it remains broken in the succeeding events. Find the number of electrified cities right after each events.
[ { "input": "5 5 10\n2 3\n4 10\n5 10\n6 9\n2 9\n4 8\n1 7\n3 6\n8 10\n1 8\n6\n3\n5\n8\n10\n2\n7\n", "output": "4\n4\n2\n2\n2\n1\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_f
Problem Statement We have a grid with H rows and W columns. Each square is painted either white or black. For each integer pair (i, j) such that 1 \leq i \leq H and 1 \leq j \leq W , the color of the square at the i -th row from the top and j -th column from the left (we simply denote this square by Square (i, j) ) is represented by A_{i, j} . Square (i, j) is white if A_{i, j} = 0 , and black if A_{i, j} = 1 . You may perform the following operations any number of (possibly 0 ) times in any order: Choose an integer i such that 1 \leq i \leq H , pay R_i yen (the currency in Japan), and invert the color of each square in the i -th row from the top in the grid. (White squares are painted black, and black squares are painted white.) Choose an integer j such that 1 \leq j \leq W , pay C_j yen, and invert the color of each square in the j -th column from the left in the grid. Print the minimum total cost to satisfy the following condition: There exists a path from Square (1, 1) to Square (H, W) that can be obtained by repeatedly moving down or to the right, such that all squares in the path (including Square (1, 1) and Square (H, W) ) have the same color. We can prove that it is always possible to satisfy the condition in a finite number of operations under the Constraints of this problem.
[ { "input": "3 4\n4 3 5\n2 6 7 4\n0100\n1011\n1010\n", "output": "9\n" }, { "input": "15 20\n29 27 79 27 30 4 93 89 44 88 70 75 96 3 78\n39 97 12 53 62 32 38 84 49 93 53 26 13 25 2 76 32 42 34 18\n01011100110000001111\n10101111100010011000\n11011000011010001010\n00010100011111010100\n11111001101010001011\n01111001100101011100\n10010000001110101110\n01001011100100101000\n11001000100101011000\n01110000111011100101\n00111110111110011111\n10101111111011101101\n11000011000111111001\n00011101011110001101\n01010000000001000000\n", "output": "125\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_g
Problem Statement In a string fair, they determine the beauty of a non-empty string S consisting of lowercase English letters. The beauty of string S equals the sum of N scores determined by N criteria. For i = 1, 2, \ldots, N , the score determined by the i -th criterion is "the number of occurrences of a string T_i (of length at most 3 given in the Input) in S as a consecutive subsequence" multiplied by P_i . Print the maximum possible beauty of a non-empty string S consisting of lowercase English letters. If it is possible to obtain infinitely large beauty, print Infinity instead. Here, the number of occurrences of a string V in a string U = U_1U_2\ldots U_{|U|} as a consecutive subsequence is defined to be the number of integers i such that 1 \leq i \leq |U|-|V|+1 and U_iU_{i+1}\ldots U_{i+|V|-1} = V .
[ { "input": "3\na -5\nab 10\nba -20\n", "output": "Infinity\n" }, { "input": "28\na -5\nab 10\nba -20\nbb -20\nbc -20\nbd -20\nbe -20\nbf -20\nbg -20\nbh -20\nbi -20\nbj -20\nbk -20\nbl -20\nbm -20\nbn -20\nbo -20\nbp -20\nbq -20\nbr -20\nbs -20\nbt -20\nbu -20\nbv -20\nbw -20\nbx -20\nby -20\nbz -20\n", "output": "5\n" }, { "input": "26\na -1\nb -1\nc -1\nd -1\ne -1\nf -1\ng -1\nh -1\ni -1\nj -1\nk -1\nl -1\nm -1\nn -1\no -1\np -1\nq -1\nr -1\ns -1\nt -1\nu -1\nv -1\nw -1\nx -1\ny -1\nz -1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc264/tasks/abc264_h
Problem Statement We have a rooted tree with N vertices numbered 1,2,\dots,N . The tree is rooted at Vertex 1 , and the parent of Vertex i \ge 2 is Vertex P_i(<i) . For each integer k=1,2,\dots,N , solve the following problem: There are 2^{k-1} ways to choose some of the vertices numbered between 1 and k so that Vertex 1 is chosen. How many of them satisfy the following condition: the subgraph induced by the set of chosen vertices forms a perfect binary tree (with 2^d-1 vertices for a positive integer d ) rooted at Vertex 1 ? Since the count may be enormous, print the count modulo 998244353 . What is an induced subgraph? Let S be a subset of the vertex set of a graph G . The subgraph H induced by this vertex set S is constructed as follows: Let the vertex set of H equal S . Then, we add edges to H as follows: For all vertex pairs (i, j) such that i,j \in S, i < j , if there is an edge connecting i and j in G , then add an edge connecting i and j to H . What is a perfect binary tree? A perfect binary tree is a rooted tree that satisfies all of the following conditions: Every vertex that is not a leaf has exactly 2 children. All leaves have the same distance from the root. Here, we regard a graph with 1 vertex and 0 edges as a perfect binary tree, too.
[ { "input": "10\n1 1 2 1 2 5 5 5 1\n", "output": "1\n1\n2\n2\n4\n4\n4\n5\n7\n10\n" }, { "input": "1\n\n", "output": "1\n" }, { "input": "10\n1 2 3 4 5 6 7 8 9\n", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" }, { "input": "13\n1 1 1 2 2 2 3 3 3 4 4 4\n", "output": "1\n1\n2\n4\n4\n4\n4\n4\n7\n13\n13\n19\n31\n" } ]
https://atcoder.jp/contests/ahc013/tasks/ahc013_a
Problem Statement Recruit Co. has a server room represented by a grid of N rows and N columns. Let (i, j) denote the cell in row i ( 0 \leq i \lt N ) from the top and column j ( 0 \leq j \lt N ) from the left of the server room. Each cell can contain up to one computer. There are K types of computers and 100 computers of each type in the server room. In the beginning, 100 \times K computers are already placed in 100 \times K cells, and the remaining N^2 - 100 \times K cells are empty. X-san can move computers around first, and then connect them with straight cables. Move and Connect is defined as follows: Move : Select one of the computers and move it to one of the adjacent cells, up, down, left, or right. You can move a computer multiple times. All of the following requirements should be met for each movement: You cannot move a computer to a cell where another computer is already located. You cannot move a computer outside the grid. Connect : Select two computers and connect them to each other with a straight cable. All of the following requirements should be met for each connection: The two computers you choose must be on the same row or in the same column, with no other computers in between. The cables do not intersect with any other cables. (Connecting multiple cables in one computer is allowed.) You cannot connect the same pair of computers twice. The two computers you choose must be different (one cannot connect a computer to itself with a single cable). Clusters are created by connecting computers. Computers C_i and C_j are considered to be "in the same cluster" if and only if computer C_j can be reached from computer C_i by a path over computers connected with cables. X-san wants to create good clusters and increase the processing performance of the server room as much as possible. The more pairs of computers of the same type in a cluster , the better the processing performance of the server room . On the other hand, the more pairs of computers of different types there are in the cluster , the lower the processing performance of the server room . The processing performance of a server room is calculated as follows: Denote the 100 \times K computers in the server room as C_0, C_1, \cdots, C_{100K-1} The processing performance of the server room is the sum of the following points summed over every integer pair (i, j) satisfying 0 \leq i \lt j \lt 100 \times K : 1 point if C_i and C_j belong to the same cluster and have the same type -1 point if C_i and C_j belong to the same cluster and are of different types 0 points if C_i and C_j do not belong to the same cluster Considering the physical burden of X-san, the number of move s and the number of connection s must be less than or equal to 100 \times K in total. Your challenge is to find a way to maximize the processing performance of the server room under all the restrictions we’ve placed above.
[]
https://atcoder.jp/contests/abc263/tasks/abc263_a
Problem Statement We have five cards with integers A , B , C , D , and E written on them, one on each card. This set of five cards is called a Full house if and only if the following condition is satisfied: the set has three cards with a same number written on them, and two cards with another same number written on them. Determine whether the set is a Full house.
[ { "input": "1 2 1 2 1\n", "output": "Yes\n" }, { "input": "12 12 11 1 2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_b
Problem Statement There are N people, called Person 1 , Person 2 , \ldots , Person N . The parent of Person i (2 \le i \le N) is Person P_i . Here, it is guaranteed that P_i < i . How many generations away from Person N is Person 1 ?
[ { "input": "3\n1 2\n", "output": "2\n" }, { "input": "10\n1 2 3 4 5 6 7 8 9\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_c
Problem Statement Print all strictly increasing integer sequences of length N where all elements are between 1 and M (inclusive), in lexicographically ascending order.
[ { "input": "2 3\n", "output": "1 2 \n1 3 \n2 3 \n" }, { "input": "3 5\n", "output": "1 2 3 \n1 2 4 \n1 2 5 \n1 3 4 \n1 3 5 \n1 4 5 \n2 3 4 \n2 3 5 \n2 4 5 \n3 4 5 \n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_d
Problem Statement You are given an integer sequence of length N : A=(A_1,A_2,\ldots,A_N) . You will perform the following consecutive operations just once: Choose an integer x (0\leq x \leq N) . If x is 0 , do nothing. If x is 1 or greater, replace each of A_1,A_2,\ldots,A_x with L . Choose an integer y (0\leq y \leq N) . If y is 0 , do nothing. If y is 1 or greater, replace each of A_{N},A_{N-1},\ldots,A_{N-y+1} with R . Print the minimum possible sum of the elements of A after the operations.
[ { "input": "5 4 3\n5 5 0 6 3\n", "output": "14\n" }, { "input": "4 10 10\n1 2 3 4\n", "output": "10\n" }, { "input": "10 -5 -3\n9 -6 10 -1 2 10 -1 7 -15 5\n", "output": "-58\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_e
Problem Statement There are N squares called Square 1 though Square N . You start on Square 1 . Each of the squares from Square 1 through Square N-1 has a die on it. The die on Square i is labeled with the integers from 0 through A_i , each occurring with equal probability. (Die rolls are independent of each other.) Until you reach Square N , you will repeat rolling a die on the square you are on. Here, if the die on Square x rolls the integer y , you go to Square x+y . Find the expected value, modulo 998244353 , of the number of times you roll a die.
[ { "input": "3\n1 1\n", "output": "4\n" }, { "input": "5\n3 1 2 1\n", "output": "332748122\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_f
Problem Statement 2^N people, numbered 1 to 2^N , will participate in a rock-paper-scissors tournament. The tournament proceeds as follows: The participants are arranged in a row in the order Person 1 , Person 2 , \ldots , Person 2^N from left to right. Let 2M be the current length of the row. For each i\ (1\leq i \leq M) , the (2i-1) -th and (2i) -th persons from the left play a game against each other. Then, the M losers are removed from the row. This process is repeated N times. Here, if Person i wins exactly j games, they receive C_{i,j} yen (Japanese currency). A person winning zero games receives nothing. Find the maximum possible total amount of money received by the 2^N people if the results of all games can be manipulated freely.
[ { "input": "2\n2 5\n6 5\n2 1\n7 9\n", "output": "15\n" }, { "input": "3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_g
Problem Statement There are integers with N different values written on a blackboard. The i -th value is A_i and is written B_i times. You may repeat the following operation as many times as possible: Choose two integers x and y written on the blackboard such that x+y is prime. Erase these two integers. Find the maximum number of times the operation can be performed.
[ { "input": "3\n3 3\n2 4\n6 2\n", "output": "3\n" }, { "input": "1\n1 4\n", "output": "2\n" } ]
https://atcoder.jp/contests/abc263/tasks/abc263_h
Problem Statement There are N lines in a two-dimensional plane. The i -th line is A_i x + B_i y + C_i = 0 . It is guaranteed that no two of the lines are parallel. In this plane, there are \frac{N(N-1)}{2} intersection points of two lines, including duplicates. Print the distance between the origin and the K -th nearest point to the origin among these \frac{N(N-1)}{2} points.
[ { "input": "3 2\n1 1 1\n2 1 -3\n1 -1 2\n", "output": "2.3570226040\n" }, { "input": "6 7\n5 1 9\n4 4 -3\n8 -1 2\n0 1 -8\n4 0 -4\n2 -3 0\n", "output": "4.0126752298\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_a
Problem Statement A sport event is held in June of every year whose remainder when divided by 4 is 2 . Suppose that it is now January of the year Y . In what year will this sport event be held next time?
[ { "input": "2022\n", "output": "2022\n" }, { "input": "2023\n", "output": "2026\n" }, { "input": "3000\n", "output": "3002\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_b
Problem Statement You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N , and the i -th (1 \leq i \leq M) edge connects Vertex U_i and Vertex V_i . Find the number of tuples of integers a, b, c that satisfy all of the following conditions: 1 \leq a \lt b \lt c \leq N There is an edge connecting Vertex a and Vertex b . There is an edge connecting Vertex b and Vertex c . There is an edge connecting Vertex c and Vertex a .
[ { "input": "5 6\n1 5\n4 5\n2 3\n1 4\n3 5\n2 5\n", "output": "2\n" }, { "input": "3 1\n1 2\n", "output": "0\n" }, { "input": "7 10\n1 7\n5 7\n2 5\n3 6\n4 7\n1 5\n2 4\n1 3\n1 6\n2 7\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_c
Problem Statement You are given a sequence a = (a_1, \dots, a_N) of length N consisting of integers between 1 and N . Find the number of pairs of integers i, j that satisfy all of the following conditions: 1 \leq i \lt j \leq N \min(a_i, a_j) = i \max(a_i, a_j) = j
[ { "input": "4\n1 3 2 4\n", "output": "2\n" }, { "input": "10\n5 8 2 2 1 6 7 2 9 10\n", "output": "8\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_d
Problem Statement You are given a sequence of positive integers A=(a_1,\ldots,a_N) of length N . There are (2^N-1) ways to choose one or more terms of A . How many of them have an integer-valued average? Find the count modulo 998244353 .
[ { "input": "3\n2 6 2\n", "output": "6\n" }, { "input": "5\n5 5 5 5 5\n", "output": "31\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_e
Problem Statement You are given a simple undirected graph with N vertices and M edges. The vertices are numbered 1, \dots, N , and the i -th (1 \leq i \leq M) edge connects Vertices U_i and V_i . There are 2^N ways to paint each vertex red or blue. Find the number, modulo 998244353 , of such ways that satisfy all of the following conditions: There are exactly K vertices painted red. There is an even number of edges connecting vertices painted in different colors.
[ { "input": "4 4 2\n1 2\n1 3\n2 3\n3 4\n", "output": "2\n" }, { "input": "10 10 3\n1 2\n2 4\n1 5\n3 6\n3 9\n4 10\n7 8\n9 10\n5 9\n3 4\n", "output": "64\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_f
Problem Statement You are given a sequence P = (p_1,p_2,\ldots,p_N) that contains 1,2,\ldots,N exactly once each. You may perform the following operations between 0 and K times in total in any order: Choose one term of P and remove it. Move the last term of P to the head. Find the lexicographically smallest P that can be obtained as a result of the operations.
[ { "input": "5 3\n4 5 2 3 1\n", "output": "1 2 3\n" }, { "input": "3 0\n3 2 1\n", "output": "3 2 1\n" }, { "input": "15 10\n12 10 7 2 8 11 9 1 6 14 3 15 13 5 4\n", "output": "1 3 4 7 2 8 11 9\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_g
Problem Statement There is an empty sequence X and an empty stack S . Also, you are given an integer sequence A=(a_1,\ldots,a_N) of length N . For each i=1,\ldots,N in this order, Takahashi will do one of the following operations: Move the integer a_i onto the top of S . Discard the integer a_i from A . Additionally, Takahashi may do the following operation whenever S is not empty: Move the integer at the top of S to the tail of X . The score of the final X is defined as follows. If X is non-decreasing, i.e. if x_i \leq x_{i+1} holds for all integer i(1 \leq i \lt |X|) , where X=(x_1,\ldots,x_{|X|}) , then the score is |X| (where |X| denotes the number of terms in X ). If X is not non-decreasing, then the score is 0 . Find the maximum possible score.
[ { "input": "7\n1 2 3 4 1 2 3\n", "output": "5\n" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1\n", "output": "10\n" } ]
https://atcoder.jp/contests/abc262/tasks/abc262_h
Problem Statement Find the number, modulo 998244353 , of integer sequences A = (A_1, \dots, A_N) of length N that satisfy all of the following conditions: 0 \leq A_i \leq M for all i such that 1 \leq i \leq N . The maximum value of A_{L_j}, \dots, A_{R_j} is X_j for all j such that 1 \leq j \leq Q .
[ { "input": "3 3 2\n1 2 2\n2 3 3\n", "output": "5\n" }, { "input": "1 1 1\n1 1 1\n", "output": "1\n" }, { "input": "6 40000000 3\n1 4 30000000\n2 6 20000000\n3 5 10000000\n", "output": "135282163\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_a
Problem Statement You are given a string S of length N consisting of A and B . You can repeat the following operation zero or more times: choose a pair of adjacent characters in S and replace them with AB . Determine whether S can be turned into a palindrome. What is a palindrome? A string T is a palindrome if and only if, for every integer i ( 1 \le i \le |T| ), the i -th character from the beginning and the i -th character from the end are the same, where |T| is the length of T .
[ { "input": "3\nBBA\n", "output": "Yes\n" }, { "input": "4\nABAB\n", "output": "No\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_b
Problem Statement The following game is called Game n : The game is played by Alice and Bob. Initially, there are n stones. The players alternate turns, making a move described below, with Alice going first. The player who becomes unable to make a move loses. In Alice's turn, she must remove a number of stones that is a positive multiple of A . In Bob's turn, he must remove a number of stones that is a positive multiple of B . In how many of Game 1 , Game 2 , ..., Game N does Alice win when both players play optimally?
[ { "input": "4 2 1\n", "output": "2\n" }, { "input": "27182818284 59045 23356\n", "output": "10752495144\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_c
Problem Statement The score of a permutation P=(P_1,P_2,\ldots,P_{2N}) of (1,2,\ldots,2N) is defined as follows: Consider dividing P into two (not necessarily contiguous) subsequences A = (A_1,A_2,\ldots,A_N) and B = (B_1,B_2,\ldots,B_N) . The score of P is the maximum possible value of \displaystyle\sum_{i=1}^{N}A_i B_i in such a division. Let M be the maximum among the scores of all permutations of (1,2,\ldots,2N) . Find the number, modulo 998244353 , of permutations of (1,2,\ldots,2N) with the score of M .
[ { "input": "2\n", "output": "16\n" }, { "input": "10000\n", "output": "391163238\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_d
Problem Statement Construct a set S of integers satisfying all of the conditions below. It can be proved that at least one such set S exists under the Constraints of this problem. S has exactly N elements. The element of S are distinct integers between -10^7 and 10^7 (inclusive). \displaystyle \sum _{s \in S} s = M . y-x\neq z-y for every triple x,y,z (x < y < z) of distinct elements in S .
[ { "input": "3 9\n", "output": "1 2 6\n" }, { "input": "5 -15\n", "output": "-15 -5 0 2 3\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_e
Problem Statement You are given two sequences, each of length N , consisting of non-negative integers: A=(A_1,A_2,\ldots,A_{N}) and B=(B_1,B_2,\ldots,B_{N}) . Determine whether it is possible to make A equal to B by performing the operation below at most 70000 times. If it is possible, present a specific sequence of operations that achieves it. Choose an integer K\ (1\le K \le N) . For every integer i\ (2\leq i \leq K) , simultaneously replace the value of A_i with A_{i-1} \oplus A_i . Here, \oplus denotes bitwise \mathrm{XOR} . 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 base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if exactly one of the digits in that place of A and B are 1 , and 0 otherwise. For example, 3\oplus 5 = 6 (in base two: 011\oplus 101 = 110 ).
[ { "input": "3\n1 2 0\n1 2 3\n", "output": "Yes\n2\n2 3\n" }, { "input": "2\n10 100\n1 0\n", "output": "No\n" }, { "input": "2\n1152921504606846975 0\n1152921504606846975 0\n", "output": "Yes\n0\n\n" } ]
https://atcoder.jp/contests/arc145/tasks/arc145_f
Problem Statement Find the number, modulo 998244353 , of non-decreasing sequences A=(A_1,A_2,\ldots,A_N) of length N consisting of integers between 0 and M (inclusive) that satisfy the following, for each K=0,1,\ldots,\mathrm{MOD}-1 : the sum of the elements in A is congruent to K modulo \mathrm{MOD} . What is a non-decreasing sequence? A sequence B is non-decreasing if and only if B_i \leq B_{i+1} for every integer ( 1 \le i \le |B| - 1 ), where |B| is the length of B .
[ { "input": "2 2 4\n", "output": "2 1 2 1\n" }, { "input": "3 45 3\n", "output": "5776 5760 5760\n" }, { "input": "1000000 1000000 6\n", "output": "340418986 783857865 191848859 783857865 340418986 635287738\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_a
Problem Statement We have a number line. Takahashi painted some parts of this line, as follows: First, he painted the part from X=L_1 to X=R_1 red. Next, he painted the part from X=L_2 to X=R_2 blue. Find the length of the part of the line painted both red and blue.
[ { "input": "0 3 1 5\n", "output": "2\n" }, { "input": "0 1 4 5\n", "output": "0\n" }, { "input": "0 3 3 7\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_b
Problem Statement N players played a round-robin tournament. You are given an N -by- N table A containing the results of the matches. Let A_{i,j} denote the element at the i -th row and j -th column of A . A_{i,j} is - if i=j , and W , L , or D otherwise. A_{i,j} is W if Player i beat Player j , L if Player i lost to Player j , and D if Player i drew with Player j . Determine whether the given table is contradictory. The table is said to be contradictory when some of the following holds: There is a pair (i,j) such that Player i beat Player j , but Player j did not lose to Player i ; There is a pair (i,j) such that Player i lost to Player j , but Player j did not beat Player i ; There is a pair (i,j) such that Player i drew with Player j , but Player j did not draw with Player i .
[ { "input": "4\n-WWW\nL-DD\nLD-W\nLDW-\n", "output": "incorrect\n" }, { "input": "2\n-D\nD-\n", "output": "correct\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_c
Problem Statement For two strings A and B , let A+B denote the concatenation of A and B in this order. You are given N strings S_1,\ldots,S_N . Modify and print them as follows, in the order i=1, \ldots, N : if none of S_1,\ldots,S_{i-1} is equal to S_i , print S_i ; if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i , print S_i+ ( +X+ ) , treating X as a string.
[ { "input": "5\nnewfile\nnewfile\nnewfolder\nnewfile\nnewfolder\n", "output": "newfile\nnewfile(1)\nnewfolder\nnewfile(2)\nnewfolder(1)\n" }, { "input": "11\na\na\na\na\na\na\na\na\na\na\na\n", "output": "a\na(1)\na(2)\na(3)\na(4)\na(5)\na(6)\na(7)\na(8)\na(9)\na(10)\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_d
Problem Statement Takahashi will toss a coin N times. He also has a counter, which initially shows 0 . Depending on the result of the i -th coin toss, the following happens: If it heads: Takahashi increases the counter's value by 1 and receives X_i yen (Japanese currency). If it tails: he resets the counter's value to 0 , without receiving money. Additionally, there are M kinds of streak bonuses. The i -th kind of streak bonus awards Y_i yen each time the counter shows C_i . Find the maximum amount of money that Takahashi can receive.
[ { "input": "6 3\n2 7 1 8 2 8\n2 10\n3 1\n5 5\n", "output": "48\n" }, { "input": "3 2\n1000000000 1000000000 1000000000\n1 1000000000\n3 1000000000\n", "output": "5000000000\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_e
Problem Statement We have a variable X and N kinds of operations that change the value of X . Operation i is represented as a pair of integers (T_i,A_i) , and is the following operation: if T_i=1 , it replaces the value of X with X\ {\rm and}\ A_i ; if T_i=2 , it replaces the value of X with X\ {\rm or}\ A_i ; if T_i=3 , it replaces the value of X with X\ {\rm xor}\ A_i . Initialize X with the value of C and execute the following procedures in order: Perform Operation 1 , and then print the resulting value of X . Next, perform Operation 1, 2 in this order, and then print the value of X . Next, perform Operation 1, 2, 3 in this order, and then print the value of X . \vdots Next, perform Operation 1, 2, \ldots, N in this order, and then print the value of X . What are {\rm and}, {\rm or}, {\rm xor} ? The {\rm and}, {\rm or}, {\rm xor} of non-negative integers A and B are defined as follows: When A\ {\rm and}\ B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if both of the digits in that place of A and B are 1 , and 0 otherwise. When A\ {\rm or}\ B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if at least one of the digits in that place of A and B is 1 , and 0 otherwise. When A\ {\rm xor}\ B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if exactly one of the digits in that place of A and B is 1 , and 0 otherwise. For example, 3\ {\rm and}\ 5 = 1 , 3\ {\rm or}\ 5 = 7 , and 3\ {\rm xor}\ 5 = 6 .
[ { "input": "3 10\n3 3\n2 5\n1 12\n", "output": "9\n15\n12\n" }, { "input": "9 12\n1 1\n2 2\n3 3\n1 4\n2 5\n3 6\n1 7\n2 8\n3 9\n", "output": "0\n2\n1\n0\n5\n3\n3\n11\n2\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_f
Problem Statement There are N balls arranged from left to right. The color of the i -th ball from the left is Color C_i , and an integer X_i is written on it. Takahashi wants to rearrange the balls so that the integers written on the balls are non-decreasing from left to right. In other words, his objective is to reach a situation where, for every 1\leq i\leq N-1 , the number written on the (i+1) -th ball from the left is greater than or equal to the number written on the i -th ball from the left. For this, Takahashi can repeat the following operation any number of times (possibly zero): Choose an integer i such that 1\leq i\leq N-1 . If the colors of the i -th and (i+1) -th balls from the left are different, pay a cost of 1 . (No cost is incurred if the colors are the same). Swap the i -th and (i+1) -th balls from the left. Find the minimum total cost Takahashi needs to pay to achieve his objective.
[ { "input": "5\n1 5 2 2 1\n3 2 1 2 1\n", "output": "6\n" }, { "input": "3\n1 1 1\n3 2 1\n", "output": "0\n" }, { "input": "3\n3 1 2\n1 1 2\n", "output": "0\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_g
Problem Statement You are given two strings S and T consisting of lowercase English letters. Takahashi starts with the string S . He can perform K kinds of operations any number of times in any order. The i -th operation is the following: Pay a cost of 1 . Then, if the current string contains the character C_i , choose one of its occurrences and replace it with the string A_i . Otherwise, do nothing. Find the minimum total cost needed to make the string equal T . If it is impossible to do so, print -1 .
[ { "input": "ab\ncbca\n3\na b\nb ca\na efg\n", "output": "4\n" }, { "input": "a\naaaaa\n2\na aa\na aaa\n", "output": "2\n" }, { "input": "a\nz\n1\na abc\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc261/tasks/abc261_h
Problem Statement We have a directed graph with N vertices and M edges. Edge i is directed from Vertex A_i to B_i and has a weight of C_i . Initially, there is a piece on Vertex v . Takahashi and Aoki will play a game where they alternate turns moving the piece as follows: If there is no edge that goes from the vertex on which the piece is placed, end the game. If there are edges that go from the vertex on which the piece is placed, choose one of those edges and move the piece along that edge. Takahashi goes first. Takahashi tries to minimize the total weight of the edges traversed by the piece, and Aoki tries to maximize it. More formally, their objectives are as follows. Takahashi gives the first priority to ending the game in a finite number of moves. If this is possible, he tries to minimize the total weight of the edges traversed by the piece. Aoki gives the first priority to preventing the game from ending in a finite number of moves. If this is impossible, he tries to maximize the total weight of the edges traversed by the piece. (If the piece traverses the same edge multiple times, the weight is added that number of times.) Determine whether the game ends in a finite number of moves when both players play optimally. If it ends, find the total weight of the edges traversed by the piece.
[ { "input": "7 6 1\n1 2 1\n1 3 10\n2 4 100\n2 5 102\n3 6 20\n3 7 30\n", "output": "40\n" }, { "input": "3 6 3\n1 2 1\n2 1 2\n2 3 3\n3 2 4\n3 1 5\n1 3 6\n", "output": "INFINITY\n" }, { "input": "4 4 1\n1 2 1\n2 3 1\n3 1 1\n2 4 1\n", "output": "5\n" } ]
https://atcoder.jp/contests/abc260/tasks/abc260_a
Problem Statement You are given a string S of length 3 . Print a character that occurs only once in S . If there is no such character, print -1 instead.
[ { "input": "pop\n", "output": "o\n" }, { "input": "abc\n", "output": "a\n" }, { "input": "xxx\n", "output": "-1\n" } ]
https://atcoder.jp/contests/abc260/tasks/abc260_b
Problem Statement N examinees took an entrance exam. The examinee numbered i scored A_i points in math and B_i points in English. The admissions are determined as follows. X examinees with the highest math scores are admitted. Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted. Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted. Those examinees who are not admitted yet are rejected. Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output. Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.
[ { "input": "6 1 0 2\n80 60 80 60 70 70\n40 20 50 90 90 80\n", "output": "1\n4\n5\n" }, { "input": "5 2 1 2\n0 100 0 100 0\n0 0 100 100 0\n", "output": "1\n2\n3\n4\n5\n" }, { "input": "15 4 3 2\n30 65 20 95 100 45 70 85 20 35 95 50 40 15 85\n0 25 45 35 65 70 80 90 40 55 20 20 45 75 100\n", "output": "2\n4\n5\n6\n7\n8\n11\n14\n15\n" } ]
https://atcoder.jp/contests/abc260/tasks/abc260_c
Problem Statement Takahashi has a red jewel of level N . (He has no other jewels.) Takahashi can do the following operations any number of times. Convert a red jewel of level n ( n is at least 2 ) into "a red jewel of level (n-1) and X blue jewels of level n ". Convert a blue jewel of level n ( n is at least 2 ) into "a red jewel of level (n-1) and Y blue jewels of level (n-1) ". Takahashi wants as many blue jewels of level 1 as possible. At most, how many blue jewels of level 1 can he obtain by the operations?
[ { "input": "2 3 4\n", "output": "12\n" }, { "input": "1 5 5\n", "output": "0\n" }, { "input": "10 5 5\n", "output": "3942349900\n" } ]
https://atcoder.jp/contests/abc260/tasks/abc260_d
Problem Statement There is a deck consisting of N face-down cards with an integer from 1 through N written on them. The integer on the i -th card from the top is P_i . Using this deck, you will perform N moves, each consisting of the following steps: Draw the topmost card from the deck. Let X be the integer written on it. Stack the drawn card, face up, onto the card with the smallest integer among the face-up topmost cards on the table with an integer greater than or equal to X written on them. If there is no such card on the table, put the drawn card on the table, face up, without stacking it onto any card. Then, if there is a pile consisting of K face-up cards on the table, eat all those cards. The eaten cards all disappear from the table. For each card, find which of the N moves eats it. If the card is not eaten until the end, report that fact.
[ { "input": "5 2\n3 5 2 1 4\n", "output": "4\n3\n3\n-1\n4\n" }, { "input": "5 1\n1 2 3 4 5\n", "output": "1\n2\n3\n4\n5\n" }, { "input": "15 3\n3 14 15 9 2 6 5 13 1 7 10 11 8 12 4\n", "output": "9\n9\n9\n15\n15\n6\n-1\n-1\n6\n-1\n-1\n-1\n-1\n6\n15\n" } ]