# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670240 |
2022-12-08T11:12:48 Z |
1bin |
Ideal city (IOI12_city) |
C++14 |
|
58 ms |
10056 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
const ll mod = 1e9;
int n, X[NMAX], Y[NMAX], a[NMAX], w[NMAX];
vector<pair<int, int>> v;
vector<int> adj[NMAX];
ll dfs(int x, int p){
ll ret = 0;
for(int& nx : adj[x]){
if(nx == p) continue;
ret += dfs(nx, x);
ret += 1LL * w[nx] * (n - w[nx]); ret %= mod;
w[x] += w[nx];
}
return ret;
}
ll go(){
sort(all(v));
ll by = -1, bx = -1, t = 0;
for(int i = 0; i < n; i++){
auto&[x, y] = v[i];
if(bx == x && y == by + 1) a[i] = a[i - 1];
else a[i] = ++t;
w[a[i]]++;
int j = lower_bound(all(v), make_pair(x - 1, y)) - v.begin();
if(v[j] == make_pair(x - 1, y)) {
adj[a[j]].emplace_back(a[i]);
adj[a[i]].emplace_back(a[j]);
}
by = y; bx = x;
}
for(int i = 1; i <= t; i++) adj[i].erase(unique(all(adj[i])), adj[i].end());
ll ret = dfs(1, -1);
for(int i = 1; i <= t; i++) adj[i].clear(), w[i] = 0;
return ret;
}
int DistanceSum(int n_, int* X, int* Y){
ll ret = 0; n = n_;
for(int i = 0; i < n; i++) v.emplace_back(X[i], Y[i]);
ret = go();
for(int i = 0; i < n; i++) swap(v[i].first, v[i].second);
ret += go(); ret %= mod;
return ret;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> X[i] >> Y[i];
cout << DistanceSum(n, X, Y);
return 0;
}*/
Compilation message
city.cpp: In function 'll go()':
city.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | auto&[x, y] = v[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
3 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2632 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2772 KB |
Output is correct |
7 |
Correct |
4 ms |
2676 KB |
Output is correct |
8 |
Correct |
3 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3432 KB |
Output is correct |
2 |
Correct |
10 ms |
3684 KB |
Output is correct |
3 |
Correct |
24 ms |
4684 KB |
Output is correct |
4 |
Correct |
25 ms |
5088 KB |
Output is correct |
5 |
Correct |
49 ms |
6792 KB |
Output is correct |
6 |
Correct |
50 ms |
7528 KB |
Output is correct |
7 |
Correct |
50 ms |
7580 KB |
Output is correct |
8 |
Correct |
49 ms |
6672 KB |
Output is correct |
9 |
Correct |
50 ms |
7384 KB |
Output is correct |
10 |
Correct |
54 ms |
10056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3636 KB |
Output is correct |
2 |
Correct |
13 ms |
3712 KB |
Output is correct |
3 |
Correct |
39 ms |
5044 KB |
Output is correct |
4 |
Correct |
28 ms |
5132 KB |
Output is correct |
5 |
Correct |
58 ms |
7404 KB |
Output is correct |
6 |
Correct |
54 ms |
7524 KB |
Output is correct |
7 |
Correct |
56 ms |
7512 KB |
Output is correct |
8 |
Correct |
53 ms |
7372 KB |
Output is correct |
9 |
Correct |
54 ms |
7116 KB |
Output is correct |
10 |
Correct |
56 ms |
7260 KB |
Output is correct |