QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#698521 | #6534. Peg Solitaire | 0x3fffffff | WA | 1ms | 3876kb | C++23 | 2.9kb | 2024-11-01 20:09:05 | 2024-11-01 20:09:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector a(n + 1, vector<int>(m + 1));
for (int i = 1;i <= k;i++) {
int x, y;cin >> x >> y;
a[x][y] = 1;
}
// for (int i = 1;i <= n;i++) {
// for (int j = 1;j <= m;j++) {
// cout << a[i][j] << " ";
// }
// cout << "\n";
// }
int ans = k;
auto ch = [&]() {
for (int i = 1;i <= n;i++) {
for (int j = 1;j < m;j++) {
if (a[i][j] == 1 and a[i][j + 1] == 1)return 0;
}
}
for (int i = 1;i < n;i++) {
for (int j = 1;j <= m;j++) {
if (a[i][j] and a[i + 1][j])return 0;
}
}
int cnt = 0;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
if (a[i][j])cnt++;
}
}
ans = min(ans, cnt);
return 1;
};
auto dfs = [&](auto&& ff, int x, int y)->void {
ch();
for (int i = 1;i <= n;i++) {
for (int j = 1;j < m;j++) {
if (a[i][j] == 1 and a[i][j + 1] == 1) {
if (j + 1 < m and a[i][j + 2] == 0) {
a[i][j + 2] = 1;
a[i][j] = 0;a[i][j + 1] = 0;
ff(ff, x, y);
a[i][j + 2] = 0;
a[i][j] = 1;a[i][j + 1] = 1;
}
if (j > 1 and a[i][j - 1] == 0) {
a[i][j - 1] = 1;
a[i][j] = 0;a[i][j + 1] = 0;
ff(ff, x, y);
a[i][j - 1] = 0;
a[i][j] = 1;a[i][j + 1] = 1;
}
}
}
}
for (int i = 1;i < n;i++) {
for (int j = 1;j <= m;j++) {
if (a[i][j] == 1 and a[i + 1][j] == 1) {
if (i + 1 < n and a[i + 2][j] == 0) {
a[i + 2][j] = 1;
a[i][j] = 0;a[i + 1][j] = 0;
ff(ff, x, y);
a[i + 2][j] = 0;
a[i][j] = 1;a[i + 1][j] = 1;
}
if (i > 1 and a[i - 1][j] == 0) {
a[i - 1][j] = 1;
a[i][j] = 0;a[i + 1][j] = 0;
ff(ff, x, y);
a[i - 1][j] = 0;
a[i][j] = 1;a[i + 1][j] = 1;
}
}
}
}
return;
};
dfs(dfs, 1, 1);
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
#ifdef LOCAL
freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
#endif
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
3 3 4 5 2 2 1 2 1 4 3 4 1 1 1 3 3 1 1 1 2 1 3 2 1 1 2 1
output:
2 3 1
result:
ok 3 number(s): "2 3 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
20 2 1 2 1 1 2 1 5 1 3 3 1 2 1 4 1 3 3 6 1 2 2 2 1 1 2 3 3 1 3 2 4 4 4 2 3 3 1 3 2 1 2 1 1 1 1 1 5 2 6 3 2 4 1 2 1 5 2 2 2 5 1 1 3 1 1 2 1 5 1 1 5 4 6 5 4 6 4 4 2 3 4 3 1 6 6 6 3 2 4 1 3 2 1 2 2 2 2 1 1 1 5 3 4 2 2 5 1 4 3 3 2 6 5 6 5 5 6 5 2 4 2 1 3 4 1 4 2 6 5 1 6 2 1 1 4 2 3 1 3 3 5 6 2 1 3 3 1 5...
output:
2 2 3 1 1 2 1 1 3 3 2 1 3 3 2 1 3 1 2 2
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3840kb
input:
20 2 1 1 2 1 4 3 2 4 3 1 1 6 4 6 4 3 5 4 4 2 3 2 3 4 2 3 3 6 4 3 1 2 6 2 4 3 5 6 6 6 3 3 3 6 4 2 3 2 4 1 1 4 3 3 1 1 1 2 3 2 2 2 2 1 3 2 2 1 2 2 2 3 4 5 2 1 3 4 3 1 2 2 3 2 2 5 5 1 5 2 3 2 5 1 4 2 2 5 6 6 5 1 2 2 1 4 5 3 4 4 1 1 2 3 4 1 1 1 2 2 2 2 1 2 3 4 1 1 2 1 1 2 2 2 6 3 6 4 2 4 1 1 3 6 2 3 3 2...
output:
1 2 2 4 4 1 1 1 2 3 6 4 4 3 5 1 1 1 3 2
result:
wrong answer 10th numbers differ - expected: '2', found: '3'