답안 #499662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499662 2021-12-29T07:45:51 Z HappyPacMan 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
2440 ms 22244 KB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
const int MAXN = 150008;
const int INF = 9999999;
vector<pair<int,int> > adj[MAXN];
int graph[2*MAXN], dist[2][2*MAXN], cycle[2][2*MAXN];
 
int dfs(int x, int u){
  if(dist[x][u] != -1) return dist[x][u];
  dist[x][u] = -INF;
  return dist[x][u] = dfs(x,graph[u]) + 1;
}
 
int cyc(int x, int v, int u){
  if(cycle[x][u] != -1) return cycle[x][u];
  cycle[x][u] = u == v ? 0 : -INF;
  return cycle[x][u] = cyc(x,v,graph[u]) + 1;
}
 
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]].emplace_back(i,R[i][1]);
    adj[R[i][1]].emplace_back(i,R[i][0]);
  }
  for(int i=0;i<N;i++){
    if(!adj[i].empty()){
      if(adj[i].size() == 1){
        int nxt = adj[i][0].second;
        int rank = adj[i][0].first;
        graph[i<<1] = nxt<<1|(rank == adj[nxt][0].first);
        graph[i<<1|1] = nxt<<1|(rank == adj[nxt][0].first);
      }else{
        int nxt = adj[i][0].second;
        int rank = adj[i][0].first;
        int alter = adj[i][1].second;
        int alter_rank = adj[i][1].first;
        graph[i<<1] = nxt<<1|(rank == adj[nxt][0].first);
        graph[i<<1|1] = alter<<1|(alter_rank == adj[alter][0].first);
      }
    }
  }
  memset(dist,-1,sizeof dist);
  memset(cycle,-1,sizeof cycle);
  dist[0][P<<1] = dist[1][P<<1|1] = 0;
  cyc(0,P<<1,P<<1);
  cyc(1,P<<1|1,P<<1|1);
  for(int i=0;i<(N<<1);i++){
    dfs(0,i);
    dfs(1,i);
  }
  for(int i=0;i<Q;i++){
    int ans = 0;
    for(int j=0;j<N;j++){
      int temp = 0;
      int try1 = dist[0][j<<1];
      int try2 = dist[1][j<<1];
      if(try1 >= 0){
        if(try1 == G[i]) ans++;
        else if(try1 < G[i] && cycle[0][P<<1] > 0){
          int Gtemp = G[i];
          Gtemp -= try1;
          Gtemp %= cycle[0][P<<1];
          if(!Gtemp) temp++;
        }
      }
      if(try2 >= 0){
        if(try2 == G[i]) ans++;
        else if(try2 < G[i] && cycle[1][P<<1|1] > 0){
          int Gtemp = G[i];
          Gtemp -= try2;
          Gtemp %= cycle[1][P<<1|1];
          if(!Gtemp) temp++;
        }
      }
      ans += (temp > 0);
    }
    answer(ans);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8572 KB Output is correct
2 Correct 4 ms 8572 KB Output is correct
3 Correct 5 ms 8572 KB Output is correct
4 Correct 5 ms 8524 KB Output is correct
5 Correct 4 ms 8524 KB Output is correct
6 Correct 5 ms 8652 KB Output is correct
7 Correct 4 ms 8440 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 6 ms 8908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8572 KB Output is correct
2 Correct 4 ms 8572 KB Output is correct
3 Correct 5 ms 8572 KB Output is correct
4 Correct 5 ms 8524 KB Output is correct
5 Correct 4 ms 8524 KB Output is correct
6 Correct 5 ms 8652 KB Output is correct
7 Correct 4 ms 8440 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 6 ms 8908 KB Output is correct
10 Correct 5 ms 8432 KB Output is correct
11 Correct 10 ms 9932 KB Output is correct
12 Correct 20 ms 11716 KB Output is correct
13 Correct 33 ms 18820 KB Output is correct
14 Correct 57 ms 17552 KB Output is correct
15 Correct 64 ms 17848 KB Output is correct
16 Correct 54 ms 16640 KB Output is correct
17 Correct 52 ms 16200 KB Output is correct
18 Correct 23 ms 11564 KB Output is correct
19 Correct 56 ms 17716 KB Output is correct
20 Correct 60 ms 17900 KB Output is correct
21 Correct 54 ms 16376 KB Output is correct
22 Correct 52 ms 15940 KB Output is correct
23 Correct 64 ms 18408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8572 KB Output is correct
2 Correct 4 ms 8572 KB Output is correct
3 Correct 5 ms 8572 KB Output is correct
4 Correct 5 ms 8524 KB Output is correct
5 Correct 4 ms 8524 KB Output is correct
6 Correct 5 ms 8652 KB Output is correct
7 Correct 4 ms 8440 KB Output is correct
8 Correct 5 ms 8524 KB Output is correct
9 Correct 6 ms 8908 KB Output is correct
10 Correct 5 ms 8432 KB Output is correct
11 Correct 10 ms 9932 KB Output is correct
12 Correct 20 ms 11716 KB Output is correct
13 Correct 33 ms 18820 KB Output is correct
14 Correct 57 ms 17552 KB Output is correct
15 Correct 64 ms 17848 KB Output is correct
16 Correct 54 ms 16640 KB Output is correct
17 Correct 52 ms 16200 KB Output is correct
18 Correct 23 ms 11564 KB Output is correct
19 Correct 56 ms 17716 KB Output is correct
20 Correct 60 ms 17900 KB Output is correct
21 Correct 54 ms 16376 KB Output is correct
22 Correct 52 ms 15940 KB Output is correct
23 Correct 64 ms 18408 KB Output is correct
24 Correct 5 ms 8452 KB Output is correct
25 Correct 88 ms 10016 KB Output is correct
26 Correct 116 ms 11644 KB Output is correct
27 Correct 2182 ms 18848 KB Output is correct
28 Correct 795 ms 17656 KB Output is correct
29 Correct 2334 ms 18048 KB Output is correct
30 Correct 1405 ms 16688 KB Output is correct
31 Correct 1354 ms 16292 KB Output is correct
32 Correct 139 ms 11716 KB Output is correct
33 Correct 869 ms 17660 KB Output is correct
34 Correct 2440 ms 17972 KB Output is correct
35 Correct 1523 ms 16496 KB Output is correct
36 Correct 1338 ms 16168 KB Output is correct
37 Correct 641 ms 18448 KB Output is correct
38 Correct 1916 ms 22244 KB Output is correct