답안 #59821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59821 2018-07-23T07:28:47 Z 김세빈(#1725) Cultivation (JOI17_cultivation) C++11
30 / 100
2000 ms 1132 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

pll P[333];
ll K[666][666], L[333], R[333];
ll n, h, w, ans = 1e18;

ll check(ll l, ll r)
{
	ll x, y, d, i, j, s, e, t, prev;
	
//	printf("%lld %lld\n", l, r);
	
	vector <ll> X, Y;
	
	for(i=1; i<=n; i++){
		x = P[i].first - l;
		X.push_back(x);
		x = P[i].first + r + 1;
		X.push_back(x);
		Y.push_back(P[i].second);
	}
	
	X.push_back(1); Y.push_back(1);
	X.push_back(h); Y.push_back(w);
	
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	
	sort(Y.begin(), Y.end());
	Y.erase(unique(Y.begin(), Y.end()), Y.end());
	
	for(i=1; i<=X.size(); i++){
		for(j=1; j<=Y.size(); j++){
			K[i][j] = 0;
		}
	}
	
	for(i=1; i<=n; i++){
		s = lower_bound(X.begin(), X.end(), P[i].first - l) - X.begin() + 1;
		e = lower_bound(X.begin(), X.end(), P[i].first + r + 1) - X.begin() + 1;
		y = lower_bound(Y.begin(), Y.end(), P[i].second) - Y.begin() + 1;
		for(j=s; j<e; j++) K[j][y] = i;
	}
	
	s = lower_bound(X.begin(), X.end(), 1) - X.begin() + 1;
	e = lower_bound(X.begin(), X.end(), h) - X.begin() + 1;
	
	x = y = d = 0;
	
	for(i=s; i<=e; i++){
		prev = -1;
		for(j=1; j<=Y.size(); j++){
			if(K[i][j]){
				t = K[i][j];
				if(prev == -1) x = max(x, P[t].second - 1);
				else d = max(d, P[t].second - P[prev].second - 1);
				prev = t;
			}
		}
		if(prev == -1) return 1e18;
		y = max(y, w - P[prev].second);
	}
	
//	printf("%lld %lld %lld\n", x, y, d);
	
	return x + y + max(0ll, d - x - y);
}

int main()
{
	ll i, j, k;
	
	scanf("%lld%lld%lld", &h, &w, &n);
	for(i=1; i<=n; i++){
		scanf("%lld%lld", &P[i].first, &P[i].second);
	}
	
	sort(P + 1, P + n + 1);
	
	for(i=1; i<=n; i++){
		L[i] = P[i].first - 1;
		for(j=1; j<i; j++){
			if(P[j].second == P[i].second) L[i] = P[i].first - P[j].first - 1;
		}
		
		R[i] = h - P[i].first;
		for(j=n; j>i; j--){
			if(P[j].second == P[i].second) R[i] = P[j].first - P[i].first - 1;
		}
	}
	
	for(i=0; i<=h; i++){
		for(j=0; j<=h; j++){
			k = check(i, j) + i + j;
			ans = min(ans, k);
		}
	}
/*	
	for(i=1; i<=n; i++){
		for(j=1; j<=n; j++){
			k = check(L[i], R[j]) + L[i] + R[j];
			ans = min(ans, k);
			
			if(L[i] >= R[j]) k = check(L[i] - R[j], R[j]) + L[i];
			ans = min(ans, k);
			
			if(L[i] <= R[j]) k = check(L[i], R[j] - L[i]) + R[j];
			ans = min(ans, k);
		}
	}
*/	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

cultivation.cpp: In function 'll check(ll, ll)':
cultivation.cpp:37:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=1; i<=X.size(); i++){
           ~^~~~~~~~~~
cultivation.cpp:38:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=1; j<=Y.size(); j++){
            ~^~~~~~~~~~
cultivation.cpp:57:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=1; j<=Y.size(); j++){
            ~^~~~~~~~~~
cultivation.cpp: In function 'int main()':
cultivation.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &h, &w, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &P[i].first, &P[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
6 Correct 3 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 2 ms 648 KB Output is correct
15 Correct 3 ms 648 KB Output is correct
16 Correct 4 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
6 Correct 3 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 2 ms 648 KB Output is correct
15 Correct 3 ms 648 KB Output is correct
16 Correct 4 ms 648 KB Output is correct
17 Correct 4 ms 648 KB Output is correct
18 Correct 15 ms 888 KB Output is correct
19 Correct 17 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 29 ms 888 KB Output is correct
22 Correct 54 ms 1004 KB Output is correct
23 Correct 12 ms 1004 KB Output is correct
24 Correct 83 ms 1004 KB Output is correct
25 Correct 64 ms 1004 KB Output is correct
26 Correct 127 ms 1004 KB Output is correct
27 Correct 140 ms 1004 KB Output is correct
28 Correct 91 ms 1004 KB Output is correct
29 Correct 110 ms 1004 KB Output is correct
30 Correct 141 ms 1004 KB Output is correct
31 Correct 128 ms 1116 KB Output is correct
32 Correct 130 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
6 Correct 3 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 2 ms 648 KB Output is correct
15 Correct 3 ms 648 KB Output is correct
16 Correct 4 ms 648 KB Output is correct
17 Correct 4 ms 648 KB Output is correct
18 Correct 15 ms 888 KB Output is correct
19 Correct 17 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 29 ms 888 KB Output is correct
22 Correct 54 ms 1004 KB Output is correct
23 Correct 12 ms 1004 KB Output is correct
24 Correct 83 ms 1004 KB Output is correct
25 Correct 64 ms 1004 KB Output is correct
26 Correct 127 ms 1004 KB Output is correct
27 Correct 140 ms 1004 KB Output is correct
28 Correct 91 ms 1004 KB Output is correct
29 Correct 110 ms 1004 KB Output is correct
30 Correct 141 ms 1004 KB Output is correct
31 Correct 128 ms 1116 KB Output is correct
32 Correct 130 ms 1116 KB Output is correct
33 Correct 4 ms 1116 KB Output is correct
34 Correct 157 ms 1132 KB Output is correct
35 Correct 202 ms 1132 KB Output is correct
36 Correct 229 ms 1132 KB Output is correct
37 Correct 147 ms 1132 KB Output is correct
38 Correct 226 ms 1132 KB Output is correct
39 Correct 222 ms 1132 KB Output is correct
40 Correct 278 ms 1132 KB Output is correct
41 Correct 127 ms 1132 KB Output is correct
42 Correct 160 ms 1132 KB Output is correct
43 Correct 202 ms 1132 KB Output is correct
44 Correct 181 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2047 ms 1132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2047 ms 1132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 2 ms 648 KB Output is correct
6 Correct 3 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 2 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 3 ms 648 KB Output is correct
12 Correct 2 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 2 ms 648 KB Output is correct
15 Correct 3 ms 648 KB Output is correct
16 Correct 4 ms 648 KB Output is correct
17 Correct 4 ms 648 KB Output is correct
18 Correct 15 ms 888 KB Output is correct
19 Correct 17 ms 888 KB Output is correct
20 Correct 3 ms 888 KB Output is correct
21 Correct 29 ms 888 KB Output is correct
22 Correct 54 ms 1004 KB Output is correct
23 Correct 12 ms 1004 KB Output is correct
24 Correct 83 ms 1004 KB Output is correct
25 Correct 64 ms 1004 KB Output is correct
26 Correct 127 ms 1004 KB Output is correct
27 Correct 140 ms 1004 KB Output is correct
28 Correct 91 ms 1004 KB Output is correct
29 Correct 110 ms 1004 KB Output is correct
30 Correct 141 ms 1004 KB Output is correct
31 Correct 128 ms 1116 KB Output is correct
32 Correct 130 ms 1116 KB Output is correct
33 Correct 4 ms 1116 KB Output is correct
34 Correct 157 ms 1132 KB Output is correct
35 Correct 202 ms 1132 KB Output is correct
36 Correct 229 ms 1132 KB Output is correct
37 Correct 147 ms 1132 KB Output is correct
38 Correct 226 ms 1132 KB Output is correct
39 Correct 222 ms 1132 KB Output is correct
40 Correct 278 ms 1132 KB Output is correct
41 Correct 127 ms 1132 KB Output is correct
42 Correct 160 ms 1132 KB Output is correct
43 Correct 202 ms 1132 KB Output is correct
44 Correct 181 ms 1132 KB Output is correct
45 Execution timed out 2047 ms 1132 KB Time limit exceeded
46 Halted 0 ms 0 KB -