結果

問題 No.831 都市めぐり
ユーザー letrangerjpletrangerjp
提出日時 2019-05-24 21:45:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 990 ms / 2,000 ms
コード長 306 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 11,800 KB
実行使用メモリ 65,708 KB
最終ジャッジ日時 2023-10-17 12:23:25
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,948 KB
testcase_01 AC 79 ms
15,948 KB
testcase_02 AC 79 ms
15,948 KB
testcase_03 AC 79 ms
15,948 KB
testcase_04 AC 78 ms
15,948 KB
testcase_05 AC 78 ms
15,948 KB
testcase_06 AC 80 ms
15,948 KB
testcase_07 AC 80 ms
15,952 KB
testcase_08 AC 83 ms
16,208 KB
testcase_09 AC 80 ms
15,948 KB
testcase_10 AC 84 ms
16,204 KB
testcase_11 AC 85 ms
16,208 KB
testcase_12 AC 124 ms
19,076 KB
testcase_13 AC 115 ms
18,436 KB
testcase_14 AC 122 ms
19,076 KB
testcase_15 AC 453 ms
37,692 KB
testcase_16 AC 233 ms
25,564 KB
testcase_17 AC 526 ms
40,204 KB
testcase_18 AC 661 ms
48,820 KB
testcase_19 AC 952 ms
64,572 KB
testcase_20 AC 990 ms
65,708 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
if N == 1
  p 0
  exit
end

a = [*1..N]

res = []
res << a.shift
loop{
  a.empty? ? break : res << a.pop
  a.empty? ? break : res.unshift(a.pop)
  a.empty? ? break : res << a.shift
  a.empty? ? break : res.unshift(a.shift)
}
res << res[0]
p res.each_cons(2).inject(0){|r,(a,b)|
  r + a * b
}
0