답안 #36271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36271 2017-12-07T03:40:42 Z funcsr 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
100 / 100
203 ms 32212 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
#define INF 1145141919
#define rep(i, n) for (int i=0; i<(n); i++)
#define _1 first
#define _2 second
#define all(x) x.begin(), x.end()
#define pb push_back
typedef pair<int, int> P;
int N, M, T, Q;
vector<P> G[150000];
vector<int> G2[150000*2];
int F[150000*2];
int A[2000];
int D[150000*2];
int C[2][150000*2];

inline int fg(P p) {
  int x = p._2, e = p._1;
  if (G[x][0]._1 == e) return x+N;
  else return x;
}

int bfs(int s) {
  queue<int> q;
  rep(i, 2*N) D[i] = INF;
  D[s] = 0;
  q.push(s);
  int ret = INF;
  while (!q.empty()) {
    int x = q.front(); q.pop();
    for (int t : G2[x]) {
      if (t == s) ret = min(ret, D[x]+1);
      if (D[t] > D[x]+1) {
        D[t] = D[x]+1;
        q.push(t);
      }
    }
  }
  return ret;
}

void count_routes(int n, int m, int p, int edges[][2], int q, int g[]) {
  N = n, M = m, T = p, Q = q;
  rep(i, N) G[i].clear();
  rep(i, M) {
    G[edges[i][0]].pb(P(i, edges[i][1]));
    G[edges[i][1]].pb(P(i, edges[i][0]));
  }
  rep(i, 2*N) G2[i].clear();
  rep(i, N) {
    F[i] = fg(G[i][0]);
    F[i+N] = fg((G[i].size()>=2)? G[i][1] : G[i][0]);
  }
  rep(i, 2*N) G2[F[i]].pb(i);
  vector<int> S[2];
  int r[2];
  r[0] = bfs(T  ); rep(i, N) S[0].pb(D[i]); sort(all(S[0]), greater<int>());
  r[1] = bfs(T+N); rep(i, N) S[1].pb(D[i]); sort(all(S[1]), greater<int>());
  rep(i, 2) rep(t, 2*N) C[i][t] = 0;

  vector<P> qs;
  rep(i, Q) qs.pb(P(g[i], i));
  sort(all(qs));

  rep(_, Q) {
    int k = qs[_]._1, q = qs[_]._2;
    int ctr = 0;
    rep(i, 2) {
      while (!S[i].empty() && S[i].back() <= k) {
        int t = S[i].back();
        if (r[i] != INF) C[i][t%r[i]]++;
        else if (t == k) ctr++;
        S[i].pop_back();
      }
    }
    rep(i, 2) if (r[i] != INF) ctr += C[i][k%r[i]];
    A[q] = ctr;
  }
  rep(i, Q) answer(A[i]);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11064 KB Output is correct
2 Correct 13 ms 11128 KB Output is correct
3 Correct 15 ms 11100 KB Output is correct
4 Correct 12 ms 10920 KB Output is correct
5 Correct 4 ms 10988 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10924 KB Output is correct
8 Correct 15 ms 10976 KB Output is correct
9 Correct 15 ms 11204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11064 KB Output is correct
2 Correct 13 ms 11128 KB Output is correct
3 Correct 15 ms 11100 KB Output is correct
4 Correct 12 ms 10920 KB Output is correct
5 Correct 4 ms 10988 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10924 KB Output is correct
8 Correct 15 ms 10976 KB Output is correct
9 Correct 15 ms 11204 KB Output is correct
10 Correct 13 ms 10920 KB Output is correct
11 Correct 27 ms 13892 KB Output is correct
12 Correct 50 ms 15908 KB Output is correct
13 Correct 73 ms 23020 KB Output is correct
14 Correct 153 ms 27184 KB Output is correct
15 Correct 202 ms 27528 KB Output is correct
16 Correct 158 ms 23356 KB Output is correct
17 Correct 146 ms 22012 KB Output is correct
18 Correct 52 ms 15988 KB Output is correct
19 Correct 163 ms 27112 KB Output is correct
20 Correct 200 ms 27424 KB Output is correct
21 Correct 150 ms 23424 KB Output is correct
22 Correct 140 ms 23012 KB Output is correct
23 Correct 158 ms 29896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11064 KB Output is correct
2 Correct 13 ms 11128 KB Output is correct
3 Correct 15 ms 11100 KB Output is correct
4 Correct 12 ms 10920 KB Output is correct
5 Correct 4 ms 10988 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10924 KB Output is correct
8 Correct 15 ms 10976 KB Output is correct
9 Correct 15 ms 11204 KB Output is correct
10 Correct 13 ms 10920 KB Output is correct
11 Correct 27 ms 13892 KB Output is correct
12 Correct 50 ms 15908 KB Output is correct
13 Correct 73 ms 23020 KB Output is correct
14 Correct 153 ms 27184 KB Output is correct
15 Correct 202 ms 27528 KB Output is correct
16 Correct 158 ms 23356 KB Output is correct
17 Correct 146 ms 22012 KB Output is correct
18 Correct 52 ms 15988 KB Output is correct
19 Correct 163 ms 27112 KB Output is correct
20 Correct 200 ms 27424 KB Output is correct
21 Correct 150 ms 23424 KB Output is correct
22 Correct 140 ms 23012 KB Output is correct
23 Correct 158 ms 29896 KB Output is correct
24 Correct 13 ms 11008 KB Output is correct
25 Correct 29 ms 13896 KB Output is correct
26 Correct 49 ms 15936 KB Output is correct
27 Correct 75 ms 24088 KB Output is correct
28 Correct 159 ms 28312 KB Output is correct
29 Correct 189 ms 28628 KB Output is correct
30 Correct 153 ms 24192 KB Output is correct
31 Correct 147 ms 23152 KB Output is correct
32 Correct 51 ms 16560 KB Output is correct
33 Correct 169 ms 28176 KB Output is correct
34 Correct 203 ms 27528 KB Output is correct
35 Correct 161 ms 23260 KB Output is correct
36 Correct 150 ms 22204 KB Output is correct
37 Correct 155 ms 29168 KB Output is correct
38 Correct 155 ms 32212 KB Output is correct