제출 #391166

#제출 시각아이디문제언어결과실행 시간메모리
391166Andyvanh1전선 연결 (IOI17_wiring)C++14
20 / 100
42 ms5428 KiB
using namespace std;


// 17.4.1.2 Headers

// C




#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define vt vector
#define pb push_back


typedef long long ll;
typedef vt<int> vi;

vt<pair<int,int>> edges;
vt<ll> weights;

const int mxN=5e5+1, M=1e9+7;
int n, m, p[mxN];

int find(int x) {
    return x^p[x]?p[x]=find(p[x]):x;
}

bool join(int x, int y) {
    if((x=find(x))==(y=find(y)))
        return 0;
    p[find(x)]=find(y);
    return 1;
}

ll prim(){
    for(int i = 0; i < 200001; i++){
        p[i] = i;
    }
    priority_queue<pair<ll,pair<int,int>>,vt<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
    for(int i = 0; i < edges.size(); i++){
        pq.push({weights[i],{edges[i].first,edges[i].second}});
    }
    ll ans = 0;
    while(!pq.empty()){
        auto e = pq.top();
        pq.pop();
        if(find(e.second.first)!=find(e.second.second)){
            join(e.second.first,e.second.second);
            ans+=e.first;

        }
    }
    return ans;


}


ll min_total_length(vi r, vi b){
    int n = r.size();
    int m = b.size();
    ll ans = 0;
    if(b[0]>r[n-1]) {
        ans += (ll) max(n, m) * (b[0] - r[n - 1]);
        for (int i = 0; i < n; i++) {
            ans += r[n - 1] - r[i];
        }
        for (int i = 0; i < m; i++) {
            ans += b[i] - b[0];
        }
        return ans;
    }else{

        ll dp[n][m];
        dp[0][0] = abs(r[0]-b[0]);
        for(int i = 0; i < n; i++){
            for(int j = (i?0:1); j < m; j++){
                if(i==0){
                    dp[i][j] = dp[i][j-1]+abs(b[j]-r[i]);
                }else if(j==0){
                    dp[i][j] = dp[i-1][j]+abs(b[j]-r[i]);
                }else{
                    dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+abs(b[j]-r[i]);
                }
            }
        }
        return dp[n-1][m-1];
    }

}

컴파일 시 표준 에러 (stderr) 메시지

wiring.cpp: In function 'll prim()':
wiring.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for(int i = 0; i < edges.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...