# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
430259 | Nicholas_Patrick | Coin Collecting (JOI19_ho_t4) | C++17 | 63 ms | 1092 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int diff(int x, int y){
return x<y?y-x:x-y;
}
int ab(int x){
return x<0?-x:x;
}
struct point{
int x, y;
};
int main(){
int n;
scanf("%d", &n);
vector<int> top(n, -1), bot(n, -1);
long long ans=0;
for(int i=n*2; i--;){
int x, y;
scanf("%d%d", &x, &y);
if(y>2){
ans+=y-2;
y=2;
}
if(y<1){
ans+=1-y;
y=1;
}
if(x<1){
ans+=1-x;
x=1;
}
if(x>n){
ans+=x-n;
x=n;
}
if(y==2)
top[x-1]++;
else
bot[x-1]++;
}
for(int i=0; i<n; i++){
if(top[i]>=0){
if(bot[i]<0){
if(top[i]<-bot[i]){
ans+=top[i];
bot[i]+=top[i];
top[i]-=top[i];
}else{
ans-=bot[i];
top[i]+=bot[i];
bot[i]-=bot[i];
}
}
}else{
if(bot[i]>=0){
if(-top[i]<bot[i]){
ans-=top[i];
bot[i]+=top[i];
top[i]-=top[i];
}else{
ans+=bot[i];
top[i]+=bot[i];
bot[i]-=bot[i];
}
}
}
if(top[i]){
ans+=ab(top[i]);
top[i+1]+=top[i];
}
if(bot[i]){
ans+=ab(bot[i]);
bot[i+1]+=bot[i];
}
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (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... |