Submission #1195720

#TimeUsernameProblemLanguageResultExecution timeMemory
1195720madamadam3선물상자 (IOI15_boxes)C++20
0 / 100
1645 ms436 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < b; i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define srt(x) sort(all(x)) typedef long long ll; using vi = vector<int>; using vl = vector<ll>; // probably binary search? ll n, k, l; vl p; vl nxt, prev; ll sim_dist(ll p1, ll p2) { ll lmoves = 0, rmoves = 0; ll lpos = p1, rpos = p1; while (lpos != p2) { lpos--; if (lpos < 0) lpos = l - 1; lmoves++; } while (rpos != p2) { rpos++; if (rpos >= l) rpos = 0; rmoves++; } return min(lmoves, rmoves); } ll dist(ll p1, ll p2) { if (p1 == p2) return 0; if (p1 < p2) return dist(p2, p1); else return min(p1 - p2, (l - p1) + p2); } ll delivery(int N, int K, int L, int P[]) { n = N, k = K, l = L; FOR(i, 0, n) p.pb(P[i]); srt(p); ll ansR = 0, ansL = 1; ll pL = L-1, pR = 0; while (pR < p.back()) { ansR++; pR++; } ansR += sim_dist(pR, 0); while(pL > p[0]) { ansL++; pL--; } ansL += sim_dist(pL, 0); return min(ansR, ansL); // return min(*max_element(all(p)) + dist(*max_element(all(p)), 0), l - *min_element(all(p)) + dist(*min_element(all(p)), 0)); // ll max_pos = *max_element(all(p)); // ll min_pos = *min_element(all(p)); // ll min_dist = dist(min_pos, l); // return min({l, 2LL * max_pos, 2LL * min_dist}); }
#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...