# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
390417 |
2021-04-16T04:06:41 Z |
Drew_ |
Aliens (IOI16_aliens) |
C++17 |
|
1 ms |
328 KB |
#include "aliens.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define f1 first
#define s2 second
vector<ii> interval;
//cost for interval [i, j], assuming interval [0, i-1] have been fulfilled
inline ll getCost(int i, int j)
{
ll res = 1LL * (interval[j].s2 - interval[i].f1 + 1) * (interval[j].s2 - interval[i].f1 + 1);
if (i)
{
if (interval[i-1].s2 >= interval[i].f1)
res -= 1LL * (interval[i-1].s2 - interval[i].f1 + 1) * (interval[i-1].s2 - interval[i].f1 + 1);
}
return res;
}
vector<ll> dp[2];
inline void dnc(int k, int l, int r, int optL, int optR)
{
if (l > r)
return;
int mid = (l + r) / 2;
ll optVal = 1e18;
int optIdx = -1;
for (int i = optL; i <= mid && i <= optR; ++i)
{
ll val = (i ? dp[(k+1) & 1][i-1] : 0) + getCost(i, mid);
if (optVal > val)
{
optVal = val;
optIdx = i;
}
}
dp[k&1][mid] = optVal;
dnc(k, l, mid-1, optL, optIdx-1);
dnc(k, mid+1, r, optIdx+1, optR);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vector<ii> v(n);
for (int i = 0; i < n; ++i)
v[i] = {min(r[i], c[i]), max(r[i], c[i])};
sort(v.begin(), v.end(), [](const ii &x, const ii &y){
return x.f1 < y.f1 || (x.f1 == y.f1 && x.s2 > y.s2);
});
interval.pb(v[0]);
for (int i = 1; i < n; ++i)
{
if (interval.back().f1 <= v[i].f1 && v[i].s2 <= interval.back().s2)
continue;
interval.pb(v[i]);
}
dp[0].resize(interval.size());
dp[1].resize(interval.size());
for (int i = 0; i < interval.size(); ++i)
dp[1][i] = getCost(0, i);
for (int j = 2; j <= k; ++j)
dnc(j, 0, interval.size() - 1, 0, interval.size() - 1);
return dp[k & 1].back();
}
Compilation message
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < interval.size(); ++i)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
208 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Incorrect |
1 ms |
296 KB |
Wrong answer: output = 247, expected = 151 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
5 |
Incorrect |
1 ms |
328 KB |
Wrong answer: output = 73, expected = 41 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
208 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Incorrect |
1 ms |
296 KB |
Wrong answer: output = 247, expected = 151 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
208 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Incorrect |
1 ms |
296 KB |
Wrong answer: output = 247, expected = 151 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
208 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Incorrect |
1 ms |
296 KB |
Wrong answer: output = 247, expected = 151 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
208 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
292 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
296 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Incorrect |
1 ms |
296 KB |
Wrong answer: output = 247, expected = 151 |
14 |
Halted |
0 ms |
0 KB |
- |