結果

問題 No.1885 Flat Permutation
ユーザー maimai
提出日時 2022-03-25 23:15:57
言語 Ruby
(3.2.2)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 11,512 KB
実行使用メモリ 15,408 KB
最終ジャッジ日時 2023-08-04 10:29:42
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,296 KB
testcase_01 AC 76 ms
15,096 KB
testcase_02 AC 75 ms
15,092 KB
testcase_03 AC 81 ms
15,156 KB
testcase_04 AC 74 ms
15,040 KB
testcase_05 AC 74 ms
15,196 KB
testcase_06 AC 82 ms
15,136 KB
testcase_07 AC 75 ms
15,044 KB
testcase_08 AC 74 ms
15,156 KB
testcase_09 AC 73 ms
15,136 KB
testcase_10 AC 73 ms
15,296 KB
testcase_11 AC 74 ms
15,124 KB
testcase_12 AC 75 ms
15,044 KB
testcase_13 AC 74 ms
15,256 KB
testcase_14 AC 75 ms
15,044 KB
testcase_15 AC 69 ms
15,196 KB
testcase_16 AC 71 ms
15,228 KB
testcase_17 AC 72 ms
15,096 KB
testcase_18 AC 77 ms
15,048 KB
testcase_19 AC 175 ms
15,252 KB
testcase_20 AC 172 ms
15,252 KB
testcase_21 AC 177 ms
15,384 KB
testcase_22 AC 163 ms
15,164 KB
testcase_23 AC 75 ms
15,184 KB
testcase_24 AC 76 ms
15,268 KB
testcase_25 AC 77 ms
15,160 KB
testcase_26 AC 73 ms
15,052 KB
testcase_27 AC 168 ms
15,124 KB
testcase_28 AC 171 ms
15,208 KB
testcase_29 AC 174 ms
15,196 KB
testcase_30 AC 173 ms
15,272 KB
testcase_31 AC 181 ms
15,188 KB
testcase_32 AC 75 ms
15,064 KB
testcase_33 AC 75 ms
15,228 KB
testcase_34 AC 76 ms
15,220 KB
testcase_35 AC 176 ms
15,132 KB
testcase_36 AC 170 ms
15,160 KB
testcase_37 AC 75 ms
15,164 KB
testcase_38 AC 74 ms
15,096 KB
testcase_39 AC 74 ms
15,132 KB
testcase_40 AC 91 ms
15,208 KB
testcase_41 AC 124 ms
15,300 KB
testcase_42 AC 84 ms
15,408 KB
testcase_43 AC 175 ms
15,248 KB
testcase_44 AC 175 ms
15,160 KB
testcase_45 AC 172 ms
15,252 KB
testcase_46 AC 175 ms
15,344 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