이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
bool DEBUG=0;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int k,n;
vll coor;
vector<pll>str;
cin >> k >> n;
ll ans = 0ll;
for(int i=0; i<n; i++){
char p; ll s; char q; ll t;
cin >> p >> s >> q >> t;
if(p==q){
ans += abs(s-t);
}else{
if(s>t)swap(s,t);
ans+=t-s+1ll;
str.eb(s,t);
}
}
n=sz(str);
//k=1
for(ii x:str){
coor.eb(x.fi);
coor.eb(x.se);
}
sort(all(coor));
ll bridge1=coor[n-1],bridge2=coor[n];
ll res1=0ll,res2=0ll;
for(int i=0; i<n; i++){
if(bridge1<str[i].fi){
res1 += 2ll*(str[i].fi-bridge1);
}else if(bridge1>str[i].se){
res1 += 2ll*(bridge1-str[i].se);
}
if(bridge2<str[i].fi){
res2 += 2ll*(str[i].fi-bridge2);
}else if(bridge2>str[i].se){
res2 += 2ll*(bridge2-str[i].se);
}
}
ans += min(res1,res2);
cout << ans << '\n';
return 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... |