제출 #116972

#제출 시각아이디문제언어결과실행 시간메모리
116972zubec전선 연결 (IOI17_wiring)C++14
100 / 100
101 ms11880 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[2][200100]; ll pref[200100]; int prv[200100], nxt[200100]; long long min_total_length(std::vector<int> r, std::vector<int> b) { vector <pair<int, int> > vec; for (int i = 0; i < r.size(); i++){ vec.push_back({r[i], 0}); } for (int i = 0; i < b.size(); i++){ vec.push_back({b[i], 1}); } int n = vec.size(); sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++){ if (i == 0 || vec[i].second != vec[i-1].second){ prv[i] = i; } else prv[i] = prv[i-1]; } for (int i = n-1; i >= 0; i--){ if (i == n-1 || vec[i].second != vec[i+1].second) nxt[i] = i+1; else nxt[i] = nxt[i+1]; } dp[0][0] = 0; dp[1][0] = 1e18; for (int i = 1; i <= n; i++){ dp[0][i] = dp[1][i] = 1e18; pref[i] = pref[i-1] + vec[i-1].first; int l = prv[i-1], r = nxt[i-1]; if (i-1 == l) dp[0][i] = min(dp[0][i], dp[1][i-1]); if (l != 0){ dp[0][i] = min(dp[0][i], dp[0][i-1] + vec[i-1].first - vec[l-1].first); int len = i-l; if (l-len >= 0){ dp[0][i] = min(dp[0][i], dp[0][l-len] + pref[i]-pref[l] - (pref[l]-pref[l-len])); } } if (r != n){ dp[1][i] = min(dp[1][i], dp[0][i-1] + vec[r].first-vec[i-1].first); } dp[0][i] = min(dp[0][i], dp[1][i]); } return dp[0][n]; } /** 4 5 1 2 3 7 0 4 5 9 10 */

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < r.size(); i++){
                     ~~^~~~~~~~~~
wiring.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < b.size(); i++){
                     ~~^~~~~~~~~~
wiring.cpp:23:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.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...