Submission #560264

# Submission time Handle Problem Language Result Execution time Memory
560264 2022-05-11T08:21:48 Z HappyPacMan Swapping Cities (APIO20_swap) C++14
7 / 100
262 ms 33348 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 4;
vector<int> sack[maxn];
vector<pair<int,int> > ucond[maxn];
int dsu[maxn],uturn[maxn],adjs[maxn];
 
void join(int u,int v,int w){
    if(dsu[u] != dsu[v]){
        if(sack[dsu[v]].size() > sack[dsu[u]].size()){
            swap(u,v);
        }
        int temp = dsu[v];
        for(int it : sack[temp]){
            sack[dsu[u]].emplace_back(it);
            dsu[it] = dsu[u];
            ucond[it].emplace_back(dsu[it],w);
        }
        sack[temp].clear();
    }
    adjs[u]++;
    adjs[v]++;
    if((adjs[u] > 2 || adjs[v] > 2) && uturn[dsu[u]] == -1){
        uturn[dsu[u]] = w;
    }
}
 
void init(int N,int M,vector<int> U,vector<int> V,vector<int> W){
    vector<tuple<int,int,int> > edge;
    for(int i=0;i<N;i++){
        dsu[i] = i;
        uturn[i] = -1;
        sack[i].emplace_back(i);
        ucond[i].emplace_back(i,0);
    }
    for(int i=0;i<M;i++){
        edge.emplace_back(W[i],U[i],V[i]);
    }
    sort(edge.begin(),edge.end());
    for(auto [w,u,v] : edge){
        join(u,v,w);
    }
    for(int i=0;i<N;i++){
        reverse(ucond[i].begin(),ucond[i].end());
    }
}
 
int getMinimumFuelCapacity(int X,int Y){
    int msize = min(ucond[X].size(),ucond[Y].size()), best = -1;
    for(int i=0;i<msize;i++){
        if(ucond[X][i].first == ucond[Y][i].first && uturn[ucond[X][i].first] != -1){
            if(best == -1){
                best = max({ucond[X][i].second,ucond[Y][i].second,uturn[ucond[X][i].first]});
            }else{
                best = min(best,max({ucond[X][i].second,ucond[Y][i].second,uturn[ucond[X][i].first]}));
            }
        }
    }
    return best;
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:41:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |     for(auto [w,u,v] : edge){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9880 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 121 ms 26948 KB Output is correct
10 Correct 203 ms 30380 KB Output is correct
11 Correct 157 ms 30036 KB Output is correct
12 Correct 189 ms 31276 KB Output is correct
13 Correct 126 ms 23744 KB Output is correct
14 Correct 148 ms 26936 KB Output is correct
15 Correct 262 ms 32728 KB Output is correct
16 Correct 256 ms 32032 KB Output is correct
17 Correct 254 ms 33348 KB Output is correct
18 Correct 193 ms 25644 KB Output is correct
19 Incorrect 64 ms 15192 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 143 ms 23280 KB Output is correct
4 Correct 151 ms 23672 KB Output is correct
5 Correct 189 ms 23680 KB Output is correct
6 Correct 142 ms 23576 KB Output is correct
7 Correct 150 ms 23616 KB Output is correct
8 Correct 180 ms 23268 KB Output is correct
9 Correct 144 ms 23492 KB Output is correct
10 Correct 174 ms 23244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9880 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Incorrect 6 ms 9692 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9880 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 121 ms 26948 KB Output is correct
10 Correct 203 ms 30380 KB Output is correct
11 Correct 157 ms 30036 KB Output is correct
12 Correct 189 ms 31276 KB Output is correct
13 Correct 126 ms 23744 KB Output is correct
14 Correct 148 ms 26936 KB Output is correct
15 Correct 262 ms 32728 KB Output is correct
16 Correct 256 ms 32032 KB Output is correct
17 Correct 254 ms 33348 KB Output is correct
18 Correct 193 ms 25644 KB Output is correct
19 Correct 143 ms 23280 KB Output is correct
20 Correct 151 ms 23672 KB Output is correct
21 Correct 189 ms 23680 KB Output is correct
22 Correct 142 ms 23576 KB Output is correct
23 Correct 150 ms 23616 KB Output is correct
24 Correct 180 ms 23268 KB Output is correct
25 Correct 144 ms 23492 KB Output is correct
26 Correct 174 ms 23244 KB Output is correct
27 Correct 6 ms 9840 KB Output is correct
28 Incorrect 6 ms 9812 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9692 KB Output isn't correct
2 Halted 0 ms 0 KB -