답안 #1096527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096527 2024-10-04T17:12:20 Z arman_ferdous Cultivation (JOI17_cultivation) C++17
0 / 100
2000 ms 356 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(); }
};

tuple<int,int,int> calc (V<int> &pts) {
    if (pts.empty()) return {1e9, 1e9, 0};
    int n = sz(pts);
    int r1 = (pts[0] - 1), r2 = (C - pts[n - 1]), r3 = 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) r3 = max(r2, y - x - 1);
    }
    return {r1, r2, r3};
}

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); }
        
        int n1 = 0, n2 = 0, n3 = 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));
            
            auto got = calc(pts);
            n1 = max(n1, get<0>(got));
            n2 = max(n2, get<1>(got)); 
            n3 = max(n3, get<2>(got));
        }
        ans = min(ans, u + d + n1 + n2 + n3);
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2102 ms 356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2102 ms 356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -