# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
49041 |
2018-05-21T13:20:14 Z |
polyfish |
Wiring (IOI17_wiring) |
C++14 |
|
177 ms |
22124 KB |
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';
#define PR0(A, n) cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';
const int maxn = 200002;
const int64_t inf = 1e18;
struct rmq {
int n;
int64_t container[maxn*4];
void init(int _n) {
n = _n;
for (int i=0; i<=4*n; ++i)
container[i] = inf;
}
void update(int pos, int64_t val, int l, int r, int id) {
if (pos<l || pos>r)
return;
if (l==pos && pos==r) {
container[id] = val;
return;
}
int mid = (l+r)/2;
update(pos, val, l, mid, id*2);
update(pos, val, mid+1, r, id*2+1);
container[id] = min(container[id*2], container[id*2+1]);
}
int64_t get(int u, int v, int l, int r, int id) {
if (v<l || u>r)
return inf;
if (u<=l && r<=v)
return container[id];
int mid = (l+r)/2;
return min(get(u, v, l, mid, id*2),
get(u, v, mid+1, r, id*2+1));
}
void update(int pos, int val) {
update(pos, val, 1, n, 1);
}
int64_t get(int u, int v) {
if (u>v)
return inf;
return get(u, v, 1, n, 1);
}
} T1, T2;
int m, n, L[maxn], R[maxn], pos[maxn];
pair<int, int> a[maxn];
int64_t f[maxn], ps[2][maxn];
void enter(vector<int> r, vector<int> b) {
m = r.size(); n = b.size();
for (int i=1; i<=m; ++i) {
a[i] = make_pair(r[i-1], 0);
}
for (int i=1; i<=n; ++i) {
a[m+i] = make_pair(b[i-1], 1);
}
}
void init() {
n = m+n;
sort(a+1, a+n+1);
int cnt = 0;
for (int i=1; i<=n+1; ++i) {
if (i==1 || i==n+1 || a[i].second!=a[i-1].second) {
++cnt;
L[cnt] = i;
R[cnt-1] = i-1;
}
pos[i] = cnt;
}
for (int i=1; i<=n; ++i) {
for (int j=0; j<2; ++j)
ps[j][i] = ps[j][i-1] + (a[i].second==j ? a[i].first : 0);
}
T1.init(n);
T2.init(n);
}
long long min_total_length(vector<int> red, vector<int> blue) {
// freopen("wiring.inp", "r", stdin);
// freopen("wiring.out", "w", stdout);
// ios::sync_with_stdio(0); cin.tie(0);
enter(red, blue);
init();
int64_t extra1 = 1LL*(-1+R[pos[1]])*a[L[pos[1]+1]].first;
int64_t extra2 = -1LL*(1-R[pos[1]])*a[R[pos[1]]].first;
T1.update(1, extra1);
T2.update(1, extra2);
for (int i=1; i<=n; ++i) {
f[i] = inf;
if (pos[i]==1) {
continue;
}
int l = L[pos[i]-1], r = R[pos[i]-1];
int w = a[i].second, b = w^1;
f[i] = T1.get(l, r-i+L[pos[i]]) + (-i + L[pos[i]])*a[L[pos[i]]].first
+ ps[w][i] - ps[b][i];
f[i] = min(f[i], T2.get(max(l, r-i+L[pos[i]]), r) - (i-L[pos[i]])*a[R[pos[i]-1]].first
+ ps[w][i] - ps[b][i]);
int64_t extra1 = 1LL*(-i+R[pos[i]])*a[L[pos[i]+1]].first;
int64_t extra2 = -1LL*(i-R[pos[i]])*a[R[pos[i]]].first;
T1.update(i, min(f[i], f[i-1])+ps[w][i-1]-ps[b][i-1] + extra1);
T2.update(i, min(f[i], f[i-1])+ps[w][i-1]-ps[b][i-1] + extra2);
}
return f[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
744 KB |
Output is correct |
8 |
Correct |
3 ms |
744 KB |
Output is correct |
9 |
Correct |
3 ms |
744 KB |
Output is correct |
10 |
Correct |
3 ms |
744 KB |
Output is correct |
11 |
Correct |
3 ms |
744 KB |
Output is correct |
12 |
Correct |
3 ms |
744 KB |
Output is correct |
13 |
Correct |
2 ms |
744 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
2 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Incorrect |
84 ms |
16528 KB |
3rd lines differ - on the 1st token, expected: '41596985758595', found: '8392593593219' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16528 KB |
Output is correct |
2 |
Correct |
2 ms |
16528 KB |
Output is correct |
3 |
Incorrect |
177 ms |
22124 KB |
3rd lines differ - on the 1st token, expected: '1068938599', found: '241687106566' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
22124 KB |
Output is correct |
2 |
Incorrect |
175 ms |
22124 KB |
3rd lines differ - on the 1st token, expected: '373710605', found: '402454260' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
744 KB |
Output is correct |
8 |
Correct |
3 ms |
744 KB |
Output is correct |
9 |
Correct |
3 ms |
744 KB |
Output is correct |
10 |
Correct |
3 ms |
744 KB |
Output is correct |
11 |
Correct |
3 ms |
744 KB |
Output is correct |
12 |
Correct |
3 ms |
744 KB |
Output is correct |
13 |
Correct |
2 ms |
744 KB |
Output is correct |
14 |
Correct |
2 ms |
744 KB |
Output is correct |
15 |
Correct |
2 ms |
744 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
2 ms |
764 KB |
Output is correct |
18 |
Correct |
2 ms |
764 KB |
Output is correct |
19 |
Incorrect |
84 ms |
16528 KB |
3rd lines differ - on the 1st token, expected: '41596985758595', found: '8392593593219' |
20 |
Halted |
0 ms |
0 KB |
- |