Submission #104329

# Submission time Handle Problem Language Result Execution time Memory
104329 2019-04-05T06:23:51 Z ihdignite Coin Collecting (JOI19_ho_t4) C++14
8 / 100
166 ms 157052 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e5;
int n;
ll a1, dp[2*mxN+1][100];
array<int, 3> a[2*mxN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i=0; i<2*n; ++i) {
		cin >> a[i][0] >> a[i][2];
		a[i][1]=rand();
		if(a[i][0]<1) {
			a1+=1-a[i][0];
			a[i][0]=1;
		} else if(a[i][0]>n) {
			a1+=a[i][0]-n;
			a[i][0]=n;
		}
		if(a[i][2]<1) {
			a1+=1-a[i][2];
			a[i][2]=1;
		} else if(a[i][2]>2) {
			a1+=a[i][2]-2;
			a[i][2]=2;
		}
	}
	sort(a, a+2*n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][48]=a1;
	for(int i=0; i<2*n; ++i) {
		for(int j=max(i/2-46, 0); j<=min(i/2+46, n); ++j) {
			if(j<n)
				dp[i+1][j-(i+1)/2+49]=min(dp[i][j-i/2+48]+abs(j+1-a[i][0])+(a[i][2]!=1), dp[i+1][j-(i+1)/2+49]);
			dp[i+1][j-(i+1)/2+48]=min(dp[i][j-i/2+48]+abs(i-j+1-a[i][0])+(a[i][2]!=2), dp[i+1][j-(i+1)/2+48]);
		}
	}
	cout << dp[2*n][48];
}
# Verdict Execution time Memory Grader output
1 Correct 134 ms 156884 KB Output is correct
2 Correct 120 ms 157000 KB Output is correct
3 Correct 120 ms 156892 KB Output is correct
4 Correct 117 ms 156920 KB Output is correct
5 Correct 130 ms 156920 KB Output is correct
6 Correct 146 ms 156996 KB Output is correct
7 Correct 137 ms 156920 KB Output is correct
8 Correct 135 ms 156880 KB Output is correct
9 Correct 148 ms 156880 KB Output is correct
10 Correct 132 ms 156896 KB Output is correct
11 Correct 134 ms 156976 KB Output is correct
12 Correct 117 ms 156920 KB Output is correct
13 Correct 147 ms 156896 KB Output is correct
14 Correct 137 ms 157048 KB Output is correct
15 Correct 135 ms 156900 KB Output is correct
16 Correct 126 ms 156920 KB Output is correct
17 Correct 155 ms 156964 KB Output is correct
18 Correct 138 ms 156832 KB Output is correct
19 Correct 143 ms 156920 KB Output is correct
20 Correct 137 ms 156840 KB Output is correct
21 Correct 142 ms 156944 KB Output is correct
22 Correct 133 ms 156932 KB Output is correct
23 Correct 138 ms 156844 KB Output is correct
24 Correct 121 ms 156920 KB Output is correct
25 Correct 142 ms 156816 KB Output is correct
26 Correct 120 ms 156872 KB Output is correct
27 Correct 127 ms 156836 KB Output is correct
28 Correct 135 ms 157020 KB Output is correct
29 Correct 134 ms 156848 KB Output is correct
30 Correct 133 ms 156920 KB Output is correct
31 Correct 123 ms 156920 KB Output is correct
32 Correct 139 ms 156908 KB Output is correct
33 Correct 136 ms 156848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 156884 KB Output is correct
2 Correct 120 ms 157000 KB Output is correct
3 Correct 120 ms 156892 KB Output is correct
4 Correct 117 ms 156920 KB Output is correct
5 Correct 130 ms 156920 KB Output is correct
6 Correct 146 ms 156996 KB Output is correct
7 Correct 137 ms 156920 KB Output is correct
8 Correct 135 ms 156880 KB Output is correct
9 Correct 148 ms 156880 KB Output is correct
10 Correct 132 ms 156896 KB Output is correct
11 Correct 134 ms 156976 KB Output is correct
12 Correct 117 ms 156920 KB Output is correct
13 Correct 147 ms 156896 KB Output is correct
14 Correct 137 ms 157048 KB Output is correct
15 Correct 135 ms 156900 KB Output is correct
16 Correct 126 ms 156920 KB Output is correct
17 Correct 155 ms 156964 KB Output is correct
18 Correct 138 ms 156832 KB Output is correct
19 Correct 143 ms 156920 KB Output is correct
20 Correct 137 ms 156840 KB Output is correct
21 Correct 142 ms 156944 KB Output is correct
22 Correct 133 ms 156932 KB Output is correct
23 Correct 138 ms 156844 KB Output is correct
24 Correct 121 ms 156920 KB Output is correct
25 Correct 142 ms 156816 KB Output is correct
26 Correct 120 ms 156872 KB Output is correct
27 Correct 127 ms 156836 KB Output is correct
28 Correct 135 ms 157020 KB Output is correct
29 Correct 134 ms 156848 KB Output is correct
30 Correct 133 ms 156920 KB Output is correct
31 Correct 123 ms 156920 KB Output is correct
32 Correct 139 ms 156908 KB Output is correct
33 Correct 136 ms 156848 KB Output is correct
34 Correct 138 ms 156952 KB Output is correct
35 Correct 135 ms 156920 KB Output is correct
36 Correct 145 ms 156972 KB Output is correct
37 Correct 142 ms 157008 KB Output is correct
38 Correct 125 ms 156908 KB Output is correct
39 Correct 130 ms 156892 KB Output is correct
40 Correct 139 ms 156920 KB Output is correct
41 Correct 141 ms 157012 KB Output is correct
42 Correct 142 ms 156940 KB Output is correct
43 Correct 128 ms 156912 KB Output is correct
44 Correct 152 ms 156920 KB Output is correct
45 Correct 127 ms 156984 KB Output is correct
46 Correct 138 ms 156920 KB Output is correct
47 Correct 153 ms 156920 KB Output is correct
48 Correct 137 ms 156920 KB Output is correct
49 Correct 131 ms 156920 KB Output is correct
50 Correct 136 ms 156948 KB Output is correct
51 Correct 166 ms 156920 KB Output is correct
52 Correct 138 ms 156916 KB Output is correct
53 Correct 131 ms 156960 KB Output is correct
54 Correct 139 ms 156972 KB Output is correct
55 Correct 138 ms 157052 KB Output is correct
56 Correct 118 ms 156920 KB Output is correct
57 Incorrect 122 ms 157000 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 156884 KB Output is correct
2 Correct 120 ms 157000 KB Output is correct
3 Correct 120 ms 156892 KB Output is correct
4 Correct 117 ms 156920 KB Output is correct
5 Correct 130 ms 156920 KB Output is correct
6 Correct 146 ms 156996 KB Output is correct
7 Correct 137 ms 156920 KB Output is correct
8 Correct 135 ms 156880 KB Output is correct
9 Correct 148 ms 156880 KB Output is correct
10 Correct 132 ms 156896 KB Output is correct
11 Correct 134 ms 156976 KB Output is correct
12 Correct 117 ms 156920 KB Output is correct
13 Correct 147 ms 156896 KB Output is correct
14 Correct 137 ms 157048 KB Output is correct
15 Correct 135 ms 156900 KB Output is correct
16 Correct 126 ms 156920 KB Output is correct
17 Correct 155 ms 156964 KB Output is correct
18 Correct 138 ms 156832 KB Output is correct
19 Correct 143 ms 156920 KB Output is correct
20 Correct 137 ms 156840 KB Output is correct
21 Correct 142 ms 156944 KB Output is correct
22 Correct 133 ms 156932 KB Output is correct
23 Correct 138 ms 156844 KB Output is correct
24 Correct 121 ms 156920 KB Output is correct
25 Correct 142 ms 156816 KB Output is correct
26 Correct 120 ms 156872 KB Output is correct
27 Correct 127 ms 156836 KB Output is correct
28 Correct 135 ms 157020 KB Output is correct
29 Correct 134 ms 156848 KB Output is correct
30 Correct 133 ms 156920 KB Output is correct
31 Correct 123 ms 156920 KB Output is correct
32 Correct 139 ms 156908 KB Output is correct
33 Correct 136 ms 156848 KB Output is correct
34 Correct 138 ms 156952 KB Output is correct
35 Correct 135 ms 156920 KB Output is correct
36 Correct 145 ms 156972 KB Output is correct
37 Correct 142 ms 157008 KB Output is correct
38 Correct 125 ms 156908 KB Output is correct
39 Correct 130 ms 156892 KB Output is correct
40 Correct 139 ms 156920 KB Output is correct
41 Correct 141 ms 157012 KB Output is correct
42 Correct 142 ms 156940 KB Output is correct
43 Correct 128 ms 156912 KB Output is correct
44 Correct 152 ms 156920 KB Output is correct
45 Correct 127 ms 156984 KB Output is correct
46 Correct 138 ms 156920 KB Output is correct
47 Correct 153 ms 156920 KB Output is correct
48 Correct 137 ms 156920 KB Output is correct
49 Correct 131 ms 156920 KB Output is correct
50 Correct 136 ms 156948 KB Output is correct
51 Correct 166 ms 156920 KB Output is correct
52 Correct 138 ms 156916 KB Output is correct
53 Correct 131 ms 156960 KB Output is correct
54 Correct 139 ms 156972 KB Output is correct
55 Correct 138 ms 157052 KB Output is correct
56 Correct 118 ms 156920 KB Output is correct
57 Incorrect 122 ms 157000 KB Output isn't correct
58 Halted 0 ms 0 KB -