Submission #121834

#TimeUsernameProblemLanguageResultExecution timeMemory
121834baluteshihIdeal city (IOI12_city)C++14
32 / 100
1077 ms4480 KiB
#include <bits/stdc++.h> #define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define pb push_back #define ET cout << "\n" #define MEM(i,j) memset(i,j,sizeof i) #define F first #define S second #define MP make_pair #define ALL(v) v.begin(),v.end() #define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;} using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1}; const int MOD=1e9; vector<int> G[100005]; bitset<100005> vis; unordered_map<ll,int> mp; int DistanceSum(int N, int *X, int *Y) { int ans=0; for(int i=0;i<N;++i) mp[(ll)X[i]<<31|Y[i]]=i; for(int i=0;i<N;++i) for(int j=0;j<4;++j) { auto p=mp.find(((ll)(X[i]+dx[j])<<31)|(Y[i]+dy[j])); if(p!=mp.end()) G[i].pb(p->S); } for(int i=0;i<N;++i) { int tp=0; queue<pii> q; q.push(MP(i,0)),vis.reset(),vis[i]=1; while(!q.empty()) { auto tmp=q.front(); q.pop(),ans=(ans+tmp.S)%MOD,vis[tmp.F]=1; for(int j:G[tmp.F]) if(!vis[j]) q.push(MP(j,tmp.S+1)),vis[j]=1; ++tp; } } return ans/2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...