#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef int INT;
#define pb push_back
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define fst first
#define snd second
#define int long long
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
const ll INF = 1e15;
vi C, R;
vii points;
int sqr(int x) {return x*x;};
long long take_photos(INT n, INT m, INT k, std::vector<INT> r, std::vector<INT> c) {
FOR(i, 0, n) if(c[i] < r[i]) swap(r[i], c[i]);
FOR(i, 0, n) points.pb({r[i], c[i]});
points.pb({INF, INF});
sort(points.begin(), points.end());
FOR(i, 0, n){
if(points[i].fst != points[i+1].fst){
if(C.size() == 0 || points[i].snd > C.back()) {R.pb(points[i].fst); C.pb(points[i].snd);}
}
}
FOR(i, 0, C.size()){
cout << R[i] << " " << C[i] << endl;
}
vector<vi> dp;
int N = C.size();
dp.assign(N+1, vi(k+1, -1));
FOR(i, 0, N) dp[i][0] = INF;
FOR(K, 0, k+1) dp[N][K] = 0;
FOR(K, 1, k+1){
for(int i = N-1; i >= 0; i--){
int mi = INF;
FOR(j, i+1, N+1) mi = min(mi, dp[j][K-1] + sqr(C[j-1]+1 - R[i]));
dp[i][K] = mi;
}
}
//FOR(K, 0, k+1) {
// FOR(i, 0, N+1) cout << dp[i][K] << " ";
// cout<<endl;
//}
return dp[0][k];
}
/*
5 7 2
0 3
4 4
4 6
4 5
4 6
*/
Compilation message
aliens.cpp: In function 'long long int take_photos(INT, INT, INT, std::vector<int>, std::vector<int>)':
aliens.cpp:8:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
^
aliens.cpp:36:5: note: in expansion of macro 'FOR'
FOR(i, 0, C.size()){
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
360 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |