Submission #497912

#TimeUsernameProblemLanguageResultExecution timeMemory
497912ZielBigger segments (IZhO19_segments)C++17
13 / 100
1 ms332 KiB
/** * LES GREATEABLES BRO TEAM **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = false; void setIO(const string &f = ""); const int N = 5e5 + 137; ll a[N], dp[N], last[N], pref[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = a[i]; pref[i] += pref[i - 1]; } dp[1] = 1; last[1] = 0; for (int j = 1; j <= n; j++) { if (dp[j] < dp[j - 1]) { dp[j] = dp[j - 1]; last[j] = last[j - 1]; } int right = 2 * pref[j] - pref[last[j]]; int lo = j + 1, hi = n, res = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (pref[mid] >= right) { res = mid; hi = mid - 1; } else lo = mid + 1; } if (res != -1) { if (dp[res] <= dp[j] + 1) { dp[res] = dp[j] + 1; last[res] = j; } } } cout << *max_element(dp + 1, dp + n + 1); } signed main() { setIO(); int tt = 1; if (FLAG) { cin >> tt; } while (tt--) { solve(); } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }

Compilation message (stderr)

segments.cpp: In function 'void setIO(const string&)':
segments.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen((f + ".out").c_str(), "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...