Submission #592700

# Submission time Handle Problem Language Result Execution time Memory
592700 2022-07-09T13:33:46 Z Mamedov Tropical Garden (IOI11_garden) C++17
100 / 100
2615 ms 27692 KB
#pragma GCC optimize ("O3")
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void dfs(int node, vvi &g, vi &dist, int &cycle) {
  for (int to : g[node]) {
    if (dist[to] == oo) {
      dist[to] = dist[node] + 1;
      dfs(to, g, dist, cycle);
    } else {
      cycle = dist[node] + 1;
    }
  }
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  vvi minTrail(2, vi(N, -1));
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < 2; ++j) {
      int u = R[i][j];
      if (minTrail[0][u] == -1) {
        minTrail[0][u] = i;
      } else if (minTrail[1][u] == -1) {
        minTrail[1][u] = i;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    if (minTrail[1][i] == -1) {
      minTrail[1][i] = minTrail[0][i];
    }
  }

  vvi gt(2 * N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 2; ++j) {
      int trail = minTrail[j][i];
      int node = R[trail][0] + R[trail][1] - i;
      if (minTrail[0][node] == trail) {
        node += N;
      }
      gt[node].eb(i + j * N);
    }
  }
  vi cycle(2, 0);
  vvi dist(2, vi(2 * N, oo));
  dist[0][P] = 0;
  dfs(P, gt, dist[0], cycle[0]);
  dist[1][P + N] = 0;
  dfs(P + N, gt, dist[1], cycle[1]);
  for (int i = 0; i < Q; ++i) {
    int cnt = 0;
    for (int j = 0; j < N; ++j) {
      if (dist[0][j] == G[i] || (cycle[0] && G[i] > dist[0][j] && (G[i] - dist[0][j]) % cycle[0] == 0)) {
        ++cnt;
      } else if (dist[1][j] == G[i] || (cycle[1] && G[i] > dist[1][j] && (G[i] - dist[1][j]) % cycle[1] == 0)) {
        ++cnt;
      }
    }
    answer(cnt);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 448 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 11 ms 3380 KB Output is correct
12 Correct 19 ms 5624 KB Output is correct
13 Correct 56 ms 18148 KB Output is correct
14 Correct 79 ms 18176 KB Output is correct
15 Correct 93 ms 18500 KB Output is correct
16 Correct 70 ms 13444 KB Output is correct
17 Correct 78 ms 11780 KB Output is correct
18 Correct 25 ms 5608 KB Output is correct
19 Correct 78 ms 18104 KB Output is correct
20 Correct 96 ms 18444 KB Output is correct
21 Correct 81 ms 13448 KB Output is correct
22 Correct 73 ms 11752 KB Output is correct
23 Correct 79 ms 20012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 448 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 11 ms 3380 KB Output is correct
12 Correct 19 ms 5624 KB Output is correct
13 Correct 56 ms 18148 KB Output is correct
14 Correct 79 ms 18176 KB Output is correct
15 Correct 93 ms 18500 KB Output is correct
16 Correct 70 ms 13444 KB Output is correct
17 Correct 78 ms 11780 KB Output is correct
18 Correct 25 ms 5608 KB Output is correct
19 Correct 78 ms 18104 KB Output is correct
20 Correct 96 ms 18444 KB Output is correct
21 Correct 81 ms 13448 KB Output is correct
22 Correct 73 ms 11752 KB Output is correct
23 Correct 79 ms 20012 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 84 ms 3384 KB Output is correct
26 Correct 118 ms 5560 KB Output is correct
27 Correct 2254 ms 18296 KB Output is correct
28 Correct 846 ms 18156 KB Output is correct
29 Correct 2569 ms 18640 KB Output is correct
30 Correct 1419 ms 13468 KB Output is correct
31 Correct 1468 ms 11832 KB Output is correct
32 Correct 106 ms 5612 KB Output is correct
33 Correct 908 ms 18236 KB Output is correct
34 Correct 2615 ms 18488 KB Output is correct
35 Correct 1607 ms 13404 KB Output is correct
36 Correct 1558 ms 11844 KB Output is correct
37 Correct 643 ms 19932 KB Output is correct
38 Correct 1957 ms 27692 KB Output is correct