답안 #104863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104863 2019-04-09T11:50:59 Z win11905 이상적인 도시 (IOI12_city) C++11
100 / 100
256 ms 24688 KB
#include <bits/stdc++.h>
#define long long long
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define x first
#define y second
using namespace std;

const int M = 1e9;
const int N = 1e5+5;

vector<set<int> > g;
vector<int> sz;
vector<pii> vec;
int n, ans;

pii dfs(int u, int p) {
    pii now(sz[u], 0);
    for(auto v : g[u]) if(v != p) {
        pii z = dfs(v, u);
        ans = (ans + 1ll * now.x * z.y + 1ll * z.x * now.y) % M;
        now.x = (now.x + z.x) % M, now.y = (now.y + z.y) % M;
    }
    return pii(now.x, (now.y + now.x) % M);
}

void solve() {
    g = vector<set<int> >(n+1), sz = vector<int>(n+1);
    sort(all(vec));
    map<pii, int> Mp;
    for(int i = 1, p = 0; p != n; ++i) {
        do {
            int z = Mp[pii(vec[p].x-1, vec[p].y)];
            if(z) g[z].emplace(i), g[i].emplace(z);
            Mp[vec[p++]] = i, sz[i]++;
        } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); 
    }
    dfs(1, 0);
}

int DistanceSum(int n, int x[], int y[]) {
    ::n = n;
    for(int i = 0; i < n; ++i) vec.emplace_back(x[i], y[i]);
    solve();
    for(auto &x : vec) swap(x.x, x.y);
    solve();
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 740 KB Output is correct
10 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 4092 KB Output is correct
2 Correct 25 ms 4092 KB Output is correct
3 Correct 63 ms 9524 KB Output is correct
4 Correct 73 ms 9592 KB Output is correct
5 Correct 149 ms 18388 KB Output is correct
6 Correct 140 ms 18516 KB Output is correct
7 Correct 162 ms 18672 KB Output is correct
8 Correct 127 ms 18288 KB Output is correct
9 Correct 159 ms 18736 KB Output is correct
10 Correct 179 ms 23688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 5364 KB Output is correct
2 Correct 33 ms 4988 KB Output is correct
3 Correct 107 ms 12532 KB Output is correct
4 Correct 88 ms 11380 KB Output is correct
5 Correct 211 ms 24404 KB Output is correct
6 Correct 155 ms 20848 KB Output is correct
7 Correct 256 ms 24688 KB Output is correct
8 Correct 178 ms 21080 KB Output is correct
9 Correct 152 ms 20180 KB Output is correct
10 Correct 146 ms 19940 KB Output is correct