# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
317795 | 2020-10-30T11:49:08 Z | amunduzbaev | 이상적인 도시 (IOI12_city) | C++14 | 59 ms | 6128 KB |
//#include "grader.cpp" #include <bits/stdc++.h> using namespace std; #define ll long long const ll mod = 1e9; int n, ans; vector<pair<int, int > > ps; vector<vector<int > > edges; vector<pair<int, pair<int, int > > > cur; int dfs(int u,int p){ int size = cur[u].second.second - cur[u].second.first + 1; for(auto x:edges[u]){ if(x==p) continue; size += dfs(x, u); } ans = (ans + (n-size)*size) % mod; return size; } void build_tree(){ cur.clear(); sort(ps.begin(), ps.end()); for(int i=0;i<n;i++){ int j=i; while(j+1 < n && ps[i].first == ps[j+1].first && ps[j].second+1 == ps[j+1].second) j++; cur.push_back({ps[i].first, {ps[i].second, ps[j].second}}); i=j; } edges.clear(); edges.resize(n); int j=0; for(int i=0;i<cur.size();i++){ while(j < cur.size() && cur[j].first < cur[i].first+1) j++; if(j == cur.size()) break; while(j<n-1 && cur[j].second.second < cur[i].second.first && cur[j].first == cur[i].first+1 ) j++; while(j<=n-1 && cur[j].second.second <= cur[i].second.second && cur[j].first == cur[i].first+1 ){ edges[i].push_back(j); edges[j].push_back(i); j++; } if(j != n && cur[j].second.first <= cur[i].second.second && cur[i].first+1 == cur[j].first){ edges[i].push_back(j); edges[j].push_back(i); } } dfs(0, 0); } int DistanceSum(int N, int *x, int *y) { n=N; ps.resize(n); for(int i=0;i<n;i++) ps[i] = {x[i], y[i]}; build_tree(); for(int i=0;i<n;i++) swap(ps[i].first, ps[i].second); build_tree(); return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 360 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 1152 KB | Output is correct |
2 | Correct | 8 ms | 1280 KB | Output is correct |
3 | Correct | 21 ms | 2432 KB | Output is correct |
4 | Correct | 21 ms | 2432 KB | Output is correct |
5 | Incorrect | 43 ms | 4344 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 1536 KB | Output is correct |
2 | Correct | 10 ms | 1536 KB | Output is correct |
3 | Correct | 28 ms | 3196 KB | Output is correct |
4 | Correct | 25 ms | 3008 KB | Output is correct |
5 | Incorrect | 59 ms | 6128 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |