제출 #287876

#제출 시각아이디문제언어결과실행 시간메모리
2878762qbingxuan이상적인 도시 (IOI12_city)C++14
32 / 100
1098 ms2048 KiB
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)

using namespace std;
const int MOD = 1000000000;

int DistanceSum(int n, int x[], int y[]) {
    vector<tuple<int,int,int>> p(n);
    vector<vector<int>> g(n);
    for(int i = 0; i < n; i++) p[i] = {i, x[i], y[i]};
    sort(all(p), [](auto a, auto b){return get<1>(a) != get<1>(b) ? get<1>(a) < get<1>(b) : get<2>(a) < get<2>(b);});
    for(int i = 1; i < n; i++) if(get<1>(p[i]) == get<1>(p[i-1]) && get<2>(p[i]) == get<2>(p[i-1])+1) {
        int a = get<0>(p[i]), b = get<0>(p[i-1]);
        g[a].pb(b), g[b].pb(a);
    }
    sort(all(p), [](auto a, auto b){return get<2>(a) != get<2>(b) ? get<2>(a) < get<2>(b) : get<1>(a) < get<1>(b);});
    for(int i = 1; i < n; i++) if(get<2>(p[i]) == get<2>(p[i-1]) && get<1>(p[i]) == get<1>(p[i-1])+1) {
        int a = get<0>(p[i]), b = get<0>(p[i-1]);
        g[a].pb(b), g[b].pb(a);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        queue<int> q;
        vector<int> dis(n, -1);
        dis[i] = 0;
        q.push(i);
        while(!q.empty()) {
            int i = q.front(); q.pop();
            for(int j: g[i]) if(dis[j] == -1) dis[j] = dis[i] + 1, q.push(j);
        }
        for(int j = 0; j < i; j++) ans = (ans + dis[j]) % MOD;
    }
    debug(ans);
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...