답안 #429698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429698 2021-06-16T08:48:03 Z oscar1f 이상적인 도시 (IOI12_city) C++17
32 / 100
1000 ms 2272 KB
#include<bits/stdc++.h>
#include <unordered_map>
/*#include <stdio.h>
#include <stdlib.h>
#include <assert.h>*/
using namespace std;
/*#define inbuf_len 1 << 16
#define outbuf_len 1 << 16*/

const long long MULTI=(long long)1024*(long long)1024*(long long)1024*(long long)2;
const int MOD=1000*1000*1000,MAX_BLOCS=100*1000+1;
int somme,dist,longueur,proch;
int dv[MAX_BLOCS],pos[MAX_BLOCS][2];
unordered_map<long long,int> grille;
deque<pair<int,int>> atraiter;

long long calcul(int pos1,int pos2) {
  return MULTI*(long long)pos1+(long long) pos2;
}

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[calcul(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[calcul(atraiter.front().first,atraiter.front().second)];
        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;

}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 3 ms 204 KB Output is correct
6 Correct 7 ms 204 KB Output is correct
7 Correct 6 ms 204 KB Output is correct
8 Correct 7 ms 320 KB Output is correct
9 Correct 6 ms 324 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Correct 7 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 392 KB Output is correct
2 Correct 166 ms 384 KB Output is correct
3 Correct 397 ms 460 KB Output is correct
4 Correct 383 ms 420 KB Output is correct
5 Correct 639 ms 492 KB Output is correct
6 Correct 570 ms 468 KB Output is correct
7 Correct 660 ms 500 KB Output is correct
8 Correct 678 ms 476 KB Output is correct
9 Correct 541 ms 476 KB Output is correct
10 Correct 572 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 1868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 2272 KB Time limit exceeded
2 Halted 0 ms 0 KB -