Submission #873063

# Submission time Handle Problem Language Result Execution time Memory
873063 2023-11-14T11:48:06 Z TAhmed33 Zemljište (COCI22_zemljiste) C++
70 / 70
441 ms 2660 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;
    if (a > b) swap(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;
            for (int i = 1; i <= m; i++) {
                while (arr[i] - arr[ptr] >= a && ptr < i) ptr++;
                mn = min(mn,  dist(arr[i] - arr[ptr]));
                if (ptr) mn = min(mn, dist(arr[i] - arr[ptr - 1]));
            }
        }
    }
    cout << mn << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 856 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 5 ms 856 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 856 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 5 ms 856 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 860 KB Output is correct
23 Correct 413 ms 2392 KB Output is correct
24 Correct 405 ms 2396 KB Output is correct
25 Correct 400 ms 2396 KB Output is correct
26 Correct 411 ms 2660 KB Output is correct
27 Correct 269 ms 2308 KB Output is correct
28 Correct 437 ms 2656 KB Output is correct
29 Correct 399 ms 2392 KB Output is correct
30 Correct 400 ms 2396 KB Output is correct
31 Correct 65 ms 2136 KB Output is correct
32 Correct 441 ms 2408 KB Output is correct
33 Correct 402 ms 2384 KB Output is correct
34 Correct 404 ms 2396 KB Output is correct
35 Correct 407 ms 2640 KB Output is correct
36 Correct 420 ms 2396 KB Output is correct
37 Correct 401 ms 2392 KB Output is correct
38 Correct 401 ms 2396 KB Output is correct
39 Correct 405 ms 2400 KB Output is correct
40 Correct 401 ms 2396 KB Output is correct
41 Correct 383 ms 2392 KB Output is correct
42 Correct 374 ms 2396 KB Output is correct
43 Correct 377 ms 2448 KB Output is correct
44 Correct 391 ms 2396 KB Output is correct