#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
#define ll long long
struct line {
ll m, c; int id;
ll eval(ll x) {
return m * x + c;
}
long double intersectX(line o) const {
return (long double) (c - o.c) / (o.m - m);
}
};
vector<pair<int, int>> points;
pair<ll, ll> ct(ll c) {
deque<line> dq;
dq.push_back({-2 * points[0].first, points[0].first * points[0].first - 2 * points[0].first, 0});
int n= points.size();
vector<int> ct(n + 5);
vector<ll> dp(n + 5);
for (int i = 0; i < n; i++) {
while (dq.size() >= 2 && dq[0].eval(points[i].second) >= dq[1].eval(points[i].second)) dq.pop_front();
ll cur = dq.front().eval(points[i].second) + (points[i].second + 1) * (points[i].second + 1) + c;
dp[i] = cur;
ct[i + 1] = ct[dq.front().id] + 1;
if (i == n-1) break;
line l = {-2 * points[i+1].first, points[i + 1].first * points[i + 1].first - 2 * points[i + 1].first + dp[i] - max(points[i].second - points[i + 1].first + 1, 0) * max(points[i].second - points[i + 1].first + 1, 0), i + 1};
while (dq.size() >= 2 && l.intersectX(dq.back()) <= dq.back().intersectX(dq[dq.size() - 2])) dq.pop_back();
dq.push_back(l);
}
return {ct[n], dp[n-1]};
}
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]);
points.emplace_back(r[i], c[i]);
}
sort(points.begin(), points.end(), [](pair<int, int> a, pair<int, int> b) {
if (a.second == b.second) {
return a.first > b.first;
} else return a.second < b.second;
});
vector<pair<int, int>> final;
for (int i = 0; i < n; i++) {
while (!final.empty() && final.back().first >= points[i].first) final.pop_back();
final.push_back(points[i]);
}
points = final;
test(points);
ll left = 0, right = 1e13;
ct(0);
while (left != right) {
ll mid = (left + right) / 2;
if (ct(mid).first > k) left = mid + 1;
else right = mid;
}
auto ans = ct(left);
return ans.second - left * k;
}
//int main() {
// take_photos(2, 2, 1, {0, 1}, {0, 1});
//
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
284 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
2 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
4 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 5 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 41 |
6 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 71923 |
7 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
8 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 741, expected = 764 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
284 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
284 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
284 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
2 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
3 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 4 |
4 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 12 |
5 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 52 |
6 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 210 |
7 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 88 |
8 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7696 |
9 |
Correct |
1 ms |
284 KB |
Correct answer: answer = 1 |
10 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 2374 |
11 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 9502 |
12 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 49 |
13 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 151 |
14 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
15 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7220 |
16 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 7550 |
17 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
18 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
19 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 624 |
20 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 10000 |
21 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
22 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 4 |
23 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 1 |
24 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 5 |
25 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 41 |
26 |
Correct |
0 ms |
204 KB |
Correct answer: answer = 71923 |
27 |
Correct |
1 ms |
204 KB |
Correct answer: answer = 77137 |
28 |
Incorrect |
1 ms |
204 KB |
Wrong answer: output = 741, expected = 764 |
29 |
Halted |
0 ms |
0 KB |
- |