Submission #1096511

# Submission time Handle Problem Language Result Execution time Memory
1096511 2024-10-04T16:38:21 Z arman_ferdous Cultivation (JOI17_cultivation) C++17
0 / 100
2000 ms 504 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(); }
};

pii calc (V<int> &pts) {
    if (pts.empty()) return {C, C};
    int n = sz(pts);
    int r1 = (pts[0] - 1) + (C - pts[n - 1]), r2 = 0;
    for (int i = 0; i + 1 < n; ++i) {
        int x = pts[i] + (C - pts[n - 1]);
        int y = pts[i + 1] - (pts[0] - 1);
        if (x + 1 < y) r2 = max(r2, y - x - 1);
    }
    return {r1, r2};
}

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 u = 0; u < R; ++u) for (int d = 0; u + d < R; ++d) {
        V<Rect> a = rect;
        for (int i = 0; i < N; ++i) { a[i].up(u); a[i].dw(d); }
        
        pii need = {0, 0};
        for (int i = 1; i <= R; ++i) {
            V<int> pts;
            for (int j = 0; j < N; ++j) if (a[j].x1 <= i && i <= a[j].x2) 
                pts.pb(a[j].y1);
            sort(all(pts));
            
            pii got = calc(pts);
            need.fi = max(need.fi, got.fi);
            need.se = max(need.se, got.se);
        }
        ans = min(ans, u + d + need.fi + need.se);
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -