답안 #576600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576600 2022-06-13T08:29:57 Z radal 자매 도시 (APIO20_swap) C++17
100 / 100
418 ms 51120 KB
#include <bits/stdc++.h>
#include "swap.h"
#pragma GCC target("sse,sse2,sse4,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 2e5+20,mod = 998244353,inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
//    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z; 
}
vector<int> pr[N],comp[N],adj[N];
vector<int> ti[N];
int mi[N],n,m;
vector<pair<int,pll> > e;
void init (int nn,int mm,vector<int> U,vector<int> V,vector<int> W){
    n = nn;
    m = mm;
    rep(i,1,n+1){
        pr[i].pb(i);
        ti[i].pb(m);
        comp[i].pb(i);
        mi[i] = inf;
    }
    rep(i,0,m){
        U[i]++;
        V[i]++;
        e.pb({W[i],{U[i],V[i]}});
    }
    sort(all(e));
    e.pb({0,{0,0}});
    rep(i,0,m){
        int x = e[i].Y.X,y = e[i].Y.Y;
        int u = pr[x].back(),v = pr[y].back();
        if (u != v){
            adj[x].pb(y);
            adj[y].pb(x);
            if (comp[u].size() > comp[v].size()) swap(u,v);
            while (!comp[u].empty()){
                int w = comp[u].back();
                comp[u].pop_back();
                pr[w].pb(v);
                ti[w].pb(i);
                comp[v].pb(w);
            }
            if (mi[u] < inf) mi[v] = min(mi[v],e[i].X);
            if (adj[x].size() >= 3 || adj[y].size() >= 3){
                mi[v] = min(mi[v],e[i].X);
            }
        }
        else{
            mi[u] = min(mi[u],e[i].X);
        }
    }
}
int getMinimumFuelCapacity(int u, int v){
    u++;
    v++;
    int po1 = pr[u].size()-1,po2 = pr[v].size()-1;
    int calc = inf;
    while (min(po1,po2) >= 0 && pr[u][po1] == pr[v][po2]){
        calc = min(calc,max(mi[pr[u][po1]],max(e[ti[u][po1]].X,e[ti[v][po2]].X)));
        po1--;
        po2--;
    }
    if (calc >= inf) return -1;
    return calc;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19096 KB Output is correct
3 Correct 9 ms 19028 KB Output is correct
4 Correct 11 ms 19176 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 11 ms 19284 KB Output is correct
8 Correct 11 ms 19156 KB Output is correct
9 Correct 221 ms 39872 KB Output is correct
10 Correct 269 ms 43968 KB Output is correct
11 Correct 271 ms 43372 KB Output is correct
12 Correct 292 ms 45132 KB Output is correct
13 Correct 149 ms 36352 KB Output is correct
14 Correct 233 ms 39608 KB Output is correct
15 Correct 358 ms 46280 KB Output is correct
16 Correct 343 ms 45460 KB Output is correct
17 Correct 375 ms 47192 KB Output is correct
18 Correct 250 ms 38080 KB Output is correct
19 Correct 82 ms 26396 KB Output is correct
20 Correct 365 ms 47552 KB Output is correct
21 Correct 331 ms 46764 KB Output is correct
22 Correct 361 ms 48428 KB Output is correct
23 Correct 230 ms 39484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19096 KB Output is correct
3 Correct 195 ms 38328 KB Output is correct
4 Correct 194 ms 39120 KB Output is correct
5 Correct 189 ms 38840 KB Output is correct
6 Correct 192 ms 39028 KB Output is correct
7 Correct 193 ms 39064 KB Output is correct
8 Correct 188 ms 38260 KB Output is correct
9 Correct 188 ms 38824 KB Output is correct
10 Correct 191 ms 38188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19096 KB Output is correct
3 Correct 9 ms 19028 KB Output is correct
4 Correct 11 ms 19176 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 11 ms 19284 KB Output is correct
8 Correct 11 ms 19156 KB Output is correct
9 Correct 9 ms 19084 KB Output is correct
10 Correct 11 ms 19164 KB Output is correct
11 Correct 10 ms 19276 KB Output is correct
12 Correct 11 ms 19284 KB Output is correct
13 Correct 12 ms 19156 KB Output is correct
14 Correct 10 ms 19156 KB Output is correct
15 Correct 11 ms 19284 KB Output is correct
16 Correct 12 ms 19328 KB Output is correct
17 Correct 11 ms 19156 KB Output is correct
18 Correct 11 ms 19284 KB Output is correct
19 Correct 11 ms 19156 KB Output is correct
20 Correct 11 ms 19284 KB Output is correct
21 Correct 10 ms 19156 KB Output is correct
22 Correct 11 ms 19156 KB Output is correct
23 Correct 10 ms 19156 KB Output is correct
24 Correct 11 ms 19248 KB Output is correct
25 Correct 11 ms 19328 KB Output is correct
26 Correct 11 ms 19304 KB Output is correct
27 Correct 10 ms 19220 KB Output is correct
28 Correct 11 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19084 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 9 ms 19096 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 11 ms 19176 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 11 ms 19284 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 11 ms 19156 KB Output is correct
10 Correct 221 ms 39872 KB Output is correct
11 Correct 269 ms 43968 KB Output is correct
12 Correct 271 ms 43372 KB Output is correct
13 Correct 292 ms 45132 KB Output is correct
14 Correct 149 ms 36352 KB Output is correct
15 Correct 11 ms 19164 KB Output is correct
16 Correct 10 ms 19276 KB Output is correct
17 Correct 11 ms 19284 KB Output is correct
18 Correct 12 ms 19156 KB Output is correct
19 Correct 10 ms 19156 KB Output is correct
20 Correct 11 ms 19284 KB Output is correct
21 Correct 12 ms 19328 KB Output is correct
22 Correct 11 ms 19156 KB Output is correct
23 Correct 11 ms 19284 KB Output is correct
24 Correct 11 ms 19156 KB Output is correct
25 Correct 11 ms 19284 KB Output is correct
26 Correct 10 ms 19156 KB Output is correct
27 Correct 11 ms 19156 KB Output is correct
28 Correct 10 ms 19156 KB Output is correct
29 Correct 11 ms 19248 KB Output is correct
30 Correct 11 ms 19328 KB Output is correct
31 Correct 11 ms 19304 KB Output is correct
32 Correct 10 ms 19220 KB Output is correct
33 Correct 11 ms 19284 KB Output is correct
34 Correct 27 ms 22148 KB Output is correct
35 Correct 288 ms 44744 KB Output is correct
36 Correct 281 ms 44560 KB Output is correct
37 Correct 286 ms 43968 KB Output is correct
38 Correct 282 ms 43008 KB Output is correct
39 Correct 271 ms 42572 KB Output is correct
40 Correct 227 ms 40060 KB Output is correct
41 Correct 316 ms 45348 KB Output is correct
42 Correct 309 ms 45604 KB Output is correct
43 Correct 140 ms 36292 KB Output is correct
44 Correct 253 ms 42188 KB Output is correct
45 Correct 183 ms 35268 KB Output is correct
46 Correct 281 ms 44536 KB Output is correct
47 Correct 237 ms 40324 KB Output is correct
48 Correct 193 ms 36648 KB Output is correct
49 Correct 71 ms 26072 KB Output is correct
50 Correct 62 ms 24300 KB Output is correct
51 Correct 148 ms 32540 KB Output is correct
52 Correct 325 ms 45752 KB Output is correct
53 Correct 258 ms 41228 KB Output is correct
54 Correct 345 ms 48712 KB Output is correct
55 Correct 144 ms 36380 KB Output is correct
56 Correct 236 ms 39272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 9 ms 19096 KB Output is correct
3 Correct 9 ms 19028 KB Output is correct
4 Correct 11 ms 19176 KB Output is correct
5 Correct 11 ms 19284 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 11 ms 19284 KB Output is correct
8 Correct 11 ms 19156 KB Output is correct
9 Correct 221 ms 39872 KB Output is correct
10 Correct 269 ms 43968 KB Output is correct
11 Correct 271 ms 43372 KB Output is correct
12 Correct 292 ms 45132 KB Output is correct
13 Correct 149 ms 36352 KB Output is correct
14 Correct 233 ms 39608 KB Output is correct
15 Correct 358 ms 46280 KB Output is correct
16 Correct 343 ms 45460 KB Output is correct
17 Correct 375 ms 47192 KB Output is correct
18 Correct 250 ms 38080 KB Output is correct
19 Correct 195 ms 38328 KB Output is correct
20 Correct 194 ms 39120 KB Output is correct
21 Correct 189 ms 38840 KB Output is correct
22 Correct 192 ms 39028 KB Output is correct
23 Correct 193 ms 39064 KB Output is correct
24 Correct 188 ms 38260 KB Output is correct
25 Correct 188 ms 38824 KB Output is correct
26 Correct 191 ms 38188 KB Output is correct
27 Correct 11 ms 19164 KB Output is correct
28 Correct 10 ms 19276 KB Output is correct
29 Correct 11 ms 19284 KB Output is correct
30 Correct 12 ms 19156 KB Output is correct
31 Correct 10 ms 19156 KB Output is correct
32 Correct 11 ms 19284 KB Output is correct
33 Correct 12 ms 19328 KB Output is correct
34 Correct 11 ms 19156 KB Output is correct
35 Correct 11 ms 19284 KB Output is correct
36 Correct 27 ms 22148 KB Output is correct
37 Correct 288 ms 44744 KB Output is correct
38 Correct 281 ms 44560 KB Output is correct
39 Correct 286 ms 43968 KB Output is correct
40 Correct 282 ms 43008 KB Output is correct
41 Correct 271 ms 42572 KB Output is correct
42 Correct 227 ms 40060 KB Output is correct
43 Correct 316 ms 45348 KB Output is correct
44 Correct 309 ms 45604 KB Output is correct
45 Correct 140 ms 36292 KB Output is correct
46 Correct 253 ms 42188 KB Output is correct
47 Correct 29 ms 22208 KB Output is correct
48 Correct 369 ms 47684 KB Output is correct
49 Correct 351 ms 46996 KB Output is correct
50 Correct 363 ms 46728 KB Output is correct
51 Correct 378 ms 45996 KB Output is correct
52 Correct 321 ms 44100 KB Output is correct
53 Correct 230 ms 37900 KB Output is correct
54 Correct 368 ms 48040 KB Output is correct
55 Correct 369 ms 48296 KB Output is correct
56 Correct 229 ms 39016 KB Output is correct
57 Correct 326 ms 44968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19084 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 9 ms 19096 KB Output is correct
4 Correct 9 ms 19028 KB Output is correct
5 Correct 11 ms 19176 KB Output is correct
6 Correct 11 ms 19284 KB Output is correct
7 Correct 11 ms 19284 KB Output is correct
8 Correct 11 ms 19284 KB Output is correct
9 Correct 11 ms 19156 KB Output is correct
10 Correct 221 ms 39872 KB Output is correct
11 Correct 269 ms 43968 KB Output is correct
12 Correct 271 ms 43372 KB Output is correct
13 Correct 292 ms 45132 KB Output is correct
14 Correct 149 ms 36352 KB Output is correct
15 Correct 233 ms 39608 KB Output is correct
16 Correct 358 ms 46280 KB Output is correct
17 Correct 343 ms 45460 KB Output is correct
18 Correct 375 ms 47192 KB Output is correct
19 Correct 250 ms 38080 KB Output is correct
20 Correct 195 ms 38328 KB Output is correct
21 Correct 194 ms 39120 KB Output is correct
22 Correct 189 ms 38840 KB Output is correct
23 Correct 192 ms 39028 KB Output is correct
24 Correct 193 ms 39064 KB Output is correct
25 Correct 188 ms 38260 KB Output is correct
26 Correct 188 ms 38824 KB Output is correct
27 Correct 191 ms 38188 KB Output is correct
28 Correct 11 ms 19164 KB Output is correct
29 Correct 10 ms 19276 KB Output is correct
30 Correct 11 ms 19284 KB Output is correct
31 Correct 12 ms 19156 KB Output is correct
32 Correct 10 ms 19156 KB Output is correct
33 Correct 11 ms 19284 KB Output is correct
34 Correct 12 ms 19328 KB Output is correct
35 Correct 11 ms 19156 KB Output is correct
36 Correct 11 ms 19284 KB Output is correct
37 Correct 27 ms 22148 KB Output is correct
38 Correct 288 ms 44744 KB Output is correct
39 Correct 281 ms 44560 KB Output is correct
40 Correct 286 ms 43968 KB Output is correct
41 Correct 282 ms 43008 KB Output is correct
42 Correct 271 ms 42572 KB Output is correct
43 Correct 227 ms 40060 KB Output is correct
44 Correct 316 ms 45348 KB Output is correct
45 Correct 309 ms 45604 KB Output is correct
46 Correct 140 ms 36292 KB Output is correct
47 Correct 253 ms 42188 KB Output is correct
48 Correct 29 ms 22208 KB Output is correct
49 Correct 369 ms 47684 KB Output is correct
50 Correct 351 ms 46996 KB Output is correct
51 Correct 363 ms 46728 KB Output is correct
52 Correct 378 ms 45996 KB Output is correct
53 Correct 321 ms 44100 KB Output is correct
54 Correct 230 ms 37900 KB Output is correct
55 Correct 368 ms 48040 KB Output is correct
56 Correct 369 ms 48296 KB Output is correct
57 Correct 229 ms 39016 KB Output is correct
58 Correct 326 ms 44968 KB Output is correct
59 Correct 82 ms 26396 KB Output is correct
60 Correct 365 ms 47552 KB Output is correct
61 Correct 331 ms 46764 KB Output is correct
62 Correct 361 ms 48428 KB Output is correct
63 Correct 230 ms 39484 KB Output is correct
64 Correct 11 ms 19156 KB Output is correct
65 Correct 11 ms 19284 KB Output is correct
66 Correct 10 ms 19156 KB Output is correct
67 Correct 11 ms 19156 KB Output is correct
68 Correct 10 ms 19156 KB Output is correct
69 Correct 11 ms 19248 KB Output is correct
70 Correct 11 ms 19328 KB Output is correct
71 Correct 11 ms 19304 KB Output is correct
72 Correct 10 ms 19220 KB Output is correct
73 Correct 11 ms 19284 KB Output is correct
74 Correct 183 ms 35268 KB Output is correct
75 Correct 281 ms 44536 KB Output is correct
76 Correct 237 ms 40324 KB Output is correct
77 Correct 193 ms 36648 KB Output is correct
78 Correct 71 ms 26072 KB Output is correct
79 Correct 62 ms 24300 KB Output is correct
80 Correct 148 ms 32540 KB Output is correct
81 Correct 325 ms 45752 KB Output is correct
82 Correct 258 ms 41228 KB Output is correct
83 Correct 345 ms 48712 KB Output is correct
84 Correct 144 ms 36380 KB Output is correct
85 Correct 236 ms 39272 KB Output is correct
86 Correct 70 ms 25636 KB Output is correct
87 Correct 368 ms 46376 KB Output is correct
88 Correct 393 ms 46472 KB Output is correct
89 Correct 330 ms 38396 KB Output is correct
90 Correct 132 ms 27956 KB Output is correct
91 Correct 148 ms 28488 KB Output is correct
92 Correct 263 ms 35304 KB Output is correct
93 Correct 388 ms 47184 KB Output is correct
94 Correct 343 ms 43800 KB Output is correct
95 Correct 418 ms 51120 KB Output is correct
96 Correct 237 ms 39080 KB Output is correct
97 Correct 300 ms 41072 KB Output is correct