Submission #872963

# Submission time Handle Problem Language Result Execution time Memory
872963 2023-11-14T07:44:59 Z TAhmed33 Zemljište (COCI22_zemljiste) C++
0 / 70
1 ms 348 KB

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll pref[501][501], n, m, a, b;
    ll dist (ll x) {
    	return abs(x - a) + abs(x - b);
    }
    int main () {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	cin >> n >> m >> a >> b;
    	for (int i = 1; i <= n; i++) {
    		for (int j = 1; j <= m; j++) {
    			cin >> pref[i][j]; pref[i][j] += pref[i - 1][j];
    		}
    	}
    	ll mn = 1e18;
    	for (int l = 1; l <= n; l++) {
    		for (int r = l; r <= n; r++) {
    			ll arr[m + 1] = {};
    			for (int j = 1; j <= m; j++) {
    				arr[j] = pref[r][j] - pref[l - 1][j];
    				arr[j] += arr[j - 1];
    			}
    			int ptr = 1, ptr2 = 1;
    			for (int i = 1; i <= m; i++) {
    				while (ptr && arr[i] - arr[ptr] < a) ptr--;
    				ptr++;
    				while (ptr2 && arr[i] - arr[ptr2] < b) ptr2--;
    				ptr2++;
                    if (i != ptr) mn = min(mn, dist(arr[i] - arr[ptr]));
                    if (i != ptr2) mn = min(mn, dist(arr[i] - arr[ptr2]));
                    if (i != ptr - 1) mn = min(mn, dist(arr[i] - arr[ptr - 1]));
    			}
    		}
    	}
    	cout << mn << '\n';
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -