답안 #801858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801858 2023-08-02T08:07:49 Z 박상훈(#10090) Cultivation (JOI17_cultivation) C++17
5 / 100
18 ms 364 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 4e18;

ll R, C;
int n;

ll X[303], Y[303];

int S[101][101], S2[101][101];

inline int sum(int s1, int e1, int s2, int e2){
	s1 = max(s1, 1);
	s2 = max(s2, 1);
	return S[e1][e2] - S[s1-1][e2] - S[e1][s2-1] + S[s1-1][s2-1];
}

inline int sum2(int s1, int e1, int s2, int e2){
	return S2[e1][e2] - S2[s1-1][e2] - S2[e1][s2-1] + S2[s1-1][s2-1];
}

bool ok(int p, int q){
	for (int i=1;i<=R+p-1;i++){
		for (int j=1;j<=C+q-1;j++){
			if (sum(i-p+1, i, j-q+1, j) > 0) S2[i][j] = 1;
			else S2[i][j] = 0;

			// if (p==3 && q==2) printf("%d ", S2[i][j]);
		}
		// if (p==3 && q==2) printf("\n");
	}

	for (int i=1;i<=R+p-1;i++){
		for (int j=1;j<=C+q-1;j++){
			S2[i][j] = S2[i][j] + S2[i][j-1] + S2[i-1][j] - S2[i-1][j-1];
		}
	}

	for (int i=R;i<=R+p-1;i++){
		for (int j=C;j<=C+q-1;j++){
			if (sum2(i-R+1, i, j-C+1, j)==R*C) return 1;
		}
	}

	return 0;
}

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

	for (int i=1;i<=n;i++) S[X[i]][Y[i]] = 1;
	for (int i=1;i<=R*2;i++){
		for (int j=1;j<=C*2;j++) S[i][j] = S[i][j] + S[i][j-1] + S[i-1][j] - S[i-1][j-1];
	}

	ll ans = INF;

	for (int i=1;i<=R;i++){
		for (int j=1;j<=C;j++) if (ok(i, j)){
			ans = min(ans, (ll)i + j - 2);
		}
	}

	printf("%lld\n", ans);
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%lld %lld", &R, &C);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cultivation.cpp:54:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  for (int i=1;i<=n;i++) scanf("%lld %lld", X+i, Y+i);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 236 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 236 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 18 ms 364 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Incorrect 13 ms 340 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 236 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 18 ms 364 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Incorrect 13 ms 340 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 236 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 18 ms 364 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Incorrect 13 ms 340 KB Output isn't correct
22 Halted 0 ms 0 KB -