이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pair<int,int>> a;
for (int i = 0; i < n; i++) {
if (r[i] < c[i]) swap(r[i], c[i]);
a.emplace_back(r[i], c[i]);
}
sort(a.begin(), a.end());
vector<pair<int,int>> b;
for (int i = 0; i < n; i++) {
while (!b.empty() && b.back().second >= a[i].second) b.pop_back();
b.push_back(a[i]);
}
swap(a, b);
n = (int) a.size();
auto test = [&](long long c) {
const long long inf = 1e18;
vector<pair<long long, int>> dp(n + 1, make_pair(inf, 0));
dp[0] = {0, 0};
for (int j = 1; j <= n; j++) {
for (int from = j; from > 0; from--) {
long long pre = (from > 1 ? a[from - 2].first : 0);
if (pre >= a[from - 1].second) pre = (pre - a[from - 1].second + 1) * (pre - a[from - 1].second + 1);
else pre = 0;
dp[j] = min(dp[j], {dp[from - 1].first + 1ll * (a[j - 1].first - a[from - 1].second + 1) * (a[j - 1].first - a[from - 1].second + 1) + c - pre, dp[from - 1].second + 1});
}
}
return dp[n];
};
long long l = 0, R = 1ll * m * m, ans = -1;
while (l <= R) {
long long mid = l + R >> 1;
if (test(mid).second <= k) {
ans = mid;
R = mid - 1;
}
else l = mid + 1;
}
assert(ans !=- 1);
return test(ans).first - ans * k;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << take_photos(2, 6, 2, {2, 3}, {3, 4});
}*/
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | long long mid = l + R >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |