# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367925 | Kenzo_1114 | Cultivation (JOI17_cultivation) | C++17 | 2 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 310;
int n, m, p, ans = 9;
bool mark[MAXN][MAXN];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool valid()
{
bool ok = true;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
ok &= mark[i][j];
return ok;
}
void BKT(int moves)
{
if(moves >= ans) return;
if(valid()) { ans = min(ans, moves); return; }
bool cur[5][5];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cur[i][j] = mark[i][j];
for(int k = 0; k < 4; k++)
{
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
int ni = i + dx[k];
int nj = j + dy[k];
mark[i][j] = cur[i][j] || cur[ni][nj];
}
BKT(moves + 1);
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
mark[i][j] = cur[i][j];
}
int main ()
{
scanf("%d %d %d", &n, &m, &p);
for(int i = 0, x, y; i < p; i++)
{
scanf("%d %d", &x, &y);
mark[x][y] = true;
}
if(n <= 4 && m <= 4)
{
BKT(0);
printf("%d\n", ans);
}
else printf("0\n");
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |