답안 #657503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657503 2022-11-10T01:58:33 Z Lobo From Hacks to Snitches (BOI21_watchmen) C++17
25 / 100
6000 ms 93748 KB
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

const int inf = 1e9+10;
const int maxn = 3e5+10;

int n, m, k;
int szrt[maxn], idrt[maxn], thrt[maxn], isrt[maxn], nxrt[maxn], dlol[maxn];
vector<int> g[maxn], d[maxn];

int32_t main() {
    // freopen("in.in", "r", stdin);

    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int u,v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }

    cin >> k;
    for(int i = 1; i <= k; i++) {
        cin >> szrt[i];
        for(int j = 0; j < szrt[i]; j++) {
            int v; cin >> v;
            idrt[v] = i;
            isrt[v] = 1;
            thrt[v] = j;
        }
    }

    szrt[0] = 1;
    for(int i = 1; i <= n; i++) {
        dlol[i] = inf;
        if(isrt[i]) {
            for(int j = 0; j < szrt[idrt[i]]; j++) {
                d[i].pb(inf);
            }
            for(auto v : g[i]) {
                if(isrt[v]) nxrt[i] = v;
            }
        }
        else {
            d[i].pb(inf);
        }

    }

    d[1][0] = 0;
    priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> pq;
    pq.push(mp(0,mp(1,0)));
    while(pq.size()) {
        int u = pq.top().sc.fr;
        int t = pq.top().sc.sc;
        int dist = pq.top().fr;
        pq.pop();

        if(t != -1 && dist != d[u][t]) continue;
        if(t == -1 && dist != dlol[u]) continue;

        if(t == -1) {
            for(auto v : g[u]) {
                if(isrt[v]) continue;
                int d1 = dlol[u]+1;
                int t1 = 0;
                if(d[v][t1] > d1) {
                    d[v][t1] = d1;
                    pq.push(mp(d[v][t1],mp(v,t1)));
                }
            }
            continue;
        }

        if(isrt[u]) {
            for(auto v : g[u]) {
                if(isrt[v]) {
                    int d1 = d[u][t]+1;
                    int t1 = d1%szrt[idrt[v]];
                    // Vou encontrar o guarda em v ou indo para v
                    // indo para v == u é depois de v e em t1 ele vai estar em u
                    if(t1 == thrt[v] || (thrt[u] == (thrt[v]+1)%szrt[idrt[u]] && t1 == thrt[u])) continue;
                    if(d[v][t1] > d1) {
                        d[v][t1] = d1;
                        pq.push(mp(d[v][t1],mp(v,t1)));
                    }
                }
                
            }
            if(dlol[u] > d[u][t]) {
                dlol[u] = d[u][t];
                pq.push(mp(dlol[u],mp(u,-1)));
            }
        }
        else {
            for(auto v : g[u]) {
                if(isrt[v]) {
                    // d[u][t]+1+i = (thrt[v]+1) MOD
                    // i = trrt[v]-d[u][t] MOD
                    int i = ((thrt[v]-d[u][t])%szrt[idrt[v]]+szrt[idrt[v]])%szrt[idrt[v]];
                    int d1 = d[u][t]+1+i;
                    int t1 = d1%szrt[idrt[v]];
                    if(t1 == thrt[v]) continue;
                    if(d[v][t1] > d1) {
                        d[v][t1] = d1;
                        pq.push(mp(d[v][t1],mp(v,t1)));
                    }
                    d1 = d[u][t]+1;
                    t1 = d1%szrt[idrt[v]];
                    if(t1 == thrt[v]) continue;
                    if(d[v][t1] > d1) {
                        d[v][t1] = d1;
                        pq.push(mp(d[v][t1],mp(v,t1)));
                    }
                }
                else {
                    int d1 = d[u][t]+1;
                    int t1 = 0;
                    if(d[v][t1] > d1) {
                        d[v][t1] = d1;
                        pq.push(mp(d[v][t1],mp(v,t1)));
                    }
                }
            }
        }
    }

    if(d[n][0] == inf) cout << "impossible" << endl;
    else cout << d[n][0] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15508 KB Output is correct
2 Correct 134 ms 22484 KB Output is correct
3 Correct 157 ms 22248 KB Output is correct
4 Correct 181 ms 22196 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 137 ms 22160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 15648 KB Output is correct
2 Correct 132 ms 22784 KB Output is correct
3 Correct 132 ms 22284 KB Output is correct
4 Correct 168 ms 22288 KB Output is correct
5 Correct 10 ms 14468 KB Output is correct
6 Correct 138 ms 22156 KB Output is correct
7 Correct 159 ms 22088 KB Output is correct
8 Correct 141 ms 22148 KB Output is correct
9 Correct 130 ms 22052 KB Output is correct
10 Correct 145 ms 22380 KB Output is correct
11 Correct 149 ms 22124 KB Output is correct
12 Correct 172 ms 22152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 15648 KB Output is correct
2 Correct 132 ms 22784 KB Output is correct
3 Correct 132 ms 22284 KB Output is correct
4 Correct 168 ms 22288 KB Output is correct
5 Correct 10 ms 14468 KB Output is correct
6 Correct 138 ms 22156 KB Output is correct
7 Correct 159 ms 22088 KB Output is correct
8 Correct 141 ms 22148 KB Output is correct
9 Correct 130 ms 22052 KB Output is correct
10 Correct 145 ms 22380 KB Output is correct
11 Correct 149 ms 22124 KB Output is correct
12 Correct 172 ms 22152 KB Output is correct
13 Correct 95 ms 15688 KB Output is correct
14 Correct 152 ms 22676 KB Output is correct
15 Correct 160 ms 22228 KB Output is correct
16 Correct 166 ms 22292 KB Output is correct
17 Correct 9 ms 14396 KB Output is correct
18 Correct 163 ms 22156 KB Output is correct
19 Correct 141 ms 22268 KB Output is correct
20 Correct 126 ms 22136 KB Output is correct
21 Correct 118 ms 22068 KB Output is correct
22 Correct 162 ms 22348 KB Output is correct
23 Correct 134 ms 22200 KB Output is correct
24 Correct 120 ms 22092 KB Output is correct
25 Correct 2884 ms 66112 KB Output is correct
26 Correct 3097 ms 71016 KB Output is correct
27 Correct 2682 ms 66724 KB Output is correct
28 Correct 2264 ms 70580 KB Output is correct
29 Correct 3436 ms 61556 KB Output is correct
30 Correct 3526 ms 64068 KB Output is correct
31 Correct 2698 ms 70668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 15648 KB Output is correct
2 Correct 132 ms 22784 KB Output is correct
3 Correct 132 ms 22284 KB Output is correct
4 Correct 168 ms 22288 KB Output is correct
5 Correct 10 ms 14468 KB Output is correct
6 Correct 138 ms 22156 KB Output is correct
7 Correct 159 ms 22088 KB Output is correct
8 Correct 141 ms 22148 KB Output is correct
9 Correct 130 ms 22052 KB Output is correct
10 Correct 145 ms 22380 KB Output is correct
11 Correct 149 ms 22124 KB Output is correct
12 Correct 172 ms 22152 KB Output is correct
13 Correct 95 ms 15688 KB Output is correct
14 Correct 152 ms 22676 KB Output is correct
15 Correct 160 ms 22228 KB Output is correct
16 Correct 166 ms 22292 KB Output is correct
17 Correct 9 ms 14396 KB Output is correct
18 Correct 163 ms 22156 KB Output is correct
19 Correct 141 ms 22268 KB Output is correct
20 Correct 126 ms 22136 KB Output is correct
21 Correct 118 ms 22068 KB Output is correct
22 Correct 162 ms 22348 KB Output is correct
23 Correct 134 ms 22200 KB Output is correct
24 Correct 120 ms 22092 KB Output is correct
25 Correct 2884 ms 66112 KB Output is correct
26 Correct 3097 ms 71016 KB Output is correct
27 Correct 2682 ms 66724 KB Output is correct
28 Correct 2264 ms 70580 KB Output is correct
29 Correct 3436 ms 61556 KB Output is correct
30 Correct 3526 ms 64068 KB Output is correct
31 Correct 2698 ms 70668 KB Output is correct
32 Correct 71 ms 15824 KB Output is correct
33 Correct 150 ms 22812 KB Output is correct
34 Correct 117 ms 22220 KB Output is correct
35 Correct 140 ms 22220 KB Output is correct
36 Correct 9 ms 14400 KB Output is correct
37 Correct 134 ms 22156 KB Output is correct
38 Correct 109 ms 22120 KB Output is correct
39 Correct 114 ms 22036 KB Output is correct
40 Correct 121 ms 22008 KB Output is correct
41 Correct 115 ms 22468 KB Output is correct
42 Correct 110 ms 22208 KB Output is correct
43 Correct 111 ms 22096 KB Output is correct
44 Correct 2715 ms 65500 KB Output is correct
45 Correct 2580 ms 70524 KB Output is correct
46 Correct 2353 ms 66484 KB Output is correct
47 Correct 2064 ms 70104 KB Output is correct
48 Correct 3078 ms 61008 KB Output is correct
49 Correct 3343 ms 64172 KB Output is correct
50 Correct 2638 ms 70592 KB Output is correct
51 Correct 2986 ms 79236 KB Output is correct
52 Correct 3020 ms 93748 KB Output is correct
53 Correct 2762 ms 77404 KB Output is correct
54 Correct 2070 ms 62980 KB Output is correct
55 Execution timed out 6032 ms 79848 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15508 KB Output is correct
2 Correct 134 ms 22484 KB Output is correct
3 Correct 157 ms 22248 KB Output is correct
4 Correct 181 ms 22196 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 137 ms 22160 KB Output is correct
7 Correct 92 ms 15648 KB Output is correct
8 Correct 132 ms 22784 KB Output is correct
9 Correct 132 ms 22284 KB Output is correct
10 Correct 168 ms 22288 KB Output is correct
11 Correct 10 ms 14468 KB Output is correct
12 Correct 138 ms 22156 KB Output is correct
13 Correct 159 ms 22088 KB Output is correct
14 Correct 141 ms 22148 KB Output is correct
15 Correct 130 ms 22052 KB Output is correct
16 Correct 145 ms 22380 KB Output is correct
17 Correct 149 ms 22124 KB Output is correct
18 Correct 172 ms 22152 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 8 ms 14324 KB Output is correct
22 Correct 73 ms 15308 KB Output is correct
23 Correct 114 ms 22240 KB Output is correct
24 Correct 103 ms 21684 KB Output is correct
25 Correct 124 ms 21780 KB Output is correct
26 Correct 8 ms 14408 KB Output is correct
27 Correct 105 ms 21580 KB Output is correct
28 Correct 100 ms 21576 KB Output is correct
29 Correct 105 ms 21640 KB Output is correct
30 Correct 101 ms 21536 KB Output is correct
31 Correct 109 ms 21896 KB Output is correct
32 Correct 107 ms 21644 KB Output is correct
33 Correct 105 ms 21672 KB Output is correct
34 Correct 2534 ms 65784 KB Output is correct
35 Correct 2582 ms 62040 KB Output is correct
36 Correct 2658 ms 62192 KB Output is correct
37 Incorrect 2445 ms 67156 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15508 KB Output is correct
2 Correct 134 ms 22484 KB Output is correct
3 Correct 157 ms 22248 KB Output is correct
4 Correct 181 ms 22196 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 137 ms 22160 KB Output is correct
7 Correct 92 ms 15648 KB Output is correct
8 Correct 132 ms 22784 KB Output is correct
9 Correct 132 ms 22284 KB Output is correct
10 Correct 168 ms 22288 KB Output is correct
11 Correct 10 ms 14468 KB Output is correct
12 Correct 138 ms 22156 KB Output is correct
13 Correct 159 ms 22088 KB Output is correct
14 Correct 141 ms 22148 KB Output is correct
15 Correct 130 ms 22052 KB Output is correct
16 Correct 145 ms 22380 KB Output is correct
17 Correct 149 ms 22124 KB Output is correct
18 Correct 172 ms 22152 KB Output is correct
19 Correct 95 ms 15688 KB Output is correct
20 Correct 152 ms 22676 KB Output is correct
21 Correct 160 ms 22228 KB Output is correct
22 Correct 166 ms 22292 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 163 ms 22156 KB Output is correct
25 Correct 141 ms 22268 KB Output is correct
26 Correct 126 ms 22136 KB Output is correct
27 Correct 118 ms 22068 KB Output is correct
28 Correct 162 ms 22348 KB Output is correct
29 Correct 134 ms 22200 KB Output is correct
30 Correct 120 ms 22092 KB Output is correct
31 Correct 2884 ms 66112 KB Output is correct
32 Correct 3097 ms 71016 KB Output is correct
33 Correct 2682 ms 66724 KB Output is correct
34 Correct 2264 ms 70580 KB Output is correct
35 Correct 3436 ms 61556 KB Output is correct
36 Correct 3526 ms 64068 KB Output is correct
37 Correct 2698 ms 70668 KB Output is correct
38 Correct 8 ms 14420 KB Output is correct
39 Correct 8 ms 14420 KB Output is correct
40 Correct 8 ms 14324 KB Output is correct
41 Correct 73 ms 15308 KB Output is correct
42 Correct 114 ms 22240 KB Output is correct
43 Correct 103 ms 21684 KB Output is correct
44 Correct 124 ms 21780 KB Output is correct
45 Correct 8 ms 14408 KB Output is correct
46 Correct 105 ms 21580 KB Output is correct
47 Correct 100 ms 21576 KB Output is correct
48 Correct 105 ms 21640 KB Output is correct
49 Correct 101 ms 21536 KB Output is correct
50 Correct 109 ms 21896 KB Output is correct
51 Correct 107 ms 21644 KB Output is correct
52 Correct 105 ms 21672 KB Output is correct
53 Correct 2534 ms 65784 KB Output is correct
54 Correct 2582 ms 62040 KB Output is correct
55 Correct 2658 ms 62192 KB Output is correct
56 Incorrect 2445 ms 67156 KB Output isn't correct
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15508 KB Output is correct
2 Correct 134 ms 22484 KB Output is correct
3 Correct 157 ms 22248 KB Output is correct
4 Correct 181 ms 22196 KB Output is correct
5 Correct 10 ms 14412 KB Output is correct
6 Correct 137 ms 22160 KB Output is correct
7 Correct 92 ms 15648 KB Output is correct
8 Correct 132 ms 22784 KB Output is correct
9 Correct 132 ms 22284 KB Output is correct
10 Correct 168 ms 22288 KB Output is correct
11 Correct 10 ms 14468 KB Output is correct
12 Correct 138 ms 22156 KB Output is correct
13 Correct 159 ms 22088 KB Output is correct
14 Correct 141 ms 22148 KB Output is correct
15 Correct 130 ms 22052 KB Output is correct
16 Correct 145 ms 22380 KB Output is correct
17 Correct 149 ms 22124 KB Output is correct
18 Correct 172 ms 22152 KB Output is correct
19 Correct 95 ms 15688 KB Output is correct
20 Correct 152 ms 22676 KB Output is correct
21 Correct 160 ms 22228 KB Output is correct
22 Correct 166 ms 22292 KB Output is correct
23 Correct 9 ms 14396 KB Output is correct
24 Correct 163 ms 22156 KB Output is correct
25 Correct 141 ms 22268 KB Output is correct
26 Correct 126 ms 22136 KB Output is correct
27 Correct 118 ms 22068 KB Output is correct
28 Correct 162 ms 22348 KB Output is correct
29 Correct 134 ms 22200 KB Output is correct
30 Correct 120 ms 22092 KB Output is correct
31 Correct 2884 ms 66112 KB Output is correct
32 Correct 3097 ms 71016 KB Output is correct
33 Correct 2682 ms 66724 KB Output is correct
34 Correct 2264 ms 70580 KB Output is correct
35 Correct 3436 ms 61556 KB Output is correct
36 Correct 3526 ms 64068 KB Output is correct
37 Correct 2698 ms 70668 KB Output is correct
38 Correct 71 ms 15824 KB Output is correct
39 Correct 150 ms 22812 KB Output is correct
40 Correct 117 ms 22220 KB Output is correct
41 Correct 140 ms 22220 KB Output is correct
42 Correct 9 ms 14400 KB Output is correct
43 Correct 134 ms 22156 KB Output is correct
44 Correct 109 ms 22120 KB Output is correct
45 Correct 114 ms 22036 KB Output is correct
46 Correct 121 ms 22008 KB Output is correct
47 Correct 115 ms 22468 KB Output is correct
48 Correct 110 ms 22208 KB Output is correct
49 Correct 111 ms 22096 KB Output is correct
50 Correct 2715 ms 65500 KB Output is correct
51 Correct 2580 ms 70524 KB Output is correct
52 Correct 2353 ms 66484 KB Output is correct
53 Correct 2064 ms 70104 KB Output is correct
54 Correct 3078 ms 61008 KB Output is correct
55 Correct 3343 ms 64172 KB Output is correct
56 Correct 2638 ms 70592 KB Output is correct
57 Correct 2986 ms 79236 KB Output is correct
58 Correct 3020 ms 93748 KB Output is correct
59 Correct 2762 ms 77404 KB Output is correct
60 Correct 2070 ms 62980 KB Output is correct
61 Execution timed out 6032 ms 79848 KB Time limit exceeded
62 Halted 0 ms 0 KB -