답안 #116557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116557 2019-06-12T23:03:10 Z dragonslayerit 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
3046 ms 29732 KB
#include "garden.h"
#include "gardenlib.h"
#include <vector>
#include <queue>
#include <cstdio>

const int INF=1e9+7;

static std::vector<int> adj[150005];
static int to[300005];
static std::vector<int> from[300005];

static int dist[2][300005];

static void bfs(int start,int* dist){
  std::queue<int> q;
  q.push(start);
  while(!q.empty()){
    int node=q.front();
    q.pop();
    for(int child:from[node]){
      if(!dist[child]){
	dist[child]=dist[node]+1;
	q.push(child);
      }
    }
  }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
  for(int i=0;i<M;i++){
    adj[R[i][0]].push_back(R[i][1]);
    adj[R[i][1]].push_back(R[i][0]);
  }
  for(int i=0;i<N;i++){
    to[i<<1]=(adj[i][0]<<1)|(i==adj[adj[i][0]][0]);
    if(adj[i].size()>1){
      to[i<<1|1]=(adj[i][1]<<1)|(i==adj[adj[i][1]][0]);
    }else{
      to[i<<1|1]=to[i<<1];
    }
  }
  for(int i=0;i<N*2;i++){
    from[to[i]].push_back(i);
  }
  bfs(P<<1,dist[0]);
  bfs(P<<1|1,dist[1]);
  int cycle[2];
  cycle[0]=dist[0][P<<1]?dist[0][P<<1]:INF;
  cycle[1]=dist[1][P<<1|1]?dist[1][P<<1|1]:INF;
  for(int q=0; q<Q; q++){
    int K=G[q];
    int ans=0;
    for(int i=0;i<N*2;i+=2){
      if(dist[0][i]) ans+=(K>=dist[0][i]&&(K-dist[0][i])%cycle[0]==0);
      if(dist[1][i]) ans+=(K>=dist[1][i]&&(K-dist[1][i])%cycle[1]==0);
    }
    answer(ans);
  }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11004 KB Output is correct
2 Correct 15 ms 10972 KB Output is correct
3 Correct 13 ms 11000 KB Output is correct
4 Correct 11 ms 10936 KB Output is correct
5 Correct 12 ms 10960 KB Output is correct
6 Correct 13 ms 10972 KB Output is correct
7 Correct 10 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11004 KB Output is correct
2 Correct 15 ms 10972 KB Output is correct
3 Correct 13 ms 11000 KB Output is correct
4 Correct 11 ms 10936 KB Output is correct
5 Correct 12 ms 10960 KB Output is correct
6 Correct 13 ms 10972 KB Output is correct
7 Correct 10 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11220 KB Output is correct
10 Correct 11 ms 10844 KB Output is correct
11 Correct 24 ms 12972 KB Output is correct
12 Correct 45 ms 14524 KB Output is correct
13 Correct 59 ms 21536 KB Output is correct
14 Correct 134 ms 23328 KB Output is correct
15 Correct 171 ms 24408 KB Output is correct
16 Correct 126 ms 19884 KB Output is correct
17 Correct 116 ms 19468 KB Output is correct
18 Correct 55 ms 14520 KB Output is correct
19 Correct 140 ms 23892 KB Output is correct
20 Correct 168 ms 24484 KB Output is correct
21 Correct 138 ms 19964 KB Output is correct
22 Correct 133 ms 19428 KB Output is correct
23 Correct 148 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 11004 KB Output is correct
2 Correct 15 ms 10972 KB Output is correct
3 Correct 13 ms 11000 KB Output is correct
4 Correct 11 ms 10936 KB Output is correct
5 Correct 12 ms 10960 KB Output is correct
6 Correct 13 ms 10972 KB Output is correct
7 Correct 10 ms 10872 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 15 ms 11220 KB Output is correct
10 Correct 11 ms 10844 KB Output is correct
11 Correct 24 ms 12972 KB Output is correct
12 Correct 45 ms 14524 KB Output is correct
13 Correct 59 ms 21536 KB Output is correct
14 Correct 134 ms 23328 KB Output is correct
15 Correct 171 ms 24408 KB Output is correct
16 Correct 126 ms 19884 KB Output is correct
17 Correct 116 ms 19468 KB Output is correct
18 Correct 55 ms 14520 KB Output is correct
19 Correct 140 ms 23892 KB Output is correct
20 Correct 168 ms 24484 KB Output is correct
21 Correct 138 ms 19964 KB Output is correct
22 Correct 133 ms 19428 KB Output is correct
23 Correct 148 ms 24140 KB Output is correct
24 Correct 13 ms 10980 KB Output is correct
25 Correct 126 ms 13088 KB Output is correct
26 Correct 171 ms 14588 KB Output is correct
27 Correct 1638 ms 21624 KB Output is correct
28 Correct 1382 ms 24196 KB Output is correct
29 Correct 1989 ms 24500 KB Output is correct
30 Correct 1307 ms 20132 KB Output is correct
31 Correct 1096 ms 19696 KB Output is correct
32 Correct 201 ms 14584 KB Output is correct
33 Correct 1435 ms 23812 KB Output is correct
34 Correct 1924 ms 24504 KB Output is correct
35 Correct 1268 ms 20200 KB Output is correct
36 Correct 1900 ms 19552 KB Output is correct
37 Correct 1045 ms 24268 KB Output is correct
38 Correct 3046 ms 29732 KB Output is correct