이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pll pair<ll, ll>
using namespace std;
typedef long long ll;
const int maxN = 5e4 + 10, maxK = 510;
const ll oo = 2e15;
ll las[maxN], dp[maxN], f[maxN];
int l[maxN], r[maxN];
vector <pii> que;
pll lines[maxN];
int sz = 0;
bool cmp(pii a1, pii a2)
{
if(a1.F != a2.F) return a1.F < a2.F;
return a1.S > a2.S;
}
ll barkhord(pll A, pll B)
{
return (B.F - A.F + A.S - B.F - 1) / (A.S - B.S);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
if(n > maxN) return cout << 1/0 << endl, -1;
for (int i=0; i<n; i++)
{
if(r[i] <= c[i])
c[i] ++;
else r[i] ++;
que.pb({min(r[i], c[i]), max(r[i], c[i])});
}
sort(que.begin(), que.end(), cmp);
int mx = -1, cnt = 0;
for (int i=0; i<n; i++)
{
if(mx >= que[i].S) continue ;
else
{
l[cnt] = que[i].F, r[cnt] = que[i].S;
mx = max(mx, que[i].S);
cnt ++;
}
}
n = cnt;
for (int i=0; i<=n; i++) las[i] = oo;
las[0] = 0;
for (int i=0; i<n-1; i++)
if(r[i] > l[i + 1]) f[i] = 1LL * (r[i] - l[i + 1]) * (r[i] - l[i + 1]);
for (int j=1; j<=k; j++)
{
dp[0] = 0;
sz = 0;
int ptr = 0;
for (int i=1; i<=n; i++)
{
ll c = 0;
if(i - 1 > 0) c = f[i - 2];
if(las[i - 1] < oo)
{
pll t = {las[i - 1] - c + (ll)l[i - 1] * l[i - 1], -2LL * l[i - 1]};
while(sz >= 2 && barkhord(lines[sz - 2], lines[sz - 1]) >= barkhord(lines[sz - 1], t)) sz--;
lines[sz ++] = t;
}
ptr = min(ptr, sz - 1);
while(ptr < sz - 1 && barkhord(lines[ptr], lines[ptr + 1]) <= r[i - 1]) ptr ++;
dp[i] = lines[ptr].F + (ll)r[i - 1] * r[i - 1] + (ll)r[i - 1] * lines[ptr].S;
}
for (int i=1; i<=n; i++)
las[i] = dp[i];
}
return dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:37:31: warning: division by zero [-Wdiv-by-zero]
if(n > maxN) return cout << 1/0 << endl, -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... |