Submission #62414

# Submission time Handle Problem Language Result Execution time Memory
62414 2018-07-28T11:41:06 Z theknife2001 Ideal city (IOI12_city) C++17
32 / 100
1000 ms 32132 KB
#include <bits/stdc++.h>

using namespace std;
const int N=2005;
int dist[N][N];
int grid[N][N];
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=grid[x][y];
            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;
  memset(grid,-1,sizeof grid);
  for(int i=0;i<n;i++)
  {
      grid[X[i]][Y[i]]=i;
  }
  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 24 ms 16064 KB Output is correct
2 Correct 19 ms 16232 KB Output is correct
3 Correct 16 ms 16324 KB Output is correct
4 Correct 18 ms 16696 KB Output is correct
5 Correct 17 ms 16696 KB Output is correct
6 Correct 18 ms 17284 KB Output is correct
7 Correct 23 ms 17284 KB Output is correct
8 Correct 20 ms 17284 KB Output is correct
9 Correct 22 ms 17284 KB Output is correct
10 Correct 21 ms 17284 KB Output is correct
11 Correct 23 ms 17284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 24112 KB Output is correct
2 Correct 67 ms 24112 KB Output is correct
3 Correct 112 ms 28128 KB Output is correct
4 Correct 136 ms 28136 KB Output is correct
5 Correct 198 ms 32116 KB Output is correct
6 Correct 198 ms 32116 KB Output is correct
7 Correct 243 ms 32116 KB Output is correct
8 Correct 151 ms 32116 KB Output is correct
9 Correct 151 ms 32132 KB Output is correct
10 Correct 137 ms 32132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 32132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 32132 KB Time limit exceeded
2 Halted 0 ms 0 KB -