답안 #1042006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042006 2024-08-02T12:02:02 Z izanbf 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 95568 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>

using namespace std;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
  vector<vector<int>> adj(N);
  for (int i = 0; i < M; ++i) {
    adj[R[i][0]].push_back(R[i][1]);
    adj[R[i][1]].push_back(R[i][0]);
  }

  set<pair<int,int>> nodes;

  for (int i = 0; i < N; ++i) {
    nodes.insert({-1, i});
    for (int v : adj[i]) nodes.insert({i, v});
  }

  int siz = nodes.size();
  
  vector<bool> inP(siz, false);
  map<pair<int,int>,int> idx;
  int idx_ = 0;
  for (auto node : nodes) {
    idx[node] = idx_;
    if (node.second == P) inP[idx_] = true;
    ++idx_;
  }
  nodes.clear();

  const int J = 29;
  vector<vector<int>> succ(J+1, vector<int>(siz, -1));
  for (int i = 0; i < N; ++i) {
    succ[0][idx[{-1, i}]] = idx[{i, adj[i][0]}];
    for (int v : adj[i]) {
      if (v != adj[i][0] or adj[i].size() == 1)
        succ[0][idx[{v, i}]] = idx[{i, adj[i][0]}];
      else
        succ[0][idx[{v, i}]] = idx[{i, adj[i][1]}];
    }
  }

  for (int j = 1; j <= J; ++j) {
    for (int u = 0; u < siz; ++u) {
      succ[j][u] = succ[j-1][ succ[j-1][u] ];
    }
  }

  for(int it = 0; it < Q; ++it) {
    int K = G[it];
    int cnt = 0;

    for (int i = 0; i < N; ++i) {
      int u = idx[{-1, i}];
      
      for (int j = J; j >= 0; --j) {
        if (K & (1 << j)) u = succ[j][u];
      }

      if (inP[u]) ++cnt;
    }

    answer(cnt);
  }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 9 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 9 ms 3676 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 41 ms 16536 KB Output is correct
12 Correct 110 ms 31576 KB Output is correct
13 Correct 171 ms 55376 KB Output is correct
14 Correct 354 ms 89172 KB Output is correct
15 Correct 383 ms 91732 KB Output is correct
16 Correct 312 ms 76632 KB Output is correct
17 Correct 303 ms 73040 KB Output is correct
18 Correct 99 ms 31572 KB Output is correct
19 Correct 363 ms 89052 KB Output is correct
20 Correct 373 ms 91724 KB Output is correct
21 Correct 311 ms 76544 KB Output is correct
22 Correct 315 ms 73044 KB Output is correct
23 Correct 398 ms 95568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 9 ms 3676 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 41 ms 16536 KB Output is correct
12 Correct 110 ms 31576 KB Output is correct
13 Correct 171 ms 55376 KB Output is correct
14 Correct 354 ms 89172 KB Output is correct
15 Correct 383 ms 91732 KB Output is correct
16 Correct 312 ms 76632 KB Output is correct
17 Correct 303 ms 73040 KB Output is correct
18 Correct 99 ms 31572 KB Output is correct
19 Correct 363 ms 89052 KB Output is correct
20 Correct 373 ms 91724 KB Output is correct
21 Correct 311 ms 76544 KB Output is correct
22 Correct 315 ms 73044 KB Output is correct
23 Correct 398 ms 95568 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 4879 ms 16580 KB Output is correct
26 Execution timed out 5043 ms 31568 KB Time limit exceeded
27 Halted 0 ms 0 KB -