#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
const ll inf = 1ll << 55;
#include "aliens.h"
ll sq(ll v) { return v * v; }
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
for (int i = 0;i < n;++i) {
if (r[i] > c[i]) swap(r[i], c[i]);
}
vector<int> allc(c); allc.pb(-1); sort(AI(allc)), allc.erase(unique(AI(allc)), end(allc));
auto get_pos = [&](int c) -> int {
return lower_bound(AI(allc), c) - begin(allc);
};
int g = allc.size();
vector<vector<ll>> dp(g, vector<ll>(k + 1, inf)), osz(g, vector<ll>(k + 1, 0));
fill(AI(dp[0]), 0);
vector<vector<ll>> segmn(g, vector<ll>(g, inf));
vector<ll> omn(g, inf);
for (int i = 0;i < n;++i) {
int j = get_pos(c[i]);
chmin(omn[j], (ll)r[i]);
}
for (int i = 0;i < g;++i) {
segmn[i][i] = omn[i];
for (int j = i+1;j < g;++j)
segmn[i][j] = min(omn[j], segmn[i][j-1]);
}
auto get_mn = [&](int ql, int qr) {
return segmn[ get_pos(ql) ][ get_pos(qr) ];
// ll ret = inf;
// for (int i = 0;i < n;++i) {
// if (ql <= c[i] && c[i] <= qr)
// chmin(ret, (ll)r[i]);
// }
// assert(ret < inf);
// return ret;
};
debug(AI(allc));
for (int i = 1;i < g;++i) {
for (int j = 1;j <= k;++j) {
for (int l = 0;l < i;++l) {
ll mnc = get_mn(allc[l]+1, allc[i]);
ll wid = allc[i] - mnc + 1;
ll rep = max<ll>(0, allc[l] - mnc + 1);
if (rep > osz[l][j-1]) continue;
if (chmin(dp[i][j], dp[l][j-1] + sq(wid) - sq(rep)))
osz[i][j] = wid;
}
}
}
debug(AI(dp[g-1]));
return dp[g-1][k];
}
Compilation message
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
aliens.cpp:68:2: note: in expansion of macro 'debug'
68 | debug(AI(allc));
| ^~~~~
aliens.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
aliens.cpp:82:2: note: in expansion of macro 'debug'
82 | debug(AI(dp[g-1]));
| ^~~~~
# |
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 |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
236 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
# |
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 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
6 |
Correct |
1 ms |
280 KB |
Correct answer: answer = 71923 |
7 |
Correct |
9 ms |
588 KB |
Correct answer: answer = 77137 |
8 |
Correct |
670 ms |
3020 KB |
Correct answer: answer = 764 |
9 |
Correct |
10 ms |
2252 KB |
Correct answer: answer = 250000 |
10 |
Execution timed out |
2067 ms |
6220 KB |
Time limit exceeded |
11 |
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 |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
236 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
280 KB |
Correct answer: answer = 71923 |
27 |
Correct |
9 ms |
588 KB |
Correct answer: answer = 77137 |
28 |
Correct |
670 ms |
3020 KB |
Correct answer: answer = 764 |
29 |
Correct |
10 ms |
2252 KB |
Correct answer: answer = 250000 |
30 |
Execution timed out |
2067 ms |
6220 KB |
Time limit exceeded |
31 |
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 |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
236 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
280 KB |
Correct answer: answer = 71923 |
27 |
Correct |
9 ms |
588 KB |
Correct answer: answer = 77137 |
28 |
Correct |
670 ms |
3020 KB |
Correct answer: answer = 764 |
29 |
Correct |
10 ms |
2252 KB |
Correct answer: answer = 250000 |
30 |
Execution timed out |
2067 ms |
6220 KB |
Time limit exceeded |
31 |
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 |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
236 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
280 KB |
Correct answer: answer = 71923 |
27 |
Correct |
9 ms |
588 KB |
Correct answer: answer = 77137 |
28 |
Correct |
670 ms |
3020 KB |
Correct answer: answer = 764 |
29 |
Correct |
10 ms |
2252 KB |
Correct answer: answer = 250000 |
30 |
Execution timed out |
2067 ms |
6220 KB |
Time limit exceeded |
31 |
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 |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
15 |
Correct |
2 ms |
236 KB |
Correct answer: answer = 7220 |
16 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 10000 |
19 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
280 KB |
Correct answer: answer = 71923 |
27 |
Correct |
9 ms |
588 KB |
Correct answer: answer = 77137 |
28 |
Correct |
670 ms |
3020 KB |
Correct answer: answer = 764 |
29 |
Correct |
10 ms |
2252 KB |
Correct answer: answer = 250000 |
30 |
Execution timed out |
2067 ms |
6220 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |