Submission #1095421

#TimeUsernameProblemLanguageResultExecution timeMemory
1095421KerimBigger segments (IZhO19_segments)C++17
37 / 100
1546 ms2516 KiB
#include "bits/stdc++.h" #define ll long long using namespace std; const int N = 2e5+4; ll a[N], b[N], par[N]; int main(){ // freopen("file.in", "r", stdin); int n; scanf("%d", &n); for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); par[i] = par[i-1]+x; } a[1] = par[1]; b[1] = 1; for(int i = 2; i <= n; ++i){ int who, mx = 0; for(int j = i; j >= 1; --j) if(par[i] >= a[j-1]+par[j-1] and b[j-1]+1 > mx){ mx = b[j-1]+1; who = j; } b[i] = b[who-1] + 1; a[i] = par[i]-par[who-1]; } printf("%lld\n", b[n]); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
segments.cpp:24:21: warning: 'who' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |         b[i] = b[who-1] + 1;
      |                  ~~~^~
#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...