Submission #562587

# Submission time Handle Problem Language Result Execution time Memory
562587 2022-05-14T17:31:23 Z Jesus Ideal city (IOI12_city) C++14
11 / 100
1000 ms 5196 KB
#include <bits/stdc++.h>

using namespace std;

int city[2002][2002];

bool revisado[2002][2002];

int visto[2002][2002];

int vacio=1;

long long int suma=0;

int lim,origen;

priority_queue<pair<long long int,int>> cola;

int col[2002], fil[2002];

void dfs(int i,int j){
    cola.push({0,city[i][j]});

    while(cola.size()>0){
        pair<long long int,int> aux=cola.top();
        cola.pop();
        if(visto[fil[aux.second]][col[aux.second]]!=vacio){
            visto[fil[aux.second]][col[aux.second]]=vacio;
            if(revisado[min(aux.second,origen)][max(aux.second,origen)]==false){
               revisado[min(aux.second,origen)][max(aux.second,origen)]=true;
               suma+=(aux.first*-1);
               suma%=1000000000;
            }
            i=fil[aux.second-1];
            j=col[aux.second-1];
            if(i<lim&&city[i+1][j]>0) cola.push({aux.first-1,city[i+1][j]});
            if(i>1&&city[i-1][j]>0) cola.push({aux.first-1,city[i-1][j]});
            if(j<lim&&city[i][j+1]>0) cola.push({aux.first-1,city[i][j+1]});
            if(j>1&&city[i][j-1]>0) cola.push({aux.first-1,city[i][j-1]});
        }

    }
}


int DistanceSum(int N, int *X, int *Y) {
    lim=N;
    long long int total=0;
    for(int i=0;i<N;i++){
        fil[i]=X[i];
        col[i]=Y[i];
        city[X[i]][Y[i]]=i+1;
    }
    for(int i=0;i<N;i++){
        suma=0;
        origen=i+1;
        dfs(X[i],Y[i]);
        total+=suma;
        total%=1000000000;
        vacio++;
    }
  return total;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 8 ms 920 KB Output is correct
7 Correct 14 ms 852 KB Output is correct
8 Correct 7 ms 980 KB Output is correct
9 Correct 10 ms 852 KB Output is correct
10 Correct 11 ms 852 KB Output is correct
11 Correct 13 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 2748 KB Output is correct
2 Correct 212 ms 2676 KB Output is correct
3 Correct 480 ms 3900 KB Output is correct
4 Correct 528 ms 3856 KB Output is correct
5 Correct 881 ms 5196 KB Output is correct
6 Execution timed out 1010 ms 4972 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 3540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 4052 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -