P3131 [USACO16JAN] Subsequences Summing to Sevens S

点击查看代码
#include<bits/stdc++.h>
using namespace std;

const int N=50010;
int n;
int pos[N];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);

    cin>>n;

    
    memset(pos,-1,sizeof pos);
    pos[0]=0;

    int s=0;
    int ans=0;
    for(int i=1;i<=n;i++){
    	int x;
    	cin>>x;
    	
        s=(s+x)%7;
        if(pos[s]==-1){
            pos[s]=i;
        }else{
            ans=max(ans,i-pos[s]);
        }
    }

    cout<<ans<<endl;

    return 0;
    
}
posted @ 2026-02-07 22:38  AnoSky  阅读(5)  评论(0)    收藏  举报