Submission #810598

#TimeUsernameProblemLanguageResultExecution timeMemory
810598Mouad_oujIdeal city (IOI12_city)C++17
32 / 100
1082 ms3392 KiB
#include <bits/stdc++.h> using namespace std; int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; vector<bool> vis; vector<vector<int> > adj; int ans=0; int DistanceSum(int n,int *a,int *b) { adj.resize(n); map<pair<int,int>,int > m; for(int x=0;x<n;x++) m[make_pair(a[x],b[x])]=x; for(int x=0;x<n;x++) { for(int y=0;y<4;y++) { if(m.find(make_pair(a[x]+dx[y],b[x]+dy[y]))!=m.end()) { adj[x].push_back(m[make_pair(a[x]+dx[y],b[x]+dy[y])]); adj[m[make_pair(a[x]+dx[y],b[x]+dy[y])]].push_back(x); } } } int tab[n]={0}; for(int x=0;x<n;x++) { queue<pair<int,int>> q; q.push(make_pair(x,0)); vis.assign(n,false); while(!q.empty()) { pair<int,int> p=q.front(); q.pop(); int node=p.first,dis=p.second; if(!vis[node]) { vis[node]=true; tab[x]+=dis; for(int y=0;y<adj[node].size();y++) { int to=adj[node][y]; if(!vis[to]) q.push(make_pair(to,dis+1)); } } } } ans=0; for(int x=0;x<n;x++) ans+=tab[x]; return ans/2; }

Compilation message (stderr)

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:39:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 for(int y=0;y<adj[node].size();y++)
      |                             ~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...