Submission #644391

# Submission time Handle Problem Language Result Execution time Memory
644391 2022-09-24T14:56:24 Z Iwanttobreakfree Zemljište (COCI22_zemljiste) C++17
70 / 70
237 ms 4780 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[i][l]+grid[j][l] > b) {
                    int val = grid[i][r]-grid[j][r]-grid[i][l]+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[i][l]+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 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 5 ms 484 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 476 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 428 KB Output is correct
21 Correct 4 ms 312 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 5 ms 484 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 476 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 4 ms 428 KB Output is correct
21 Correct 4 ms 312 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 237 ms 4780 KB Output is correct
24 Correct 225 ms 4676 KB Output is correct
25 Correct 222 ms 4672 KB Output is correct
26 Correct 232 ms 4680 KB Output is correct
27 Correct 151 ms 3208 KB Output is correct
28 Correct 226 ms 4672 KB Output is correct
29 Correct 229 ms 4672 KB Output is correct
30 Correct 224 ms 4676 KB Output is correct
31 Correct 31 ms 852 KB Output is correct
32 Correct 222 ms 4660 KB Output is correct
33 Correct 228 ms 4688 KB Output is correct
34 Correct 226 ms 4676 KB Output is correct
35 Correct 227 ms 4680 KB Output is correct
36 Correct 233 ms 4692 KB Output is correct
37 Correct 227 ms 4680 KB Output is correct
38 Correct 223 ms 4676 KB Output is correct
39 Correct 235 ms 4672 KB Output is correct
40 Correct 225 ms 4684 KB Output is correct
41 Correct 182 ms 3416 KB Output is correct
42 Correct 199 ms 3412 KB Output is correct
43 Correct 186 ms 3400 KB Output is correct
44 Correct 182 ms 3404 KB Output is correct