# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
773616 |
2023-07-05T07:15:09 Z |
peteza |
Aliens (IOI16_aliens) |
C++14 |
|
43 ms |
3284 KB |
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
long long dp[4005][4005];
long long square(long long x) {
x = max(0ll, x);
return x*x;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
std::vector<pii> points;
std::vector<pii> rps;
for(int i=0;i<n;i++) {
if(r[i] < c[i]) points.emplace_back(r[i], c[i]);
else points.emplace_back(c[i], r[i]);
}
sort(points.begin(), points.end(), [](pii a, pii b){return a.first < b.first || (a.first == b.first && a.second > b.second);});
int last = -1;
for(auto e:points) {
if(last == e.first) continue;
while(!rps.empty() && rps.back().second >= e.second) rps.pop_back();
if(rps.empty() || rps.back().second < e.second) rps.emplace_back(e);
last = e.first;
}
for(int i=0;i<rps.size();i++) dp[i][0] = square(rps[i].second-rps[0].first+1)/*, cout << dp[i][0] << ' '*/;
for(int j=1;j<min((int)rps.size(), k);j++) {
for(int i=j;i<rps.size();i++) {
dp[i][j] = 1000000000000000000ll;
for(int k=j-1;k<i;k++) {
dp[i][j] = min(dp[i][j], dp[k][j-1] - square(rps[k].second-rps[k+1].first+1) + square(rps[i].second-rps[k+1].first+1));
}
}
}
return dp[rps.size()-1][min(k-1, (int)rps.size()-1)];
}
/*
#include <cstdio>
#include <cassert>
int main() {
int n, m, k;
assert(3 == scanf("%d %d %d", &n, &m, &k));
std::vector<int> r(n), c(n);
for (int i = 0; i < n; i++) {
assert(2 == scanf("%d %d", &r[i], &c[i]));
}
long long ans = take_photos(n, m, k, r, c);
printf("%lld\n", ans);
return 0;
}
*/
Compilation message
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0;i<rps.size();i++) dp[i][0] = square(rps[i].second-rps[0].first+1)/*, cout << dp[i][0] << ' '*/;
| ~^~~~~~~~~~~
aliens.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=j;i<rps.size();i++) {
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Incorrect |
0 ms |
212 KB |
Wrong answer: output = 1, expected = 4 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 1 |
4 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 5 |
5 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 41 |
6 |
Correct |
1 ms |
340 KB |
Correct answer: answer = 71923 |
7 |
Correct |
1 ms |
980 KB |
Correct answer: answer = 77137 |
8 |
Correct |
20 ms |
2388 KB |
Correct answer: answer = 764 |
9 |
Correct |
1 ms |
2260 KB |
Correct answer: answer = 250000 |
10 |
Correct |
43 ms |
3284 KB |
Correct answer: answer = 500 |
11 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 32 |
12 |
Correct |
1 ms |
2260 KB |
Correct answer: answer = 130050 |
13 |
Correct |
12 ms |
2500 KB |
Correct answer: answer = 5110 |
14 |
Correct |
2 ms |
1364 KB |
Correct answer: answer = 2626 |
15 |
Correct |
5 ms |
1364 KB |
Correct answer: answer = 796 |
16 |
Correct |
9 ms |
2388 KB |
Correct answer: answer = 7580 |
17 |
Correct |
38 ms |
2668 KB |
Correct answer: answer = 1904 |
18 |
Correct |
1 ms |
1876 KB |
Correct answer: answer = 996004 |
19 |
Correct |
4 ms |
2004 KB |
Correct answer: answer = 38817 |
20 |
Correct |
13 ms |
2072 KB |
Correct answer: answer = 4096 |
21 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 1 |
23 |
Correct |
25 ms |
2736 KB |
Correct answer: answer = 2040 |
24 |
Correct |
1 ms |
212 KB |
Correct answer: answer = 2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Incorrect |
0 ms |
212 KB |
Wrong answer: output = 1, expected = 4 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Incorrect |
0 ms |
212 KB |
Wrong answer: output = 1, expected = 4 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Incorrect |
0 ms |
212 KB |
Wrong answer: output = 1, expected = 4 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
212 KB |
Correct answer: answer = 4 |
3 |
Incorrect |
0 ms |
212 KB |
Wrong answer: output = 1, expected = 4 |
4 |
Halted |
0 ms |
0 KB |
- |