QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418752#6534. Peg SolitaireDaDian#AC ✓1ms3564kbC++201.9kb2024-05-23 15:32:362024-05-23 15:32:38

Judging History

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

  • [2024-05-23 15:32:38]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3564kb
  • [2024-05-23 15:32:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 2e5+7,mod=1e9+7,INF=1e18;
#define endl '\n'

void solve(){
	ll n, m, k;
	cin >> n >> m >> k;
	map<pair<ll, ll>, ll> mp;
	for(ll i = 1 ; i <= k; i++){
		ll x, y; cin >> x >> y;
		mp[{x, y}] = 1;
	}
	
	ll ans = 1e9;
	auto dfs = [&](auto &&dfs) -> void{
		vector<pair<pair<ll, ll>, ll>> ve;	
		for(auto [u, v] : mp){
			auto [x, y] = u;
			if(mp.find({x, y + 1}) != mp.end() && y + 2 <= m && mp.find({x, y + 2}) == mp.end()){
				ve.push_back({{x, y}, 1});
			}
			if(mp.find({x + 1, y}) != mp.end() && x + 2 <= n && mp.find({x + 2, y}) == mp.end()){
				ve.push_back({{x, y}, 2});
			}
			if(mp.find({x, y - 1}) != mp.end() && y - 2 >= 1 && mp.find({x, y - 2}) == mp.end()){
				ve.push_back({{x, y}, 3});
			}
			if(mp.find({x - 1, y}) != mp.end() && x - 2 >= 1 && mp.find({x - 2, y}) == mp.end()){
				ve.push_back({{x, y}, 4});
			}
		} 
		
		if(ve.size() == 0){
			ll num = mp.size();
			ans = min(num, ans);
			return;
		}
		
		for(auto [u, v] : ve){
			auto [x, y] = u;
			if(v == 1){
				mp.erase(u);
				mp.erase({x, y + 1});
				mp[{x, y + 2}] = 1;
				dfs(dfs);
				mp[u] = 1;
				mp[{x, y + 1}] = 1;
				mp.erase({x, y + 2});	
			}else if(v == 2){
				mp.erase(u);
				mp.erase({x + 1, y});
				mp[{x + 2, y}] = 1;
				dfs(dfs);
				mp[u] = 1;
				mp[{x + 1, y}] = 1;
				mp.erase({x + 2, y});
			}else if(v == 3){
				mp.erase(u);
				mp.erase({x, y - 1});
				mp[{x, y - 2}] = 1;
				dfs(dfs);
				mp[u] = 1;
				mp[{x, y - 1}] = 1;
				mp.erase({x, y - 2});
			}else if(v == 4){
				mp.erase(u);
				mp.erase({x - 1, y});
				mp[{x - 2, y}] = 1;
				dfs(dfs);
				mp[u] = 1;
				mp[{x - 1, y}] = 1;
				mp.erase({x - 2, y});
			}
		}
	};
	dfs(dfs);
	
	cout << ans << endl;
	
}
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	ll T=1;
	
	cin>>T;
	
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 3564kb

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

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

20
2 1 1
2 1
4 3 2
4 3
1 1
6 4 6
4 3
5 4
4 2
3 2
3 4
2 3
3 6 4
3 1
2 6
2 4
3 5
6 6 6
3 3
3 6
4 2
3 2
4 1
1 4
3 3 1
1 1
2 3 2
2 2
2 1
3 2 2
1 2
2 2
3 4 5
2 1
3 4
3 1
2 2
3 2
2 5 5
1 5
2 3
2 5
1 4
2 2
5 6 6
5 1
2 2
1 4
5 3
4 4
1 1
2 3 4
1 1
1 2
2 2
2 1
2 3 4
1 1
2 1
1 2
2 2
6 3 6
4 2
4 1
1 3
6 2
3 3
2...

output:

1
2
2
4
4
1
1
1
2
2
6
2
2
3
4
1
1
1
3
2

result:

ok 20 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

20
1 5 3
1 2
1 3
1 1
5 6 6
5 4
2 4
4 4
4 6
2 5
3 3
5 2 4
4 1
3 1
4 2
5 2
6 3 6
3 1
5 2
3 2
4 1
4 3
3 3
5 3 5
5 2
2 2
3 1
4 3
3 2
6 1 4
3 1
5 1
1 1
4 1
3 5 6
1 1
2 1
3 4
1 5
2 2
3 3
2 5 2
2 5
2 1
5 4 6
1 3
4 3
2 2
1 2
3 3
2 3
2 3 3
2 3
1 1
1 3
1 1 1
1 1
1 1 1
1 1
1 1 1
1 1
6 4 5
2 1
6 2
3 2
1 2
4 2
5...

output:

2
1
2
2
1
2
3
2
2
3
1
1
1
3
2
2
2
3
2
1

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

20
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 20 numbers