Submission #1033884

#TimeUsernameProblemLanguageResultExecution timeMemory
1033884vannnnnnnnBigger segments (IZhO19_segments)C++14
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long using namespace std; int main() { ll n; scanf("%lld", &n); ll a[n+5]; pair<ll, ll>dp[n+5]; memset(dp, 0, sizeof(dp)); for(int i=1; i<=n; i++) { scanf("%lld", &a[i]); } int p=2, last=2; dp[1].fi=a[1]; dp[1].se=1; for(int i=2; i<=n; i++) { if(dp[p].fi==0)dp[p].se=i; dp[p].fi+=a[i]; // printf("%lld %lld\n", dp[p].fi, dp[p-1].fi); if(dp[p].fi>=dp[p-1].fi) { while(dp[p-1].fi+a[dp[p].se]<=dp[p].fi-a[dp[p].se]) { dp[p].fi-=a[dp[p].se]; dp[p-1].fi+=a[dp[p].se]; dp[p].se++; } p++; } } printf("%lld\n", p-1); }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:13:26: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, long long int>' with no trivial copy-assignment; use assignment instead [-Wclass-memaccess]
   13 |  memset(dp, 0, sizeof(dp));
      |                          ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from segments.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, long long int>' declared here
  211 |     struct pair
      |            ^~~~
segments.cpp:37:13: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   37 |  printf("%lld\n", p-1);
      |          ~~~^     ~~~
      |             |      |
      |             |      int
      |             long long int
      |          %d
segments.cpp:18:11: warning: unused variable 'last' [-Wunused-variable]
   18 |  int p=2, last=2;
      |           ^~~~
segments.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
segments.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   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...