# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
852931 |
2023-09-23T08:07:22 Z |
hngwlog |
Wiring (IOI17_wiring) |
C++14 |
|
1 ms |
348 KB |
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
long long min_total_length(vector<int> r, vector<int> b) {
vector<long long> sum(_size(b));
REP(i, _size(b)) sum[
i] = b[i] + (i > 0 ? sum[i - 1] : 0);
long long ans = 0;
int j = 0;
REP(i, _size(r) - 1) {
int pos = upper_bound(b.begin(), b.end(), (r[i] + r[i + 1]) / 2) - b.begin();
pos--;
pos = min(pos, _size(b) - 1 - (_size(r) - i - 1));
if (pos <= j) {
ans += abs(r[i] - b[j]);
j++;
continue;
}
int _pos = lower_bound(b.begin(), b.end(), r[i]) - b.begin();
if (_pos > pos) ans += 1LL * (pos - j + 1) * r[i] - (sum[pos] - (j ? sum[j - 1] : 0));
else if (_pos < j) ans += sum[pos] - (j ? sum[j - 1] : 0) - 1LL * (pos - j + 1) * r[i];
else ans += 1LL * (_pos - j) * r[i] - ((_pos ? sum[_pos - 1] : 0) - (j ? sum[j - 1] : 0)) + sum[pos] - (_pos ? sum[_pos - 1] : 0) - 1LL * (pos - _pos + 1) * r[i];
j = pos + 1;
}
FOR(i, j, _size(b) - 1) ans += abs(r.back() - b[i]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '25897' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '904', found: '1016' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '19052' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '27', found: '30' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '25897' |
2 |
Halted |
0 ms |
0 KB |
- |