제출 #925354

#제출 시각아이디문제언어결과실행 시간메모리
925354antonIdeal city (IOI12_city)C++17
11 / 100
1053 ms1372 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int, int> #define ll long long pii delta[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; pii add(pii lh, pii rh){ return {lh.first+rh.first, lh.second+rh.second}; } unordered_map<ll, int> blocks; ll flat(pii pos){ return pos.first + (ll)(pos.second) * (1LL<<32); } bool check_presence(pii pos){ if(blocks.find(flat(pos))!= blocks.end()){ return true; } return false; } vector<pii> get_adj(pii pos){ vector<pii> res; for(int i = 0; i<4; i++){ pii pos2 = add(pos, delta[i]); if(check_presence(pos2)){ res.push_back(pos2); } } return res; } void BFS(pii origin){ for(pair<ll, int> e: blocks){ blocks[e.first] = -1; } blocks[flat(origin)] = 0; queue<pair<pii, int>> q; q.push({origin, 0}); while(q.size()>0){ auto cur = q.front(); auto u = cur.first; auto d= cur.second; q.pop(); for(auto v: get_adj(u)){ if(blocks[flat(v)] == -1){ blocks[flat(v)]= d+1; q.push({v, d+1}); } } } } const long long mod = 1000000000; int DistanceSum(int N, int *X, int *Y) { for(int i = 0; i<N; i++){ blocks[flat({X[i], Y[i]})] = -1; } long long res = 0; for(int i = 0; i<N; i++){ BFS({X[i], Y[i]}); for(auto e: blocks){ res = res + (long long)(e.second); } } res/=2; return res%mod; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...