QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425962 | #6534. Peg Solitaire | yukino | WA | 0ms | 3612kb | C++17 | 2.9kb | 2024-05-30 19:41:09 | 2024-05-30 19:41:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define PLL pair<int,int>
const int N=1e5+10;
using namespace std;
int ans;
void dfs( vector<vector<int>>a,int cnt,int i,int j,int n,int m)
{
if(a[i][j]!=1)
return;
ans=min(ans,cnt);
if(i-1>=1&&a[i-1][j]==1)
{
if(i-2>=1&&a[i-2][j]==0)
{
a[i][j]=0;
a[i-1][j]=0;
a[i-2][j]=1;
dfs(a,cnt-1,i-2,j,n,m);
a[i][j]=1;
a[i-1][j]=1;
a[i-2][j]=0;
}
if(i+1<=n&&a[i+1][j]==0)
{
a[i-1][j]=0;
a[i][j]=0;
a[i+1][j]=1;
dfs(a,cnt-1,i+1,j,n,m);
a[i-1][j]=1;
a[i][j]=1;
a[i+1][j]=0;
}
}
if(i+1<=n&&a[i+1][j]==1)
{
if(i+2<=n&&a[i+2][j]==0)
{
a[i][j]=0;
a[i+1][j]=0;
a[i+2][j]=1;
dfs(a,cnt-1,i+2,j,n,m);
a[i][j]=1;
a[i+1][j]=1;
a[i+2][j]=0;
}
if(i-1>=1&&a[i-1][j]==0)
{
a[i+1][j]=0;
a[i][j]=0;
a[i-1][j]=1;
dfs(a,cnt-1,i-1,j,n,m);
a[i+1][j]=1;
a[i][j]=1;
a[i-1][j]=0;
}
}
if(j+1<=m&&a[i][j+1]==1)
{
if(j+2<=m&&a[i][j+2]==0)
{
a[i][j]=0;
a[i][j+1]=0;
a[i][j+2]=1;
dfs(a,cnt-1,i,j+2,n,m);
a[i][j]=1;
a[i][j+1]=1;
a[i][j+2]=0;
}
if(j-1>=1&&a[i][j-1]==0)
{
a[i][j+1]=0;
a[i][j]=0;
a[i][j-1]=1;
dfs(a,cnt-1,i,j-1,n,m);
a[i][j+1]=1;
a[i][j]=1;
a[i][j-1]=0;
}
}
if(j-1>=1&&a[i][j-1]==1)
{
if(j-2>=1&&a[i][j-2]==0)
{
a[i][j]=0;
a[i][j-1]=0;
a[i][j-2]=1;
dfs(a,cnt-1,i,j-2,n,m);
a[i][j]=1;
a[i][j-1]=1;
a[i][j-2]=0;
}
if(j+1<=m&&a[i][j+1]==0)
{
a[i][j-1]=0;
a[i][j]=0;
a[i][j+1]=1;
dfs(a,cnt-1,i,j+1,n,m);
a[i][j-1]=1;
a[i][j]=1;
a[i][j+1]=0;
}
}
}
void solve()
{
int n,m,k;
cin>>n>>m>>k;
vector<vector<int>>a(7,vector<int>(7,0));
int cnt=0;
for(int i=1;i<=k;i++)
{
int x,y;
cin>>x>>y;
a[x][y]=1;
cnt++;
}
ans=cnt;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
//cout<<i<<j<<"\n";
dfs(a,cnt,i,j,n,m);
}
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: -100
Wrong Answer
time: 0ms
memory: 3612kb
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 4 1 1 4 1 1 3 3 2 1 5 3 5 1 4 1 3 2
result:
wrong answer 3rd numbers differ - expected: '3', found: '4'