Submission #810598

# Submission time Handle Problem Language Result Execution time Memory
810598 2023-08-06T11:58:08 Z Mouad_ouj Ideal city (IOI12_city) C++17
32 / 100
1000 ms 3392 KB
#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

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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 3 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 340 KB Output is correct
2 Correct 65 ms 440 KB Output is correct
3 Correct 115 ms 512 KB Output is correct
4 Correct 148 ms 532 KB Output is correct
5 Correct 214 ms 620 KB Output is correct
6 Correct 291 ms 624 KB Output is correct
7 Correct 206 ms 592 KB Output is correct
8 Correct 297 ms 596 KB Output is correct
9 Correct 291 ms 620 KB Output is correct
10 Correct 298 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 3392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 3276 KB Time limit exceeded
2 Halted 0 ms 0 KB -