Submission #8610433


Source Code Expand

Copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
from collections import defaultdict

N,K,*A = map(int,read().split())

A = [0] + [x-1 for x in A]

# 和が0となる場所を答えればよい

Acum = list(itertools.accumulate(A))
Acum = [x % K for x in Acum]

counter = defaultdict(int)
answer = 0
for i,x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-K+1]] -= 1

print(answer)

Submission Info

Submission Time
Task E - Rem of Sum is Num
User maspy
Language Python (3.4.3)
Score 500
Code Size 548 Byte
Status AC
Exec Time 240 ms
Memory 41416 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 29
Set Name Test Cases
sample sample01, sample02, sample03
All few01, few02, few03, hand01, hand02, hand03, hand04, large01, large02, large03, max01, max02, max03, mid01, mid02, mid03, mid04, mid05, min01, min02, min03, sample01, sample02, sample03, small01, small02, small03, small04, small05
Case Name Status Exec Time Memory
few01 AC 199 ms 20684 KB
few02 AC 197 ms 25380 KB
few03 AC 199 ms 25760 KB
hand01 AC 20 ms 3316 KB
hand02 AC 218 ms 22240 KB
hand03 AC 225 ms 22220 KB
hand04 AC 183 ms 22244 KB
large01 AC 219 ms 39800 KB
large02 AC 235 ms 41416 KB
large03 AC 230 ms 40508 KB
max01 AC 240 ms 41188 KB
max02 AC 225 ms 41188 KB
max03 AC 217 ms 41188 KB
mid01 AC 22 ms 3564 KB
mid02 AC 22 ms 3692 KB
mid03 AC 23 ms 3564 KB
mid04 AC 22 ms 3564 KB
mid05 AC 23 ms 3564 KB
min01 AC 164 ms 17020 KB
min02 AC 163 ms 16432 KB
min03 AC 169 ms 17480 KB
sample01 AC 20 ms 3316 KB
sample02 AC 20 ms 3316 KB
sample03 AC 20 ms 3316 KB
small01 AC 20 ms 3316 KB
small02 AC 20 ms 3316 KB
small03 AC 20 ms 3316 KB
small04 AC 20 ms 3316 KB
small05 AC 20 ms 3316 KB