이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
//#define int long long
#define ss second
#define ff first
#define endl '\n'
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k,n; cin>>k>>n;
int sum=0;
vector<pair<int,int> > v,d;
for(int i=0; i<n; i++){
int s,t;
char p,q;
cin>>p>>s>>q>>t;
if(p==q){
sum+=abs(s-t);
}else{
sum++;
v.push_back({s,i});
v.push_back({t,i});
d.push_back({s,t});
}
}
int sl=0,sr=0;
ordered_set f,s;
vector<bool> vis(n);
sort(v.begin(),v.end());
int ml=0,mr=v[v.size()/2].ff;
for(int i=0; i<v.size(); i++){
sr+=abs(mr-v[i].ff);
s.insert({v[i].ff,v[i].ss});
}
int res=sl+sr;
if(k==1){
cout<<res+sum;
}else{
// for(int i=0; i<v.size(); i++){
// if(!vis[v[i].ss]){
// vis[v[i].ss]=1;
// s.erase({d[v[i].ss].ff,v[i].ss});
// s.erase({d[v[i].ss].ss,v[i].ss});
// f.insert({d[v[i].ss].ff,v[i].ss});
// f.insert({d[v[i].ss].ss,v[i].ss});
// int fh=f.size()/2,sh=s.size()/2;
// int pl=(*f.find_by_order(fh)).ff;
// int pr=(*s.find_by_order(sh)).ff;
// sl+=abs(d[v[i].ss].ff-ml);
// sl+=abs(d[v[i].ss].ss-ml);
// sl+=fh*(pl-ml);
// sl-=(f.size()-fh)*(pl-ml);
// sr-=abs(d[v[i].ss].ff-mr);
// sr-=abs(d[v[i].ss].ss-mr);
// sr+=sh*(pr-mr);
// sr-=(s.size()-sh)*(pr-mr);
// ml=pl;
// mr=pr;
// res=min(res,sl+sr);
// }
// }
// cout<<res+sum;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0; i<v.size(); i++){
| ~^~~~~~~~~
bridge.cpp:59:9: warning: unused variable 'ml' [-Wunused-variable]
59 | int ml=0,mr=v[v.size()/2].ff;
| ^~
# | 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... |