結果

問題 No.1535 五七五
ユーザー ThetaTheta
提出日時 2024-04-16 16:09:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 1,886 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 194,264 KB
最終ジャッジ日時 2024-04-16 16:09:20
合計ジャッジ時間 4,171 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 38 ms
52,608 KB
testcase_03 AC 39 ms
52,480 KB
testcase_04 AC 164 ms
173,188 KB
testcase_05 AC 234 ms
188,216 KB
testcase_06 AC 189 ms
187,964 KB
testcase_07 AC 37 ms
52,352 KB
testcase_08 AC 39 ms
51,968 KB
testcase_09 AC 39 ms
52,608 KB
testcase_10 AC 39 ms
52,096 KB
testcase_11 AC 38 ms
52,096 KB
testcase_12 AC 38 ms
52,224 KB
testcase_13 AC 38 ms
52,480 KB
testcase_14 AC 39 ms
52,352 KB
testcase_15 AC 37 ms
52,096 KB
testcase_16 AC 37 ms
51,840 KB
testcase_17 AC 39 ms
52,352 KB
testcase_18 AC 253 ms
194,136 KB
testcase_19 AC 270 ms
193,988 KB
testcase_20 AC 235 ms
194,264 KB
testcase_21 AC 239 ms
193,864 KB
testcase_22 AC 259 ms
193,984 KB
testcase_23 AC 236 ms
194,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate


def main():
    N = int(input())
    a, b, c = map(int, input().split())
    S = list(map(len, input().split()))
    S_accum = list(accumulate(S, initial=0))
    patterns = 0

    head_idx = 0
    ab_idx = 1
    bc_idx = 2
    tail_idx = 3
    part_a = S[0]
    part_b = S[1]
    part_c = S[2]
    while head_idx < N - 2 and tail_idx <= N:
        if part_a == a and part_b == b and part_c == c:
            patterns += 1
            if tail_idx >= N:
                break
            part_c += S[tail_idx]
            tail_idx += 1
            part_c -= S[bc_idx]
            part_b += S[bc_idx]
            bc_idx += 1
            part_b -= S[ab_idx]
            part_a += S[ab_idx]
            ab_idx += 1
            part_a -= S[head_idx]
            head_idx += 1
            continue

        if head_idx >= ab_idx:
            part_a += S[ab_idx]
            part_b -= S[ab_idx]
            ab_idx += 1
            continue
        if ab_idx >= bc_idx:
            part_b += S[bc_idx]
            part_c -= S[bc_idx]
            bc_idx += 1
            continue
        if bc_idx >= tail_idx:
            if tail_idx >= N:
                break
            part_c += S[tail_idx]
            tail_idx += 1
            continue

        if part_c < c:
            if tail_idx >= N:
                break
            part_c += S[tail_idx]
            tail_idx += 1
            continue

        if part_c > c or part_b < b:
            part_c -= S[bc_idx]
            part_b += S[bc_idx]
            bc_idx += 1
            continue

        if part_b > b or part_a < a:
            part_b -= S[ab_idx]
            part_a += S[ab_idx]
            ab_idx += 1
            continue

        if part_a > a:
            part_a -= S[head_idx]
            head_idx += 1
            continue

    print(patterns)


if __name__ == "__main__":
    main()
0