QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357845#6534. Peg SolitairePorNPtree#WA 0ms3720kbC++20976b2024-03-19 13:51:162024-03-19 13:51:16

Judging History

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

  • [2024-03-19 13:51:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-03-19 13:51:16]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fi first
#define se second
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=9,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int T,n,m,K,a[N][N],ans;
inline bool chk(int x,int y){return 1<=x&&x<=n&&1<=y&&y<=m;}
void dfs()
{
	int cnt=0;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]) cnt++;ans=min(ans,cnt);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j])
	{
		for(int k=0;k<4;k++)
		{
			int nx=i+dx[k],ny=j+dy[k],Nx=nx+dx[k],Ny=ny+dy[k];
			if(!a[nx][ny]||a[Nx][Ny]||!chk(Nx,Ny)) continue;
			a[i][j]=a[nx][ny]=0;a[Nx][Ny]=1;
			dfs();
			a[i][j]=a[nx][ny]=0;a[Nx][Ny]=1;
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
	while(T--)
	{
		cin>>n>>m>>K;ans=K;
		for(int i=1,x,y;i<=K;i++) cin>>x>>y,a[x][y]=1;
		dfs();cout<<ans<<"\n";
		memset(a,0,sizeof(a));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

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: 3720kb

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

result:

wrong answer 4th numbers differ - expected: '1', found: '2'