Submission #1297376

#TimeUsernameProblemLanguageResultExecution timeMemory
1297376mage__Cultivation (JOI17_cultivation)C++17
0 / 100
1 ms572 KiB
#include<bits/stdc++.h> using namespace std; #define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "CONE" #define opf freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); #define ll long long #define int ll #define ii pair<int, int> #define fi first #define se second #define BIT(k) __builtin_popcount(k) #define _ << " " << #define _n << "\n"; #define _s << " "; #define t_ << "\t" << const int INF = 2e9; int n, r, c; namespace sub1 { const int N = 45; vector<vector<int>> a(N, vector<int>(N)); int ans = INF; int cnt; void backtrack(int huong, int ngay, vector<vector<int>> &a) { ++cnt; // cerr t_ cnt _n if (cnt >= 160) return; vector<vector<int>> ta(N, vector<int>(N)); bool ck = 1; for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 0) { ck = 0; break; } } if (!ck) break; } if (ck) { ans = min(ans, ngay); return; } if (huong == 1) { for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 1) { ta[i][j] = 1; if (j > 1) ta[i][j - 1] = 1; } } } } else if (huong == 2) { for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 1) { ta[i][j] = 1; if (j < c) ta[i][j + 1] = 1; } } } } else if (huong == 3) { for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 1) { ta[i][j] = 1; if (i > 1) ta[i - 1][j] = 1; } } } } else if (huong == 4) { for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 1) { ta[i][j] = 1; if (i < c) ta[i + 1][j] = 1; } } } } if (ta == a) return; if (ngay > 160) return; // for (int i = 1; i <= r; ++i) { // for (int j = 1; j <= c; ++j) { // cerr t_ ta[i][j] _s // } // cerr _n // } backtrack(1, ngay + 1, ta); backtrack(2, ngay + 1, ta); backtrack(3, ngay + 1, ta); backtrack(4, ngay + 1, ta); ta.clear(); } void sol() { cin >> n; for (int i = 1; i <= n; ++i) { int u, v; cin >> u >> v; a[u][v] = 1; } backtrack(1, 0, a); cnt = 0; backtrack(2, 0, a); cnt = 0; backtrack(3, 0, a); cnt = 0; backtrack(4, 0, a); cout << ans _n } } signed main() { fio if (fopen(name".inp", "r")) { opf } cin >> r >> c; if (n == 1) cout << (r + c - 2) _n else if (r <= 40 && c <= 40) sub1::sol(); else cout << min(r - 1, min(c - 1, n)) _n }

Compilation message (stderr)

cultivation.cpp: In function 'int main()':
cultivation.cpp:6:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define opf freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:126:9: note: in expansion of macro 'opf'
  126 |         opf
      |         ^~~
cultivation.cpp:6:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define opf freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:126:9: note: in expansion of macro 'opf'
  126 |         opf
      |         ^~~
#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...