Submission #497934

#TimeUsernameProblemLanguageResultExecution timeMemory
497934ZielBigger segments (IZhO19_segments)C++17
100 / 100
69 ms15968 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 = ""); #define int ll 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] = 1; for (int j = 1; j <= n; j++) { int right = 2 * pref[j] - pref[last[j] - 1]; int lo = j, 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 + 1; } } if (dp[j + 1] < dp[j]) { dp[j + 1] = dp[j]; last[j + 1] = last[j]; } else if (dp[j + 1] == dp[j] && last[j] > last[j + 1]) { dp[j + 1] = dp[j]; last[j + 1] = last[j]; } } cout << dp[n]; } 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:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         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...