#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;
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;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
for(int o=1;o<=m;o++){
for(int p=o;p<=m;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);
}
}
}
}
cout<<mini<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
13 ms |
864 KB |
Output is correct |
11 |
Correct |
61 ms |
1204 KB |
Output is correct |
12 |
Correct |
49 ms |
1208 KB |
Output is correct |
13 |
Correct |
56 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
48 ms |
1108 KB |
Output is correct |
16 |
Correct |
48 ms |
1208 KB |
Output is correct |
17 |
Correct |
51 ms |
1208 KB |
Output is correct |
18 |
Correct |
49 ms |
1108 KB |
Output is correct |
19 |
Correct |
53 ms |
1108 KB |
Output is correct |
20 |
Correct |
53 ms |
1164 KB |
Output is correct |
21 |
Correct |
66 ms |
1152 KB |
Output is correct |
22 |
Correct |
48 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
13 ms |
864 KB |
Output is correct |
11 |
Correct |
61 ms |
1204 KB |
Output is correct |
12 |
Correct |
49 ms |
1208 KB |
Output is correct |
13 |
Correct |
56 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
48 ms |
1108 KB |
Output is correct |
16 |
Correct |
48 ms |
1208 KB |
Output is correct |
17 |
Correct |
51 ms |
1208 KB |
Output is correct |
18 |
Correct |
49 ms |
1108 KB |
Output is correct |
19 |
Correct |
53 ms |
1108 KB |
Output is correct |
20 |
Correct |
53 ms |
1164 KB |
Output is correct |
21 |
Correct |
66 ms |
1152 KB |
Output is correct |
22 |
Correct |
48 ms |
1108 KB |
Output is correct |
23 |
Execution timed out |
2049 ms |
6564 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |