답안 #958092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958092 2024-04-04T22:07:53 Z d4xn 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
69 / 100
5000 ms 76208 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 15e4, B = 30;

int n, m, p, q, adj[2][N];
pair<int, int> dp[2][B][N];

int f(int x, int k) {
  pair<int, int> pr = make_pair(0, x);
  for (int i = 29; i >= 0; i--) {
    if ((k >> i) & 1) {
      pr = dp[pr.first][i][pr.second];
    }
  }
  return pr.second;
}

void count_routes(int n, int m, int p, int R[][2], int q, int G[])
{
  for (int i = 0; i < n; i++) {
    adj[0][i] = adj[1][i] = -1;
  }

  for (int i = 0; i < m; i++) {
    int x = R[i][0];
    int y = R[i][1];

    if (adj[0][x] == -1) {
      adj[0][x] = adj[1][x] = y;
    }
    else if (adj[1][x] == adj[0][x]) {
      adj[1][x] = y;
    }

    if (adj[0][y] == -1) {
      adj[0][y] = adj[1][y] = x;
    }
    else if (adj[1][y] == adj[0][y]) {
      adj[1][y] = x;
    }
  }

  for (int i = 0; i < n; i++) {
    int x = adj[0][i];
    if (x == -1) {
      dp[0][0][i] = make_pair(0, i);
    }
    else {
      dp[0][0][i] = make_pair((adj[0][x] == i ? 1 : 0), x);
    }

    x = adj[1][i];
    if (x == -1) {
      dp[1][0][i] = make_pair(0, i);
    }
    else {
      dp[1][0][i] = make_pair((adj[0][x] == i ? 1 : 0), x);
    }
  }

  for (int i = 1; i < B; i++) {
    for (int j = 0; j < n; j++) {
      pair<int, int> mid = dp[0][i-1][j];
      dp[0][i][j] = dp[mid.first][i-1][mid.second];

      mid = dp[1][i-1][j];
      dp[1][i][j] = dp[mid.first][i-1][mid.second];
    }
  }

  cin >> q;
  for (int i = 0; i < q; i++) {
    int x = G[i];

    int ans = 0;
    for (int j = 0; j < n; j++) {
      if (f(j, x) == p) ans++;
    }
    answer(ans);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 72028 KB Output is correct
2 Correct 8 ms 72028 KB Output is correct
3 Correct 8 ms 72164 KB Output is correct
4 Correct 8 ms 72028 KB Output is correct
5 Correct 8 ms 72028 KB Output is correct
6 Correct 8 ms 72028 KB Output is correct
7 Correct 8 ms 72024 KB Output is correct
8 Correct 8 ms 72028 KB Output is correct
9 Correct 10 ms 72028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 72028 KB Output is correct
2 Correct 8 ms 72028 KB Output is correct
3 Correct 8 ms 72164 KB Output is correct
4 Correct 8 ms 72028 KB Output is correct
5 Correct 8 ms 72028 KB Output is correct
6 Correct 8 ms 72028 KB Output is correct
7 Correct 8 ms 72024 KB Output is correct
8 Correct 8 ms 72028 KB Output is correct
9 Correct 10 ms 72028 KB Output is correct
10 Correct 8 ms 72028 KB Output is correct
11 Correct 13 ms 72436 KB Output is correct
12 Correct 19 ms 74332 KB Output is correct
13 Correct 27 ms 75420 KB Output is correct
14 Correct 42 ms 76116 KB Output is correct
15 Correct 49 ms 76144 KB Output is correct
16 Correct 40 ms 75972 KB Output is correct
17 Correct 37 ms 76120 KB Output is correct
18 Correct 19 ms 74840 KB Output is correct
19 Correct 43 ms 76116 KB Output is correct
20 Correct 43 ms 76208 KB Output is correct
21 Correct 43 ms 75932 KB Output is correct
22 Correct 36 ms 76084 KB Output is correct
23 Correct 48 ms 76208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 72028 KB Output is correct
2 Correct 8 ms 72028 KB Output is correct
3 Correct 8 ms 72164 KB Output is correct
4 Correct 8 ms 72028 KB Output is correct
5 Correct 8 ms 72028 KB Output is correct
6 Correct 8 ms 72028 KB Output is correct
7 Correct 8 ms 72024 KB Output is correct
8 Correct 8 ms 72028 KB Output is correct
9 Correct 10 ms 72028 KB Output is correct
10 Correct 8 ms 72028 KB Output is correct
11 Correct 13 ms 72436 KB Output is correct
12 Correct 19 ms 74332 KB Output is correct
13 Correct 27 ms 75420 KB Output is correct
14 Correct 42 ms 76116 KB Output is correct
15 Correct 49 ms 76144 KB Output is correct
16 Correct 40 ms 75972 KB Output is correct
17 Correct 37 ms 76120 KB Output is correct
18 Correct 19 ms 74840 KB Output is correct
19 Correct 43 ms 76116 KB Output is correct
20 Correct 43 ms 76208 KB Output is correct
21 Correct 43 ms 75932 KB Output is correct
22 Correct 36 ms 76084 KB Output is correct
23 Correct 48 ms 76208 KB Output is correct
24 Correct 14 ms 72284 KB Output is correct
25 Correct 2542 ms 72664 KB Output is correct
26 Correct 4264 ms 75060 KB Output is correct
27 Execution timed out 5098 ms 75400 KB Time limit exceeded
28 Halted 0 ms 0 KB -