Submission #956064

#TimeUsernameProblemLanguageResultExecution timeMemory
956064Neco_arcBigger segments (IZhO19_segments)C++17
0 / 100
2 ms2396 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define all(x) x.begin(), x.end() #define Neco "Bigger segments" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 2e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rng); } int n; ll a[maxn]; pair<int, ll> dp[maxn]; pair<int, ll> cb(pair<int, ll> x, pair<int, ll> y) { if(x.first > y.first) return x; if(x.first == y.first && x.second < y.second) return x; return y; } bool check(){ ll pre = 0; fi(i, 1, n) { ll val = dp[i].first + dp[i].second; if(val < pre) return 0; pre = val; } return 1; } void solve() { cin >> n; fi(i, 1, n) cin >> a[i]; fi(i, 1, n) { ll S = 0; fid(j, i, 1) { S += a[j]; if(S >= dp[j - 1].second) dp[i] = cb(dp[i], {dp[j - 1].first + 1, S}); } } if(check()) cout << dp[n].first; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(Neco".out", "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...