Submission #783319

#TimeUsernameProblemLanguageResultExecution timeMemory
783319MatblubeBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
727 ms320960 KiB
#include "boxes.h" #include <iostream> #include <iomanip> #include <string> #include <math.h> #include <algorithm> #include <cstring> #include <numeric> #include <vector> #include <map> #include <set> #include <deque> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; #define dbg(x) cerr<<#x<<": "<<x<<"\n"; #define fr(i, x) for(ll i=0 ; i<x ; i++) #define fra(x, v) for(auto x:v) #define fra1(x,v) for(auto &x:v) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define pb(x) push_back(x) #define F first #define S second const ll maxN=1e7; ll dp[maxN], dp1[maxN]; long long delivery(int N, int K, int L, int p[]) { ll n=N, k=K, l=L; vector<ll>v(n); fr(i, n) v[i]=p[i]; deque<pair<ll, ll>>dq; dq.pb(make_pair(0, -1)); for(ll i=0; i<n ; i++){ if(dq.front().S==i-k-1) dq.pop_front(); dp[i]+=(min(l, 2*v[i]))+dq.front().F; while(dq.size() && dq.front().F>=dp[i]) dq.pop_front(); dq.pb(make_pair(dp[i], i)); } while(dq.size()) dq.pop_back(); dq.pb(make_pair(0, n)); for(ll i=n-1 ; i>=0 ; i--){ if(dq.front().S==i+k+1)dq.pop_front(); dp1[i]+=(min(l, 2*(l-v[i])))+dq.front().F; while(dq.size() && dq.front().F>=dp1[i]) dq.pop_front(); dq.pb(make_pair(dp1[i], i)); } // fr(i, n) cout<<dp[i]<<" "<<dp1[i]<<"\n"; ll ans=1e18; for(ll i=0 ; i<n ; i++){ ans=min(ans, dp[i]+dp1[(i+1)%n]); } return min(ans, min(dp[n-1], dp1[0])); }
#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...