Submission #958091

# Submission time Handle Problem Language Result Execution time Memory
958091 2024-04-04T22:07:16 Z d4xn Tropical Garden (IOI11_garden) C++17
49 / 100
45 ms 92188 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 15e4, B = 18;

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);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 45404 KB Output is correct
2 Correct 5 ms 45576 KB Output is correct
3 Correct 5 ms 45400 KB Output is correct
4 Correct 5 ms 45572 KB Output is correct
5 Correct 6 ms 45404 KB Output is correct
6 Correct 6 ms 45400 KB Output is correct
7 Correct 5 ms 45404 KB Output is correct
8 Correct 6 ms 45404 KB Output is correct
9 Correct 7 ms 45400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 45404 KB Output is correct
2 Correct 5 ms 45576 KB Output is correct
3 Correct 5 ms 45400 KB Output is correct
4 Correct 5 ms 45572 KB Output is correct
5 Correct 6 ms 45404 KB Output is correct
6 Correct 6 ms 45400 KB Output is correct
7 Correct 5 ms 45404 KB Output is correct
8 Correct 6 ms 45404 KB Output is correct
9 Correct 7 ms 45400 KB Output is correct
10 Correct 5 ms 45404 KB Output is correct
11 Runtime error 45 ms 92188 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 45404 KB Output is correct
2 Correct 5 ms 45576 KB Output is correct
3 Correct 5 ms 45400 KB Output is correct
4 Correct 5 ms 45572 KB Output is correct
5 Correct 6 ms 45404 KB Output is correct
6 Correct 6 ms 45400 KB Output is correct
7 Correct 5 ms 45404 KB Output is correct
8 Correct 6 ms 45404 KB Output is correct
9 Correct 7 ms 45400 KB Output is correct
10 Correct 5 ms 45404 KB Output is correct
11 Runtime error 45 ms 92188 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -