제출 #731604

#제출 시각아이디문제언어결과실행 시간메모리
731604jasen_penchevAliens (IOI16_aliens)C++14
0 / 100
1 ms296 KiB
/// Convex Hull Trick Optimization #include <algorithm> #include <iostream> #include <utility> #include <vector> #include <deque> #define endl '\n' using namespace std; const long long INF = (long long)(1e18); struct line { long long a, b; long long calc(long long x) { return (a * x + b); } long double intersect(line l) { return (long double)(l.b - b) / (a - l.a); } }; long long take_photos(int n, int m, int k, vector<int> row, vector<int> col) { vector< pair<int, int> > temp; for (int i = 0; i < n; ++ i) { temp.push_back({max(row[i], col[i]), min(row[i], col[i])}); } sort(temp.begin(), temp.end()); vector< pair<int, int> > interv; interv.push_back({-1, -1}); for (auto [r, l] : temp) { while (interv.size() and interv.back().first >= l) interv.pop_back(); interv.push_back({l, r}); } n = interv.size() - 1; vector< vector<long long> > dp(n + 1, vector<long long>(2, INF)); for (int i = 1; i <= n; ++ i) { dp[i][0] = 1ll * (interv[i].second - interv[1].first + 1) * (interv[i].second - interv[1].first + 1); } long long ret = dp[n][1]; int pos = 0; for (int j = 2; j <= min(n, k); ++ j) { pos ^= 1; deque<line> dq; dq.push_back({-2ll * interv[j].first, dp[j - 1][pos ^ 1] + 1ll * interv[j].first * interv[j].first - 1ll * max(0, interv[j - 1].second - interv[j].first + 1) * max(0, interv[j - 1].second - interv[j].first + 1)}); for (int i = j; i <= n; ++ i) { while (dq.size() >= 2 and dq[0].calc(interv[i].second + 1) >= dq[1].calc(interv[i].second + 1)) dq.pop_front(); dp[i][pos] = dq[0].calc(interv[i].second + 1) + 1ll * (interv[i].second + 1) * (interv[i].second + 1); line curr = {-2ll * interv[i + 1].first, dp[i][pos ^ 1] + 1ll * interv[i + 1].first * interv[i + 1].first - 1ll * max(0, interv[i].second - interv[i + 1].first + 1) * max(0, interv[i].second - interv[i + 1].first + 1)}; while (dq.size() >= 2 and curr.intersect(dq.back()) <= dq.back().intersect(dq[dq.size() - 2])) dq.pop_back(); dq.push_back(curr); } ret = min(ret, dp[n][pos]); } return ret; } /**int main() { ios :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> row, col; for (int i = 1; i <= n; ++ i) { int r, c; cin >> r >> c; row.push_back(r); col.push_back(c); } cout << take_photos(n, m, k, row, col) << endl; return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:36:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |     for (auto [r, l] : temp)
      |               ^
#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...