//In the name of God
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 5e4 + 100;
const ll maxk = 105;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
vector<pll> vec;
ll dp[maxk][maxn], ps[maxn];
void solve(ll k, ll l, ll r, ll s, ll e){
if(l >= r) return;
ll mid = (l + r) >> 1;
ll opt = s;
dp[k][mid] = inf;
for(ll i = s; i < e && i <= mid; i++){
ll x = dp[k - 1][i - 1] + (vec[mid].F - vec[i].S + 1) * (vec[mid].F - vec[i].S + 1) - ps[i];
if(x < dp[k][mid]){
dp[k][mid] = x;
opt = i;
}
}
solve(k, l, mid, s, e);
solve(k, mid + 1, r, s, e);
return;
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pll> p(n);
vec.pb(Mp(-1, -1));
for(ll i = 0; i < n; i++){
if(r[i] < c[i]) swap(r[i], c[i]);
p[i] = Mp(c[i], -r[i]);
}
sort(all(p));
ll mx = -1;
for(ll i = 0; i < n; i++){
p[i].S *= -1;
if(p[i].S > mx){
vec.pb(Mp(p[i].S, p[i].F));
mx = p[i].S;
}
}
n = Sz(vec) - 1;
for(ll i = 2; i <= n; i++){
ll x = max(0ll, vec[i - 1].F - vec[i].S + 1);
ps[i] = x * x;
}
k = min(k, n);
fill(dp[0] + 1, dp[0] + n + 1, inf);
for(ll i = 1; i <= k; i++){
solve(i, 1, n + 1, 1, n + 1);
}
return dp[k][n];
}
/*int main(){
fast_io;
return 0;
}*/
Compilation message
aliens.cpp: In function 'void solve(ll, ll, ll, ll, ll)':
aliens.cpp:29:5: warning: variable 'opt' set but not used [-Wunused-but-set-variable]
29 | ll opt = s;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
332 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 |
1 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
460 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
304 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 |
304 KB |
Correct answer: answer = 41 |
6 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
7 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
8 |
Runtime error |
23 ms |
2068 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
332 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 |
1 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
460 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 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 |
304 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 |
304 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
23 ms |
2068 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
332 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 |
1 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
460 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 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 |
304 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 |
304 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
23 ms |
2068 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
332 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 |
1 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
460 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 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 |
304 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 |
304 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
23 ms |
2068 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
332 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 |
1 ms |
332 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
460 KB |
Correct answer: answer = 151 |
14 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
556 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 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 |
304 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 |
304 KB |
Correct answer: answer = 41 |
26 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
332 KB |
Correct answer: answer = 77137 |
28 |
Runtime error |
23 ms |
2068 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |