結果
| 問題 | 
                            No.1535 五七五
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-03-20 20:22:37 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 242 ms / 2,000 ms | 
| コード長 | 1,134 bytes | 
| コンパイル時間 | 236 ms | 
| コンパイル使用メモリ | 82,284 KB | 
| 実行使用メモリ | 205,956 KB | 
| 最終ジャッジ日時 | 2025-03-20 20:24:34 | 
| 合計ジャッジ時間 | 4,503 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    a, b, c = map(int, input[ptr:ptr+3])
    ptr += 3
    S = input[ptr:ptr+N]
    
    # Compute prefix sums
    sum_ = [0] * (N + 1)
    pre_sum_dict = {0: 0}
    current_sum = 0
    for i in range(1, N + 1):
        current_sum += len(S[i-1])
        sum_[i] = current_sum
        pre_sum_dict[current_sum] = i  # Since sum is strictly increasing, overwriting is not needed
    
    ans = 0
    for R in range(1, N + 1):
        sum_R = sum_[R]
        sum_x_target = sum_R - b - c
        if sum_x_target not in pre_sum_dict:
            continue
        x = pre_sum_dict[sum_x_target]
        sum_y_target = sum_x_target + b  # which should equal sum_R - c
        if sum_y_target not in pre_sum_dict:
            continue
        y = pre_sum_dict[sum_y_target]
        # Check if x < y and y < R
        if not (x < y and y < R):
            continue
        sum_L1 = sum_x_target - a
        if sum_L1 not in pre_sum_dict:
            continue
        ans += 1
    print(ans)
if __name__ == "__main__":
    main()
            
            
            
        
            
lam6er