답안 #426054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426054 2021-06-13T13:21:09 Z duality From Hacks to Snitches (BOI21_watchmen) C++11
15 / 100
6000 ms 68908 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];
priority_queue<pii> H;
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]++;
    }
    dist[0][0] = 0,H.push(mp(0,0));
    while (!H.empty()) {
        int u = H.top().second;
        int d = -H.top().first;
        H.pop();

        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 = 0; i < adjList[u].size(); i++) {
            int v = adjList[u][i],t = d;
            for (j = 0; j < ((p[u].first == 1) ? p[v].first:1); 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;
                        H.push(mp(-(d+1),v));
                    }
                }
                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;
        }
        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:65:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (i = 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: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 22 ms 13124 KB Output is correct
2 Correct 115 ms 20304 KB Output is correct
3 Correct 127 ms 20776 KB Output is correct
4 Correct 165 ms 20888 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 123 ms 20764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 13132 KB Output is correct
2 Correct 136 ms 20232 KB Output is correct
3 Correct 96 ms 20776 KB Output is correct
4 Correct 131 ms 21072 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 82 ms 20676 KB Output is correct
7 Correct 133 ms 20276 KB Output is correct
8 Correct 82 ms 20500 KB Output is correct
9 Correct 75 ms 20292 KB Output is correct
10 Correct 107 ms 20752 KB Output is correct
11 Correct 110 ms 20556 KB Output is correct
12 Correct 105 ms 20616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 13132 KB Output is correct
2 Correct 136 ms 20232 KB Output is correct
3 Correct 96 ms 20776 KB Output is correct
4 Correct 131 ms 21072 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 82 ms 20676 KB Output is correct
7 Correct 133 ms 20276 KB Output is correct
8 Correct 82 ms 20500 KB Output is correct
9 Correct 75 ms 20292 KB Output is correct
10 Correct 107 ms 20752 KB Output is correct
11 Correct 110 ms 20556 KB Output is correct
12 Correct 105 ms 20616 KB Output is correct
13 Correct 26 ms 13772 KB Output is correct
14 Correct 97 ms 21092 KB Output is correct
15 Correct 126 ms 20732 KB Output is correct
16 Correct 161 ms 21104 KB Output is correct
17 Correct 9 ms 12108 KB Output is correct
18 Correct 86 ms 20736 KB Output is correct
19 Correct 105 ms 20288 KB Output is correct
20 Correct 103 ms 20496 KB Output is correct
21 Correct 126 ms 20376 KB Output is correct
22 Correct 141 ms 20760 KB Output is correct
23 Correct 106 ms 20708 KB Output is correct
24 Correct 117 ms 20600 KB Output is correct
25 Correct 2530 ms 64876 KB Output is correct
26 Correct 2438 ms 68908 KB Output is correct
27 Correct 2300 ms 65632 KB Output is correct
28 Correct 1748 ms 68904 KB Output is correct
29 Execution timed out 6029 ms 60592 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 13132 KB Output is correct
2 Correct 136 ms 20232 KB Output is correct
3 Correct 96 ms 20776 KB Output is correct
4 Correct 131 ms 21072 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 82 ms 20676 KB Output is correct
7 Correct 133 ms 20276 KB Output is correct
8 Correct 82 ms 20500 KB Output is correct
9 Correct 75 ms 20292 KB Output is correct
10 Correct 107 ms 20752 KB Output is correct
11 Correct 110 ms 20556 KB Output is correct
12 Correct 105 ms 20616 KB Output is correct
13 Correct 26 ms 13772 KB Output is correct
14 Correct 97 ms 21092 KB Output is correct
15 Correct 126 ms 20732 KB Output is correct
16 Correct 161 ms 21104 KB Output is correct
17 Correct 9 ms 12108 KB Output is correct
18 Correct 86 ms 20736 KB Output is correct
19 Correct 105 ms 20288 KB Output is correct
20 Correct 103 ms 20496 KB Output is correct
21 Correct 126 ms 20376 KB Output is correct
22 Correct 141 ms 20760 KB Output is correct
23 Correct 106 ms 20708 KB Output is correct
24 Correct 117 ms 20600 KB Output is correct
25 Correct 2530 ms 64876 KB Output is correct
26 Correct 2438 ms 68908 KB Output is correct
27 Correct 2300 ms 65632 KB Output is correct
28 Correct 1748 ms 68904 KB Output is correct
29 Execution timed out 6029 ms 60592 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 13124 KB Output is correct
2 Correct 115 ms 20304 KB Output is correct
3 Correct 127 ms 20776 KB Output is correct
4 Correct 165 ms 20888 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 123 ms 20764 KB Output is correct
7 Correct 29 ms 13132 KB Output is correct
8 Correct 136 ms 20232 KB Output is correct
9 Correct 96 ms 20776 KB Output is correct
10 Correct 131 ms 21072 KB Output is correct
11 Correct 8 ms 12108 KB Output is correct
12 Correct 82 ms 20676 KB Output is correct
13 Correct 133 ms 20276 KB Output is correct
14 Correct 82 ms 20500 KB Output is correct
15 Correct 75 ms 20292 KB Output is correct
16 Correct 107 ms 20752 KB Output is correct
17 Correct 110 ms 20556 KB Output is correct
18 Correct 105 ms 20616 KB Output is correct
19 Correct 9 ms 12016 KB Output is correct
20 Correct 9 ms 12048 KB Output is correct
21 Correct 9 ms 12052 KB Output is correct
22 Correct 26 ms 13808 KB Output is correct
23 Correct 100 ms 21292 KB Output is correct
24 Correct 133 ms 20992 KB Output is correct
25 Correct 178 ms 21152 KB Output is correct
26 Correct 11 ms 12108 KB Output is correct
27 Correct 120 ms 20996 KB Output is correct
28 Correct 102 ms 20584 KB Output is correct
29 Correct 98 ms 20772 KB Output is correct
30 Correct 116 ms 20500 KB Output is correct
31 Correct 118 ms 20984 KB Output is correct
32 Correct 112 ms 20912 KB Output is correct
33 Correct 97 ms 20804 KB Output is correct
34 Correct 2827 ms 65608 KB Output is correct
35 Correct 2745 ms 61848 KB Output is correct
36 Correct 2406 ms 61880 KB Output is correct
37 Incorrect 2068 ms 67244 KB Output isn't correct
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 13124 KB Output is correct
2 Correct 115 ms 20304 KB Output is correct
3 Correct 127 ms 20776 KB Output is correct
4 Correct 165 ms 20888 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 123 ms 20764 KB Output is correct
7 Correct 29 ms 13132 KB Output is correct
8 Correct 136 ms 20232 KB Output is correct
9 Correct 96 ms 20776 KB Output is correct
10 Correct 131 ms 21072 KB Output is correct
11 Correct 8 ms 12108 KB Output is correct
12 Correct 82 ms 20676 KB Output is correct
13 Correct 133 ms 20276 KB Output is correct
14 Correct 82 ms 20500 KB Output is correct
15 Correct 75 ms 20292 KB Output is correct
16 Correct 107 ms 20752 KB Output is correct
17 Correct 110 ms 20556 KB Output is correct
18 Correct 105 ms 20616 KB Output is correct
19 Correct 26 ms 13772 KB Output is correct
20 Correct 97 ms 21092 KB Output is correct
21 Correct 126 ms 20732 KB Output is correct
22 Correct 161 ms 21104 KB Output is correct
23 Correct 9 ms 12108 KB Output is correct
24 Correct 86 ms 20736 KB Output is correct
25 Correct 105 ms 20288 KB Output is correct
26 Correct 103 ms 20496 KB Output is correct
27 Correct 126 ms 20376 KB Output is correct
28 Correct 141 ms 20760 KB Output is correct
29 Correct 106 ms 20708 KB Output is correct
30 Correct 117 ms 20600 KB Output is correct
31 Correct 2530 ms 64876 KB Output is correct
32 Correct 2438 ms 68908 KB Output is correct
33 Correct 2300 ms 65632 KB Output is correct
34 Correct 1748 ms 68904 KB Output is correct
35 Execution timed out 6029 ms 60592 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 13124 KB Output is correct
2 Correct 115 ms 20304 KB Output is correct
3 Correct 127 ms 20776 KB Output is correct
4 Correct 165 ms 20888 KB Output is correct
5 Correct 8 ms 12108 KB Output is correct
6 Correct 123 ms 20764 KB Output is correct
7 Correct 29 ms 13132 KB Output is correct
8 Correct 136 ms 20232 KB Output is correct
9 Correct 96 ms 20776 KB Output is correct
10 Correct 131 ms 21072 KB Output is correct
11 Correct 8 ms 12108 KB Output is correct
12 Correct 82 ms 20676 KB Output is correct
13 Correct 133 ms 20276 KB Output is correct
14 Correct 82 ms 20500 KB Output is correct
15 Correct 75 ms 20292 KB Output is correct
16 Correct 107 ms 20752 KB Output is correct
17 Correct 110 ms 20556 KB Output is correct
18 Correct 105 ms 20616 KB Output is correct
19 Correct 26 ms 13772 KB Output is correct
20 Correct 97 ms 21092 KB Output is correct
21 Correct 126 ms 20732 KB Output is correct
22 Correct 161 ms 21104 KB Output is correct
23 Correct 9 ms 12108 KB Output is correct
24 Correct 86 ms 20736 KB Output is correct
25 Correct 105 ms 20288 KB Output is correct
26 Correct 103 ms 20496 KB Output is correct
27 Correct 126 ms 20376 KB Output is correct
28 Correct 141 ms 20760 KB Output is correct
29 Correct 106 ms 20708 KB Output is correct
30 Correct 117 ms 20600 KB Output is correct
31 Correct 2530 ms 64876 KB Output is correct
32 Correct 2438 ms 68908 KB Output is correct
33 Correct 2300 ms 65632 KB Output is correct
34 Correct 1748 ms 68904 KB Output is correct
35 Execution timed out 6029 ms 60592 KB Time limit exceeded
36 Halted 0 ms 0 KB -