結果
問題 | No.2428 Returning Shuffle |
ユーザー | miya145592 |
提出日時 | 2023-08-18 23:31:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,132 ms / 2,000 ms |
コード長 | 2,457 bytes |
コンパイル時間 | 385 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 303,528 KB |
最終ジャッジ日時 | 2024-05-06 06:18:46 |
合計ジャッジ時間 | 7,403 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 277 ms
141,056 KB |
testcase_01 | AC | 1,132 ms
303,444 KB |
testcase_02 | AC | 1,110 ms
303,528 KB |
testcase_03 | AC | 38 ms
53,428 KB |
testcase_04 | AC | 38 ms
54,736 KB |
testcase_05 | AC | 37 ms
53,444 KB |
testcase_06 | AC | 37 ms
54,132 KB |
testcase_07 | AC | 38 ms
53,608 KB |
testcase_08 | AC | 37 ms
53,408 KB |
testcase_09 | AC | 37 ms
54,668 KB |
testcase_10 | AC | 36 ms
53,264 KB |
testcase_11 | AC | 37 ms
53,676 KB |
testcase_12 | AC | 38 ms
54,872 KB |
testcase_13 | AC | 38 ms
53,728 KB |
testcase_14 | AC | 40 ms
53,864 KB |
testcase_15 | AC | 38 ms
53,724 KB |
testcase_16 | AC | 38 ms
55,040 KB |
testcase_17 | AC | 37 ms
53,776 KB |
testcase_18 | AC | 37 ms
54,904 KB |
testcase_19 | AC | 529 ms
206,232 KB |
testcase_20 | AC | 519 ms
205,856 KB |
testcase_21 | AC | 37 ms
53,948 KB |
testcase_22 | AC | 36 ms
53,552 KB |
testcase_23 | AC | 37 ms
54,128 KB |
testcase_24 | AC | 547 ms
268,628 KB |
testcase_25 | AC | 540 ms
269,012 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)