// . .. ... .... ..... be name khoda ..... .... ... .. . \\
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2000002;
const int BLUE = 1;
const int RED = 2;
struct Point
{
int x, color;
bool operator <(const Point &p) const { return x < p.x; }
};
Point p[N], tmp[N];
int blockRightCnt[N];
long long min_total_length(vector<int> red, vector<int> blue)
{
int nb = blue.size();
int nr = red.size();
for(int i = 0; i < nb; i++)
{
tmp[i].x = blue[i];
tmp[i].color = BLUE;
}
for(int i = 0; i < nr; i++)
{
tmp[nb + i].x = red[i];
tmp[nb + i].color = RED;
}
merge(tmp, tmp + nb, tmp + nb, tmp + nb + nr, p + 1);
long long ans = 0;
int n = nb + nr;
int st = 1, lastSz = 0;
for(int i = 1; i <= n; i++)
{
if(i == n || p[i].color != p[i + 1].color)
{
int sz = i - st + 1;
long long sum = 0;
if(i == n)
blockRightCnt[i] = 0;
else if(st == 1)
blockRightCnt[i] = sz;
else
blockRightCnt[i] = (sz + (lastSz <= sz/2))/2;
sum = 1LL * blockRightCnt[i] * (blockRightCnt[i] - 1)/2;
sum += 1LL * (sz - blockRightCnt[i]) * (sz - blockRightCnt[i] - 1)/2;
if(st != 1)
sum += max(blockRightCnt[st - 1], sz - blockRightCnt[i]);
// cerr << st << ", " << i << " : " << blockRightCnt[i] << " => " << sum << endl;
ans += sum;
st = i + 1;
lastSz = blockRightCnt[i];
}
}
return ans;
}
Compilation message
wiring.cpp:1:2: warning: multi-line comment [-Wcomment]
// . .. ... .... ..... be name khoda ..... .... ... .. . \\
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
41080 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '63' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
41080 KB |
3rd lines differ - on the 1st token, expected: '904', found: '315' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
41080 KB |
3rd lines differ - on the 1st token, expected: '316', found: '36' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
41080 KB |
Output is correct |
2 |
Correct |
26 ms |
42648 KB |
Output is correct |
3 |
Correct |
29 ms |
42648 KB |
Output is correct |
4 |
Correct |
39 ms |
42648 KB |
Output is correct |
5 |
Correct |
29 ms |
42648 KB |
Output is correct |
6 |
Correct |
0 ms |
41080 KB |
Output is correct |
7 |
Correct |
0 ms |
41080 KB |
Output is correct |
8 |
Correct |
0 ms |
41080 KB |
Output is correct |
9 |
Correct |
0 ms |
41080 KB |
Output is correct |
10 |
Correct |
0 ms |
41080 KB |
Output is correct |
11 |
Correct |
0 ms |
41080 KB |
Output is correct |
12 |
Correct |
0 ms |
41080 KB |
Output is correct |
13 |
Correct |
0 ms |
41080 KB |
Output is correct |
14 |
Correct |
0 ms |
41080 KB |
Output is correct |
15 |
Correct |
0 ms |
41080 KB |
Output is correct |
16 |
Correct |
0 ms |
41080 KB |
Output is correct |
17 |
Correct |
0 ms |
41080 KB |
Output is correct |
18 |
Correct |
23 ms |
42648 KB |
Output is correct |
19 |
Correct |
26 ms |
42648 KB |
Output is correct |
20 |
Correct |
26 ms |
42648 KB |
Output is correct |
21 |
Correct |
26 ms |
42648 KB |
Output is correct |
22 |
Correct |
26 ms |
42648 KB |
Output is correct |
23 |
Correct |
36 ms |
42648 KB |
Output is correct |
24 |
Correct |
43 ms |
42648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
41080 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '63' |
2 |
Halted |
0 ms |
0 KB |
- |