結果

問題 No.2045 Two Reflections
ユーザー tomerun
提出日時 2022-08-19 22:16:27
言語 Crystal
(1.14.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 13,344 ms
コンパイル使用メモリ 301,704 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-10-08 09:07:14
合計ジャッジ時間 14,391 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

require "big"
MOD = 998244353i64
n, p, q = read_line.split.map(&.to_i)
if p == 1 && q == 1
  puts 1
  exit
elsif p == 1 || q == 1
  puts 2
  exit
elsif p + q <= n
  puts 4
  exit
end
a = Array.new(n) { |i| i }
a_orig = a.dup
a[...p] = a[...p].reverse
a[-q..] = a[-q..].reverse
ans = BigInt.new(1)
visited = Array.new(n, false)
n.times do |i|
  next if visited[i]
  cur = i
  len = 0
  while !visited[cur]
    visited[cur] = true
    len += 1
    cur = a[cur]
  end
  ans = ans.lcm(BigInt.new(len))
end
puts ans * 2 % MOD
0