Submission #336459

#TimeUsernameProblemLanguageResultExecution timeMemory
336459beksultan04Bigger segments (IZhO19_segments)C++14
100 / 100
117 ms16084 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define OK puts("OK"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define pb push_back #define sz(v) (int)v.size() #define endi puts(""); const int N = 5e5+12,INF=1e9+7; int q[N],p[N],dp[N]; main(){ int n,m,i,j; scan1(n) priority_queue <pii> q; q.push({0,0}); int tmp=0; for (i=1;i<=n;++i){ int x; scan1(x) p[i]=p[i-1]+x; } for (i=1;i<=n;++i){ while (!q.empty() && -q.top().fr <= p[i]){ if (dp[tmp] < dp[q.top().sc]){ tmp = q.top().sc; } if (dp[tmp] == dp[q.top().sc] && tmp < q.top().sc)tmp = q.top().sc; q.pop(); } dp[i]=dp[tmp]+1; q.push({p[tmp]-p[i]*2,i}); } cout <<dp[n]; }

Compilation message (stderr)

segments.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      |      ^
segments.cpp: In function 'int main()':
segments.cpp:19:11: warning: unused variable 'm' [-Wunused-variable]
   19 |     int n,m,i,j;
      |           ^
segments.cpp:19:15: warning: unused variable 'j' [-Wunused-variable]
   19 |     int n,m,i,j;
      |               ^
segments.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
segments.cpp:20:5: note: in expansion of macro 'scan1'
   20 |     scan1(n)
      |     ^~~~~
segments.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
segments.cpp:27:9: note: in expansion of macro 'scan1'
   27 |         scan1(x)
      |         ^~~~~
#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...