Submission #863069

#TimeUsernameProblemLanguageResultExecution timeMemory
863069LePhiPhatBigger segments (IZhO19_segments)C++17
27 / 100
1 ms348 KiB
// https://codeforces.com/blog/entry/64479?#comment-484350 #include <iostream> #include <cstdint> #include <string> #include <vector> using namespace std; #ifdef DEBUG #include "debuge.cpp" #else #define debug(...) 42 #endif typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vii; #define fi first #define se second #define all(v) (v).begin(), (v).end() #define SZ(x) ((int) (x).size()) #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define ROF(i, a, b) for (int i = (a); i > (b); --i) void LPP(int &test) { int n; cin >> n; vll a(n + 1), p(n + 1); vector<pll> dp(n + 1); // number of segment - sum for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[i]; // subtask 4 dp[0].fi = dp[0].se = 0; for (int i = 1; i <= n; i++) { dp[i].fi = 0; dp[i].se = 1e18; } auto mx = [&] (pll &l, pll &r) { if (l.fi > r.fi) return l; if (l.fi < r.fi) return r; if (l.se > r.se) return r; return l; }; dp[0].fi = dp[0].se = 0; for (int i = 0; i < n; i++) { if (p[n] - p[i] >= dp[i].se) { int lo = i, hi = n + 1; while (lo + 1 < hi) { int mi = (lo + hi) / 2; if (p[mi] - p[i] >= dp[i].se) { hi = mi; } else { lo = mi; } } debug(hi); if (hi != n + 1) { pll tmp; tmp.fi = dp[i].fi + 1; tmp.se = p[hi] - p[i]; dp[hi] = mx(dp[hi], tmp); } } if (dp[i].fi > dp[i + 1].fi) { dp[i + 1].fi = dp[i].fi; dp[i + 1].se = dp[i].se + a[i + 1]; } else if (dp[i].fi < dp[i + 1].fi) { } else { dp[i + 1].se = min(dp[i + 1].se, dp[i].se + a[i]); } debug(i, dp[i]); } cout << dp[n].fi; } int32_t main() { cin.tie(0) -> ios::sync_with_stdio(false); int tc = 1; // cin >> tc; for (int i = 1; i <= tc; i++) LPP(i); } /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> */

Compilation message (stderr)

segments.cpp: In function 'void LPP(int&)':
segments.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 42
      |                    ^~
segments.cpp:67:4: note: in expansion of macro 'debug'
   67 |    debug(hi);
      |    ^~~~~
segments.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 42
      |                    ^~
segments.cpp:81:3: note: in expansion of macro 'debug'
   81 |   debug(i, dp[i]);
      |   ^~~~~
#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...