Submission #1075501

#TimeUsernameProblemLanguageResultExecution timeMemory
1075501TB_Boxes with souvenirs (IOI15_boxes)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl

long long delivery(int N, int K, int L, int p[]) {

    priority_queue<ll> pq;
    fo(i, N){
        pq.push(p[i]);
    }
    ll ans = 1e18;
    ll res = 0;
    while(!pq.empty()){
        ll pos = 0;
        fo(i, K){
            ll next = pq.top();
            pq.pop();
            res+=min((next-pos+L)%L, (pos-next+L)%L);
        }
        ll next = 0;
        res+=min((next-pos+L)%L, (pos-next+L)%L);
    }
    ans = res;
    fo(i, N){
        pq.push(-p[i]);
    }
    while(!pq.empty()){
        ll pos = 0;
        ll res = 0;
        fo(i, K){
            ll next = -pq.top();
            pq.pop();
            res+=min((next-pos+L)%L, (pos-next+L)%L);
        }
        ll next = 0;
        res+=min((next-pos+L)%L, (pos-next+L)%L);
    }
    ans = min(res, ans);



    return ans;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:36:12: warning: declaration of 'res' shadows a previous local [-Wshadow]
   36 |         ll res = 0;
      |            ^~~
boxes.cpp:19:8: note: shadowed declaration is here
   19 |     ll res = 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...