이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <array>
#define all(v) (v.begin()), (v.end())
#define setall(a, val) for(auto& x : a) x = val
#define ll long long
#define cerr (cerr << "D: ")
clock_t start_time;
using namespace std;
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
void init(bool oj = 1) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
srand(time(0)); start_time = clock();
if (oj) {
#ifndef ONLINE_JUDGE
FILE* _ = freopen("in.txt", "r", stdin);
//FILE* __ = freopen("out.txt", "w", stdout);
#endif
}
}
const ll MOD = 1e9 + 7;
const ll N = 7e3 + 7;
const ll M = 2e3 + 7;
//####################################################################################
ll delivery(int N, int K, int L, vector<int> positions) {
int l = 0, r = N - 1;
ll ans = 0;
while (l <= r) {
ll a = 0;
if (positions[max(l, r - K + 1)] > L / 2)
a += 2 * (L - positions[max(l, r - K + 1)]);
else if (positions[r] > L / 2)
a += L;
else
a += 2 * positions[r];
ll b = 0;
if (positions[min(r, l + K - 1)] < L / 2)
b += 2 * positions[min(r, l + K - 1)];
else if (positions[l] < L / 2)
b += L;
else
b += 2 * (L - positions[l]);
if (a < b)
r -= K, ans += a;
else
l += K, ans += b;
}
return ans;
}
int main() {
init(0);
int n, k, l;
cin >> n >> k >> l;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
cout << delivery(n, k, l, p) << endl;
cerr << get_time() << "s" << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void init(bool)':
teams.cpp:15:9: warning: unused variable '_' [-Wunused-variable]
15 | FILE* _ = freopen("in.txt", "r", stdin);
| ^
# | 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... |
# | 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... |