이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
#define x first
#define y second
const int maxn = 100004;
const lint inf = (lint)4.29e12;
vector<pint> ra, a;
lint m[maxn];
int p[maxn];
lint sq(int x) { return x*(lint)x; }
lint cost(int x, int y) {
lint ret = sq(a[y].y - a[x+1].x + 1);
if (x>=0 and a[x].y >= a[x+1].x) ret -= sq(a[x].y - a[x+1].x + 1);
if (x>=0) ret += m[x];
return ret;
}
int f(lint k) {
fill(m, m+maxn, -inf);
for (int i=0, j=-1; i<a.size(); i++) {
while (j+1<i and cost(j, i) > cost(j+1, i)) j++;
m[i] = cost(j, i) + k;
p[i] = j;
}
int ret = 0;
for (int i=a.size()-1; ~i; i=p[i]) ret++;
return ret;
}
lint take_photos(int n, int M, int k, vector<int> R, vector<int> c) {
for (int i=0; i<n; i++) ra.emplace_back(min(R[i], c[i]), max(R[i], c[i]));
sort(ra.begin(), ra.end(), [](pint a, pint b) { return a.x < b.x or (a.x == b.x and a.y > b.y); });
int mx = -1;
for (pint& i : ra) {
if (i.y <= mx) continue;
mx = i.y;
a.push_back(i);
}
lint l = 0, r = inf;
while (l+1<r) {
lint m = (l+r) / 2;
if (f(m) > k) l = m;
else r = m;
}
k = f(r);
return m[a.size()-1] - r * k;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'int f(lint)':
aliens.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0, j=-1; i<a.size(); i++) {
~^~~~~~~~~
# | 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... |