제출 #701692

#제출 시각아이디문제언어결과실행 시간메모리
701692AsamaiBigger segments (IZhO19_segments)C++17
37 / 100
135 ms46672 KiB
#include <bits/stdc++.h> using namespace std; template<class A, class B> bool maximize(A& x, B y) {if (x < y) return x = y, true; else return false;} template<class A, class B> bool minimize(A& x, B y) {if (x > y) return x = y, true; else return false;} void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << " ]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define deb(x...) cerr << "[ in " <<__func__<< "() : line " <<__LINE__<< " ] : [ " << #x << " ] = [ "; _print(x); cerr << '\n'; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> plli; typedef pair<int, ll> pill; #define all(a) a.begin(), a.end() #define pb push_back #define pf push_front #define fi first #define se second #define int long long const int MAX_N = 5e5 + 5; const int MAX_M = 3000 + 5; const int inf = 1e18 + 1; int n; int a[MAX_N]; int sum[MAX_N]; pii dp[MAX_N]; int dp2[MAX_M][MAX_M]; void update(pii &a, const pii& b) { if (a.fi == b.fi) { minimize(a.se, b.se); } else { if (b.fi > a.fi) { a = b; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; dp[i] = {1, sum[i]}; } if (n <= 3000) { for (int i = 1; i <= n; i++) { dp2[i][1] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { maximize(dp2[i][j], dp2[i - 1][j]); if (!dp2[i][j] || i == n) continue; int curr = sum[i] - sum[j - 1]; int low = i + 1, high = n; int res = n + 1; while (low <= high) { int mid = (low + high) >> 1; if (sum[mid] - sum[i] >= curr) { res = mid; high = mid - 1; } else { low = mid + 1; } } if (res <= n) { maximize(dp2[res][i + 1], dp2[i][j] + 1); } } } int ans = 1; for (int i = 1; i <= n; i++) { maximize(ans, dp2[n][i]); } cout << ans; return 0; } for (int i = 1; i <= n; i++) { update(dp[i], {dp[i - 1].fi, dp[i - 1].se + a[i]}); int low = i + 1, high = n; int k = n + 1; while (low <= high) { int mid = (low + high) >> 1; if (sum[mid] - sum[i] >= dp[i].se) { k = mid; high = mid - 1; } else { low = mid + 1; } } if (k <= n) { update(dp[k], {dp[i].fi + 1, sum[k] - sum[i]}); } } cout << dp[n].fi; return 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...