답안 #118208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118208 2019-06-18T11:01:38 Z nvmdava 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2979 ms 9188 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;

int n, p;
int to[300005];
int best[150005][2];
bool proc[300005][2];
int cyc[2];
int t[300005][2];

void dfs1(int v){
   if(proc[v][0]) return;
   proc[v][0] = 1;
   if(v == p) return;
   dfs1(to[v]);
   t[v][0] = t[to[v]][0] + 1;
}

void dfs0(int v){
   if(proc[v][1]) return;
   proc[v][1] = 1;
   if(v == p + n) return;
   dfs0(to[v]);
   t[v][1] = t[to[v]][1] + 1;
}

void count_routes(int n, int m, int p, int r[][2], int q, int g[]){
   memset(best, -1, sizeof best);
   memset(t, 0x3f, sizeof t);
   for(int i = 0; i < m; i++){
      int v = r[i][0], u = r[i][1];
      if(best[v][0] == -1) best[v][0] = u;
      else if(best[v][1] == -1) best[v][1] = u;
      if(best[u][0] == -1) best[u][0] = v;
      else if(best[u][1] == -1) best[u][1] = v;
   }
   ::n = n;
   ::p = p;
   for(int i = 0; i < n; i++)
      if(best[i][1] == -1) best[i][1] = best[i][0];

   for(int i = 0; i < n; i++){
      to[i] = best[i][0] + n * (best[best[i][0]][0] == i);
      to[i + n] = best[i][1] + n * (best[best[i][1]][0] == i);
   }

   t[p][0] = 0;
   t[p + n][1] = 0;

   for(int i = 0; i < n * 2; i++){
      dfs1(i);
      dfs0(i);
   }

   cyc[0] = 1 + t[to[p]][0];
   cyc[1] = 1 + t[to[n + p]][1];

   for(int j = 0; j < q; j++){
      int res = 0;
      for(int i = 0; i < n; i++){
         if((t[i][0] < 0x3f3f3f3f && (g[j] - t[i][0]) % cyc[0] == 0 && g[j] >= t[i][0]) || (t[i][1] < 0x3f3f3f3f && g[j] >= t[i][1] && (g[j] - t[i][1]) % cyc[1] == 0)) res++;
      }
      answer(res);
   }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3808 KB Output is correct
5 Correct 3 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3960 KB Output is correct
9 Correct 1 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3808 KB Output is correct
5 Correct 3 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3960 KB Output is correct
9 Correct 1 ms 3960 KB Output is correct
10 Correct 8 ms 3804 KB Output is correct
11 Correct 12 ms 4364 KB Output is correct
12 Correct 21 ms 4832 KB Output is correct
13 Correct 32 ms 8228 KB Output is correct
14 Correct 53 ms 6560 KB Output is correct
15 Correct 54 ms 6612 KB Output is correct
16 Correct 48 ms 6176 KB Output is correct
17 Correct 47 ms 5776 KB Output is correct
18 Correct 20 ms 4732 KB Output is correct
19 Correct 54 ms 6496 KB Output is correct
20 Correct 54 ms 6652 KB Output is correct
21 Correct 54 ms 6064 KB Output is correct
22 Correct 46 ms 5752 KB Output is correct
23 Correct 58 ms 6896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3808 KB Output is correct
5 Correct 3 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3960 KB Output is correct
9 Correct 1 ms 3960 KB Output is correct
10 Correct 8 ms 3804 KB Output is correct
11 Correct 12 ms 4364 KB Output is correct
12 Correct 21 ms 4832 KB Output is correct
13 Correct 32 ms 8228 KB Output is correct
14 Correct 53 ms 6560 KB Output is correct
15 Correct 54 ms 6612 KB Output is correct
16 Correct 48 ms 6176 KB Output is correct
17 Correct 47 ms 5776 KB Output is correct
18 Correct 20 ms 4732 KB Output is correct
19 Correct 54 ms 6496 KB Output is correct
20 Correct 54 ms 6652 KB Output is correct
21 Correct 54 ms 6064 KB Output is correct
22 Correct 46 ms 5752 KB Output is correct
23 Correct 58 ms 6896 KB Output is correct
24 Correct 6 ms 3804 KB Output is correct
25 Correct 118 ms 4432 KB Output is correct
26 Correct 160 ms 4928 KB Output is correct
27 Correct 1709 ms 8260 KB Output is correct
28 Correct 1392 ms 6612 KB Output is correct
29 Correct 1999 ms 6692 KB Output is correct
30 Correct 1094 ms 6108 KB Output is correct
31 Correct 1151 ms 5884 KB Output is correct
32 Correct 171 ms 4768 KB Output is correct
33 Correct 1424 ms 6616 KB Output is correct
34 Correct 1916 ms 6684 KB Output is correct
35 Correct 1060 ms 6060 KB Output is correct
36 Correct 1957 ms 6004 KB Output is correct
37 Correct 956 ms 6920 KB Output is correct
38 Correct 2979 ms 9188 KB Output is correct