結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー simansiman
提出日時 2021-06-01 12:17:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-04-26 09:47:44
合計ジャッジ時間 6,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
12,288 KB
testcase_01 AC 90 ms
12,160 KB
testcase_02 AC 89 ms
12,288 KB
testcase_03 AC 90 ms
12,160 KB
testcase_04 AC 85 ms
12,288 KB
testcase_05 AC 84 ms
12,160 KB
testcase_06 AC 85 ms
12,288 KB
testcase_07 AC 87 ms
12,288 KB
testcase_08 AC 84 ms
12,288 KB
testcase_09 AC 85 ms
12,288 KB
testcase_10 AC 85 ms
12,160 KB
testcase_11 AC 82 ms
12,160 KB
testcase_12 AC 79 ms
12,160 KB
testcase_13 AC 78 ms
12,160 KB
testcase_14 AC 76 ms
12,160 KB
testcase_15 AC 78 ms
12,288 KB
testcase_16 AC 78 ms
12,160 KB
testcase_17 AC 77 ms
12,160 KB
testcase_18 AC 83 ms
12,160 KB
testcase_19 AC 85 ms
12,160 KB
testcase_20 AC 76 ms
12,288 KB
testcase_21 AC 76 ms
12,288 KB
testcase_22 AC 119 ms
18,432 KB
testcase_23 AC 123 ms
18,688 KB
testcase_24 AC 118 ms
18,048 KB
testcase_25 AC 118 ms
18,432 KB
testcase_26 AC 121 ms
19,328 KB
testcase_27 AC 127 ms
19,456 KB
testcase_28 AC 123 ms
19,712 KB
testcase_29 AC 117 ms
18,304 KB
testcase_30 AC 124 ms
18,688 KB
testcase_31 AC 118 ms
18,560 KB
testcase_32 AC 123 ms
18,432 KB
testcase_33 AC 123 ms
18,816 KB
testcase_34 AC 128 ms
19,584 KB
testcase_35 AC 129 ms
19,584 KB
testcase_36 AC 123 ms
19,968 KB
testcase_37 AC 127 ms
19,712 KB
testcase_38 AC 118 ms
18,176 KB
testcase_39 AC 124 ms
18,304 KB
testcase_40 AC 127 ms
18,560 KB
testcase_41 AC 129 ms
19,584 KB
testcase_42 AC 133 ms
19,456 KB
testcase_43 AC 137 ms
19,456 KB
testcase_44 AC 135 ms
20,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
S, T = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

R1 = [0]
R2 = [0]
c1 = (T - S).abs - 1
c2 = (N - 2) - c1

if S < T
  1.upto(c1) do |v|
    i = (S - 1 + v) % N
    R1 << R1.last + A[i]
  end

  1.upto(c2) do |v|
    i = (S - 1) - v
    R2 << R2.last + A[i]
  end
else
  1.upto(c1) do |v|
    i = (S - 1) - v
    R1 << R1.last + A[i]
  end

  1.upto(c2) do |v|
    i = (S - 1 + v) % N
    R2 << R2.last + A[i]
  end
end

x = A[S - 1]
y = A[T - 1]

if c1.even? && c2.even?
  x += R1[c1 / 2] + R2[c2 / 2]
  y += (R1.last - R1[c1 / 2]) + (R2.last - R2[c2 / 2])
elsif c1.even?
  x += R1[c1 / 2] + R2[c2 / 2 + 1]
  y += (R1.last - R1[c1 / 2]) + (R2.last - R2[c2 / 2 + 1])
elsif c2.even?
  x += R1[c1 / 2 + 1] + R2[c2 / 2]
  y += (R1.last - R1[c1 / 2 + 1]) + (R2.last - R2[c2 / 2])
else
  x1 = x + R1[c1 / 2] + R2[c2 / 2 + 1]
  y1 = y + (R1.last - R1[c1 / 2]) + (R2.last - R2[c2 / 2 + 1])
  x2 = x + R1[c1 / 2 + 1] + R2[c2 / 2]
  y2 = y + (R1.last - R1[c1 / 2 + 1]) + (R2.last - R2[c2 / 2])

  if x1 - y1 < x2 - y2
    x, y = x2, y2
  else
    x, y = x1, y1
  end
end

puts x - y
0