Submission #26395

# Submission time Handle Problem Language Result Execution time Memory
26395 2017-06-29T18:54:36 Z pacu Cultivation (JOI17_cultivation) C++
30 / 100
36 ms 2048 KB
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int N,rows,cols;
int 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];
int cNorth[600];
int cSouth[600];
int cSum[600];
int cid[600];
int C;

void getColumnVals(int k,int loc)
{
	cx[C] = loc;
	cSum[C] = 0;
	int 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;

int 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;
	int 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);
	int 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 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 0 ms 2048 KB Output is correct
12 Correct 0 ms 2048 KB Output is correct
13 Correct 0 ms 2048 KB Output is correct
14 Correct 0 ms 2048 KB Output is correct
15 Correct 0 ms 2048 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 0 ms 2048 KB Output is correct
12 Correct 0 ms 2048 KB Output is correct
13 Correct 0 ms 2048 KB Output is correct
14 Correct 0 ms 2048 KB Output is correct
15 Correct 0 ms 2048 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 0 ms 2048 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 0 ms 2048 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 0 ms 2048 KB Output is correct
24 Correct 16 ms 2048 KB Output is correct
25 Correct 6 ms 2048 KB Output is correct
26 Correct 29 ms 2048 KB Output is correct
27 Correct 29 ms 2048 KB Output is correct
28 Correct 13 ms 2048 KB Output is correct
29 Correct 29 ms 2048 KB Output is correct
30 Correct 33 ms 2048 KB Output is correct
31 Correct 36 ms 2048 KB Output is correct
32 Correct 36 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 0 ms 2048 KB Output is correct
12 Correct 0 ms 2048 KB Output is correct
13 Correct 0 ms 2048 KB Output is correct
14 Correct 0 ms 2048 KB Output is correct
15 Correct 0 ms 2048 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 0 ms 2048 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 0 ms 2048 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 0 ms 2048 KB Output is correct
24 Correct 16 ms 2048 KB Output is correct
25 Correct 6 ms 2048 KB Output is correct
26 Correct 29 ms 2048 KB Output is correct
27 Correct 29 ms 2048 KB Output is correct
28 Correct 13 ms 2048 KB Output is correct
29 Correct 29 ms 2048 KB Output is correct
30 Correct 33 ms 2048 KB Output is correct
31 Correct 36 ms 2048 KB Output is correct
32 Correct 36 ms 2048 KB Output is correct
33 Correct 0 ms 2048 KB Output is correct
34 Correct 23 ms 2048 KB Output is correct
35 Correct 29 ms 2048 KB Output is correct
36 Correct 29 ms 2048 KB Output is correct
37 Correct 26 ms 2048 KB Output is correct
38 Correct 33 ms 2048 KB Output is correct
39 Correct 33 ms 2048 KB Output is correct
40 Correct 33 ms 2048 KB Output is correct
41 Correct 23 ms 2048 KB Output is correct
42 Correct 23 ms 2048 KB Output is correct
43 Correct 29 ms 2048 KB Output is correct
44 Correct 33 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2048 KB Output is correct
2 Correct 0 ms 2048 KB Output is correct
3 Correct 0 ms 2048 KB Output is correct
4 Correct 0 ms 2048 KB Output is correct
5 Correct 0 ms 2048 KB Output is correct
6 Correct 0 ms 2048 KB Output is correct
7 Correct 0 ms 2048 KB Output is correct
8 Correct 0 ms 2048 KB Output is correct
9 Correct 0 ms 2048 KB Output is correct
10 Correct 0 ms 2048 KB Output is correct
11 Correct 0 ms 2048 KB Output is correct
12 Correct 0 ms 2048 KB Output is correct
13 Correct 0 ms 2048 KB Output is correct
14 Correct 0 ms 2048 KB Output is correct
15 Correct 0 ms 2048 KB Output is correct
16 Correct 0 ms 2048 KB Output is correct
17 Correct 0 ms 2048 KB Output is correct
18 Correct 0 ms 2048 KB Output is correct
19 Correct 0 ms 2048 KB Output is correct
20 Correct 0 ms 2048 KB Output is correct
21 Correct 0 ms 2048 KB Output is correct
22 Correct 0 ms 2048 KB Output is correct
23 Correct 0 ms 2048 KB Output is correct
24 Correct 16 ms 2048 KB Output is correct
25 Correct 6 ms 2048 KB Output is correct
26 Correct 29 ms 2048 KB Output is correct
27 Correct 29 ms 2048 KB Output is correct
28 Correct 13 ms 2048 KB Output is correct
29 Correct 29 ms 2048 KB Output is correct
30 Correct 33 ms 2048 KB Output is correct
31 Correct 36 ms 2048 KB Output is correct
32 Correct 36 ms 2048 KB Output is correct
33 Correct 0 ms 2048 KB Output is correct
34 Correct 23 ms 2048 KB Output is correct
35 Correct 29 ms 2048 KB Output is correct
36 Correct 29 ms 2048 KB Output is correct
37 Correct 26 ms 2048 KB Output is correct
38 Correct 33 ms 2048 KB Output is correct
39 Correct 33 ms 2048 KB Output is correct
40 Correct 33 ms 2048 KB Output is correct
41 Correct 23 ms 2048 KB Output is correct
42 Correct 23 ms 2048 KB Output is correct
43 Correct 29 ms 2048 KB Output is correct
44 Correct 33 ms 2048 KB Output is correct
45 Incorrect 0 ms 2048 KB Output isn't correct
46 Halted 0 ms 0 KB -