Submission #497964

# Submission time Handle Problem Language Result Execution time Memory
497964 2021-12-24T06:26:07 Z Nuraly_Serikbay Coin Collecting (JOI19_ho_t4) C++14
100 / 100
54 ms 5148 KB
#include <bits/stdc++.h>
  
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1  

using namespace std;
 
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

   
typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double ld;
typedef long double lld;
  
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const ll INF = 1e18 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const ld eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;
   
 
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}
 
void pre (ll a) {
    cout << fixed << setprecision(a);
    return;
}

ll n;
ll in[3][100100];
ll totalans;


inline void Solution () {
	cin >> n;
	for (int i = 1; i <= n * 2; ++ i) {
		ll x, y;
		cin >> x >> y;
		if (1 <= x && x <= n && 1 <= y && y <= 2) {
			in[y][x] ++;
			continue;
		}
		if (1 <= x && x <= n) {
			if (y < 1) totalans += 1 - y, in[1][x] ++;
			else totalans += y - 2, in[2][x] ++;
		}
		else if (1 <= y && y <= 2) {
			if (x < 1) totalans += 1 - x, in[y][1] ++;
			else totalans += x - n, in[y][n] ++;

		}
		else {
			if (x < 1 && y < 1) {
				totalans += 1 - x + 1 - y;
				in[1][1] ++;
			}
			if (x > n && y > 2) {
				totalans += x - n + y - 2;
				in[2][n] ++;
			}
			if (x > n && y < 1) {
				totalans += x - n + 1 - y;
				in[1][n] ++;
			}
			if (x < 1 && y > 2) {
				totalans += 1 - x + y - 2;
				in[2][1] ++;
			}
		}	
	}
	ll a, b = 0;
	a = b;
	for (int i = 1; i <= n; ++ i) {
		a += in[1][i] - 1;
		b += in[2][i] - 1;
		ll mn = min (abs(a), abs(b));
		if (a < 0 && b > 0) {
			totalans += mn;
			b -= mn;
			a += mn;	
		}
		else if (a > 0 && b < 0) {
			totalans += mn;
			b += mn;
			a -= mn;
		}
		totalans += abs(a) + abs(b);
	}
	cout << totalans;
	return;
}
 
 
int main () {
	YOSIK();
	Solution ();
	exit (0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 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 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 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 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 376 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 444 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 2 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 2 ms 352 KB Output is correct
57 Correct 1 ms 356 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 372 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 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 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 376 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 444 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 2 ms 336 KB Output is correct
53 Correct 2 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 2 ms 352 KB Output is correct
57 Correct 1 ms 356 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 372 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 25 ms 3396 KB Output is correct
66 Correct 54 ms 4908 KB Output is correct
67 Correct 45 ms 5056 KB Output is correct
68 Correct 44 ms 5060 KB Output is correct
69 Correct 46 ms 5052 KB Output is correct
70 Correct 41 ms 4928 KB Output is correct
71 Correct 44 ms 4928 KB Output is correct
72 Correct 44 ms 3496 KB Output is correct
73 Correct 39 ms 3504 KB Output is correct
74 Correct 38 ms 3512 KB Output is correct
75 Correct 41 ms 3384 KB Output is correct
76 Correct 40 ms 3520 KB Output is correct
77 Correct 47 ms 3404 KB Output is correct
78 Correct 39 ms 3524 KB Output is correct
79 Correct 41 ms 3544 KB Output is correct
80 Correct 37 ms 3532 KB Output is correct
81 Correct 39 ms 3528 KB Output is correct
82 Correct 40 ms 3576 KB Output is correct
83 Correct 36 ms 3524 KB Output is correct
84 Correct 39 ms 4140 KB Output is correct
85 Correct 40 ms 4148 KB Output is correct
86 Correct 39 ms 5044 KB Output is correct
87 Correct 42 ms 4916 KB Output is correct
88 Correct 39 ms 5148 KB Output is correct
89 Correct 44 ms 5048 KB Output is correct
90 Correct 47 ms 5052 KB Output is correct
91 Correct 42 ms 5056 KB Output is correct
92 Correct 46 ms 4280 KB Output is correct
93 Correct 43 ms 5052 KB Output is correct
94 Correct 43 ms 4916 KB Output is correct
95 Correct 43 ms 4148 KB Output is correct
96 Correct 43 ms 4036 KB Output is correct
97 Correct 36 ms 4040 KB Output is correct
98 Correct 36 ms 4416 KB Output is correct
99 Correct 51 ms 4164 KB Output is correct
100 Correct 44 ms 3864 KB Output is correct
101 Correct 38 ms 3976 KB Output is correct
102 Correct 43 ms 4296 KB Output is correct
103 Correct 43 ms 4212 KB Output is correct