Submission #429643

#TimeUsernameProblemLanguageResultExecution timeMemory
429643oscar1fIdeal city (IOI12_city)C++17
11 / 100
1092 ms3148 KiB
#include<bits/stdc++.h> /*#include <stdio.h> #include <stdlib.h> #include <assert.h>*/ using namespace std; /* #define inbuf_len 1 << 16 #define outbuf_len 1 << 16*/ const int MOD=1000*1000*1000,MAX_BLOCS=100*1000+1; int somme,dist,longueur,proch; int dv[MAX_BLOCS],pos[MAX_BLOCS][2]; map<pair<int,int>,int> grille; deque<pair<int,int>> atraiter; int DistanceSum(int nbBlocs, int *X, int *Y) { for (int i=1;i<=nbBlocs;i++) { pos[i][0]=X[i-1]; pos[i][1]=Y[i-1]; grille[make_pair(pos[i][0],pos[i][1])]=i; } for (int deb=1;deb<nbBlocs;deb++) { dist=0; atraiter.push_back(make_pair(pos[deb][0],pos[deb][1])); while (atraiter.size()>0) { longueur=atraiter.size(); for (int i=0;i<longueur;i++) { proch=grille[atraiter.front()]; atraiter.pop_front(); if (proch>0 and dv[proch]!=deb) { dv[proch]=deb; if (proch>deb) { somme+=dist; somme%=MOD; } atraiter.push_back(make_pair(pos[proch][0]+1,pos[proch][1])); atraiter.push_back(make_pair(pos[proch][0]-1,pos[proch][1])); atraiter.push_back(make_pair(pos[proch][0],pos[proch][1]+1)); atraiter.push_back(make_pair(pos[proch][0],pos[proch][1]-1)); } } dist++; } } return somme; } //int DistanceSum(int N, int *X, int *Y); /* int main() { int tmp; */ /* Set input and output buffering *//* char *inbuf, *outbuf; inbuf = (char*) malloc(inbuf_len * sizeof(char)); outbuf = (char*) malloc(outbuf_len * sizeof(char)); tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len); assert(tmp == 0); tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len); assert(tmp == 0); int N, i; tmp = scanf("%d", &N); assert(tmp == 1); int *sq_x, *sq_y; sq_x = (int*) malloc(N * sizeof(int)); sq_y = (int*) malloc(N * sizeof(int)); for (i = 0; i < N; i++) { tmp = scanf("%d %d", &sq_x[i], &sq_y[i]); assert(tmp == 2); } int ds = DistanceSum(N, sq_x, sq_y); printf("%d\n", ds); return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...