#include <bits/stdc++.h>
using namespace std;
int r, c;
bitset<1600> moveleft(bitset<1600> mask) {
for (int i = 0; i < r; i++)
mask[i * c] = false;
return mask >> 1;
}
bitset<1600> moveright(bitset<1600> mask) {
for (int i = 0; i < r; i++)
mask[i * c + c - 1] = false;
return mask << 1;
}
bitset<1600> moveup(bitset<1600> mask) {
for (int i = 0; i < c; i++)
mask[i] = false;
mask >>= c;
for (int i = 0; i < c; i++)
mask[(r - 1) * c + i] = false;
return mask;
}
bitset<1600> movedown(bitset<1600> mask) {
for (int i = 0; i < c; i++)
mask[(r - 1) * c + i] = false;
return mask << c;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> r >> c;
int n;
cin >> n;
vector<pair<int, int>> pts;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
swap(x, y);
pts.push_back({x, y});
}
swap(r, c);
bitset<1600> init(0);
for (auto p : pts) {
if ((p.first - 1) * c + p.second - 1 < 1600)
init[(p.first - 1) * c + p.second - 1] = true;
}
for (int ans = 0; ans <= 100; ans++) {
for (int p = 0; p <= c && p <= ans; p++) {
for (int q = 0; q <= c && q <= ans; q++) {
for (int s = 0; s <= r && s <= ans; s++) {
int t = ans - p - q - s;
if (t < 0 || t > r)
continue;
auto state = init;
int comm = max({p, q, s, t});
for (int _ = 0; _ < comm; _++) {
if (_ < p)
state |= moveleft(state);
if (_ < s)
state |= moveup(state);
if (_ < q)
state |= moveright(state);
if (_ < t)
state |= movedown(state);
}
if (state.count() >= r * c) {
cout << ans << endl;
return 0;
}
}
}
}
}
cout << c - 1 + r - 1 << endl;
return 0;
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:66:39: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | if (state.count() >= r * c) {
| ~~~~~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
97 ms |
432 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
1002 ms |
424 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
764 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
456 KB |
Output is correct |
26 |
Correct |
15 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
97 ms |
432 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
1002 ms |
424 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
764 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
456 KB |
Output is correct |
26 |
Correct |
15 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 7 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 7 |
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 |
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 |
1 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 |
1 ms |
404 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
97 ms |
432 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
1002 ms |
424 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
764 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
7 ms |
456 KB |
Output is correct |
26 |
Correct |
15 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |