# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
776238 | faruk | Aliens (IOI16_aliens) | C++17 | 2033 ms | 22356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <bits/stdc++.h>
#define intsum(a) (a.second - a.first + 1LL) * (a.second - a.first + 1LL)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll INF = 1e18;
bool cmp(pii a, pii b) {return pii(a.first, -a.second) < pii(b.first, -b.second);}
vector<pii> get_intervals(vector<int> r, vector<int> c) {
vector<pii> all_intervals;
for (int i = 0; i < r.size(); i++)
all_intervals.push_back({min(r[i], c[i]), max(r[i], c[i])});
sort(all(all_intervals), cmp);
vector<pii> intervals;
for (pii a : all_intervals) {
if (intervals.size() == 0) {
intervals.push_back(a);
} else {
pii last = *prev(intervals.end());
if (last.second < a.second)
intervals.push_back(a);
}
}
return intervals;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vector<pii> ints = get_intervals(r, c);
ints.insert(ints.begin(), pii(-1, -1));
vector<vector<ll> > dp(k + 1, vector<ll>(ints.size() + 1, INF));
dp[0][0] = 0;
for (int i = 1; i <= k; i++) {
dp[i][0] = 0;
for (int j = 1; j < ints.size(); j++) {
dp[i][j] = dp[i - 1][j];
for (int l = 1; l <= j; l++) {
ll cost = dp[i - 1][l - 1];
cost += intsum(pii(ints[l].first, ints[j].second));
pii intersection_interval(ints[l].first, ints[l - 1].second);
if (intersection_interval.first <= intersection_interval.second)
cost -= intsum(intersection_interval);
dp[i][j] = min(dp[i][j], cost);
}
}
}
return dp[k][ints.size() - 1];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |