Submission #426410

# Submission time Handle Problem Language Result Execution time Memory
426410 2021-06-14T01:17:08 Z duality From Hacks to Snitches (BOI21_watchmen) C++11
35 / 100
3930 ms 159000 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;

vi adjList[250000];
pair<int,pii> p[250000];
bool comp(int a,int b) {
    return p[a] < p[b];
}
int pos[250000];
vector<LLI> dist[250000];
priority_queue<pair<LLI,int> > H;
int relax(int u,LLI d) {
    if ((dist[u][d % p[u].first] == -1) || (d < dist[u][d % p[u].first])) {
        dist[u][d % p[u].first] = d;
        H.push(mp(-d,u));
    }
    return 0;
}
int done[250000],done2[250000];
set<pii> done3[250000];
int main() {
    int i,j;
    int N,M,K;
    int u,v,l;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) {
        scanf("%d %d",&u,&v);
        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);
    }
    for (i = 0; i < N; i++) {
        sort(adjList[i].begin(),adjList[i].end(),comp);
        while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first == 1)) pos[i]++;
    }
    dist[0][0] = 0,H.push(mp(0,0));
    while (!H.empty()) {
        int u = H.top().second;
        LLI d = -H.top().first;
        H.pop();

        if (d > dist[u][d % p[u].first]) continue;
        else if (u == N-1) {
            printf("%lld\n",d);
            return 0;
        }
        if ((p[u].first == 1) || (((d+1) % p[u].first) != p[u].second.first)) relax(u,d+1);
        if (done[u] && (dist[u][(d+p[u].first-1) % p[u].first] == d-1) && (dist[u][(d+p[u].first-2) % p[u].first] == d-2)) continue;
        for (i = done[u] ? pos[u]:0; i < adjList[u].size(); i++) {
            int v = adjList[u][i];
            if (p[v].first == 1) relax(v,d+1);
            else if (p[u].first == 1) {
                if (done2[v]) continue;
                else {
                    for (j = 0; j < p[v].first; j++) {
                        LLI d2 = d+j+1;
                        if ((d2 % p[v].first) != p[v].second.first) relax(v,d2);
                    }
                    done2[v] = 1;
                }
            }
            else if (p[u].second.second == p[v].second.second) {
                if (((d+1) % p[v].first) == p[v].second.first) continue;
                if (((d % p[v].first) == p[v].second.first) && (((d+1) % p[u].first) == p[u].second.first)) continue;
                relax(v,d+1);
            }
            else {
                if (done3[v].count(mp(d % p[v].first,p[u].first))) continue;
                for (j = 0; j < p[v].first; j++) {
                    LLI d2 = d+(LLI) j*p[u].first+1;
                    if ((d2 % p[v].first) != p[v].second.first) relax(v,d2);
                }
                done3[v].insert(mp(d % p[v].first,p[u].first));
            }
        }
        done[u] = 1;
    }
    printf("impossible\n");

    return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:51:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first == 1)) pos[i]++;
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:66:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (i = done[u] ? pos[u]:0; 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:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d",&K);
      |     ~~~~~^~~~~~~~~
watchmen.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d",&l);
      |         ~~~~~^~~~~~~~~
watchmen.cpp:41:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i));
      |                                 ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 25232 KB Output is correct
2 Correct 136 ms 32328 KB Output is correct
3 Correct 133 ms 32024 KB Output is correct
4 Correct 123 ms 32328 KB Output is correct
5 Correct 16 ms 24012 KB Output is correct
6 Correct 135 ms 32048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 25284 KB Output is correct
2 Correct 150 ms 32240 KB Output is correct
3 Correct 123 ms 32052 KB Output is correct
4 Correct 131 ms 32344 KB Output is correct
5 Correct 17 ms 23896 KB Output is correct
6 Correct 139 ms 31988 KB Output is correct
7 Correct 114 ms 31684 KB Output is correct
8 Correct 107 ms 31796 KB Output is correct
9 Correct 145 ms 31468 KB Output is correct
10 Correct 147 ms 32112 KB Output is correct
11 Correct 122 ms 31836 KB Output is correct
12 Correct 129 ms 31980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 25284 KB Output is correct
2 Correct 150 ms 32240 KB Output is correct
3 Correct 123 ms 32052 KB Output is correct
4 Correct 131 ms 32344 KB Output is correct
5 Correct 17 ms 23896 KB Output is correct
6 Correct 139 ms 31988 KB Output is correct
7 Correct 114 ms 31684 KB Output is correct
8 Correct 107 ms 31796 KB Output is correct
9 Correct 145 ms 31468 KB Output is correct
10 Correct 147 ms 32112 KB Output is correct
11 Correct 122 ms 31836 KB Output is correct
12 Correct 129 ms 31980 KB Output is correct
13 Correct 45 ms 25296 KB Output is correct
14 Correct 143 ms 32392 KB Output is correct
15 Correct 179 ms 32072 KB Output is correct
16 Correct 132 ms 32388 KB Output is correct
17 Correct 18 ms 23844 KB Output is correct
18 Correct 136 ms 32068 KB Output is correct
19 Correct 161 ms 31556 KB Output is correct
20 Correct 108 ms 31784 KB Output is correct
21 Correct 141 ms 31508 KB Output is correct
22 Correct 147 ms 32028 KB Output is correct
23 Correct 126 ms 31812 KB Output is correct
24 Correct 116 ms 31868 KB Output is correct
25 Correct 2981 ms 77480 KB Output is correct
26 Correct 2980 ms 81784 KB Output is correct
27 Correct 2690 ms 78352 KB Output is correct
28 Correct 2059 ms 81100 KB Output is correct
29 Correct 2700 ms 74672 KB Output is correct
30 Correct 2653 ms 77260 KB Output is correct
31 Correct 2953 ms 82204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 25284 KB Output is correct
2 Correct 150 ms 32240 KB Output is correct
3 Correct 123 ms 32052 KB Output is correct
4 Correct 131 ms 32344 KB Output is correct
5 Correct 17 ms 23896 KB Output is correct
6 Correct 139 ms 31988 KB Output is correct
7 Correct 114 ms 31684 KB Output is correct
8 Correct 107 ms 31796 KB Output is correct
9 Correct 145 ms 31468 KB Output is correct
10 Correct 147 ms 32112 KB Output is correct
11 Correct 122 ms 31836 KB Output is correct
12 Correct 129 ms 31980 KB Output is correct
13 Correct 45 ms 25296 KB Output is correct
14 Correct 143 ms 32392 KB Output is correct
15 Correct 179 ms 32072 KB Output is correct
16 Correct 132 ms 32388 KB Output is correct
17 Correct 18 ms 23844 KB Output is correct
18 Correct 136 ms 32068 KB Output is correct
19 Correct 161 ms 31556 KB Output is correct
20 Correct 108 ms 31784 KB Output is correct
21 Correct 141 ms 31508 KB Output is correct
22 Correct 147 ms 32028 KB Output is correct
23 Correct 126 ms 31812 KB Output is correct
24 Correct 116 ms 31868 KB Output is correct
25 Correct 2981 ms 77480 KB Output is correct
26 Correct 2980 ms 81784 KB Output is correct
27 Correct 2690 ms 78352 KB Output is correct
28 Correct 2059 ms 81100 KB Output is correct
29 Correct 2700 ms 74672 KB Output is correct
30 Correct 2653 ms 77260 KB Output is correct
31 Correct 2953 ms 82204 KB Output is correct
32 Correct 41 ms 25168 KB Output is correct
33 Correct 117 ms 32320 KB Output is correct
34 Correct 133 ms 32036 KB Output is correct
35 Correct 117 ms 32392 KB Output is correct
36 Correct 15 ms 23920 KB Output is correct
37 Correct 127 ms 32068 KB Output is correct
38 Correct 139 ms 31644 KB Output is correct
39 Correct 118 ms 31940 KB Output is correct
40 Correct 123 ms 31548 KB Output is correct
41 Correct 138 ms 32044 KB Output is correct
42 Correct 134 ms 31940 KB Output is correct
43 Correct 122 ms 31844 KB Output is correct
44 Correct 2695 ms 77372 KB Output is correct
45 Correct 2565 ms 81556 KB Output is correct
46 Correct 2670 ms 78256 KB Output is correct
47 Correct 1906 ms 81048 KB Output is correct
48 Correct 2528 ms 74620 KB Output is correct
49 Correct 2687 ms 77300 KB Output is correct
50 Correct 2956 ms 82108 KB Output is correct
51 Correct 3426 ms 94356 KB Output is correct
52 Correct 3437 ms 111016 KB Output is correct
53 Correct 3405 ms 112476 KB Output is correct
54 Correct 1880 ms 73412 KB Output is correct
55 Correct 3930 ms 159000 KB Output is correct
56 Correct 3783 ms 116616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 25232 KB Output is correct
2 Correct 136 ms 32328 KB Output is correct
3 Correct 133 ms 32024 KB Output is correct
4 Correct 123 ms 32328 KB Output is correct
5 Correct 16 ms 24012 KB Output is correct
6 Correct 135 ms 32048 KB Output is correct
7 Correct 46 ms 25284 KB Output is correct
8 Correct 150 ms 32240 KB Output is correct
9 Correct 123 ms 32052 KB Output is correct
10 Correct 131 ms 32344 KB Output is correct
11 Correct 17 ms 23896 KB Output is correct
12 Correct 139 ms 31988 KB Output is correct
13 Correct 114 ms 31684 KB Output is correct
14 Correct 107 ms 31796 KB Output is correct
15 Correct 145 ms 31468 KB Output is correct
16 Correct 147 ms 32112 KB Output is correct
17 Correct 122 ms 31836 KB Output is correct
18 Correct 129 ms 31980 KB Output is correct
19 Correct 16 ms 23772 KB Output is correct
20 Correct 16 ms 23812 KB Output is correct
21 Correct 17 ms 23784 KB Output is correct
22 Correct 44 ms 25152 KB Output is correct
23 Correct 141 ms 32028 KB Output is correct
24 Correct 135 ms 31952 KB Output is correct
25 Correct 139 ms 32204 KB Output is correct
26 Correct 18 ms 23884 KB Output is correct
27 Correct 148 ms 31896 KB Output is correct
28 Correct 155 ms 31464 KB Output is correct
29 Correct 138 ms 31684 KB Output is correct
30 Correct 155 ms 31360 KB Output is correct
31 Correct 166 ms 31888 KB Output is correct
32 Correct 128 ms 31752 KB Output is correct
33 Correct 149 ms 31632 KB Output is correct
34 Correct 3039 ms 78124 KB Output is correct
35 Correct 2996 ms 74492 KB Output is correct
36 Correct 3296 ms 74464 KB Output is correct
37 Correct 2771 ms 79052 KB Output is correct
38 Incorrect 3017 ms 76768 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 25232 KB Output is correct
2 Correct 136 ms 32328 KB Output is correct
3 Correct 133 ms 32024 KB Output is correct
4 Correct 123 ms 32328 KB Output is correct
5 Correct 16 ms 24012 KB Output is correct
6 Correct 135 ms 32048 KB Output is correct
7 Correct 46 ms 25284 KB Output is correct
8 Correct 150 ms 32240 KB Output is correct
9 Correct 123 ms 32052 KB Output is correct
10 Correct 131 ms 32344 KB Output is correct
11 Correct 17 ms 23896 KB Output is correct
12 Correct 139 ms 31988 KB Output is correct
13 Correct 114 ms 31684 KB Output is correct
14 Correct 107 ms 31796 KB Output is correct
15 Correct 145 ms 31468 KB Output is correct
16 Correct 147 ms 32112 KB Output is correct
17 Correct 122 ms 31836 KB Output is correct
18 Correct 129 ms 31980 KB Output is correct
19 Correct 45 ms 25296 KB Output is correct
20 Correct 143 ms 32392 KB Output is correct
21 Correct 179 ms 32072 KB Output is correct
22 Correct 132 ms 32388 KB Output is correct
23 Correct 18 ms 23844 KB Output is correct
24 Correct 136 ms 32068 KB Output is correct
25 Correct 161 ms 31556 KB Output is correct
26 Correct 108 ms 31784 KB Output is correct
27 Correct 141 ms 31508 KB Output is correct
28 Correct 147 ms 32028 KB Output is correct
29 Correct 126 ms 31812 KB Output is correct
30 Correct 116 ms 31868 KB Output is correct
31 Correct 2981 ms 77480 KB Output is correct
32 Correct 2980 ms 81784 KB Output is correct
33 Correct 2690 ms 78352 KB Output is correct
34 Correct 2059 ms 81100 KB Output is correct
35 Correct 2700 ms 74672 KB Output is correct
36 Correct 2653 ms 77260 KB Output is correct
37 Correct 2953 ms 82204 KB Output is correct
38 Correct 16 ms 23772 KB Output is correct
39 Correct 16 ms 23812 KB Output is correct
40 Correct 17 ms 23784 KB Output is correct
41 Correct 44 ms 25152 KB Output is correct
42 Correct 141 ms 32028 KB Output is correct
43 Correct 135 ms 31952 KB Output is correct
44 Correct 139 ms 32204 KB Output is correct
45 Correct 18 ms 23884 KB Output is correct
46 Correct 148 ms 31896 KB Output is correct
47 Correct 155 ms 31464 KB Output is correct
48 Correct 138 ms 31684 KB Output is correct
49 Correct 155 ms 31360 KB Output is correct
50 Correct 166 ms 31888 KB Output is correct
51 Correct 128 ms 31752 KB Output is correct
52 Correct 149 ms 31632 KB Output is correct
53 Correct 3039 ms 78124 KB Output is correct
54 Correct 2996 ms 74492 KB Output is correct
55 Correct 3296 ms 74464 KB Output is correct
56 Correct 2771 ms 79052 KB Output is correct
57 Incorrect 3017 ms 76768 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 25232 KB Output is correct
2 Correct 136 ms 32328 KB Output is correct
3 Correct 133 ms 32024 KB Output is correct
4 Correct 123 ms 32328 KB Output is correct
5 Correct 16 ms 24012 KB Output is correct
6 Correct 135 ms 32048 KB Output is correct
7 Correct 46 ms 25284 KB Output is correct
8 Correct 150 ms 32240 KB Output is correct
9 Correct 123 ms 32052 KB Output is correct
10 Correct 131 ms 32344 KB Output is correct
11 Correct 17 ms 23896 KB Output is correct
12 Correct 139 ms 31988 KB Output is correct
13 Correct 114 ms 31684 KB Output is correct
14 Correct 107 ms 31796 KB Output is correct
15 Correct 145 ms 31468 KB Output is correct
16 Correct 147 ms 32112 KB Output is correct
17 Correct 122 ms 31836 KB Output is correct
18 Correct 129 ms 31980 KB Output is correct
19 Correct 45 ms 25296 KB Output is correct
20 Correct 143 ms 32392 KB Output is correct
21 Correct 179 ms 32072 KB Output is correct
22 Correct 132 ms 32388 KB Output is correct
23 Correct 18 ms 23844 KB Output is correct
24 Correct 136 ms 32068 KB Output is correct
25 Correct 161 ms 31556 KB Output is correct
26 Correct 108 ms 31784 KB Output is correct
27 Correct 141 ms 31508 KB Output is correct
28 Correct 147 ms 32028 KB Output is correct
29 Correct 126 ms 31812 KB Output is correct
30 Correct 116 ms 31868 KB Output is correct
31 Correct 2981 ms 77480 KB Output is correct
32 Correct 2980 ms 81784 KB Output is correct
33 Correct 2690 ms 78352 KB Output is correct
34 Correct 2059 ms 81100 KB Output is correct
35 Correct 2700 ms 74672 KB Output is correct
36 Correct 2653 ms 77260 KB Output is correct
37 Correct 2953 ms 82204 KB Output is correct
38 Correct 41 ms 25168 KB Output is correct
39 Correct 117 ms 32320 KB Output is correct
40 Correct 133 ms 32036 KB Output is correct
41 Correct 117 ms 32392 KB Output is correct
42 Correct 15 ms 23920 KB Output is correct
43 Correct 127 ms 32068 KB Output is correct
44 Correct 139 ms 31644 KB Output is correct
45 Correct 118 ms 31940 KB Output is correct
46 Correct 123 ms 31548 KB Output is correct
47 Correct 138 ms 32044 KB Output is correct
48 Correct 134 ms 31940 KB Output is correct
49 Correct 122 ms 31844 KB Output is correct
50 Correct 2695 ms 77372 KB Output is correct
51 Correct 2565 ms 81556 KB Output is correct
52 Correct 2670 ms 78256 KB Output is correct
53 Correct 1906 ms 81048 KB Output is correct
54 Correct 2528 ms 74620 KB Output is correct
55 Correct 2687 ms 77300 KB Output is correct
56 Correct 2956 ms 82108 KB Output is correct
57 Correct 3426 ms 94356 KB Output is correct
58 Correct 3437 ms 111016 KB Output is correct
59 Correct 3405 ms 112476 KB Output is correct
60 Correct 1880 ms 73412 KB Output is correct
61 Correct 3930 ms 159000 KB Output is correct
62 Correct 3783 ms 116616 KB Output is correct
63 Correct 16 ms 23772 KB Output is correct
64 Correct 16 ms 23812 KB Output is correct
65 Correct 17 ms 23784 KB Output is correct
66 Correct 44 ms 25152 KB Output is correct
67 Correct 141 ms 32028 KB Output is correct
68 Correct 135 ms 31952 KB Output is correct
69 Correct 139 ms 32204 KB Output is correct
70 Correct 18 ms 23884 KB Output is correct
71 Correct 148 ms 31896 KB Output is correct
72 Correct 155 ms 31464 KB Output is correct
73 Correct 138 ms 31684 KB Output is correct
74 Correct 155 ms 31360 KB Output is correct
75 Correct 166 ms 31888 KB Output is correct
76 Correct 128 ms 31752 KB Output is correct
77 Correct 149 ms 31632 KB Output is correct
78 Correct 3039 ms 78124 KB Output is correct
79 Correct 2996 ms 74492 KB Output is correct
80 Correct 3296 ms 74464 KB Output is correct
81 Correct 2771 ms 79052 KB Output is correct
82 Incorrect 3017 ms 76768 KB Output isn't correct
83 Halted 0 ms 0 KB -