Submission #749179

# Submission time Handle Problem Language Result Execution time Memory
749179 2023-05-27T12:58:15 Z 이동현(#9963) From Hacks to Snitches (BOI21_watchmen) C++17
25 / 100
6000 ms 159444 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

const int NS = 250004;
int n, m, k;
vector<int> way[NS];
int dist[NS][2], period[NS], col[NS], st[NS], num[NS];
vector<int> vc;
int vcdist[2754][2754][2];

struct Node{
    int x, y, z;
    Node(){}
    Node(int x, int y, int z):x(x), y(y), z(z){}
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        way[x].push_back(y);
        way[y].push_back(x);
    }

    cin >> k;
    for(int i = 0; i < k; ++i){
        int l;
        cin >> l;
        for(int j = 0; j < l; ++j){
            int x;
            cin >> x;
            --x;
            num[x] = (int)vc.size();
            vc.push_back(x);
            col[x] = i + 1;
            st[x] = j;
            period[x] = l;
        }
    }

    queue<Node> que;
    for(int i = 0; i < n; ++i){
        dist[i][0] = dist[i][1] = (int)1e9;
    }
    for(int i = 0; i < 2754; ++i){
        for(int j = 0; j < 2754; ++j){
            vcdist[i][j][0] = vcdist[i][j][1] = (int)1e9;
        }
    }
    dist[0][1] = 0;
    que.push(Node(0, -1, 1));

    while(!que.empty()){
        int now = que.front().x, t = que.front().y, z = que.front().z;
        if(now == n - 1){
            cout << dist[now][z] << '\n';
            return 0;
        }
        if(col[now]){
            //cout << now + 1 << ' ' << t << ' ' << z << ' ' << (int)vcdist[num[now]][t][z] << endl;
        }
        que.pop();

        if(t == -1){
            if(z == 1){
                if(dist[now][1] + 1 < dist[now][0]){
                    dist[now][0] = dist[now][1] + 1;
                    que.push(Node(now, -1, 0));
                }
            }
            for(auto&nxt:way[now]){
                //cout << now << ' ' << nxt << ' ' << col[nxt] << endl;
                if(!col[nxt]){
                    if(dist[now][z] + 1 < dist[nxt][1]){
                        dist[nxt][1] = dist[now][z] + 1;
                        que.push(Node(nxt, -1, 1));
                    }
                }
                else{
                    int md = (st[nxt] - dist[now][z] % period[nxt] - 1 + period[nxt] * 2) % period[nxt];
                    if(md != 0){
                        if(dist[now][z] + 1 < vcdist[num[nxt]][md][1]){
                            vcdist[num[nxt]][md][1] = dist[now][z] + 1;
                            que.push(Node(nxt, md, 1));
                        }
                    }
                }
            }
        }
        else{
            int nd = vcdist[num[now]][t][z];
            if(z == 1 && nd + 1 < vcdist[num[now]][(t - 1 + period[now]) % period[now]][1]){
                vcdist[num[now]][(t - 1 + period[now]) % period[now]][1] = nd + 1;
                que.push(Node(now, (t - 1 + period[now]) % period[now], 1));
            }
            for(auto&nxt:way[now]){
                if(!col[nxt]){
                    if(nd + 1 < dist[nxt][1]){
                        dist[nxt][1] = nd + 1;
                        que.push(Node(nxt, -1, 1));
                    }
                }
                else{
                    int md = (st[nxt] - nd % period[nxt] - 1 + period[nxt] * 2) % period[nxt];
                    if(md != 0){
                        if(md != (period[nxt] - 1) || t != 1){
                            if(t != 0){
                                if(nd + 1 < vcdist[num[nxt]][md][0]){
                                    vcdist[num[nxt]][md][0] = nd + 1;
                                    que.push(Node(nxt, md, 0));
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << "impossible\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 36 ms 66452 KB Output is correct
2 Correct 76 ms 70528 KB Output is correct
3 Correct 83 ms 70284 KB Output is correct
4 Correct 104 ms 70424 KB Output is correct
5 Correct 25 ms 65584 KB Output is correct
6 Correct 73 ms 70268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 66520 KB Output is correct
2 Correct 73 ms 70560 KB Output is correct
3 Correct 78 ms 70312 KB Output is correct
4 Correct 112 ms 70368 KB Output is correct
5 Correct 26 ms 65476 KB Output is correct
6 Correct 72 ms 70220 KB Output is correct
7 Correct 67 ms 70176 KB Output is correct
8 Correct 63 ms 70276 KB Output is correct
9 Correct 76 ms 70224 KB Output is correct
10 Correct 90 ms 70368 KB Output is correct
11 Correct 67 ms 70248 KB Output is correct
12 Correct 85 ms 70220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 66520 KB Output is correct
2 Correct 73 ms 70560 KB Output is correct
3 Correct 78 ms 70312 KB Output is correct
4 Correct 112 ms 70368 KB Output is correct
5 Correct 26 ms 65476 KB Output is correct
6 Correct 72 ms 70220 KB Output is correct
7 Correct 67 ms 70176 KB Output is correct
8 Correct 63 ms 70276 KB Output is correct
9 Correct 76 ms 70224 KB Output is correct
10 Correct 90 ms 70368 KB Output is correct
11 Correct 67 ms 70248 KB Output is correct
12 Correct 85 ms 70220 KB Output is correct
13 Correct 37 ms 66508 KB Output is correct
14 Correct 75 ms 70540 KB Output is correct
15 Correct 70 ms 70220 KB Output is correct
16 Correct 119 ms 70480 KB Output is correct
17 Correct 29 ms 65600 KB Output is correct
18 Correct 69 ms 70248 KB Output is correct
19 Correct 65 ms 70168 KB Output is correct
20 Correct 74 ms 70220 KB Output is correct
21 Correct 68 ms 70324 KB Output is correct
22 Correct 88 ms 70464 KB Output is correct
23 Correct 74 ms 70312 KB Output is correct
24 Correct 86 ms 70252 KB Output is correct
25 Correct 1379 ms 113400 KB Output is correct
26 Correct 1342 ms 119412 KB Output is correct
27 Correct 1163 ms 113376 KB Output is correct
28 Correct 892 ms 118236 KB Output is correct
29 Correct 3741 ms 107056 KB Output is correct
30 Correct 4388 ms 110400 KB Output is correct
31 Correct 1455 ms 158644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 66520 KB Output is correct
2 Correct 73 ms 70560 KB Output is correct
3 Correct 78 ms 70312 KB Output is correct
4 Correct 112 ms 70368 KB Output is correct
5 Correct 26 ms 65476 KB Output is correct
6 Correct 72 ms 70220 KB Output is correct
7 Correct 67 ms 70176 KB Output is correct
8 Correct 63 ms 70276 KB Output is correct
9 Correct 76 ms 70224 KB Output is correct
10 Correct 90 ms 70368 KB Output is correct
11 Correct 67 ms 70248 KB Output is correct
12 Correct 85 ms 70220 KB Output is correct
13 Correct 37 ms 66508 KB Output is correct
14 Correct 75 ms 70540 KB Output is correct
15 Correct 70 ms 70220 KB Output is correct
16 Correct 119 ms 70480 KB Output is correct
17 Correct 29 ms 65600 KB Output is correct
18 Correct 69 ms 70248 KB Output is correct
19 Correct 65 ms 70168 KB Output is correct
20 Correct 74 ms 70220 KB Output is correct
21 Correct 68 ms 70324 KB Output is correct
22 Correct 88 ms 70464 KB Output is correct
23 Correct 74 ms 70312 KB Output is correct
24 Correct 86 ms 70252 KB Output is correct
25 Correct 1379 ms 113400 KB Output is correct
26 Correct 1342 ms 119412 KB Output is correct
27 Correct 1163 ms 113376 KB Output is correct
28 Correct 892 ms 118236 KB Output is correct
29 Correct 3741 ms 107056 KB Output is correct
30 Correct 4388 ms 110400 KB Output is correct
31 Correct 1455 ms 158644 KB Output is correct
32 Correct 36 ms 67084 KB Output is correct
33 Correct 77 ms 71716 KB Output is correct
34 Correct 68 ms 71392 KB Output is correct
35 Correct 112 ms 71484 KB Output is correct
36 Correct 29 ms 65484 KB Output is correct
37 Correct 79 ms 71356 KB Output is correct
38 Correct 81 ms 71328 KB Output is correct
39 Correct 73 ms 71368 KB Output is correct
40 Correct 70 ms 71436 KB Output is correct
41 Correct 86 ms 71588 KB Output is correct
42 Correct 69 ms 71500 KB Output is correct
43 Correct 99 ms 71424 KB Output is correct
44 Correct 1460 ms 151932 KB Output is correct
45 Correct 1313 ms 157972 KB Output is correct
46 Correct 1238 ms 151848 KB Output is correct
47 Correct 1016 ms 156672 KB Output is correct
48 Correct 4152 ms 145788 KB Output is correct
49 Correct 4368 ms 148884 KB Output is correct
50 Correct 1448 ms 158652 KB Output is correct
51 Correct 1634 ms 153556 KB Output is correct
52 Correct 1711 ms 159444 KB Output is correct
53 Correct 1808 ms 151956 KB Output is correct
54 Correct 914 ms 145972 KB Output is correct
55 Execution timed out 6025 ms 152400 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 66452 KB Output is correct
2 Correct 76 ms 70528 KB Output is correct
3 Correct 83 ms 70284 KB Output is correct
4 Correct 104 ms 70424 KB Output is correct
5 Correct 25 ms 65584 KB Output is correct
6 Correct 73 ms 70268 KB Output is correct
7 Correct 42 ms 66520 KB Output is correct
8 Correct 73 ms 70560 KB Output is correct
9 Correct 78 ms 70312 KB Output is correct
10 Correct 112 ms 70368 KB Output is correct
11 Correct 26 ms 65476 KB Output is correct
12 Correct 72 ms 70220 KB Output is correct
13 Correct 67 ms 70176 KB Output is correct
14 Correct 63 ms 70276 KB Output is correct
15 Correct 76 ms 70224 KB Output is correct
16 Correct 90 ms 70368 KB Output is correct
17 Correct 67 ms 70248 KB Output is correct
18 Correct 85 ms 70220 KB Output is correct
19 Correct 27 ms 65492 KB Output is correct
20 Correct 29 ms 65488 KB Output is correct
21 Correct 34 ms 65508 KB Output is correct
22 Correct 58 ms 66712 KB Output is correct
23 Correct 85 ms 70736 KB Output is correct
24 Correct 73 ms 70476 KB Output is correct
25 Correct 114 ms 70664 KB Output is correct
26 Correct 28 ms 65456 KB Output is correct
27 Correct 72 ms 70540 KB Output is correct
28 Correct 74 ms 70476 KB Output is correct
29 Correct 72 ms 70436 KB Output is correct
30 Correct 67 ms 70480 KB Output is correct
31 Correct 82 ms 70696 KB Output is correct
32 Correct 86 ms 70564 KB Output is correct
33 Correct 79 ms 70436 KB Output is correct
34 Correct 1352 ms 113680 KB Output is correct
35 Correct 1435 ms 110116 KB Output is correct
36 Correct 1405 ms 110160 KB Output is correct
37 Incorrect 1210 ms 116152 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 66452 KB Output is correct
2 Correct 76 ms 70528 KB Output is correct
3 Correct 83 ms 70284 KB Output is correct
4 Correct 104 ms 70424 KB Output is correct
5 Correct 25 ms 65584 KB Output is correct
6 Correct 73 ms 70268 KB Output is correct
7 Correct 42 ms 66520 KB Output is correct
8 Correct 73 ms 70560 KB Output is correct
9 Correct 78 ms 70312 KB Output is correct
10 Correct 112 ms 70368 KB Output is correct
11 Correct 26 ms 65476 KB Output is correct
12 Correct 72 ms 70220 KB Output is correct
13 Correct 67 ms 70176 KB Output is correct
14 Correct 63 ms 70276 KB Output is correct
15 Correct 76 ms 70224 KB Output is correct
16 Correct 90 ms 70368 KB Output is correct
17 Correct 67 ms 70248 KB Output is correct
18 Correct 85 ms 70220 KB Output is correct
19 Correct 37 ms 66508 KB Output is correct
20 Correct 75 ms 70540 KB Output is correct
21 Correct 70 ms 70220 KB Output is correct
22 Correct 119 ms 70480 KB Output is correct
23 Correct 29 ms 65600 KB Output is correct
24 Correct 69 ms 70248 KB Output is correct
25 Correct 65 ms 70168 KB Output is correct
26 Correct 74 ms 70220 KB Output is correct
27 Correct 68 ms 70324 KB Output is correct
28 Correct 88 ms 70464 KB Output is correct
29 Correct 74 ms 70312 KB Output is correct
30 Correct 86 ms 70252 KB Output is correct
31 Correct 1379 ms 113400 KB Output is correct
32 Correct 1342 ms 119412 KB Output is correct
33 Correct 1163 ms 113376 KB Output is correct
34 Correct 892 ms 118236 KB Output is correct
35 Correct 3741 ms 107056 KB Output is correct
36 Correct 4388 ms 110400 KB Output is correct
37 Correct 1455 ms 158644 KB Output is correct
38 Correct 27 ms 65492 KB Output is correct
39 Correct 29 ms 65488 KB Output is correct
40 Correct 34 ms 65508 KB Output is correct
41 Correct 58 ms 66712 KB Output is correct
42 Correct 85 ms 70736 KB Output is correct
43 Correct 73 ms 70476 KB Output is correct
44 Correct 114 ms 70664 KB Output is correct
45 Correct 28 ms 65456 KB Output is correct
46 Correct 72 ms 70540 KB Output is correct
47 Correct 74 ms 70476 KB Output is correct
48 Correct 72 ms 70436 KB Output is correct
49 Correct 67 ms 70480 KB Output is correct
50 Correct 82 ms 70696 KB Output is correct
51 Correct 86 ms 70564 KB Output is correct
52 Correct 79 ms 70436 KB Output is correct
53 Correct 1352 ms 113680 KB Output is correct
54 Correct 1435 ms 110116 KB Output is correct
55 Correct 1405 ms 110160 KB Output is correct
56 Incorrect 1210 ms 116152 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 66452 KB Output is correct
2 Correct 76 ms 70528 KB Output is correct
3 Correct 83 ms 70284 KB Output is correct
4 Correct 104 ms 70424 KB Output is correct
5 Correct 25 ms 65584 KB Output is correct
6 Correct 73 ms 70268 KB Output is correct
7 Correct 42 ms 66520 KB Output is correct
8 Correct 73 ms 70560 KB Output is correct
9 Correct 78 ms 70312 KB Output is correct
10 Correct 112 ms 70368 KB Output is correct
11 Correct 26 ms 65476 KB Output is correct
12 Correct 72 ms 70220 KB Output is correct
13 Correct 67 ms 70176 KB Output is correct
14 Correct 63 ms 70276 KB Output is correct
15 Correct 76 ms 70224 KB Output is correct
16 Correct 90 ms 70368 KB Output is correct
17 Correct 67 ms 70248 KB Output is correct
18 Correct 85 ms 70220 KB Output is correct
19 Correct 37 ms 66508 KB Output is correct
20 Correct 75 ms 70540 KB Output is correct
21 Correct 70 ms 70220 KB Output is correct
22 Correct 119 ms 70480 KB Output is correct
23 Correct 29 ms 65600 KB Output is correct
24 Correct 69 ms 70248 KB Output is correct
25 Correct 65 ms 70168 KB Output is correct
26 Correct 74 ms 70220 KB Output is correct
27 Correct 68 ms 70324 KB Output is correct
28 Correct 88 ms 70464 KB Output is correct
29 Correct 74 ms 70312 KB Output is correct
30 Correct 86 ms 70252 KB Output is correct
31 Correct 1379 ms 113400 KB Output is correct
32 Correct 1342 ms 119412 KB Output is correct
33 Correct 1163 ms 113376 KB Output is correct
34 Correct 892 ms 118236 KB Output is correct
35 Correct 3741 ms 107056 KB Output is correct
36 Correct 4388 ms 110400 KB Output is correct
37 Correct 1455 ms 158644 KB Output is correct
38 Correct 36 ms 67084 KB Output is correct
39 Correct 77 ms 71716 KB Output is correct
40 Correct 68 ms 71392 KB Output is correct
41 Correct 112 ms 71484 KB Output is correct
42 Correct 29 ms 65484 KB Output is correct
43 Correct 79 ms 71356 KB Output is correct
44 Correct 81 ms 71328 KB Output is correct
45 Correct 73 ms 71368 KB Output is correct
46 Correct 70 ms 71436 KB Output is correct
47 Correct 86 ms 71588 KB Output is correct
48 Correct 69 ms 71500 KB Output is correct
49 Correct 99 ms 71424 KB Output is correct
50 Correct 1460 ms 151932 KB Output is correct
51 Correct 1313 ms 157972 KB Output is correct
52 Correct 1238 ms 151848 KB Output is correct
53 Correct 1016 ms 156672 KB Output is correct
54 Correct 4152 ms 145788 KB Output is correct
55 Correct 4368 ms 148884 KB Output is correct
56 Correct 1448 ms 158652 KB Output is correct
57 Correct 1634 ms 153556 KB Output is correct
58 Correct 1711 ms 159444 KB Output is correct
59 Correct 1808 ms 151956 KB Output is correct
60 Correct 914 ms 145972 KB Output is correct
61 Execution timed out 6025 ms 152400 KB Time limit exceeded
62 Halted 0 ms 0 KB -