답안 #497073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497073 2021-12-22T10:10:31 Z vinnipuh01 Coin Collecting (JOI19_ho_t4) C++17
100 / 100
177 ms 6100 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 ] ++;
	}
	mn = 0;
	for ( int i = 1; i <= n; i ++ ) {
		bl[ i ][ 1 ] --;
		if ( bl[ i ][ 1 ] > 0 ) {
			sum += bl[ i ][ 1 ];
		}
		else if ( bl[ i ][ 1 ] < 0 ) {
			mx ++;
		}
		bl[ i ][ 2 ] --;
		if ( bl[ i ][ 2 ] > 0 )
			num += bl[ i ][ 2 ];
		else if ( bl[ i ][  2] < 0 )
			mn ++;
		if ( mn && num ) {
			if ( mn < num ) {
				num -= mn;
				mn = 0;
			}
			else
				mn -= num, num = 0;
		}
		if ( mx && sum ) {
			if ( mx < sum )
				sum -= mx, mx = 0;
			else
				mx -= sum, sum = 0;
		}
		if ( mn && sum ) {
			ans += min( mn, sum );
			if ( mn < sum )
				sum -= mn, mn = 0;
			else
				mn -= sum, sum = 0;
		}
		if ( mx && num ) {
			ans += min( mx, num );
			if ( mx < num )
				num -= mx, mx = 0;
			else
				mx -= num, num = 0;
		}
		ans += num + sum + mx + mn;
	}
	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 1 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 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 0 ms 308 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 0 ms 308 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 296 KB Output is correct
43 Correct 2 ms 368 KB Output is correct
44 Correct 2 ms 316 KB Output is correct
45 Correct 2 ms 320 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 324 KB Output is correct
49 Correct 2 ms 316 KB Output is correct
50 Correct 2 ms 332 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 312 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 2 ms 332 KB Output is correct
56 Correct 2 ms 316 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 2 ms 332 KB Output is correct
59 Correct 2 ms 332 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 316 KB Output is correct
63 Correct 2 ms 332 KB Output is correct
64 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 0 ms 308 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 296 KB Output is correct
43 Correct 2 ms 368 KB Output is correct
44 Correct 2 ms 316 KB Output is correct
45 Correct 2 ms 320 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 324 KB Output is correct
49 Correct 2 ms 316 KB Output is correct
50 Correct 2 ms 332 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 312 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 2 ms 332 KB Output is correct
56 Correct 2 ms 316 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 2 ms 332 KB Output is correct
59 Correct 2 ms 332 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 316 KB Output is correct
63 Correct 2 ms 332 KB Output is correct
64 Correct 2 ms 380 KB Output is correct
65 Correct 87 ms 5896 KB Output is correct
66 Correct 171 ms 6100 KB Output is correct
67 Correct 137 ms 5932 KB Output is correct
68 Correct 150 ms 5956 KB Output is correct
69 Correct 136 ms 5920 KB Output is correct
70 Correct 132 ms 6016 KB Output is correct
71 Correct 140 ms 6016 KB Output is correct
72 Correct 127 ms 5980 KB Output is correct
73 Correct 141 ms 5968 KB Output is correct
74 Correct 134 ms 5992 KB Output is correct
75 Correct 125 ms 5952 KB Output is correct
76 Correct 162 ms 5984 KB Output is correct
77 Correct 123 ms 5968 KB Output is correct
78 Correct 151 ms 5992 KB Output is correct
79 Correct 127 ms 6000 KB Output is correct
80 Correct 130 ms 5984 KB Output is correct
81 Correct 135 ms 5996 KB Output is correct
82 Correct 143 ms 6012 KB Output is correct
83 Correct 129 ms 5944 KB Output is correct
84 Correct 128 ms 5988 KB Output is correct
85 Correct 144 ms 5956 KB Output is correct
86 Correct 126 ms 5956 KB Output is correct
87 Correct 136 ms 5920 KB Output is correct
88 Correct 126 ms 6052 KB Output is correct
89 Correct 136 ms 5988 KB Output is correct
90 Correct 156 ms 6068 KB Output is correct
91 Correct 143 ms 6092 KB Output is correct
92 Correct 145 ms 6020 KB Output is correct
93 Correct 148 ms 6100 KB Output is correct
94 Correct 134 ms 6012 KB Output is correct
95 Correct 135 ms 5976 KB Output is correct
96 Correct 159 ms 6084 KB Output is correct
97 Correct 159 ms 5956 KB Output is correct
98 Correct 139 ms 5948 KB Output is correct
99 Correct 133 ms 6012 KB Output is correct
100 Correct 177 ms 5956 KB Output is correct
101 Correct 129 ms 5956 KB Output is correct
102 Correct 157 ms 5900 KB Output is correct
103 Correct 146 ms 5920 KB Output is correct