url
stringlengths
49
92
description
stringlengths
22
4.78k
cases
listlengths
0
6
https://atcoder.jp/contests/abc297/tasks/abc297_d
Problem Statement You are given positive integers A and B . You will repeat the following operation until A=B : compare A and B to perform one of the following two: if A > B , replace A with A-B ; if A < B , replace B with B-A . How many times will you repeat it until A=B ? It is guaranteed that a finite repetition ma...
[ { "input": "3 8\n", "output": "4\n" }, { "input": "1234567890 1234567890\n", "output": "0\n" }, { "input": "1597 987\n", "output": "15\n" } ]
https://atcoder.jp/contests/abc297/tasks/abc297_e
Problem Statement In AtCoder Kingdom, N kinds of takoyaki s (ball-shaped Japanese food) are sold. A takoyaki of the i -th kind is sold for A_i yen. Takahashi will buy at least one takoyaki in total. He is allowed to buy multiple takoyakis of the same kind. Find the K -th lowest price that Takahashi may pay. Here, if...
[ { "input": "4 6\n20 25 30 100\n", "output": "50\n" }, { "input": "2 10\n2 1\n", "output": "10\n" }, { "input": "10 200000\n955277671 764071525 871653439 819642859 703677532 515827892 127889502 881462887 330802980 503797872\n", "output": "5705443819\n" } ]
https://atcoder.jp/contests/abc297/tasks/abc297_f
Problem Statement We have a grid with H rows and W columns. We choose K cells in this grid uniformly at random. The score is the number of cells in the minimum rectangle (whose edges are parallel to the axes of the grid) that contains all of the chosen cells. Find the expected score modulo 998244353 . What is rational...
[ { "input": "2 2 2\n", "output": "665496238\n" }, { "input": "10 10 1\n", "output": "1\n" }, { "input": "314 159 2653\n", "output": "639716353\n" } ]
https://atcoder.jp/contests/abc297/tasks/abc297_g
Problem Statement There are N piles of stones. Initially, the i -th pile contains A_i stones. With these piles, Taro the First and Jiro the Second play a game against each other. Taro the First and Jiro the Second make the following move alternately, with Taro the First going first: Choose a pile of stones, and remov...
[ { "input": "3 1 2\n2 3 3\n", "output": "First\n" }, { "input": "5 1 1\n3 1 4 1 5\n", "output": "Second\n" }, { "input": "7 3 14\n10 20 30 40 50 60 70\n", "output": "First\n" } ]
https://atcoder.jp/contests/abc297/tasks/abc297_h
Problem Statement A positive-integer sequence is said to be splendid if no two adjacent elements are equal. Find the sum, modulo 998244353 , of the lengths of all splendid sequences whose elements have a sum of N .
[ { "input": "4\n", "output": "8\n" }, { "input": "297\n", "output": "475867236\n" }, { "input": "123456\n", "output": "771773807\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_a
Problem Statement You are given an N -by- N matrix A=(a_{i,j}) , where a_{i,j} \in \{0,1\} . We have the following directed graph. The graph has NK vertices numbered 1,2,\ldots,NK . The edges correspond to the NK -by- NK matrix X=(x_{i,j}) obtained by arranging K^2 copies of A in K rows and K columns (see Sample Input/...
[ { "input": "3 2\n1 1 1\n1 1 0\n0 1 0\n4\n1 2\n1 4\n1 6\n6 3\n", "output": "1\n1\n1\n3\n" }, { "input": "4 1000000000\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n1\n1 4000000000\n", "output": "-1\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_b
Problem Statement We have variables a and b . Initially, a=A and b=B . Takahashi will repeat the following operation while both a and b are greater than or equal to 1 . Let g be the greatest common divisor of a and b , and replace a and b with a-g and b-g , respectively. How many times will he perform the operation?
[ { "input": "15 9\n", "output": "2\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "12345678910 10987654321\n", "output": "36135\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_c
Problem Statement You are given a sequence of positive integers: A=(a_1,\ldots,a_N) . Determine whether it is possible to make all elements of A equal by repeating the following operation between 0 and 10^4 times, inclusive. If it is possible, show one way to do so. Choose a permutation (p_1,\ldots,p_N) of (1,\ldots,N)...
[ { "input": "2\n15 9\n", "output": "Yes\n8\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n" }, { "input": "5\n1 2 3 10 10\n", "output": "No\n" }, { "input": "4\n1 1 1 1\n", "output": "Yes\n0\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_d
Problem Statement We have a sequence X , which is initially empty. Takahashi has performed the following operation for i=1,2,\ldots,N in this order. Append l_i,l_i+1,\ldots,r_i in this order to the end of X . Find the greatest length of a strictly increasing subsequence of the final X .
[ { "input": "4\n1 1\n2 4\n10 11\n7 10\n", "output": "8\n" }, { "input": "4\n1 1\n1 1\n1 1\n1 1\n", "output": "1\n" }, { "input": "1\n1 1000000000\n", "output": "1000000000\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_e
Problem Statement You are given a positive integer N , and M pairs of positive integers: (a_0,b_0),\ldots,(a_{M-1},b_{M-1}) (note that a_i and b_i start with index 0 ). We have the following sequence of non-negative integers X=(x_1,\ldots,x_N) . x_i is determined as follows. Let l=1 , r=N , and t=0 . Let m=\left \lfloo...
[ { "input": "5 1\n1 1\n3\n1 2\n2 4\n3 5\n", "output": "1\n3\n2\n" }, { "input": "1000000000000000 2\n15 9\n9 15\n3\n100 10000\n5000 385723875\n150 17095708\n", "output": "19792\n771437738\n34191100\n" } ]
https://atcoder.jp/contests/arc159/tasks/arc159_f
Problem Statement A sequence X is called good when the following holds. X can be emptied by repeating the following operation zero or more times. Delete two adjacent elements x_i and x_{i+1} of X such that x_i \neq x_{i+1} . You are given a sequence with 2N elements: A=(a_1,\ldots,a_{2N}) . Among the 2^{2N-1} ways to d...
[ { "input": "3\n1 1 2 3 4 5\n", "output": "2\n" }, { "input": "1\n1 2\n", "output": "1\n" }, { "input": "1\n1 1\n", "output": "0\n" }, { "input": "12\n4 2 17 12 18 15 17 4 22 6 9 20 21 16 23 16 13 2 20 15 16 3 7 15\n", "output": "2048\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_a
Problem Statement There is a row of N people. They are described by a string S of length N . The i -th person from the front is male if the i -th character of S is M , and female if it is F . Determine whether the men and women are alternating. It is said that the men and women are alternating if and only if there is n...
[ { "input": "6\nMFMFMF\n", "output": "Yes\n" }, { "input": "9\nFMFMMFMFM\n", "output": "No\n" }, { "input": "1\nF\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_b
Problem Statement Locate a piece on a chessboard. We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2 -character name determined as follows. The first character of the name of a square in the 1 -st column from the left is a . Similarly, the first character of the name of a square in the 2 -...
[ { "input": "........\n........\n........\n........\n........\n........\n........\n*.......\n", "output": "a1\n" }, { "input": "........\n........\n........\n........\n........\n.*......\n........\n........\n", "output": "b3\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_c
Problem Statement You are given a sequence of N numbers: A=(A_1,\ldots,A_N) . Determine whether there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X .
[ { "input": "6 5\n3 1 4 1 5 9\n", "output": "Yes\n" }, { "input": "6 -4\n-2 -7 -1 -8 -2 -8\n", "output": "No\n" }, { "input": "2 0\n141421356 17320508\n", "output": "Yes\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_d
Problem Statement You are given positive integers N and M . Find the smallest positive integer X that satisfies both of the conditions below, or print -1 if there is no such integer. X can be represented as the product of two integers a and b between 1 and N , inclusive. Here, a and b may be the same. X is at least M .
[ { "input": "5 7\n", "output": "8\n" }, { "input": "2 5\n", "output": "-1\n" }, { "input": "100000 10000000000\n", "output": "10000000000\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_e
Problem Statement You are given a sequence of N numbers: A=(A_1,A_2,\ldots,A_N) . Here, each A_i (1\leq i\leq N) satisfies 1\leq A_i \leq N . Takahashi and Aoki will play N rounds of a game. For each i=1,2,\ldots,N , the i -th game will be played as follows. Aoki specifies a positive integer K_i . After knowing K_i Aok...
[ { "input": "3\n2 2 3\n", "output": "2\n" }, { "input": "2\n2 1\n", "output": "2\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_f
Problem Statement You are given two sequences of N numbers: A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N) . Takahashi can repeat the following operation any number of times (possibly zero). Choose three pairwise distinct integers i , j , and k between 1 and N . Swap the i -th and j -th elements of A , and swap the ...
[ { "input": "3\n1 2 1\n1 1 2\n", "output": "Yes\n" }, { "input": "3\n1 2 2\n1 1 2\n", "output": "No\n" }, { "input": "5\n1 2 3 2 1\n3 2 2 1 1\n", "output": "Yes\n" }, { "input": "8\n1 2 3 4 5 6 7 8\n7 8 5 6 4 3 1 2\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_g
Problem Statement There is a convex N -gon S in the two-dimensional coordinate plane where the positive x -axis points to the right and the positive y -axis points upward. The vertices of S have the coordinates (X_1,Y_1),\ldots,(X_N,Y_N) in counter-clockwise order. For each of Q points (A_i,B_i) , answer the following ...
[ { "input": "4\n0 4\n-2 2\n-1 0\n3 1\n3\n-1 3\n0 2\n2 0\n", "output": "ON\nIN\nOUT\n" }, { "input": "3\n0 0\n1 0\n0 1\n3\n0 0\n1 0\n0 1\n", "output": "ON\nON\nON\n" } ]
https://atcoder.jp/contests/abc296/tasks/abc296_h
Problem Statement We have a grid with N rows and M columns, where each square is painted black or white. Here, at least one square is painted black. The initial state of the grid is given as N strings S_1,S_2,\ldots,S_N of length M . The square at the i -th row from the top and j -th column from the left is painted bl...
[ { "input": "3 5\n...#.\n.#...\n....#\n", "output": "3\n" }, { "input": "3 3\n###\n###\n###\n", "output": "0\n" }, { "input": "10 1\n.\n#\n.\n.\n.\n.\n.\n.\n#\n.\n", "output": "6\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_a
問題文 2N+1 行、 2N+1 列のマス目があります。上から i 行目、左から j 列目のマス目のことをマス (i,j) と呼ぶことにします。 また、 (2N+1) \times (2N+1) 整数行列 A が与えられます。 ここで、マス (1,N+1),(2N+1,N+1) を除く各マスには壁を設置することができ、マス (i,j) に壁を設置する コスト は A_{i,j} です。 いま、マス (1,N+1) に駒が置かれています。この駒は今いるマス目と上下左右に隣接し、かつ壁が置かれていないマス目に移動するという操作を任意の回数行うことができます。 厳密には、マス (x,y) に駒が置かれている時、マス (x',y') であっ...
[ { "input": "1\n1 -1 5\n2 4 6\n3 -1 7\n", "output": "10\n" }, { "input": "2\n8 1 -1 5 5\n7 4 9 9 3\n3 2 1 1 8\n4 4 3 3 4\n3 5 -1 5 8\n", "output": "10\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_b
問題文 長さ N の正整数列 A が与えられます。これからこの数列に以下の M 回の処理を行います。 i\ (1 \le i \le M) 回目の処理 : 1 \le j \le N を満たす整数 j を選ぶ。 A_j を \max(A_j,B_i) に置き換える。 処理の結果できる A として考えられるものの個数を 998244353 で割った余りを求めてください。
[ { "input": "6 1\n1 2 3 4 5 6\n5\n", "output": "5\n" }, { "input": "3 3\n1 1 1\n1 1 1\n", "output": "1\n" }, { "input": "6 6\n1 2 3 4 5 6\n1 2 3 4 5 6\n", "output": "203\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_c
問題文 この問題においては、「 1 番目の文字」で文字 a を、「 2 番目の文字」で文字 b を、...、「 26 番目の文字」で文字 z を指すものとします。 英小文字からなる文字列 S が与えられます。 あなたは 1\leq L\leq R\leq |S| となる整数 L, R および (1,2,\ldots,26) の順列 (p_1,p_2,\ldots,p_{26}) を選びます。その後、以下の手順で新たな文字列 T を作ります。 S' を S の L 文字目から R 文字目を取り出してできる文字列とする。 1 以上 26 以下の全ての整数 i について、 S' に含まれる「 i 番目の文字」を「 p_i 番目の文字」で置...
[ { "input": "abcba\n", "output": "zyzx\n" }, { "input": "nolemonnomelon\n", "output": "zzyxwvyz\n" }, { "input": "hhhhhqqqhhhhhjjhhhhhpppp\n", "output": "zzzzzyyzzzzzxxxx\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_d
問題文 ここに N 個の箱があり、箱 i には A_i 個のボールが入っています。あなたは、以下の操作を 0 回以上 2 \times 10^6 回以下行うことができます。 整数対 (X,Y)(X \neq Y) であって、「箱 X に入っているボールの個数」が「箱 Y に入っているボールの個数」以下であるものを選ぶ。 そして、箱 X に入っているボールの数だけ箱 Y から箱 X にボールを移す。 一つの箱にすべてのボールが入っている状態にできるか判定し、可能ならば操作列を一つ構築してください。
[ { "input": "3\n1 3 4\n", "output": "Yes\n3\n1 2\n2 1\n3 2\n" }, { "input": "4\n7 2 3 1\n", "output": "No\n" }, { "input": "5\n2 6 2 1 5\n", "output": "Yes\n6\n4 5\n1 2\n4 3\n2 1\n5 4\n5 2\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_e
問題文 1 以上 2 \times 10^6 以下の整数からなる長さ 10^5 の数列の組 (A,B) であって、以下の条件を満たすものを一つ構築してください。 1 以上 2 \times 10^6 以下のすべての整数 k について、 A_i\times B_j=k を満たす整数対 (i,j) が存在する。
[]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_f
問題文 0 以上 2^M 未満の整数からなる長さ N の数列 A=(A_0,A_1,\ldots,A_{N-1}) であって、以下の条件を満たすものの個数を 998244353 で割った余りを求めてください。 すべての整数 i\ (0 \le i \le N-1) について、 A_i \oplus A_{(i+1) \bmod N} \neq T_i かつ A_i \oplus A_{(i+1) \bmod N} \neq U_i が成り立つ ただし \oplus はビット単位 \mathrm{XOR} 演算を表します。 ビット単位 \mathrm{XOR} 演算とは 非負整数 A,B のビット単位 \mathrm{XOR} 演算、...
[ { "input": "3 2\n0 1\n1 2\n2 3\n", "output": "8\n" }, { "input": "3 1\n0 1\n0 1\n0 1\n", "output": "0\n" }, { "input": "5 10\n31 415\n92 653\n58 979\n32 384\n62 643\n", "output": "552613140\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_g
問題文 N\times N 整数行列 A が与えられます。以下の条件を満たす N \times N 整数行列 B が存在するか判定してください。 すべての整数対 (i,j) について、 A_{i,j} \neq -1 ならば A_{i,j}=B_{i,j} B のどの 4 \times 4 の部分正方形を取り出しても、その部分正方形は 1 以上 16 以下の整数をすべて含む。
[ { "input": "4\n1 2 -1 -1\n5 -1 7 -1\n9 10 -1 -1\n13 14 15 -1\n", "output": "Yes\n" }, { "input": "5\n1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 -1 1 -1\n-1 -1 -1 -1 -1\n", "output": "No\n" }, { "input": "6\n1 -1 -1 -1 -1 1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -1\n-1 -1 -1 -1 -1 -...
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_h
問題文 想定解に誤りが見つかったため、正しい解法に差し替えたうえで問題の制約を変更しました。( M \le 10^{12} から M \le 10^9 )影響を受けた方、申し訳ありません。(15:29) 正整数 N,M が与えられます。 0\leq K\leq N-1 を満たす全ての K に対して、次の値を 998244353 で割った余りを求めてください。 1 以上 M 以下の整数のみからなる長さ N の数列 A=(A_1,A_2,\ldots,A_N) であって、 A_i \times A_{i+1} が平方数であるような i\,(1\leq i\leq N-1) がちょうど K 個存在するようなものの総数
[ { "input": "3 2\n", "output": "2\n4\n2\n" }, { "input": "7 9\n", "output": "1236360\n1801104\n1168800\n444960\n111630\n17796\n2319\n" }, { "input": "10 1000000000\n", "output": "463421383\n80897715\n609130572\n681545366\n345958046\n718253740\n76864047\n286280738\n642996694\n527041309...
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_i
問題文 長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。 A の要素を自由に並び替えることができるとき、以下の値としてありうる最小値を求めてください。 \displaystyle \sum_{k=1}^N(A_1\lor A_2\lor\cdots\lor A_k) ただし \lor はビット単位 \operatorname{OR} 演算を表します。 ビット単位 \operatorname{OR} 演算とは 非負整数 A,B に対するビット単位 \operatorname{OR} 演算 A\lor B は、以下のように定義されます。 A\lor B を二進表記した際の 2^k\,(k\geq0)...
[ { "input": "3\n4 1 2\n", "output": "11\n" }, { "input": "3\n2 5 6\n", "output": "15\n" }, { "input": "4\n13 13 13 13\n", "output": "52\n" }, { "input": "6\n11 15 10 9 4 12\n", "output": "74\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_j
問題文 長さ N の整数列 A が与えられます。長さ N の順列 P が以下の条件を満たすとき、 \displaystyle \max_{1 \le i,j \le N} |iP_i-jP_j| としてありうる最小の値を求めてください。 すべての i について、 A_i \neq -1 ならば A_i = P_i
[ { "input": "3\n-1 -1 2\n", "output": "4\n" }, { "input": "1\n-1\n", "output": "0\n" }, { "input": "5\n2 4 5 1 3\n", "output": "13\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_k
問題文 長さ N の整数列 A = (A_0, A_1, \ldots, A_{N-1}),B=(B_1,B_2,\ldots,B_N) 、長さ M の整数列 C=(C_0,C_1,\ldots,C_{M-1}),D=(D_1,D_2,\ldots,D_M) と非負整数 K が与えられます。 ここで、長さ K+1 の数列 F=(F_0,F_1,\ldots,F_K),G=(G_0,G_1,\ldots,G_K) を以下で定義します。 F_i = A_i\ (0 \le i < N) \displaystyle F_i = \sum_{k=1}^N B_kF_{i-k}\ (N \le i \le K) G_j = C_j\ (0 \...
[ { "input": "2 2 5\n0 1\n1 1\n0 1\n1 1\n", "output": "40\n" }, { "input": "3 2 1\n1 2 3\n4 5 6\n7 8\n9 10\n", "output": "23\n" }, { "input": "6 7 924844033\n3 1 4 1 5 9\n2 6 5 3 5 8\n9 7 9 3 2 3 8\n4 6 2 6 4 3 3\n", "output": "142556085\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day3/tasks/pakencamp_2022_day3_l
問題文 0 以上 2^M 未満の整数からなる長さ N の数列 A すべてについて以下の値を考え、その総和を 998244353 で割った余りを求めてください。 (A_1\times A_2) \oplus (A_2\times A_3) \oplus \ldots \oplus (A_{N-1}\times A_N) を 2^M で割った余り ただし \oplus はビット単位 \mathrm{XOR} 演算を表します。 ビット単位 \mathrm{XOR} 演算とは 非負整数 A,B のビット単位 \mathrm{XOR} 演算、 A\oplus B は、以下のように定義されます。 A\oplus B を二進表記した際の 2^k\...
[ { "input": "2 1\n", "output": "1\n" }, { "input": "2 2\n", "output": "16\n" }, { "input": "314 159\n", "output": "856758166\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_a
問題文 パ研王国は N 個の街とそれを繋ぐ M 本の道路からなります。街には標高が高い順に 1, 2, \ldots, N の番号がついており、全ての道路は標高が高い街から低い街へ一方向に移動することができます。具体的には、 i 番目の道路は街 A_i から街 B_i への一方向に移動することができます (A_i < B_i) 。 さて、今年もパ研合宿が開催されます。今年のパ研合宿ではいくつかの街に会場を設け、パ研王国のどの街からでも 0 本以上の道路を通ることで会場のある街に移動できるようにします。 しかし、予算に制約があるため、会場を設ける街をできるだけ少なくしたいです。このとき、会場を設ける街の集合を一つ定めて下さい。
[ { "input": "4 4\n1 2\n1 3\n1 4\n2 4\n", "output": "2\n3 4\n" }, { "input": "10 20\n4 6\n7 9\n1 8\n4 7\n2 3\n5 6\n5 8\n8 10\n8 9\n3 4\n7 8\n3 6\n1 2\n4 9\n8 10\n6 10\n5 9\n2 7\n6 10\n1 8\n", "output": "2\n9 10\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_b
問題文 パ研学園では各年度に N 個の学期があり、 1, 2, \ldots, N の番号が付いています。各学期ごとに成績が付き、成績は 1 から N までの整数値で表されます。 さて、パ研学園の生徒であるあなたは、一年の最後に自分の各学期の成績表を眺めていました。すると、次のことに気が付きました。ここで i 番目の学期の成績を G_i とします。 G は長さ N の順列である。 2 学期以降について、前の学期より成績が下がっている学期が存在し、それらは連続する 1 つの区間になっている。 このとき、これらの条件を満たす成績 G_1, G_2, \ldots, G_N の個数を求めて下さい。ただし、答えはとても大きくなることがあるの...
[ { "input": "4\n", "output": "18\n" }, { "input": "13\n", "output": "398574\n" }, { "input": "2947\n", "output": "663703367\n" }, { "input": "999999\n", "output": "946508973\n" }, { "input": "1000000000000000000\n", "output": "856673235\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_c
問題文 パ研町にはパ研美術館とこまば美術館があります。それぞれの美術館には N 個の美術品が一列に展示されており、パ研美術館の左から i 番目の美術品の価値は A_i で、こまば美術館の左から i 番目の美術品の価値は B_i です。来場者をより楽しませるために、美術品は左から右に向かって価値の低い物から高い物の順に並んでいます。 パ研美術館とこまば美術館はコラボ展示をすることになりました。コラボには Q 個のプランがあり、 i 番目のプランでは、パ研美術館の左から L_i 番目から R_i 番目の美術品と、こまば美術館の左から X_i 番目から Y_i 番目の美術品を展示します。コラボ展示でも同様に、美術品は左から右に向かって価値...
[ { "input": "6\n1 3 6 8 9 11\n2 2 4 7 10 11\n4\n1 6 2 5\n1 6 5 5\n2 5 5 5\n4 6 3 6\n", "output": "1\n1\n1\n0\n" }, { "input": "10\n4 14 18 31 47 51 59 72 78 96\n2 23 25 36 58 60 63 85 88 97\n7\n1 3 5 5\n6 10 3 4\n8 10 1 4\n7 10 2 4\n6 7 1 3\n2 4 6 9\n2 3 2 9\n", "output": "4\n6\n2\n2\n2\n3\n2\n" ...
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_d
問題文 0 と 1 からなる長さ N の文字列であって 1 以上 M 以下の全ての整数 i について次の条件を満たすものの個数を 998244353 で割った余りを求めてください。 L_i 文字目から R_i 文字目の間に文字 C_i が存在する
[ { "input": "3 2\n1 3 0\n1 2 1\n", "output": "5\n" }, { "input": "5 4\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n", "output": "13\n" }, { "input": "7 9\n4 6 0\n1 2 0\n5 7 1\n3 4 0\n7 7 0\n6 7 1\n2 5 1\n3 5 0\n1 7 1\n", "output": "13\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_e
問題文 パ研楽団には、 N 人の演奏者がいます。また、パ研楽団は M 種類の楽器を所有しています。 i 人目の演奏者の熟練度は A_i で担当楽器は B_i 、楽器の移行コストは C_i です。 i 人目の演奏者は C_i の移行コストで担当の楽器を好きなものに変更することができます。 楽団の調和度を以下のように定義します。 M 種類の楽器それぞれについて、その楽器を担当する人の熟練度の最大値を考える。この M 個の値の最小値が調和度である。ただし、担当する人がいない楽器が存在する場合、調和度は 0 である。 x = X_1, X_2, \ldots ,X_Q について、移行コストの総和が x を超えずに実現できる最大の調和度を求め...
[ { "input": "5 3\n7 1 4\n10 3 3\n8 3 3\n9 3 5\n7 1 4\n6\n2 9 12 15 25 46\n", "output": "0\n8\n8\n8\n8\n8\n" }, { "input": "10 6\n10 3 4\n12 2 5\n2 1 3\n7 3 15\n12 1 10\n8 3 3\n11 3 14\n13 6 9\n3 3 12\n4 5 1\n10\n1 3 7 37 53 85 88 91 94 148\n", "output": "0\n4\n8\n8\n8\n8\n8\n8\n8\n8\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_f
問題文 パ研君は、次の問題を解いています。 N 頂点の木が与えられる。頂点には 1, 2, \ldots, N の番号が付けられている。 各頂点について、その頂点から最も離れた頂点を一つ求めよ。複数ある場合はどれを求めてもいい。 パ研君はこの問題を解き、 1 \leq i \leq N について頂点 i から最も離れた頂点のうち一つが頂点 A_i であると分かりました。 しかしなんという事でしょう、せっかく問題を解けたのに、元の木や A の一部の値が分からなくなってしまいました。あなたはパ研君のために、数列 A を復元してあげたいと考えました。 今あなたには長さ N の数列 B が与えられます。この数列は残っている A の情報を表し...
[ { "input": "3\n2 -1 -1\n", "output": "3\n" }, { "input": "8\n-1 8 7 5 -1 1 2 3\n", "output": "47\n" }, { "input": "4\n1 2 3 4\n", "output": "0\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_g
問題文 この問題はインタラクティブな問題です。 パ研町には N 戸の家があり、 1, 2, \ldots, N の番号が付いています。また家と家を双方向に結ぶ 0 本以上の道路があり、道路は 300 本以下であることが分かっていますが、何本あるかや、それぞれの道路がどの家とどの家を結んでいるかは分かりません。ただし、両端が同じ家を結んでいる道路はなく、複数の道路が同じ家の組を結んでいることもありません。 パ研町の町長となったあなたは、これから毎日 1 回ずつ集会を開きます。 N 戸の家それぞれについて、その家の住人を招待するかしないか決めることができます。 しかし、パ研町は非常に険悪な町です。特に隣人、つまり 1 つの道路で結ばれた...
[]
https://atcoder.jp/contests/pakencamp-2022-day2/tasks/pakencamp_2022_day2_h
問題文 パ研部員が一列に N 人並んでいます。左から i \ (1 \leq i \leq N) 番目の部員を部員 i と呼ぶことにします。現在の部員 i のパソコン力は A_i です。隣り合う部員同士には仲良し度という指標が存在し、 1 \leq i \leq N - 1 について現在の部員 i と部員 i + 1 の仲良し度は B_i です。ここで B_i は相異なります。 パ研部員は派閥争いが大好きです。普段は派閥争いが禁止されていますが、万が一派閥争いが起こってしまったときのことを考えてみましょう。 人 l, l + 1, \cdots , r \ (1 \leq l \leq r \leq N) が派閥争いを始めると、以下...
[ { "input": "5\n5 9 9 7 9\n6 7 3 4\n3\n1 4 7 4 5\n2 4 10 1 3\n1 1 6 1 3\n", "output": "5\n2\n2\n" }, { "input": "8\n14 10 12 20 18 1 6 13\n2 16 1 3 4 12 11\n5\n1 2 3 1 8\n1 3 8 1 8\n1 1 4 1 8\n1 7 15 1 8\n1 4 19 1 8\n", "output": "8\n8\n8\n7\n7\n" }, { "input": "8\n10 17 13 17 16 1 19 8\n...
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_a
問題文 座標平面上の点 P(X, Y) を、次の操作を繰り返して原点に動かしたいです。 ある実数 a を選び、 P の現在の座標を (x, y) として、 P を (x, a) または (a, y) に動かす。 必要な最小の操作回数を求めてください。
[ { "input": "6 4\n", "output": "2\n" }, { "input": "0 1\n", "output": "1\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_b
問題文 XXXX 年のパ研合宿には N 人の参加者がいました。 パソコンを充電するために 1 人 1 つのコンセントが必要です。しかし、会場には使用可能なコンセントが 1 つしかありませんでした。そのため、運営は M 個口の電源タップをいくつか用意することにしました。 M 個口の電源タップ 1 つを未使用の使用可能なコンセント 1 つに挿すことで、新たに使用可能なコンセントが M 個できます。 参加者 1 人につき最低でも 1 つ使用可能なコンセントがあるようにするには最低で何個の電源タップを用意する必要がありますか? ただし、 1 人 1 つのコンセントを用意することが不可能である場合はそのことを報告してください。
[ { "input": "5 5\n", "output": "1\n" }, { "input": "30 1\n", "output": "-1\n" }, { "input": "998244353 3\n", "output": "499122176\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_c
問題文 英小文字と ? のみからなる文字列 S が与えられます。 文字列 S に含まれる ? をそれぞれ好きな英小文字に置き換えることで作れる回文は何通りあるか求めてください。 ただし、答えは非常に大きくなる可能性があるので、 998244353 で割ったあまりを出力してください。 回文の定義 文字列 T が回文であるとは、 1 \leq i \leq | T | を満たすすべての整数 i について、 T の前から i 文字目の文字と後ろから i 文字目の文字が同じ文字であることをいいます。
[ { "input": "a??\n", "output": "26\n" }, { "input": "atcoder\n", "output": "0\n" }, { "input": "?????????????\n", "output": "45855352\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_d
問題文 N 個の椅子が横一列に並んでいます。これらの椅子に K 人の人を座らせます。 1 つの椅子に座る人は高々 1 人である必要があります。このとき次の条件を満たす i \,(2 \leq i \leq N-1) の個数を最小化したいです。 左から i-1 , i , i+1 番目の椅子全てに人が座っている このような座り方を一つ見つけてください。
[ { "input": "6 4\n", "output": "1 2 4 6 \n" }, { "input": "6 5\n", "output": "1 2 4 5 6 \n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_e
問題文 縦の長さが H 、横の長さが W の長方形の中に半径の長さが等しい 2 つの円板を入れることを考えます。このとき、円板が長方形からはみ出したり、 2 つの円板の共通部分の面積が 0 より大きくなったりしてはいけません。このとき、円板の半径の最大値を解答してください。
[ { "input": "6 4\n", "output": "1.535898384862246\n" }, { "input": "4 1\n", "output": "0.500000000000000\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_f
問題文 パ研合宿の K 運営長はある一日に開催するイベントを何にするか決めたいです。 現在 N 個のイベントの候補があり、パ研合宿の参加者は M 人です。 i 個目のイベントの時間の長さは L_i です。また、 i 個目のイベントに対する j 人目の参加者の満足度は A_{i,j} です。 1 個以上の行うイベントを定めたとき、そのイベントの集合に対する良さは全ての人に対してのイベントの満足度の最大値の総和と定義されます。 一日の時間は限られているため、イベントの時間の長さの合計は D 以下である必要があります。このとき、行うイベントの集合の良さは最大でいくつになりますか? ただし、イベントを一個も行うことができない場合はそのことを...
[ { "input": "2 4 10\n5 6\n1 2 3 4\n5 6 7 8\n", "output": "26\n" }, { "input": "1 4 10\n11\n3 6 1 8\n", "output": "-1\n" }, { "input": "4 8 100\n30 40 50 110\n3 1 4 1 5 9 2 6\n5 3 5 8 9 7 9 3\n2 3 8 4 6 2 6 4\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_g
問題文 N 頂点の根付き木が与えられます。頂点には 1 から N までの番号が振られており、根は頂点 1 で、頂点 i\,(2\leq i\leq N) の親は頂点 P_i です。 Q 個の質問が与えられるので答えてください。 i 番目の質問では整数 X_i, Y_i が与えられます。頂点 X_i は頂点 Y_i の祖先であり、二頂点間の距離を d とすると d\geq2 です。頂点 X_i と Y_i を結ぶパス上の頂点の番号を順に v_0,v_1,\ldots,v_d (ただし、 v_0=X_i, v_d=Y_i )とするとき、 v_1 を出力してください。
[ { "input": "7\n1 1 3 3 5 5\n3\n1 7\n3 6\n3 7\n", "output": "3\n5\n5\n" }, { "input": "7\n1 2 3 4 5 6\n5\n1 6\n2 5\n3 7\n3 7\n1 4\n", "output": "2\n3\n4\n4\n2\n" }, { "input": "7\n1 1 1 4 3 2\n3\n1 6\n1 7\n1 5\n", "output": "3\n2\n4\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_h
問題文 hiikunZ 君はクイズ大会の主催者ですが、得点の管理が苦手です。そこで、あなたが「アタックサバイバル」というルールにおいて得点の管理を行うプログラムを書いてあげることにしました。以下の問題を解くプログラムを書いてください。 クイズ大会に N 人の参加者が参加していて、 1 から N までの番号がつけられています。各参加者は「体力」というパラメータを持っています。はじめ、参加者 i の体力は A_i です。そして Q 回、以下の 2 種類のイベントが発生します。 1 x y : 参加者 x が配点 y の問題に正解する。すると、参加者 x 以外の体力が 0 より大きいすべての参加者の体力が y 減る。 2 x y : 参加...
[ { "input": "4 2\n5 5 5 10\n1 2 5\n2 4 5\n", "output": "2 1 3\n1 4\n" }, { "input": "4 3\n20 10 5 5\n1 2 1\n1 2 500\n2 2 500\n", "output": "0\n3 1 3 4\n1 2\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_i
問題文 あなたは長さ N の数列 X=(X_1,X_2,\ldots,X_N) を持っていましたが、 X の各要素の具体的な値は忘れてしまいました。あなたは次のことを覚えています。 (15:18 修正) X のすべての要素は正整数である。 i=1,2,\ldots,P について、 X_{A_i}=X_{B_i} i=1,2,\ldots,Q について、 X_{C_i}\neq X_{D_i} X として考えられるもののうち、辞書順で最小のものを求めてください。ただし、 X として考えられるものが存在しない場合はそのことを報告してください。
[ { "input": "5 2 3\n1 2\n2 4\n1 3\n4 5\n3 5\n", "output": "1 1 2 1 3\n" }, { "input": "5 1 1\n1 2\n1 2\n", "output": "-1\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_j
問題文 パ研王国には N 個の街があり、 1,2,3,\ldots,N と番号がついています。 王国には N-1 本の道路があり、 i 本目の道路は街 A_i と街 B_i を結んでいて、 C_i という重みが定まっています。パ研王国のすべての街は道路を使って行き来することができます。 パ研王国の K 国王は変わっているので、 Q 個の街の組をあなたに言い渡し、各組 (S_i,T_i)(1 \leq i \leq Q) について街 S_i から街 T_i へのパス上の道路の重みの中央値を求めたいと言いました。召使のあなたは K 国王の代わりに王が求めたい値を求めてあげてください。 (2023/03/27 15:36追記:) 数列 X...
[ { "input": "5\n1 2 50\n2 3 100\n1 4 20\n4 5 30\n1\n3 5\n", "output": "40\n" }, { "input": "3\n1 2 100\n2 3 50\n1\n1 3\n", "output": "75\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_k
問題文 数列 X=(X_1,X_2,\ldots,X_M) の 美しさ を以下のように定めます。 Y_i\coloneqq \max(X_1,X_2,\ldots,X_i) としたときの、 Y_1,Y_2,\ldots,Y_M に含まれる数の種類数 長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。 Q 個のクエリを処理してください。 i 番目のクエリでは整数 L_i,R_i が与えられるので、数列 (A_{L_i},A_{L_i+1},\ldots,A_{R_i}) の 美しさ を出力してください。
[ { "input": "5\n1 5 2 4 3\n4\n1 5\n2 5\n3 3\n3 5\n", "output": "2\n1\n1\n2\n" }, { "input": "5\n3 2 2 4 5\n4\n1 5\n1 5\n4 5\n4 5\n", "output": "3\n3\n2\n2\n" }, { "input": "5\n4 4 1 3 5\n15\n1 1\n1 2\n1 3\n1 4\n1 5\n2 2\n2 3\n2 4\n2 5\n3 3\n3 4\n3 5\n4 4\n4 5\n5 5\n", "output": "1\n1\...
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_l
問題文 有限個の非負整数からなる多重集合 S に対して、 \operatorname{mex}(S) を S に含まれない最小の非負整数と定義します。例えば、 \operatorname{mex}(\lbrace 0,0,1,3 \rbrace)=2,\operatorname{mex}(\lbrace 1 \rbrace)=0,\operatorname{mex}(\lbrace\rbrace)=0 です。 黒板に長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が書かれています。 あなたは、以下の操作をちょうど K 回行います。 A の中から非負整数を 0 個以上選ぶ。選んだ非負整数からなる多重集合を S と...
[ { "input": "3 1\n0 1 3\n", "output": "3\n" }, { "input": "5 10\n3 1 4 1 5\n", "output": "14476910\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_m
問題文 頂点 1 を根とする N 頂点の根付き木があります。頂点 i の親は頂点 P_i です。これから各頂点に 0 または 1 を書き込みたいです。 以下の与えられた条件を満たすような頂点に対する 0 と 1 の割り当て方を一つ求めてください。また、そのような割り当て方が存在しない場合はそのことを報告してください。 K 個の頂点 M_1 ,M_2, \cdots M_K にはそれぞれ S_1 ,S_2, \cdots S_K が書き込まれている。 頂点 i に 1 が書き込まれているならば、頂点 A_i とその子孫の頂点には 1 が書き込まれている。 頂点 i に 0 が書き込まれているならば、頂点 A_i とその子孫の頂点には ...
[ { "input": "4\n1 1 2\n1\n2 1\n3 4 3 2\n", "output": "1111\n" }, { "input": "5\n1 2 3 4\n2\n1 1\n2 0\n3 1 4 1 5\n", "output": "IMPOSSIBLE\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_n
問題文 はじめに整数 T が与えられます。 T 個のテストケースについて次の問題を解いてください。 hiikunZ 君は、誕生日プレゼントとしてパ研マシンをもらいました。 パ研マシンには、ディスプレイ、ライト、ボタンが 1 つずつついています。 はじめ、ディスプレイには整数 s が表示されていて、ライトは赤に点灯しています。 hiikunZ 君がボタンを押すたびに、ディスプレイに表示される整数 x とライトの色は、次の通りに変化します。 ボタンを押す前に、ライトが赤に点灯していた場合、 x は A_r \times x + B_r を素数 P で割ったあまりに変化し、ライトは青に点灯する。 ボタンを押す前に、ライトが青に点灯していた...
[ { "input": "3\n1 8 13\n1 2 3 4 5 6\n0 1 3\n1 0 1 0 1 0\n123456789 634 998244353\n1 23 456 7890 123456789 987654321\n", "output": "4\n-1\n164941630\n" } ]
https://atcoder.jp/contests/pakencamp-2022-day1/tasks/pakencamp_2022_day1_o
問題文 パ研ランドには N 個のアトラクションがあり、 1 から N までの番号がつけられています。 また、これらのアトラクションを結ぶ道が N - 1 本あり、 1 から N - 1 までの番号がつけられています。 道 i (1 \leq i \leq N - 1) はアトラクション A_i と アトラクション B_i を双方向に結んでいます。 さらに、パ研ランドのそれぞれの道には「楽しさ」という値が設定されていて、道 i (1 \leq i \leq N - 1) の楽しさは C_i です。 パ研ランドでのアトラクション間の移動も楽しみたい hiikunZ 君のために、すべてのアトラクション i (1 \leq i \leq N...
[ { "input": "3\n1 2 3\n2 3 6\n", "output": "4\n6\n6\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_a
Problem Statement You are given N strings W_1,W_2,\dots,W_N consisting of lowercase English letters. If one or more of these strings equal and , not , that , the , or you , then print Yes ; otherwise, print No .
[ { "input": "10\nin that case you should print yes and not no\n", "output": "Yes\n" }, { "input": "10\nin diesem fall sollten sie no und nicht yes ausgeben\n", "output": "No\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_b
Problem Statement We have a board with R rows running horizontally and C columns running vertically. Let (i,j) denote the square at the i -th row from the top and j -th column from the left. You are given characters B_{i,j} representing the current states of (i,j) . . represents an empty square; # represents a square w...
[ { "input": "4 4\n.1.#\n###.\n.#2.\n#.##\n", "output": "...#\n#...\n....\n#...\n" }, { "input": "2 5\n..#.#\n###.#\n", "output": "..#.#\n###.#\n" }, { "input": "2 3\n11#\n###\n", "output": "...\n..#\n" }, { "input": "4 6\n#.#3#.\n###.#.\n##.###\n#1..#.\n", "output": "........
https://atcoder.jp/contests/abc295/tasks/abc295_c
Problem Statement You have N socks. The color of the i -th sock is A_i . You want to perform the following operation as many times as possible. How many times can it be performed at most? Choose two same-colored socks that are not paired yet, and pair them.
[ { "input": "6\n4 1 7 4 1 4\n", "output": "2\n" }, { "input": "1\n158260522\n", "output": "0\n" }, { "input": "10\n295 2 29 295 29 2 29 295 2 29\n", "output": "4\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_d
Problem Statement The string 20230322 can be rearranged into 02320232 , which is a repetition of 0232 twice. Similarly, a string consisting of digits is said to be happy when it can be rearranged into (or already is) a repetition of some string twice. You are given a string S consisting of digits. Find the number of pa...
[ { "input": "20230322\n", "output": "4\n" }, { "input": "0112223333444445555556666666777777778888888889999999999\n", "output": "185\n" }, { "input": "3141592653589793238462643383279502884197169399375105820974944\n", "output": "9\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_e
Problem Statement We have a sequence of length N consisting of integers between 0 and M , inclusive: A=(A_1,A_2,\dots,A_N) . Snuke will perform the following operations 1 and 2 in order. For each i such that A_i=0 , independently choose a uniform random integer between 1 and M , inclusive, and replace A_i with that int...
[ { "input": "3 5 2\n2 0 4\n", "output": "3\n" }, { "input": "2 3 1\n0 0\n", "output": "221832080\n" }, { "input": "10 20 7\n6 5 0 2 0 0 0 15 0 0\n", "output": "617586310\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_f
Problem Statement You are given a string S consisting of digits and positive integers L and R for each of T test cases. Solve the following problem. For a positive integer x , let us define f(x) as the number of contiguous substrings of the decimal representation of x (without leading zeros) that equal S . For instance...
[ { "input": "6\n22 23 234\n0295 295 295\n0 1 9999999999999999\n2718 998244353 9982443530000000\n869120 1234567890123456 2345678901234567\n2023032520230325 1 9999999999999999\n", "output": "12\n0\n14888888888888889\n12982260572545\n10987664021\n1\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_g
Problem Statement We have a directed graph G_S with N vertices numbered 1 to N . It has N-1 edges. The i -th edge (1\leq i \leq N-1) goes from vertex p_i\ (1\leq p_i \leq i) to vertex i+1 . We have another directed graph G with N vertices numbered 1 to N . Initially, G equals G_S . Process Q queries on G in the orde...
[ { "input": "5\n1 2 3 3\n5\n2 4\n1 4 2\n2 4\n1 5 1\n2 4\n", "output": "4\n2\n1\n" }, { "input": "7\n1 1 2 2 3 3\n10\n2 5\n1 5 2\n2 5\n1 2 1\n1 7 1\n1 6 3\n2 5\n2 6\n2 1\n1 7 1\n", "output": "5\n2\n1\n1\n1\n" } ]
https://atcoder.jp/contests/abc295/tasks/abc295_h
Problem Statement We have a grid A with N rows and M columns. Initially, 0 is written on every square. Let us perform the following operation. For each integer i such that 1 \le i \le N , in the i -th row, turn the digits in zero or more leftmost squares into 1 . For each integer j such that 1 \le j \le M , in the j -t...
[ { "input": "2 3\n0?1\n?1?\n", "output": "6\n" }, { "input": "5 3\n101\n010\n101\n010\n101\n", "output": "0\n" }, { "input": "18 18\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n??????????????????\n????????????????...
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_a
問題文 正整数 N に対して、 f(N) を以下で定めます。 N の各桁の数字を並び替えて得られる整数の集合を S とする。ただし、並び替えた結果先頭に 0 が続く場合 leading zero として解釈する。例えば、 N=102 のとき S=\lbrace 12,21,102,120,201,210\rbrace である。 S の要素全てを割り切る最大の整数を f(N) とする。 10^{18} 以下の正整数 K が与えられます。 f(N)=K を満たすような 10^{18} 以下の正整数 N が存在するか判定し、存在する場合 1 つ求めてください。 T 個のテストケースが与えられるので、それぞれについて答えてください。
[ { "input": "2\n3\n10\n", "output": "123\n-1\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_b
問題文 2 次元平面上に nok0 君と N 匹のスライムがいます。はじめ nok0 君の座標は (0, 0) 、 i\ (1\le i\le N) 番目のスライムの座標は (X_i, Y_i) です。 nok0 君は平面上の任意の地点で何度でも以下の行動ができます。 x 軸正負方向、 y 軸正負方向の合計 4 方向に同時にビームを打つ。nok0 君と等しい x 座標または y 座標をもつスライムが消滅する。 nok0 君は平面上を任意の方向に連続的に移動することができます。nok0 君が平面上にいるすべてのスライムを消滅させるのに必要な移動距離の最小値を求めてください。
[ { "input": "3\n1 -1\n2 6\n8 3\n", "output": "3.605551275463989\n" }, { "input": "1\n100000000 -100000000\n", "output": "100000000.000000000000000\n" }, { "input": "18\n2092413 29557322\n-83061793 -86609930\n41750783 34587912\n94366440 62086679\n42714686 -18841496\n10264522 -60895144\n947...
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_c
問題文 UT 君と PC 君は Nim というゲームで遊んでいます。 N 個の正整数 A_1, A_2,\ldots, A_N に対し、 \mathrm{Nim}(A_1, A_2, \ldots, A_N) とは次のゲームのことを指します。 いくつかの石からなる N 個の山があり、はじめ i\ (1\le i\le N) 番目の山には A_i 個の石がある。UT 君から始めて、 2 人は交互に以下の操作を 1 回ずつ繰り返す。 (操作) 石が 1 個以上残っている山を 1 つ選ぶ。その山から石を 1 個以上取り除く。 石が全て取り除かれた時点でゲームを終了し、最後に操作を行ったプレイヤーを勝ち、もう一方のプレイヤーを負けとする。 ...
[ { "input": "2 2\n", "output": "12\n" }, { "input": "4 5\n", "output": "6748\n" }, { "input": "1 222\n", "output": "222\n" }, { "input": "987654321 456\n", "output": "897555885\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_d
問題文 この問題は インタラクティブな問題 (あなたの作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。 N 個のおもりが手元にあります。 i 番目のおもりの重さを P_i としたとき、 (P_1, \dots, P_N) は (1, \dots, N) の順列となることが分かっていますが、 P_i の具体的な値は分かっていません。 また、 -2N 以上 2N 以下の整数の目盛りがついた棒が、位置 0 のところでつるされています。目盛りがついている位置には穴が開いており、それぞれの穴には 1 個までおもりをぶら下げることができます。 はじめはおもりが 1 つもぶら下がっておらず、棒はつりあっていま...
[]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_e
問題文 長さ N の順列 P=(P_1,P_2,\ldots,P_N), Q=(Q_1,Q_2,\ldots,Q_N) があります。はじめ P_i = Q_i = i (1 \leq i \leq N) です。 この 2 つの順列に対して、以下の操作を 0 回以上好きなだけ繰り返します。 1 \le i \le M を満たす整数 i を選ぶ。 P の a_i 番目と b_i 番目の要素を入れ替え、 Q の c_i 番目と d_i 番目の要素を入れ替える。 操作後の P, Q の状態の組としてありうるものの個数を 998244353 で割ったあまりを求めてください。
[ { "input": "3 1\n1 2 2 3\n", "output": "2\n" }, { "input": "4 3\n1 2 2 4\n2 3 1 2\n1 4 2 3\n", "output": "288\n" }, { "input": "2 0\n", "output": "1\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_f
問題文 (1, 2, \ldots, N) の順列 P = (P_1, P_2, \ldots, P_N) と整数 K が与えられます。 以下の疑似コードで表されるアルゴリズムを実行した場合、(1) の式は何回実行されますか? for (int i = 1; i <= N; i++) { for (int j = 1; j <= N - i - K + 2; j++) { if ((P[j], P[j + 1], ..., P[j + K - 1]) が昇順に並んでいない) { (P[j], P[j + 1], ..., P[j + K - 1]) を昇順に並び替える ... (...
[ { "input": "4 2\n1 3 4 2\n", "output": "2\n" }, { "input": "6 3\n5 1 6 4 3 2\n", "output": "6\n" }, { "input": "20 7\n10 17 8 1 16 13 14 5 20 19 4 15 18 3 11 2 12 9 7 6\n", "output": "23\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_g
問題文 黒板に N 個の整数 A_1, A_2, \ldots, A_N が書かれています。 あなたは次の操作を N - 1 回行います。 黒板に書かれている数を 2 つ選んで消す。消した数を x と y として、 K - x - y を新たに黒板に書く。 N - 1 回の操作を終えた後、黒板にはただ一つの整数が残りますが、この整数として考えられる最大値はいくつですか?
[ { "input": "4 3\n1 2 3 4\n", "output": "7\n" }, { "input": "4 7\n1 2 3 4\n", "output": "5\n" }, { "input": "10 3\n1 4 1 5 9 2 6 5 3 5\n", "output": "32\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_h
問題文 整数 N が与えられます。あなたは、整数 N に対して以下の 操作 を 1 回だけ行えます。 操作 : N の桁のうち、いくつかの桁を選び( 0 個でも良い)、それらを全て独立に 0 ~ 9 のいずれかに等確率で置き換える。ただし、先頭に 0 が続く場合 leading zero として解釈する。 あなたの目的は、出来るだけ高い確率で N の値を操作前よりも大きくすることです。最適な戦略をとった場合に操作前の N よりも大きい数を得られる確率を \text{mod } 998244353 で求めてください。 確率 \text{mod } 998244353 の定義 この問題で求める確率は必ず有理数になることが証明できます。 ...
[ { "input": "502\n", "output": "509104621\n" }, { "input": "520\n", "output": "698771048\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_i
問題文 ( , ) のみからなる文字列のうち、以下のいずれかに該当するものを「正しい括弧列」といいます。 空文字列 ある「正しい括弧列」 A が存在して ( , A , ) をこの順につなげた文字列 ある空でない「正しい括弧列」 A,\ B が存在して A,\ B をこの順につなげた文字列 長さ 4N で ( , ) のみからなる文字列 S と 2N 個の 2 整数の組 (L_i, R_i)\ (1\leq L_i < R_i \leq 4N) が与えられます。ここで、 (L_1,L_2,\dots,L_{2N}) は (1,2,\dots,2N) の、 (R_1,R_2,\dots,R_{2N}) は (2N+1,2N+2,\do...
[ { "input": "3\n1\n()()\n1 3\n2 4\n2\n))()((()\n1 6\n2 5\n3 7\n4 8\n8\n))()))))()())((((()))(()(()))(((\n8 26\n2 25\n1 18\n4 22\n7 17\n12 32\n10 31\n5 30\n15 27\n9 23\n13 19\n11 24\n14 29\n6 28\n16 20\n3 21\n", "output": "Yes\nNo\nYes\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_j
問題文 (1,2,\ldots,N) の順列 P = (P_1,P_2,\ldots,P_N) が与えられます。あなたは以下の操作を 0 回以上 15 回以下行うことができます。 1\leq l \leq r \leq N かつ r-l+1 が奇数であるような整数組 (l,r) を選び、数列 (P_l,P_{l+1},\ldots,P_r) の中央値を M とする。このとき P_x = M なる整数 x が一意に定まる。 P の l 番目から x-1 番目を(存在すれば)昇順に並び替え、 x+1 番目から r 番目を(存在すれば)昇順に並び替える。 操作によって P を昇順に並び替えられるか判定し、可能な場合はそのような操作列を一つ...
[ { "input": "5\n2 1 3 5 4\n", "output": "1\n1 5\n" }, { "input": "4\n1 2 3 4\n", "output": "2\n1 3\n2 4\n" }, { "input": "2\n2 1\n", "output": "-1\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_k
問題文 2N\times 2M のグリッド状のマス目があります。上から i 行目、左から j 列目のマス目を (i,j) で表します。はじめ、各マスの色はすべて白色です。 これから以下の条件を満たすように NM 個のマス目を赤く塗ります。 赤く塗られたマス目 (i,j) について i+j は偶数である。 赤く塗られたマス目は端点を共有しない。厳密には、赤く塗られた 2 つの異なるマス目 (i,j),(k,l) であって、 |i-k|\leq 1 かつ |j-l| \leq 1 を満たすものが存在しない。 K 個のマス目 (X_i,Y_i) は必ず赤く塗る。 条件を満たすように NM 個のマス目を赤く塗る方法の数を 998244353...
[ { "input": "2 2 1\n3 1\n", "output": "3\n" }, { "input": "1 2 2\n1 1\n2 2\n", "output": "0\n" }, { "input": "20 20 10\n26 26\n27 9\n7 21\n38 20\n30 34\n36 14\n17 7\n30 40\n19 3\n38 8\n", "output": "908257345\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_l
問題文 N 人が参加するじゃんけん大会が開催されます。参加者は、人 1 、人 2 、 \ldots 、人 N と呼ばれます。どの参加者もそれぞれ得意な手を持っていて、毎試合得意な手のみを出します。 参加者の得意な手は、 R , P , S からなる長さ N の文字列 S によって表されます。人 i の得意な手は、 S の i 文字目 S_i です。ここで文字 R はグーを、 P はパーを、 S はチョキを表します。 大会では、人 1 、人 2 、 \ldots 、人 N をこの順に横一列に並べた後、 0 回以上の「試合」を行います。「試合」は、次のように行われます。 列で隣り合っている 2 人であって、じゃんけんをしたときにあいこに...
[ { "input": "4\nRSPR\n", "output": "2\n" }, { "input": "3\nRSR\n", "output": "0\n" }, { "input": "6\nSRPPSR\n", "output": "3\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_m
問題文 長さ n の非負整数列 X=(X_1,X_2,\dots,X_n) に対し f(X) を、 Y_1+Y_2+\dots+Y_n=X_1+X_2+\dots+X_n を満たす長さ n の非負整数列 Y=(Y_1,Y_2,\dots,Y_n) 全てにおける Y_1 \oplus Y_2 \oplus \dots \oplus Y_n の最小値とします。ただしここで、 \oplus はビット単位 \mathrm{XOR} 演算を表します。 長さ N の非負整数列 A=(A_1,A_2,\dots,A_N) が与えられます。 A の空でない部分列 B は 2^N-1 個考えられますが、それらすべてに対する f(B) の総和を 998...
[ { "input": "3\n0 1 2\n", "output": "8\n" }, { "input": "15\n99412 355422 750910 993699 41414 435678 325371 637849 939332 512546 112254 175315 865362 459658 311661\n", "output": "7032514\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_n
問題文 整数 N と、 0 と 1 のみからなる長さ N の文字列 T が与えられます。 0 と 1 のみからなる、長さ 2N の文字列 S = s_1 s_2 \ldots s_{2N} と T を用いて、Alice と Bob がゲームをします。二人は Alice から始めて、 S の全ての文字に印がつくまで交互に以下の操作をします。 1 \le i \le 2N を満たす整数 i であって、 s_i にまだ印がついていないようなものを選ぶ。その後、 Alice の手番であれば、その桁に o の印をつける。 Bob の手番であれば、その桁に x の印をつける。 ゲームが終了した時に、 o の印がついている桁だけを左から読み、 N...
[ { "input": "1\n0\n", "output": "4\n" }, { "input": "1\n1\n", "output": "3\n" }, { "input": "12\n011011000111\n", "output": "13225655\n" } ]
https://atcoder.jp/contests/utpc2022/tasks/utpc2022_o
問題文 頂点 1 を根とする、 N 頂点の根付き木があります。頂点 i (2 \le i \le N) の親は P_i です。頂点 1 には椅子が 10^{100} 個置いてあり、それ以外の頂点には椅子が 1 個ずつ置いてあります。それぞれの椅子には、人が 1 人まで座ることができます。 これから M 人の人たちが順番にこの木に休憩しに訪れます。 i = 1, 2, \dots, M の順に、 i 番目の人は以下の行動をとります。 頂点 A_i に訪れる。その後、空いている椅子がある頂点にたどり着くまで根の方向に向かって進む。空いている椅子がある頂点にたどり着いたら、その椅子に座り行動を終了する。 全員が行動を終了するまでに i 番...
[ { "input": "3\n1 1\n4\n1 2 3 2\n", "output": "1\n" }, { "input": "7\n1 1 3 4 5 5\n6\n3 5 3 6 6 2\n", "output": "3\n" } ]
https://atcoder.jp/contests/abc294/tasks/abc294_a
Problem Statement You are given a sequence of N integers: A=(A _ 1,A _ 2,\ldots,A _ N) . Print all even numbers in A without changing the order.
[ { "input": "5\n1 2 3 5 6\n", "output": "2 6\n" }, { "input": "5\n2 2 2 3 3\n", "output": "2 2 2\n" }, { "input": "10\n22 3 17 8 30 15 12 14 11 17\n", "output": "22 8 30 12 14\n" } ]
https://atcoder.jp/contests/abc294/tasks/abc294_b
Problem Statement You are given an H -by- W matrix A consisting of integers between 0 and 26 . The element at the i -th row from the top and j -th column from the left is A_{i,j} . Let S_1, S_2, \dots, S_H be H strings of length W that satisfy the following. The j -th character of S_i is a period ( . ) if A_{i,j} is 0 ...
[ { "input": "2 3\n0 1 2\n0 0 3\n", "output": ".AB\n..C\n" }, { "input": "3 3\n24 0 0\n0 25 0\n0 0 26\n", "output": "X..\n.Y.\n..Z\n" }, { "input": "3 1\n2\n9\n4\n", "output": "B\nI\nD\n" }, { "input": "24 60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 ...
https://atcoder.jp/contests/abc294/tasks/abc294_c
Problem Statement You are given strictly increasing sequences of length N and M : A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B _ 1,B _ 2,\ldots,B _ M) . Here, A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M) . Let C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+M that results fro...
[ { "input": "4 3\n3 14 15 92\n6 53 58\n", "output": "1 3 4 7\n2 5 6\n" }, { "input": "4 4\n1 2 3 4\n100 200 300 400\n", "output": "1 2 3 4\n5 6 7 8\n" }, { "input": "8 12\n3 4 10 15 17 18 22 30\n5 7 11 13 14 16 19 21 23 24 27 28\n", "output": "1 2 5 9 11 12 15 20\n3 4 6 7 8 10 13 14 1...
https://atcoder.jp/contests/abc294/tasks/abc294_d
Problem Statement N people, with ID numbers 1 , 2 , \dots , N , are lining up in front of a bank. There will be Q events. The following three kinds of events can happen. 1 : The teller calls the person with the smallest ID number who has not been called. 2 x : The person with the ID number x comes to the teller for the...
[ { "input": "4 10\n1\n1\n3\n2 1\n1\n2 3\n3\n1\n2 2\n3\n", "output": "1\n2\n4\n" } ]
https://atcoder.jp/contests/abc294/tasks/abc294_e
Problem Statement We have a grid with 2 rows and L columns. Let (i,j) denote the square at the i -th row from the top (i\in\lbrace1,2\rbrace) and j -th column from the left (1\leq j\leq L) . (i,j) has an integer x _ {i,j} written on it. Find the number of integers j such that x _ {1,j}=x _ {2,j} . Here, the descriptio...
[ { "input": "8 4 3\n1 2\n3 2\n2 3\n3 1\n1 4\n2 1\n3 3\n", "output": "4\n" }, { "input": "10000000000 1 1\n1 10000000000\n1 10000000000\n", "output": "10000000000\n" }, { "input": "1000 4 7\n19 79\n33 463\n19 178\n33 280\n19 255\n33 92\n34 25\n19 96\n12 11\n19 490\n33 31\n", "output": ...
https://atcoder.jp/contests/abc294/tasks/abc294_f
Problem Statement Takahashi and Aoki have N and M bottles of sugar water, respectively. Takahashi's i -th sugar water is composed of A_i grams of sugar and B_i grams of water. Aoki's i -th sugar water is composed of C_i grams of sugar and D_i grams of water. There are NM ways to choose one from Takahashi's sugar waters...
[ { "input": "3 1 1\n1 2\n4 1\n1 4\n1 4\n", "output": "50.000000000000000\n" }, { "input": "2 2 2\n6 4\n10 1\n5 8\n9 6\n", "output": "62.500000000000000\n" }, { "input": "4 5 10\n5 4\n1 6\n7 4\n9 8\n2 2\n5 6\n6 7\n5 3\n8 1\n", "output": "54.166666666666664\n" } ]
https://atcoder.jp/contests/abc294/tasks/abc294_g
Problem Statement You are given a tree T with N vertices. Edge i (1\leq i\leq N-1) connects vertices u _ i and v _ i , and has a weight of w _ i . Process Q queries in order. There are two kinds of queries as follows. 1 i w : Change the weight of edge i to w . 2 u v :Print the distance between vertex u and vertex v . H...
[ { "input": "5\n1 2 3\n1 3 6\n1 4 9\n4 5 10\n4\n2 2 3\n2 1 5\n1 3 1\n2 1 5\n", "output": "9\n19\n11\n" }, { "input": "7\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n3\n2 1 6\n1 1 294967296\n2 1 6\n", "output": "5000000000\n4294967296\n" }, {...
https://atcoder.jp/contests/abc294/tasks/abc294_h
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, modulo 998244353 , of ways to write an integer between 1 and K , inclusive, on each vertex of this graph to satisfy the following condition...
[ { "input": "4 3 2\n1 2\n2 4\n2 3\n", "output": "2\n" }, { "input": "4 0 10\n", "output": "10000\n" }, { "input": "5 10 5\n3 5\n1 3\n1 2\n1 4\n3 4\n2 5\n4 5\n1 5\n2 3\n2 4\n", "output": "120\n" }, { "input": "5 6 294\n1 2\n2 4\n1 3\n2 3\n4 5\n3 5\n", "output": "838338733\n...
https://atcoder.jp/contests/ahc019/tasks/ahc019_a
Problem Statement AtCoder is developing an educational toy that combines blocks to create a three-dimensional object with a specified silhouette. The toy consists of a set of polycube-shaped blocks consisting of 1\times 1\times 1 cubes joined face to face and a pair of two 2D monochrome silhouette images. You will wi...
[ { "input": "5\n10001\n11011\n11111\n10101\n10001\n01110\n11011\n10000\n11011\n01110\n11110\n00011\n01110\n11000\n11111\n11110\n00011\n01110\n00011\n11110\n", "output": "19\n0 1 2 3 0 4 5 0 3 3 6 0 0 0 3 7 7 0 3 3 0 7 0 8 0 0 5 9 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 9 10 0 0 0 0 10 0 0 0 0 0 0 0 0...
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_a
問題文 N 行 M 列からなる盤面があり,各マス目には row-major 順に 1 から N \times M までの整数が書かれています. つまり,上から i 行目,左から j 列目のマスに書かれている整数を A_{i,j} で表すことにすると, A_{i,j}=(i-1) \times M + j です. この盤面の部分長方形であって,その内部に書かれた値の総和がちょうど V になるものの個数を数えてください. より厳密に言えば,整数の 4 つ組 (a,b,c,d) ( 1 \leq a \leq b \leq N , 1 \leq c \leq d \leq M ) であって, \sum_{a \leq i \leq b,\...
[ { "input": "2 2 3\n", "output": "2\n" }, { "input": "2 2 5\n", "output": "0\n" }, { "input": "13 8 1032\n", "output": "5\n" } ]
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_b
問題文 1 から N までの番号がついた N 問のクイズがあり,あなたはこれらを使ったゲームに参加します. このゲームでは,あなたはクイズに 1 問ずつ回答していきます. クイズに回答する順番は自由に選ぶことができます. クイズ i に回答すると P_i % の確率で正解します. 正解した場合,あなたは S_i 点を獲得し,(まだ未回答のクイズがあるなら)次のクイズの回答へと移ります. 正解しなかった場合,即座にゲームが終了し,残りのクイズに回答することができなくなります. あなたは,獲得する得点の合計の期待値を最大化したいです. 目的を達成するための戦略(=クイズに回答する順番)を求めてください. なお,各クイズに正解するか否かの...
[ { "input": "2\n1000 10\n300 50\n", "output": "2 1\n" }, { "input": "6\n1 0\n1 20\n1 40\n1 60\n1 80\n1 100\n", "output": "6 5 4 3 2 1\n" }, { "input": "9\n88994950 78\n405248480 35\n561113280 28\n22802150 2\n946582650 25\n201425280 52\n669650 41\n128877450 71\n1396050 25\n", "output":...
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_c
問題文 整数 L,R が与えられます. 以下の条件を満たす整数の組 (A,B) の個数を数えてください. L \leq A < B \leq R A は A \oplus B で割り切れる. B は A \oplus B で割り切れる. ただしここで \oplus はビット単位 \mathrm{XOR} 演算を表します. ビット単位 \mathrm{XOR} 演算とは 非負整数 A, B のビット単位 \mathrm{XOR} 、 A \oplus B は、以下のように定義されます。 A \oplus B を二進表記した際の 2^k ( k \geq 0 ) の位の数は、 A, B を二進表記した際の 2^k の位の数のうち一方のみ...
[ { "input": "3 6\n", "output": "2\n" }, { "input": "1 100\n", "output": "124\n" }, { "input": "999000000 1000000000\n", "output": "1726239\n" } ]
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_d
問題文 (0,1,\cdots,N-1) の順列 P=(P_0,P_1,\cdots,P_{N-1}) が与えられます. 整数 a,b ( 0 \leq a,b \leq N-1 ) に対して,順列 f(a,b) を次のように定義します. f(a,b)=(q_0,q_1,\cdots,q_{N-1}) とおいて, q_{(i+a \pmod N)}=(P_i+b \pmod N) ( 0 \leq i \leq N-1 ) と定める. すべての a,b に対し f(a,b) を求めると, N^2 個の順列が得られます. これらの順列を辞書順でソートすることを考えます. ソートしたあと,先頭から K 番目に位置している順列を求めてくだ...
[ { "input": "2 2\n0 1\n", "output": "0 1\n" }, { "input": "4 6\n0 2 1 3\n", "output": "1 2 0 3\n" }, { "input": "10 79\n6 5 9 8 7 1 3 2 0 4\n", "output": "7 9 8 2 1 0 4 6 5 3\n" } ]
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_e
問題文 0 , 1 からなる長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. 今,二次元平面上の座標 (0,0) の点に駒があります. あなたはこれから,以下の操作を好きな回数繰り返します. 整数 x,y ( 1 \leq x,y \leq N ) を選び,駒の X , Y 座標をそれぞれ x , y ずつ増やす. ただしここで,以下の 2 つの条件を満たす必要がある. A_x=1 が成立. 操作後の駒の座標を (p,q) とおくとき, q \leq p が成立. 最終的に駒が座標 (N,N) へと至るような操作方法が何通りあるかを 998244353 で割ったあまりを求めてください.
[ { "input": "2\n1 1\n", "output": "2\n" }, { "input": "1\n0\n", "output": "0\n" }, { "input": "4\n1 1 0 1\n", "output": "10\n" }, { "input": "25\n1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 0\n", "output": "934946952\n" } ]
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_f
問題文 A , B からなる長さ N の文字列 S が与えられます. あなたは,以下の操作を 0 回以上繰り返すことができます. S 中の連続する 2 文字であって, AB で ない ものを選び,消す. その後,残った左右の(空かもしれない)文字列を連結し,これを新たに S とする. 操作後の S としてあり得る文字列が何通りあるかを 998244353 で割ったあまりを求めてください.
[ { "input": "3\nBBA\n", "output": "3\n" }, { "input": "5\nABABA\n", "output": "3\n" }, { "input": "9\nBABBAAAAB\n", "output": "14\n" }, { "input": "48\nAABABBBAABAAABAAABBBAAABBBAABAABBABAABBAAAAABBBB\n", "output": "3073910\n" } ]
https://atcoder.jp/contests/toyota2023spring-final-open/tasks/toyota2023spring_final_g
問題文 プログラミング初心者のすぬけくんが,以下のようなコードを書きました. N = read_integer() parent = array(N, -1) //長さ N の配列 parent を作り,すべての要素を -1 で初期化 find(v): if parent[v] == -1: return v else: return find(parent[v]) union(a,b): parent[find(b)] = find(a) for i = 0 to N-2: A_i = read_integer() B_i = read_integer...
[ { "input": "2\n0 1\n", "output": "2\n" }, { "input": "3\n0 1\n0 2\n", "output": "5\n" }, { "input": "5\n0 1\n0 2\n0 3\n3 4\n", "output": "13\n" }, { "input": "20\n6 16\n10 6\n16 8\n1 5\n9 4\n5 3\n13 16\n19 10\n12 2\n14 10\n12 18\n0 2\n15 16\n12 7\n11 14\n1 10\n6 4\n17 8\n12 1...
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_a
問題文 N 行 M 列からなる盤面があり,各マス目には row-major 順に 1 から N \times M までの整数が書かれています. つまり,上から i 行目,左から j 列目のマスに書かれている整数を A_{i,j} で表すことにすると, A_{i,j}=(i-1) \times M + j です. この盤面の部分長方形であって,その内部に書かれた値の総和がちょうど V になるものの個数を数えてください. より厳密に言えば,整数の 4 つ組 (a,b,c,d) ( 1 \leq a \leq b \leq N , 1 \leq c \leq d \leq M ) であって, \sum_{a \leq i \leq b,\...
[ { "input": "2 2 3\n", "output": "2\n" }, { "input": "2 2 5\n", "output": "0\n" }, { "input": "13 8 1032\n", "output": "5\n" } ]
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_b
問題文 1 から N までの番号がついた N 問のクイズがあり,あなたはこれらを使ったゲームに参加します. このゲームでは,あなたはクイズに 1 問ずつ回答していきます. クイズに回答する順番は自由に選ぶことができます. クイズ i に回答すると P_i % の確率で正解します. 正解した場合,あなたは S_i 点を獲得し,(まだ未回答のクイズがあるなら)次のクイズの回答へと移ります. 正解しなかった場合,即座にゲームが終了し,残りのクイズに回答することができなくなります. あなたは,獲得する得点の合計の期待値を最大化したいです. 目的を達成するための戦略(=クイズに回答する順番)を求めてください. なお,各クイズに正解するか否かの...
[ { "input": "2\n1000 10\n300 50\n", "output": "2 1\n" }, { "input": "6\n1 0\n1 20\n1 40\n1 60\n1 80\n1 100\n", "output": "6 5 4 3 2 1\n" }, { "input": "9\n88994950 78\n405248480 35\n561113280 28\n22802150 2\n946582650 25\n201425280 52\n669650 41\n128877450 71\n1396050 25\n", "output":...
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_c
問題文 整数 L,R が与えられます. 以下の条件を満たす整数の組 (A,B) の個数を数えてください. L \leq A < B \leq R A は A \oplus B で割り切れる. B は A \oplus B で割り切れる. ただしここで \oplus はビット単位 \mathrm{XOR} 演算を表します. ビット単位 \mathrm{XOR} 演算とは 非負整数 A, B のビット単位 \mathrm{XOR} 、 A \oplus B は、以下のように定義されます。 A \oplus B を二進表記した際の 2^k ( k \geq 0 ) の位の数は、 A, B を二進表記した際の 2^k の位の数のうち一方のみ...
[ { "input": "3 6\n", "output": "2\n" }, { "input": "1 100\n", "output": "124\n" }, { "input": "999000000 1000000000\n", "output": "1726239\n" } ]
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_d
問題文 (0,1,\cdots,N-1) の順列 P=(P_0,P_1,\cdots,P_{N-1}) が与えられます. 整数 a,b ( 0 \leq a,b \leq N-1 ) に対して,順列 f(a,b) を次のように定義します. f(a,b)=(q_0,q_1,\cdots,q_{N-1}) とおいて, q_{(i+a \pmod N)}=(P_i+b \pmod N) ( 0 \leq i \leq N-1 ) と定める. すべての a,b に対し f(a,b) を求めると, N^2 個の順列が得られます. これらの順列を辞書順でソートすることを考えます. ソートしたあと,先頭から K 番目に位置している順列を求めてくだ...
[ { "input": "2 2\n0 1\n", "output": "0 1\n" }, { "input": "4 6\n0 2 1 3\n", "output": "1 2 0 3\n" }, { "input": "10 79\n6 5 9 8 7 1 3 2 0 4\n", "output": "7 9 8 2 1 0 4 6 5 3\n" } ]
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_e
問題文 0 , 1 からなる長さ N の整数列 A=(A_1,A_2,\cdots,A_N) が与えられます. 今,二次元平面上の座標 (0,0) の点に駒があります. あなたはこれから,以下の操作を好きな回数繰り返します. 整数 x,y ( 1 \leq x,y \leq N ) を選び,駒の X , Y 座標をそれぞれ x , y ずつ増やす. ただしここで,以下の 2 つの条件を満たす必要がある. A_x=1 が成立. 操作後の駒の座標を (p,q) とおくとき, q \leq p が成立. 最終的に駒が座標 (N,N) へと至るような操作方法が何通りあるかを 998244353 で割ったあまりを求めてください.
[ { "input": "2\n1 1\n", "output": "2\n" }, { "input": "1\n0\n", "output": "0\n" }, { "input": "4\n1 1 0 1\n", "output": "10\n" }, { "input": "25\n1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 0\n", "output": "934946952\n" } ]
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_f
問題文 A , B からなる長さ N の文字列 S が与えられます. あなたは,以下の操作を 0 回以上繰り返すことができます. S 中の連続する 2 文字であって, AB で ない ものを選び,消す. その後,残った左右の(空かもしれない)文字列を連結し,これを新たに S とする. 操作後の S としてあり得る文字列が何通りあるかを 998244353 で割ったあまりを求めてください.
[ { "input": "3\nBBA\n", "output": "3\n" }, { "input": "5\nABABA\n", "output": "3\n" }, { "input": "9\nBABBAAAAB\n", "output": "14\n" }, { "input": "48\nAABABBBAABAAABAAABBBAAABBBAABAABBABAABBAAAAABBBB\n", "output": "3073910\n" } ]
https://atcoder.jp/contests/toyota2023spring-final/tasks/toyota2023spring_final_g
問題文 プログラミング初心者のすぬけくんが,以下のようなコードを書きました. N = read_integer() parent = array(N, -1) //長さ N の配列 parent を作り,すべての要素を -1 で初期化 find(v): if parent[v] == -1: return v else: return find(parent[v]) union(a,b): parent[find(b)] = find(a) for i = 0 to N-2: A_i = read_integer() B_i = read_integer...
[ { "input": "2\n0 1\n", "output": "2\n" }, { "input": "3\n0 1\n0 2\n", "output": "5\n" }, { "input": "5\n0 1\n0 2\n0 3\n3 4\n", "output": "13\n" }, { "input": "20\n6 16\n10 6\n16 8\n1 5\n9 4\n5 3\n13 16\n19 10\n12 2\n14 10\n12 18\n0 2\n15 16\n12 7\n11 14\n1 10\n6 4\n17 8\n12 1...