#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n;
const int inf = 2e9;
vector<int> col[100001];
int x[100001];
int c[100001];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> c[i];
col[c[i]].push_back(x[i]);
}
for (int i = 1; i <= n; ++i) {
sort(col[i].begin(), col[i].end());
}
llong ans = 0;
for (int i = 0; i < n; ++i) {
if (col[c[i]].size() > 1) {
if (lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i] + 1)
- lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i]) == 1) {
int v = inf;
auto ri = lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i] + 1);
if (ri != col[c[i]].end()) v = min(v, *ri - x[i]);
auto li = lower_bound(col[c[i]].begin(), col[c[i]].end(), x[i]);
if (li != col[c[i]].begin()) v = min(v, x[i] - *(--li));
ans += v;
}
}
}
printf("%lld\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2792 KB |
Output is correct |
4 |
Correct |
4 ms |
2880 KB |
Output is correct |
5 |
Correct |
4 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Correct |
5 ms |
2900 KB |
Output is correct |
8 |
Correct |
5 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2792 KB |
Output is correct |
4 |
Correct |
4 ms |
2880 KB |
Output is correct |
5 |
Correct |
4 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Correct |
5 ms |
2900 KB |
Output is correct |
8 |
Correct |
5 ms |
2900 KB |
Output is correct |
9 |
Correct |
5 ms |
2956 KB |
Output is correct |
10 |
Correct |
7 ms |
2980 KB |
Output is correct |
11 |
Correct |
5 ms |
2980 KB |
Output is correct |
12 |
Correct |
6 ms |
2980 KB |
Output is correct |
13 |
Correct |
5 ms |
2980 KB |
Output is correct |
14 |
Correct |
5 ms |
2980 KB |
Output is correct |
15 |
Correct |
5 ms |
2980 KB |
Output is correct |
16 |
Correct |
7 ms |
2980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2792 KB |
Output is correct |
4 |
Correct |
4 ms |
2880 KB |
Output is correct |
5 |
Correct |
4 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Correct |
5 ms |
2900 KB |
Output is correct |
8 |
Correct |
5 ms |
2900 KB |
Output is correct |
9 |
Correct |
5 ms |
2956 KB |
Output is correct |
10 |
Correct |
7 ms |
2980 KB |
Output is correct |
11 |
Correct |
5 ms |
2980 KB |
Output is correct |
12 |
Correct |
6 ms |
2980 KB |
Output is correct |
13 |
Correct |
5 ms |
2980 KB |
Output is correct |
14 |
Correct |
5 ms |
2980 KB |
Output is correct |
15 |
Correct |
5 ms |
2980 KB |
Output is correct |
16 |
Correct |
7 ms |
2980 KB |
Output is correct |
17 |
Correct |
7 ms |
3052 KB |
Output is correct |
18 |
Correct |
9 ms |
3052 KB |
Output is correct |
19 |
Correct |
8 ms |
3068 KB |
Output is correct |
20 |
Correct |
9 ms |
3168 KB |
Output is correct |
21 |
Correct |
8 ms |
3168 KB |
Output is correct |
22 |
Correct |
8 ms |
3168 KB |
Output is correct |
23 |
Correct |
9 ms |
3168 KB |
Output is correct |
24 |
Correct |
9 ms |
3196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
4 ms |
2792 KB |
Output is correct |
4 |
Correct |
4 ms |
2880 KB |
Output is correct |
5 |
Correct |
4 ms |
2880 KB |
Output is correct |
6 |
Correct |
5 ms |
2880 KB |
Output is correct |
7 |
Correct |
5 ms |
2900 KB |
Output is correct |
8 |
Correct |
5 ms |
2900 KB |
Output is correct |
9 |
Correct |
5 ms |
2956 KB |
Output is correct |
10 |
Correct |
7 ms |
2980 KB |
Output is correct |
11 |
Correct |
5 ms |
2980 KB |
Output is correct |
12 |
Correct |
6 ms |
2980 KB |
Output is correct |
13 |
Correct |
5 ms |
2980 KB |
Output is correct |
14 |
Correct |
5 ms |
2980 KB |
Output is correct |
15 |
Correct |
5 ms |
2980 KB |
Output is correct |
16 |
Correct |
7 ms |
2980 KB |
Output is correct |
17 |
Correct |
7 ms |
3052 KB |
Output is correct |
18 |
Correct |
9 ms |
3052 KB |
Output is correct |
19 |
Correct |
8 ms |
3068 KB |
Output is correct |
20 |
Correct |
9 ms |
3168 KB |
Output is correct |
21 |
Correct |
8 ms |
3168 KB |
Output is correct |
22 |
Correct |
8 ms |
3168 KB |
Output is correct |
23 |
Correct |
9 ms |
3168 KB |
Output is correct |
24 |
Correct |
9 ms |
3196 KB |
Output is correct |
25 |
Correct |
67 ms |
5116 KB |
Output is correct |
26 |
Correct |
43 ms |
5116 KB |
Output is correct |
27 |
Correct |
56 ms |
5116 KB |
Output is correct |
28 |
Correct |
41 ms |
5116 KB |
Output is correct |
29 |
Correct |
54 ms |
5116 KB |
Output is correct |
30 |
Correct |
59 ms |
5116 KB |
Output is correct |
31 |
Correct |
46 ms |
5116 KB |
Output is correct |
32 |
Correct |
54 ms |
5116 KB |
Output is correct |