이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int k, n;
cin >> k >> n;
int N = 0;
int64_t ans = 0;
vector<array<int, 2>> v;
vector<array<int, 2>> next;
for(int i = 0; i < n; i++){
char s, d;
int st, dt;
cin >> s >> st >> d >> dt;
ans += int64_t(abs(dt - st));
if(s == d)
continue;
if(st > dt) swap(st, dt);
v.push_back({st, dt});
next.push_back({st, 0}), next.push_back({dt, 1});
N++;
}
n = N;
sort(v.begin(), v.end());
sort(next.begin(), next.end());
int current = -1;
array<int, 2> a = {n, 0};
int64_t inc = 0;
for(int i = 0; i < n; i++){
inc += 2LL*int64_t(v[i][0] - current);
}
int64_t cur = inc;
for(int i = 0; i < 2*n; i++){
int nxt = next[i][0];
cur = cur - 2LL*a[0]*int64_t(nxt - current) - 2LL*a[1]*int64_t(nxt - current);
inc = min(inc, cur);
current = nxt;
a[next[i][1]]--;
}
cout << ans + inc + n << '\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... |