Submission #467028

#TimeUsernameProblemLanguageResultExecution timeMemory
467028TeaTimeBigger segments (IZhO19_segments)C++17
0 / 100
1 ms204 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("avx2") #include <iostream> #include <vector> #include <string> #include <algorithm> #include <map> #include <set> #include <queue> #include <unordered_map> #include <cmath> using namespace std; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); typedef long long ll; typedef long double ld; const ll SZ = 1e6 + 100, INF = 1e9, AM = 2, K = 26; pair<ll, ll> dp[SZ]; ll n; vector<ll> vec; signed main() { fastInp; cin >> n; vec.resize(n); vector<ll> pref(1); for (auto& c : vec) { cin >> c; pref.push_back(pref.back() + c); } ll i2 = 0; dp[1] = { 1, vec[0] }; ll ans = 1; vector<ll> bstj; bstj.push_back(1); bstj.push_back(0); for (int i = 2; i <= n; i++) { pair<ll, ll> bst = { -1, -1 }; for (auto j : bstj) { if (pref[i] - pref[j] >= dp[j].second) { bst = max(bst, { dp[j].first + 1, -(pref[i] - pref[j]) }); } } bst.second = -bst.second; dp[i] = bst; if (ans < dp[i].first) { bstj.insert(bstj.begin(), i); } ans = max(ans, dp[i].first); while (dp[bstj.back()].first < ans - 3) bstj.pop_back(); for (auto& c : bstj) { if (dp[bstj.back()].first == bst.first) { if (dp[bstj.back()].second > bst.second) c = i; } } } cout << ans; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:37:8: warning: unused variable 'i2' [-Wunused-variable]
   37 |     ll i2 = 0;
      |        ^~
#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...