Submission #532972

# Submission time Handle Problem Language Result Execution time Memory
532972 2022-03-04T09:35:06 Z amunduzbaev Coin Collecting (JOI19_ho_t4) C++17
8 / 100
176 ms 8524 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n; n <<= 1;
	vector<ar<int, 2>> a(n), b(n);
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
		b[i][0] = i / 2 + 1, b[i][1] = (i&1) + 1;
	}
	vector<int> dp(1 << n, 1e15);
	dp[0] = 0;
	for(int mask=1;mask < (1 << n);mask++){
		int in = __builtin_popcount(mask) - 1;
		for(int i=0;i<n;i++){
			if(mask >> i & 1){
				dp[mask] = min(dp[mask], dp[mask ^ (1 << i)] + 
				abs(a[i][0] - b[in][0]) + abs(a[i][1] - b[in][1]));
			}
		}
	}
	
	cout<<dp[(1 << n) - 1]<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 75 ms 8500 KB Output is correct
5 Correct 74 ms 8524 KB Output is correct
6 Correct 73 ms 8524 KB Output is correct
7 Correct 74 ms 8524 KB Output is correct
8 Correct 78 ms 8524 KB Output is correct
9 Correct 77 ms 8524 KB Output is correct
10 Correct 73 ms 8504 KB Output is correct
11 Correct 75 ms 8524 KB Output is correct
12 Correct 74 ms 8524 KB Output is correct
13 Correct 72 ms 8524 KB Output is correct
14 Correct 78 ms 8432 KB Output is correct
15 Correct 77 ms 8524 KB Output is correct
16 Correct 75 ms 8524 KB Output is correct
17 Correct 73 ms 8524 KB Output is correct
18 Correct 74 ms 8524 KB Output is correct
19 Correct 75 ms 8524 KB Output is correct
20 Correct 72 ms 8524 KB Output is correct
21 Correct 73 ms 8524 KB Output is correct
22 Correct 73 ms 8524 KB Output is correct
23 Correct 74 ms 8524 KB Output is correct
24 Correct 72 ms 8504 KB Output is correct
25 Correct 75 ms 8524 KB Output is correct
26 Correct 73 ms 8524 KB Output is correct
27 Correct 75 ms 8500 KB Output is correct
28 Correct 97 ms 8512 KB Output is correct
29 Correct 89 ms 8524 KB Output is correct
30 Correct 78 ms 8524 KB Output is correct
31 Correct 82 ms 8524 KB Output is correct
32 Correct 77 ms 8524 KB Output is correct
33 Correct 95 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 75 ms 8500 KB Output is correct
5 Correct 74 ms 8524 KB Output is correct
6 Correct 73 ms 8524 KB Output is correct
7 Correct 74 ms 8524 KB Output is correct
8 Correct 78 ms 8524 KB Output is correct
9 Correct 77 ms 8524 KB Output is correct
10 Correct 73 ms 8504 KB Output is correct
11 Correct 75 ms 8524 KB Output is correct
12 Correct 74 ms 8524 KB Output is correct
13 Correct 72 ms 8524 KB Output is correct
14 Correct 78 ms 8432 KB Output is correct
15 Correct 77 ms 8524 KB Output is correct
16 Correct 75 ms 8524 KB Output is correct
17 Correct 73 ms 8524 KB Output is correct
18 Correct 74 ms 8524 KB Output is correct
19 Correct 75 ms 8524 KB Output is correct
20 Correct 72 ms 8524 KB Output is correct
21 Correct 73 ms 8524 KB Output is correct
22 Correct 73 ms 8524 KB Output is correct
23 Correct 74 ms 8524 KB Output is correct
24 Correct 72 ms 8504 KB Output is correct
25 Correct 75 ms 8524 KB Output is correct
26 Correct 73 ms 8524 KB Output is correct
27 Correct 75 ms 8500 KB Output is correct
28 Correct 97 ms 8512 KB Output is correct
29 Correct 89 ms 8524 KB Output is correct
30 Correct 78 ms 8524 KB Output is correct
31 Correct 82 ms 8524 KB Output is correct
32 Correct 77 ms 8524 KB Output is correct
33 Correct 95 ms 8524 KB Output is correct
34 Incorrect 176 ms 832 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 75 ms 8500 KB Output is correct
5 Correct 74 ms 8524 KB Output is correct
6 Correct 73 ms 8524 KB Output is correct
7 Correct 74 ms 8524 KB Output is correct
8 Correct 78 ms 8524 KB Output is correct
9 Correct 77 ms 8524 KB Output is correct
10 Correct 73 ms 8504 KB Output is correct
11 Correct 75 ms 8524 KB Output is correct
12 Correct 74 ms 8524 KB Output is correct
13 Correct 72 ms 8524 KB Output is correct
14 Correct 78 ms 8432 KB Output is correct
15 Correct 77 ms 8524 KB Output is correct
16 Correct 75 ms 8524 KB Output is correct
17 Correct 73 ms 8524 KB Output is correct
18 Correct 74 ms 8524 KB Output is correct
19 Correct 75 ms 8524 KB Output is correct
20 Correct 72 ms 8524 KB Output is correct
21 Correct 73 ms 8524 KB Output is correct
22 Correct 73 ms 8524 KB Output is correct
23 Correct 74 ms 8524 KB Output is correct
24 Correct 72 ms 8504 KB Output is correct
25 Correct 75 ms 8524 KB Output is correct
26 Correct 73 ms 8524 KB Output is correct
27 Correct 75 ms 8500 KB Output is correct
28 Correct 97 ms 8512 KB Output is correct
29 Correct 89 ms 8524 KB Output is correct
30 Correct 78 ms 8524 KB Output is correct
31 Correct 82 ms 8524 KB Output is correct
32 Correct 77 ms 8524 KB Output is correct
33 Correct 95 ms 8524 KB Output is correct
34 Incorrect 176 ms 832 KB Output isn't correct
35 Halted 0 ms 0 KB -