Submission #1096490

#TimeUsernameProblemLanguageResultExecution timeMemory
1096490arman_ferdousCultivation (JOI17_cultivation)C++17
15 / 100
2064 ms600 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...