Submission #62413

# Submission time Handle Problem Language Result Execution time Memory
62413 2018-07-28T11:38:10 Z theknife2001 Ideal city (IOI12_city) C++17
11 / 100
1000 ms 12724 KB
#include <bits/stdc++.h>

using namespace std;
const int N=2005;
int dist[N][N];
map < pair < int , int > , int > mp;
int mx[]={ 0, 0,-1,+1};
int my[]={-1,+1, 0, 0};
int n;

void bfs(int s,int *X,int *Y)
{
    for(int i=0;i<n;i++)
        dist[s][i]=1e9+55;
    dist[s][s]=0;
    queue < int > q;
    q.push(s);
    int u ,c ,v;
    int x,y;
    while(q.size())
    {
        u=q.front();
        c=dist[s][u];
        q.pop();
        for(int i=0;i<4;i++)
        {
            x=mx[i]+X[u];
            y=my[i]+Y[u];
            v=mp[{x,y}];
            if(v==0)
                continue;
            v--;
            if(dist[s][v]>c+1)
            {
                dist[s][v]=c+1;
                q.push(v);
            }
        }
    }
}

int DistanceSum(int N, int *X, int *Y) {

  n=N;
  long long ans=0;
  int m=1e9;
  for(int i=0;i<n;i++)
  {
      mp[{X[i],Y[i]}]=i+1;
  }
  for(int i=0;i<n;i++)
    bfs(i,X,Y);
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
        ans+=dist[i][j];
        ans%=m;
    }
  }
  int ret=ans;
  return ret;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 5 ms 964 KB Output is correct
5 Correct 7 ms 964 KB Output is correct
6 Correct 15 ms 1616 KB Output is correct
7 Correct 13 ms 1616 KB Output is correct
8 Correct 14 ms 1616 KB Output is correct
9 Correct 16 ms 1616 KB Output is correct
10 Correct 15 ms 1616 KB Output is correct
11 Correct 16 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 8560 KB Output is correct
2 Correct 388 ms 8588 KB Output is correct
3 Execution timed out 1014 ms 12724 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 12724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 12724 KB Time limit exceeded
2 Halted 0 ms 0 KB -