# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1037317 | ican0534 | Toilets (JOI16_toilets) | C++14 | 1 ms | 2396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct st{int x, ty, gr;} a[200005];
int n, m, g, ans, t[200005];
bool cmpx(st p, st q) {
if(p.x != q.x) return p.x < q.x;
return p.ty < q.ty;
}
bool cmpg(st p, st q) {
if(p.gr != q.gr) return p.gr < q.gr;
return p.x < q.x;
}
int dist(int *d, int k) {
int i, s=0, mn;
for(i=0; i<k-1; i+=2) s += d[i+1] - d[i];
mn = s;
if(k%2) {
for(i=k-2; i>0; i-=2) {
s += d[i+1] + d[i-1] - 2*d[i];
mn = min(mn, s);
}
}
return mn;
}
int main() {
int i, j;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++) scanf("%d", &a[i].x), a[i].ty = 1;
for(i=n; i<n+m; i++) scanf("%d", &a[i].x), a[i].ty = 2;
sort(a, a+n+m, cmpx);
for(i=1; i<n+m; i++) {
if(a[i].ty == a[i-1].ty) {
a[i].ty==1 ? g-- : g++;
}
a[i].gr = g;
}
sort(a, a+n+m, cmpg);
for(i=0; i<n+m; i=j) {
for(j=i; j<n+m && a[j].gr==a[i].gr; j++) t[j-i] = a[j].x;
ans += dist(t, j-i);
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |