/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 79ms 21.688 MiB
#2 Accepted 170ms 25.031 MiB
#3 Accepted 134ms 23.543 MiB
#4 Accepted 122ms 23.391 MiB
#5 Accepted 132ms 33.73 MiB
#6 Accepted 114ms 41.094 MiB
#7 Accepted 121ms 48.008 MiB
#8 Accepted 118ms 48.004 MiB
#9 Accepted 159ms 24.562 MiB

Code

from collections import *        # Useful for deque, Counter, defaultdict, namedtuple, etc.
from itertools import *          # Provides tools for combinations, permutations, product, etc.
from functools import *          # Includes tools like lru_cache for memoization, reduce, etc.
from heapq import *              # Provides heap operations like heappush, heappop, useful for priority queues
from bisect import *             # For efficient binary search and maintaining sorted lists
from math import *               # Includes functions like gcd, sqrt, factorial, isqrt, comb, etc.
from operator import *           # Includes functions like itemgetter, attrgetter, add, mul for functional programming
from array import *              # For efficient storage and manipulation of numeric arrays
from typing import *             # Provides typing hints (List, Tuple, Dict, etc.) to improve readability and error-checking
from decimal import *            # High-precision arithmetic operations, useful for certain precision tasks
from queue import *              # Includes Queue, LifoQueue, PriorityQueue useful in BFS, DFS, and other algorithms
import sys
sys.setrecursionlimit(10**5)
def POW(base, exp, mod):
    result = 1
    base = base % mod  # Handle case when base is larger than mod
    while exp > 0:
        if exp % 2 == 1:  # If exp is odd, multiply base with result
            result = (result * base) % mod
        exp = exp // 2    # Divide exp by 2
        base = (base * base) % mod  # Square the base
    return result
def IL():
  return [int(i) for i in input().split()]
def CL():
  return [i for i in input().split()]
def I():
  return input()
def inti():
  return int(input())
def db(x):
  return print(x)
def dbl(x):
  return print(*x)
def dbm(x):
  for i in x:
    print(i)
def sq(x):
  return x==int(x**0.5)**2
def prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if (n & 1) == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

char="abcdefghijklmnopqrstuvwxyz"
mod=pow(10,9)+7


for _ in range(int(input())):
  n,k,d=IL()
  arr=IL()
  pre=list(accumulate(arr))
  ans=defaultdict(list)
  z=[]
  h=0
  for i in arr:
    h+=1 if i==0 else 0
    z.append(h)
  
  for i in range(n-k+1):
    cur=pre[i+k-1]-(pre[i-1] if i>0 else 0)
    if cur%d==0:
      curP=z[i+k-1]-(z[i-1] if i>0 else 0)
      if curP!=0:
        P=0
      else:
        P=1
      ans[P].append(i+1)
  if not ans:
    print(-1)
  else:
    print(ans[max(ans.keys())][0])
  

Information

Submit By
Type
Submission
Problem
P1190 Segment Strength
Contest
Brain Booster #9
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-04-06 16:17:52
Judged At
2025-04-06 16:17:52
Judged By
Score
100
Total Time
170ms
Peak Memory
48.008 MiB