QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141399 | #6534. Peg Solitaire | cy1999 | AC ✓ | 1ms | 3624kb | C++20 | 1.2kb | 2023-08-17 11:37:02 | 2023-08-17 11:37:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=7,dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int a[N][N],n,m,k,ans=10;
void dfs(){
// for(int x=1; x<=n; x++,putchar('\n'))
// for(int y=1; y<=m; y++) cout<<a[x][y]<<' ';
int cc=0;
for(int x=1; x<=n; x++){
for(int y=1; y<=m; y++){
if(!a[x][y]) continue;
for(int k=0; k<4; k++){
int xx=x+dir[k][0],yy=y+dir[k][1];
if(xx<1||yy<1||xx>n||yy>m) continue;
if(xx+dir[k][0]<1||yy+dir[k][1]<1||xx+dir[k][0]>n||yy+dir[k][1]>m) continue;
if(a[xx][yy]==0) continue;
if(a[xx+dir[k][0]][yy+dir[k][1]]) continue;
a[xx][yy]=0;
a[x][y]=0;
a[xx+dir[k][0]][yy+dir[k][1]]=1;
dfs();
cc++;
a[x][y]=1;
a[xx][yy]=1;
a[xx+dir[k][0]][yy+dir[k][1]]=0;
}
}
}
if(!cc){
int cnt=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cnt+=a[i][j];
}
}
ans=min(ans,cnt);
}
}
void solve(){
ans=10;
cin>>n>>m>>k;
memset(a,0,sizeof a);
for(int i=1; i<=k; i++){
int x,y;
cin>>x>>y;
a[x][y]=1;
}
dfs();
cout<<ans<<'\n';
}
int main(){
int T;
cin>>T;
while(T--) solve();
return 0;
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3340kb
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: 3624kb
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: 0
Accepted
time: 1ms
memory: 3448kb
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 2 6 2 2 3 4 1 1 1 3 2
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
20 1 5 3 1 2 1 3 1 1 5 6 6 5 4 2 4 4 4 4 6 2 5 3 3 5 2 4 4 1 3 1 4 2 5 2 6 3 6 3 1 5 2 3 2 4 1 4 3 3 3 5 3 5 5 2 2 2 3 1 4 3 3 2 6 1 4 3 1 5 1 1 1 4 1 3 5 6 1 1 2 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