Submission #545406

#TimeUsernameProblemLanguageResultExecution timeMemory
545406krit3379Bigger segments (IZhO19_segments)C++17
0 / 100
1 ms308 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define N 500005 int ans=1; long long a[N],dp[N],h[N],now,pos,val; int main(){ int n,i; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%lld",&a[i]); for(i=1;i<=n;i++){ dp[ans]+=a[i]; if(dp[ans]>=dp[ans-1]){ h[ans]=i; while(dp[ans]-a[h[ans-1]+1]>=dp[ans-1]+a[h[ans-1]+1]){ dp[ans]-=a[h[ans-1]+1]; dp[ans-1]+=a[h[ans-1]+1]; h[ans-1]++; } ans++; } } printf("%d",ans-1); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
segments.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for(i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~~~
#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...