Submission #99052

# Submission time Handle Problem Language Result Execution time Memory
99052 2019-02-28T08:12:18 Z 구재현(#2854, gs14004) Coin Collecting (JOI19_ho_t4) C++17
37 / 100
90 ms 32128 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
using lint = long long;
using pi = pair<int, int>;

struct pnt{
	int x, y;
	bool operator<(const pnt &p)const{
		return pi(x, y) < pi(p.x, p.y);
	}
}a[MAXN];

int n;
lint dp[MAXN][MAXN];
int cnt[3][MAXN];

int dist(pnt a, pi b){
	return abs(a.y - b.first) + abs(a.x - b.second);
}

lint f(int l, int r){
	if(l == n + 1 && r == n + 1) return 0;
	if(~dp[l][r]) return dp[l][r];
	lint ret = 1e18;
	if(l < n + 1){
		ret = min(ret, dist(a[l+r-2], pi(1, l)) + f(l + 1, r));
	}
	if(r < n + 1){
		ret = min(ret, dist(a[l+r-2], pi(2, r)) + f(l, r + 1));
	}
	return dp[l][r] = ret;
}

int main(){
	scanf("%d",&n);
	memset(dp, -1, sizeof(dp));
	lint cdap = 0;
	for(int i=0; i<n*2; i++){
		scanf("%d %d",&a[i].x,&a[i].y);
		if(a[i].x < 1){
			cdap += 1 - a[i].x;
			a[i].x = 1;
		}
		if(a[i].x > n){
			cdap += a[i].x - n;
			a[i].x = n;
		}
		if(a[i].y < 1){
			cdap += 1 - a[i].y;
			a[i].y = 1;
		}
		if(a[i].y > 2){
			cdap += a[i].y - 2;
			a[i].y = 2;
		}
		cnt[a[i].y][a[i].x]++;
	}
	sort(a, a + n + n);
	cout << cdap + f(1, 1) << endl;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
joi2019_ho_t4.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].x,&a[i].y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31864 KB Output is correct
2 Correct 24 ms 31736 KB Output is correct
3 Correct 27 ms 31844 KB Output is correct
4 Correct 28 ms 31872 KB Output is correct
5 Correct 32 ms 31864 KB Output is correct
6 Correct 31 ms 31872 KB Output is correct
7 Correct 90 ms 31736 KB Output is correct
8 Correct 29 ms 31872 KB Output is correct
9 Correct 25 ms 31864 KB Output is correct
10 Correct 25 ms 31872 KB Output is correct
11 Correct 28 ms 31736 KB Output is correct
12 Correct 26 ms 31744 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 28 ms 31872 KB Output is correct
15 Correct 27 ms 31872 KB Output is correct
16 Correct 32 ms 31864 KB Output is correct
17 Correct 29 ms 31864 KB Output is correct
18 Correct 30 ms 31744 KB Output is correct
19 Correct 28 ms 31736 KB Output is correct
20 Correct 26 ms 31872 KB Output is correct
21 Correct 28 ms 31744 KB Output is correct
22 Correct 32 ms 31812 KB Output is correct
23 Correct 30 ms 31736 KB Output is correct
24 Correct 27 ms 32000 KB Output is correct
25 Correct 29 ms 31864 KB Output is correct
26 Correct 25 ms 31872 KB Output is correct
27 Correct 27 ms 31736 KB Output is correct
28 Correct 27 ms 31736 KB Output is correct
29 Correct 27 ms 31864 KB Output is correct
30 Correct 30 ms 31736 KB Output is correct
31 Correct 28 ms 31744 KB Output is correct
32 Correct 26 ms 31872 KB Output is correct
33 Correct 28 ms 31732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31864 KB Output is correct
2 Correct 24 ms 31736 KB Output is correct
3 Correct 27 ms 31844 KB Output is correct
4 Correct 28 ms 31872 KB Output is correct
5 Correct 32 ms 31864 KB Output is correct
6 Correct 31 ms 31872 KB Output is correct
7 Correct 90 ms 31736 KB Output is correct
8 Correct 29 ms 31872 KB Output is correct
9 Correct 25 ms 31864 KB Output is correct
10 Correct 25 ms 31872 KB Output is correct
11 Correct 28 ms 31736 KB Output is correct
12 Correct 26 ms 31744 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 28 ms 31872 KB Output is correct
15 Correct 27 ms 31872 KB Output is correct
16 Correct 32 ms 31864 KB Output is correct
17 Correct 29 ms 31864 KB Output is correct
18 Correct 30 ms 31744 KB Output is correct
19 Correct 28 ms 31736 KB Output is correct
20 Correct 26 ms 31872 KB Output is correct
21 Correct 28 ms 31744 KB Output is correct
22 Correct 32 ms 31812 KB Output is correct
23 Correct 30 ms 31736 KB Output is correct
24 Correct 27 ms 32000 KB Output is correct
25 Correct 29 ms 31864 KB Output is correct
26 Correct 25 ms 31872 KB Output is correct
27 Correct 27 ms 31736 KB Output is correct
28 Correct 27 ms 31736 KB Output is correct
29 Correct 27 ms 31864 KB Output is correct
30 Correct 30 ms 31736 KB Output is correct
31 Correct 28 ms 31744 KB Output is correct
32 Correct 26 ms 31872 KB Output is correct
33 Correct 28 ms 31732 KB Output is correct
34 Correct 44 ms 31864 KB Output is correct
35 Correct 55 ms 32000 KB Output is correct
36 Correct 47 ms 31992 KB Output is correct
37 Correct 46 ms 32000 KB Output is correct
38 Correct 51 ms 32000 KB Output is correct
39 Correct 44 ms 31992 KB Output is correct
40 Correct 45 ms 32000 KB Output is correct
41 Correct 40 ms 31964 KB Output is correct
42 Correct 45 ms 31992 KB Output is correct
43 Correct 49 ms 31992 KB Output is correct
44 Correct 49 ms 32128 KB Output is correct
45 Correct 45 ms 31864 KB Output is correct
46 Correct 46 ms 31992 KB Output is correct
47 Correct 42 ms 31992 KB Output is correct
48 Correct 46 ms 32000 KB Output is correct
49 Correct 41 ms 32120 KB Output is correct
50 Correct 51 ms 31992 KB Output is correct
51 Correct 48 ms 31988 KB Output is correct
52 Correct 47 ms 31996 KB Output is correct
53 Correct 54 ms 31864 KB Output is correct
54 Correct 44 ms 32120 KB Output is correct
55 Correct 42 ms 31992 KB Output is correct
56 Correct 51 ms 31868 KB Output is correct
57 Correct 51 ms 32000 KB Output is correct
58 Correct 50 ms 32020 KB Output is correct
59 Correct 41 ms 31992 KB Output is correct
60 Correct 45 ms 31972 KB Output is correct
61 Correct 44 ms 32072 KB Output is correct
62 Correct 44 ms 31992 KB Output is correct
63 Correct 57 ms 31992 KB Output is correct
64 Correct 45 ms 31992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31864 KB Output is correct
2 Correct 24 ms 31736 KB Output is correct
3 Correct 27 ms 31844 KB Output is correct
4 Correct 28 ms 31872 KB Output is correct
5 Correct 32 ms 31864 KB Output is correct
6 Correct 31 ms 31872 KB Output is correct
7 Correct 90 ms 31736 KB Output is correct
8 Correct 29 ms 31872 KB Output is correct
9 Correct 25 ms 31864 KB Output is correct
10 Correct 25 ms 31872 KB Output is correct
11 Correct 28 ms 31736 KB Output is correct
12 Correct 26 ms 31744 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 28 ms 31872 KB Output is correct
15 Correct 27 ms 31872 KB Output is correct
16 Correct 32 ms 31864 KB Output is correct
17 Correct 29 ms 31864 KB Output is correct
18 Correct 30 ms 31744 KB Output is correct
19 Correct 28 ms 31736 KB Output is correct
20 Correct 26 ms 31872 KB Output is correct
21 Correct 28 ms 31744 KB Output is correct
22 Correct 32 ms 31812 KB Output is correct
23 Correct 30 ms 31736 KB Output is correct
24 Correct 27 ms 32000 KB Output is correct
25 Correct 29 ms 31864 KB Output is correct
26 Correct 25 ms 31872 KB Output is correct
27 Correct 27 ms 31736 KB Output is correct
28 Correct 27 ms 31736 KB Output is correct
29 Correct 27 ms 31864 KB Output is correct
30 Correct 30 ms 31736 KB Output is correct
31 Correct 28 ms 31744 KB Output is correct
32 Correct 26 ms 31872 KB Output is correct
33 Correct 28 ms 31732 KB Output is correct
34 Correct 44 ms 31864 KB Output is correct
35 Correct 55 ms 32000 KB Output is correct
36 Correct 47 ms 31992 KB Output is correct
37 Correct 46 ms 32000 KB Output is correct
38 Correct 51 ms 32000 KB Output is correct
39 Correct 44 ms 31992 KB Output is correct
40 Correct 45 ms 32000 KB Output is correct
41 Correct 40 ms 31964 KB Output is correct
42 Correct 45 ms 31992 KB Output is correct
43 Correct 49 ms 31992 KB Output is correct
44 Correct 49 ms 32128 KB Output is correct
45 Correct 45 ms 31864 KB Output is correct
46 Correct 46 ms 31992 KB Output is correct
47 Correct 42 ms 31992 KB Output is correct
48 Correct 46 ms 32000 KB Output is correct
49 Correct 41 ms 32120 KB Output is correct
50 Correct 51 ms 31992 KB Output is correct
51 Correct 48 ms 31988 KB Output is correct
52 Correct 47 ms 31996 KB Output is correct
53 Correct 54 ms 31864 KB Output is correct
54 Correct 44 ms 32120 KB Output is correct
55 Correct 42 ms 31992 KB Output is correct
56 Correct 51 ms 31868 KB Output is correct
57 Correct 51 ms 32000 KB Output is correct
58 Correct 50 ms 32020 KB Output is correct
59 Correct 41 ms 31992 KB Output is correct
60 Correct 45 ms 31972 KB Output is correct
61 Correct 44 ms 32072 KB Output is correct
62 Correct 44 ms 31992 KB Output is correct
63 Correct 57 ms 31992 KB Output is correct
64 Correct 45 ms 31992 KB Output is correct
65 Execution timed out 30 ms 31992 KB Time limit exceeded (wall clock)
66 Halted 0 ms 0 KB -