답안 #304145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304145 2020-09-21T03:32:55 Z kkm0476 자매 도시 (APIO20_swap) C++17
6 / 100
2000 ms 22884 KB
#include "swap.h"
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

std::vector<int> r[100010];
std::vector<std::pair<int, int> > w, w1;

int mx_ = 0;
int subt = 1;

bool cmp(std::pair<int, int> a, std::pair<int, int> b) {
    return a.first < b.first;
}


void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    std::vector<int> next[N + 1];
    for(int i = 0; i < M; i++) {
        r[U[i]].push_back(i);
        r[V[i]].push_back(i);
        next[U[i]].push_back(V[i]);
        next[V[i]].push_back(U[i]);
        mx_ = std::max(mx_, W[i]);
        w.push_back({W[i], i});
        w1.push_back({W[i], i});
    }
    
    for(int i = 0; i < N; i++)
        if(next[i].size() != 2)
            mx_ = -1;
    if(N > 3 && M == N - 1 && next[0].size() == M)
        subt = 2;
    sort(w.begin(), w.end(), cmp);
}

int getMinimumFuelCapacity(int X, int Y) {
    if(subt == 1)
        return mx_;
    std::vector<std::pair<int, int> > W = w;
    std::vector<std::pair<int, int> > W1 = w1;
    if(X > Y)
        std::swap(X, Y);

    int a = W1[r[X].back()].first;
    int b = W1[r[Y].back()].first;
    
    std::pair<int, int> x = W1[r[X].back()];
    std::pair<int, int> y = W1[r[Y].back()];
    
    if(X == 0) {
        a = b;
        x = y;
    }

    int mx = std::max(a, b);
    
    
    if(std::lower_bound(W.begin(), W.end(), x) != W.end())
        W.erase(std::lower_bound(W.begin(), W.end(), x));
    if(X != 0 && std::lower_bound(W.begin(), W.end(), y) != W.end())
        W.erase(std::lower_bound(W.begin(), W.end(), y));
    
    return std::max(mx, W[0].first);
}

Compilation message

swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:33:46: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     if(N > 3 && M == N - 1 && next[0].size() == M)
      |                               ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 105 ms 14412 KB Output is correct
10 Correct 138 ms 16740 KB Output is correct
11 Correct 133 ms 16480 KB Output is correct
12 Correct 147 ms 17292 KB Output is correct
13 Correct 148 ms 17408 KB Output is correct
14 Correct 116 ms 14696 KB Output is correct
15 Correct 220 ms 21100 KB Output is correct
16 Correct 210 ms 20628 KB Output is correct
17 Correct 226 ms 21448 KB Output is correct
18 Correct 225 ms 21448 KB Output is correct
19 Correct 84 ms 10104 KB Output is correct
20 Correct 219 ms 22112 KB Output is correct
21 Correct 220 ms 21916 KB Output is correct
22 Correct 230 ms 22884 KB Output is correct
23 Correct 235 ms 22856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Execution timed out 2074 ms 21804 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 105 ms 14412 KB Output is correct
10 Correct 138 ms 16740 KB Output is correct
11 Correct 133 ms 16480 KB Output is correct
12 Correct 147 ms 17292 KB Output is correct
13 Correct 148 ms 17408 KB Output is correct
14 Correct 116 ms 14696 KB Output is correct
15 Correct 220 ms 21100 KB Output is correct
16 Correct 210 ms 20628 KB Output is correct
17 Correct 226 ms 21448 KB Output is correct
18 Correct 225 ms 21448 KB Output is correct
19 Execution timed out 2074 ms 21804 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct