結果

問題 No.1535 五七五
ユーザー tomeruntomerun
提出日時 2021-06-06 18:09:54
言語 Crystal
(1.11.2)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 22,339 ms
コンパイル使用メモリ 252,920 KB
実行使用メモリ 41,936 KB
最終ジャッジ日時 2023-08-15 00:14:10
合計ジャッジ時間 22,167 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,412 KB
testcase_01 AC 2 ms
4,392 KB
testcase_02 AC 3 ms
4,488 KB
testcase_03 AC 3 ms
4,472 KB
testcase_04 AC 49 ms
24,852 KB
testcase_05 AC 64 ms
41,364 KB
testcase_06 AC 65 ms
41,936 KB
testcase_07 AC 3 ms
4,476 KB
testcase_08 AC 3 ms
4,548 KB
testcase_09 AC 2 ms
4,516 KB
testcase_10 AC 3 ms
4,456 KB
testcase_11 AC 3 ms
4,500 KB
testcase_12 AC 2 ms
4,564 KB
testcase_13 AC 2 ms
4,440 KB
testcase_14 AC 3 ms
4,524 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,432 KB
testcase_17 AC 2 ms
4,508 KB
testcase_18 AC 85 ms
38,336 KB
testcase_19 AC 80 ms
37,976 KB
testcase_20 AC 83 ms
38,472 KB
testcase_21 AC 82 ms
37,556 KB
testcase_22 AC 82 ms
37,364 KB
testcase_23 AC 82 ms
38,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def pos(cs, s)
  n = cs.size
  ret = Array.new(n, -1)
  r = 0
  sum = 0
  n.times do |l|
    while r < n && sum + cs[r] <= s
      sum += cs[r]
      r += 1
    end
    if sum == s
      ret[l] = r
    end
    sum -= cs[l]
  end
  return ret
end

n = read_line.to_i
a, b, c = read_line.split.map(&.to_i)
s = read_line.split.map { |w| w.size }
pa = pos(s, a)
pb = pos(s, a + b)
pc = pos(s, a + b + c)
puts (0...n).count { |i| pa[i] != -1 && pb[i] != -1 && pc[i] != -1 }
0