# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
153321 | mhy908 | Coin Collecting (JOI19_ho_t4) | C++14 | 78 ms | 4988 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define llinf 8987654321987654321
#define inf 1987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
LL ans;
int cnt[100010][3], temp1, temp2;
int n;
int main()
{
scanf("%d", &n);
for(int i=1; i<=2*n; i++){
LL x, y;
scanf("%lld %lld", &x, &y);
if(x<1)ans+=1-x, x=1;
if(x>n)ans+=x-(LL)n, x=(LL)n;
if(y<1)ans+=1-y, y=1;
if(y>2)ans+=y-2, y=2;
cnt[(int)x][(int)y]++;
}
for(int i=1; i<=n; i++){
temp1+=cnt[i][1]-1;
temp2+=cnt[i][2]-1;
if(temp1>0&&temp2<0){
int t=min(temp1, -temp2);
ans+=(LL)t;
temp1-=t;
temp2+=t;
}
if(temp1<0&&temp2>0){
int t=min(-temp1, +temp2);
ans+=(LL)t;
temp1+=t;
temp2-=t;
}
ans+=llabs((LL)temp1)+llabs((LL)temp2);
}
printf("%lld", 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... |