結果
問題 | No.2428 Returning Shuffle |
ユーザー | Akijin_007 |
提出日時 | 2023-08-18 22:22:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 938 ms / 2,000 ms |
コード長 | 1,379 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 268,060 KB |
最終ジャッジ日時 | 2024-11-28 08:05:38 |
合計ジャッジ時間 | 7,719 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#int(input()) #map(int, input().split()) #list(map(int, input().split())) N, M = map(int, input().split()) T = [0] * M S = [0] * M for i in range(M): a = list(map(int, input().split())) T[i] = a[0] for j in range(a[0]): a[j+1] -= 1 S[i] = a[1:] mod = 998244353 # print(S[i]) l = list(range(N)) nl = list(range(N)) for i in range(M): t = T[i] u = l[S[i][t-2]] for j in range(t-2, -1, -1): l[S[i][(j)%t]] = l[S[i][(j-1)%t]] # l = list(nl) l[S[i][t-1]] = u v = [-1] * N u = [] # print(l) for i in range(N): if v[i] == -1: q = l[i] c = 1 v[i] = 1 while q != i: v[q] = 1 c += 1 q = l[q] u.append(c) # print(i, v, u) # print(l) # print(u) B = 10 ** 6 + 10 p = [-1] * B for i in range(2, B): if p[i] != -1: continue for j in range(B): if i * j >= B: break p[i*j] = i def prime_factorize(n): a = [] while n != 1: u = p[n] a.append(u) n //= u return a from collections import Counter ps = dict() for x in u: c = Counter(prime_factorize(x)) for k, v in c.items(): if k not in ps: ps[k] = v else: ps[k] = max(ps[k], v) # print(ps) ans = 1 for k, v in ps.items(): ans = (ans * pow(k, v, mod)) % mod print(ans)