結果
問題 | No.2428 Returning Shuffle |
ユーザー | tassei903 |
提出日時 | 2023-08-15 05:33:14 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,135 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 276,224 KB |
最終ジャッジ日時 | 2024-11-23 19:58:27 |
合計ジャッジ時間 | 6,389 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 41 ms
54,272 KB |
testcase_04 | AC | 40 ms
54,656 KB |
testcase_05 | AC | 39 ms
53,888 KB |
testcase_06 | WA | - |
testcase_07 | AC | 40 ms
54,272 KB |
testcase_08 | AC | 41 ms
54,144 KB |
testcase_09 | WA | - |
testcase_10 | AC | 41 ms
54,656 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 41 ms
54,144 KB |
testcase_15 | AC | 39 ms
54,272 KB |
testcase_16 | AC | 40 ms
54,144 KB |
testcase_17 | AC | 40 ms
53,888 KB |
testcase_18 | AC | 40 ms
54,144 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 40 ms
54,272 KB |
testcase_22 | AC | 42 ms
54,656 KB |
testcase_23 | AC | 39 ms
54,144 KB |
testcase_24 | AC | 603 ms
276,224 KB |
testcase_25 | AC | 601 ms
275,800 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) n, m = na() p = [i for i in range(n)] pinv = [i for i in range(n)] for i in range(m): t, *s = na() s = [i-1 for i in s] for j in range(t-1): p[pinv[s[j]]] = s[j+1] p[pinv[s[t-1]]] = s[0] tmp = pinv[s[t-1]] for j in range(t-2,-1,-1): pinv[s[j+1]] = pinv[s[j]] pinv[s[0]] = tmp uf = UnionFind(n) for i in range(n): uf.union(i, p[i]) ans = 1 mod = 998244353 for i in uf.roots(): ans *= uf.size(i) ans %= mod print(ans)