Submission #446889

# Submission time Handle Problem Language Result Execution time Memory
446889 2021-07-23T17:40:39 Z wiwiho From Hacks to Snitches (BOI21_watchmen) C++14
15 / 100
6000 ms 105356 KB
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))

using namespace std;

typedef long long ll;
const ll MAX = 1LL << 60;

using pii = pair<int, int>;

ll iceil(ll a, ll b){
    return (a + b - 1) / b;
}

int n, m, k;
vector<int> len;
vector<int> rid; // route id
vector<int> id; // id in route
vector<vector<int>> g, route;

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

    cin >> n >> m;
    rid.resize(n + 1);
    id.resize(n + 1);
    g.resize(n + 1);
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        g[u].eb(v);
        g[v].eb(u);
    }

    vector<vector<ll>> dis(n + 1, vector<ll>(1, MAX));

    cin >> k;
    len.resize(k + 1);
    route.resize(k + 1);
    len[0] = 1;
    for(int i = 1; i <= k; i++){
        cin >> len[i];
        route[i].resize(len[i]);
        for(int j = 0; j < len[i]; j++){
            int v;
            cin >> v;
            route[i][j] = v;
            rid[v] = i;
            id[v] = j;
            dis[v].resize(len[i], MAX);
        }
    }

    dis[1][0] = 0;
    priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<>> pq;
    pq.push(mp(0, mp(1, 0)));
    while(!pq.empty()){
        ll d = pq.top().F;
        int now = pq.top().S.F;
        int t = pq.top().S.S;
        pq.pop();
        if(d != dis[now][t]) continue;

        // stay
        if(rid[now] != 0 && (t + 1) % len[rid[now]] != id[now]){
            int tmp = (t + 1) % len[rid[now]];
            if(d + 1 < dis[now][tmp]){
                dis[now][tmp] = d + 1;
                pq.push(mp(d + 1, mp(now, tmp)));
            }
        }

        // move
        for(int i : g[now]){
            if(rid[i] == 0){
                if(d + 1 < dis[i][0]){
                    dis[i][0] = d + 1;
                    pq.push(mp(d + 1, mp(i, 0)));
                }
            }
            else if(rid[now] == 0){
                int to = (d + 1) % len[rid[i]];
                if(to != id[i]){
                    if(d + 1 < dis[i][to]){
                        dis[i][to] = d + 1;
                        pq.push(mp(d + 1, mp(i, to)));
                    }
                }
                to = (id[i] + 1) % len[rid[i]];
                ll nd = ((d + 1) / len[rid[i]]) * len[rid[i]] + to;
                if(nd < d + 1) nd += len[rid[i]];
                if(nd < dis[i][to]){
                    dis[i][to] = nd;
                    pq.push(mp(nd, mp(i, to)));
                }
            }
            else if(rid[now] == rid[i]){
                int to = (d + 1) % len[rid[i]];
                if(to == id[i]) continue;
                if(to == id[now] && t == id[i]) continue;
                if(d + 1 < dis[i][to]){
                    dis[i][to] = d + 1;
                    pq.push(mp(d + 1, mp(i, to)));
                }
            }
            else assert(false);
        }
    }

    if(dis[n][0] != MAX) cout << dis[n][0] << "\n";
    else cout << "impossible\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1868 KB Output is correct
2 Correct 110 ms 13268 KB Output is correct
3 Correct 112 ms 12404 KB Output is correct
4 Correct 100 ms 12500 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 78 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1904 KB Output is correct
2 Correct 91 ms 13256 KB Output is correct
3 Correct 85 ms 12292 KB Output is correct
4 Correct 117 ms 12484 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 80 ms 12484 KB Output is correct
7 Correct 71 ms 12336 KB Output is correct
8 Correct 72 ms 12284 KB Output is correct
9 Correct 72 ms 12120 KB Output is correct
10 Correct 99 ms 12476 KB Output is correct
11 Correct 86 ms 12308 KB Output is correct
12 Correct 100 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1904 KB Output is correct
2 Correct 91 ms 13256 KB Output is correct
3 Correct 85 ms 12292 KB Output is correct
4 Correct 117 ms 12484 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 80 ms 12484 KB Output is correct
7 Correct 71 ms 12336 KB Output is correct
8 Correct 72 ms 12284 KB Output is correct
9 Correct 72 ms 12120 KB Output is correct
10 Correct 99 ms 12476 KB Output is correct
11 Correct 86 ms 12308 KB Output is correct
12 Correct 100 ms 12356 KB Output is correct
13 Correct 58 ms 1844 KB Output is correct
14 Correct 77 ms 13212 KB Output is correct
15 Correct 74 ms 12352 KB Output is correct
16 Correct 99 ms 12484 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 81 ms 12360 KB Output is correct
19 Correct 88 ms 12248 KB Output is correct
20 Correct 81 ms 12248 KB Output is correct
21 Correct 89 ms 12240 KB Output is correct
22 Correct 84 ms 12448 KB Output is correct
23 Correct 77 ms 12236 KB Output is correct
24 Correct 88 ms 12436 KB Output is correct
25 Correct 1845 ms 100856 KB Output is correct
26 Correct 1720 ms 105356 KB Output is correct
27 Correct 1754 ms 100736 KB Output is correct
28 Correct 1366 ms 104564 KB Output is correct
29 Execution timed out 6085 ms 97008 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1904 KB Output is correct
2 Correct 91 ms 13256 KB Output is correct
3 Correct 85 ms 12292 KB Output is correct
4 Correct 117 ms 12484 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 80 ms 12484 KB Output is correct
7 Correct 71 ms 12336 KB Output is correct
8 Correct 72 ms 12284 KB Output is correct
9 Correct 72 ms 12120 KB Output is correct
10 Correct 99 ms 12476 KB Output is correct
11 Correct 86 ms 12308 KB Output is correct
12 Correct 100 ms 12356 KB Output is correct
13 Correct 58 ms 1844 KB Output is correct
14 Correct 77 ms 13212 KB Output is correct
15 Correct 74 ms 12352 KB Output is correct
16 Correct 99 ms 12484 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 81 ms 12360 KB Output is correct
19 Correct 88 ms 12248 KB Output is correct
20 Correct 81 ms 12248 KB Output is correct
21 Correct 89 ms 12240 KB Output is correct
22 Correct 84 ms 12448 KB Output is correct
23 Correct 77 ms 12236 KB Output is correct
24 Correct 88 ms 12436 KB Output is correct
25 Correct 1845 ms 100856 KB Output is correct
26 Correct 1720 ms 105356 KB Output is correct
27 Correct 1754 ms 100736 KB Output is correct
28 Correct 1366 ms 104564 KB Output is correct
29 Execution timed out 6085 ms 97008 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1868 KB Output is correct
2 Correct 110 ms 13268 KB Output is correct
3 Correct 112 ms 12404 KB Output is correct
4 Correct 100 ms 12500 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 78 ms 12356 KB Output is correct
7 Correct 56 ms 1904 KB Output is correct
8 Correct 91 ms 13256 KB Output is correct
9 Correct 85 ms 12292 KB Output is correct
10 Correct 117 ms 12484 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 80 ms 12484 KB Output is correct
13 Correct 71 ms 12336 KB Output is correct
14 Correct 72 ms 12284 KB Output is correct
15 Correct 72 ms 12120 KB Output is correct
16 Correct 99 ms 12476 KB Output is correct
17 Correct 86 ms 12308 KB Output is correct
18 Correct 100 ms 12356 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Runtime error 1 ms 460 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1868 KB Output is correct
2 Correct 110 ms 13268 KB Output is correct
3 Correct 112 ms 12404 KB Output is correct
4 Correct 100 ms 12500 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 78 ms 12356 KB Output is correct
7 Correct 56 ms 1904 KB Output is correct
8 Correct 91 ms 13256 KB Output is correct
9 Correct 85 ms 12292 KB Output is correct
10 Correct 117 ms 12484 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 80 ms 12484 KB Output is correct
13 Correct 71 ms 12336 KB Output is correct
14 Correct 72 ms 12284 KB Output is correct
15 Correct 72 ms 12120 KB Output is correct
16 Correct 99 ms 12476 KB Output is correct
17 Correct 86 ms 12308 KB Output is correct
18 Correct 100 ms 12356 KB Output is correct
19 Correct 58 ms 1844 KB Output is correct
20 Correct 77 ms 13212 KB Output is correct
21 Correct 74 ms 12352 KB Output is correct
22 Correct 99 ms 12484 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 81 ms 12360 KB Output is correct
25 Correct 88 ms 12248 KB Output is correct
26 Correct 81 ms 12248 KB Output is correct
27 Correct 89 ms 12240 KB Output is correct
28 Correct 84 ms 12448 KB Output is correct
29 Correct 77 ms 12236 KB Output is correct
30 Correct 88 ms 12436 KB Output is correct
31 Correct 1845 ms 100856 KB Output is correct
32 Correct 1720 ms 105356 KB Output is correct
33 Correct 1754 ms 100736 KB Output is correct
34 Correct 1366 ms 104564 KB Output is correct
35 Execution timed out 6085 ms 97008 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1868 KB Output is correct
2 Correct 110 ms 13268 KB Output is correct
3 Correct 112 ms 12404 KB Output is correct
4 Correct 100 ms 12500 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 78 ms 12356 KB Output is correct
7 Correct 56 ms 1904 KB Output is correct
8 Correct 91 ms 13256 KB Output is correct
9 Correct 85 ms 12292 KB Output is correct
10 Correct 117 ms 12484 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 80 ms 12484 KB Output is correct
13 Correct 71 ms 12336 KB Output is correct
14 Correct 72 ms 12284 KB Output is correct
15 Correct 72 ms 12120 KB Output is correct
16 Correct 99 ms 12476 KB Output is correct
17 Correct 86 ms 12308 KB Output is correct
18 Correct 100 ms 12356 KB Output is correct
19 Correct 58 ms 1844 KB Output is correct
20 Correct 77 ms 13212 KB Output is correct
21 Correct 74 ms 12352 KB Output is correct
22 Correct 99 ms 12484 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 81 ms 12360 KB Output is correct
25 Correct 88 ms 12248 KB Output is correct
26 Correct 81 ms 12248 KB Output is correct
27 Correct 89 ms 12240 KB Output is correct
28 Correct 84 ms 12448 KB Output is correct
29 Correct 77 ms 12236 KB Output is correct
30 Correct 88 ms 12436 KB Output is correct
31 Correct 1845 ms 100856 KB Output is correct
32 Correct 1720 ms 105356 KB Output is correct
33 Correct 1754 ms 100736 KB Output is correct
34 Correct 1366 ms 104564 KB Output is correct
35 Execution timed out 6085 ms 97008 KB Time limit exceeded
36 Halted 0 ms 0 KB -