Submission #26396

# Submission time Handle Problem Language Result Execution time Memory
26396 2017-06-29T18:56:08 Z pacu Cultivation (JOI17_cultivation) C++
80 / 100
2000 ms 2716 KB
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int N;
long long rows,cols;
long long x[300],y[300];
int xid[300];
int yid[300];

bool cmpx(int a,int b)
{
	return x[a]<x[b];
}
bool cmpy(int a,int b)
{
	return y[a]<y[b];
}

int cx[600];
long long cNorth[600];
long long cSouth[600];
long long cSum[600];
int cid[600];
int C;

void getColumnVals(long long k,int loc)
{
	cx[C] = loc;
	cSum[C] = 0;
	long long pre = -1;
	for(int j=0;j<N;j++)
		if(x[yid[j]] <= loc && x[yid[j]] + k >= loc)
		{
			cSum[C] = max(cSum[C],y[yid[j]]-pre-1);
			if(pre==-1) cNorth[C] = y[yid[j]];
			pre = y[yid[j]];
		}
	cSouth[C] = rows-pre-1;
	cSum[C] = max(cSum[C],rows-pre-1);
	if(pre==-1) cSum[C] = cNorth[C] = cSouth[C] = 2000000000;
//	cout << loc << ": " << cSum[C] << ' ' << cNorth[C] << ' ' << cSouth[C] << '\n';
	C++;
}

bool cmpc(int a,int b)
{
	return cx[a]<cx[b];
}

int queSum[600];
int queNorth[600];
int queSouth[600];
int backSum,backNorth,backSouth,topSum,topNorth,topSouth;

set<int> visk;

long long getMinSum(int k)
{
	if(visk.find(k) != visk.end()) return 2000000000;
	visk.insert(k);
	C = 0;
	for(int i=0;i<N;i++)
		getColumnVals(k,x[xid[i]]);
	for(int i=0;i<N;i++)
		getColumnVals(k,x[xid[i]]+k+1);
	for(int i=0;i<C;i++)
		cid[i] = i;
	sort(cid,cid+C,cmpc);
	backSum = backNorth = backSouth = 0;
	topSum = topNorth = topSouth = 0;
	long long ans = 2000000000;
	for(int i=C-1;i>=0;i--)
	{
		int cur = cid[i];
		while(backSum < topSum && cx[queSum[backSum]]-cx[cur] >= cols)
			backSum++;
		while(backNorth < topNorth && cx[queNorth[backNorth]]-cx[cur] >= cols)
			backNorth++;
		while(backSouth < topSouth && cx[queSouth[backSouth]]-cx[cur] >= cols)
			backSouth++;
		while(backSum < topSum && cSum[cur] >= cSum[queSum[topSum-1]])
			topSum--;
		while(backNorth < topNorth && cNorth[cur] >= cNorth[queNorth[topNorth-1]])
			topNorth--;
		while(backSouth < topSouth && cSouth[cur] >= cSouth[queSouth[topSouth-1]])
			topSouth--;
		queSum[topSum++] = cur;
		queNorth[topNorth++] = cur;
		queSouth[topSouth++] = cur;
		ans = min(ans,max(cSum[queSum[backSum]],cNorth[queNorth[backNorth]]+cSouth[queSouth[backSouth]]));
	}
	return ans+k;
}

int main()
{
	cin >> cols >> rows;
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> x[i] >> y[i];
		y[i]--,x[i]--;
		xid[i] = yid[i] = i;
	}
	sort(xid,xid+N,cmpx);
	sort(yid,yid+N,cmpy);
	long long ans = 2000000000;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
		{
			if(x[xid[j]]>x[xid[i]])
				ans = min(ans,getMinSum(x[xid[j]]-x[xid[i]]-1));
			ans = min(ans,getMinSum(x[xid[i]]+cols-1-x[xid[j]]));
		}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 0 ms 2056 KB Output is correct
3 Correct 0 ms 2056 KB Output is correct
4 Correct 0 ms 2056 KB Output is correct
5 Correct 0 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 0 ms 2056 KB Output is correct
9 Correct 0 ms 2056 KB Output is correct
10 Correct 0 ms 2056 KB Output is correct
11 Correct 0 ms 2056 KB Output is correct
12 Correct 0 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 0 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 0 ms 2056 KB Output is correct
3 Correct 0 ms 2056 KB Output is correct
4 Correct 0 ms 2056 KB Output is correct
5 Correct 0 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 0 ms 2056 KB Output is correct
9 Correct 0 ms 2056 KB Output is correct
10 Correct 0 ms 2056 KB Output is correct
11 Correct 0 ms 2056 KB Output is correct
12 Correct 0 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 0 ms 2056 KB Output is correct
17 Correct 0 ms 2056 KB Output is correct
18 Correct 0 ms 2056 KB Output is correct
19 Correct 0 ms 2056 KB Output is correct
20 Correct 0 ms 2056 KB Output is correct
21 Correct 0 ms 2056 KB Output is correct
22 Correct 6 ms 2056 KB Output is correct
23 Correct 0 ms 2056 KB Output is correct
24 Correct 16 ms 2056 KB Output is correct
25 Correct 9 ms 2056 KB Output is correct
26 Correct 36 ms 2056 KB Output is correct
27 Correct 39 ms 2056 KB Output is correct
28 Correct 16 ms 2056 KB Output is correct
29 Correct 33 ms 2056 KB Output is correct
30 Correct 36 ms 2056 KB Output is correct
31 Correct 36 ms 2056 KB Output is correct
32 Correct 36 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 0 ms 2056 KB Output is correct
3 Correct 0 ms 2056 KB Output is correct
4 Correct 0 ms 2056 KB Output is correct
5 Correct 0 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 0 ms 2056 KB Output is correct
9 Correct 0 ms 2056 KB Output is correct
10 Correct 0 ms 2056 KB Output is correct
11 Correct 0 ms 2056 KB Output is correct
12 Correct 0 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 0 ms 2056 KB Output is correct
17 Correct 0 ms 2056 KB Output is correct
18 Correct 0 ms 2056 KB Output is correct
19 Correct 0 ms 2056 KB Output is correct
20 Correct 0 ms 2056 KB Output is correct
21 Correct 0 ms 2056 KB Output is correct
22 Correct 6 ms 2056 KB Output is correct
23 Correct 0 ms 2056 KB Output is correct
24 Correct 16 ms 2056 KB Output is correct
25 Correct 9 ms 2056 KB Output is correct
26 Correct 36 ms 2056 KB Output is correct
27 Correct 39 ms 2056 KB Output is correct
28 Correct 16 ms 2056 KB Output is correct
29 Correct 33 ms 2056 KB Output is correct
30 Correct 36 ms 2056 KB Output is correct
31 Correct 36 ms 2056 KB Output is correct
32 Correct 36 ms 2056 KB Output is correct
33 Correct 0 ms 2056 KB Output is correct
34 Correct 26 ms 2056 KB Output is correct
35 Correct 36 ms 2056 KB Output is correct
36 Correct 36 ms 2056 KB Output is correct
37 Correct 49 ms 2056 KB Output is correct
38 Correct 36 ms 2056 KB Output is correct
39 Correct 36 ms 2056 KB Output is correct
40 Correct 39 ms 2056 KB Output is correct
41 Correct 29 ms 2056 KB Output is correct
42 Correct 29 ms 2056 KB Output is correct
43 Correct 33 ms 2056 KB Output is correct
44 Correct 33 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 3 ms 2056 KB Output is correct
3 Correct 3 ms 2056 KB Output is correct
4 Correct 3 ms 2056 KB Output is correct
5 Correct 6 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 3 ms 2056 KB Output is correct
9 Correct 3 ms 2056 KB Output is correct
10 Correct 3 ms 2056 KB Output is correct
11 Correct 3 ms 2056 KB Output is correct
12 Correct 3 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 3 ms 2056 KB Output is correct
17 Correct 3 ms 2056 KB Output is correct
18 Correct 0 ms 2056 KB Output is correct
19 Correct 6 ms 2056 KB Output is correct
20 Correct 3 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 3 ms 2056 KB Output is correct
3 Correct 3 ms 2056 KB Output is correct
4 Correct 3 ms 2056 KB Output is correct
5 Correct 6 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 3 ms 2056 KB Output is correct
9 Correct 3 ms 2056 KB Output is correct
10 Correct 3 ms 2056 KB Output is correct
11 Correct 3 ms 2056 KB Output is correct
12 Correct 3 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 3 ms 2056 KB Output is correct
17 Correct 3 ms 2056 KB Output is correct
18 Correct 0 ms 2056 KB Output is correct
19 Correct 6 ms 2056 KB Output is correct
20 Correct 3 ms 2056 KB Output is correct
21 Correct 683 ms 2452 KB Output is correct
22 Correct 1116 ms 2716 KB Output is correct
23 Correct 1066 ms 2716 KB Output is correct
24 Correct 1033 ms 2716 KB Output is correct
25 Correct 1106 ms 2716 KB Output is correct
26 Correct 429 ms 2452 KB Output is correct
27 Correct 753 ms 2716 KB Output is correct
28 Correct 1143 ms 2716 KB Output is correct
29 Correct 1089 ms 2716 KB Output is correct
30 Correct 1086 ms 2716 KB Output is correct
31 Correct 1113 ms 2716 KB Output is correct
32 Correct 1073 ms 2716 KB Output is correct
33 Correct 753 ms 2716 KB Output is correct
34 Correct 1008 ms 2716 KB Output is correct
35 Correct 966 ms 2716 KB Output is correct
36 Correct 949 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2056 KB Output is correct
2 Correct 0 ms 2056 KB Output is correct
3 Correct 0 ms 2056 KB Output is correct
4 Correct 0 ms 2056 KB Output is correct
5 Correct 0 ms 2056 KB Output is correct
6 Correct 0 ms 2056 KB Output is correct
7 Correct 0 ms 2056 KB Output is correct
8 Correct 0 ms 2056 KB Output is correct
9 Correct 0 ms 2056 KB Output is correct
10 Correct 0 ms 2056 KB Output is correct
11 Correct 0 ms 2056 KB Output is correct
12 Correct 0 ms 2056 KB Output is correct
13 Correct 0 ms 2056 KB Output is correct
14 Correct 0 ms 2056 KB Output is correct
15 Correct 0 ms 2056 KB Output is correct
16 Correct 0 ms 2056 KB Output is correct
17 Correct 0 ms 2056 KB Output is correct
18 Correct 0 ms 2056 KB Output is correct
19 Correct 0 ms 2056 KB Output is correct
20 Correct 0 ms 2056 KB Output is correct
21 Correct 0 ms 2056 KB Output is correct
22 Correct 6 ms 2056 KB Output is correct
23 Correct 0 ms 2056 KB Output is correct
24 Correct 16 ms 2056 KB Output is correct
25 Correct 9 ms 2056 KB Output is correct
26 Correct 36 ms 2056 KB Output is correct
27 Correct 39 ms 2056 KB Output is correct
28 Correct 16 ms 2056 KB Output is correct
29 Correct 33 ms 2056 KB Output is correct
30 Correct 36 ms 2056 KB Output is correct
31 Correct 36 ms 2056 KB Output is correct
32 Correct 36 ms 2056 KB Output is correct
33 Correct 0 ms 2056 KB Output is correct
34 Correct 26 ms 2056 KB Output is correct
35 Correct 36 ms 2056 KB Output is correct
36 Correct 36 ms 2056 KB Output is correct
37 Correct 49 ms 2056 KB Output is correct
38 Correct 36 ms 2056 KB Output is correct
39 Correct 36 ms 2056 KB Output is correct
40 Correct 39 ms 2056 KB Output is correct
41 Correct 29 ms 2056 KB Output is correct
42 Correct 29 ms 2056 KB Output is correct
43 Correct 33 ms 2056 KB Output is correct
44 Correct 33 ms 2056 KB Output is correct
45 Correct 0 ms 2056 KB Output is correct
46 Correct 3 ms 2056 KB Output is correct
47 Correct 3 ms 2056 KB Output is correct
48 Correct 3 ms 2056 KB Output is correct
49 Correct 6 ms 2056 KB Output is correct
50 Correct 0 ms 2056 KB Output is correct
51 Correct 0 ms 2056 KB Output is correct
52 Correct 3 ms 2056 KB Output is correct
53 Correct 3 ms 2056 KB Output is correct
54 Correct 3 ms 2056 KB Output is correct
55 Correct 3 ms 2056 KB Output is correct
56 Correct 3 ms 2056 KB Output is correct
57 Correct 0 ms 2056 KB Output is correct
58 Correct 0 ms 2056 KB Output is correct
59 Correct 0 ms 2056 KB Output is correct
60 Correct 3 ms 2056 KB Output is correct
61 Correct 3 ms 2056 KB Output is correct
62 Correct 0 ms 2056 KB Output is correct
63 Correct 6 ms 2056 KB Output is correct
64 Correct 3 ms 2056 KB Output is correct
65 Correct 683 ms 2452 KB Output is correct
66 Correct 1116 ms 2716 KB Output is correct
67 Correct 1066 ms 2716 KB Output is correct
68 Correct 1033 ms 2716 KB Output is correct
69 Correct 1106 ms 2716 KB Output is correct
70 Correct 429 ms 2452 KB Output is correct
71 Correct 753 ms 2716 KB Output is correct
72 Correct 1143 ms 2716 KB Output is correct
73 Correct 1089 ms 2716 KB Output is correct
74 Correct 1086 ms 2716 KB Output is correct
75 Correct 1113 ms 2716 KB Output is correct
76 Correct 1073 ms 2716 KB Output is correct
77 Correct 753 ms 2716 KB Output is correct
78 Correct 1008 ms 2716 KB Output is correct
79 Correct 966 ms 2716 KB Output is correct
80 Correct 949 ms 2716 KB Output is correct
81 Execution timed out 2000 ms 2452 KB Execution timed out
82 Halted 0 ms 0 KB -