結果

問題 No.2045 Two Reflections
ユーザー tamatotamato
提出日時 2022-08-19 23:20:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 79,500 KB
最終ジャッジ日時 2024-04-17 01:56:04
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,352 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 82 ms
76,944 KB
testcase_03 AC 64 ms
78,156 KB
testcase_04 WA -
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 35 ms
51,968 KB
testcase_07 AC 68 ms
77,260 KB
testcase_08 WA -
testcase_09 AC 33 ms
52,224 KB
testcase_10 AC 33 ms
52,224 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 31 ms
52,736 KB
testcase_14 AC 32 ms
52,480 KB
testcase_15 AC 34 ms
52,224 KB
testcase_16 WA -
testcase_17 AC 44 ms
52,224 KB
testcase_18 AC 56 ms
79,496 KB
testcase_19 AC 54 ms
79,500 KB
testcase_20 AC 31 ms
52,352 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 69 ms
77,184 KB
testcase_29 AC 70 ms
77,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, p, q = map(int, input().split())

    if p + q <= N:
        if p == q == 1:
            print(1)
        elif p == 1 or q == 1:
            print(2)
        else:
            print(4)
        exit()

    if p == q == N:
        print(2)
        exit()

    UF = UnionFind(N)
    for i in range(1, p+1):
        if i * 2 >= p + 1:
            break
        UF.unite(i, p + 1 - i)
    for i in range(1, q+1):
        if i * 2 >= q + 1:
            break
        UF.unite(N - i + 1, N - q + i)

    S = []
    for i in range(1, N+1):
        if i == UF.find_root(i):
            S.append(UF.size(i))
    S = list(set(S))
    S.sort(reverse=True)
    ans = 1
    for s in S:
        ans = (ans * s) % mod
    if len(S) > 1:
        ans = (ans * 2) % mod
    print(ans)


if __name__ == '__main__':
    main()
0