Submission #426385

# Submission time Handle Problem Language Result Execution time Memory
426385 2021-06-13T22:17:38 Z duality From Hacks to Snitches (BOI21_watchmen) C++11
25 / 100
6000 ms 160652 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<int> 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);
        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(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(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:65:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         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 43 ms 25152 KB Output is correct
2 Correct 139 ms 32812 KB Output is correct
3 Correct 158 ms 32584 KB Output is correct
4 Correct 214 ms 32968 KB Output is correct
5 Correct 18 ms 23916 KB Output is correct
6 Correct 129 ms 32580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 25156 KB Output is correct
2 Correct 139 ms 32800 KB Output is correct
3 Correct 143 ms 32604 KB Output is correct
4 Correct 161 ms 32968 KB Output is correct
5 Correct 19 ms 23876 KB Output is correct
6 Correct 140 ms 32608 KB Output is correct
7 Correct 109 ms 32084 KB Output is correct
8 Correct 124 ms 32376 KB Output is correct
9 Correct 137 ms 32076 KB Output is correct
10 Correct 134 ms 32588 KB Output is correct
11 Correct 127 ms 32388 KB Output is correct
12 Correct 121 ms 32428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 25156 KB Output is correct
2 Correct 139 ms 32800 KB Output is correct
3 Correct 143 ms 32604 KB Output is correct
4 Correct 161 ms 32968 KB Output is correct
5 Correct 19 ms 23876 KB Output is correct
6 Correct 140 ms 32608 KB Output is correct
7 Correct 109 ms 32084 KB Output is correct
8 Correct 124 ms 32376 KB Output is correct
9 Correct 137 ms 32076 KB Output is correct
10 Correct 134 ms 32588 KB Output is correct
11 Correct 127 ms 32388 KB Output is correct
12 Correct 121 ms 32428 KB Output is correct
13 Correct 49 ms 25332 KB Output is correct
14 Correct 180 ms 32756 KB Output is correct
15 Correct 121 ms 32552 KB Output is correct
16 Correct 169 ms 32908 KB Output is correct
17 Correct 21 ms 23884 KB Output is correct
18 Correct 164 ms 32644 KB Output is correct
19 Correct 124 ms 32188 KB Output is correct
20 Correct 120 ms 32324 KB Output is correct
21 Correct 136 ms 32016 KB Output is correct
22 Correct 161 ms 32616 KB Output is correct
23 Correct 120 ms 32448 KB Output is correct
24 Correct 125 ms 32340 KB Output is correct
25 Correct 2796 ms 88244 KB Output is correct
26 Correct 2969 ms 92524 KB Output is correct
27 Correct 2655 ms 89264 KB Output is correct
28 Correct 2080 ms 92376 KB Output is correct
29 Correct 2804 ms 85796 KB Output is correct
30 Correct 2921 ms 78312 KB Output is correct
31 Correct 2927 ms 83080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 25156 KB Output is correct
2 Correct 139 ms 32800 KB Output is correct
3 Correct 143 ms 32604 KB Output is correct
4 Correct 161 ms 32968 KB Output is correct
5 Correct 19 ms 23876 KB Output is correct
6 Correct 140 ms 32608 KB Output is correct
7 Correct 109 ms 32084 KB Output is correct
8 Correct 124 ms 32376 KB Output is correct
9 Correct 137 ms 32076 KB Output is correct
10 Correct 134 ms 32588 KB Output is correct
11 Correct 127 ms 32388 KB Output is correct
12 Correct 121 ms 32428 KB Output is correct
13 Correct 49 ms 25332 KB Output is correct
14 Correct 180 ms 32756 KB Output is correct
15 Correct 121 ms 32552 KB Output is correct
16 Correct 169 ms 32908 KB Output is correct
17 Correct 21 ms 23884 KB Output is correct
18 Correct 164 ms 32644 KB Output is correct
19 Correct 124 ms 32188 KB Output is correct
20 Correct 120 ms 32324 KB Output is correct
21 Correct 136 ms 32016 KB Output is correct
22 Correct 161 ms 32616 KB Output is correct
23 Correct 120 ms 32448 KB Output is correct
24 Correct 125 ms 32340 KB Output is correct
25 Correct 2796 ms 88244 KB Output is correct
26 Correct 2969 ms 92524 KB Output is correct
27 Correct 2655 ms 89264 KB Output is correct
28 Correct 2080 ms 92376 KB Output is correct
29 Correct 2804 ms 85796 KB Output is correct
30 Correct 2921 ms 78312 KB Output is correct
31 Correct 2927 ms 83080 KB Output is correct
32 Correct 43 ms 25408 KB Output is correct
33 Correct 140 ms 32880 KB Output is correct
34 Correct 121 ms 32692 KB Output is correct
35 Correct 173 ms 33096 KB Output is correct
36 Correct 18 ms 23840 KB Output is correct
37 Correct 120 ms 32748 KB Output is correct
38 Correct 133 ms 32208 KB Output is correct
39 Correct 156 ms 32532 KB Output is correct
40 Correct 137 ms 32220 KB Output is correct
41 Correct 138 ms 32712 KB Output is correct
42 Correct 139 ms 32580 KB Output is correct
43 Correct 127 ms 32548 KB Output is correct
44 Correct 2924 ms 78408 KB Output is correct
45 Correct 2786 ms 82696 KB Output is correct
46 Correct 2670 ms 79332 KB Output is correct
47 Correct 2124 ms 82204 KB Output is correct
48 Correct 2778 ms 75704 KB Output is correct
49 Correct 2870 ms 78656 KB Output is correct
50 Correct 3079 ms 83344 KB Output is correct
51 Correct 3728 ms 95628 KB Output is correct
52 Correct 4279 ms 112644 KB Output is correct
53 Correct 3946 ms 114216 KB Output is correct
54 Correct 2053 ms 74776 KB Output is correct
55 Execution timed out 6050 ms 160652 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 25152 KB Output is correct
2 Correct 139 ms 32812 KB Output is correct
3 Correct 158 ms 32584 KB Output is correct
4 Correct 214 ms 32968 KB Output is correct
5 Correct 18 ms 23916 KB Output is correct
6 Correct 129 ms 32580 KB Output is correct
7 Correct 49 ms 25156 KB Output is correct
8 Correct 139 ms 32800 KB Output is correct
9 Correct 143 ms 32604 KB Output is correct
10 Correct 161 ms 32968 KB Output is correct
11 Correct 19 ms 23876 KB Output is correct
12 Correct 140 ms 32608 KB Output is correct
13 Correct 109 ms 32084 KB Output is correct
14 Correct 124 ms 32376 KB Output is correct
15 Correct 137 ms 32076 KB Output is correct
16 Correct 134 ms 32588 KB Output is correct
17 Correct 127 ms 32388 KB Output is correct
18 Correct 121 ms 32428 KB Output is correct
19 Correct 17 ms 23756 KB Output is correct
20 Correct 18 ms 23796 KB Output is correct
21 Correct 17 ms 23756 KB Output is correct
22 Correct 48 ms 25736 KB Output is correct
23 Correct 138 ms 33284 KB Output is correct
24 Correct 124 ms 33096 KB Output is correct
25 Correct 169 ms 33440 KB Output is correct
26 Correct 18 ms 23884 KB Output is correct
27 Correct 123 ms 33092 KB Output is correct
28 Correct 134 ms 32612 KB Output is correct
29 Correct 122 ms 32820 KB Output is correct
30 Correct 119 ms 32528 KB Output is correct
31 Correct 138 ms 32976 KB Output is correct
32 Correct 187 ms 32920 KB Output is correct
33 Correct 128 ms 32964 KB Output is correct
34 Correct 3127 ms 90924 KB Output is correct
35 Correct 3095 ms 87284 KB Output is correct
36 Correct 3067 ms 87516 KB Output is correct
37 Incorrect 2630 ms 91636 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 25152 KB Output is correct
2 Correct 139 ms 32812 KB Output is correct
3 Correct 158 ms 32584 KB Output is correct
4 Correct 214 ms 32968 KB Output is correct
5 Correct 18 ms 23916 KB Output is correct
6 Correct 129 ms 32580 KB Output is correct
7 Correct 49 ms 25156 KB Output is correct
8 Correct 139 ms 32800 KB Output is correct
9 Correct 143 ms 32604 KB Output is correct
10 Correct 161 ms 32968 KB Output is correct
11 Correct 19 ms 23876 KB Output is correct
12 Correct 140 ms 32608 KB Output is correct
13 Correct 109 ms 32084 KB Output is correct
14 Correct 124 ms 32376 KB Output is correct
15 Correct 137 ms 32076 KB Output is correct
16 Correct 134 ms 32588 KB Output is correct
17 Correct 127 ms 32388 KB Output is correct
18 Correct 121 ms 32428 KB Output is correct
19 Correct 49 ms 25332 KB Output is correct
20 Correct 180 ms 32756 KB Output is correct
21 Correct 121 ms 32552 KB Output is correct
22 Correct 169 ms 32908 KB Output is correct
23 Correct 21 ms 23884 KB Output is correct
24 Correct 164 ms 32644 KB Output is correct
25 Correct 124 ms 32188 KB Output is correct
26 Correct 120 ms 32324 KB Output is correct
27 Correct 136 ms 32016 KB Output is correct
28 Correct 161 ms 32616 KB Output is correct
29 Correct 120 ms 32448 KB Output is correct
30 Correct 125 ms 32340 KB Output is correct
31 Correct 2796 ms 88244 KB Output is correct
32 Correct 2969 ms 92524 KB Output is correct
33 Correct 2655 ms 89264 KB Output is correct
34 Correct 2080 ms 92376 KB Output is correct
35 Correct 2804 ms 85796 KB Output is correct
36 Correct 2921 ms 78312 KB Output is correct
37 Correct 2927 ms 83080 KB Output is correct
38 Correct 17 ms 23756 KB Output is correct
39 Correct 18 ms 23796 KB Output is correct
40 Correct 17 ms 23756 KB Output is correct
41 Correct 48 ms 25736 KB Output is correct
42 Correct 138 ms 33284 KB Output is correct
43 Correct 124 ms 33096 KB Output is correct
44 Correct 169 ms 33440 KB Output is correct
45 Correct 18 ms 23884 KB Output is correct
46 Correct 123 ms 33092 KB Output is correct
47 Correct 134 ms 32612 KB Output is correct
48 Correct 122 ms 32820 KB Output is correct
49 Correct 119 ms 32528 KB Output is correct
50 Correct 138 ms 32976 KB Output is correct
51 Correct 187 ms 32920 KB Output is correct
52 Correct 128 ms 32964 KB Output is correct
53 Correct 3127 ms 90924 KB Output is correct
54 Correct 3095 ms 87284 KB Output is correct
55 Correct 3067 ms 87516 KB Output is correct
56 Incorrect 2630 ms 91636 KB Output isn't correct
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 25152 KB Output is correct
2 Correct 139 ms 32812 KB Output is correct
3 Correct 158 ms 32584 KB Output is correct
4 Correct 214 ms 32968 KB Output is correct
5 Correct 18 ms 23916 KB Output is correct
6 Correct 129 ms 32580 KB Output is correct
7 Correct 49 ms 25156 KB Output is correct
8 Correct 139 ms 32800 KB Output is correct
9 Correct 143 ms 32604 KB Output is correct
10 Correct 161 ms 32968 KB Output is correct
11 Correct 19 ms 23876 KB Output is correct
12 Correct 140 ms 32608 KB Output is correct
13 Correct 109 ms 32084 KB Output is correct
14 Correct 124 ms 32376 KB Output is correct
15 Correct 137 ms 32076 KB Output is correct
16 Correct 134 ms 32588 KB Output is correct
17 Correct 127 ms 32388 KB Output is correct
18 Correct 121 ms 32428 KB Output is correct
19 Correct 49 ms 25332 KB Output is correct
20 Correct 180 ms 32756 KB Output is correct
21 Correct 121 ms 32552 KB Output is correct
22 Correct 169 ms 32908 KB Output is correct
23 Correct 21 ms 23884 KB Output is correct
24 Correct 164 ms 32644 KB Output is correct
25 Correct 124 ms 32188 KB Output is correct
26 Correct 120 ms 32324 KB Output is correct
27 Correct 136 ms 32016 KB Output is correct
28 Correct 161 ms 32616 KB Output is correct
29 Correct 120 ms 32448 KB Output is correct
30 Correct 125 ms 32340 KB Output is correct
31 Correct 2796 ms 88244 KB Output is correct
32 Correct 2969 ms 92524 KB Output is correct
33 Correct 2655 ms 89264 KB Output is correct
34 Correct 2080 ms 92376 KB Output is correct
35 Correct 2804 ms 85796 KB Output is correct
36 Correct 2921 ms 78312 KB Output is correct
37 Correct 2927 ms 83080 KB Output is correct
38 Correct 43 ms 25408 KB Output is correct
39 Correct 140 ms 32880 KB Output is correct
40 Correct 121 ms 32692 KB Output is correct
41 Correct 173 ms 33096 KB Output is correct
42 Correct 18 ms 23840 KB Output is correct
43 Correct 120 ms 32748 KB Output is correct
44 Correct 133 ms 32208 KB Output is correct
45 Correct 156 ms 32532 KB Output is correct
46 Correct 137 ms 32220 KB Output is correct
47 Correct 138 ms 32712 KB Output is correct
48 Correct 139 ms 32580 KB Output is correct
49 Correct 127 ms 32548 KB Output is correct
50 Correct 2924 ms 78408 KB Output is correct
51 Correct 2786 ms 82696 KB Output is correct
52 Correct 2670 ms 79332 KB Output is correct
53 Correct 2124 ms 82204 KB Output is correct
54 Correct 2778 ms 75704 KB Output is correct
55 Correct 2870 ms 78656 KB Output is correct
56 Correct 3079 ms 83344 KB Output is correct
57 Correct 3728 ms 95628 KB Output is correct
58 Correct 4279 ms 112644 KB Output is correct
59 Correct 3946 ms 114216 KB Output is correct
60 Correct 2053 ms 74776 KB Output is correct
61 Execution timed out 6050 ms 160652 KB Time limit exceeded
62 Halted 0 ms 0 KB -