提出 #37397882


ソースコード 拡げる

n = gets.chomp.to_i

total = 0
cumu_sum = gets.chomp.split.map { |value| total += value.to_i }
cumu_sum.unshift(0)

tenth, mod = total.divmod(10)

if mod > 0
  puts "No"
  exit
end

left_index = 0
right_index = 1

while left_index < n && right_index <= n
  if left_index < right_index
    current_part = cumu_sum[right_index] - cumu_sum[left_index]
  else
    current_part = (cumu_sum[n] - cumu_sum[left_index]) + (cumu_sum[right_index])
  end

  if current_part == tenth
    # ちょうどの箇所を発見したので終了
    puts "Yes"
    exit
  elsif current_part < tenth
    # 足りないので幅を広げたい
    right_index += 1
  else
    # 多い場合はとりあえず左端を進める
    left_index += 1

    # 範囲を狭める余地がないので次の領域を見る
    right_index += 1 if left_index == right_index
  end

  back_to_start, left_index = left_index.divmod(n + 1)
  break if back_to_start > 0
  right_index %= (n + 1)
end

puts "No"

提出情報

提出日時
問題 076 - Cake Cut(★3)
ユーザ thatblue
言語 Ruby (2.7.1)
得点 3
コード長 1019 Byte
結果 AC
実行時間 103 ms
メモリ 22640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 3 / 3
結果
AC × 4
AC × 29
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 55 ms 14004 KiB
hand_02.txt AC 79 ms 22640 KiB
hand_03.txt AC 58 ms 14084 KiB
hand_04.txt AC 76 ms 20832 KiB
hand_05.txt AC 53 ms 14032 KiB
random_01.txt AC 77 ms 21724 KiB
random_02.txt AC 57 ms 14640 KiB
random_03.txt AC 61 ms 14392 KiB
random_04.txt AC 63 ms 16412 KiB
random_05.txt AC 66 ms 17676 KiB
random_06.txt AC 73 ms 20700 KiB
random_07.txt AC 76 ms 21348 KiB
random_08.txt AC 65 ms 16972 KiB
random_09.txt AC 68 ms 17884 KiB
random_10.txt AC 53 ms 14284 KiB
random_11.txt AC 102 ms 21768 KiB
random_12.txt AC 73 ms 17348 KiB
random_13.txt AC 103 ms 22292 KiB
random_14.txt AC 82 ms 18492 KiB
random_15.txt AC 80 ms 18204 KiB
random_16.txt AC 65 ms 16244 KiB
random_17.txt AC 66 ms 16228 KiB
random_18.txt AC 79 ms 18480 KiB
random_19.txt AC 75 ms 18572 KiB
random_20.txt AC 74 ms 18804 KiB
sample_01.txt AC 51 ms 14112 KiB
sample_02.txt AC 54 ms 14164 KiB
sample_03.txt AC 55 ms 14060 KiB
sample_04.txt AC 59 ms 14184 KiB