Submission #1090730

# Submission time Handle Problem Language Result Execution time Memory
1090730 2024-09-18T16:05:18 Z Kuzeuy54_ Zemljište (COCI22_zemljiste) C++17
70 / 70
340 ms 6516 KB
#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define int long long
const int mod=1e9+7;
const int N=501;
int mat[N][N], dp[N][N];
inline int toplam(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(){
	cin.tie(0)->sync_with_stdio(0);
	int x,y,a,b;
	cin>>x>>y>>a>>b;
	if(a>b)
		swap(a,b);
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++){
			cin>>mat[i][j];
			dp[i][j]=mat[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
		}
	int ans=inf;
	for(int i=1;i<=x;i++)
		for(int j=1;j<=x;j++){
			int l=1,r=1;
			while(r<=y){
				int suan=toplam(i,l,j,r);
				ans=min(ans,abs(a-suan)+abs(b-suan));
				if(suan>b){
					l++;
					if(l>r)
						r++;
				}
				else if(suan>=a){
					cout<<b-a<<"\n";
					return 0;
				}
				else
					r++;
			}
		}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 1 ms 2392 KB Output is correct
9 Correct 0 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 1 ms 2392 KB Output is correct
9 Correct 0 ms 2520 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 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 5 ms 2908 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2924 KB Output is correct
18 Correct 1 ms 2788 KB Output is correct
19 Correct 1 ms 2652 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 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 1 ms 2392 KB Output is correct
9 Correct 0 ms 2520 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 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 5 ms 2908 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 2924 KB Output is correct
18 Correct 1 ms 2788 KB Output is correct
19 Correct 1 ms 2652 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 2904 KB Output is correct
23 Correct 23 ms 6516 KB Output is correct
24 Correct 28 ms 5800 KB Output is correct
25 Correct 24 ms 5736 KB Output is correct
26 Correct 19 ms 5716 KB Output is correct
27 Correct 14 ms 5228 KB Output is correct
28 Correct 25 ms 5760 KB Output is correct
29 Correct 19 ms 6044 KB Output is correct
30 Correct 20 ms 5828 KB Output is correct
31 Correct 4 ms 4444 KB Output is correct
32 Correct 329 ms 5744 KB Output is correct
33 Correct 327 ms 5968 KB Output is correct
34 Correct 321 ms 5712 KB Output is correct
35 Correct 326 ms 5716 KB Output is correct
36 Correct 322 ms 5896 KB Output is correct
37 Correct 336 ms 5712 KB Output is correct
38 Correct 320 ms 5712 KB Output is correct
39 Correct 340 ms 5688 KB Output is correct
40 Correct 322 ms 5720 KB Output is correct
41 Correct 15 ms 5116 KB Output is correct
42 Correct 13 ms 5144 KB Output is correct
43 Correct 13 ms 4940 KB Output is correct
44 Correct 13 ms 5024 KB Output is correct