QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141404 | #6534. Peg Solitaire | cy1999 | AC ✓ | 1ms | 3880kb | C++14 | 1.3kb | 2023-08-17 11:41:20 | 2023-08-17 11:41:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
ll x = 0,f = 1;
char ch = getchar();
while(ch < '0' ||ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ '0');
ch = getchar();
}
return x * f;
}
const int N = 7;
int t; int n, m, k;
bool vis[N][N]; int ans;
int mov[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
void dfs(int st) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (vis[i][j]) {
for (int nw = 0; nw < 4; nw++) {
int xx = i + mov[nw][0], yy = j + mov[nw][1];
int tox = xx + mov[nw][0], toy = yy + mov[nw][1];
if (tox >= 1 && tox <= n && toy >= 1 && toy <= m) {
if (vis[xx][yy] && !vis[tox][toy]) {
vis[tox][toy] = 1; vis[xx][yy] = vis[i][j] = 0;
dfs(st + 1);
vis[tox][toy] = 0; vis[xx][yy] = vis[i][j] = 1;
}
}
}
}
}
}
ans = max(ans, st);
return;
}
int main() {
t = read();
while (t--) {
n = read(), m = read(), k = read();
memset(vis, 0, sizeof vis); ans = 0;
for (int i = 1; i <= k; i++) {
int a = read(), b = read();
vis[a][b] = 1;
}
dfs(0);
printf("%d\n",k - ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
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: 1ms
memory: 3808kb
input:
20 2 1 2 1 1 2 1 5 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