제출 #43197

#제출 시각아이디문제언어결과실행 시간메모리
43197szawinis전선 연결 (IOI17_wiring)C++14
7 / 100
63 ms9308 KiB
#include "wiring.h" #include <bits/stdc++.h> #define pos first #define col second using namespace std; using ll = long long; const int N = 1e5+1; const ll INF = 1e17; int n; vector<pair<int,int> > a; ll s[N], dp[N]; ll min_total_length(std::vector<int> r, std::vector<int> b) { n = r.size() + b.size(); for(int i = 0; i < r.size(); i++) a.emplace_back(r[i], 0); for(int i = 0; i < b.size(); i++) a.emplace_back(b[i], 1); a.emplace_back(INT_MIN, INT_MIN); sort(a.begin(), a.end()); for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i].pos; fill(dp+1, dp+n+1, INF); for(int i = 2; i <= n; i++) { // case segments completely disjoint int k = i-1; while(k && a[k].col == a[i].col) --k; for(int j = k-1; a[j+1].col == a[k].col; j--) { ll res = dp[j] + (s[i] - s[k]) - (s[k] - s[j]); if(i-k > k-j) res -= 1ll * ((i-k) - (k-j)) * a[k].pos; else if(i-k < k-j) res += 1ll * ((k-j) - (i-k)) * a[k+1].pos; dp[i] = min(res, dp[i]); } // case segments intersect at one node if(k-1 >= 1 && a[k-1].col == a[i].col) dp[i] = min(dp[k] + s[i] - s[k] - 1ll * (i-k) * a[k].pos, dp[i]); } return dp[n]; }

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

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