# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
211842 | DodgeBallMan | Coin Collecting (JOI19_ho_t4) | C++14 | 121 ms | 9056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = 1e5 + 10;
int n;
int coin[N][2];
vector<long> b[2], emp[2];
long ans;
int main()
{
scanf("%d",&n);
for( int i = 0, x, y ; i < 2*n ; i++ ) {
scanf("%d %d",&x,&y);
if( x < 1 ) ans += 1 - x, x = 1;
if( x > n ) ans += x - n, x = n;
if( y < 1 ) ans += 1 - y, y = 1;
if( y > 2 ) ans += y - 2, y = 2;
coin[--x][--y]++;
}
for( int i = 0 ; i < n ; i++ ) for( int j = 0 ; j < 2 ; j++ ) if( !coin[i][j] ) emp[j].emplace_back( i );
sort( emp[0].begin(), emp[0].end(), greater<int>() ), sort( emp[1].begin(), emp[1].end(), greater<int>() );
for( int i = 0 ; i < n ; i++ ) {
for( int j = 0 ; j < 2 ; j++ ) if( !b[j].empty() ) {
if( coin[i][j] == 0 ) {
ans += i - b[j].back();
b[j].pop_back(), emp[j].pop_back();
coin[i][j]++;
}
if( !coin[i][j^1] && !b[j].empty() && b[j^1].empty() ) {
ans += i - b[j].back() + 1;
b[j].pop_back(), emp[j^1].pop_back();
coin[i][j^1]++;
}
}
for( int j = 0 ; j < 2 ; j++ ) {
while( coin[i][j] > 1 ) {
if( !emp[j].empty() && emp[j].back() <= i ) {
ans += i - emp[j].back();
emp[j].pop_back();
}
else if( !emp[j^1].empty() && emp[1^j].back() <= i ) {
if( coin[i][j^1] > 1 ) {
coin[i][j^1]--;
ans += i - emp[j^1].back();
emp[j^1].pop_back();
continue ;
}
ans += i - emp[j^1].back() + 1;
emp[j^1].pop_back();
}
else b[j].emplace_back( i );
coin[i][j]--;
}
}
}
printf("%lld",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... |