Submission #345402

# Submission time Handle Problem Language Result Execution time Memory
345402 2021-01-07T09:05:24 Z casperwang Tropical Garden (IOI11_garden) C++14
100 / 100
3077 ms 45076 KB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define pb emplace_back
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
 
const int MAXN = 150000;
const int MAXQ = 2000;
 
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  vector <vector<int>> tmp(N), path(2*N), repath(2*N);
  for (int i = 0; i < M; i++) {
    tmp[R[i][0]].pb(R[i][1]);
    tmp[R[i][1]].pb(R[i][0]);
  }
  for (int i = 0; i < N; i++) {
    int t = tmp[i][0];
    t = (tmp[t][0] == i ? t+N : t);
    path[i].pb(t);
    repath[t].pb(i);
    if (tmp[i].size() > 1) {
      t = tmp[i][1];
      t = (tmp[t][0] == i ? t+N : t);
      path[i+N].pb(t);
      repath[t].pb(i+N);
    } else {
      path[i+N].pb(t);
      repath[t].pb(i+N);
    }
  }
  vector <int> vis1(2*N), vis2(2*N);
  queue <int> nxt;
  nxt.push(P);
  while (nxt.size()) {
    int now = nxt.front();
    nxt.pop();
    for (int i : repath[now])
      if (!vis1[i])
        vis1[i] = vis1[now]+1, nxt.push(i);
  }
  nxt.push(P+N);
  while (nxt.size()) {
    int now = nxt.front();
    nxt.pop();
    for (int i : repath[now])
      if (!vis2[i])
        vis2[i] = vis2[now]+1, nxt.push(i);
  }
  for (int q = 0; q < Q; q++) {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if ((vis1[i] || i == P) && (vis1[i] == G[q] || (G[q] >= vis1[i] && vis1[P] && (G[q] - vis1[i]) % vis1[P] == 0))) {
        ans++;
      } else if (vis2[i] && (vis2[i] == G[q] || (G[q] >= vis2[i] && vis2[P+N] && (G[q] - vis2[i]) % vis2[P+N] == 0))) {
        ans++;
      }
    }
    answer(ans);
  }
  return;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 26 ms 6508 KB Output is correct
12 Correct 61 ms 10732 KB Output is correct
13 Correct 84 ms 25708 KB Output is correct
14 Correct 236 ms 36844 KB Output is correct
15 Correct 273 ms 37356 KB Output is correct
16 Correct 202 ms 25836 KB Output is correct
17 Correct 191 ms 22124 KB Output is correct
18 Correct 59 ms 10780 KB Output is correct
19 Correct 243 ms 36772 KB Output is correct
20 Correct 287 ms 37484 KB Output is correct
21 Correct 219 ms 25964 KB Output is correct
22 Correct 232 ms 22040 KB Output is correct
23 Correct 315 ms 40684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 26 ms 6508 KB Output is correct
12 Correct 61 ms 10732 KB Output is correct
13 Correct 84 ms 25708 KB Output is correct
14 Correct 236 ms 36844 KB Output is correct
15 Correct 273 ms 37356 KB Output is correct
16 Correct 202 ms 25836 KB Output is correct
17 Correct 191 ms 22124 KB Output is correct
18 Correct 59 ms 10780 KB Output is correct
19 Correct 243 ms 36772 KB Output is correct
20 Correct 287 ms 37484 KB Output is correct
21 Correct 219 ms 25964 KB Output is correct
22 Correct 232 ms 22040 KB Output is correct
23 Correct 315 ms 40684 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 111 ms 6636 KB Output is correct
26 Correct 185 ms 10732 KB Output is correct
27 Correct 2548 ms 25756 KB Output is correct
28 Correct 1240 ms 36972 KB Output is correct
29 Correct 3077 ms 37460 KB Output is correct
30 Correct 1736 ms 25888 KB Output is correct
31 Correct 1779 ms 22192 KB Output is correct
32 Correct 187 ms 10732 KB Output is correct
33 Correct 1193 ms 36904 KB Output is correct
34 Correct 3047 ms 37440 KB Output is correct
35 Correct 1839 ms 25876 KB Output is correct
36 Correct 1776 ms 22252 KB Output is correct
37 Correct 912 ms 40748 KB Output is correct
38 Correct 2277 ms 45076 KB Output is correct