# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
24582 |
2017-06-10T13:30:16 Z |
Donghyun Kim(#1044) |
Aliens (IOI16_aliens) |
C++14 |
|
0 ms |
3232 KB |
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Pos{ int x, y; };
const ll inf = 1e18;
int n, m, k;
Pos a[50010];
ll x[50010], y[50010], *dp[4010];
stack<Pos> st;
struct Cht{
struct Lin{ ll a, b; };
double cr(Lin p, Lin q){ return 1.0 * (q.b - p.b) / (p.a - q.a); }
vector<Lin> v;
int f, r;
void ini(){ v.clear(); f = r = 0; }
void upd(ll a, ll b){
Lin c = {a, b};
while(r - f > 1 && cr(v[r - 2], v[r - 1]) > cr(v[r - 2], c)){ v.pop_back(); r--; }
v.push_back(c); r++;
}
ll get(ll x){
while(r - f > 1 && cr(v[f], v[f + 1]) < x) f++;
return v[f].a * x + v[f].b;
}
} C;
ll take_photos(int N, int M, int K, vector<int> r, vector<int> c) {
n = N; m = M; k = K;
for(int i = 1; i <= n; i++){
a[i] = {r[i - 1], c[i - 1]};
if(a[i].x < a[i].y) swap(a[i].x, a[i].y);
}
sort(a + 1, a + n + 1, [&](const Pos &a, const Pos &b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
});
for(int i = 1; i <= n; i++){
while(!st.empty() && st.top().y >= a[i].y) st.pop();
st.push(a[i]);
}
n = st.size();
k = min(n, k);
for(int i = n; i >= 1; i--){
x[i] = st.top().x;
y[i] = st.top().y - 1;
st.pop();
}
dp[1] = new ll[n + 1];
for(int i = 1; i <= n; i++){
dp[1][i] = (x[i] - y[1]) * (x[i] - y[1]);
}
for(int i = 2; i <= k; i++){
dp[i] = new ll[n + 1];
C.ini();
C.upd(-2 * y[i], dp[i - 1][i - 1] + y[i] * y[i] - max(0LL, (x[i - 1] - y[i]) * (x[i - 1] - y[i])));
for(int j = i; j <= n; j++){
dp[i][j] = x[j] * x[j] + C.get(x[j]);
C.upd(-2 * y[j + 1], dp[i - 1][j] + y[j + 1] * y[j + 1] - max(0LL, (x[j] - y[j + 1]) * (x[j] - y[j + 1])));
}
}
return dp[k][n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
19 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 559, expected = 624 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 5 |
5 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 21, expected = 41 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
19 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 559, expected = 624 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
19 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 559, expected = 624 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
19 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 559, expected = 624 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 4 |
4 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 52 |
6 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7696 |
9 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 49 |
13 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
3232 KB |
Correct answer: answer = 10000 |
19 |
Incorrect |
0 ms |
3232 KB |
Wrong answer: output = 559, expected = 624 |
20 |
Halted |
0 ms |
0 KB |
- |