이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 2e18;
struct Line{
ll k, n;
Line(ll _k = 0, ll _n = LINF){ k = _k; n = _n; }
ll operator()(ll x) const { return k*x+n; }
};
class LiChao{
ll L, R;
vector<Line> tree;
vector<array<int, 2> > ch;
int Node(){ tree.pb(Line()); ch.pb({-1, -1}); return tree.size()-1; }
int Child(int s, int i){ if (!~ch[s][i]){ int u = Node(); ch[s][i] = u; } return ch[s][i]; }
void Insert(int s, int l, int r, Line f){
int m = (l + r)>>1;
if (f(m) < tree[s](m)) swap(tree[s], f);
if (f(l) < tree[s](l)) Insert(Child(s, 0), l, m, f);
if (f(r) < tree[s](r)) Insert(Child(s, 1), m+1, r, f);
}
ll Get(int s, int l, int r, ll x) const {
if (!~s) return LINF;
int m = (l + r)>>1;
if (x <= m) return min(tree[s](x), Get(ch[s][0], l, m, x));
else return min(tree[s](x), Get(ch[s][1], m+1, r, x));
}
public:
LiChao(ll l, ll r){ Assign(l, r); }
void Assign(ll l, ll r){
L = l; R = r;
tree.clear(); ch.clear();
Node();
}
void Insert(ll k, ll n){ Insert(0, L, R, Line(k, n)); }
ll Get(ll x) const { return Get(0, L, R, x); }
};
const int mxN = 5e4+10, INF = 2e9;
ll n, m, dp[mxN][4005];
array<int, 2> a[mxN];
ll sq(ll x){ return x*x; }
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c){
for (int i = 0; i < n; i++)
a[i] = {min(r[i], c[i]), max(r[i], c[i])};
sort(a, a+n);
vector<array<int, 2> > tmp;
for (int i = 0, mx = -1; i < n; i++){
if (a[i][1] > mx) tmp.pb(a[i]);
smax(mx, a[i][1]);
}
a[0] = {-1, -1};
for (int i = 0; i < tmp.size(); i++)
a[i+1] = tmp[i];
n = tmp.size();
for (int i = 1; i <= n; i++)
dp[i][0] = LINF;
for (int j = 1; j <= k; j++){
LiChao cht(0, 1e6);
for (int i = 1; i <= n; i++){
cht.Insert(-2 * (a[i][0] - 1), dp[i-1][j-1] + sq(a[i][0] - 1) - sq(max(0, a[i-1][1] - a[i][0] + 1)));
dp[i][j] = sq(a[i][1]) + cht.Get(a[i][1]);
}
}
ll ans = LINF;
for (int i = 0; i <= k; i++)
smin(ans, dp[n][i]);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int i = 0; i < tmp.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... |