Submission #59837

# Submission time Handle Problem Language Result Execution time Memory
59837 2018-07-23T07:51:51 Z koosaga(#1721) Cultivation (JOI17_cultivation) C++11
30 / 100
2000 ms 748 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 305;

int n, r, c;
pi a[MAXN];

struct sweep{
	int pos, val, mode;
	bool operator<(const sweep &s)const{
		return pi(pos, -mode) < pi(s.pos, -s.mode);
	}
};

lint Do(vector<sweep> sw){
	vector<int> v = {1, r + 1};
	for(int i=0; i<sw.size(); i++){ 
		v.push_back(sw[i].pos);
	}
	sort(sw.begin(), sw.end());
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	multiset<int> s;
	int ptr = 0;
	int lv = 0, rv = 0, sum = 0;
	for(int i=0; i+1<v.size(); i++){
		while(ptr < sw.size() && sw[ptr].pos == v[i]){
			if(sw[ptr].mode == 1) s.insert(sw[ptr].val);
			else s.erase(s.find(sw[ptr].val));
			ptr++;
		}
		if(s.size() == 0) return 1e18;
		lv = max(lv, *s.begin() - 1);
		rv = max(rv, c - *s.rbegin());
		auto it = s.begin();
		while(next(it) != s.end()){
			auto in = next(it);
			sum = max(*in - *it - 1, sum);
			it = in;
		}
	}
	return max(lv + rv, sum);
}

lint solve(){
	lint ans = 1e18;
	for(int i=0; i<=r-1; i++){
		for(int j=0; j<=r-1; j++){
			vector<sweep> sw;
			for(int k=0; k<n; k++){
				int le = max(1, a[k].first - i);
				int ri = min(r, a[k].first + j);
				int v = a[k].second;
				sw.push_back({le, v, +1});
				sw.push_back({ri + 1, v, -1});
			}
			ans = min(ans, i + j + Do(sw));
		}
	}
	return ans;
}

int main(){
	cin >> r >> c >> n;
	for(int i=0; i<n; i++){
		cin >> a[i].first >> a[i].second;
	}
	cout << solve() << endl;
}

Compilation message

cultivation.cpp: In function 'lint Do(std::vector<sweep>)':
cultivation.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<sw.size(); i++){
               ~^~~~~~~~~~
cultivation.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i+1<v.size(); i++){
               ~~~^~~~~~~~~
cultivation.cpp:30:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(ptr < sw.size() && sw[ptr].pos == v[i]){
         ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 24 ms 620 KB Output is correct
19 Correct 22 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 38 ms 620 KB Output is correct
22 Correct 106 ms 620 KB Output is correct
23 Correct 22 ms 620 KB Output is correct
24 Correct 180 ms 624 KB Output is correct
25 Correct 134 ms 624 KB Output is correct
26 Correct 284 ms 624 KB Output is correct
27 Correct 264 ms 636 KB Output is correct
28 Correct 166 ms 748 KB Output is correct
29 Correct 237 ms 748 KB Output is correct
30 Correct 271 ms 748 KB Output is correct
31 Correct 285 ms 748 KB Output is correct
32 Correct 269 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 24 ms 620 KB Output is correct
19 Correct 22 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 38 ms 620 KB Output is correct
22 Correct 106 ms 620 KB Output is correct
23 Correct 22 ms 620 KB Output is correct
24 Correct 180 ms 624 KB Output is correct
25 Correct 134 ms 624 KB Output is correct
26 Correct 284 ms 624 KB Output is correct
27 Correct 264 ms 636 KB Output is correct
28 Correct 166 ms 748 KB Output is correct
29 Correct 237 ms 748 KB Output is correct
30 Correct 271 ms 748 KB Output is correct
31 Correct 285 ms 748 KB Output is correct
32 Correct 269 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 235 ms 748 KB Output is correct
35 Correct 295 ms 748 KB Output is correct
36 Correct 281 ms 748 KB Output is correct
37 Correct 220 ms 748 KB Output is correct
38 Correct 281 ms 748 KB Output is correct
39 Correct 271 ms 748 KB Output is correct
40 Correct 280 ms 748 KB Output is correct
41 Correct 224 ms 748 KB Output is correct
42 Correct 234 ms 748 KB Output is correct
43 Correct 272 ms 748 KB Output is correct
44 Correct 279 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2044 ms 748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2044 ms 748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 24 ms 620 KB Output is correct
19 Correct 22 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 38 ms 620 KB Output is correct
22 Correct 106 ms 620 KB Output is correct
23 Correct 22 ms 620 KB Output is correct
24 Correct 180 ms 624 KB Output is correct
25 Correct 134 ms 624 KB Output is correct
26 Correct 284 ms 624 KB Output is correct
27 Correct 264 ms 636 KB Output is correct
28 Correct 166 ms 748 KB Output is correct
29 Correct 237 ms 748 KB Output is correct
30 Correct 271 ms 748 KB Output is correct
31 Correct 285 ms 748 KB Output is correct
32 Correct 269 ms 748 KB Output is correct
33 Correct 2 ms 748 KB Output is correct
34 Correct 235 ms 748 KB Output is correct
35 Correct 295 ms 748 KB Output is correct
36 Correct 281 ms 748 KB Output is correct
37 Correct 220 ms 748 KB Output is correct
38 Correct 281 ms 748 KB Output is correct
39 Correct 271 ms 748 KB Output is correct
40 Correct 280 ms 748 KB Output is correct
41 Correct 224 ms 748 KB Output is correct
42 Correct 234 ms 748 KB Output is correct
43 Correct 272 ms 748 KB Output is correct
44 Correct 279 ms 748 KB Output is correct
45 Execution timed out 2044 ms 748 KB Time limit exceeded
46 Halted 0 ms 0 KB -