Submission #701651

#TimeUsernameProblemLanguageResultExecution timeMemory
701651lto5Bigger segments (IZhO19_segments)C++14
37 / 100
427 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int a[100005]; int64_t s[100005]; int f[5005][5005]; int suf[5005][5005]; int64_t get(int l, int r) { return s[r] - s[l - 1]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "a" if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = s[i - 1] + a[i]; } memset(f, -1, sizeof(f)); for (int i = 1; i <= n; i++) { int k = i; for (int j = i; j >= 2; j--) { while (k - 1 >= 1 && get(j, i) >= get(k - 1, j - 1)) { k--; } if (k >= 1 && k <= j - 1 && get(j, i) >= get(k, j - 1)) { if (suf[j - 1][k] != -1) f[i][j] = suf[j - 1][k] + 1; } } f[i][1] = 1; suf[i][i + 1] = -1; for (int j = i; j >= 1; j--) { suf[i][j] = max(suf[i][j + 1], f[i][j]); } } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { ans = max(ans, f[i][j]); } } cout << ans; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(task ".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(task ".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...