Submission #910992

#TimeUsernameProblemLanguageResultExecution timeMemory
910992daoquanglinh2007Bigger segments (IZhO19_segments)C++17
0 / 100
2 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair <int, int> #define fi first #define se second #define mp make_pair const int NM = 5e5; int N, a[NM+5], pref[NM+5], trace[NM+5]; pii dp[NM+5]; signed main(){ freopen("SEGMENTS.inp", "r", stdin); freopen("SEGMENTS.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i <= N; i++){ cin >> a[i]; pref[i] = pref[i-1]+a[i]; } dp[1] = mp(1, a[1]); trace[1] = 1; int t = 1; for (int i = 2; i <= N; i++){ int l, r, j = -1; if (pref[i]-pref[t] >= dp[t].se) l = t+1, r = i; else{ l = trace[i-1], r = t; } while (l <= r){ int mid = (l+r)/2; if (pref[i]-pref[mid-1] >= dp[mid-1].se){ j = mid; l = mid+1; } else r = mid-1; } dp[i].fi = dp[j-1].fi+1; dp[i].se = pref[i]-pref[j-1]; trace[i] = j; if (dp[i].fi > dp[i-1].fi) t = i; } cout << dp[N].fi; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:16:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  freopen("SEGMENTS.inp", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:17:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  freopen("SEGMENTS.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...