제출 #957241

#제출 시각아이디문제언어결과실행 시간메모리
957241duckindogAliens (IOI16_aliens)C++17
16 / 100
78 ms2408 KiB
#include <bits/stdc++.h> using namespace std; #ifndef LOCAL #include "aliens.h" #endif long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { using pii = pair<int, int>; vector<pii> p(n); bool sub2 = true; for (int i = 0; i < n; ++i) { if (r[i] > c[i]) swap(r[i], c[i]); sub2 &= (r[i] == c[i]); p[i] = {r[i], c[i]}; } if (n <= 50 && m <= 100 && k == n) { vector<vector<bool>> mk(m, vector<bool>(m)); for (int i = 0; i < n; ++i) { auto [x, y] = p[i]; if (x > y) swap(x, y); for (int i = x; i <= y; ++i) { for (int j = x; j <= y; ++j) mk[i][j] = true; } } int answer = 0; for (int i = 0; i < m; ++i) for (int j = 0; j < m; ++j) answer += mk[i][j]; return answer; } auto dis = [&](pii a) { return abs(a.first - a.second) + 1; }; sort(p.begin(), p.end()); p.resize(n = unique(p.begin(), p.end()) - p.begin()); k = min(k, n); sort(p.begin(), p.end(), [&](const auto& a, const auto& b) { return make_pair(a.first, dis(a)) < make_pair(b.first, dis(b)); }); vector<vector<long long>> f(k + 1, vector<long long>(n + 1, 1e15)); if (sub2) { f[0][0] = 0; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= n; ++j) { auto& ret = f[i][j]; for (int t = 1; t <= j; ++t) { int nval = (p[j - 1].first - p[t - 1].first + 1); nval *= nval; ret = min(ret, f[i - 1][t - 1] + nval); } } } return f[k][n]; } return 0; } #ifdef LOCAL int32_t main() { cin.tie(0)->sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; vector<int> r(n), c(n); for (int i = 0; i < n; ++i) cin >> r[i] >> c[i]; cout << take_photos(n, m, k, r, c) << "\n"; } #endif
#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...