이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 1000006;
int n, k;
LL m, l[N], r[N],pos[N];
LL ans=mod*mod;
LL delivery(int N, int K, int L, int* P)
{
n = N;
k = min(K,N);
m = L;
for (int i = 0; i < n; i++)
if (P[i])
pos[i + 1] = P[i];
pos[n + 1] = m;
for (int i = 1; i <= n; i++)
{
int id = (i - 1) / k;
l[i] = min(l[id * k], l[max(i - k, 0)]);
l[i] += abs(pos[i] - pos[0]) * 2ll;
}
reverse(pos, pos + 1 + n + 1);
for (int i = 1; i <= n; i++)
{
int id = (i - 1) / k;
r[i] = min(r[id * k], r[max(i - k, 0)]);
r[i] += abs(pos[i] - pos[0]) * 2ll;
}
reverse(pos, pos + 1 + n + 1);
for (int i = 0; i <= n; i++)
ans = min(ans, l[i] + r[n - i]);
for (int i = 0; i <= n; i++)
ans = min(ans, l[i] + r[max(0, n - i - k)] + m);
for (int i = 0; i <= n; i++)
ans = min(ans, r[i] + l[max(0, n - i - k)] + m);
return ans;
}
#ifdef death
int main()
{
int N, K, L;
int P[102];
cin >> N >> K >> L;
for (int i = 0; i < N; i++)
cin >> P[i];
cout << delivery(N, K, L, P) << endl;
return 0;
}
#endif
/*
3 2 8
1 2 5
4 3 6
0 0 4 5
2 3 7
3 4
0 1 2 3 4 5 6 0
* *
*/
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:31:40: warning: declaration of 'N' shadows a global declaration [-Wshadow]
LL delivery(int N, int K, int L, int* P)
^
boxes.cpp:25:11: note: shadowed declaration is here
const int N = 1000006;
^
# | 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... |