Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
43414 hanyihong 【J】T3 C++ 通过 100 101 MS 14644 KB 483 2026-10-29 14:42:21

Tests(10/10):


#include<bits/stdc++.h> using namespace std; const int N=1e6+5; int n,p,a[N],lst[N],pre[N],f[N]; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>n>>p; for(int i=1;i<=n;i++)cin>>a[i],a[i]=(a[i]+a[i-1])%p,lst[i]=-1; for(int i=0;i<=n;i++){ pre[i]=lst[a[i]]; lst[a[i]]=i; } for(int i=1;i<=n;i++){ if(pre[i]!=-1)f[i]=max(f[i-1],f[pre[i]]+1); else f[i]=f[i-1]; } cout<<f[n]; return 0; }


测评信息: