#include "bits/stdc++.h"
#define int long long
#define fi first
#define se second
#define pb push_back
using namespace std;
const int BIG = 1e18;
const int is_query = -BIG;
struct line {
int m, b;
mutable function<const line*()> succ;
bool operator<(const line& rhs) const {
if (rhs.b != is_query) return m < rhs.m;
const line* s = succ();
if (!s) return 0;
int x = rhs.m;
return b - s->b < (s->m - m) * x;
}
};
struct dynamic_hull : public multiset<line> {
const int inf = BIG;
bool bad(iterator y) {
auto z = next(y);
if (y == begin()) {
if (z == end()) return 0;
return y->m == z->m && y->b <= z->b;
}
auto x = prev(y);
if (z == end()) return y->m == x->m && y->b <= x->b;
int v1 = (x->b - y->b);
if (y->m == x->m) v1 = x->b > y->b ? inf : -inf;
else v1 /= (y->m - x->m);
int v2 = (y->b - z->b);
if (z->m == y->m) v2 = y->b > z->b ? inf : -inf;
else v2 /= (z->m - y->m);
return v1 >= v2;
}
void insert_line(int m, int b) {
auto y = insert({m,b});
y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
if (bad(y)) { erase(y); return; }
while (next(y) != end() && bad(next(y))) erase(next(y));
while (y != begin() && bad(prev(y))) erase(prev(y));
}
int eval(int x) {
auto l = *lower_bound((line) { x, is_query });
return l.m * x + l.b;
}
};
int N,M,K;
int take_photos(signed N, signed M,signed K,vector<signed>r, vector<signed>c){
sort(r.begin(), r.end());
int dp[K+1][N];
for(int i=0;i<N;i++){
dp[1][i]=(r[i]-r[0]+1)*(r[i]-r[0]+1);
}
for(int i=2;i<=K;i++){
for(int j=i-1;j<N;j++){
dp[i][j]=1e14;
for(int k=i-2;k<j;k++){
dp[i][j]=min(dp[i][j],dp[i-1][k]+(r[j]-r[k+1]+1)*(r[j]-r[k+1]+1));
}
}
}
int ans=1e18;
for(int i=1;i<=K;i++) ans=min(ans, dp[i][N-1]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 1, expected = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
204 KB |
Correct answer: answer = 5 |
5 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 41 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 71923 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
8 |
Correct |
31 ms |
1156 KB |
Correct answer: answer = 764 |
9 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 250000 |
10 |
Correct |
36 ms |
2132 KB |
Correct answer: answer = 500 |
11 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 32 |
12 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 130050 |
13 |
Correct |
10 ms |
492 KB |
Correct answer: answer = 5110 |
14 |
Correct |
2 ms |
332 KB |
Correct answer: answer = 2626 |
15 |
Correct |
4 ms |
332 KB |
Correct answer: answer = 796 |
16 |
Correct |
7 ms |
332 KB |
Correct answer: answer = 7580 |
17 |
Correct |
23 ms |
688 KB |
Correct answer: answer = 1904 |
18 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 996004 |
19 |
Correct |
4 ms |
332 KB |
Correct answer: answer = 38817 |
20 |
Correct |
18 ms |
600 KB |
Correct answer: answer = 4096 |
21 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
37 ms |
2184 KB |
Correct answer: answer = 1 |
23 |
Correct |
25 ms |
716 KB |
Correct answer: answer = 2040 |
24 |
Correct |
36 ms |
2120 KB |
Correct answer: answer = 2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 1, expected = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 1, expected = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 1, expected = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 1, expected = 4 |
2 |
Halted |
0 ms |
0 KB |
- |