답안 #704855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704855 2023-03-03T05:40:34 Z PixelCat Zemljište (COCI22_zemljiste) C++14
70 / 70
453 ms 2388 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 510;

int s[MAXN][MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // nya ><
    int n, m, a, b; cin >> n >> m >> a >> b;
    For(i, 1, n) For(j, 1, m) {
        cin >> s[i][j];
        s[i][j] += s[i - 1][j];
    }
    auto cost = [&](int k) {
        return abs(k - a) + abs(k - b);
    };
    int mn = cost(s[1][1]);
    For(u, 1, n) For(d, u, n) {
        int r = 0;
        int now = 0;
        For(l, 1, m) {
            if(r < l) {
                r++; now += s[d][r] - s[u - 1][r];
            }
            while(cost(now) > cost(now + s[d][r + 1] - s[u - 1][r + 1])) {
                r++; now += s[d][r] - s[u - 1][r];
            }
            mn = min(mn, cost(now));
            now -= s[d][l] - s[u - 1][l];
        }
    }
    cout << mn << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 728 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 7 ms 728 KB Output is correct
20 Correct 5 ms 724 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 4 ms 728 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 7 ms 728 KB Output is correct
20 Correct 5 ms 724 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
23 Correct 319 ms 2304 KB Output is correct
24 Correct 317 ms 2304 KB Output is correct
25 Correct 312 ms 2252 KB Output is correct
26 Correct 323 ms 2304 KB Output is correct
27 Correct 219 ms 2288 KB Output is correct
28 Correct 335 ms 2304 KB Output is correct
29 Correct 309 ms 2236 KB Output is correct
30 Correct 374 ms 2304 KB Output is correct
31 Correct 57 ms 2004 KB Output is correct
32 Correct 307 ms 2388 KB Output is correct
33 Correct 352 ms 2304 KB Output is correct
34 Correct 309 ms 2308 KB Output is correct
35 Correct 327 ms 2300 KB Output is correct
36 Correct 322 ms 2304 KB Output is correct
37 Correct 310 ms 2304 KB Output is correct
38 Correct 335 ms 2304 KB Output is correct
39 Correct 306 ms 2308 KB Output is correct
40 Correct 352 ms 2300 KB Output is correct
41 Correct 407 ms 2304 KB Output is correct
42 Correct 426 ms 2316 KB Output is correct
43 Correct 409 ms 2304 KB Output is correct
44 Correct 453 ms 2304 KB Output is correct