제출 #673626

#제출 시각아이디문제언어결과실행 시간메모리
673626tbzard전선 연결 (IOI17_wiring)C++14
0 / 100
1090 ms7668 KiB
#include <bits/stdc++.h> using namespace std; long long min_total_length(vector<int> r, vector<int> b){ vector<pair<int, int> > a; for(int i=0;i<r.size();i++) a.push_back(make_pair(r[i], 0)); for(int i=0;i<b.size();i++) a.push_back(make_pair(b[i], 1)); a.push_back(make_pair(-1, -1)); int n = r.size()+b.size(); sort(a.begin(), a.end()); vector<int> sz(n+1); vector<long long> dp(n+1); for(int i=1;i<=n;i++) dp[i] = 1e18; for(int i=1;i<=n;i++){ if(i == 1 || a[i].second != a[i-1].second) sz[i] = 1; else sz[i] = sz[i-1] + 1; long long sum0 = a[i].first, sum1 = 0; int color0 = 1, color1 = 0; for(int j=i-1;j>=1;j--){ if(color1 && a[j].second == a[i].second) break; if(a[j].second == a[i].second){ color0++; sum0 += a[j].first; } else{ color1++; sum1 += a[j].first; } if(color0 > 0 && color1 > 0){ if(color0 >= color1) dp[i] = min(dp[i], dp[j-1] + sum0 - sum1 - (color0-color1)*1ll*a[i-sz[i]].first); else dp[i] = min(dp[i], dp[j-1] + sum0 - sum1 + (color1-color0)*1ll*a[i-sz[i]+1].first); } } } return dp[n]; }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:5:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |     for(int i=0;i<r.size();i++) a.push_back(make_pair(r[i], 0));
      |                 ~^~~~~~~~~
wiring.cpp:6:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for(int i=0;i<b.size();i++) a.push_back(make_pair(b[i], 1));
      |                 ~^~~~~~~~~
#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...