답안 #737083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737083 2023-05-06T14:57:51 Z becaido 게임 (APIO22_game) C++17
100 / 100
1598 ms 144176 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "game.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 3e5 + 5;

int n, k;
int l[SIZE], r[SIZE];
vector<int> adj[SIZE], rev[SIZE];

void init(int N, int K) {
    n = N, k = K;
    FOR (i, 0, k - 1) l[i] = r[i] = i;
    FOR (i, k, n - 1) l[i] = -1, r[i] = k;
}

bool upd(int a, int b) {
    if (l[a] >= r[b]) return 1;
    int mid = (l[a] + r[a]) >> 1;
    if (r[b] <= mid) {
        r[a] = mid;
        for (int p : adj[a]) if (upd(a, p)) return 1;
        for (int p : rev[a]) if (upd(p, a)) return 1;
    }
    mid = (l[b] + r[b]) >> 1;
    if (l[a] > mid) {
        l[b] = mid + 1;
        for (int p : adj[b]) if (upd(b, p)) return 1;
        for (int p : rev[b]) if (upd(p, b)) return 1;
    }
    return 0;
}

int add_teleporter(int a, int b) {
    if (max(a, b) < k && a >= b) return 1;
    adj[a].pb(b);
    rev[b].pb(a);
    return upd(a, b);
}

#ifdef WAIMAI
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() {
  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
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 9 ms 14288 KB Output is correct
6 Correct 8 ms 14288 KB Output is correct
7 Correct 9 ms 14408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 9 ms 14288 KB Output is correct
6 Correct 8 ms 14288 KB Output is correct
7 Correct 9 ms 14408 KB Output is correct
8 Correct 9 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 9 ms 14288 KB Output is correct
14 Correct 9 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14288 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 10 ms 14408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 9 ms 14288 KB Output is correct
6 Correct 8 ms 14288 KB Output is correct
7 Correct 9 ms 14408 KB Output is correct
8 Correct 9 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 9 ms 14288 KB Output is correct
14 Correct 9 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14288 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 10 ms 14408 KB Output is correct
20 Correct 9 ms 14432 KB Output is correct
21 Correct 8 ms 14288 KB Output is correct
22 Correct 9 ms 14544 KB Output is correct
23 Correct 9 ms 14344 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14416 KB Output is correct
27 Correct 11 ms 14416 KB Output is correct
28 Correct 10 ms 14544 KB Output is correct
29 Correct 10 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 9 ms 14288 KB Output is correct
6 Correct 8 ms 14288 KB Output is correct
7 Correct 9 ms 14408 KB Output is correct
8 Correct 9 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 9 ms 14288 KB Output is correct
14 Correct 9 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14288 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 10 ms 14408 KB Output is correct
20 Correct 9 ms 14432 KB Output is correct
21 Correct 8 ms 14288 KB Output is correct
22 Correct 9 ms 14544 KB Output is correct
23 Correct 9 ms 14344 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14416 KB Output is correct
27 Correct 11 ms 14416 KB Output is correct
28 Correct 10 ms 14544 KB Output is correct
29 Correct 10 ms 14544 KB Output is correct
30 Correct 25 ms 15824 KB Output is correct
31 Correct 11 ms 15040 KB Output is correct
32 Correct 29 ms 24704 KB Output is correct
33 Correct 29 ms 16456 KB Output is correct
34 Correct 45 ms 32760 KB Output is correct
35 Correct 48 ms 18348 KB Output is correct
36 Correct 45 ms 16456 KB Output is correct
37 Correct 62 ms 16436 KB Output is correct
38 Correct 34 ms 16176 KB Output is correct
39 Correct 44 ms 16320 KB Output is correct
40 Correct 44 ms 19072 KB Output is correct
41 Correct 48 ms 18428 KB Output is correct
42 Correct 62 ms 19376 KB Output is correct
43 Correct 47 ms 17956 KB Output is correct
44 Correct 53 ms 17844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 9 ms 14288 KB Output is correct
6 Correct 8 ms 14288 KB Output is correct
7 Correct 9 ms 14408 KB Output is correct
8 Correct 9 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 8 ms 14288 KB Output is correct
13 Correct 9 ms 14288 KB Output is correct
14 Correct 9 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14288 KB Output is correct
18 Correct 10 ms 14408 KB Output is correct
19 Correct 10 ms 14408 KB Output is correct
20 Correct 9 ms 14432 KB Output is correct
21 Correct 8 ms 14288 KB Output is correct
22 Correct 9 ms 14544 KB Output is correct
23 Correct 9 ms 14344 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 12 ms 14544 KB Output is correct
26 Correct 11 ms 14416 KB Output is correct
27 Correct 11 ms 14416 KB Output is correct
28 Correct 10 ms 14544 KB Output is correct
29 Correct 10 ms 14544 KB Output is correct
30 Correct 25 ms 15824 KB Output is correct
31 Correct 11 ms 15040 KB Output is correct
32 Correct 29 ms 24704 KB Output is correct
33 Correct 29 ms 16456 KB Output is correct
34 Correct 45 ms 32760 KB Output is correct
35 Correct 48 ms 18348 KB Output is correct
36 Correct 45 ms 16456 KB Output is correct
37 Correct 62 ms 16436 KB Output is correct
38 Correct 34 ms 16176 KB Output is correct
39 Correct 44 ms 16320 KB Output is correct
40 Correct 44 ms 19072 KB Output is correct
41 Correct 48 ms 18428 KB Output is correct
42 Correct 62 ms 19376 KB Output is correct
43 Correct 47 ms 17956 KB Output is correct
44 Correct 53 ms 17844 KB Output is correct
45 Correct 251 ms 28080 KB Output is correct
46 Correct 18 ms 17128 KB Output is correct
47 Correct 14 ms 17104 KB Output is correct
48 Correct 361 ms 47560 KB Output is correct
49 Correct 250 ms 35620 KB Output is correct
50 Correct 652 ms 144176 KB Output is correct
51 Correct 981 ms 70124 KB Output is correct
52 Correct 643 ms 35632 KB Output is correct
53 Correct 869 ms 35828 KB Output is correct
54 Correct 857 ms 35528 KB Output is correct
55 Correct 1132 ms 37156 KB Output is correct
56 Correct 1374 ms 36068 KB Output is correct
57 Correct 510 ms 29668 KB Output is correct
58 Correct 491 ms 29552 KB Output is correct
59 Correct 577 ms 29596 KB Output is correct
60 Correct 631 ms 29632 KB Output is correct
61 Correct 851 ms 29236 KB Output is correct
62 Correct 511 ms 44232 KB Output is correct
63 Correct 439 ms 40808 KB Output is correct
64 Correct 1283 ms 76504 KB Output is correct
65 Correct 617 ms 49024 KB Output is correct
66 Correct 531 ms 34348 KB Output is correct
67 Correct 942 ms 70596 KB Output is correct
68 Correct 260 ms 26368 KB Output is correct
69 Correct 61 ms 20268 KB Output is correct
70 Correct 934 ms 44668 KB Output is correct
71 Correct 321 ms 29260 KB Output is correct
72 Correct 230 ms 25012 KB Output is correct
73 Correct 701 ms 44376 KB Output is correct
74 Correct 1598 ms 35680 KB Output is correct
75 Correct 1117 ms 49576 KB Output is correct
76 Correct 1218 ms 58060 KB Output is correct