QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141409 | #6534. Peg Solitaire | cy1999 | WA | 1ms | 3468kb | C++17 | 1.7kb | 2023-08-17 11:44:29 | 2023-08-17 11:44:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bool mp[10][10];
int n,m,k,ans;
struct P{
int x,y;
};
P find(){
for(int x=1;x<=n;x++){
for(int y=1;y<=m;y++){
if(mp[x][y]){
if(x-2>=1&&mp[x-1][y]&&!mp[x-2][y]){
return (P){x,y};
}
if(x+2<=n&&mp[x+1][y]&&!mp[x+2][y]){
return (P){x,y};
}
if(y-2>=1&&mp[x][y-1]&&!mp[x][y-2]){
return (P){x,y};
}
if(y+2<=m&&mp[x][y+1]&&!mp[x][y+2]){
return (P){x,y};
}
}
}
}
return (P){0,0};
}
void tiao(int x,int y){
// P now=find();
if(x==0&&y==0) {
int res=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
res+=mp[i][j];
}
}
ans=min(ans,res);
return;
}
// cout<<x<<" "<<y<<endl;
bool f=0;
mp[x][y]=0;
if(x-2>=1&&mp[x-1][y]&&!mp[x-2][y]){
mp[x-1][y]=0;mp[x-2][y]=1;
tiao(x-2,y);
mp[x-1][y]=1;mp[x-2][y]=0;
f=1;
}
if(x+2<=n&&mp[x+1][y]&&!mp[x+2][y]){
mp[x+1][y]=0;mp[x+2][y]=1;
tiao(x+2,y);
mp[x+1][y]=1;mp[x+2][y]=0;
f=1;
}
if(y-2>=1&&mp[x][y-1]&&!mp[x][y-2]){
mp[x][y-1]=0;mp[x][y-2]=1;
tiao(x,y-2);
mp[x][y-1]=1;mp[x][y-2]=0;
f=1;
}
if(y+2<=m&&mp[x][y+1]&&!mp[x][y+2]){
mp[x][y+1]=0;mp[x][y+2]=1;
tiao(x,y+2);
mp[x][y+1]=1;mp[x][y+2]=0;
f=1;
}
mp[x][y]=1;
if(!f) {
tiao(find().x,find().y);
}
}
int main(){
int t;cin>>t;
while(t--){
cin>>n>>m>>k;
ans=1e9+10;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) mp[i][j]=0;
}
for(int i=1;i<=k;i++){
int x,y;cin>>x>>y;
mp[x][y]=1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]) tiao(i,j);
}
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3396kb
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: 3468kb
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: 3452kb
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: -100
Wrong Answer
time: 1ms
memory: 3456kb
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 1 3 4 1 5 2 2 3 3 2 5 2 2 5 2 1 5 4 6 1 3 4 3 2 2 1 2 3 3 2 3 2 3 3 2 3 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 4 5 2 1 6 2 3 2 1 2 4 2 5...
output:
2 1 2 2 2 2 3 2 2 3 1 1 1 3 2 2 2 3 2 1
result:
wrong answer 5th numbers differ - expected: '1', found: '2'