Submission #701680

#TimeUsernameProblemLanguageResultExecution timeMemory
701680AsamaiBigger segments (IZhO19_segments)C++14
0 / 100
1 ms340 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 = 3e3 + 5; const int inf = 1e18 + 1; int n; int dp[MAX_N][MAX_N]; int a[MAX_N]; int sum[MAX_N]; 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]; } for (int i = 1; i <= n; i++) { dp[i][1] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j <= i; j++) { // maximize(dp[i][j], dp[i - 1][j]); // 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(dp[res][i + 1], dp[i][j] + 1); // } for (int k = i + 1; k <= n; k++) { if (sum[k] - sum[i] >= sum[i] - sum[j - 1]) { maximize(dp[k][i + 1], dp[i][j] + 1); } } } } int ans = -inf; for (int i = 1; i <= n; i++) { maximize(ans, dp[n][i]); } cout << ans; 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...