답안 #118211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118211 2019-06-18T11:09:37 Z nvmdava 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2937 ms 9192 KB
#include "garden.h"
#include "gardenlib.h"
#pragma GCC optimize("O3")
#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 3860 KB Output is correct
2 Correct 6 ms 3824 KB Output is correct
3 Correct 5 ms 3988 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 4 ms 3820 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 6 ms 3952 KB Output is correct
9 Correct 8 ms 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3860 KB Output is correct
2 Correct 6 ms 3824 KB Output is correct
3 Correct 5 ms 3988 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 4 ms 3820 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 6 ms 3952 KB Output is correct
9 Correct 8 ms 3932 KB Output is correct
10 Correct 5 ms 3824 KB Output is correct
11 Correct 12 ms 4572 KB Output is correct
12 Correct 20 ms 5304 KB Output is correct
13 Correct 30 ms 8796 KB Output is correct
14 Correct 42 ms 7500 KB Output is correct
15 Correct 50 ms 7524 KB Output is correct
16 Correct 46 ms 6700 KB Output is correct
17 Correct 44 ms 6436 KB Output is correct
18 Correct 17 ms 5112 KB Output is correct
19 Correct 50 ms 7412 KB Output is correct
20 Correct 52 ms 7580 KB Output is correct
21 Correct 45 ms 6600 KB Output is correct
22 Correct 46 ms 6520 KB Output is correct
23 Correct 51 ms 7580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3860 KB Output is correct
2 Correct 6 ms 3824 KB Output is correct
3 Correct 5 ms 3988 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 4 ms 3820 KB Output is correct
6 Correct 5 ms 3932 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 6 ms 3952 KB Output is correct
9 Correct 8 ms 3932 KB Output is correct
10 Correct 5 ms 3824 KB Output is correct
11 Correct 12 ms 4572 KB Output is correct
12 Correct 20 ms 5304 KB Output is correct
13 Correct 30 ms 8796 KB Output is correct
14 Correct 42 ms 7500 KB Output is correct
15 Correct 50 ms 7524 KB Output is correct
16 Correct 46 ms 6700 KB Output is correct
17 Correct 44 ms 6436 KB Output is correct
18 Correct 17 ms 5112 KB Output is correct
19 Correct 50 ms 7412 KB Output is correct
20 Correct 52 ms 7580 KB Output is correct
21 Correct 45 ms 6600 KB Output is correct
22 Correct 46 ms 6520 KB Output is correct
23 Correct 51 ms 7580 KB Output is correct
24 Correct 6 ms 3832 KB Output is correct
25 Correct 114 ms 4676 KB Output is correct
26 Correct 144 ms 5428 KB Output is correct
27 Correct 1534 ms 8888 KB Output is correct
28 Correct 1396 ms 7512 KB Output is correct
29 Correct 1921 ms 7664 KB Output is correct
30 Correct 1053 ms 6880 KB Output is correct
31 Correct 1145 ms 6920 KB Output is correct
32 Correct 169 ms 5348 KB Output is correct
33 Correct 1407 ms 7772 KB Output is correct
34 Correct 1828 ms 7912 KB Output is correct
35 Correct 1022 ms 6964 KB Output is correct
36 Correct 1898 ms 6520 KB Output is correct
37 Correct 940 ms 7876 KB Output is correct
38 Correct 2937 ms 9192 KB Output is correct