Submission #1090672

# Submission time Handle Problem Language Result Execution time Memory
1090672 2024-09-18T15:17:40 Z Kuzeuy54_ Zemljište (COCI22_zemljiste) C++17
0 / 70
3 ms 4184 KB
#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define int long long
const int mod=1e9+7;
const int MAXN=501;
vector<vector<int>>dp(MAXN,vector<int>(MAXN,0)),mat(MAXN,vector<int>(MAXN,0));
int omg(int x1,int x2,int y1,int y2){
	return dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1];
}
int32_t main(){
    int n,m,a,b,ans=inf,temp;
	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>>mat[i][j];
			dp[i][j]=mat[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
		}
	for(int i=1;i<=m;i++)
		for(int j=1;j<=m;j++){
			int l=1,r=1;
			while(r<=m){
				int aq=omg(i,l,j,r);
				ans=min(abs(a-aq)+abs(b-aq),ans);
				if(aq>b){
					l++;
					if(l>r)
						r++;
				}
				else if(aq>=a){
					cout<<b-a<<"\n";
					return 0;
				}
				else 
					r++;
			}
		}
	cout<<ans<<"\n";
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:12:25: warning: unused variable 'temp' [-Wunused-variable]
   12 |     int n,m,a,b,ans=inf,temp;
      |                         ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -