답안 #381037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381037 2021-03-24T09:58:30 Z parsabahrami 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
100 / 100
2785 ms 33976 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second
 
const int N = 3e5 + 10;
int n, m, q, cnt[2], mn[N], M[2][N], C[2][N], out[N], dp[2][N]; vector<int> adj[N];

int cycDFS(int v, int t) {
    if (C[t][v]) return 0;
    if (M[t][v]) { 
        C[t][v] = 1;
        return 1;
    }
    M[t][v] = 1;
    int u = out[v];
    int f = cycDFS(u, t);
    if (C[t][v]) return 0;
    return C[t][v] = f;
}

void BFS(int st) {
    int *pd = dp[st >= n];
    fill(pd, pd + N, 2e9);
    pd[st] = 0; queue<int> Q; Q.push(st);
    while (SZ(Q)) {
        int v = Q.front(); Q.pop();
        for (int u : adj[v]) 
            if (pd[u] > pd[v] + 1) 
                pd[u] = pd[v] + 1, Q.push(u);
    }
}

inline int check(int p, int v, int x) {
    if (dp[p >= n][v] > x) return 0;
    int tmp = (!C[p >= n][p] ? 2e9 : cnt[p >= n]);
    int f = !((x - dp[p >= n][v]) % tmp);
    return f;
}

void count_routes(int _n, int _m, int P, int R[][2], int _q, int G[]) {
    n = _n, m = _m, q = _q;
    fill(mn, mn + N, 2e9);
    for (int i = 0; i < m; i++) {
        adj[R[i][0]].push_back(i), mn[R[i][0]] = min(mn[R[i][0]], i);
        adj[R[i][1]].push_back(i), mn[R[i][1]] = min(mn[R[i][1]], i);
    }
    for (int i = 0; i < n * 2; i++) {
        if (i >= n) {
            int v = R[mn[i - n]][0] ^ (i - n) ^ R[mn[i - n]][1];
            if (mn[i - n] == mn[v]) out[i] = v;
            else out[i] = v + n;
        } else {
            int sec = -1;
            for (int id : adj[i]) 
                if (id != mn[i]) { sec = id; break; }
            if (!~sec) sec = mn[i];
            int v = R[sec][0] ^ i ^ R[sec][1];
            if (sec == mn[v]) out[i] = v;
            else out[i] = v + n;
        }
    }
    memset(C, 0, sizeof C);
    cycDFS(P, 0); cycDFS(P + n, 1);
    for (int i = 0; i < 2 * n; i++)
        cnt[0] += C[0][i], cnt[1] += C[1][i];
    for (int i = 0; i < n; i++) 
        adj[i] = {};
    for (int i = 0; i < 2 * n; i++) 
        adj[out[i]].push_back(i);
    BFS(P), BFS(P + n);
    for (int _ = 0; _ < q; _++) {
        int x = G[_], f = 0;
        for (int i = n; i < 2 * n; i++) {
            f += (check(P, i, x) || check(P + n, i, x));
        }
        answer(f);
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13292 KB Output is correct
2 Correct 9 ms 13292 KB Output is correct
3 Correct 9 ms 13292 KB Output is correct
4 Correct 8 ms 13292 KB Output is correct
5 Correct 8 ms 13292 KB Output is correct
6 Correct 9 ms 13420 KB Output is correct
7 Correct 8 ms 13292 KB Output is correct
8 Correct 8 ms 13292 KB Output is correct
9 Correct 10 ms 13548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13292 KB Output is correct
2 Correct 9 ms 13292 KB Output is correct
3 Correct 9 ms 13292 KB Output is correct
4 Correct 8 ms 13292 KB Output is correct
5 Correct 8 ms 13292 KB Output is correct
6 Correct 9 ms 13420 KB Output is correct
7 Correct 8 ms 13292 KB Output is correct
8 Correct 8 ms 13292 KB Output is correct
9 Correct 10 ms 13548 KB Output is correct
10 Correct 8 ms 13292 KB Output is correct
11 Correct 22 ms 14828 KB Output is correct
12 Correct 34 ms 16004 KB Output is correct
13 Correct 63 ms 26652 KB Output is correct
14 Correct 103 ms 22252 KB Output is correct
15 Correct 145 ms 22636 KB Output is correct
16 Correct 107 ms 20204 KB Output is correct
17 Correct 98 ms 19564 KB Output is correct
18 Correct 46 ms 16108 KB Output is correct
19 Correct 142 ms 22252 KB Output is correct
20 Correct 141 ms 22528 KB Output is correct
21 Correct 105 ms 20332 KB Output is correct
22 Correct 98 ms 19436 KB Output is correct
23 Correct 114 ms 23148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13292 KB Output is correct
2 Correct 9 ms 13292 KB Output is correct
3 Correct 9 ms 13292 KB Output is correct
4 Correct 8 ms 13292 KB Output is correct
5 Correct 8 ms 13292 KB Output is correct
6 Correct 9 ms 13420 KB Output is correct
7 Correct 8 ms 13292 KB Output is correct
8 Correct 8 ms 13292 KB Output is correct
9 Correct 10 ms 13548 KB Output is correct
10 Correct 8 ms 13292 KB Output is correct
11 Correct 22 ms 14828 KB Output is correct
12 Correct 34 ms 16004 KB Output is correct
13 Correct 63 ms 26652 KB Output is correct
14 Correct 103 ms 22252 KB Output is correct
15 Correct 145 ms 22636 KB Output is correct
16 Correct 107 ms 20204 KB Output is correct
17 Correct 98 ms 19564 KB Output is correct
18 Correct 46 ms 16108 KB Output is correct
19 Correct 142 ms 22252 KB Output is correct
20 Correct 141 ms 22528 KB Output is correct
21 Correct 105 ms 20332 KB Output is correct
22 Correct 98 ms 19436 KB Output is correct
23 Correct 114 ms 23148 KB Output is correct
24 Correct 9 ms 13292 KB Output is correct
25 Correct 126 ms 14960 KB Output is correct
26 Correct 174 ms 16236 KB Output is correct
27 Correct 2532 ms 26604 KB Output is correct
28 Correct 1098 ms 22252 KB Output is correct
29 Correct 2785 ms 22616 KB Output is correct
30 Correct 1659 ms 20428 KB Output is correct
31 Correct 1707 ms 19816 KB Output is correct
32 Correct 164 ms 16748 KB Output is correct
33 Correct 1103 ms 24152 KB Output is correct
34 Correct 2753 ms 24428 KB Output is correct
35 Correct 1735 ms 21860 KB Output is correct
36 Correct 1944 ms 21228 KB Output is correct
37 Correct 884 ms 24940 KB Output is correct
38 Correct 2357 ms 33976 KB Output is correct