제출 #98198

#제출 시각아이디문제언어결과실행 시간메모리
98198E869120이상적인 도시 (IOI12_city)C++14
55 / 100
160 ms3704 KiB
#include <bits/stdc++.h> using namespace std; vector<int> G[2009]; int dist[2009], mod = 1000000000; long long cx[200009], cy[200009]; int DistanceSum(int N, int *X, int *Y) { if (N > 2000) { int minx = 2147483647, miny = 2147483647; for (int i = 0; i < N; i++) { minx = min(minx, X[i]); miny = min(miny, Y[i]); } for (int i = 0; i < N; i++) { cx[X[i] - minx]++; cy[Y[i] - miny]++; } for (int i = 1; i <= N; i++) { cx[i] += cx[i - 1]; cy[i] += cy[i - 1]; } long long sum = 0; for (int i = 0; i <= N; i++) sum += 1LL * cx[i] * (1LL * N - cx[i]); for (int i = 0; i <= N; i++) sum += 1LL * cy[i] * (1LL * N - cy[i]); return sum % mod; } else { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int V = abs(X[i] - X[j]) + abs(Y[i] - Y[j]); if (V == 1) G[i].push_back(j); } } int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) dist[j] = 10000; queue<int> que; que.push(i); dist[i] = 0; while (!que.empty()) { int pos = que.front(); que.pop(); for (int j = 0; j < (int)G[pos].size(); j++) { if (dist[G[pos][j]] > dist[pos] + 1) { dist[G[pos][j]] = dist[pos] + 1; que.push(G[pos][j]); } } } for (int j = i + 1; j < N; j++) { sum += dist[j]; sum %= mod; } } return sum; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...