此题暴力可过
查看原帖
此题暴力可过
537934
litjohn楼主2024/7/10 16:36

rt。

#include <bits/stdc++.h>

using namespace std;
int n, s[50005], a[50005], ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i] % 7;
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + ans; j <= n; ++j, ++cnt) {
            if ((s[j] - s[i - 1]) % 7 == 0) {
                ans = max(ans, j - i + 1);
            }
            if (cnt > 500000000) {
                cout << ans;
                exit(0);
            }
        }
    }
    cout << ans;
    return 0;
}
2024/7/10 16:36
加载中...