답안 #304704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304704 2020-09-21T17:42:24 Z AlexPop28 열대 식물원 (Tropical Garden) (IOI11_garden) C++11
69 / 100
5000 ms 46840 KB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"

#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

const int N = 150000;

vector<int> to[N];
int nxt[2 * N];
int jump[30][2 * N];

void count_routes(int n, int m, int p, int r[][2], int q, int qrs[]) {
  for (int i = 0; i < m; ++i) {
    int a = r[i][0], b = r[i][1];
    if ((int)to[a].size() < 2) to[a].emplace_back(b);
    if ((int)to[b].size() < 2) to[b].emplace_back(a);
  }
  
  for (int i = 0; i < 2 * n; ++i) nxt[i] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 2 && j < (int)to[i].size(); ++j) {
      int x = to[i][j];
      int node = (to[x][0] == i) * n + x;
      nxt[j * n + i] = node;
    }
  }
  for (int i = n; i < 2 * n; ++i) if (nxt[i] == -1) nxt[i] = nxt[i - n];

  for (int i = 0; i < 2 * n; ++i) jump[0][i] = nxt[i];
  for (int i = 1; i < 30; ++i) {
    for (int j = 0; j < 2 * n; ++j) {
      jump[i][j] = jump[i - 1][jump[i - 1][j]];
    }
  }
  
  vector<int> pos(n);
  for (int it = 0; it < q; ++it) {
    int k = qrs[it];
    iota(pos.begin(), pos.end(), 0);
    
    for (int bit = 0; k; ++bit) {
      if (!(k & (1 << bit))) continue;
      k ^= 1 << bit;
      for (int i = 0; i < n; ++i) {
        pos[i] = jump[bit][pos[i]];
      }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      ans += pos[i] == p || pos[i] == n + p;
    }
    answer(ans);
  }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4276 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 4 ms 4352 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 5 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4276 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 4 ms 4352 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 5 ms 4352 KB Output is correct
10 Correct 3 ms 4096 KB Output is correct
11 Correct 15 ms 10496 KB Output is correct
12 Correct 30 ms 14844 KB Output is correct
13 Correct 50 ms 28280 KB Output is correct
14 Correct 97 ms 42616 KB Output is correct
15 Correct 99 ms 43132 KB Output is correct
16 Correct 76 ms 30456 KB Output is correct
17 Correct 68 ms 26360 KB Output is correct
18 Correct 30 ms 14840 KB Output is correct
19 Correct 97 ms 42636 KB Output is correct
20 Correct 100 ms 43128 KB Output is correct
21 Correct 84 ms 30716 KB Output is correct
22 Correct 73 ms 26360 KB Output is correct
23 Correct 105 ms 46744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4276 KB Output is correct
3 Correct 3 ms 4352 KB Output is correct
4 Correct 3 ms 4096 KB Output is correct
5 Correct 3 ms 4096 KB Output is correct
6 Correct 4 ms 4352 KB Output is correct
7 Correct 3 ms 4096 KB Output is correct
8 Correct 3 ms 4352 KB Output is correct
9 Correct 5 ms 4352 KB Output is correct
10 Correct 3 ms 4096 KB Output is correct
11 Correct 15 ms 10496 KB Output is correct
12 Correct 30 ms 14844 KB Output is correct
13 Correct 50 ms 28280 KB Output is correct
14 Correct 97 ms 42616 KB Output is correct
15 Correct 99 ms 43132 KB Output is correct
16 Correct 76 ms 30456 KB Output is correct
17 Correct 68 ms 26360 KB Output is correct
18 Correct 30 ms 14840 KB Output is correct
19 Correct 97 ms 42636 KB Output is correct
20 Correct 100 ms 43128 KB Output is correct
21 Correct 84 ms 30716 KB Output is correct
22 Correct 73 ms 26360 KB Output is correct
23 Correct 105 ms 46744 KB Output is correct
24 Correct 5 ms 4096 KB Output is correct
25 Correct 488 ms 10532 KB Output is correct
26 Correct 860 ms 14840 KB Output is correct
27 Correct 2426 ms 28408 KB Output is correct
28 Correct 4170 ms 42744 KB Output is correct
29 Correct 4233 ms 43256 KB Output is correct
30 Correct 2755 ms 30456 KB Output is correct
31 Correct 2286 ms 26360 KB Output is correct
32 Correct 908 ms 14924 KB Output is correct
33 Correct 4277 ms 42744 KB Output is correct
34 Correct 4476 ms 43144 KB Output is correct
35 Correct 3175 ms 30584 KB Output is correct
36 Correct 2632 ms 26492 KB Output is correct
37 Execution timed out 5092 ms 46840 KB Time limit exceeded