Submission #1096490

# Submission time Handle Problem Language Result Execution time Memory
1096490 2024-10-04T15:39:32 Z arman_ferdous Cultivation (JOI17_cultivation) C++17
15 / 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 calc (bitset<41> &f, int c) {
    int ret = 0;
    for (int i = 1; i <= c; ++i) if (f[i] == 0) {
        int j = i;
        while (j + 1 <= c && f[j + 1] == 0) ++j;
        ret = max(ret, j - i + 1);
        i = j;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int r, c, n;
    cin >> r >> c >> n;
    V<int> x(n), y(n);
    for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];

    int ans = r + c - 2;
    V<bitset<41>> b(41);
    for (int i = 0; i < n; ++i) b[x[i]][y[i]] = 1;

    for (int u = 0; u < r; ++u) for (int d = 0; d < r; ++d) {
        V<bitset<41>> f = b;
        for (int i = 0; i < u; ++i) {
            for (int j = 1; j < r; ++j) f[j] |= f[j + 1];
        }
        for (int i = 0; i < d; ++i) {
            for (int j = r; j > 1; --j) f[j] |= f[j - 1];
        }
        bool bad = false;
        for (int j = 1; j <= r; ++j) if (f[j] == 0) bad = true;
        if (bad) continue;

        for (int l = 0; l < c; ++l) {
            V<bitset<41>> foo = f;
            for (int i = 0; i < l; ++i) for (int j = 1; j <= r; ++j) foo[j] |= foo[j] << 1;

            bad = false;
            for (int j = 1; j <= r; ++j) if (foo[j][c] == 0) bad = true;
            if (bad) continue;

            int ri = 0;
            for (int j = 1; j <= r; ++j) {
                ri = max(ri, calc(foo[j], c));
            }

            if (u + d + l + ri < ans) { 
                dbg(u, d, l, ri);
                ans = min(ans, u + d + l + ri);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 452 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 0 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 0 ms 348 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 0 ms 344 KB Output is correct
2 Correct 0 ms 452 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 0 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 0 ms 348 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 1 ms 348 KB Output is correct
18 Correct 13 ms 452 KB Output is correct
19 Correct 71 ms 428 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 38 ms 348 KB Output is correct
22 Correct 79 ms 348 KB Output is correct
23 Correct 22 ms 344 KB Output is correct
24 Correct 77 ms 348 KB Output is correct
25 Correct 77 ms 344 KB Output is correct
26 Correct 77 ms 344 KB Output is correct
27 Correct 80 ms 344 KB Output is correct
28 Correct 75 ms 344 KB Output is correct
29 Correct 63 ms 348 KB Output is correct
30 Correct 85 ms 436 KB Output is correct
31 Correct 88 ms 348 KB Output is correct
32 Correct 78 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 452 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 0 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 0 ms 348 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 1 ms 348 KB Output is correct
18 Correct 13 ms 452 KB Output is correct
19 Correct 71 ms 428 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 38 ms 348 KB Output is correct
22 Correct 79 ms 348 KB Output is correct
23 Correct 22 ms 344 KB Output is correct
24 Correct 77 ms 348 KB Output is correct
25 Correct 77 ms 344 KB Output is correct
26 Correct 77 ms 344 KB Output is correct
27 Correct 80 ms 344 KB Output is correct
28 Correct 75 ms 344 KB Output is correct
29 Correct 63 ms 348 KB Output is correct
30 Correct 85 ms 436 KB Output is correct
31 Correct 88 ms 348 KB Output is correct
32 Correct 78 ms 436 KB Output is correct
33 Execution timed out 2064 ms 348 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 452 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 0 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 0 ms 348 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 1 ms 348 KB Output is correct
18 Correct 13 ms 452 KB Output is correct
19 Correct 71 ms 428 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 38 ms 348 KB Output is correct
22 Correct 79 ms 348 KB Output is correct
23 Correct 22 ms 344 KB Output is correct
24 Correct 77 ms 348 KB Output is correct
25 Correct 77 ms 344 KB Output is correct
26 Correct 77 ms 344 KB Output is correct
27 Correct 80 ms 344 KB Output is correct
28 Correct 75 ms 344 KB Output is correct
29 Correct 63 ms 348 KB Output is correct
30 Correct 85 ms 436 KB Output is correct
31 Correct 88 ms 348 KB Output is correct
32 Correct 78 ms 436 KB Output is correct
33 Execution timed out 2064 ms 348 KB Time limit exceeded
34 Halted 0 ms 0 KB -