제출 #420965

#제출 시각아이디문제언어결과실행 시간메모리
420965albertolg101Wiring (IOI17_wiring)C++17
13 / 100
154 ms16944 KiB
#include <bits/stdc++.h> #include "wiring.h" using namespace std; using ll = long long; using pii = pair<ll, int>; const int INF = 2e9; void print (vector<pii> v) { for(auto i: v) cout << i.first << ' ' << i.second << endl ; cout << endl ; } void print (vector<ll> v) { for(auto i: v) cout << i << ' ' ; cout << endl ; } long long min_total_length(std::vector<int> r, std::vector<int> b) { vector<pii> ar; for(auto i: r) ar.push_back({i, 0}); for(auto i: b) ar.push_back({i, 1}); sort(ar.begin(), ar.end()); ar.insert(ar.begin(), (pii){0, 0}); int acc = 0; map<int, int> mfirst, mlast; vector<long long> cost; mfirst[0] = 0; mlast[0] = 0; cost.push_back(0); for(int i = 1 ; i < ar.size() ; i++) { ar[i].second ? acc++ : acc--; if(mlast.count(acc)) { if(mlast[acc] + 2 == i) cost.push_back(cost[mlast[acc]] + ar[i].first - ar[i-1].first); else cost.push_back(cost[mlast[acc]] + cost[i-1] - cost[mlast[acc] + 1] + ar[i].first - ar[mlast[acc] + 1].first); mlast[acc] = i; } else { long long temp = INF; if(ar[i].second == 0) //b swap(b, r); auto pt = lower_bound(r.begin(), r.end(), ar[i].first); if(pt != r.end()) temp = *pt - ar[i].first ; if(pt != r.begin()) temp = min(temp, ar[i].first - *prev(pt)); if(ar[i].second == 0) swap(b, r); cost.push_back(cost[i-1] + temp); mlast[acc] = mfirst[acc] = i ; } } //print(ar); //print(cost); return cost.back(); }

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

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 1 ; i < ar.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...