답안 #46509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46509 2018-04-21T08:25:08 Z ikura355 Cultivation (JOI17_cultivation) C++14
0 / 100
2 ms 740 KB
//30 pts.
#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> have[45];
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);
	//fix up and down (R<=40)
	int ans = inf;
	for(int up=0;up<=R;up++) {
		for(int down=0;down<=R;down++) {
			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);
				}
			}
			int mx = 0;
			for(int row=1;row<=R;row++) {
				if(have[row].size()==0) {
					mx = inf;
					break;
				}
				sort(have[row].begin(),have[row].end());
				int use = (*have[row].begin() - 1) + (C - *have[row].rbegin());
				int gap = 0;
				for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i] - have[row][i-1] - 1);
				mx = max(mx, use + max(0, gap-use));
			}
			ans = min(ans, mx + up + down);
		}
	}
	printf("%d",ans);
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:34:18: 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);
                 ~^~~~~~~~~~~~~~~~~
cultivation.cpp:13: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:14: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 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Incorrect 2 ms 568 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Incorrect 2 ms 568 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Incorrect 2 ms 568 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Incorrect 2 ms 568 KB Output isn't correct
6 Halted 0 ms 0 KB -