답안 #553140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553140 2022-04-24T18:29:06 Z Itamar 자매 도시 (APIO20_swap) C++14
13 / 100
319 ms 33320 KB
#include "swap.h"

#include <cassert>
#include <cstdio>
#pragma warning(disable : 4996)
#include <map>
#include <iostream>
using namespace std;
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#define ll long long
#define vi vector<int> 
#define vll vector<ll>
#define pi pair<int,int> 
#define pll pair<ll,ll>


vi col_v;
vector<vector<pi>> his;
vector<vi> col;
vector<pi> kats;
void uni(int i, int j, int t) {
    if (col_v[i] == col_v[j]) {
        if (his[i][0].first == -1) {
            for (int x : col[col_v[i]]) {
                his[x][0] = { t,-1 };
            }
        }
        return;
    }
    if (col[col_v[i]].size() > col[col_v[j]].size())
        swap(i, j);
    int c = col_v[j];
    int c1 = col_v[i];
    if (his[i][0].first != -1) {
        if (his[j][0].first == -1) {
            for (int x : col[c]) {
                his[x][0] = { t,-1 };
            }
        }
    }
    else if (his[j][0].first != -1) {
        if (his[i][0].first == -1) {
            for (int x : col[c1]) {
                his[x][0] = { t,-1 };
            }
        }
    }
    else if (i == kats[c1].first) {
        if (j == kats[c].second) {
            kats[c] = { kats[c1].second,kats[c].first };
        }
        else if (j == kats[c].first) {
            kats[c] = { kats[c1].second,kats[c].second };
        }
        else {
            for (int x : col[c1]) {
                his[x][0] = { t,-1 };
            }
            for (int x : col[c]) {
                his[x][0] = { t,-1 };
            }
        }
    }
    else if (i == kats[c1].second) {
        if (j == kats[c].second) {
            kats[c] = { kats[c1].first,kats[c].first };
        }
        else if (j == kats[c].first) {
            kats[c] = { kats[c1].first,kats[c].second };
        }
        else {
            for (int x : col[c1]) {
                his[x][0] = { t,-1 };
            }
            for (int x : col[c]) {
                his[x][0] = { t,-1 };
            }
        }
    }
    else {
        for (int x : col[c1]) {
            his[x][0] = { t,-1 };
        }
        for (int x : col[c]) {
            his[x][0] = { t,-1 };
        }
    }

    for (int x : col[col_v[i]]) {
        col_v[x] = c;
        col[col_v[j]].push_back(x);
        his[x].push_back({ t,c });
    }
}
void init(int N, int M,
    std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    col_v.resize(N);
    his.resize(N);
    vector<vi> v;
    for (int i = 0; i < N; i++) {
        his[i].push_back({ -1,-1 });
        his[i].push_back({ 0,i });
        kats.push_back( { i, i });
    }

    col.resize(N);
    for (int i = 0; i < N; i++) {
        col_v[i] = i;
        col[i].push_back(i);
    }
    for (int i = 0; i < M; i++) {
        v.push_back({ W[i],V[i],U[i] });
    }
    sort(v.begin(), v.end());
    for (vi vec : v) {
        uni(vec[1], vec[2], vec[0]);
    }
}

int getMinimumFuelCapacity(int X, int Y) {
    
    vector<pi> v1 = his[X];
    vector<pi> v2 = his[Y];
    int s = max(v1[0].first, v2[0].first);
    int it1 = v1.size() - 1;
    int it2= v2.size() - 1;
    if (v1[0].first == -1)
        return -1;
    while (true) {
        it1--;
        it2--;
        if (v1[it1].second != v2[it2+1].second ) {
            return max(v2[it2].first, s);
        }
        if (v1[it1+1].second != v2[it2 ].second) {
            return max(v1[it1].first, s);
        }

    }

}

Compilation message

swap.cpp:5: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    5 | #pragma warning(disable : 4996)
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 135 ms 25012 KB Output is correct
10 Correct 193 ms 30208 KB Output is correct
11 Correct 207 ms 29380 KB Output is correct
12 Correct 196 ms 31408 KB Output is correct
13 Correct 116 ms 23488 KB Output is correct
14 Correct 167 ms 25016 KB Output is correct
15 Correct 268 ms 32260 KB Output is correct
16 Correct 306 ms 31208 KB Output is correct
17 Correct 293 ms 33320 KB Output is correct
18 Correct 220 ms 25088 KB Output is correct
19 Correct 70 ms 7916 KB Output is correct
20 Correct 314 ms 32284 KB Output is correct
21 Correct 271 ms 31152 KB Output is correct
22 Correct 319 ms 33320 KB Output is correct
23 Correct 198 ms 25044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 195 ms 23352 KB Output is correct
4 Correct 199 ms 24460 KB Output is correct
5 Correct 218 ms 23688 KB Output is correct
6 Correct 205 ms 24484 KB Output is correct
7 Correct 188 ms 24076 KB Output is correct
8 Correct 191 ms 23152 KB Output is correct
9 Correct 206 ms 23992 KB Output is correct
10 Correct 169 ms 22964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Incorrect 1 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 135 ms 25012 KB Output is correct
11 Correct 193 ms 30208 KB Output is correct
12 Correct 207 ms 29380 KB Output is correct
13 Correct 196 ms 31408 KB Output is correct
14 Correct 116 ms 23488 KB Output is correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 135 ms 25012 KB Output is correct
10 Correct 193 ms 30208 KB Output is correct
11 Correct 207 ms 29380 KB Output is correct
12 Correct 196 ms 31408 KB Output is correct
13 Correct 116 ms 23488 KB Output is correct
14 Correct 167 ms 25016 KB Output is correct
15 Correct 268 ms 32260 KB Output is correct
16 Correct 306 ms 31208 KB Output is correct
17 Correct 293 ms 33320 KB Output is correct
18 Correct 220 ms 25088 KB Output is correct
19 Correct 195 ms 23352 KB Output is correct
20 Correct 199 ms 24460 KB Output is correct
21 Correct 218 ms 23688 KB Output is correct
22 Correct 205 ms 24484 KB Output is correct
23 Correct 188 ms 24076 KB Output is correct
24 Correct 191 ms 23152 KB Output is correct
25 Correct 206 ms 23992 KB Output is correct
26 Correct 169 ms 22964 KB Output is correct
27 Incorrect 1 ms 468 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 135 ms 25012 KB Output is correct
11 Correct 193 ms 30208 KB Output is correct
12 Correct 207 ms 29380 KB Output is correct
13 Correct 196 ms 31408 KB Output is correct
14 Correct 116 ms 23488 KB Output is correct
15 Correct 167 ms 25016 KB Output is correct
16 Correct 268 ms 32260 KB Output is correct
17 Correct 306 ms 31208 KB Output is correct
18 Correct 293 ms 33320 KB Output is correct
19 Correct 220 ms 25088 KB Output is correct
20 Correct 195 ms 23352 KB Output is correct
21 Correct 199 ms 24460 KB Output is correct
22 Correct 218 ms 23688 KB Output is correct
23 Correct 205 ms 24484 KB Output is correct
24 Correct 188 ms 24076 KB Output is correct
25 Correct 191 ms 23152 KB Output is correct
26 Correct 206 ms 23992 KB Output is correct
27 Correct 169 ms 22964 KB Output is correct
28 Incorrect 1 ms 468 KB Output isn't correct
29 Halted 0 ms 0 KB -