이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
using namespace std;
const ll N = 1e6 + 5;
int n, m, cntL[N], cntR[N], R[N];
pii dp[N];
vector<int> st[N];
ll check(ll c) {
for(ll x = 1; x <= n; x++) {
dp[x] = {n * n + 5, 0};
if(cntL[x - 1] + cntR[x + 1] == m) dp[x] = dp[x - 1];
for(ll l = 1; l <= x; l++) {
ll r = R[l - 1];
if(r >= x) continue;
ll y = dp[r].f + (ll)(x - l + 1) * (x - l + 1) - (ll)(r - l + 1) * (r - l + 1) + c;
dp[x] = min(dp[x], {y, dp[r].s - 1});
}
}
return -dp[n].s;
}
long long take_photos(int N, int M, int k, std::vector<int> r1, std::vector<int> c) {
swap(N, M);
m = M; n = N;
// vector<ll> l(m + 5);
int mnl = n, mxr = 0;
for(int i = 0; i < m; i++) {
if(c[i] > r1[i]) swap(c[i], r1[i]);
int l = min(r1[i], c[i]); r1[i] = max(r1[i], c[i]);
l++; r1[i]++;
cntL[r1[i]]++; cntR[l]++;
st[l].push_back(r1[i]);
mnl = min(l, mnl); mxr = max(mxr, r1[i]);
}
if(k == 1) {
return (ll)(mxr - mnl + 1) * (mxr - mnl + 1);
}
for(int i = 1; i <= n; i++) cntL[i] += cntL[i - 1];
for(int i = n; i >= 1; i--) cntR[i] += cntR[i + 1];
int C = 0;
for(int i = 1; i <= n; i++) {
C = max(C, i);
for(ll j = 0; j < st[i].size(); j++) {
C = max(C, st[i][j]);
}
R[i] = C;
}
ll l = 0, r = 2e9, p = 0;
while(l <= r) {
ll mid = (l + r) / 2;
if(check(mid) >= k) {
p = mid;
l = mid + 1;
} else r = mid - 1;
}
check(p);
return dp[n].f - (ll)p * k;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:49:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(ll j = 0; j < st[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
# | 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... |