답안 #27797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27797 2017-07-14T06:19:58 Z 김동현(#1158) Cultivation (JOI17_cultivation) C++14
0 / 100
0 ms 2104 KB
#include <bits/stdc++.h>
using namespace std;

const int inf = 2e9;
int r, c, n, x[301], y[301], a[101][101], s[101][101], ans = inf;
set<int> xs, ys;
vector<int> xv, yv;

int can(int X, int Y){
	X++; Y++;
	for(int i = 1; i <= 100; i++) fill(a[i] + 1, a[i] + 101, 0);
	for(int i = 1; i <= n; i++){
		a[x[i]][y[i]]++;
		a[x[i] + X][y[i]]--;
		a[x[i]][y[i] + Y]--;
		a[x[i] + X][y[i] + Y]++;
	}
	for(int i = 1; i <= 100; i++){
		for(int j = 1; j <= 100; j++){
			a[i][j] += a[i - 1][j];
		}
	}
	for(int i = 1; i <= 100; i++){
		for(int j = 1; j <= 100; j++){
			a[i][j] += a[i][j - 1];
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + !!(a[i][j]);
		}
	}
	for(int i = 0; i < X; i++){
		for(int j = 0; j < Y; j++){
			if(s[i + r][j + c] - s[i + r][j] - s[i][j + c] + s[i][j] == r * c) return 1;
		}
	}
	return 0;
}

int main(){
	scanf("%d%d%d", &r, &c, &n);
	xs.insert(0); ys.insert(0);
	for(int i = 1; i <= n; i++){
		scanf("%d%d", x + i, y + i);
		xs.insert(x[i] - 1); xs.insert(r - x[i]);
		ys.insert(y[i] - 1); ys.insert(c - y[i]);
		for(int j = 1; j < i; j++){
			xs.insert(max(0, abs(x[i] - x[j]) - 1));
			ys.insert(max(0, abs(y[i] - y[j]) - 1));
		}
	}
	for(auto &i : xs) xv.push_back(i);
	for(auto &i : ys) yv.push_back(i);
	for(int i = 0, j = yv.size(); i < xv.size(); i++){
		for(; j > 0; j--) if(!can(xv[i], yv[j - 1])) break;
		if(j < yv.size()) ans = min(ans, xv[i] + yv[j]);
	}
	printf("%d\n", ans);
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:51:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0, j = yv.size(); i < xv.size(); i++){
                                  ^
cultivation.cpp:53:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(j < yv.size()) ans = min(ans, xv[i] + yv[j]);
        ^
cultivation.cpp:38:29: 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:41:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", x + i, y + i);
                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2104 KB Output is correct
2 Incorrect 0 ms 2104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2104 KB Output is correct
2 Incorrect 0 ms 2104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2104 KB Output is correct
2 Incorrect 0 ms 2104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2104 KB Output is correct
2 Incorrect 0 ms 2104 KB Output isn't correct
3 Halted 0 ms 0 KB -