Submission #1104556

# Submission time Handle Problem Language Result Execution time Memory
1104556 2024-10-24T03:28:32 Z Nxmkxing Tropical Garden (IOI11_garden) C++14
49 / 100
259 ms 125380 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int inf = 1e9;

const int MxN = 1e5 + 10;
const int MxL = 32;
int n, m, p, q, ans[MxN], g[MxN];
pii up[MxN][MxL][2];
vector<pii> adj[MxN];

int cnt = -1;

pii dfs(int u, int l, int op) {
  if (l == 0) {
    return up[u][l][op] = pii(adj[u][op].second, u);
  }
  if (up[u][l][op] != pii(-1, -1)) return up[u][l][op];
  pii cur = pii(u, -1);
  cur = dfs(cur.first, l - 1, op);
  int new_op = 0;
  if (cur.second == adj[cur.first][0].second) new_op = 1;
  cur = dfs(cur.first, l - 1, new_op);
  return up[u][l][op] = cur;
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  n = N, m = M, p = P;
  for (int i = 0; i < M; i++) {
    int u = R[i][0];
    int v = R[i][1];
    adj[u].push_back({i, v});
    adj[v].push_back({i, u});
  }
  q = Q;
  for (int i = 0; i < Q; i++) {
    g[i] = G[i];
  }
  for (int i = 0; i < n; i++) {
    sort(adj[i].begin(), adj[i].end());
    if (adj[i].size() == 1) adj[i].push_back({-1, adj[i][0].second});
    adj[i].resize(2);
  }
  for (int j = 0; j < MxL; j++) {
    for (int i = 0; i < n; i++) {
      up[i][j][0] = up[i][j][1] = pii(-1, -1);
      dfs(i, j, 0); dfs(i, j, 1);
    }
  }
  for (int i = 0; i < q; i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      pii cur = pii(j, -1);
      int op = 0;
      for (int k = 0; k < MxL; k++) {
        if (g[i] & (1 << k)) {
          cur = up[cur.first][k][op];
          if (cur.second == adj[cur.first][0].second) op = 1;
          else op = 0;
        }
      }
      if (cur.first == p) ans++;
    }
    answer(ans);
  }
  
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6904 KB Output is correct
5 Correct 1 ms 6736 KB Output is correct
6 Correct 3 ms 6736 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 3 ms 7020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6904 KB Output is correct
5 Correct 1 ms 6736 KB Output is correct
6 Correct 3 ms 6736 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 3 ms 7020 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 31 ms 17744 KB Output is correct
12 Correct 67 ms 29520 KB Output is correct
13 Correct 259 ms 53328 KB Output is correct
14 Runtime error 110 ms 125380 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6904 KB Output is correct
5 Correct 1 ms 6736 KB Output is correct
6 Correct 3 ms 6736 KB Output is correct
7 Correct 1 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 3 ms 7020 KB Output is correct
10 Correct 1 ms 6736 KB Output is correct
11 Correct 31 ms 17744 KB Output is correct
12 Correct 67 ms 29520 KB Output is correct
13 Correct 259 ms 53328 KB Output is correct
14 Runtime error 110 ms 125380 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -