이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll delivery(int n, int k, int l, int p[]) {
vl a, b;
a.pb(0);
rep(i, n) {
if (p[i] <= l / 2) a.pb(p[i]);
else b.pb(l - p[i]);
}
b.pb(0);
reverse(all(b));
rep(i, SZ(a)) {
a[i] *= 2;
if (i >= k) a[i] += a[i - k];
}
rep(i, SZ(b)) {
b[i] *= 2;
if (i >= k) b[i] += b[i - k];
}
ll ans = a.back() + b.back();
ll mx = max(0LL, ans - ll(n + k - 1) / k * l);
for (ll &i: a) i = a.back() - i;
for (ll &i: b) i = b.back() - i;
reverse(all(a));
reverse(all(b));
// rep(i, SZ(a)) rep(j, SZ(b)) {
// if ((i + j) % k) continue;
// chmax(mx, a[i] + b[j] - ll(i + j + k - 1) / k * l);
// }
rep(sa, k + 1) {
int ori = sa;
int sb = k - sa;
if (sa >= SZ(a) or sb >= SZ(b)) continue;
ll now = a[sa] + b[sb] - l;
chmax(mx, now);
while (sa + k < SZ(a) or sb + k < SZ(b)) {
if (sa + k < SZ(a) and sb + k < SZ(b)) {
if (a[sa + k] - a[sa] > b[sb + k] - b[sb]) {
now += a[sa + k] - a[sa] - l;
sa += k;
} else {
now += b[sb + k] - b[sb] - l;
sb += k;
}
} else if (sa + k < SZ(a)) {
now += a[sa + k] - a[sa] - l;
sa += k;
} else {
now += b[sb + k] - b[sb] - l;
sb += k;
}
chmax(mx, now);
}
sa = ori;
}
return ans - mx;
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:71:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
71 | int ori = sa;
| ^~
boxes.cpp:72:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
72 | int sb = k - sa;
| ~~^~~~
# | 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... |