#include<bits/stdc++.h>
using namespace std;
int r, s, a, b, c[501][501];
long long pref[501][501], ans;
inline long long get_sm(int x1, int x2, int y1, int y2){
return pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> r >> s >> a >> b;
for(register int i = 1; i <= r; ++i){
for(register int j = 1; j <= s; ++j){
cin >> c[i][j];
ans += c[i][j];
pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + c[i][j];
}
}
for(register int x1 = 1; x1 <= r; ++x1){
for(register int y1 = 1; y1 <= s; ++y1){
for(register int x2 = x1; x2 <= r; ++x2){
for(register int y2 = y1; y2 <= s; ++y2){
long long cur = get_sm(x1, x2, y1, y2);
ans = min(ans, 0ll + abs(cur - a) + abs(cur - b));
//if(cur > max(a, b)) break;
}
}
}
}
cout << ans << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:15:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
15 | for(register int i = 1; i <= r; ++i){
| ^
Main.cpp:16:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
16 | for(register int j = 1; j <= s; ++j){
| ^
Main.cpp:23:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
23 | for(register int x1 = 1; x1 <= r; ++x1){
| ^~
Main.cpp:25:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
25 | for(register int y1 = 1; y1 <= s; ++y1){
| ^~
Main.cpp:27:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
27 | for(register int x2 = x1; x2 <= r; ++x2){
| ^~
Main.cpp:29:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
29 | for(register int y2 = y1; y2 <= s; ++y2){
| ^~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |