QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425979#6534. Peg SolitaireyukinoWA 83ms3628kbC++173.6kb2024-05-30 19:52:222024-05-30 19:52:23

Judging History

你现在查看的是最新测评结果

  • [2024-05-30 19:52:23]
  • 评测
  • 测评结果:WA
  • 用时:83ms
  • 内存:3628kb
  • [2024-05-30 19:52:22]
  • 提交

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;
bool vis[10][10];
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);
    for(int x=1;x<=n;x++)
    {
        for(int y=1;y<=m;y++)
        {
            if(vis[x][y]==0)
            {
                vis[x][y]=1;
                dfs(a,cnt,x,y,n,m);
                vis[x][y]=0;
            }

        }
    }
   if(i-1>=1&&a[i-1][j]==1)
   {
       if(i-2>=1&&a[i-2][j]==0&&vis[i-2][j]==0)
       {
           a[i][j]=0;
           a[i-1][j]=0;
           a[i-2][j]=1;
           vis[i-2][j]=1;
           dfs(a,cnt-1,i-2,j,n,m);
           vis[i-2][j]=0;
           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&&vis[i+2][j]==0)
       {
           a[i][j]=0;
           a[i+1][j]=0;
           a[i+2][j]=1;
           vis[i+2][j]=1;
           dfs(a,cnt-1,i+2,j,n,m);
           vis[i+2][j]=0;
           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&&vis[i][j+2]==0)
        {
            a[i][j]=0;
            a[i][j+1]=0;
            a[i][j+2]=1;
            vis[i][j+2]=1;
            dfs(a,cnt-1,i,j+2,n,m);
            vis[i][j+2]=0;
            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&&vis[i][j-2]==0)
        {
            a[i][j]=0;
            a[i][j-1]=0;
            a[i][j-2]=1;
            vis[i][j-2]=1;
            dfs(a,cnt-1,i,j-2,n,m);
            vis[i][j-2]=0;
            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";
            vis[i][j]=1;
            dfs(a,cnt,i,j,n,m);
            vis[i][j]=0;
        }
    }
    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: 1ms
memory: 3620kb

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: 83ms
memory: 3628kb

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
3
2

result:

wrong answer 19th numbers differ - expected: '2', found: '3'