結果

問題 No.2045 Two Reflections
ユーザー tamatotamato
提出日時 2022-08-19 23:15:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 79,488 KB
最終ジャッジ日時 2024-04-17 01:53:05
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
51,840 KB
testcase_01 AC 48 ms
52,224 KB
testcase_02 AC 107 ms
77,312 KB
testcase_03 AC 93 ms
77,824 KB
testcase_04 AC 100 ms
77,480 KB
testcase_05 AC 47 ms
52,096 KB
testcase_06 AC 47 ms
51,840 KB
testcase_07 AC 104 ms
77,716 KB
testcase_08 WA -
testcase_09 AC 47 ms
52,096 KB
testcase_10 AC 46 ms
52,224 KB
testcase_11 AC 90 ms
76,032 KB
testcase_12 WA -
testcase_13 AC 46 ms
52,096 KB
testcase_14 AC 47 ms
52,352 KB
testcase_15 AC 47 ms
51,712 KB
testcase_16 WA -
testcase_17 AC 46 ms
52,224 KB
testcase_18 AC 89 ms
79,488 KB
testcase_19 AC 87 ms
79,488 KB
testcase_20 AC 47 ms
51,968 KB
testcase_21 AC 105 ms
77,056 KB
testcase_22 AC 107 ms
76,672 KB
testcase_23 AC 107 ms
76,800 KB
testcase_24 AC 106 ms
76,928 KB
testcase_25 AC 105 ms
76,544 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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[:2]:
        ans = (ans * s) % mod
    if len(S) > 1:
        ans = (ans * 2) % mod
    print(ans)


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