Submission #932923

# Submission time Handle Problem Language Result Execution time Memory
932923 2024-02-24T14:24:07 Z Amirreza_Fakhri Zemljište (COCI22_zemljiste) C++17
70 / 70
490 ms 4956 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = (1e9+7)*(1e9+7);
const int mod = 998244353;
const int maxn = 5e2+5;

int r, s, a, b, c[maxn][maxn], ps[maxn][maxn];

int f1(int x1, int x2, int y1, int y2) {
    return ps[x2][y2]-ps[x1-1][y2]-ps[x2][y1-1]+ps[x1-1][y1-1];
}

int f2(int x) {
    return abs(x-a)+abs(x-b);
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r >> s >> a >> b;
    if (a > b) swap(a, b);
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= s; j++) {
            cin >> c[i][j];
            ps[i][j] = ps[i-1][j]+ps[i][j-1]-ps[i-1][j-1]+c[i][j];
        }
    }
    int ans = inf;
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= r; j++) {
            int l = 1;
            for (int k = 1; k <= s; k++) {
                while (l < k and f1(i, j, l, k) > b) l++;
                smin(ans, f2(f1(i, j, l, k)));
                if (l-1) smin(ans, f2(f1(i, j, l-1, k)));
            }
        }
    }
    cout << ans << '\n';
    return 0;
} 











# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 5 ms 2852 KB Output is correct
12 Correct 6 ms 2652 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 5 ms 2848 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 4 ms 2860 KB Output is correct
19 Correct 4 ms 2788 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 4 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 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 2648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 5 ms 2852 KB Output is correct
12 Correct 6 ms 2652 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 5 ms 2848 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 4 ms 2860 KB Output is correct
19 Correct 4 ms 2788 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 4 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
23 Correct 487 ms 4408 KB Output is correct
24 Correct 457 ms 4408 KB Output is correct
25 Correct 463 ms 4412 KB Output is correct
26 Correct 457 ms 4412 KB Output is correct
27 Correct 309 ms 4396 KB Output is correct
28 Correct 467 ms 4408 KB Output is correct
29 Correct 454 ms 4432 KB Output is correct
30 Correct 483 ms 4436 KB Output is correct
31 Correct 61 ms 4188 KB Output is correct
32 Correct 460 ms 4416 KB Output is correct
33 Correct 456 ms 4444 KB Output is correct
34 Correct 490 ms 4432 KB Output is correct
35 Correct 458 ms 4412 KB Output is correct
36 Correct 465 ms 4412 KB Output is correct
37 Correct 451 ms 4412 KB Output is correct
38 Correct 456 ms 4956 KB Output is correct
39 Correct 474 ms 4432 KB Output is correct
40 Correct 462 ms 4184 KB Output is correct
41 Correct 330 ms 4432 KB Output is correct
42 Correct 352 ms 4184 KB Output is correct
43 Correct 333 ms 4408 KB Output is correct
44 Correct 326 ms 4184 KB Output is correct