제출 #443504

#제출 시각아이디문제언어결과실행 시간메모리
443504mjhmjh1104Distributing Candies (IOI21_candies)C++17
0 / 100
134 ms7324 KiB
#include "candies.h" #include <vector> #include <algorithm> using namespace std; struct Move { long long o; long long n; long long c; }; vector<Move> V; long long cnt; vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) { cnt = 0; V.clear(); int n = (int)c.size(), q = (int)v.size(); long long globalMin = 0, globalMax = 0; vector<int> s(n); for (int t = 0; t < q; t++) { long long tmp_curr = v[t]; if (tmp_curr > 0) { long long curr = tmp_curr; while (!V.empty()) { if (V.back().n > V.back().o) { tmp_curr = cnt + tmp_curr - V.back().o; cnt = V.back().o; V.pop_back(); } else if (V.back().c <= curr) V.pop_back(); else break; } } else { long long curr = -tmp_curr; while (!V.empty()) { if (V.back().n < V.back().o) { tmp_curr = cnt + tmp_curr - V.back().o; cnt = V.back().o; V.pop_back(); } else if (V.back().c <= curr) V.pop_back(); else break; } } V.push_back(Move{ cnt, cnt + tmp_curr, tmp_curr > 0 ? tmp_curr : -tmp_curr }); cnt += tmp_curr; globalMin = min(globalMin, cnt), globalMax = max(globalMax, cnt); } //for (auto &i: V) printf("%lld %lld %d\n", i.o, i.n, i.c); for (int i = 0; i < n; i++) { long long l = globalMin, r = globalMax; if (V.front().c >= c[i]) { Move x = *(upper_bound(V.begin(), V.end(), Move{ 0LL, 0LL, c[i] }, [](const Move &a, const Move &b) { return a.c > b.c; }) - 1); if (x.o > x.n) l = x.n, r = l + c[i]; else r = x.n, l = r - c[i]; //printf("%lld %lld %d\n", x.o, x.n, x.c); } //printf("! %lld %lld\n", l, r); if (l < 0) s[i] = cnt - l; else if (r > c[i]) s[i] = cnt - r + c[i]; else s[i] = cnt; } return s; }
#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...