# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1071367 | Plurm | Cultivation (JOI17_cultivation) | C++11 | 2036 ms | 348 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;
int r, c;
bitset<16> moveleft(bitset<16> mask) {
mask[0] = mask[c] = mask[2 * c] = mask[3 * c] = false;
return mask >> 1;
}
bitset<16> moveright(bitset<16> mask) {
mask[c - 1] = mask[2 * c - 1] = mask[3 * c - 1] = mask[4 * c - 1] = false;
return mask << 1;
}
bitset<16> moveup(bitset<16> mask) {
for (int i = 0; i < c; i++)
mask[i] = false;
return mask >> c;
}
bitset<16> movedown(bitset<16> 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;
pts.push_back({x, y});
}
for (int ans = 0; ans < 10; ans++) {
for (int mask = 0; mask < (1 << (2 * ans)); mask++) {
bitset<16> state(0);
for (auto p : pts) {
state[(p.first - 1) * c + p.second - 1] = true;
}
for (int i = 0; i < ans; i++) {
int dir1 = mask & (1 << (2 * i)) ? 1 : 0;
int dir2 = mask & (1 << (2 * i + 1)) ? 1 : 0;
int dir = dir1 * 2 + dir2;
switch (dir) {
case 0:
state |= moveleft(state);
break;
case 1:
state |= moveright(state);
break;
case 2:
state |= moveup(state);
break;
case 3:
state |= movedown(state);
break;
}
}
if (state.count() >= r * c) {
cout << ans << endl;
return 0;
}
}
}
}
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... |