結果
問題 | No.2428 Returning Shuffle |
ユーザー | miya145592 |
提出日時 | 2023-08-18 23:31:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,038 ms / 2,000 ms |
コード長 | 2,457 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 303,536 KB |
最終ジャッジ日時 | 2024-11-28 10:56:16 |
合計ジャッジ時間 | 6,809 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 275 ms
141,216 KB |
testcase_01 | AC | 1,038 ms
303,536 KB |
testcase_02 | AC | 1,028 ms
303,268 KB |
testcase_03 | AC | 34 ms
52,352 KB |
testcase_04 | AC | 34 ms
52,992 KB |
testcase_05 | AC | 35 ms
52,992 KB |
testcase_06 | AC | 34 ms
52,608 KB |
testcase_07 | AC | 34 ms
52,992 KB |
testcase_08 | AC | 34 ms
52,992 KB |
testcase_09 | AC | 37 ms
53,120 KB |
testcase_10 | AC | 35 ms
52,992 KB |
testcase_11 | AC | 41 ms
52,864 KB |
testcase_12 | AC | 34 ms
52,736 KB |
testcase_13 | AC | 33 ms
52,864 KB |
testcase_14 | AC | 33 ms
52,608 KB |
testcase_15 | AC | 34 ms
52,736 KB |
testcase_16 | AC | 34 ms
52,992 KB |
testcase_17 | AC | 34 ms
52,864 KB |
testcase_18 | AC | 35 ms
52,864 KB |
testcase_19 | AC | 516 ms
205,996 KB |
testcase_20 | AC | 521 ms
205,744 KB |
testcase_21 | AC | 36 ms
52,480 KB |
testcase_22 | AC | 36 ms
52,608 KB |
testcase_23 | AC | 35 ms
52,992 KB |
testcase_24 | AC | 555 ms
268,528 KB |
testcase_25 | AC | 554 ms
268,348 KB |
ソースコード
class UnionFind: def __init__(self, n, w=None): self.par = [-1]*n self.rank = [0]*n self.siz = [1]*n self.cnt = n self.min_node = [i for i in range(n)] self.weight = w if w else [1]*n def root(self, x): if self.par[x] == -1: return x self.par[x] = self.root(self.par[x]) return self.par[x] def issame(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): px = self.root(x) py = self.root(y) if px == py: return False if self.rank[px] < self.rank[py]: px, py = py, px self.par[py] = px if self.rank[px] == self.rank[py]: self.rank[px] += 1 self.siz[px] += self.siz[py] self.cnt -= 1 self.min_node[px] = min(self.min_node[px], self.min_node[py]) self.weight[px] += self.weight[py] return False def count(self): return self.cnt def min(self, x): return self.min_node[self.root(x)] def getweight(self, x): return self.weight[self.root(x)] def size(self, x): return self.siz[self.root(x)] MOD = 998244353 N, M = map(int, input().split()) T = [] S = [] for _ in range(M): ts = list(map(int, input().split())) T.append(ts[0]) S.append(ts[1:]) dp = [i for i in range(N)] for i in range(M): bk = dp[S[i][0]-1] for j in range(T[i]): bk, dp[S[i][(j+1)%T[i]]-1] = dp[S[i][(j+1)%T[i]]-1], bk seen = [0 for _ in range(N)] UF = UnionFind(N) for i in range(N): now = i if seen[now]: continue st = i seen[now] = 1 while st!=dp[now]: UF.unite(now, dp[now]) now = dp[now] seen[now] = 1 import math d = dict() for i in range(N): r = UF.root(i) d[r] = UF.size(r) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr P = dict() for key in d: f = factorization(d[key]) for p, e in f: if p not in P: P[p] = e else: P[p] = max(P[p], e) ans = 1 for p in P: ans *= pow(p, P[p], MOD) ans %= MOD print(ans)