QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418816#6534. Peg SolitaireSIGHT#WA 1ms3684kbC++232.0kb2024-05-23 15:55:562024-05-23 15:55:56

Judging History

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

  • [2024-05-23 15:55:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3684kb
  • [2024-05-23 15:55:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k;
int g[6][6];

int dfs(int l) {
//	for(int i = 0 ; i < n; i++) {
//		for(int j = 0; j < m; j++) {
//			std::cout <<g[i][j] << " " ;
//		}
//		std::cout << '\n';
//	}
//	std::cout << '\n';
	int res = l;
	
	for(int i = 0; i < n - 1; i++) {
		for(int j = 0; j < m - 1; j++) {
			if(g[i][j] == 0) continue;
			if(g[i + 1][j] == 1) {
				if(i - 1 >= 0 && i - 1 < n && g[i - 1][j] == 0) {
					g[i][j] = 0;
					g[i + 1][j] = 0;
					g[i - 1][j] = 1;
					res = std::min(res, dfs( l - 1));
					g[i][j] = 1;
					g[i + 1][j] = 1;
					g[i - 1][j] = 0;
				}
				if(i + 2 >= 0 && i + 2 < n && g[i + 2][j] == 0) {
					g[i][j] = 0;
					g[i + 1][j] = 0;
					g[i + 2][j] = 1;
					res = std::min(res, dfs( l - 1));
					g[i][j] = 1;
					g[i + 1][j] = 1;
					g[i + 2][j] = 0;
				}
			}
			
			if(g[i][j + 1] == 1) {
				if(j - 1 >= 0 && j - 1 < m && g[i][j - 1] == 0) {
					g[i][j] = 0;
					g[i][j + 1] = 0;
					g[i][j - 1] = 1;
					res = std::min(res, dfs( l - 1));
					g[i][j] = 1;
					g[i][j + 1] = 1;
					g[i][j - 1] = 0;
				}
				if(j + 2 >= 0 && j + 2 < m && g[i][j + 2] == 0) {
					g[i][j] = 0;
					g[i][j + 1] = 0;
					g[i][j + 2] = 1;
					res = std::min(res, dfs( l - 1));
					g[i][j] = 1;
					g[i][j + 1] = 1;
					g[i][j + 2] = 0;
				}
			}
		}
	}
	
	
	return res;
}



void solve(){
	std::cin >> n >> m >> k;
	for(int i= 0; i < 6; i++) {
		for(int j = 0; j < 6; j++) {
			g[i][j] = 0;
		}
	}
	int x, y;
	for(int i = 0; i < k; i++) {
		std::cin >> x >> y;
		g[x - 1][y - 1] = 1;
	}
//	for(int i = 0; i < n; i++) {
//		for(int j = 0; j < m; j++) {
//			std::cout << g[i][j] << " ";
//		}
//		std::cout << '\n';
//	}
	std::cout << dfs( k) << '\n';
//	for(int i = 0; i < n; i++) {
//		for(int j = 0; j < m; j++) {
//			std::cout << g[i][j] << " ";
//		}
//		std::cout << '\n';
//	}
}
int main()
{
	int t = 1;
	std::cin >> t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3684kb

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

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

result:

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