結果

問題 No.607 開通777年記念
ユーザー simansiman
提出日時 2020-10-13 01:19:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 25,324 KB
最終ジャッジ日時 2023-09-27 23:53:23
合計ジャッジ時間 2,856 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
15,040 KB
testcase_01 AC 70 ms
15,140 KB
testcase_02 AC 72 ms
15,080 KB
testcase_03 AC 75 ms
15,268 KB
testcase_04 AC 73 ms
15,224 KB
testcase_05 AC 70 ms
15,024 KB
testcase_06 AC 69 ms
15,288 KB
testcase_07 AC 139 ms
17,532 KB
testcase_08 AC 72 ms
15,152 KB
testcase_09 AC 75 ms
15,244 KB
testcase_10 AC 73 ms
15,432 KB
testcase_11 AC 466 ms
25,284 KB
testcase_12 AC 486 ms
25,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = M.times.map { gets.split.map(&:to_i) }
R = Array.new(N, 0)

M.times do |i|
  A[i].each_with_index do |x, idx|
    R[idx] += x
  end

  l = 0
  r = 0
  sum = R[0]

  while l < N && l <= r && sum != 777
    if sum < 777
      r += 1

      if r < N
        sum += R[r]
      else
        break
      end
    else
      sum -= R[l]
      l += 1

      if r < l
        r = l
        sum = R[r]
      end
    end
  end

  if sum == 777
    puts 'YES'
    exit
  end
end

puts 'NO'
0