Submission #897083

# Submission time Handle Problem Language Result Execution time Memory
897083 2024-01-02T14:17:25 Z vjudge1 Game (APIO22_game) C++17
2 / 100
1 ms 2904 KB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

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

bool cycle;
int n, k, mn[N];
bitset<N> bt[K];
vector<int> adj[N];

void dfs(int x, int y) {
  if (bt[x][y]) return;
  bt[x][y] = 1;
  mn[x] = min({mn[x], mn[y], y});

  for (int& z : adj[y]) {
    if (bt[x][z]) continue;
    dfs(x, z);
  }
}

void init(int N, int K) {
  n = N;
  k = K;
  cycle = 0;

  for (int i = 0; i < n; i++) {
    adj[i].clear();
    mn[i] = (i < k-1 ? k-1 : inf);
  }

  for (int i = 0; i < k; i++) {
    bt[i].reset();
  }
}

int add_teleporter(int u, int v) {
  if (cycle) return 1;

  if (u < k && u == v) return cycle = 1;

  adj[u].push_back(v);

  if (min(u, v) >= k) {
    for (int i = 0; i < k; i++) {
      if (!bt[i][u]) continue;
      bt[i][v] = 1;
      adj[i].push_back(v);
      mn[i] = min({mn[i], mn[v], v});
    }
  }
  else if (u < k && v < k) {
    if (u < v) return 0;
    else return cycle = 1;
  }
  else if (u < k) {
    dfs(u, v);
  }
  else {
    // v < k
    mn[u] = min({mn[u], mn[v], v});
  }

  for (int i = 0; i < k; i++) {
    if (mn[i] <= i) {
      cycle = 1;
      break;
    }
  }
  
  return cycle;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Incorrect 1 ms 2648 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Incorrect 1 ms 2648 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Incorrect 1 ms 2648 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2460 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Incorrect 1 ms 2648 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -