最后三个点TLE,求优化

P3131 [USACO16JAN] Subsequences Summing to Sevens S

```cpp #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const long long NUM = (50005LL); long long a[NUM], f[NUM]; int maxer[NUM]; int main() { //ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; ++i) /*cin >> a[i]*/ scanf("%lld", &a[i]); //cout << "a[0]="<<a[0]<<endl; for (int i = 1; i <= n; ++i) f[i] = f[i - 1] + a[i]; //for (int i = 1; i <= n; ++i) cout << "f["<<i<<']'<<"="<<f[i] << endl; int i, j, t = 0; for (i = 1; i <= n; ++i) { t++; for (j = i + 1; j <= n; ++j) { if ((f[j] - f[i - 1]) % 7 == 0) { //maxer.push_back(j - (i - 1)); maxer[t] = (j - (i - 1)); } } } maxer[t++] = 0; int a = *max_element(maxer, maxer + n); /*for (int i = 0; i < t; ++i) { cout << i << '=' << ' ' << maxer[i] << endl; }*/ /*for (int i = 0; i < maxer.size(); ++i) { cout << maxer[i] << endl; }*/ printf("%d\n", a); return 0; } 我的也是70分。。。qaq ```
by Alextokc @ 2017-03-04 20:02:56


$O(n^2)$ 还想拿满分咯?
by rushcheyo @ 2017-03-11 14:18:22


|