Submission #925352

#TimeUsernameProblemLanguageResultExecution timeMemory
925352antonIdeal city (IOI12_city)C++17
11 / 100
1055 ms2028 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int, int> 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}; } map<pii, int> blocks; bool check_presence(pii pos){ if(blocks.find(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<pii, int> e: blocks){ blocks[e.first] = -1; } blocks[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[v] == -1){ blocks[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[{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...