Submission #958986

# Submission time Handle Problem Language Result Execution time Memory
958986 2024-04-07T10:52:12 Z vjudge1 Ideal city (IOI12_city) C++17
32 / 100
1000 ms 6744 KB
//#include "city.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()

const int N = 1e4+4, inf = INT_MAX;

const vector<pair<int, int>> dir = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

ll ans;
bitset<N> cell[N], vis[N];

bool ok(int x, int y) {
  return min(x, y) >= 0;
}

void bfs(int X, int Y) {
  queue<tuple<int, int, int>> q;
  q.push(make_tuple(0, X, Y));
  while (!q.empty()) {
    int d = get<0>(q.front());
    int x = get<1>(q.front());
    int y = get<2>(q.front());
    q.pop();

    if (vis[x][y]) continue;
    vis[x][y] = 1;

    ans += d;

    for (auto [a, b] : dir) {
      if (ok(x+a, y+b) && 
      cell[x+a][y+b] &&
      !vis[x+a][y+b]) {
        q.push(make_tuple(d+1, x+a, y+b));
      }
    }
  }
}

int DistanceSum(int N, int *X, int *Y) {
  ans = 0;

  int mnX = inf;
  int mnY = inf;
  for (int i = 0; i < N; i++) {
    mnX = min(mnX, X[i]);
    mnY = min(mnY, Y[i]);
  }

  for (int i = 0; i < N; i++) {
    X[i] -= mnX;
    Y[i] -= mnY;

    cell[X[i]][Y[i]] = 1;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      vis[X[j]][Y[j]] = 0;
    }
    bfs(X[i], Y[i]);
  }

  return ans/2;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2492 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2572 KB Output is correct
2 Correct 27 ms 2392 KB Output is correct
3 Correct 73 ms 2580 KB Output is correct
4 Correct 64 ms 2592 KB Output is correct
5 Correct 130 ms 2648 KB Output is correct
6 Correct 105 ms 2396 KB Output is correct
7 Correct 146 ms 2652 KB Output is correct
8 Correct 110 ms 2648 KB Output is correct
9 Correct 102 ms 2396 KB Output is correct
10 Correct 100 ms 2588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1012 ms 6744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 6744 KB Time limit exceeded
2 Halted 0 ms 0 KB -