Submission #810566

#TimeUsernameProblemLanguageResultExecution timeMemory
810566YassirSalamaIdeal city (IOI12_city)C++17
32 / 100
1086 ms6356 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define OVL(v,s) for(auto x:v) cout<<x<<s;cout<<endl; #define all(v) v.begin(),v.end() #define F first #define S second #define pb push_back void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #define endl "\n" #define mod 1000000007 const ll INF=1e18; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int DistanceSum(int N, int *X, int *Y) { vector<set<int>> v(N); map<pair<int,int>,int> mp; for(int i=0;i<N;i++) mp[{X[i],Y[i]}]=i; for(int i=0;i<N;i++){ for(int x=0;x<4;x++){ int ni=X[i]+dx[x]; int nj=Y[i]+dy[x]; if(mp.find({ni,nj})==mp.end()) continue; v[i].insert((*mp.find({ni,nj})).second); v[(*mp.find({ni,nj})).second].insert(i); } } int ans=0; for(int i=0;i<N;i++) { bool visited[N]; memset(visited,false,sizeof(visited)); queue<pair<int,int>> q; q.push({i,0}); while(!q.empty()){ pair<int,int> p=q.front(); q.pop(); if(visited[p.F]) continue; visited[p.F]=true; ans+=p.S; for(auto x:v[p.F]){ if(!visited[x]) q.push({x,p.S+1}); } } } return ans/2; } #ifdef IOI #define inbuf_len 1 << 16 #define outbuf_len 1 << 16 int DistanceSum(int N, int *X, int *Y); int main() { int tmp; /* Set input and output buffering */ char *inbuf, *outbuf; inbuf = (char*) malloc(inbuf_len * sizeof(char)); outbuf = (char*) malloc(outbuf_len * sizeof(char)); tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len); assert(tmp == 0); tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len); assert(tmp == 0); int N, i; tmp = scanf("%d", &N); assert(tmp == 1); int *sq_x, *sq_y; sq_x = (int*) malloc(N * sizeof(int)); sq_y = (int*) malloc(N * sizeof(int)); for (i = 0; i < N; i++) { tmp = scanf("%d %d", &sq_x[i], &sq_y[i]); assert(tmp == 2); } int ds = DistanceSum(N, sq_x, sq_y); printf("%d\n", ds); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...