Submission #1096560

# Submission time Handle Problem Language Result Execution time Memory
1096560 2024-10-04T18:26:11 Z arman_ferdous Cultivation (JOI17_cultivation) C++17
5 / 100
2000 ms 600 KB
#ifdef DeBuG
#include "debug.h"
#else
#include <bits/stdc++.h>
#define dbg(...)
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) begin(v),end(v)
#define rep(i,a,b) for (int i=(a);i<(b);++i)
using ll = long long; template <class T> using V = vector<T>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

int R, C, N;

struct Rect {
    int x1, y1, x2, y2;
    Rect () {}

    void up () { x1 = max(x1 - 1, 1); }
    void dw () { x2 = min(x2 + 1, R); }
    void le () { y1 = max(y1 - 1, 1); }
    void ri () { y2 = min(y2 + 1, C); }
    void up (int k) { while (k--) up(); }
    void dw (int k) { while (k--) dw(); }
    void le (int k) { while (k--) le(); }
    void ri (int k) { while (k--) ri(); }
};

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> R >> C >> N;
    V<Rect> rect(N);
    for (int i = 0; i < N; ++i) {
        int x, y; cin >> x >> y;
        rect[i].x1 = rect[i].x2 = x;
        rect[i].y1 = rect[i].y2 = y;
    }

    int ans = R + C - 2;
    for (int i1 = 0; i1 < N; ++i1) for (int i2 = 0; i2 < N; ++i2) {
        int u = rect[i1].x1 - 1;
        int d = R - rect[i2].x2;

        V<Rect> a = rect;
        for (int i = 0; i < N; ++i) { a[i].up(u); a[i].dw(d); }
        
        int n1 = 0, n2 = 0, n3 = 0;
        V<int> pts[R + 1];
        for (int i = 1; i <= R; ++i) {
            for (int j = 0; j < N; ++j) if (a[j].x1 <= i && i <= a[j].x2) 
                pts[i].pb(a[j].y1);
            sort(all(pts[i]));
        }
        for (int i = 1; i <= R; ++i) {
            if (pts[i].empty()) { n1 = 1e9, n2 = 1e9; break; }
            n1 = max(n1, pts[i][0] - 1);
            n2 = max(n2, C - pts[i].back());
        }
        for (int i = 1; i <= R; ++i) {
            for (int j = 0; j + 1 < sz(pts[i]); ++j) {
                int x = pts[i][j] + n2, y = pts[i][j + 1] - n1;
                if (x + 1 < y) n3 = max(n3, y - x - 1);
            }
        }
        // dbg(u, d, n1, n2, n3);
        ans = min(ans, u + d + n1 + n2 + n3);
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 63 ms 600 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 45 ms 348 KB Output is correct
22 Correct 685 ms 348 KB Output is correct
23 Correct 16 ms 344 KB Output is correct
24 Execution timed out 2081 ms 492 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 63 ms 600 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 45 ms 348 KB Output is correct
22 Correct 685 ms 348 KB Output is correct
23 Correct 16 ms 344 KB Output is correct
24 Execution timed out 2081 ms 492 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2021 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2021 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 63 ms 600 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 45 ms 348 KB Output is correct
22 Correct 685 ms 348 KB Output is correct
23 Correct 16 ms 344 KB Output is correct
24 Execution timed out 2081 ms 492 KB Time limit exceeded
25 Halted 0 ms 0 KB -