이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define FOR(i,a, b) for (int i=a; i<=(b); i++)
#define F0R(i,a, b) for (int i=a; i>=(b); i--)
using namespace std;
int n, k, kep;
long long ans, slo, sup, pref[100005];
vector<pair<int,int>> v;
priority_queue<int>lo;
priority_queue<int,vector<int>,greater<int>>hi;
void ins (int x){
if (lo.empty()){lo.push(x);slo+=x;return;}
if (x > lo.top())
hi.push(x), sup+=x;
else
lo.push(x), slo+=x;
if (hi.size() > lo.size()){
int top = hi.top();
hi.pop();
lo.push(top);
sup -= top;
slo += top;
}
else if (lo.size() > hi.size()+1){
int top = hi.top();
lo.pop();
hi.push(top);
slo -= top;
sup += top;
}
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> k >> n;
FOR(i,1,n){
char c1, c2;
int x, y;
cin >> c1 >> x >> c2 >> y;
if (c1 == c2)
kep += abs(x-y);
else
v.pb({x,y});
}
n = v.size();
FOR(i,0,n-1){
ins(v[i].F);
ins(v[i].S);
pref[i] = sup-slo;
}
ans = pref[n-1];
if (k == 2){
while (hi.size())hi.pop(); sup=0;
while (lo.size())lo.pop(); slo=0;
F0R(i,n-1, 1){
ins(v[i].F);
ins(v[i].S);
ans = min(ans, (long long)sup-slo+pref[i-1]);
}
}
cout << ans + kep + n;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int32_t main()':
bridge.cpp:72:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
72 | while (hi.size())hi.pop(); sup=0;
| ^~~~~
bridge.cpp:72:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
72 | while (hi.size())hi.pop(); sup=0;
| ^~~
bridge.cpp:73:9: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
73 | while (lo.size())lo.pop(); slo=0;
| ^~~~~
bridge.cpp:73:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
73 | while (lo.size())lo.pop(); slo=0;
| ^~~
# | 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... |