Submission #1090693

# Submission time Handle Problem Language Result Execution time Memory
1090693 2024-09-18T15:29:59 Z Kuzeuy54_ Zemljište (COCI22_zemljiste) C++17
70 / 70
334 ms 4440 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]=arr[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
		}
	}
	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){
				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";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2652 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2800 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2652 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2800 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 24 ms 4188 KB Output is correct
24 Correct 17 ms 4188 KB Output is correct
25 Correct 20 ms 4188 KB Output is correct
26 Correct 18 ms 4188 KB Output is correct
27 Correct 14 ms 4188 KB Output is correct
28 Correct 26 ms 4308 KB Output is correct
29 Correct 17 ms 4188 KB Output is correct
30 Correct 21 ms 4288 KB Output is correct
31 Correct 3 ms 4188 KB Output is correct
32 Correct 320 ms 4368 KB Output is correct
33 Correct 329 ms 4184 KB Output is correct
34 Correct 331 ms 4184 KB Output is correct
35 Correct 334 ms 4440 KB Output is correct
36 Correct 318 ms 4188 KB Output is correct
37 Correct 329 ms 4364 KB Output is correct
38 Correct 323 ms 4188 KB Output is correct
39 Correct 331 ms 4184 KB Output is correct
40 Correct 322 ms 4364 KB Output is correct
41 Correct 13 ms 4184 KB Output is correct
42 Correct 13 ms 4264 KB Output is correct
43 Correct 13 ms 4148 KB Output is correct
44 Correct 13 ms 4384 KB Output is correct