이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
const int maxn=1e5+7;
struct nguoi
{
int xo,yo,xt,yt;
};
nguoi a[maxn];
int k,n;
main()
{
cin>>k>>n;
vector<ii>v;
vector<int>tmp;
long long delt=0;
for(int i=1;i<=n;i++){
char xo,xt;
cin>>xo>>a[i].yo>>xt>>a[i].yt;
a[i].xo=(xo=='B');
a[i].xt=(xt=='B');
if(xo==xt){
delt+=abs(a[i].yt-a[i].yo);
}
else{
tmp.push_back(a[i].yo);
tmp.push_back(a[i].yt);
v.push_back({a[i].yo,a[i].yt});
}
}
long long ans=LLONG_MAX;
sort(tmp.begin(),tmp.end());
int to=tmp[tmp.size()/2];
long long s=0ll;
for(auto [x,y]:v){
s=s+((abs(x-to)+abs(y-to))+1);
}
ans=min(ans,s);
// if(tmp.size()/2-1>=0){
// to=tmp[tmp.size()/2-1];
// s=0ll;
// for(auto [x,y]:v)
// {
// s=s+((abs(x-to)+abs(y-to))+1);
// }
// ans=min(ans,s);
// }
// if(tmp.size()/2+1<tmp.size()){
// to=tmp[tmp.size()/2+1];
// s=0ll;
// for(auto [x,y]:v)
// {
// s=s+((abs(x-to)+abs(y-to))+1);
// }
// ans=min(ans,s);
// }
cout<<ans+delt;
return 0;
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main()
| ^~~~
bridge.cpp: In function 'int main()':
bridge.cpp:36:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | for(auto [x,y]:v){
| ^
# | 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... |