Submission #644389

# Submission time Handle Problem Language Result Execution time Memory
644389 2022-09-24T14:51:27 Z Iwanttobreakfree Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 296 KB
#include <iostream>
#include <vector>

using namespace std;

#define int long long

signed main() {
    int r, s, a, b;
    cin >> r >> s >> a >> b;
    if (b > a) swap (a, b);
    vector<vector<int>> grid (r+1,vector<int> (s+1));
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < s; ++j) {
            int x;
            cin >> x;
            grid[i+1][j+1]=grid[i+1][j]+grid[i][j+1]-grid[i][j]+x;
        }
    }
    int sol = 1e18;
    for (int i = 1; i <= r; ++i) {
        for (int j = 0; j < i; ++j) {
            int l = 0, r = 1;
            while (r <= s) {
                while (l < r and grid[i][r]-grid[j][r]-grid[j][l+1]+grid[j][l] > b) {
                    int val = grid[i][r]-grid[j][r]-grid[j][l+1]+grid[j][l];
                    sol = min (sol, abs (a-val)+abs (b-val));
                    ++l;
                }
                if (l < r) {
                    int val = grid[i][r]-grid[j][r]-grid[j][l+1]+grid[j][l];
                    //cout << grid[j][l+1] << ' ';
                    sol = min (sol, abs (a-val)+abs (b-val));
                }
                ++r;
            }
        }
    }
    cout << sol << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -