結果

問題 No.1885 Flat Permutation
ユーザー maimai
提出日時 2022-03-25 23:15:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-22 08:10:59
合計ジャッジ時間 7,839 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,160 KB
testcase_01 AC 78 ms
12,032 KB
testcase_02 AC 76 ms
12,032 KB
testcase_03 AC 82 ms
12,160 KB
testcase_04 AC 75 ms
12,160 KB
testcase_05 AC 78 ms
12,160 KB
testcase_06 AC 76 ms
12,160 KB
testcase_07 AC 78 ms
12,032 KB
testcase_08 AC 80 ms
12,160 KB
testcase_09 AC 79 ms
12,032 KB
testcase_10 AC 78 ms
12,160 KB
testcase_11 AC 77 ms
12,160 KB
testcase_12 AC 76 ms
12,032 KB
testcase_13 AC 79 ms
12,032 KB
testcase_14 AC 76 ms
11,904 KB
testcase_15 AC 76 ms
12,160 KB
testcase_16 AC 78 ms
12,032 KB
testcase_17 AC 78 ms
12,032 KB
testcase_18 AC 79 ms
11,904 KB
testcase_19 AC 179 ms
12,032 KB
testcase_20 AC 177 ms
12,032 KB
testcase_21 AC 178 ms
12,288 KB
testcase_22 AC 166 ms
12,160 KB
testcase_23 AC 77 ms
12,032 KB
testcase_24 AC 75 ms
11,904 KB
testcase_25 AC 77 ms
12,032 KB
testcase_26 AC 75 ms
11,904 KB
testcase_27 AC 178 ms
12,160 KB
testcase_28 AC 176 ms
12,032 KB
testcase_29 AC 177 ms
12,032 KB
testcase_30 AC 177 ms
12,032 KB
testcase_31 AC 175 ms
12,032 KB
testcase_32 AC 77 ms
11,904 KB
testcase_33 AC 74 ms
12,160 KB
testcase_34 AC 75 ms
12,032 KB
testcase_35 AC 179 ms
12,160 KB
testcase_36 AC 177 ms
12,288 KB
testcase_37 AC 81 ms
11,904 KB
testcase_38 AC 79 ms
11,904 KB
testcase_39 AC 84 ms
12,032 KB
testcase_40 AC 97 ms
12,160 KB
testcase_41 AC 123 ms
12,160 KB
testcase_42 AC 89 ms
12,160 KB
testcase_43 AC 181 ms
12,160 KB
testcase_44 AC 185 ms
12,160 KB
testcase_45 AC 184 ms
12,288 KB
testcase_46 AC 179 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def lscan; gets.split.map(&:to_i); end


def fibo(n)
  return 1 if n <= 0
  a1 = 1
  a2 = 0
  a3 = 0
  n.times do
    b1 = a2 + a1
    b2 = a3 + 0
    b3 =  0 + a1
    a1,a2,a3=[b1,b2,b3].map{|x| x%998244353}
    # p [a1,a2,a3]
  end
  a1
end

def solve(n,x,y)
  return 1 if n <= 2
  return solve(n,y,x) if x > y
  
  x -= 1 if x == 1
  y += 1 if y == n
  
  return 0 if y - x <= 1
  
  fibo(y-x-2)
end


n,x,y = lscan

# (1..n).each do |x|
#   (1..n).each do |y|

# a = (1..n).to_a.permutation(n).count {|li|
#   li[0] == x && li[-1] == y && li.each_cons(2).all?{|a, b| (a-b).abs <= 2}
# }

# a -= solve(n,x,y)

# printf "%3d", a
# end
# puts
# end

p solve(n,x,y)
0