이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 1000000005
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
#define mod 1000000007
int pre[505][505],dizi[505][505];
int32_t main(){
faster
int n,m,a,b;
cin>>n>>m>>a>>b;
int maxi=abs(a-b);
if(maxi&1)maxi++;
maxi/=2;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>dizi[i][j];
pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+dizi[i][j];
}
}
//////////////DEBUG
/*for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<pre[i][j]<<" ";
}
cout<<endl;
}*/
int mini=OYY;
bool stop=true;
for(int i=1;i<=n && stop;i++){
for(int j=i;j<=n && stop;j++){
for(int o=1;o<=m && stop;o++){
for(int p=o;p<=m && stop;p++){
int deg=pre[j][p]-pre[i-1][p]-pre[j][o-1]+pre[i-1][o-1];
//cout<<pre[j][p]<<" "<<pre[i-1][p]<<" "<<pre[j][o-1]<<" "<<pre[i-1][o-1]<<endl;
deg=abs(deg-a)+abs(deg-b);
mini=min(mini,deg);
if(maxi==mini)stop=false;
}
}
}
}
cout<<mini<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |