結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,968 KB
testcase_01 AC 42 ms
52,096 KB
testcase_02 AC 96 ms
77,568 KB
testcase_03 AC 84 ms
77,824 KB
testcase_04 WA -
testcase_05 AC 41 ms
51,968 KB
testcase_06 AC 42 ms
52,096 KB
testcase_07 AC 96 ms
77,676 KB
testcase_08 WA -
testcase_09 AC 41 ms
52,224 KB
testcase_10 AC 42 ms
52,224 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 42 ms
52,352 KB
testcase_14 AC 42 ms
51,712 KB
testcase_15 AC 42 ms
52,224 KB
testcase_16 AC 42 ms
52,480 KB
testcase_17 AC 42 ms
52,224 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 43 ms
52,096 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 95 ms
77,056 KB
testcase_29 AC 96 ms
77,440 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))
    ans = 2
    for s in S:
        ans = (ans * s) % mod
    print(ans)


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