結果

問題 No.607 開通777年記念
ユーザー cympfhcympfh
提出日時 2017-12-08 01:46:54
言語 Ruby
(3.3.0)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,404 KB
実行使用メモリ 16,112 KB
最終ジャッジ日時 2023-08-19 12:39:55
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
15,156 KB
testcase_01 AC 75 ms
15,116 KB
testcase_02 AC 68 ms
15,028 KB
testcase_03 AC 70 ms
15,028 KB
testcase_04 AC 70 ms
15,272 KB
testcase_05 AC 71 ms
15,064 KB
testcase_06 AC 68 ms
15,064 KB
testcase_07 AC 94 ms
15,576 KB
testcase_08 AC 68 ms
15,244 KB
testcase_09 AC 74 ms
15,468 KB
testcase_10 AC 72 ms
15,264 KB
testcase_11 AC 460 ms
16,056 KB
testcase_12 AC 504 ms
16,112 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.chomp.split.map(&:to_i)
a = [0] * n

m.times do
  xs = gets.chomp.split.map(&:to_i)
  n.times do |i|
    a[i] += xs[i]
  end
  s = a[0]
  i = 0
  j = 1
  ok = false
  loop do
    while s < 777 and j < n
      s += a[j]
      j += 1
    end
    while s > 777 and i < j
      s -= a[i]
      i += 1
    end
    if s == 777
      ok = true
      break
    end
    break if j >= n
  end
  if ok
    puts :YES
    exit
  end
end

puts :NO
0