Submission #813369

#TimeUsernameProblemLanguageResultExecution timeMemory
813369OrazBBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
1418 ms165280 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <ll, ll> #define pb push_back #define ff first #define ss second const int N = 1e7+5; ll dp[N]; ll F(ll x, int t, ll L){ ll cur = (t ? (L-x)*2 : x*2); return min(L, cur); } ll delivery(int n, int K, int L, int p[]){ dp[0] = min(F(p[0], 1, L), F(p[0], 0, L)); int pos = 0; priority_queue<pii> s; s.push({-F(p[0], 1, L), 0}); for (int i = 1; i < n; i++){ if (i-K < 0) dp[i] = min(F(p[0], 1, L), F(p[i], 0, L)); else dp[i] = dp[i-K]+min(F(p[i-K+1], 1, L), F(p[i], 0, L)); dp[i] = min(dp[i], dp[i-1]+F(p[i], 1, L)); while(s.size() and s.top().ss < i-K+1) s.pop(); if (s.size()) dp[i] = min(dp[i], -s.top().ff); s.push({-(dp[i-1]+F(p[i], 1, L)), i}); } return dp[n-1]; } // int main () // { // ios::sync_with_stdio(false); // cin.tie(0); // int n, k, l; // cin >> n >> k >> l; // int p[n]; // for (int i = 0; i < n; i++) cin >> p[i]; // cout << delivery(n, k, l, p); // }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:20:6: warning: unused variable 'pos' [-Wunused-variable]
   20 |  int pos = 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...