Submission #853734

#TimeUsernameProblemLanguageResultExecution timeMemory
853734hngwlogBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
517 ms330760 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; #define fi first #define se second #define _size(x) (int)x.size() #define BIT(i, x) ((x >> i) & 1) #define MASK(n) ((1 << n) - 1) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i++) #define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++) #define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--) #define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i) #define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i) #define FORALL(i, a) for (auto i: a) #define fastio ios_base::sync_with_stdio(0); cin.tie(0); const long long inf = 1e18; long long delivery(int n, int k, int l, int positions[]) { vector<int> pos; REP(i, n) if (positions[i]) pos.push_back(positions[i]); if (!_size(pos)) return 0; n = _size(pos); vector<long long> f(n); REP(i, n) f[i] = 1LL * pos[i] + 1LL * min(l - pos[i], pos[i]) + (i < k ? 0 : f[i - k]); vector<long long> g(n); FORD(i, n - 1, 0) g[i] = 1LL * (l - pos[i]) + 1LL * min(l - pos[i], pos[i]) + (i + k > n - 1 ? 0 : g[i + k]); long long ans = inf; REP(i, n) { ans = min(ans, f[i] + (i + 1 > n - 1 ? 0 : g[i + 1])); ans = min(ans, f[i] + 1LL * l + (i + k > n - 1 ? 0 : g[i + k + 1])); } ans = min(ans, g[0]); return ans; }
#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...