답안 #925352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925352 2024-02-11T13:22:38 Z anton 이상적인 도시 (IOI12_city) C++17
11 / 100
1000 ms 2028 KB
#include<bits/stdc++.h>

using namespace std;
#define pii pair<int, int>

pii delta[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
pii add(pii lh, pii rh){
  return {lh.first+rh.first, lh.second+rh.second};
}
map<pii, int> blocks;

bool check_presence(pii pos){
  if(blocks.find(pos)!= blocks.end()){
    return true;
  }
  return false;
}

vector<pii> get_adj(pii pos){
  vector<pii> res;
  for(int i = 0; i<4; i++){
    pii pos2 = add(pos, delta[i]);
    if(check_presence(pos2)){
      res.push_back(pos2);
    }
  }
  return res;
}

void BFS(pii origin){
  for(pair<pii, int> e: blocks){
    blocks[e.first] = -1;
  }
  blocks[origin] = 0;
  queue<pair<pii, int>> q;

  q.push({origin, 0});

  while(q.size()>0){
    auto cur = q.front();
    auto u = cur.first;
    auto d= cur.second;
    q.pop();
    for(auto v: get_adj(u)){
      if(blocks[v] == -1){
        blocks[v]= d+1;
        q.push({v, d+1});
      }
    }
  }
}
const long long mod = 1000000000;

int DistanceSum(int N, int *X, int *Y) {


  for(int i = 0; i<N; i++){
    blocks[{X[i], Y[i]}] = -1;
  }


  long long res = 0;
  for(int i = 0; i<N; i++){
    BFS({X[i], Y[i]});

    for(auto e: blocks){
      res = res + (long long)(e.second);
    }
  }
  res/=2;
  return res%mod;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 15 ms 452 KB Output is correct
7 Correct 17 ms 348 KB Output is correct
8 Correct 15 ms 348 KB Output is correct
9 Correct 17 ms 348 KB Output is correct
10 Correct 18 ms 452 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 500 KB Output is correct
2 Correct 583 ms 592 KB Output is correct
3 Execution timed out 1029 ms 344 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1055 ms 2028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1031 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -