# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
384692 |
2021-04-02T05:14:32 Z |
anachor |
Aliens (IOI16_aliens) |
C++14 |
|
2 ms |
512 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7, K = 55;
long long sq(long long z) {
return z*z;
}
long long cost(int l, int r, int *x, int *y, long long c) {
// cout<<l<<" "<<r<<" "<<c<<" "<<y[r]<<" "<<x[l]<<" "<<(y[r] - x[l])*(y[r] - x[l]) + c<<endl;
return sq(y[r] - x[l]) - sq(max(0, y[l-1] - x[l])) + c;
}
typedef pair<long long, long long> PLL;
PLL dp[N];
PLL operator+(PLL a, PLL b) {
return PLL(a.first+b.first, a.second+b.second);
}
long long opt[N];
int x[N], y[N];
PLL check(long long c, int n, int *x, int *y) {
deque<pair<int, int>> dq;
dq.push_back({0, 1});
dp[0] = {0, 0};
for (int i=1; i<=n; i++) {
opt[i] = dq.front().first;
dp[i] = dp[opt[i]] + PLL(cost(opt[i]+1, i, x, y, c), -1);
// cout<<i<<" --> "<<opt[i]<<" "<<dp[i].first<<endl;
dq[0].second++;
if (dq.size() > 1 && dq[0].second == dq[1].second) dq.pop_front();
int en = n;
while(dq.size()) {
int o = dq.back().first, st = dq.back().second;
if (dp[o]+PLL(cost(o+1, st, x, y, c), -1) >= dp[i]+PLL(cost(i+1, st, x, y, c), -1)) dq.pop_back();
else {
int lo = st, hi = en;
while (lo < hi) {
int mid = (lo+hi+1)/2;
if (dp[o]+PLL(cost(o+1, mid, x, y, c), -1) < dp[i]+PLL(cost(i+1, mid, x, y, c), -1) ) lo = mid;
else hi = mid-1;
}
if (lo < n) dq.push_back({i, lo+1});
break;
}
en = st-1;
}
if (dq.empty()) dq.push_back({i, i+1});
}
dp[n].second *= -1;
// cout<<c<<" "<<dp[n].first<<" "<<dp[n].second<<endl;
return dp[n];
}
long long take_photos(int n, int N, int k, vector<int> xx, vector<int> yy) {
vector<pair<int, int>> ranges;
for (int i=0; i<n; i++) {
ranges.push_back({max(xx[i], yy[i]), -min(xx[i], yy[i])});
}
sort(ranges.begin(), ranges.end());
vector<pair<int, int>> r2;
for (auto pr: ranges) {
int r = pr.first, l = -pr.second;
while (r2.size() && r2.back().first >= l) r2.pop_back();
r2.push_back({l, r});
}
n = r2.size();
for (int i=1; i<=n; i++) {
x[i] = r2[i-1].first, y[i] = r2[i-1].second+1;
}
k = n;
long long lo = -1e12, hi = 1e12;
while (lo < hi) {
long long mid = lo + (hi-lo+1)/2;
if (check(mid, n, x, y).second < k) hi = mid-1;
else lo = mid;
}
auto pr = check(lo+1, n, x, y);
return min(check(lo, n, x, y).first - k*lo, pr.first - pr.second*(lo+1));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
364 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
2 |
Incorrect |
1 ms |
364 KB |
Wrong answer: output = 2, expected = 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
364 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
1 ms |
364 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
364 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
1 ms |
364 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
364 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
1 ms |
364 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Correct answer: answer = 4 |
2 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 12 |
5 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 210 |
7 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 88 |
8 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
10 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 2374 |
11 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 9502 |
12 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 151 |
14 |
Correct |
2 ms |
364 KB |
Correct answer: answer = 7550 |
15 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 7220 |
16 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 7550 |
17 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
18 |
Correct |
1 ms |
384 KB |
Correct answer: answer = 10000 |
19 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 624 |
20 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 10000 |
21 |
Correct |
1 ms |
364 KB |
Correct answer: answer = 1 |
22 |
Incorrect |
1 ms |
364 KB |
Wrong answer: output = 2, expected = 4 |
23 |
Halted |
0 ms |
0 KB |
- |