Submission #989368

#TimeUsernameProblemLanguageResultExecution timeMemory
989368muhammadFeast (NOI19_feast)C++17
100 / 100
92 ms10532 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pli pair<ll, int> const int mxN=3e5; int n, k; ll a[mxN+1], lb, rb=3e14; pli dp[mxN+1]; pli cdp(ll x) { memset(dp, 0, sizeof(dp)); pli ms{}; for(int i=0; i<n; ++i) { pli cs{dp[i].first-a[i], dp[i].second}; if(cs.first^ms.first?cs.first>ms.first:cs.second<ms.second) ms=cs; pli nd{ms.first-x+a[i+1], ms.second+1}; dp[i+1]=(nd.first^dp[i].first?nd.first>dp[i].first:nd.second<dp[i].second)?nd:dp[i]; } return dp[n]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i=0; i<n; ++i) cin >> a[i+1], a[i+1]+=a[i]; while(lb<rb) { ll mb=(lb+rb)/2; if(cdp(mb).second<=k) rb=mb; else lb=mb+1; } pli r=cdp(lb); cout << r.first+k*lb; }

Compilation message (stderr)

feast.cpp: In function 'std::pair<long long int, int> cdp(long long int)':
feast.cpp:13:26: warning: 'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<long long int, 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/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from feast.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<long long int, int>' declared here
  211 |     struct pair
      |            ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...