Submission #925354

# Submission time Handle Problem Language Result Execution time Memory
925354 2024-02-11T13:26:25 Z anton Ideal city (IOI12_city) C++17
11 / 100
1000 ms 1372 KB
#include<bits/stdc++.h>

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

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};
}
unordered_map<ll, int> blocks;

ll flat(pii pos){
  return pos.first + (ll)(pos.second) * (1LL<<32);
}
bool check_presence(pii pos){
  if(blocks.find(flat(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<ll, int> e: blocks){
    blocks[e.first] = -1;
  }
  blocks[flat(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[flat(v)] == -1){
        blocks[flat(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[flat({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;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 18 ms 444 KB Output is correct
7 Correct 24 ms 348 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 20 ms 348 KB Output is correct
10 Correct 22 ms 344 KB Output is correct
11 Correct 22 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 464 KB Output is correct
2 Correct 233 ms 476 KB Output is correct
3 Correct 455 ms 504 KB Output is correct
4 Correct 466 ms 348 KB Output is correct
5 Correct 895 ms 544 KB Output is correct
6 Correct 908 ms 540 KB Output is correct
7 Execution timed out 1006 ms 596 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -