結果

問題 No.2045 Two Reflections
ユーザー とりゐとりゐ
提出日時 2022-08-20 00:38:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 77,784 KB
最終ジャッジ日時 2024-04-17 03:05:03
合計ジャッジ時間 2,810 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,144 KB
testcase_01 AC 37 ms
54,016 KB
testcase_02 AC 77 ms
77,124 KB
testcase_03 AC 72 ms
77,312 KB
testcase_04 AC 78 ms
77,008 KB
testcase_05 AC 69 ms
76,672 KB
testcase_06 AC 61 ms
70,912 KB
testcase_07 AC 88 ms
77,276 KB
testcase_08 AC 111 ms
77,784 KB
testcase_09 AC 74 ms
75,264 KB
testcase_10 AC 71 ms
75,264 KB
testcase_11 AC 81 ms
76,868 KB
testcase_12 AC 36 ms
54,144 KB
testcase_13 AC 35 ms
53,632 KB
testcase_14 AC 34 ms
53,760 KB
testcase_15 AC 34 ms
54,400 KB
testcase_16 AC 35 ms
54,400 KB
testcase_17 AC 34 ms
54,016 KB
testcase_18 AC 35 ms
53,632 KB
testcase_19 AC 35 ms
54,272 KB
testcase_20 AC 34 ms
53,888 KB
testcase_21 AC 75 ms
77,288 KB
testcase_22 AC 75 ms
77,568 KB
testcase_23 AC 76 ms
77,184 KB
testcase_24 AC 78 ms
77,312 KB
testcase_25 AC 76 ms
77,132 KB
testcase_26 AC 76 ms
76,916 KB
testcase_27 AC 76 ms
76,928 KB
testcase_28 AC 76 ms
77,224 KB
testcase_29 AC 77 ms
77,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd

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

n,p,q=map(int,input().split())
p,q=min(p,q),max(p,q)
if p==q==1:
  print(1)
  exit()
if p==1 or p==q==n:
  print(2)
  exit()

uf=UnionFind(n)
for i in range(p):
  uf.union(i,p-1-i)
for i in range(q):
  uf.union(n-q+i,n-1-i)

lcm=1
for i in range(n):
  lcm=lcm*uf.size(i)//gcd(lcm,uf.size(i))

print(lcm*2%998244353)
0