結果
| 問題 | No.3516 Very Large Range Mod |
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2026-04-24 22:26:40 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 520 ms / 2,000 ms |
| コード長 | 1,136 bytes |
| 記録 | |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 85,428 KB |
| 実行使用メモリ | 116,516 KB |
| 最終ジャッジ日時 | 2026-04-24 22:26:56 |
| 合計ジャッジ時間 | 12,773 ms |
|
ジャッジサーバーID (参考情報) |
judge4_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
N,K,mod=map(int,input().split())
B=list(map(int,input().split()))
C=list(map(int,input().split()))
posa=0
resta=B[0]
count=0
score=0
for i in range(N):
if count+B[i]>=K:
posb=i
restb=count+B[i]-K
score+=C[i]*(K-count)
score%=mod
break
else:
count+=B[i]
score+=C[i]*B[i]
score%=mod
result=0
from math import gcd
while True:
d=(C[posa]-C[posb])%mod
n0=resta
n1=restb+1
if n1<=n0:
if d==0:
if score==0:
result+=n1
else:
y=gcd(d,mod)
if score%y==0:
w=score//y
t=d//y
mod2=mod//y
x=(w*pow(t,-1,mod2))%mod2
result+=(n1-1-x)//mod2+1
score-=C[posa]*n1
score+=C[posb]*(n1-1)
if posb==N-1:
break
posb+=1
score+=C[posb]
score%=mod
restb=B[posb]-1
resta-=n1
else:
if d==0:
if score==0:
result+=n0
else:
y=gcd(d,mod)
if score%y==0:
w=score//y
t=d//y
mod2=mod//y
x=(w*pow(t,-1,mod2))%mod2
result+=(n0-1-x)//mod2+1
score-=C[posa]*n0
score+=C[posb]*n0
posa+=1
restb-=n0
resta=B[posa]
print(result)
ゼット