이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int k, n;
cin >> k >> n;
int ans1 = 0, ans2 = 0x3f3f3f3f;
vector<int> a, b;
for(int i=1; i<=n; i++){
int s, t;
char p, q;
cin >> p >> s >> q >> t;
if(p == q) ans1 += abs(s - t);
else{
if(p == 'B') swap(s, t);
a.push_back(s);
b.push_back(t);
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(int i=0; i<a.size(); i++){
int tot = 0;
for(int j=0; j<i; j++) tot += a[i] - a[j];
for(int j=i+1; j<a.size(); j++) tot += a[j] - a[i];
for(int j=0; j<b.size(); j++) tot += abs(a[i] - b[j]);
ans2 = min(ans2, tot);
}
for(int i=0; i<b.size(); i++){
int tot = 0;
for(int j=0; j<i; j++) tot += b[i] - b[j];
for(int j=i+1; j<b.size(); j++) tot += b[j] - b[i];
for(int j=0; j<a.size(); j++) tot += abs(a[i] - b[j]);
ans2 = min(ans2, tot);
}
cout << ans1 + ans2 + (int)a.size() << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<a.size(); i++){
~^~~~~~~~~
bridge.cpp:25:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1; j<a.size(); j++) tot += a[j] - a[i];
~^~~~~~~~~
bridge.cpp:26:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<b.size(); j++) tot += abs(a[i] - b[j]);
~^~~~~~~~~
bridge.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<b.size(); i++){
~^~~~~~~~~
bridge.cpp:32:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=i+1; j<b.size(); j++) tot += b[j] - b[i];
~^~~~~~~~~
bridge.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<a.size(); j++) tot += abs(a[i] - b[j]);
~^~~~~~~~~
# | 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... |