2 条题解
-
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000005; int pre[MAXN], n, len, maxx = -1, first[7], last[7]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> pre[i]; pre[i] = (pre[i] + pre[i - 1]) % 7; } for (int i = n; i >= 1; i--) first[pre[i]] = i; first[0] = 0; for (int i = 1; i <= n; i++) last[pre[i]] = i; for (int i = 0; i <= 6; i++) maxx = max(last[i] - first[i], maxx); cout << maxx << endl; return 0; }
-
0
#include<bits/stdc++.h> int a[50001],n,ans; int first[7],last[7]; int main() { std::cin>>n; memset(first,-1,sizeof(first)); memset(last,-1,sizeof(last)); first[0]=last[0]=0; for(int i=1;i<=n;i+=1) { std::cin>>a[i]; a[i]=(a[i]+a[i-1])%7; if(first[a[i]]==-1)first[a[i]]=i; last[a[i]]=i; } for(int i=0;i<7;i+=1)if(first[i]!=-1)ans=std::max(ans,last[i]-first[i]); std::cout<<ans; }
- 1
信息
- ID
- 584
- 时间
- 500ms
- 内存
- 512MiB
- 难度
- 6
- 标签
- 递交数
- 258
- 已通过
- 82
- 上传者