Submission #535843

# Submission time Handle Problem Language Result Execution time Memory
535843 2022-03-11T14:06:00 Z mario05092929 Swapping Cities (APIO20_swap) C++17
100 / 100
311 ms 37916 KB
#include "swap.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const int INF = 1e9+1;
const int TMX = 1 << 18;
const long long llINF = 1e18;
const long long mod = 1e9+7;
const long long hashmod = 100003;
const int MAXN = 100000;
const int MAXM = 1000000;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;
int n,m,ans[100005],deg[100005];
vecpi p[100005];
vec ch[100005];
vector <pair<int,pi>> edge;

void init(int N,int M,vec U,vec V,vec W) {
    n = N, m = M;
    for(int i = 0;i < N;i++) {
        p[i].pb({0,i});
        ch[i].pb(i);
        ans[i] = INF;
    }
    for(int i = 0;i < M;i++) {
        edge.pb({W[i],{U[i],V[i]}});
    }
    sort(all(edge));
    for(auto I : edge) {
        int val = I.x, x = I.y.x, y = I.y.y;
        int px = p[x].back().y, py = p[y].back().y;
        if(px == py) {
            ans[px] = min(ans[px],val);
        }
        else {
            if(ch[px].size() < ch[py].size()) {
                swap(x,y), swap(px,py);
            }
            deg[x]++, deg[y]++;
            ans[px] = min(ans[px],max(ans[py],val));
            if(deg[x] > 2||deg[y] > 2) ans[px] = min(ans[px],val);
            for(int i : ch[py]) {
                p[i].pb({val,px});
                ch[px].pb(i);
            }
        }
    }
}

int getMinimumFuelCapacity(int x, int y) {
    int i = p[x].size(), j = p[y].size();
    int ret = INF;
    i--, j--;
    while(i >= 0&&j >= 0&&p[x][i].y == p[y][j].y) {
        ret = min(ret,max({ans[p[x][i].y],p[x][i].x,p[y][j].x}));
        i--, j--;
    }
    return (ret == INF ? -1 : ret);
}

Compilation message

swap.cpp:7: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    7 | #pragma gcc optimize("O3")
      | 
swap.cpp:8: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    8 | #pragma gcc optimize("Ofast")
      | 
swap.cpp:9: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    9 | #pragma gcc optimize("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 123 ms 23308 KB Output is correct
10 Correct 167 ms 26964 KB Output is correct
11 Correct 160 ms 26636 KB Output is correct
12 Correct 173 ms 27932 KB Output is correct
13 Correct 100 ms 20616 KB Output is correct
14 Correct 147 ms 23704 KB Output is correct
15 Correct 257 ms 31624 KB Output is correct
16 Correct 226 ms 30880 KB Output is correct
17 Correct 242 ms 32368 KB Output is correct
18 Correct 161 ms 24720 KB Output is correct
19 Correct 66 ms 13668 KB Output is correct
20 Correct 234 ms 32500 KB Output is correct
21 Correct 228 ms 32180 KB Output is correct
22 Correct 251 ms 33712 KB Output is correct
23 Correct 187 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 158 ms 22756 KB Output is correct
4 Correct 154 ms 23132 KB Output is correct
5 Correct 143 ms 23168 KB Output is correct
6 Correct 151 ms 22992 KB Output is correct
7 Correct 146 ms 23268 KB Output is correct
8 Correct 139 ms 22632 KB Output is correct
9 Correct 140 ms 22972 KB Output is correct
10 Correct 136 ms 22616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5204 KB Output is correct
12 Correct 4 ms 5128 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 4 ms 5148 KB Output is correct
15 Correct 4 ms 5148 KB Output is correct
16 Correct 3 ms 5148 KB Output is correct
17 Correct 3 ms 5144 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5204 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5144 KB Output is correct
23 Correct 4 ms 5148 KB Output is correct
24 Correct 4 ms 5164 KB Output is correct
25 Correct 4 ms 5148 KB Output is correct
26 Correct 4 ms 5144 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 123 ms 23308 KB Output is correct
11 Correct 167 ms 26964 KB Output is correct
12 Correct 160 ms 26636 KB Output is correct
13 Correct 173 ms 27932 KB Output is correct
14 Correct 100 ms 20616 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 4 ms 5204 KB Output is correct
17 Correct 4 ms 5128 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 4 ms 5148 KB Output is correct
20 Correct 4 ms 5148 KB Output is correct
21 Correct 3 ms 5148 KB Output is correct
22 Correct 3 ms 5144 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5144 KB Output is correct
28 Correct 4 ms 5148 KB Output is correct
29 Correct 4 ms 5164 KB Output is correct
30 Correct 4 ms 5148 KB Output is correct
31 Correct 4 ms 5144 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 4 ms 5144 KB Output is correct
34 Correct 14 ms 7704 KB Output is correct
35 Correct 178 ms 27516 KB Output is correct
36 Correct 177 ms 27376 KB Output is correct
37 Correct 175 ms 26896 KB Output is correct
38 Correct 159 ms 25988 KB Output is correct
39 Correct 154 ms 25664 KB Output is correct
40 Correct 129 ms 23608 KB Output is correct
41 Correct 177 ms 28288 KB Output is correct
42 Correct 182 ms 28052 KB Output is correct
43 Correct 94 ms 19588 KB Output is correct
44 Correct 150 ms 25612 KB Output is correct
45 Correct 127 ms 21800 KB Output is correct
46 Correct 178 ms 27436 KB Output is correct
47 Correct 140 ms 23956 KB Output is correct
48 Correct 118 ms 21256 KB Output is correct
49 Correct 66 ms 14772 KB Output is correct
50 Correct 53 ms 12304 KB Output is correct
51 Correct 97 ms 18912 KB Output is correct
52 Correct 200 ms 30264 KB Output is correct
53 Correct 189 ms 26748 KB Output is correct
54 Correct 242 ms 33560 KB Output is correct
55 Correct 95 ms 19776 KB Output is correct
56 Correct 166 ms 25416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 123 ms 23308 KB Output is correct
10 Correct 167 ms 26964 KB Output is correct
11 Correct 160 ms 26636 KB Output is correct
12 Correct 173 ms 27932 KB Output is correct
13 Correct 100 ms 20616 KB Output is correct
14 Correct 147 ms 23704 KB Output is correct
15 Correct 257 ms 31624 KB Output is correct
16 Correct 226 ms 30880 KB Output is correct
17 Correct 242 ms 32368 KB Output is correct
18 Correct 161 ms 24720 KB Output is correct
19 Correct 158 ms 22756 KB Output is correct
20 Correct 154 ms 23132 KB Output is correct
21 Correct 143 ms 23168 KB Output is correct
22 Correct 151 ms 22992 KB Output is correct
23 Correct 146 ms 23268 KB Output is correct
24 Correct 139 ms 22632 KB Output is correct
25 Correct 140 ms 22972 KB Output is correct
26 Correct 136 ms 22616 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5204 KB Output is correct
29 Correct 4 ms 5128 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 4 ms 5148 KB Output is correct
32 Correct 4 ms 5148 KB Output is correct
33 Correct 3 ms 5148 KB Output is correct
34 Correct 3 ms 5144 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 14 ms 7704 KB Output is correct
37 Correct 178 ms 27516 KB Output is correct
38 Correct 177 ms 27376 KB Output is correct
39 Correct 175 ms 26896 KB Output is correct
40 Correct 159 ms 25988 KB Output is correct
41 Correct 154 ms 25664 KB Output is correct
42 Correct 129 ms 23608 KB Output is correct
43 Correct 177 ms 28288 KB Output is correct
44 Correct 182 ms 28052 KB Output is correct
45 Correct 94 ms 19588 KB Output is correct
46 Correct 150 ms 25612 KB Output is correct
47 Correct 18 ms 8152 KB Output is correct
48 Correct 252 ms 32664 KB Output is correct
49 Correct 239 ms 31956 KB Output is correct
50 Correct 231 ms 31848 KB Output is correct
51 Correct 228 ms 31236 KB Output is correct
52 Correct 215 ms 29556 KB Output is correct
53 Correct 143 ms 24500 KB Output is correct
54 Correct 238 ms 33380 KB Output is correct
55 Correct 239 ms 33168 KB Output is correct
56 Correct 160 ms 24984 KB Output is correct
57 Correct 210 ms 30900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 123 ms 23308 KB Output is correct
11 Correct 167 ms 26964 KB Output is correct
12 Correct 160 ms 26636 KB Output is correct
13 Correct 173 ms 27932 KB Output is correct
14 Correct 100 ms 20616 KB Output is correct
15 Correct 147 ms 23704 KB Output is correct
16 Correct 257 ms 31624 KB Output is correct
17 Correct 226 ms 30880 KB Output is correct
18 Correct 242 ms 32368 KB Output is correct
19 Correct 161 ms 24720 KB Output is correct
20 Correct 158 ms 22756 KB Output is correct
21 Correct 154 ms 23132 KB Output is correct
22 Correct 143 ms 23168 KB Output is correct
23 Correct 151 ms 22992 KB Output is correct
24 Correct 146 ms 23268 KB Output is correct
25 Correct 139 ms 22632 KB Output is correct
26 Correct 140 ms 22972 KB Output is correct
27 Correct 136 ms 22616 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5128 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5148 KB Output is correct
33 Correct 4 ms 5148 KB Output is correct
34 Correct 3 ms 5148 KB Output is correct
35 Correct 3 ms 5144 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 14 ms 7704 KB Output is correct
38 Correct 178 ms 27516 KB Output is correct
39 Correct 177 ms 27376 KB Output is correct
40 Correct 175 ms 26896 KB Output is correct
41 Correct 159 ms 25988 KB Output is correct
42 Correct 154 ms 25664 KB Output is correct
43 Correct 129 ms 23608 KB Output is correct
44 Correct 177 ms 28288 KB Output is correct
45 Correct 182 ms 28052 KB Output is correct
46 Correct 94 ms 19588 KB Output is correct
47 Correct 150 ms 25612 KB Output is correct
48 Correct 18 ms 8152 KB Output is correct
49 Correct 252 ms 32664 KB Output is correct
50 Correct 239 ms 31956 KB Output is correct
51 Correct 231 ms 31848 KB Output is correct
52 Correct 228 ms 31236 KB Output is correct
53 Correct 215 ms 29556 KB Output is correct
54 Correct 143 ms 24500 KB Output is correct
55 Correct 238 ms 33380 KB Output is correct
56 Correct 239 ms 33168 KB Output is correct
57 Correct 160 ms 24984 KB Output is correct
58 Correct 210 ms 30900 KB Output is correct
59 Correct 66 ms 13668 KB Output is correct
60 Correct 234 ms 32500 KB Output is correct
61 Correct 228 ms 32180 KB Output is correct
62 Correct 251 ms 33712 KB Output is correct
63 Correct 187 ms 26104 KB Output is correct
64 Correct 3 ms 5076 KB Output is correct
65 Correct 3 ms 5204 KB Output is correct
66 Correct 3 ms 5076 KB Output is correct
67 Correct 3 ms 5144 KB Output is correct
68 Correct 4 ms 5148 KB Output is correct
69 Correct 4 ms 5164 KB Output is correct
70 Correct 4 ms 5148 KB Output is correct
71 Correct 4 ms 5144 KB Output is correct
72 Correct 4 ms 5076 KB Output is correct
73 Correct 4 ms 5144 KB Output is correct
74 Correct 127 ms 21800 KB Output is correct
75 Correct 178 ms 27436 KB Output is correct
76 Correct 140 ms 23956 KB Output is correct
77 Correct 118 ms 21256 KB Output is correct
78 Correct 66 ms 14772 KB Output is correct
79 Correct 53 ms 12304 KB Output is correct
80 Correct 97 ms 18912 KB Output is correct
81 Correct 200 ms 30264 KB Output is correct
82 Correct 189 ms 26748 KB Output is correct
83 Correct 242 ms 33560 KB Output is correct
84 Correct 95 ms 19776 KB Output is correct
85 Correct 166 ms 25416 KB Output is correct
86 Correct 54 ms 12180 KB Output is correct
87 Correct 243 ms 31492 KB Output is correct
88 Correct 234 ms 31760 KB Output is correct
89 Correct 186 ms 25200 KB Output is correct
90 Correct 129 ms 18492 KB Output is correct
91 Correct 127 ms 18884 KB Output is correct
92 Correct 158 ms 23920 KB Output is correct
93 Correct 311 ms 34160 KB Output is correct
94 Correct 238 ms 31612 KB Output is correct
95 Correct 295 ms 37916 KB Output is correct
96 Correct 163 ms 25020 KB Output is correct
97 Correct 205 ms 28644 KB Output is correct