Submission #31108

# Submission time Handle Problem Language Result Execution time Memory
31108 2017-08-10T01:38:44 Z h0ngjun7 Ideal city (IOI12_city) C++14
32 / 100
156 ms 21872 KB
#include<bits/stdc++.h>
using namespace std;
#define MAXN2 2000
#define MOD 1000000000
#define mp make_pair
#define pint pair<int, int>
#define f first
#define s second
 
bool city[MAXN2+2][MAXN2+2];
int dis[MAXN2+2][MAXN2+2];
 
int DistanceSum(int N, int X[], int Y[]) {
    if(N>2000) return 0;
    long long ans=0;
    queue<pint > q;
    int minx=X[0], miny=Y[0];
    for(int i=1; i<N; i++) minx=min(minx, X[i]), miny=min(miny, Y[i]);
    for(int i=0; i<N; i++) X[i]-=minx-1, Y[i]-=miny-1;
    for(int i=0; i<N; i++) city[X[i]][Y[i]]=true;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++) dis[X[j]][Y[j]]=-1;
        dis[X[i]][Y[i]]=0;
        q.push(mp(X[i], Y[i]));
        while(!q.empty()){
            int x=q.front().f, y=q.front().s;
            q.pop();
            ans+=dis[x][y];
            if(city[x-1][y]&&dis[x-1][y]==-1) dis[x-1][y]=dis[x][y]+1, q.push(mp(x-1, y));
            if(city[x+1][y]&&dis[x+1][y]==-1) dis[x+1][y]=dis[x][y]+1, q.push(mp(x+1, y));
            if(city[x][y-1]&&dis[x][y-1]==-1) dis[x][y-1]=dis[x][y]+1, q.push(mp(x, y-1));
            if(city[x][y+1]&&dis[x][y+1]==-1) dis[x][y+1]=dis[x][y]+1, q.push(mp(x, y+1));
        }
        //printf("[%lld]\n", ans);
    }
    return ans/2;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21728 KB Output is correct
2 Correct 0 ms 21728 KB Output is correct
3 Correct 0 ms 21728 KB Output is correct
4 Correct 0 ms 21728 KB Output is correct
5 Correct 0 ms 21728 KB Output is correct
6 Correct 0 ms 21728 KB Output is correct
7 Correct 0 ms 21728 KB Output is correct
8 Correct 0 ms 21728 KB Output is correct
9 Correct 0 ms 21728 KB Output is correct
10 Correct 0 ms 21728 KB Output is correct
11 Correct 0 ms 21728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 21728 KB Output is correct
2 Correct 26 ms 21728 KB Output is correct
3 Correct 79 ms 21728 KB Output is correct
4 Correct 66 ms 21728 KB Output is correct
5 Correct 146 ms 21728 KB Output is correct
6 Correct 93 ms 21728 KB Output is correct
7 Correct 156 ms 21728 KB Output is correct
8 Correct 103 ms 21728 KB Output is correct
9 Correct 93 ms 21728 KB Output is correct
10 Correct 83 ms 21728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 21872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 21872 KB Output isn't correct
2 Halted 0 ms 0 KB -