# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
967447 | 2024-04-22T06:31:27 Z | Isam | Zemljište (COCI22_zemljiste) | C++17 | 609 ms | 5692 KB |
#include<bits/stdc++.h> using namespace std; constexpr long long inf = 1e18 + 7; int r, s, a, b, c[501][501]; long long pref[501][501], ans; inline long long get_cost(long long sm){ return abs(sm - a) + abs(sm - b); } inline long long get_sm(int x1, int x2, int y1, int y2){ long long res = pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1]; //if(x1!=x2||y1!=y2) ans = min(ans, get_cost(res)); return res; } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); cin >> r >> s >> a >> b; if(a>b) swap(a, b); for(register int i = 1; i <= r; ++i){ for(register int j = 1; j <= s; ++j){ cin >> c[i][j]; pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1] + c[i][j]; } } ans = pref[r][s]; long long sm(0), cost(0), next_sm(0), cur_sm(0), cur_cost(inf), prev_cost(inf), next_cost(inf); for(register int x1 = 0; x1 <= r; ++x1){ for(register int x2 = x1; x2 <= r; ++x2){ int y1(0), y2(0); cur_cost = prev_cost = next_cost = inf; while(max(y1, y2) <= s){ next_sm = get_sm(x1, x2, y1, y2 + 1); next_cost = get_cost(next_sm); if(next_cost > prev_cost){ ++y1; }else{ ++y2; } cur_sm = get_sm(x1, x2, y1, y2); cur_cost = get_cost(cur_sm); if(x1!=x2||y1!=y2) ans = min(ans, cur_cost); prev_cost = cur_cost; } } } cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 2 ms | 2560 KB | Output is correct |
6 | Correct | 1 ms | 2516 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 2 ms | 2560 KB | Output is correct |
6 | Correct | 1 ms | 2516 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 3 ms | 2648 KB | Output is correct |
11 | Correct | 6 ms | 2652 KB | Output is correct |
12 | Correct | 6 ms | 2652 KB | Output is correct |
13 | Correct | 7 ms | 2652 KB | Output is correct |
14 | Correct | 1 ms | 2396 KB | Output is correct |
15 | Correct | 6 ms | 2736 KB | Output is correct |
16 | Correct | 6 ms | 2652 KB | Output is correct |
17 | Correct | 6 ms | 2648 KB | Output is correct |
18 | Correct | 5 ms | 2532 KB | Output is correct |
19 | Correct | 5 ms | 2652 KB | Output is correct |
20 | Correct | 5 ms | 2652 KB | Output is correct |
21 | Correct | 5 ms | 2652 KB | Output is correct |
22 | Correct | 7 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 2 ms | 2560 KB | Output is correct |
6 | Correct | 1 ms | 2516 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2392 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 3 ms | 2648 KB | Output is correct |
11 | Correct | 6 ms | 2652 KB | Output is correct |
12 | Correct | 6 ms | 2652 KB | Output is correct |
13 | Correct | 7 ms | 2652 KB | Output is correct |
14 | Correct | 1 ms | 2396 KB | Output is correct |
15 | Correct | 6 ms | 2736 KB | Output is correct |
16 | Correct | 6 ms | 2652 KB | Output is correct |
17 | Correct | 6 ms | 2648 KB | Output is correct |
18 | Correct | 5 ms | 2532 KB | Output is correct |
19 | Correct | 5 ms | 2652 KB | Output is correct |
20 | Correct | 5 ms | 2652 KB | Output is correct |
21 | Correct | 5 ms | 2652 KB | Output is correct |
22 | Correct | 7 ms | 2652 KB | Output is correct |
23 | Correct | 524 ms | 5692 KB | Output is correct |
24 | Correct | 548 ms | 5684 KB | Output is correct |
25 | Correct | 588 ms | 5688 KB | Output is correct |
26 | Correct | 589 ms | 5684 KB | Output is correct |
27 | Correct | 381 ms | 4916 KB | Output is correct |
28 | Correct | 552 ms | 5684 KB | Output is correct |
29 | Correct | 596 ms | 5692 KB | Output is correct |
30 | Correct | 518 ms | 5688 KB | Output is correct |
31 | Correct | 69 ms | 3416 KB | Output is correct |
32 | Correct | 601 ms | 5688 KB | Output is correct |
33 | Correct | 566 ms | 5688 KB | Output is correct |
34 | Correct | 587 ms | 5684 KB | Output is correct |
35 | Correct | 531 ms | 5688 KB | Output is correct |
36 | Correct | 565 ms | 5688 KB | Output is correct |
37 | Correct | 526 ms | 5688 KB | Output is correct |
38 | Correct | 546 ms | 5692 KB | Output is correct |
39 | Correct | 574 ms | 5688 KB | Output is correct |
40 | Correct | 544 ms | 5688 KB | Output is correct |
41 | Correct | 560 ms | 4540 KB | Output is correct |
42 | Correct | 542 ms | 4444 KB | Output is correct |
43 | Correct | 539 ms | 4544 KB | Output is correct |
44 | Correct | 609 ms | 4544 KB | Output is correct |