답안 #426382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426382 2021-06-13T21:44:25 Z duality From Hacks to Snitches (BOI21_watchmen) C++11
25 / 100
6000 ms 135608 KB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int readInt() {
    char c;
    int n = 0;
    while ((c=getchar()) < '0');
    n = c-'0';
    while ((c=getchar()) >= '0') n = n*10+c-'0';
    return n;
}

vi adjList[250000];
int pos[250000];
pair<int,pii> p[250000];
bool comp(int a,int b) {
    return p[a] < p[b];
}
vi dist[250000];
int done[250000],done2[250000];
vi Q[1000000];
int main() {
    int i,j;
    int N,M,K;
    int u,v,l;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) {
        u = readInt();
        v = readInt();
        u--,v--;
        adjList[u].pb(v);
        adjList[v].pb(u);
    }
    scanf("%d",&K);
    for (i = 0; i < K; i++) {
        scanf("%d",&l);
        for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i));
    }

    for (i = 0; i < N; i++) {
        if (p[i].first == 0) p[i].first = 1;
        dist[i].resize(p[i].first);
        fill(dist[i].begin(),dist[i].end(),-1);
        sort(adjList[i].begin(),adjList[i].end(),comp);
        while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first <= 1)) pos[i]++;
    }
    int pp = 0;
    dist[0][0] = 0,Q[0].pb(0);
    while (1) {
        while ((pp < 1000000) && (Q[pp].empty())) pp++;
        if (pp == 1000000) break;
        int u = Q[pp].back();
        int d = pp;
        Q[pp].pop_back();

        if (d > dist[u][d % p[u].first]) continue;
        else if (u == N-1) {
            printf("%d\n",d);
            return 0;
        }
        i = 0;
        if (done2[u]) i = pos[u];
        for (; i < adjList[u].size(); i++) {
            int v = adjList[u][i],t = d;
            for (j = 0; j < ((p[u].first == 1) ? p[v].first:((p[u].second.second == p[v].second.second) ? 1:p[v].first)); j++) {
                if (done[v] && (p[u].first == 1)) break;
                int bad = 0;
                if (p[v].first != 1) {
                    if (((d+1) % p[v].first) == p[v].second.first) bad = 1;
                    if (((d % p[v].first) == p[v].second.first) && (p[u].second.second == p[v].second.second) \
                        && (p[u].second.first == ((p[v].second.first+1) % p[v].first))) bad = 1;
                }
                if (!bad) {
                    if ((dist[v][(d+1) % p[v].first] == -1) || (d+1 < dist[v][(d+1) % p[v].first])) {
                        dist[v][(d+1) % p[v].first] = d+1;
                        Q[d+1].pb(v);
                    }
                }
                d += p[u].first;
                bad = 0;
                if (p[v].first != 1) {
                    if (((d+1) % p[v].first) == p[v].second.first) bad = 1;
                    if (((d % p[v].first) == p[v].second.first) && (p[u].second.second == p[v].second.second) \
                        && (p[u].second.first == ((p[v].second.first+1) % p[v].first))) bad = 1;
                }
                if (!bad) {
                    if ((dist[v][(d+1) % p[v].first] == -1) || (d+1 < dist[v][(d+1) % p[v].first])) {
                        dist[v][(d+1) % p[v].first] = d+1;
                        Q[d+1].pb(v);
                    }
                }
                d += p[u].first;
                bad = 0;
                if (p[v].first != 1) {
                    if (((d+1) % p[v].first) == p[v].second.first) bad = 1;
                    if (((d % p[v].first) == p[v].second.first) && (p[u].second.second == p[v].second.second) \
                        && (p[u].second.first == ((p[v].second.first+1) % p[v].first))) bad = 1;
                }
                if (!bad) {
                    if ((dist[v][(d+1) % p[v].first] == -1) || (d+1 < dist[v][(d+1) % p[v].first])) {
                        dist[v][(d+1) % p[v].first] = d+1;
                        Q[d+1].pb(v);
                    }
                }
                d -= 2*p[u].first;
                d++;
                if ((p[u].first != 1) && ((d % p[u].first) == p[u].second.first)) break;
            }
            if ((p[u].first == 1) && (p[v].first != 1)) done[v] = 1;
            d = t+p[u].first;
            int bad = 0;
            if (p[v].first != 1) {
                if (((d+1) % p[v].first) == p[v].second.first) bad = 1;
                if (((d % p[v].first) == p[v].second.first) && (p[u].second.second == p[v].second.second) \
                    && (p[u].second.first == ((p[v].second.first+1) % p[v].first))) bad = 1;
            }
            if (!bad) {
                if ((dist[v][(d+1) % p[v].first] == -1) || (d+1 < dist[v][(d+1) % p[v].first])) {
                    dist[v][(d+1) % p[v].first] = d+1;
                    Q[d+1].pb(v);
                }
            }
            d = t;
        }
        done2[u] = 1;
    }
    printf("impossible\n");

    return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first <= 1)) pos[i]++;
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (; i < adjList[u].size(); i++) {
      |                ~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d",&K);
      |     ~~~~~^~~~~~~~~
watchmen.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d",&l);
      |         ~~~~~^~~~~~~~~
watchmen.cpp:42:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i));
      |                                 ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 36996 KB Output is correct
2 Correct 146 ms 47456 KB Output is correct
3 Correct 103 ms 46024 KB Output is correct
4 Correct 208 ms 45504 KB Output is correct
5 Correct 21 ms 35584 KB Output is correct
6 Correct 117 ms 45804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 37068 KB Output is correct
2 Correct 115 ms 47428 KB Output is correct
3 Correct 111 ms 46020 KB Output is correct
4 Correct 209 ms 45460 KB Output is correct
5 Correct 22 ms 35604 KB Output is correct
6 Correct 106 ms 45720 KB Output is correct
7 Correct 110 ms 45800 KB Output is correct
8 Correct 105 ms 46172 KB Output is correct
9 Correct 105 ms 46140 KB Output is correct
10 Correct 130 ms 44796 KB Output is correct
11 Correct 106 ms 44312 KB Output is correct
12 Correct 112 ms 45692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 37068 KB Output is correct
2 Correct 115 ms 47428 KB Output is correct
3 Correct 111 ms 46020 KB Output is correct
4 Correct 209 ms 45460 KB Output is correct
5 Correct 22 ms 35604 KB Output is correct
6 Correct 106 ms 45720 KB Output is correct
7 Correct 110 ms 45800 KB Output is correct
8 Correct 105 ms 46172 KB Output is correct
9 Correct 105 ms 46140 KB Output is correct
10 Correct 130 ms 44796 KB Output is correct
11 Correct 106 ms 44312 KB Output is correct
12 Correct 112 ms 45692 KB Output is correct
13 Correct 40 ms 36888 KB Output is correct
14 Correct 127 ms 47580 KB Output is correct
15 Correct 115 ms 46036 KB Output is correct
16 Correct 202 ms 45508 KB Output is correct
17 Correct 22 ms 35620 KB Output is correct
18 Correct 105 ms 45780 KB Output is correct
19 Correct 110 ms 45876 KB Output is correct
20 Correct 107 ms 46208 KB Output is correct
21 Correct 105 ms 46148 KB Output is correct
22 Correct 125 ms 44784 KB Output is correct
23 Correct 102 ms 44368 KB Output is correct
24 Correct 112 ms 45692 KB Output is correct
25 Correct 2570 ms 95144 KB Output is correct
26 Correct 2345 ms 99796 KB Output is correct
27 Correct 2154 ms 96508 KB Output is correct
28 Correct 1525 ms 100548 KB Output is correct
29 Correct 2603 ms 88260 KB Output is correct
30 Correct 2814 ms 89512 KB Output is correct
31 Correct 2815 ms 98084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 37068 KB Output is correct
2 Correct 115 ms 47428 KB Output is correct
3 Correct 111 ms 46020 KB Output is correct
4 Correct 209 ms 45460 KB Output is correct
5 Correct 22 ms 35604 KB Output is correct
6 Correct 106 ms 45720 KB Output is correct
7 Correct 110 ms 45800 KB Output is correct
8 Correct 105 ms 46172 KB Output is correct
9 Correct 105 ms 46140 KB Output is correct
10 Correct 130 ms 44796 KB Output is correct
11 Correct 106 ms 44312 KB Output is correct
12 Correct 112 ms 45692 KB Output is correct
13 Correct 40 ms 36888 KB Output is correct
14 Correct 127 ms 47580 KB Output is correct
15 Correct 115 ms 46036 KB Output is correct
16 Correct 202 ms 45508 KB Output is correct
17 Correct 22 ms 35620 KB Output is correct
18 Correct 105 ms 45780 KB Output is correct
19 Correct 110 ms 45876 KB Output is correct
20 Correct 107 ms 46208 KB Output is correct
21 Correct 105 ms 46148 KB Output is correct
22 Correct 125 ms 44784 KB Output is correct
23 Correct 102 ms 44368 KB Output is correct
24 Correct 112 ms 45692 KB Output is correct
25 Correct 2570 ms 95144 KB Output is correct
26 Correct 2345 ms 99796 KB Output is correct
27 Correct 2154 ms 96508 KB Output is correct
28 Correct 1525 ms 100548 KB Output is correct
29 Correct 2603 ms 88260 KB Output is correct
30 Correct 2814 ms 89512 KB Output is correct
31 Correct 2815 ms 98084 KB Output is correct
32 Correct 41 ms 36788 KB Output is correct
33 Correct 126 ms 47308 KB Output is correct
34 Correct 111 ms 45912 KB Output is correct
35 Correct 206 ms 45324 KB Output is correct
36 Correct 23 ms 35516 KB Output is correct
37 Correct 106 ms 45556 KB Output is correct
38 Correct 106 ms 45764 KB Output is correct
39 Correct 104 ms 46004 KB Output is correct
40 Correct 104 ms 46084 KB Output is correct
41 Correct 134 ms 44736 KB Output is correct
42 Correct 105 ms 44196 KB Output is correct
43 Correct 108 ms 45508 KB Output is correct
44 Correct 2552 ms 94344 KB Output is correct
45 Correct 2424 ms 99164 KB Output is correct
46 Correct 2313 ms 96100 KB Output is correct
47 Correct 1551 ms 100200 KB Output is correct
48 Correct 2580 ms 87704 KB Output is correct
49 Correct 2841 ms 88868 KB Output is correct
50 Correct 2877 ms 97872 KB Output is correct
51 Correct 3144 ms 115044 KB Output is correct
52 Correct 3213 ms 135608 KB Output is correct
53 Correct 3225 ms 117148 KB Output is correct
54 Correct 1665 ms 93052 KB Output is correct
55 Execution timed out 6054 ms 110632 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 36996 KB Output is correct
2 Correct 146 ms 47456 KB Output is correct
3 Correct 103 ms 46024 KB Output is correct
4 Correct 208 ms 45504 KB Output is correct
5 Correct 21 ms 35584 KB Output is correct
6 Correct 117 ms 45804 KB Output is correct
7 Correct 40 ms 37068 KB Output is correct
8 Correct 115 ms 47428 KB Output is correct
9 Correct 111 ms 46020 KB Output is correct
10 Correct 209 ms 45460 KB Output is correct
11 Correct 22 ms 35604 KB Output is correct
12 Correct 106 ms 45720 KB Output is correct
13 Correct 110 ms 45800 KB Output is correct
14 Correct 105 ms 46172 KB Output is correct
15 Correct 105 ms 46140 KB Output is correct
16 Correct 130 ms 44796 KB Output is correct
17 Correct 106 ms 44312 KB Output is correct
18 Correct 112 ms 45692 KB Output is correct
19 Correct 24 ms 35528 KB Output is correct
20 Correct 24 ms 35436 KB Output is correct
21 Correct 28 ms 35532 KB Output is correct
22 Correct 41 ms 36556 KB Output is correct
23 Correct 137 ms 47048 KB Output is correct
24 Correct 126 ms 45604 KB Output is correct
25 Correct 216 ms 45184 KB Output is correct
26 Correct 23 ms 35532 KB Output is correct
27 Correct 130 ms 45384 KB Output is correct
28 Correct 110 ms 45520 KB Output is correct
29 Correct 122 ms 45860 KB Output is correct
30 Correct 134 ms 45788 KB Output is correct
31 Correct 158 ms 44556 KB Output is correct
32 Correct 112 ms 43944 KB Output is correct
33 Correct 156 ms 45428 KB Output is correct
34 Correct 3099 ms 92080 KB Output is correct
35 Correct 3054 ms 87200 KB Output is correct
36 Correct 3111 ms 89312 KB Output is correct
37 Correct 2745 ms 94952 KB Output is correct
38 Correct 2647 ms 94020 KB Output is correct
39 Correct 2492 ms 87772 KB Output is correct
40 Correct 2863 ms 88320 KB Output is correct
41 Correct 2431 ms 87852 KB Output is correct
42 Correct 2663 ms 93748 KB Output is correct
43 Correct 3331 ms 93660 KB Output is correct
44 Correct 3099 ms 96512 KB Output is correct
45 Incorrect 1809 ms 85916 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 36996 KB Output is correct
2 Correct 146 ms 47456 KB Output is correct
3 Correct 103 ms 46024 KB Output is correct
4 Correct 208 ms 45504 KB Output is correct
5 Correct 21 ms 35584 KB Output is correct
6 Correct 117 ms 45804 KB Output is correct
7 Correct 40 ms 37068 KB Output is correct
8 Correct 115 ms 47428 KB Output is correct
9 Correct 111 ms 46020 KB Output is correct
10 Correct 209 ms 45460 KB Output is correct
11 Correct 22 ms 35604 KB Output is correct
12 Correct 106 ms 45720 KB Output is correct
13 Correct 110 ms 45800 KB Output is correct
14 Correct 105 ms 46172 KB Output is correct
15 Correct 105 ms 46140 KB Output is correct
16 Correct 130 ms 44796 KB Output is correct
17 Correct 106 ms 44312 KB Output is correct
18 Correct 112 ms 45692 KB Output is correct
19 Correct 40 ms 36888 KB Output is correct
20 Correct 127 ms 47580 KB Output is correct
21 Correct 115 ms 46036 KB Output is correct
22 Correct 202 ms 45508 KB Output is correct
23 Correct 22 ms 35620 KB Output is correct
24 Correct 105 ms 45780 KB Output is correct
25 Correct 110 ms 45876 KB Output is correct
26 Correct 107 ms 46208 KB Output is correct
27 Correct 105 ms 46148 KB Output is correct
28 Correct 125 ms 44784 KB Output is correct
29 Correct 102 ms 44368 KB Output is correct
30 Correct 112 ms 45692 KB Output is correct
31 Correct 2570 ms 95144 KB Output is correct
32 Correct 2345 ms 99796 KB Output is correct
33 Correct 2154 ms 96508 KB Output is correct
34 Correct 1525 ms 100548 KB Output is correct
35 Correct 2603 ms 88260 KB Output is correct
36 Correct 2814 ms 89512 KB Output is correct
37 Correct 2815 ms 98084 KB Output is correct
38 Correct 24 ms 35528 KB Output is correct
39 Correct 24 ms 35436 KB Output is correct
40 Correct 28 ms 35532 KB Output is correct
41 Correct 41 ms 36556 KB Output is correct
42 Correct 137 ms 47048 KB Output is correct
43 Correct 126 ms 45604 KB Output is correct
44 Correct 216 ms 45184 KB Output is correct
45 Correct 23 ms 35532 KB Output is correct
46 Correct 130 ms 45384 KB Output is correct
47 Correct 110 ms 45520 KB Output is correct
48 Correct 122 ms 45860 KB Output is correct
49 Correct 134 ms 45788 KB Output is correct
50 Correct 158 ms 44556 KB Output is correct
51 Correct 112 ms 43944 KB Output is correct
52 Correct 156 ms 45428 KB Output is correct
53 Correct 3099 ms 92080 KB Output is correct
54 Correct 3054 ms 87200 KB Output is correct
55 Correct 3111 ms 89312 KB Output is correct
56 Correct 2745 ms 94952 KB Output is correct
57 Correct 2647 ms 94020 KB Output is correct
58 Correct 2492 ms 87772 KB Output is correct
59 Correct 2863 ms 88320 KB Output is correct
60 Correct 2431 ms 87852 KB Output is correct
61 Correct 2663 ms 93748 KB Output is correct
62 Correct 3331 ms 93660 KB Output is correct
63 Correct 3099 ms 96512 KB Output is correct
64 Incorrect 1809 ms 85916 KB Output isn't correct
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 36996 KB Output is correct
2 Correct 146 ms 47456 KB Output is correct
3 Correct 103 ms 46024 KB Output is correct
4 Correct 208 ms 45504 KB Output is correct
5 Correct 21 ms 35584 KB Output is correct
6 Correct 117 ms 45804 KB Output is correct
7 Correct 40 ms 37068 KB Output is correct
8 Correct 115 ms 47428 KB Output is correct
9 Correct 111 ms 46020 KB Output is correct
10 Correct 209 ms 45460 KB Output is correct
11 Correct 22 ms 35604 KB Output is correct
12 Correct 106 ms 45720 KB Output is correct
13 Correct 110 ms 45800 KB Output is correct
14 Correct 105 ms 46172 KB Output is correct
15 Correct 105 ms 46140 KB Output is correct
16 Correct 130 ms 44796 KB Output is correct
17 Correct 106 ms 44312 KB Output is correct
18 Correct 112 ms 45692 KB Output is correct
19 Correct 40 ms 36888 KB Output is correct
20 Correct 127 ms 47580 KB Output is correct
21 Correct 115 ms 46036 KB Output is correct
22 Correct 202 ms 45508 KB Output is correct
23 Correct 22 ms 35620 KB Output is correct
24 Correct 105 ms 45780 KB Output is correct
25 Correct 110 ms 45876 KB Output is correct
26 Correct 107 ms 46208 KB Output is correct
27 Correct 105 ms 46148 KB Output is correct
28 Correct 125 ms 44784 KB Output is correct
29 Correct 102 ms 44368 KB Output is correct
30 Correct 112 ms 45692 KB Output is correct
31 Correct 2570 ms 95144 KB Output is correct
32 Correct 2345 ms 99796 KB Output is correct
33 Correct 2154 ms 96508 KB Output is correct
34 Correct 1525 ms 100548 KB Output is correct
35 Correct 2603 ms 88260 KB Output is correct
36 Correct 2814 ms 89512 KB Output is correct
37 Correct 2815 ms 98084 KB Output is correct
38 Correct 41 ms 36788 KB Output is correct
39 Correct 126 ms 47308 KB Output is correct
40 Correct 111 ms 45912 KB Output is correct
41 Correct 206 ms 45324 KB Output is correct
42 Correct 23 ms 35516 KB Output is correct
43 Correct 106 ms 45556 KB Output is correct
44 Correct 106 ms 45764 KB Output is correct
45 Correct 104 ms 46004 KB Output is correct
46 Correct 104 ms 46084 KB Output is correct
47 Correct 134 ms 44736 KB Output is correct
48 Correct 105 ms 44196 KB Output is correct
49 Correct 108 ms 45508 KB Output is correct
50 Correct 2552 ms 94344 KB Output is correct
51 Correct 2424 ms 99164 KB Output is correct
52 Correct 2313 ms 96100 KB Output is correct
53 Correct 1551 ms 100200 KB Output is correct
54 Correct 2580 ms 87704 KB Output is correct
55 Correct 2841 ms 88868 KB Output is correct
56 Correct 2877 ms 97872 KB Output is correct
57 Correct 3144 ms 115044 KB Output is correct
58 Correct 3213 ms 135608 KB Output is correct
59 Correct 3225 ms 117148 KB Output is correct
60 Correct 1665 ms 93052 KB Output is correct
61 Execution timed out 6054 ms 110632 KB Time limit exceeded
62 Halted 0 ms 0 KB -