実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 100 点
問題文
N 個の文字列 S_1,S_2,\ldots,S_N がこの順番で与えられます。
S_N,S_{N-1},\ldots,S_1 の順番で出力してください。
制約
- 1\leq N \leq 10
- N は整数
- S_i は英小文字、英大文字、数字からなる長さ 1 以上 10 以下の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、S_{N+1-i} を出力せよ。
入力例 1
3 Takahashi Aoki Snuke
出力例 1
Snuke Aoki Takahashi
N=3、S_1= Takahashi
、S_2= Aoki
、S_3= Snuke
です。
よって、Snuke
、Aoki
、Takahashi
の順で出力します。
入力例 2
4 2023 Year New Happy
出力例 2
Happy New Year 2023
与えられる文字列が数字を含むこともあります。
Score : 100 points
Problem Statement
You are given N strings S_1,S_2,\ldots,S_N in this order.
Print S_N,S_{N-1},\ldots,S_1 in this order.
Constraints
- 1\leq N \leq 10
- N is an integer.
- S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print N lines. The i-th (1\leq i \leq N) line should contain S_{N+1-i}.
Sample Input 1
3 Takahashi Aoki Snuke
Sample Output 1
Snuke Aoki Takahashi
We have N=3, S_1= Takahashi
, S_2= Aoki
, and S_3= Snuke
.
Thus, you should print Snuke
, Aoki
, and Takahashi
in this order.
Sample Input 2
4 2023 Year New Happy
Sample Output 2
Happy New Year 2023
The given strings may contain digits.
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 200 点
問題文
この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。
- N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?
制約
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
各テストケースは以下の形式で与えられる。
N A_1 A_2 \dots A_N
出力
T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。
入力例 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
出力例 1
2 1 5 0
この入力は 4 個のテストケースが含まれています。
入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。
Score : 200 points
Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.
- We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?
Constraints
- 1 \leq T \leq 100
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
Each test case is in the following format:
N A_1 A_2 \dots A_N
Output
Print T lines. The i-th line should contain the answer for the i-th test case.
Sample Input 1
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000
Sample Output 1
2 1 5 0
This input contains four test cases.
The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 300 点
問題文
頂点に 1 から N の番号が、辺に 1 から M の番号がついた N 頂点 M 辺の単純無向グラフが与えられます。辺 i は頂点 u_i と頂点 v_i を結んでいます。
グラフに含まれる連結成分の個数を求めてください。
注釈
単純無向グラフ とは、単純で辺に向きの無いグラフのことをいいます。
グラフが 単純 であるとは、グラフが自己ループや多重辺を含まないことをいいます。
あるグラフの 部分グラフ とは、元のグラフのいくつかの頂点といくつかの辺を選んでできるグラフのことをいいます。
グラフが 連結 であるとは、グラフに含まれるすべての頂点同士が辺を経由して互いに行き来できることをいいます。
連結成分 とは、連結な部分グラフのうち、そのグラフを含んだより大きい連結な部分グラフが存在しないものをいいます。
制約
- 1 \leq N \leq 100
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq u_i, v_i \leq N
- 入力で与えられるグラフは単純
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
答えを出力せよ。
入力例 1
5 3 1 2 1 3 4 5
出力例 1
2
与えられるグラフに含まれる連結成分は次の 2 個です。
- 頂点 1, 2, 3 および辺 1, 2 からなる部分グラフ
- 頂点 4, 5 および辺 3 からなる部分グラフ
入力例 2
5 0
出力例 2
5
入力例 3
4 6 1 2 1 3 1 4 2 3 2 4 3 4
出力例 3
1
Score : 300 points
Problem Statement
You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i connects vertex u_i and vertex v_i.
Find the number of connected components in this graph.
Notes
A simple undirected graph is a graph that is simple and has undirected edges.
A graph is simple if and only if it has no self-loop or multi-edge.
A subgraph of a graph is a graph formed from some of the vertices and edges of that graph.
A graph is connected if and only if one can travel between every pair of vertices via edges.
A connected component is a connected subgraph that is not part of any larger connected subgraph.
Constraints
- 1 \leq N \leq 100
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq u_i, v_i \leq N
- The given graph is simple.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print the answer.
Sample Input 1
5 3 1 2 1 3 4 5
Sample Output 1
2
The given graph contains the following two connected components:
- a subgraph formed from vertices 1, 2, 3, and edges 1, 2;
- a subgraph formed from vertices 4, 5, and edge 3.
Sample Input 2
5 0
Sample Output 2
5
Sample Input 3
4 6 1 2 1 3 1 4 2 3 2 4 3 4
Sample Output 3
1
実行時間制限: 3 sec / メモリ制限: 1024 MB
配点 : 400 点
問題文
正整数 N が与えられます。N は、2 つの相異なる素数 p,q を用いて N=p^2q と表せることがわかっています。
p,q を求めてください。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 入力は全て整数
- 1\leq T\leq 10
- 1\leq N \leq 9\times 10^{18}
- N は、2 つの相異なる素数 p,q を用いて N=p^2q と表せる
入力
入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
各テストケースは以下の形式で与えられる。
N
出力
T 行出力せよ。
i\ (1\leq i \leq T) 行目には、i 番目のテストケースにおける p,q を空白区切りで出力せよ。 なお、この問題の制約下では、N=p^2q を満たす素数 p,q の組は 1 通りしか存在しないことが証明できる。
入力例 1
3 2023 63 1059872604593911
出力例 1
17 7 3 7 104149 97711
1 番目のテストケースについて、N=2023=17^2\times 7 です。よって、p=17,q=7 です。
Score : 400 points
Problem Statement
You are given a positive integer N. It is known that N can be represented as N=p^2q using two different prime numbers p and q.
Find p and q.
You have T test cases to solve.
Constraints
- All values in the input are integers.
- 1\leq T\leq 10
- 1\leq N \leq 9\times 10^{18}
- N can be represented as N=p^2q using two different prime numbers p and q.
Input
The input is given from Standard Input in the following format, where \text{test}_i represents the i-th test case:
T \text{test}_1 \text{test}_2 \vdots \text{test}_T
Each test case is in the following format:
N
Output
Print T lines.
The i-th (1\leq i \leq T) line should contain p and q for the i-th test case, separated by a space. Under the constraints of this problem, it can be proved that the pair of prime numbers p and q such that N=p^2q is unique.
Sample Input 1
3 2023 63 1059872604593911
Sample Output 1
17 7 3 7 104149 97711
For the first test case, we have N=2023=17^2\times 7. Thus, p=17 and q=7.
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 500 点
問題文
頂点に 1 から N の番号が、辺に 1 から M の番号がついた N 頂点 M 辺の単純無向グラフが与えられます。辺 i は頂点 u_i と頂点 v_i を結んでいます。また、各頂点の次数は 10 以下です。
頂点 1 を始点とする単純パス(同じ頂点を複数回通らないパス)の個数を K とします。\min(K, 10^6) を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \left(2 \times 10^5, \frac{N(N-1)}{2}\right)
- 1 \leq u_i, v_i \leq N
- 入力で与えられるグラフは単純グラフ
- 入力で与えられるグラフの頂点の次数はすべて 10 以下
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
答えを出力せよ。
入力例 1
4 2 1 2 2 3
出力例 1
3
条件を満たすパスは次の 3 個です。(長さが 0 のパスも数えるのに注意してください。)
- 頂点 1
- 頂点 1, 頂点 2
- 頂点 1, 頂点 2, 頂点 3
入力例 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
出力例 2
16
入力例 3
8 21 2 6 1 3 5 6 3 8 3 6 4 7 4 6 3 4 1 5 2 4 1 2 2 7 1 4 3 5 2 5 2 3 4 5 3 7 6 7 5 7 2 8
出力例 3
2023
Score : 500 points
Problem Statement
You are given a simple undirected graph with N vertices numbered 1 to N and M edges numbered 1 to M. Edge i connects vertex u_i and vertex v_i. The degree of each vertex is at most 10.
Let K be the number of simple paths (paths without repeated vertices) starting from vertex 1. Print \min(K, 10^6).
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \left(2 \times 10^5, \frac{N(N-1)}{2}\right)
- 1 \leq u_i, v_i \leq N
- The given graph is simple.
- The degree of each vertex in the given graph is at most 10.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
Output
Print the answer.
Sample Input 1
4 2 1 2 2 3
Sample Output 1
3
We have the following three paths that count. (Note that a path of length 0 also counts.)
- Vertex 1;
- vertex 1, vertex 2;
- vertex 1, vertex 2, vertex 3.
Sample Input 2
4 6 1 2 1 3 1 4 2 3 2 4 3 4
Sample Output 2
16
Sample Input 3
8 21 2 6 1 3 5 6 3 8 3 6 4 7 4 6 3 4 1 5 2 4 1 2 2 7 1 4 3 5 2 5 2 3 4 5 3 7 6 7 5 7 2 8
Sample Output 3
2023
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 500 点
問題文
長さ N の文字列 S および整数 i\ (0\leq i\leq N) に対して、f_i(S) を、
- S の先頭 i 文字
- S を反転した文字列
- S の末尾 N-i 文字
をこの順に連結した文字列と定義します。
例えば、S= abc
、i=2 のとき、f_i(S)= abcbac
です。
長さ 2N の文字列 T が与えられます。 f_i(S)=T を満たす長さ N の文字列 S と整数 i\ (0\leq i\leq N) の組を 1 つ見つけてください。 そのような S,i の組が存在しない場合は、それを報告してください。
制約
- 1\leq N \leq 10^6
- N は整数
- T は英小文字からなる長さ 2N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N T
出力
条件を満たす S,i の組が存在しないならば、-1
と出力せよ。
存在するならば、S,i を改行区切りで出力せよ。
条件を満たす S,i の組が複数存在する場合は、そのどれを出力しても良い。
入力例 1
3 abcbac
出力例 1
abc 2
問題文中に書いた通り、S= abc
、i=2 とすると f_i(S)= abcbac
となって T に一致するため、abc
と 2 を出力します。
入力例 2
4 abababab
出力例 2
abab 1
S= abab
、i=3 としても条件を満たします。
入力例 3
3 agccga
出力例 3
cga 0
S= agc
、i=3 としても条件を満たします。
入力例 4
4 atcodeer
出力例 4
-1
条件を満たす S,i の組が存在しない場合は -1
を出力してください。
Score : 500 points
Problem Statement
For a string S of length N and an integer i\ (0\leq i\leq N), let us define the string f_i(S) as the concatenation of:
- the first i characters of S,
- the reversal of S, and
- the last (N-i) characters of S,
in this order.
For instance, if S= abc
and i=2, we have f_i(S)= abcbac
.
You are given a string T of length 2N. Find a pair of a string S of length N and an integer i\ (0\leq i\leq N) such that f_i(S)=T. If no such pair of S and i exists, report that fact.
Constraints
- 1\leq N \leq 10^6
- N is an integer.
- T is a string of length 2N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N T
Output
If no pair of S and i satisfies the condition, print -1
.
Otherwise, print S and i, separated by a newline.
If multiple pairs of S and i satisfy the condition, you may print any of them.
Sample Input 1
3 abcbac
Sample Output 1
abc 2
As mentioned in the problem statement, if S= abc
and i=2, we have f_i(S)= abcbac
, which equals T, so you should print abc
and 2.
Sample Input 2
4 abababab
Sample Output 2
abab 1
S= abab
and i=3 also satisfy the condition.
Sample Input 3
3 agccga
Sample Output 3
cga 0
S= agc
and i=3 also satisfy the condition.
Sample Input 4
4 atcodeer
Sample Output 4
-1
If no pair of S and i satisfies the condition, print -1
.
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 600 点
問題文
1 以上 N 以下の整数からなる長さ N の数列 A = (A_1,A_2,\dots,A_N) および整数 i\ (1\leq i \leq N) に対して、 長さ 10^{100} の数列 B_i=(B_{i,1},B_{i,2},\dots,B_{i,10^{100}}) を以下のように定義します。
- B_{i,1}=i
- B_{i,j+1}=A_{B_{i,j}}\ (1\leq j<10^{100})
また、S_i を「数列 B_i のなかでちょうど 1 度だけ出てくる数の種類数」と定義します。 より厳密には、S_i は「B_{i,j}=k を満たす j\ (1\leq j\leq 10^{100}) がちょうど 1 つであるような k の数」です。
整数 N が与えられます。数列 A として考えられるものは N^N 通りありますが、それら全てに対して \displaystyle \sum_{i=1}^{N} S_i を求め、 その総和を M で割った余りを答えてください。
制約
- 1\leq N \leq 2\times 10^5
- 10^8\leq M \leq 10^9
- N,M は整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを整数として出力せよ。
入力例 1
4 100000000
出力例 1
624
例として、A=(2,3,3,4) の場合を考えます。
- i=1 のとき : B_1=(1,2,3,3,3,\dots) となるから、1 度だけ出てくる数は 1,2 の 2 つで、S_1=2
- i=2 のとき : B_2=(2,3,3,3,\dots) となるから、1 度だけ出てくる数は 2 のみで、S_2=1
- i=3 のとき : B_3=(3,3,3,\dots) となるから、1 度だけ出てくる数は存在せず、S_3=0
- i=4 のとき : B_4=(4,4,4,\dots) となるから、1 度だけ出てくる数は存在せず、S_4=0
よって、\displaystyle \sum_{i=1}^{N} S_i=2+1+0+0=3 です。
他の 255 通りの A に対しても同様に \displaystyle \sum_{i=1}^{N} S_i を計算したうえで、 256 通り全ての総和をとると 624 になります。
入力例 2
7 1000000000
出力例 2
5817084
入力例 3
2023 998244353
出力例 3
737481389
総和を M で割った余りを出力してください。
入力例 4
100000 353442899
出力例 4
271798911
Score : 600 points
Problem Statement
For a sequence of length N, A = (A_1,A_2,\dots,A_N), consisting of integers between 1 and N, inclusive, and an integer i\ (1\leq i \leq N), let us define a sequence of length 10^{100}, B_i=(B_{i,1},B_{i,2},\dots,B_{i,10^{100}}), as follows.
- B_{i,1}=i.
- B_{i,j+1}=A_{B_{i,j}}\ (1\leq j<10^{100}).
Additionally, let us define S_i as the number of distinct integers that occur exactly once in the sequence B_i. More formally, S_i is the number of values k such that exactly one index j\ (1\leq j\leq 10^{100}) satisfies B_{i,j}=k.
You are given an integer N. There are N^N sequences that can be A. Find the sum of \displaystyle \sum_{i=1}^{N} S_i over all of them, modulo M.
Constraints
- 1\leq N \leq 2\times 10^5
- 10^8\leq M \leq 10^9
- N and M are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the answer as an integer.
Sample Input 1
4 100000000
Sample Output 1
624
As an example, let us consider the case A=(2,3,3,4).
- For i=1: we have B_1=(1,2,3,3,3,\dots), where two integers, 1 and 2, occur exactly once, so S_1=2.
- For i=2: we have B_2=(2,3,3,3,\dots), where one integer, 2, occurs exactly once, so S_2=1.
- For i=3: we have B_3=(3,3,3,\dots), where no integers occur exactly once, so S_3=0.
- For i=4: we have B_4=(4,4,4,\dots), where no integers occur exactly once, so S_4=0.
Thus, we have \displaystyle \sum_{i=1}^{N} S_i=2+1+0+0=3.
If we similarly compute \displaystyle \sum_{i=1}^{N} S_i for the other 255 sequences, the sum of this value over all 256 sequences is 624.
Sample Input 2
7 1000000000
Sample Output 2
5817084
Sample Input 3
2023 998244353
Sample Output 3
737481389
Print the sum modulo M.
Sample Input 4
100000 353442899
Sample Output 4
271798911
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 600 点
問題文
あなたは次の一連の操作によってグラフを生成します。
- 頂点ラベルのない N 頂点の単純無向グラフを 1 つ自由に選ぶ。
- グラフの各頂点に K 以下の正整数を 1 個ずつ書きこむ。ただし、K 以下の正整数であってどの頂点にも書きこまれない数が存在してはならない。
操作によって得られるグラフとしてあり得るものの個数を \text{mod }P で数え上げてください。(P は素数)
ただし、2 つのグラフは、以下の条件を満たすようにそれぞれのグラフの頂点に頂点ラベル v_1, v_2, \dots, v_N をつけられる場合に同じグラフであるとみなします。
- 1 \leq i \leq N であるすべての i について、頂点 v_i に書きこまれた数が 2 つのグラフの間で一致している。
- 1 \leq i \lt j \leq N であるすべての (i, j) について、v_iv_j 間の辺の有無が 2 つのグラフの間で一致している。
制約
- 1 \leq K \leq N \leq 30
- 10^8 \leq P \leq 10^9
- P は素数
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K P
出力
答えを出力せよ。
入力例 1
3 1 998244353
出力例 1
4
条件を満たすグラフは次の 4 通りです。
入力例 2
3 2 998244353
出力例 2
12
条件を満たすグラフは次の 12 通りです。
入力例 3
5 5 998244353
出力例 3
1024
入力例 4
30 15 202300013
出力例 4
62712469
Score : 600 points
Problem Statement
You are to generate a graph by the following procedure.
- Choose a simple undirected graph with N unlabeled vertices.
- Write a positive integer at most K in each vertex in the graph. Here, there must not be a positive integer at most K that is not written in any vertex.
Find the number of possible graphs that can be obtained, modulo P. (P is a prime.)
Two graphs are considered the same if and only if one can label the vertices in each graph as v_1, v_2, \dots, v_N to satisfy the following conditions.
- For every i such that 1 \leq i \leq N, the numbers written in vertex v_i in the two graphs are the same.
- For every i and j such that 1 \leq i \lt j \leq N, there is an edge between v_i and v_j in one of the graphs if and only if there is an edge between v_i and v_j in the other graph.
Constraints
- 1 \leq K \leq N \leq 30
- 10^8 \leq P \leq 10^9
- P is a prime.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N K P
Output
Print the answer.
Sample Input 1
3 1 998244353
Sample Output 1
4
The following four graphs satisfy the condition.
Sample Input 2
3 2 998244353
Sample Output 2
12
The following 12 graphs satisfy the condition.
Sample Input 3
5 5 998244353
Sample Output 3
1024
Sample Input 4
30 15 202300013
Sample Output 4
62712469