답안 #446905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446905 2021-07-23T18:14:27 Z wiwiho From Hacks to Snitches (BOI21_watchmen) C++14
50 / 100
6000 ms 163100 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, tg, rg;

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);
    tg.resize(n + 1);
    rg.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);
    len[0] = 1;
    for(int i = 1; i <= k; i++){
        cin >> len[i];
        for(int j = 0; j < len[i]; j++){
            int v;
            cin >> v;
            rid[v] = i;
            id[v] = j;
            dis[v].resize(len[i], MAX);
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j : g[i]){
            if(rid[j] == 0) tg[i].eb(j);
            else rg[i].eb(j);
        }
    }

    dis[1][0] = 0;
    priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<>> pq;
    pq.push(mp(0, mp(1, 0)));
    vector<bool> vst(n + 1);
    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;
        if(!vst[now]){
            for(int i : tg[now]){
                if(d + 1 < dis[i][0]){ dis[i][0] = d + 1;
                    pq.push(mp(d + 1, mp(i, 0)));
                }
            }
        }
        vst[now] = true;


        // 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 : rg[now]){
            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{
                for(int r = 0; r < len[rid[i]]; r++){
                    ll nd = d + (ll) r * len[rid[now]];
                    int to = (nd + 1) % len[rid[i]];
                    if(to == id[i]) continue;
                    if(nd + 1 < dis[i][to]){
                        dis[i][to] = nd + 1;
                        pq.push(mp(nd + 1, mp(i, to)));
                    }
                }
            }
        }
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2252 KB Output is correct
2 Correct 122 ms 19988 KB Output is correct
3 Correct 109 ms 18268 KB Output is correct
4 Correct 123 ms 18640 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 108 ms 18204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2364 KB Output is correct
2 Correct 118 ms 20016 KB Output is correct
3 Correct 125 ms 18328 KB Output is correct
4 Correct 116 ms 18480 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 103 ms 18280 KB Output is correct
7 Correct 99 ms 18184 KB Output is correct
8 Correct 102 ms 18164 KB Output is correct
9 Correct 103 ms 18112 KB Output is correct
10 Correct 101 ms 18628 KB Output is correct
11 Correct 111 ms 18416 KB Output is correct
12 Correct 122 ms 18224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2364 KB Output is correct
2 Correct 118 ms 20016 KB Output is correct
3 Correct 125 ms 18328 KB Output is correct
4 Correct 116 ms 18480 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 103 ms 18280 KB Output is correct
7 Correct 99 ms 18184 KB Output is correct
8 Correct 102 ms 18164 KB Output is correct
9 Correct 103 ms 18112 KB Output is correct
10 Correct 101 ms 18628 KB Output is correct
11 Correct 111 ms 18416 KB Output is correct
12 Correct 122 ms 18224 KB Output is correct
13 Correct 31 ms 2256 KB Output is correct
14 Correct 113 ms 20020 KB Output is correct
15 Correct 100 ms 18244 KB Output is correct
16 Correct 123 ms 18500 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 96 ms 18208 KB Output is correct
19 Correct 101 ms 18160 KB Output is correct
20 Correct 91 ms 18228 KB Output is correct
21 Correct 122 ms 18116 KB Output is correct
22 Correct 99 ms 18684 KB Output is correct
23 Correct 97 ms 18456 KB Output is correct
24 Correct 99 ms 18228 KB Output is correct
25 Correct 1877 ms 112380 KB Output is correct
26 Correct 1833 ms 120692 KB Output is correct
27 Correct 1679 ms 112632 KB Output is correct
28 Correct 1365 ms 121424 KB Output is correct
29 Correct 1771 ms 106392 KB Output is correct
30 Correct 1748 ms 108620 KB Output is correct
31 Correct 1996 ms 119748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2364 KB Output is correct
2 Correct 118 ms 20016 KB Output is correct
3 Correct 125 ms 18328 KB Output is correct
4 Correct 116 ms 18480 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 103 ms 18280 KB Output is correct
7 Correct 99 ms 18184 KB Output is correct
8 Correct 102 ms 18164 KB Output is correct
9 Correct 103 ms 18112 KB Output is correct
10 Correct 101 ms 18628 KB Output is correct
11 Correct 111 ms 18416 KB Output is correct
12 Correct 122 ms 18224 KB Output is correct
13 Correct 31 ms 2256 KB Output is correct
14 Correct 113 ms 20020 KB Output is correct
15 Correct 100 ms 18244 KB Output is correct
16 Correct 123 ms 18500 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 96 ms 18208 KB Output is correct
19 Correct 101 ms 18160 KB Output is correct
20 Correct 91 ms 18228 KB Output is correct
21 Correct 122 ms 18116 KB Output is correct
22 Correct 99 ms 18684 KB Output is correct
23 Correct 97 ms 18456 KB Output is correct
24 Correct 99 ms 18228 KB Output is correct
25 Correct 1877 ms 112380 KB Output is correct
26 Correct 1833 ms 120692 KB Output is correct
27 Correct 1679 ms 112632 KB Output is correct
28 Correct 1365 ms 121424 KB Output is correct
29 Correct 1771 ms 106392 KB Output is correct
30 Correct 1748 ms 108620 KB Output is correct
31 Correct 1996 ms 119748 KB Output is correct
32 Correct 32 ms 2432 KB Output is correct
33 Correct 109 ms 20116 KB Output is correct
34 Correct 96 ms 18336 KB Output is correct
35 Correct 116 ms 18676 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 106 ms 18396 KB Output is correct
38 Correct 91 ms 18360 KB Output is correct
39 Correct 111 ms 18404 KB Output is correct
40 Correct 94 ms 18244 KB Output is correct
41 Correct 133 ms 18720 KB Output is correct
42 Correct 106 ms 18740 KB Output is correct
43 Correct 94 ms 18388 KB Output is correct
44 Correct 1872 ms 112244 KB Output is correct
45 Correct 1861 ms 120800 KB Output is correct
46 Correct 1597 ms 112468 KB Output is correct
47 Correct 1453 ms 121300 KB Output is correct
48 Correct 1762 ms 106276 KB Output is correct
49 Correct 1914 ms 108672 KB Output is correct
50 Correct 1959 ms 119768 KB Output is correct
51 Correct 2536 ms 129164 KB Output is correct
52 Correct 2779 ms 150576 KB Output is correct
53 Correct 2312 ms 130652 KB Output is correct
54 Correct 1365 ms 104004 KB Output is correct
55 Execution timed out 6060 ms 134716 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2252 KB Output is correct
2 Correct 122 ms 19988 KB Output is correct
3 Correct 109 ms 18268 KB Output is correct
4 Correct 123 ms 18640 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 108 ms 18204 KB Output is correct
7 Correct 32 ms 2364 KB Output is correct
8 Correct 118 ms 20016 KB Output is correct
9 Correct 125 ms 18328 KB Output is correct
10 Correct 116 ms 18480 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 103 ms 18280 KB Output is correct
13 Correct 99 ms 18184 KB Output is correct
14 Correct 102 ms 18164 KB Output is correct
15 Correct 103 ms 18112 KB Output is correct
16 Correct 101 ms 18628 KB Output is correct
17 Correct 111 ms 18416 KB Output is correct
18 Correct 122 ms 18224 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 34 ms 2872 KB Output is correct
23 Correct 99 ms 21140 KB Output is correct
24 Correct 97 ms 19392 KB Output is correct
25 Correct 112 ms 19624 KB Output is correct
26 Correct 3 ms 588 KB Output is correct
27 Correct 127 ms 19428 KB Output is correct
28 Correct 123 ms 19332 KB Output is correct
29 Correct 93 ms 19364 KB Output is correct
30 Correct 103 ms 19264 KB Output is correct
31 Correct 101 ms 19776 KB Output is correct
32 Correct 122 ms 19600 KB Output is correct
33 Correct 122 ms 19344 KB Output is correct
34 Correct 1954 ms 154392 KB Output is correct
35 Correct 1991 ms 144728 KB Output is correct
36 Correct 1956 ms 144580 KB Output is correct
37 Correct 1748 ms 155952 KB Output is correct
38 Correct 1959 ms 150564 KB Output is correct
39 Correct 1767 ms 145108 KB Output is correct
40 Correct 1962 ms 147316 KB Output is correct
41 Correct 1929 ms 145128 KB Output is correct
42 Correct 1956 ms 150496 KB Output is correct
43 Correct 2097 ms 157648 KB Output is correct
44 Correct 2130 ms 157744 KB Output is correct
45 Correct 2108 ms 149512 KB Output is correct
46 Correct 2020 ms 150520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2252 KB Output is correct
2 Correct 122 ms 19988 KB Output is correct
3 Correct 109 ms 18268 KB Output is correct
4 Correct 123 ms 18640 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 108 ms 18204 KB Output is correct
7 Correct 32 ms 2364 KB Output is correct
8 Correct 118 ms 20016 KB Output is correct
9 Correct 125 ms 18328 KB Output is correct
10 Correct 116 ms 18480 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 103 ms 18280 KB Output is correct
13 Correct 99 ms 18184 KB Output is correct
14 Correct 102 ms 18164 KB Output is correct
15 Correct 103 ms 18112 KB Output is correct
16 Correct 101 ms 18628 KB Output is correct
17 Correct 111 ms 18416 KB Output is correct
18 Correct 122 ms 18224 KB Output is correct
19 Correct 31 ms 2256 KB Output is correct
20 Correct 113 ms 20020 KB Output is correct
21 Correct 100 ms 18244 KB Output is correct
22 Correct 123 ms 18500 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 96 ms 18208 KB Output is correct
25 Correct 101 ms 18160 KB Output is correct
26 Correct 91 ms 18228 KB Output is correct
27 Correct 122 ms 18116 KB Output is correct
28 Correct 99 ms 18684 KB Output is correct
29 Correct 97 ms 18456 KB Output is correct
30 Correct 99 ms 18228 KB Output is correct
31 Correct 1877 ms 112380 KB Output is correct
32 Correct 1833 ms 120692 KB Output is correct
33 Correct 1679 ms 112632 KB Output is correct
34 Correct 1365 ms 121424 KB Output is correct
35 Correct 1771 ms 106392 KB Output is correct
36 Correct 1748 ms 108620 KB Output is correct
37 Correct 1996 ms 119748 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 34 ms 2872 KB Output is correct
42 Correct 99 ms 21140 KB Output is correct
43 Correct 97 ms 19392 KB Output is correct
44 Correct 112 ms 19624 KB Output is correct
45 Correct 3 ms 588 KB Output is correct
46 Correct 127 ms 19428 KB Output is correct
47 Correct 123 ms 19332 KB Output is correct
48 Correct 93 ms 19364 KB Output is correct
49 Correct 103 ms 19264 KB Output is correct
50 Correct 101 ms 19776 KB Output is correct
51 Correct 122 ms 19600 KB Output is correct
52 Correct 122 ms 19344 KB Output is correct
53 Correct 1954 ms 154392 KB Output is correct
54 Correct 1991 ms 144728 KB Output is correct
55 Correct 1956 ms 144580 KB Output is correct
56 Correct 1748 ms 155952 KB Output is correct
57 Correct 1959 ms 150564 KB Output is correct
58 Correct 1767 ms 145108 KB Output is correct
59 Correct 1962 ms 147316 KB Output is correct
60 Correct 1929 ms 145128 KB Output is correct
61 Correct 1956 ms 150496 KB Output is correct
62 Correct 2097 ms 157648 KB Output is correct
63 Correct 2130 ms 157744 KB Output is correct
64 Correct 2108 ms 149512 KB Output is correct
65 Correct 2020 ms 150520 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 32 ms 2884 KB Output is correct
70 Correct 116 ms 21060 KB Output is correct
71 Correct 108 ms 19388 KB Output is correct
72 Correct 121 ms 19636 KB Output is correct
73 Correct 3 ms 332 KB Output is correct
74 Correct 106 ms 19440 KB Output is correct
75 Correct 103 ms 19400 KB Output is correct
76 Correct 98 ms 19404 KB Output is correct
77 Correct 105 ms 19376 KB Output is correct
78 Correct 109 ms 19784 KB Output is correct
79 Correct 106 ms 19588 KB Output is correct
80 Correct 106 ms 19388 KB Output is correct
81 Correct 1986 ms 150940 KB Output is correct
82 Correct 1862 ms 159260 KB Output is correct
83 Correct 1824 ms 151312 KB Output is correct
84 Correct 1494 ms 159944 KB Output is correct
85 Correct 1838 ms 145080 KB Output is correct
86 Correct 1855 ms 146984 KB Output is correct
87 Correct 2093 ms 158356 KB Output is correct
88 Correct 1955 ms 154460 KB Output is correct
89 Correct 2078 ms 144672 KB Output is correct
90 Correct 2055 ms 144512 KB Output is correct
91 Correct 1948 ms 155912 KB Output is correct
92 Correct 2069 ms 150468 KB Output is correct
93 Correct 1906 ms 145176 KB Output is correct
94 Correct 2039 ms 147156 KB Output is correct
95 Correct 1835 ms 144956 KB Output is correct
96 Correct 1993 ms 150612 KB Output is correct
97 Correct 2041 ms 157796 KB Output is correct
98 Correct 2093 ms 157916 KB Output is correct
99 Correct 2104 ms 149432 KB Output is correct
100 Correct 1996 ms 150504 KB Output is correct
101 Correct 2045 ms 154596 KB Output is correct
102 Correct 1862 ms 156080 KB Output is correct
103 Correct 1988 ms 150752 KB Output is correct
104 Execution timed out 6098 ms 163100 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2252 KB Output is correct
2 Correct 122 ms 19988 KB Output is correct
3 Correct 109 ms 18268 KB Output is correct
4 Correct 123 ms 18640 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 108 ms 18204 KB Output is correct
7 Correct 32 ms 2364 KB Output is correct
8 Correct 118 ms 20016 KB Output is correct
9 Correct 125 ms 18328 KB Output is correct
10 Correct 116 ms 18480 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 103 ms 18280 KB Output is correct
13 Correct 99 ms 18184 KB Output is correct
14 Correct 102 ms 18164 KB Output is correct
15 Correct 103 ms 18112 KB Output is correct
16 Correct 101 ms 18628 KB Output is correct
17 Correct 111 ms 18416 KB Output is correct
18 Correct 122 ms 18224 KB Output is correct
19 Correct 31 ms 2256 KB Output is correct
20 Correct 113 ms 20020 KB Output is correct
21 Correct 100 ms 18244 KB Output is correct
22 Correct 123 ms 18500 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 96 ms 18208 KB Output is correct
25 Correct 101 ms 18160 KB Output is correct
26 Correct 91 ms 18228 KB Output is correct
27 Correct 122 ms 18116 KB Output is correct
28 Correct 99 ms 18684 KB Output is correct
29 Correct 97 ms 18456 KB Output is correct
30 Correct 99 ms 18228 KB Output is correct
31 Correct 1877 ms 112380 KB Output is correct
32 Correct 1833 ms 120692 KB Output is correct
33 Correct 1679 ms 112632 KB Output is correct
34 Correct 1365 ms 121424 KB Output is correct
35 Correct 1771 ms 106392 KB Output is correct
36 Correct 1748 ms 108620 KB Output is correct
37 Correct 1996 ms 119748 KB Output is correct
38 Correct 32 ms 2432 KB Output is correct
39 Correct 109 ms 20116 KB Output is correct
40 Correct 96 ms 18336 KB Output is correct
41 Correct 116 ms 18676 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 106 ms 18396 KB Output is correct
44 Correct 91 ms 18360 KB Output is correct
45 Correct 111 ms 18404 KB Output is correct
46 Correct 94 ms 18244 KB Output is correct
47 Correct 133 ms 18720 KB Output is correct
48 Correct 106 ms 18740 KB Output is correct
49 Correct 94 ms 18388 KB Output is correct
50 Correct 1872 ms 112244 KB Output is correct
51 Correct 1861 ms 120800 KB Output is correct
52 Correct 1597 ms 112468 KB Output is correct
53 Correct 1453 ms 121300 KB Output is correct
54 Correct 1762 ms 106276 KB Output is correct
55 Correct 1914 ms 108672 KB Output is correct
56 Correct 1959 ms 119768 KB Output is correct
57 Correct 2536 ms 129164 KB Output is correct
58 Correct 2779 ms 150576 KB Output is correct
59 Correct 2312 ms 130652 KB Output is correct
60 Correct 1365 ms 104004 KB Output is correct
61 Execution timed out 6060 ms 134716 KB Time limit exceeded
62 Halted 0 ms 0 KB -