Submission #430687

#TimeUsernameProblemLanguageResultExecution timeMemory
430687MarcoMeijerIdeal city (IOI12_city)C++14
0 / 100
497 ms460 KiB
#include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll MOD = 1e9; const int dx[] = {0,1,0,-1}; const int dy[] = {1,0,-1,0}; int DistanceSum(int n, int *X, int *Y) { ll res = 0; if(n <= 2000) { map<ii,int> posToI; RE(i,n) posToI[{X[i],Y[i]}] = i; RE(i,n) { // do a bfs from i queue<int> q; q.push(i); vi dep; dep.assign(n,0); while(!q.empty()) { int i = q.front(); q.pop(); int x = X[i], y = Y[i]; RE(d,4) { int nx = x+dx[d]; int ny = y+dy[d]; if(posToI.find({nx,ny}) == posToI.end()) continue; int j = posToI[{nx,ny}]; if(dep[j] != 0) continue; dep[j] = dep[i] + 1; if(i < j) res += dep[i]; q.push(j); } } res %= MOD; } } else { } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...