QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425959 | #6534. Peg Solitaire | yukino | WA | 1ms | 3640kb | C++17 | 2.9kb | 2024-05-30 19:38:56 | 2024-05-30 19:38:57 |
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]==1)
{
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]==1)
{
a[i-1][j]=0;
a[i][j]=0;
a[i][j+1]=1;
dfs(a,cnt-1,i+1,j,n,m);
a[i-1][j]=1;
a[i][j]=1;
a[i][j+1]=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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 1ms
memory: 3636kb
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 3 1 4 1 1 3 3 2 1 5 3 4 1 4 1 4 2
result:
wrong answer 4th numbers differ - expected: '1', found: '3'