結果

問題 No.1535 五七五
ユーザー simansiman
提出日時 2023-02-28 22:19:40
言語 Ruby
(3.3.0)
結果
AC  
実行時間 738 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 11,220 KB
実行使用メモリ 150,928 KB
最終ジャッジ日時 2023-10-14 04:46:15
合計ジャッジ時間 11,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,076 KB
testcase_01 AC 81 ms
15,144 KB
testcase_02 AC 81 ms
15,340 KB
testcase_03 AC 80 ms
15,208 KB
testcase_04 AC 733 ms
142,212 KB
testcase_05 AC 701 ms
136,920 KB
testcase_06 AC 735 ms
150,928 KB
testcase_07 AC 80 ms
15,072 KB
testcase_08 AC 79 ms
15,244 KB
testcase_09 AC 81 ms
15,076 KB
testcase_10 AC 80 ms
15,120 KB
testcase_11 AC 79 ms
15,296 KB
testcase_12 AC 81 ms
15,288 KB
testcase_13 AC 80 ms
15,224 KB
testcase_14 AC 82 ms
15,128 KB
testcase_15 AC 79 ms
15,068 KB
testcase_16 AC 80 ms
15,296 KB
testcase_17 AC 82 ms
15,136 KB
testcase_18 AC 691 ms
103,108 KB
testcase_19 AC 677 ms
102,116 KB
testcase_20 AC 678 ms
103,016 KB
testcase_21 AC 738 ms
116,576 KB
testcase_22 AC 592 ms
102,052 KB
testcase_23 AC 585 ms
94,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A, B, C = gets.split.map(&:to_i)
S = gets.chomp.split.map(&:size)
E = Array.new(N) { {} }

[A, B, C].uniq.each do |x|
  l = 0
  r = 0
  num = S[0]

  while l < N
    if num == x
      E[l][x] = r + 1
    end

    if r == N - 1
      num -= S[l]
      l += 1
    elsif num < x
      r += 1
      num += S[r]
    else
      num -= S[l]
      l += 1
    end
  end
end

ans = 0

N.times do |i|
  cur = i

  next if E[cur][A].nil?
  cur = E[cur][A]

  next if cur >= N
  next if E[cur][B].nil?
  cur = E[cur][B]

  next if cur >= N
  next if E[cur][C].nil?

  ans += 1
end

puts ans
0