답안 #408770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408770 2021-05-19T15:40:52 Z ly20 From Hacks to Snitches (BOI21_watchmen) C++17
15 / 100
6000 ms 211736 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 251234;
const long long INF = 1123456789012345678;
vector <int> gf[MAXN], grafo[MAXN];
int id;
map <pair <int, int>, int> mp;
long long dist[MAXN];
vector <int> cic[MAXN];
int inv[MAXN];
vector <pair <int, int> > nodes;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    int k;
    for(int i = 1; i <= n; i++) {
        inv[i] = -1;
    }
    for(int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        gf[a].push_back(b); gf[b].push_back(a);
    }
    scanf("%d", &k);
    for(int i = 0; i < k; i++) {
        int t;
        scanf("%d", &t);
        for(int j = 0; j < t; j++) {
            int a;
            scanf("%d", &a);
            inv[a] = i;
            cic[i].push_back(a);
            //printf("oi\n");
        }
    }
    for(int i = 1; i <= n; i++) {
        if(inv[i] == -1) {
            mp[make_pair(i, 0)] = id++;
            nodes.push_back(make_pair(i, 0));
        }
        else {
            int c = inv[i];
            for(int j = 0; j < cic[c].size(); j++) {
                mp[make_pair(i, j)] = id++;
                nodes.push_back(make_pair(i, j));
            }
        }
    }
    //printf("%d\n", nodes.size());
    for(int i = 0; i < nodes.size(); i++) {
        dist[i] = INF;
        pair <int, int> cur = nodes[i];
        //printf("%d %d %d %d\n", i, cur.first, cur.second, inv[cur.first]);
        if(inv[cur.first] == -1) {
            for(int j = 0; j < gf[cur.first].size(); j++) {
                int viz = gf[cur.first][j];
                if(inv[viz] != -1) continue;
                int vzn = mp[make_pair(viz, 0)];
                grafo[i].push_back(vzn);
            }
        }
        else {
                //printf("oi\n");
            if(cic[inv[cur.first]][cur.second] == cur.first) continue;
        //printf("oi2\n");
            for(int j = 0; j < gf[cur.first].size(); j++) {
                int viz = gf[cur.first][j];
            //printf("%d\n", viz);
                if(inv[viz] == -1) {
                    int vzn = mp[make_pair(viz, 0)];
                    grafo[i].push_back(vzn);
                    grafo[vzn].push_back(i);
                }
                else {
                    int pr = (cur.second + 1) % (cic[inv[cur.first]].size());
                    //printf("oi\n");
                    if(cic[inv[viz]][pr] == viz || (cic[inv[viz]][pr] == cur.first && cic[inv[viz]][cur.second] == viz)) continue;
                    //printf("%d %d\n", viz, pr);
                    int vzn = mp[make_pair(viz, pr)];
                    grafo[i].push_back(vzn);
                    //grafo[vzn].push_back(i);
                }
            }
        }
    }
    dist[0] = 0;
    set <pair <long long, int> > s;
    for(int i = 0; i < nodes.size(); i++) {
        s.insert(make_pair(dist[i], i));
    }
    while(!s.empty()) {
        int cur = (*s.begin()).second;
        s.erase(s.begin());
        //int cz = nodes[cur].first;
        for(int i = 0; i < grafo[cur].size(); i++) {
            int viz = grafo[cur][i];
            int vz = nodes[viz].first, md = nodes[viz].second;
            long long d1 = dist[cur] + 1;
            int tam;
            if(inv[vz] != -1) {
                tam = cic[inv[vz]].size();
                if(md != d1 % tam) {
                    if(d1 % tam <= md)d1 = d1 + (md - d1 % tam);
                    else d1 = d1 + (md - d1 % tam + tam);
                }
            }
            if(d1 < dist[viz]) {
                s.erase(make_pair(dist[viz], viz));
                dist[viz] = d1;
                s.insert(make_pair(dist[viz], viz));
            }
        }
    }
    /*for(int i = 0; i < nodes.size(); i++) {
        printf("%d %d %lld\n", nodes[i].first, nodes[i].second, dist[i]);
    }*/
    if(dist[id - 1] < INF) printf("%lld\n", dist[id - 1]);
    else printf("impossible\n");
    return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:43:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for(int j = 0; j < cic[c].size(); j++) {
      |                            ~~^~~~~~~~~~~~~~~
watchmen.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < nodes.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
watchmen.cpp:55:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int j = 0; j < gf[cur.first].size(); j++) {
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~
watchmen.cpp:66:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for(int j = 0; j < gf[cur.first].size(); j++) {
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~
watchmen.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i = 0; i < nodes.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
watchmen.cpp:95:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(int i = 0; i < grafo[cur].size(); i++) {
      |                        ~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
watchmen.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
watchmen.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~
watchmen.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |             scanf("%d", &a);
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1139 ms 70640 KB Output is correct
2 Correct 363 ms 42552 KB Output is correct
3 Correct 321 ms 40524 KB Output is correct
4 Correct 1010 ms 57048 KB Output is correct
5 Correct 29 ms 20620 KB Output is correct
6 Correct 318 ms 40624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1131 ms 70500 KB Output is correct
2 Correct 343 ms 42460 KB Output is correct
3 Correct 308 ms 40480 KB Output is correct
4 Correct 1006 ms 56972 KB Output is correct
5 Correct 29 ms 20556 KB Output is correct
6 Correct 320 ms 40504 KB Output is correct
7 Correct 306 ms 38984 KB Output is correct
8 Correct 290 ms 38688 KB Output is correct
9 Correct 268 ms 38244 KB Output is correct
10 Correct 543 ms 44200 KB Output is correct
11 Correct 340 ms 40052 KB Output is correct
12 Correct 300 ms 39132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1131 ms 70500 KB Output is correct
2 Correct 343 ms 42460 KB Output is correct
3 Correct 308 ms 40480 KB Output is correct
4 Correct 1006 ms 56972 KB Output is correct
5 Correct 29 ms 20556 KB Output is correct
6 Correct 320 ms 40504 KB Output is correct
7 Correct 306 ms 38984 KB Output is correct
8 Correct 290 ms 38688 KB Output is correct
9 Correct 268 ms 38244 KB Output is correct
10 Correct 543 ms 44200 KB Output is correct
11 Correct 340 ms 40052 KB Output is correct
12 Correct 300 ms 39132 KB Output is correct
13 Correct 1134 ms 70668 KB Output is correct
14 Correct 345 ms 42556 KB Output is correct
15 Correct 325 ms 40580 KB Output is correct
16 Correct 990 ms 57132 KB Output is correct
17 Correct 29 ms 20556 KB Output is correct
18 Correct 315 ms 40448 KB Output is correct
19 Correct 294 ms 39096 KB Output is correct
20 Correct 281 ms 38724 KB Output is correct
21 Correct 310 ms 38368 KB Output is correct
22 Correct 568 ms 44108 KB Output is correct
23 Correct 343 ms 40060 KB Output is correct
24 Correct 287 ms 39108 KB Output is correct
25 Runtime error 4262 ms 211736 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1131 ms 70500 KB Output is correct
2 Correct 343 ms 42460 KB Output is correct
3 Correct 308 ms 40480 KB Output is correct
4 Correct 1006 ms 56972 KB Output is correct
5 Correct 29 ms 20556 KB Output is correct
6 Correct 320 ms 40504 KB Output is correct
7 Correct 306 ms 38984 KB Output is correct
8 Correct 290 ms 38688 KB Output is correct
9 Correct 268 ms 38244 KB Output is correct
10 Correct 543 ms 44200 KB Output is correct
11 Correct 340 ms 40052 KB Output is correct
12 Correct 300 ms 39132 KB Output is correct
13 Correct 1134 ms 70668 KB Output is correct
14 Correct 345 ms 42556 KB Output is correct
15 Correct 325 ms 40580 KB Output is correct
16 Correct 990 ms 57132 KB Output is correct
17 Correct 29 ms 20556 KB Output is correct
18 Correct 315 ms 40448 KB Output is correct
19 Correct 294 ms 39096 KB Output is correct
20 Correct 281 ms 38724 KB Output is correct
21 Correct 310 ms 38368 KB Output is correct
22 Correct 568 ms 44108 KB Output is correct
23 Correct 343 ms 40060 KB Output is correct
24 Correct 287 ms 39108 KB Output is correct
25 Runtime error 4262 ms 211736 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1139 ms 70640 KB Output is correct
2 Correct 363 ms 42552 KB Output is correct
3 Correct 321 ms 40524 KB Output is correct
4 Correct 1010 ms 57048 KB Output is correct
5 Correct 29 ms 20620 KB Output is correct
6 Correct 318 ms 40624 KB Output is correct
7 Correct 1131 ms 70500 KB Output is correct
8 Correct 343 ms 42460 KB Output is correct
9 Correct 308 ms 40480 KB Output is correct
10 Correct 1006 ms 56972 KB Output is correct
11 Correct 29 ms 20556 KB Output is correct
12 Correct 320 ms 40504 KB Output is correct
13 Correct 306 ms 38984 KB Output is correct
14 Correct 290 ms 38688 KB Output is correct
15 Correct 268 ms 38244 KB Output is correct
16 Correct 543 ms 44200 KB Output is correct
17 Correct 340 ms 40052 KB Output is correct
18 Correct 300 ms 39132 KB Output is correct
19 Correct 10 ms 17980 KB Output is correct
20 Correct 10 ms 18004 KB Output is correct
21 Correct 11 ms 17976 KB Output is correct
22 Correct 1154 ms 70532 KB Output is correct
23 Correct 351 ms 42548 KB Output is correct
24 Correct 315 ms 40536 KB Output is correct
25 Correct 1006 ms 56980 KB Output is correct
26 Correct 31 ms 20552 KB Output is correct
27 Correct 349 ms 40468 KB Output is correct
28 Correct 286 ms 39096 KB Output is correct
29 Correct 294 ms 38812 KB Output is correct
30 Correct 289 ms 38312 KB Output is correct
31 Correct 562 ms 44184 KB Output is correct
32 Correct 357 ms 40120 KB Output is correct
33 Correct 309 ms 39180 KB Output is correct
34 Execution timed out 6098 ms 125712 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1139 ms 70640 KB Output is correct
2 Correct 363 ms 42552 KB Output is correct
3 Correct 321 ms 40524 KB Output is correct
4 Correct 1010 ms 57048 KB Output is correct
5 Correct 29 ms 20620 KB Output is correct
6 Correct 318 ms 40624 KB Output is correct
7 Correct 1131 ms 70500 KB Output is correct
8 Correct 343 ms 42460 KB Output is correct
9 Correct 308 ms 40480 KB Output is correct
10 Correct 1006 ms 56972 KB Output is correct
11 Correct 29 ms 20556 KB Output is correct
12 Correct 320 ms 40504 KB Output is correct
13 Correct 306 ms 38984 KB Output is correct
14 Correct 290 ms 38688 KB Output is correct
15 Correct 268 ms 38244 KB Output is correct
16 Correct 543 ms 44200 KB Output is correct
17 Correct 340 ms 40052 KB Output is correct
18 Correct 300 ms 39132 KB Output is correct
19 Correct 1134 ms 70668 KB Output is correct
20 Correct 345 ms 42556 KB Output is correct
21 Correct 325 ms 40580 KB Output is correct
22 Correct 990 ms 57132 KB Output is correct
23 Correct 29 ms 20556 KB Output is correct
24 Correct 315 ms 40448 KB Output is correct
25 Correct 294 ms 39096 KB Output is correct
26 Correct 281 ms 38724 KB Output is correct
27 Correct 310 ms 38368 KB Output is correct
28 Correct 568 ms 44108 KB Output is correct
29 Correct 343 ms 40060 KB Output is correct
30 Correct 287 ms 39108 KB Output is correct
31 Runtime error 4262 ms 211736 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1139 ms 70640 KB Output is correct
2 Correct 363 ms 42552 KB Output is correct
3 Correct 321 ms 40524 KB Output is correct
4 Correct 1010 ms 57048 KB Output is correct
5 Correct 29 ms 20620 KB Output is correct
6 Correct 318 ms 40624 KB Output is correct
7 Correct 1131 ms 70500 KB Output is correct
8 Correct 343 ms 42460 KB Output is correct
9 Correct 308 ms 40480 KB Output is correct
10 Correct 1006 ms 56972 KB Output is correct
11 Correct 29 ms 20556 KB Output is correct
12 Correct 320 ms 40504 KB Output is correct
13 Correct 306 ms 38984 KB Output is correct
14 Correct 290 ms 38688 KB Output is correct
15 Correct 268 ms 38244 KB Output is correct
16 Correct 543 ms 44200 KB Output is correct
17 Correct 340 ms 40052 KB Output is correct
18 Correct 300 ms 39132 KB Output is correct
19 Correct 1134 ms 70668 KB Output is correct
20 Correct 345 ms 42556 KB Output is correct
21 Correct 325 ms 40580 KB Output is correct
22 Correct 990 ms 57132 KB Output is correct
23 Correct 29 ms 20556 KB Output is correct
24 Correct 315 ms 40448 KB Output is correct
25 Correct 294 ms 39096 KB Output is correct
26 Correct 281 ms 38724 KB Output is correct
27 Correct 310 ms 38368 KB Output is correct
28 Correct 568 ms 44108 KB Output is correct
29 Correct 343 ms 40060 KB Output is correct
30 Correct 287 ms 39108 KB Output is correct
31 Runtime error 4262 ms 211736 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -