이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const ll PW = 43;
const int N = 30010;
const int B = 100;
const int oo = 2e9;
const ll OO = 1e18;
vector<pii> seg;
vector<int> pts;
ll extra = 0, best = OO;
int k, n;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> k >> n;
assert(k == 1);
for (int i = 0; i < n; i++){
char c1, c2; int l, r;
cin >> c1 >> l >> c2 >> r;
if (l > r) swap(l, r);
extra += r - l;
if (c1 != c2){
seg.PB(MP(l, r));
pts.PB(l);
if (l > 0)
pts.PB(l - 1);
if (r > 0)
pts.PB(r - 1);
pts.PB(r);
if (l < int(1e9))
pts.PB(l + 1);
if (r < int(1e9))
pts.PB(r + 1);
}
}
sort(all(pts));
pts.resize(unique(all(pts)) - pts.begin());
for (int x : pts){
ll cur = 0;
for (pii cr : seg){
if (cr.sd < x)
cur += x - cr.sd;
if (cr.ft > x)
cur += cr.ft - x;
}
best = min(best, cur + cur);
}
if (best == OO)
return -1;
cout << best + extra + sz(seg);
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... |