Submission #704854

# Submission time Handle Problem Language Result Execution time Memory
704854 2023-03-03T05:39:32 Z PixelCat Zemljište (COCI22_zemljiste) C++14
0 / 70
1 ms 340 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 510;

int s[MAXN][MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // nya ><
    int n, m, a, b; cin >> n >> m >> a >> b;
    For(i, 1, n) For(j, 1, m) {
        cin >> s[i][j];
        s[i][j] += s[i - 1][j];
    }
    auto cost = [&](int k) {
        return abs(k - a) + abs(k - b);
    };
    int mn = cost(s[1][1]);
    For(u, 1, n) For(d, u, n) {
        int r = 0;
        int now = 0;
        For(l, 1, m) {
            if(r < l) {
                r++; now += s[d][r] - s[u - 1][r];
            }
            while(cost(now) > cost(now + s[d][r + 1] - s[u - 1][r + 1])) {
                r++; now += s[d][r] - s[u - 1][r];
            }
            mn = min(mn, cost(now));
        }
    }
    cout << mn << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -