답안 #46525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46525 2018-04-21T09:49:43 Z ikura355 Cultivation (JOI17_cultivation) C++14
5 / 100
486 ms 3724 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define X first
#define Y second
const int maxn = 300 + 5;
const int inf = 1e9;
int n,R,C;
pii p[maxn];
vector<int> forup, fordown;

int szx, szy;
int recx[maxn*2], recy[maxn*2];
map<int,int> mpx, mpy;

int cnt[maxn*2][maxn*2];

vector<int> have[100];

void check(int up, int down, int sleft, int sright, int sgap, int sgaprow) {
			for(int row=1;row<=R;row++) have[row].clear();
			for(int x=1;x<=n;x++) {
				for(int i=max(1,p[x].X-up);i<=min(R,p[x].X+down);i++) {
					have[i].push_back(p[x].Y);
				}
			}
			for(int row=1;row<=R;row++) sort(have[row].begin(), have[row].end());
			int left = 0, right = 0, gap = 0;
			int gaprow = 0, con = 0;
            for(int row=1;row<=R;row++) {
                if(have[row].size()==0) {
                    con++;
                    gaprow = max(gaprow, con);
                }
                else {
                    con = 0;
                    left = max(left, *have[row].begin()-1);
                    right = max(right, C-*have[row].rbegin());
                }
            }
            for(int row=1;row<=R;row++) {
            	for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
            }
	//assert(sleft==left);
	//assert(sright==right);
	assert(sgap==gap);
	assert(sgaprow==gaprow);
}

int main() {
	scanf("%d%d%d",&R,&C,&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&p[i].X,&p[i].Y);

	//prep
	sort(&p[1],&p[n+1]);
	for(int i=1;i<=n;i++) mpy[p[i].Y];
	for(auto &t : mpy) {
		t.second = ++szy;
		recy[szy] = t.first;
	}
	for(int i=1;i<=n;i++) {
		forup.push_back(p[i].X-1);
		fordown.push_back(R-p[i].X);
	}

	//solve
	int ans = inf;
	for(auto up : forup) {
		for(auto down : fordown) {
			//gap row
			int gaprow = 0;
			for(int i=2;i<=n;i++) gaprow = max(gaprow, p[i].X-p[i-1].X-1-up-down);

			//cpidx for x
			mpx.clear(); szx = 0;
			for(int i=1;i<=n;i++) mpx[max(1,p[i].X-up)], mpx[min(R,p[i].X+down)];
			for(auto &t : mpx) {
                t.second = ++szx;
                recx[szx] = t.first;
			}

			//place
			memset(cnt,0,sizeof(cnt));
			for(int row=1;row<=szx;row++) {
				for(int i=1;i<=n;i++) {
					if(p[i].X-up <= recx[row] && recx[row] <= p[i].X+down) cnt[row][mpy[p[i].Y]] = 1;
				}
			}

			//show
//			printf("up = %d down = %d\n",up,down);
//			for(int x=1;x<=szx;x++) {
//                for(int y=1;y<=szy;y++) printf("%d ",cnt[x][y]);
//                printf("\n");
//			}
//			printf("-------------------------\n");

			//left and right
			int left = 0, right = 0;
			for(int x=1;x<=szx;x++) {
				for(int y=1;y<=szy;y++) {
					if(cnt[x][y]) {
						left = max(left, recy[y] - 1);
						break;
					}
				}
				for(int y=szy;y>=1;y--) {
					if(cnt[x][y]) {
						right = max(right, C - recy[y]);
						break;
					}
				}
			}

			//gap
			int gap = 0;
			for(int x=1;x<=szx;x++) {
				int last = -1;
				for(int y=1;y<=szy;y++) {
					if(!cnt[x][y]) continue;
					if(last!=-1) {
						gap = max(gap, recy[y] - recy[last] - 1 - left - right);
					}
					last = y;
				}
			}

			ans = min(ans, up + down + left + right + gap + gaprow);
			check(up,down,left,right,gap,gaprow);

//			printf("up = %d down = %d (%d) : use %d %d %d\n",up,down,gaprow,left,right,gap);
		}
	}
	printf("%d",ans);
}

Compilation message

cultivation.cpp: In function 'void check(int, int, int, int, int, int)':
cultivation.cpp:42:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
              for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
                          ~^~~~~~~~~~~~~~~~~
cultivation.cpp: In function 'int main()':
cultivation.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&R,&C,&n);
  ~~~~~^~~~~~~~~~~~~~~~~~~
cultivation.cpp:52:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d%d",&p[i].X,&p[i].Y);
                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 12 ms 1968 KB Output is correct
6 Correct 3 ms 2028 KB Output is correct
7 Correct 3 ms 2028 KB Output is correct
8 Correct 21 ms 2028 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 3 ms 2044 KB Output is correct
14 Correct 3 ms 2044 KB Output is correct
15 Correct 3 ms 2044 KB Output is correct
16 Correct 3 ms 2044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 12 ms 1968 KB Output is correct
6 Correct 3 ms 2028 KB Output is correct
7 Correct 3 ms 2028 KB Output is correct
8 Correct 21 ms 2028 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 3 ms 2044 KB Output is correct
14 Correct 3 ms 2044 KB Output is correct
15 Correct 3 ms 2044 KB Output is correct
16 Correct 3 ms 2044 KB Output is correct
17 Correct 39 ms 2044 KB Output is correct
18 Correct 486 ms 2304 KB Output is correct
19 Runtime error 16 ms 3708 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 12 ms 1968 KB Output is correct
6 Correct 3 ms 2028 KB Output is correct
7 Correct 3 ms 2028 KB Output is correct
8 Correct 21 ms 2028 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 3 ms 2044 KB Output is correct
14 Correct 3 ms 2044 KB Output is correct
15 Correct 3 ms 2044 KB Output is correct
16 Correct 3 ms 2044 KB Output is correct
17 Correct 39 ms 2044 KB Output is correct
18 Correct 486 ms 2304 KB Output is correct
19 Runtime error 16 ms 3708 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 3724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 3724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1784 KB Output is correct
2 Correct 3 ms 1784 KB Output is correct
3 Correct 3 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 12 ms 1968 KB Output is correct
6 Correct 3 ms 2028 KB Output is correct
7 Correct 3 ms 2028 KB Output is correct
8 Correct 21 ms 2028 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 3 ms 2044 KB Output is correct
14 Correct 3 ms 2044 KB Output is correct
15 Correct 3 ms 2044 KB Output is correct
16 Correct 3 ms 2044 KB Output is correct
17 Correct 39 ms 2044 KB Output is correct
18 Correct 486 ms 2304 KB Output is correct
19 Runtime error 16 ms 3708 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -