답안 #497029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497029 2021-12-22T08:51:13 Z vinnipuh01 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 204 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
 
using namespace std;
 
const long long oo = 1000000000000000000;
 
long long  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    freopen ( "sum.in", "r", stdin )
*/
 
int bl[ 1000001 ][ 3 ];
queue <pair<int, int> > q, qq;
 
int d( int x, int y, int xx, int yy ) {
	return abs( x - xx ) + abs( y - yy );
}
 
main () {
	int n;
	cin >> n;
	pair<int, int> a[ n + n + 1 ];
	int y, x;
	int x1, y1, x2, y2, x3, y3, x4, y4;
	x1 = y1 = 1;
	x2 = 1, y2 = 2;
	x3 = n, y3 = 1;
	x4 = n, y4 = 2;
	for ( int i = 1; i <= n + n; i ++ ) {
		cin >> a[ i ].first >> a[ i ].second;
		if ( a[ i ].second <= 1 ) {
			y = 1;
			if ( a[ i ].first >= 1 && a[ i ].first <= n )
				x = a[ i ].first;
			else {
				if ( a[ i ].first < 1 )
					x = 1;
				else	
					x = n;
			}
		}
		else {
			y = 2;
			if ( a[ i ].first >= 1 && a[ i ].first <= n )
				x = a[ i ].first;
			else {
				if ( a[ i ].first < 1 )
					x = 1;
				else	
					x = n;
			}
		}
		ans += d( x, y, a[ i ].first, a[ i ].second );
		bl[ x ][ y ] ++;
	}
	for ( int i = 1; i <= n; i ++ ) {
		for ( int j = 1; j <= 2; j ++ ) {
			if ( !bl[ i ][ j ] ) {
				if ( j == 1 )
					q.push( { i, j } );
				else
					qq.push( { i, j } );
			}
		}
	}
	for ( int i = 1; i <= n; i ++ ) {
		for ( int j = 1; j <= 2; j ++ ) {
			while ( bl[ i ][ j ] > 1 ) {
				if ( j == 1 ) {
					if ( q.size() && q.front().first <= i ) {
						bl[ i ][ j ] --;
						ans += d( i, j, q.front().first, q.front().second );
						q.pop();
						continue;
					}
					if ( q.size() && q.front().first > i ) {
						ans += d( i, j, q.front().first, q.front().second );
						bl[ i ][ j ] --;
						q.pop();
						continue;
					}
					if ( qq.size() && qq.front().first <= i ) {
						bl[ i ][ j ] --;
						ans += d( i, j, qq.front().first, qq.front().second );
						qq.pop();
						continue;
					}
					if ( qq.size() && qq.front().first > i ) {
						ans += d( i, j, qq.front().first, qq.front().second );
						bl[ i ][ j ] --;
						qq.pop();
						continue;
					}
				}
				else {
					if ( qq.size() && qq.front().first <= i ) {
						ans += d( i, j, qq.front().first, qq.front().second );
						bl[ i ][ j ] --;
						qq.pop();
						continue;
					}
					if ( qq.size() && qq.front().first >= i ) {
						ans += d( i, j, qq.front().first, qq.front().second );
						bl[ i ][ j ] --;
						qq.pop();
						continue;
					}
					if ( q.size() && q.front().first <= i ) {
						ans += d( i, j, q.front().first, q.front().second );
						bl[ i ][ j ] --;
						q.pop();
						continue;
					}
					if ( q.size() && q.front().first >= i ) {
						ans += d( i, j, q.front().first, q.front().second );
						bl[ i ][ j ] --;
						q.pop();
						continue;
					}
				}
			}
		}
	}
	cout << ans;
}

Compilation message

joi2019_ho_t4.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main () {
      | ^~~~
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:58:6: warning: variable 'x1' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |      ^~
joi2019_ho_t4.cpp:58:14: warning: variable 'x2' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |              ^~
joi2019_ho_t4.cpp:58:18: warning: variable 'y2' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |                  ^~
joi2019_ho_t4.cpp:58:22: warning: variable 'x3' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |                      ^~
joi2019_ho_t4.cpp:58:26: warning: variable 'y3' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |                          ^~
joi2019_ho_t4.cpp:58:30: warning: variable 'x4' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |                              ^~
joi2019_ho_t4.cpp:58:34: warning: variable 'y4' set but not used [-Wunused-but-set-variable]
   58 |  int x1, y1, x2, y2, x3, y3, x4, y4;
      |                                  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -