이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define int long long
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int n,k;cin >> k >> n;
vector<pair<int,int>> loc;
int same_part = 0;
int mx = 0;
for(int i = 0;i<n;i++){
char c1, c2;
int a,b;
cin >> c1 >> a >> c2 >> b;
if(c1 == c2){
same_part += abs(a - b);
}
else{
mx = max(mx, max(a, b));
same_part++;
if(a > b)swap(a, b);
loc.emplace_back(a, b);
}
}
deb(loc);
multiset<pair<int,int>> aset, bset;
for(auto e : loc)aset.insert(e);
int ans = 1e18;
int sump1 = 0;
int sump2 = 0;
int sump3 = 0;
int inp2 = 0;
for(auto e : aset)sump1 += e.first + e.second;
set<pair<int,int>> extra;
for(int i = 0;i<=mx;i++){
while(aset.size() > 0){
auto it = *aset.begin();
if(i >= it.first){
bset.insert({it.second, it.first});
aset.erase(aset.begin());
sump1 -= it.first + it.second;
sump3 += abs(it.first - it.second);
}
else
break;
}
while(bset.size() > 0){
auto it = *bset.begin();
if(i >= it.first){
bset.erase(bset.begin());
extra.insert(it);
sump2 += it.first + it.second;
sump3 -= abs(it.first - it.second);
inp2++;
}
else break;
}
deb(aset, bset, extra);
int p1 = sump1 - 2*i*aset.size();
int p2 = inp2*2*i - sump2;
deb(same_part, p1, p2, sump3);
ans = min(ans, same_part + (sump1 - 2*i*(int)aset.size()) + (inp2*2*i - sump2) + sump3);
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:64:13: warning: unused variable 'p1' [-Wunused-variable]
64 | int p1 = sump1 - 2*i*aset.size();
| ^~
bridge.cpp:65:13: warning: unused variable 'p2' [-Wunused-variable]
65 | int p2 = inp2*2*i - sump2;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |