답안 #971126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971126 2024-04-28T03:02:54 Z nguyentunglam 게임 (APIO22_game) C++17
60 / 100
947 ms 7360 KB
#include "game.h"
#include<bits/stdc++.h>
using namespace std;

const int N = 30'000 + 10, K = 1000 + 10;

bitset<N> f[K];

vector<int> adj[N];

bool cycle;

int n, k;

void expand (int root, int u) {
  f[root][u] = 1;
  for(int &v : adj[u]) {
    if (v == root) cycle = 1;
    if (!f[root][v]) expand(root, v);
  }
}

void add (int u, int v) {
  adj[u].push_back(v);
  for(int start = 0; start < k; start++) {
    if (f[start][u] && v == start) cycle = 1;
    if (f[start][u] && !f[start][v]) expand(start, v);
  }
}

void init(int N, int K) {
  n = N;
  k = K;
  cycle = 0;
  for(int i = 0; i < k; i++) f[i][i] = 1;
  for(int i = 0; i + 1 < k; i++) add(i, i + 1);
}

int add_teleporter(int u, int v) {
  add(u, v);
  return cycle;
}

#ifdef ngu
namespace {

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

}  // namespace

int main() {
  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);
  int N = read_int();
  int M = read_int();
  int K = read_int();
  std::vector<int> u(M), v(M);
  for (int i = 0; i < M; ++i) {
    u[i] = read_int();
    v[i] = read_int();
  }

  init(N, K);
  int i;
  for (i = 0; i < M; ++i) {
    int answer = add_teleporter(u[i], v[i]);
    if (answer != 0 && answer != 1) {
      i = -1;
      break;
    } else if (answer == 1) {
      break;
    }
  }
  printf("%d\n", i);
  return 0;
}
#endif // ngu
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2648 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 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2648 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 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4696 KB Output is correct
25 Correct 4 ms 2904 KB Output is correct
26 Correct 3 ms 3448 KB Output is correct
27 Correct 6 ms 4696 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 5 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2648 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 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4696 KB Output is correct
25 Correct 4 ms 2904 KB Output is correct
26 Correct 3 ms 3448 KB Output is correct
27 Correct 6 ms 4696 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 5 ms 4952 KB Output is correct
30 Correct 16 ms 3416 KB Output is correct
31 Correct 19 ms 5980 KB Output is correct
32 Correct 32 ms 4472 KB Output is correct
33 Correct 13 ms 3932 KB Output is correct
34 Correct 505 ms 6856 KB Output is correct
35 Correct 262 ms 6592 KB Output is correct
36 Correct 53 ms 4496 KB Output is correct
37 Correct 324 ms 5812 KB Output is correct
38 Correct 251 ms 5808 KB Output is correct
39 Correct 264 ms 5748 KB Output is correct
40 Correct 491 ms 7304 KB Output is correct
41 Correct 236 ms 6296 KB Output is correct
42 Correct 208 ms 5852 KB Output is correct
43 Correct 947 ms 7360 KB Output is correct
44 Correct 435 ms 7080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2648 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 1 ms 2648 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 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4696 KB Output is correct
25 Correct 4 ms 2904 KB Output is correct
26 Correct 3 ms 3448 KB Output is correct
27 Correct 6 ms 4696 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 5 ms 4952 KB Output is correct
30 Correct 16 ms 3416 KB Output is correct
31 Correct 19 ms 5980 KB Output is correct
32 Correct 32 ms 4472 KB Output is correct
33 Correct 13 ms 3932 KB Output is correct
34 Correct 505 ms 6856 KB Output is correct
35 Correct 262 ms 6592 KB Output is correct
36 Correct 53 ms 4496 KB Output is correct
37 Correct 324 ms 5812 KB Output is correct
38 Correct 251 ms 5808 KB Output is correct
39 Correct 264 ms 5748 KB Output is correct
40 Correct 491 ms 7304 KB Output is correct
41 Correct 236 ms 6296 KB Output is correct
42 Correct 208 ms 5852 KB Output is correct
43 Correct 947 ms 7360 KB Output is correct
44 Correct 435 ms 7080 KB Output is correct
45 Runtime error 3 ms 4956 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -