Submission #237245

# Submission time Handle Problem Language Result Execution time Memory
237245 2020-06-05T12:06:32 Z _7_7_ Coin Collecting (JOI19_ho_t4) C++14
100 / 100
287 ms 9976 KB
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, x[N], y[N], ans, cnt[N][2];
deque < int > need[2], have[2];

main () {
	cin >> n;
	for (int i = 1; i <= n + n; ++i) {
	    cin >> x[i] >> y[i];
		if (x[i] > n) {
			ans += x[i] - n;
			x[i] = n;
		}
		if (x[i] < 1) {
			ans += 1 - x[i];
			x[i] = 1;
		}
		if (y[i] > 2) {
			ans += y[i] - 2;
			y[i] = 2;
		}
		if (y[i] < 1) {
			ans += 1 - y[i];
			y[i] = 1;
		}

		--y[i];
		++cnt[x[i]][y[i]];
	}


	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 2; ++j) {
			for (int x = 0; x < cnt[i][j]; ++x)
				 have[j].pb(i);
			need[j].pb(i);
			while (sz(need[j]) && sz(have[j])) {
				ans += abs(need[j].front() - have[j].front());
				need[j].pop_front();
				have[j].pop_front();
			}
		}
		
		for (int j = 0; j < 2; ++j) {
			while (sz(need[j ^ 1]) && sz(have[j])) {
				ans += abs(need[j ^ 1].front() - have[j].front()) + 1;
				have[j].pop_front();
				need[j ^ 1].pop_front();
			} 
		}
	}

	cout << ans << endl;
}

Compilation message

joi2019_ho_t4.cpp:42:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 8 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 7 ms 384 KB Output is correct
39 Correct 7 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 6 ms 384 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 7 ms 384 KB Output is correct
45 Correct 6 ms 384 KB Output is correct
46 Correct 6 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 7 ms 384 KB Output is correct
49 Correct 7 ms 384 KB Output is correct
50 Correct 7 ms 384 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 7 ms 384 KB Output is correct
54 Correct 7 ms 384 KB Output is correct
55 Correct 7 ms 384 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 7 ms 384 KB Output is correct
59 Correct 7 ms 384 KB Output is correct
60 Correct 6 ms 384 KB Output is correct
61 Correct 7 ms 384 KB Output is correct
62 Correct 6 ms 384 KB Output is correct
63 Correct 7 ms 512 KB Output is correct
64 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 8 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 7 ms 384 KB Output is correct
39 Correct 7 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 6 ms 384 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 7 ms 384 KB Output is correct
45 Correct 6 ms 384 KB Output is correct
46 Correct 6 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 7 ms 384 KB Output is correct
49 Correct 7 ms 384 KB Output is correct
50 Correct 7 ms 384 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 7 ms 384 KB Output is correct
54 Correct 7 ms 384 KB Output is correct
55 Correct 7 ms 384 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 7 ms 384 KB Output is correct
59 Correct 7 ms 384 KB Output is correct
60 Correct 6 ms 384 KB Output is correct
61 Correct 7 ms 384 KB Output is correct
62 Correct 6 ms 384 KB Output is correct
63 Correct 7 ms 512 KB Output is correct
64 Correct 6 ms 384 KB Output is correct
65 Correct 138 ms 6520 KB Output is correct
66 Correct 287 ms 9720 KB Output is correct
67 Correct 222 ms 8152 KB Output is correct
68 Correct 227 ms 8184 KB Output is correct
69 Correct 227 ms 8184 KB Output is correct
70 Correct 236 ms 8284 KB Output is correct
71 Correct 232 ms 8248 KB Output is correct
72 Correct 217 ms 8440 KB Output is correct
73 Correct 217 ms 9080 KB Output is correct
74 Correct 218 ms 7544 KB Output is correct
75 Correct 212 ms 7544 KB Output is correct
76 Correct 216 ms 7288 KB Output is correct
77 Correct 215 ms 7672 KB Output is correct
78 Correct 223 ms 7288 KB Output is correct
79 Correct 217 ms 7544 KB Output is correct
80 Correct 218 ms 7544 KB Output is correct
81 Correct 225 ms 7672 KB Output is correct
82 Correct 214 ms 6964 KB Output is correct
83 Correct 217 ms 7032 KB Output is correct
84 Correct 217 ms 7288 KB Output is correct
85 Correct 221 ms 7032 KB Output is correct
86 Correct 217 ms 8312 KB Output is correct
87 Correct 220 ms 8184 KB Output is correct
88 Correct 224 ms 8312 KB Output is correct
89 Correct 228 ms 8184 KB Output is correct
90 Correct 233 ms 8372 KB Output is correct
91 Correct 232 ms 8188 KB Output is correct
92 Correct 233 ms 8312 KB Output is correct
93 Correct 225 ms 8312 KB Output is correct
94 Correct 212 ms 8164 KB Output is correct
95 Correct 214 ms 8056 KB Output is correct
96 Correct 225 ms 9976 KB Output is correct
97 Correct 222 ms 9848 KB Output is correct
98 Correct 223 ms 8572 KB Output is correct
99 Correct 226 ms 8572 KB Output is correct
100 Correct 220 ms 8688 KB Output is correct
101 Correct 232 ms 9604 KB Output is correct
102 Correct 224 ms 8392 KB Output is correct
103 Correct 225 ms 8184 KB Output is correct