답안 #1090689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090689 2024-09-18T15:28:30 Z Kuzeuy54_ Zemljište (COCI22_zemljiste) C++17
70 / 70
349 ms 6784 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int N = 501;
int arr[N][N], dp[N][N];
 
inline int sum(int x1, int y1, int x2, int y2) {
	return dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1];
};
 
int32_t main(){
	fast
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	if(a > b) swap(a, b);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> arr[i][j];
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i][j];
		}
	}
	int ans = inf;
	for(int rowst = 1; rowst <= n; rowst++) {
		for(int rownd = 1; rownd <= n; rownd++) {
			int l = 1, r = 1;
			while(r <= m) {
				// implement
				int now = sum(rowst, l, rownd, r);
				ans = min(ans, abs(a - now) + abs(b - now));
				if(now > b) {
					l++;
					if(l > r) {
						r++;
					}
				}
				else if(now >= a) {
					cout << b - a << "\n";
					return 0;
				}
				else {
					r++;
				}
			}
		}
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2908 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2784 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2908 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2784 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 18 ms 6568 KB Output is correct
24 Correct 18 ms 6644 KB Output is correct
25 Correct 19 ms 6736 KB Output is correct
26 Correct 19 ms 6648 KB Output is correct
27 Correct 17 ms 5908 KB Output is correct
28 Correct 22 ms 6748 KB Output is correct
29 Correct 19 ms 6748 KB Output is correct
30 Correct 23 ms 6604 KB Output is correct
31 Correct 4 ms 4440 KB Output is correct
32 Correct 344 ms 6728 KB Output is correct
33 Correct 332 ms 6756 KB Output is correct
34 Correct 333 ms 6784 KB Output is correct
35 Correct 337 ms 6708 KB Output is correct
36 Correct 349 ms 6628 KB Output is correct
37 Correct 336 ms 6776 KB Output is correct
38 Correct 323 ms 6636 KB Output is correct
39 Correct 334 ms 6784 KB Output is correct
40 Correct 328 ms 6776 KB Output is correct
41 Correct 14 ms 5384 KB Output is correct
42 Correct 14 ms 5468 KB Output is correct
43 Correct 14 ms 5468 KB Output is correct
44 Correct 15 ms 5468 KB Output is correct