이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "
const int MAX_N = 1e7 + 10;
ll dp[MAX_N];
ll sufMin[MAX_N];
long long delivery(int N, int K, int L, int p[]) {
bool gotMid = false;
int lastSmaller = -1;
int n = N, k = K;
for(int i = 0; i < n; i ++) {
if(p[i] == L / 2 && L % 2 == 0) {
gotMid = true;
}
if(p[i] <= (L - 1) / 2) {
lastSmaller = i;
}
}
for(int i = 0; i < n; i ++) {
if(i >= k - 1) {
ll cost = mod * mod;
if(i - k + 1 <= lastSmaller && lastSmaller < i) {
cost = 2 * p[lastSmaller] + 2 * L - 2 * p[lastSmaller + 1];
} else if(i - k + 1 <= lastSmaller && lastSmaller <= i) {
cost = 2 * p[lastSmaller];
} else if(i <= lastSmaller) {
cost = 2 * p[i];
} else {
cost = 2 * L - 2 * p[i - k + 1];
}
dp[i] = dp[i - k + 1] + cost;
}
//cout << dp[i] << " ";
}
for(int i = n - 1; i > 0; i --) {
if(i == n - 1) {
sufMin[i] = dp[i];
} else {
sufMin[i] = min(dp[i] + 2 * L - 2 * p[i + 1], sufMin[i + 1]);
}
}
ll ret = mod * mod;
for(int i = 1; i <= k; i ++) {
chkmin(ret, p[i - 1] * 2 + sufMin[n - i]);
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:21:10: warning: variable 'gotMid' set but not used [-Wunused-but-set-variable]
21 | bool gotMid = false;
| ^~~~~~
# | 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... |