結果
問題 | No.2428 Returning Shuffle |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-08-24 21:02:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,134 ms / 2,000 ms |
コード長 | 2,913 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 335,400 KB |
最終ジャッジ日時 | 2024-06-02 10:24:15 |
合計ジャッジ時間 | 11,207 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 407 ms
169,600 KB |
testcase_01 | AC | 1,134 ms
244,920 KB |
testcase_02 | AC | 1,130 ms
244,076 KB |
testcase_03 | AC | 128 ms
97,664 KB |
testcase_04 | AC | 125 ms
97,664 KB |
testcase_05 | AC | 134 ms
97,664 KB |
testcase_06 | AC | 125 ms
97,920 KB |
testcase_07 | AC | 129 ms
97,920 KB |
testcase_08 | AC | 125 ms
97,920 KB |
testcase_09 | AC | 124 ms
98,048 KB |
testcase_10 | AC | 123 ms
97,920 KB |
testcase_11 | AC | 126 ms
97,920 KB |
testcase_12 | AC | 126 ms
97,920 KB |
testcase_13 | AC | 125 ms
97,664 KB |
testcase_14 | AC | 123 ms
98,048 KB |
testcase_15 | AC | 125 ms
97,920 KB |
testcase_16 | AC | 124 ms
97,664 KB |
testcase_17 | AC | 125 ms
97,792 KB |
testcase_18 | AC | 125 ms
98,048 KB |
testcase_19 | AC | 874 ms
227,612 KB |
testcase_20 | AC | 890 ms
252,640 KB |
testcase_21 | AC | 131 ms
97,664 KB |
testcase_22 | AC | 131 ms
97,920 KB |
testcase_23 | AC | 151 ms
99,712 KB |
testcase_24 | AC | 855 ms
335,400 KB |
testcase_25 | AC | 848 ms
335,264 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) class DSU: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] class prime_factorize(): def __init__(self,M=10**6): self.sieve = [-1]*(M+1) self.sieve[1] = 1 self.p = [False]*(M+1) self.mu = [1]*(M+1) for i in range(2,M+1): if self.sieve[i] == -1: self.p[i] = True i2 = i**2 for j in range(i2,M+1,i2): self.mu[j] = 0 for j in range(i,M+1,i): self.sieve[j] = i self.mu[j] *= -1 def factors(self,x): tmp = [] while self.sieve[x] != x: tmp.append(self.sieve[x]) x //= self.sieve[x] tmp.append(self.sieve[x]) return tmp def is_prime(self,x): return self.p[x] def mobius(self,x): return self.mu[x] pf = prime_factorize() X = [i for i in range(N)] for _ in range(M): t,*S = map(int,input().split()) Y = [] for j in range(t): s0 = S[j]-1 # s1 = S[(j+1)%t]-1 Y.append(X[s0]) for j in range(t): s1 = S[(j+1)%t]-1 X[s1] = Y[j] # print(X) D = DSU(N) for i,s in enumerate(X): D.merge(i,s) X = [len(g) for g in D.groups()] V = defaultdict(int) for x in X: for k,v in Counter(pf.factors(x)).items(): V[k] = max(V[k],v) mod = 998244353 ans = 1 for k,v in V.items(): ans *= pow(k,v,mod) ans %= mod print(ans)