题解
2023-09-01 12:27:53
发布于:广东
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int MOD = 7;
int main() {
int cow_num;
cin >> cow_num;
int longest_photo = 0;
vector<int> first(MOD, -1);
first[0] = 0;
int curr_remainder = 0;
for (int i = 1; i <= cow_num; i++) {
int cow;
cin >> cow;
curr_remainder = (curr_remainder + cow) % MOD;
if (first[curr_remainder] == -1) {
first[curr_remainder] = i;
} else {
longest_photo = max(longest_photo, i - first[curr_remainder]);
}
}
cout << longest_photo << endl;
}
这里空空如也
有帮助,赞一个