結果

問題 No.554 recurrence formula
ユーザー ueyukiueyuki
提出日時 2017-09-22 05:38:53
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 167 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 148,316 KB
最終ジャッジ日時 2023-08-08 14:14:55
合計ジャッジ時間 6,142 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 79 ms
15,300 KB
testcase_02 AC 78 ms
15,128 KB
testcase_03 AC 77 ms
15,280 KB
testcase_04 AC 78 ms
15,268 KB
testcase_05 AC 78 ms
15,064 KB
testcase_06 AC 78 ms
15,148 KB
testcase_07 AC 79 ms
15,264 KB
testcase_08 AC 79 ms
15,076 KB
testcase_09 AC 78 ms
15,220 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 TLE -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i

a = [0, 1]
ans = 0

2.upto(n) do |i|
  ans = i * ((i % 2 == 0) ? a[1] : a[0])
  (i % 2 == 0) ? a[0] = ans + a[0] : a[1] = ans + a[1]
end

puts ans
0