제출 #283400

#제출 시각아이디문제언어결과실행 시간메모리
283400DystoriaX전선 연결 (IOI17_wiring)C++14
0 / 100
1 ms384 KiB
#include "wiring.h" #include <algorithm> #include <iostream> #include <set> using namespace std; vector<pair<int, int> > v; const long long INF = 1e18; long long dp[200010], val[200010]; multiset<long long> s, sk; long long lazy; long long min_total_length(std::vector<int> r, std::vector<int> b) { for(auto &k : r) v.emplace_back(k, 0); for(auto &k : b) v.emplace_back(k, 1); sort(v.begin(), v.end()); int last = -1; for(int i = 1; i < (int) v.size(); i++){ if(v[i].second == v[i - 1].second) continue; else {last = i; break;} } for(int i = 0; i < (int) v.size(); i++) dp[i] = 1e17; // cerr << last << "\n"; int lpos = v[last - 1].first, cpos = v[last].first; int ls = -1, conmax = 0; for(int i = last; i < (int) v.size(); i++){ if(v[i].second == v[i - 1].second){ if(!s.empty()) s.erase(s.find(val[i - ls])), sk.insert(val[i - ls] - lazy); lazy += v[i].first - lpos; if(!s.empty()) dp[i] = *s.begin() + v[i].first - cpos; dp[i] = min(dp[i], *sk.begin() + lazy); } else { lpos = v[i - 1].first; cpos = v[i].first; ls = i; long long cost = 0; s.clear(); sk.clear(); lazy = 0; for(int j = i - 1; j >= 0; j--){ if(v[j].second == v[i].second) break; cost += v[i].first - v[j].first; long long pen = (j == 0) ? 0 : dp[j - 1]; val[i - j] = pen + cost; s.insert(val[i - j]); conmax = i - j; } dp[i] = *s.begin(); } // cerr << v[i].first << " " << i << " = " << dp[i] << "\n"; } return dp[v.size() - 1]; }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:30:15: warning: variable 'conmax' set but not used [-Wunused-but-set-variable]
   30 |  int ls = -1, conmax = 0;
      |               ^~~~~~
#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...