結果
問題 | No.2428 Returning Shuffle |
ユーザー | tassei903 |
提出日時 | 2023-08-15 05:23:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,042 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 268,488 KB |
最終ジャッジ日時 | 2024-11-23 19:58:11 |
合計ジャッジ時間 | 6,377 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 46 ms
54,016 KB |
testcase_04 | AC | 43 ms
53,888 KB |
testcase_05 | AC | 45 ms
54,016 KB |
testcase_06 | WA | - |
testcase_07 | AC | 47 ms
54,272 KB |
testcase_08 | AC | 45 ms
54,144 KB |
testcase_09 | WA | - |
testcase_10 | AC | 47 ms
53,888 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 45 ms
53,888 KB |
testcase_15 | AC | 44 ms
53,888 KB |
testcase_16 | AC | 45 ms
54,016 KB |
testcase_17 | AC | 46 ms
53,888 KB |
testcase_18 | AC | 45 ms
54,144 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 45 ms
54,144 KB |
testcase_22 | AC | 44 ms
54,400 KB |
testcase_23 | AC | 44 ms
54,144 KB |
testcase_24 | AC | 607 ms
268,484 KB |
testcase_25 | AC | 611 ms
268,488 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 = list(range(n)) que = [na() for i in range(m)] for i in range(m): t, *s = que[-1-i] s = [i-1 for i in s] x = p[s[0]] for i in range(t-1): p[s[i]] = p[s[i+1]] p[s[-1]] = x #print(p) 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)