Submission #344635

#TimeUsernameProblemLanguageResultExecution timeMemory
344635nevermoreeBigger segments (IZhO19_segments)C++17
27 / 100
1574 ms12824 KiB
#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);

using namespace std;

const long long MXN = 1e6 + 3;
const long long MAXN = 1e3 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long MAXLOG = 22;
const long long MAX = 32000;

inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, a[MXN], ans;

ll dp[MAXN][MAXN], pref[MXN];

int main() {

	f_math();

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
        dp[1][i] = 1;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j++) {
            for(int k = j + 1; k <= n; k++) {
                if(!dp[i][j]) continue;
                if(pref[k] - pref[j] >= pref[j] - pref[i - 1]) {
                    dp[j + 1][k] = max(dp[j + 1][k], dp[i][j] + 1);
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        ans = max(ans, dp[i][n]);
    }
    cout << ans;
    return 0;
}

Compilation message (stderr)

segments.cpp: In function 'void f_math(bool)':
segments.cpp:20:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   20 | #define pressF freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:31:55: note: in expansion of macro 'pressF'
   31 | inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }
      |                                                       ^~~~~~
segments.cpp:20:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   20 | #define pressF freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);
      |                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:31:55: note: in expansion of macro 'pressF'
   31 | inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }
      |                                                       ^~~~~~
#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...