Submission #691382

#TimeUsernameProblemLanguageResultExecution timeMemory
691382drdilyorBigger segments (IZhO19_segments)C++17
37 / 100
1574 ms3396 KiB
#include <bits/stdc++.h>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
const string fileio = "";
constexpr int tests = 0, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;

int solve() {
    int n; cin >> n;
    vector<int> arr(n);
    for (auto& i : arr) {cin >> i;}
    vector<ll> pref(n+1);
    for (int i = 0; i < n; i++)
        pref[i+1] = pref[i] + arr[i];

    vector<ll> dp(n+1), cnt(n+1);
    int j = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j >= 0; j--) {
            if (dp[j] <= pref[i+1] - pref[j]) {
                if (cnt[j]+1 > cnt[i+1] || (cnt[j]+1 == cnt[i+1] && pref[i+1] - pref[j] < dp[i+1])) {
                    dp[i+1] = pref[i+1] - pref[j];
                    cnt[i+1] = cnt[j] + 1;
                }
            }
        }
    }
    debug(dp);
    debug(cnt);
    cout << cnt[n] << '\n';

    return 0;
}

signed main() {
    int t = 1;
    #ifdef ONPC
    t = 10000;
    #else
    if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
    #endif
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit | cin.eofbit);
    cout << fixed << setprecision(8);
    if (tests) cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/

Compilation message (stderr)

segments.cpp: In function 'int solve()':
segments.cpp:5:24: warning: statement has no effect [-Wunused-value]
    5 |     #define debug(...) 42
      |                        ^~
segments.cpp:39:5: note: in expansion of macro 'debug'
   39 |     debug(dp);
      |     ^~~~~
segments.cpp:5:24: warning: statement has no effect [-Wunused-value]
    5 |     #define debug(...) 42
      |                        ^~
segments.cpp:40:5: note: in expansion of macro 'debug'
   40 |     debug(cnt);
      |     ^~~~~
segments.cpp:28:9: warning: unused variable 'j' [-Wunused-variable]
   28 |     int j = 0;
      |         ^
segments.cpp: In function 'int main()':
segments.cpp:51:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:51:74: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...