QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278213#3166. Hopscotchddl_VS_pigeon#TL 0ms0kbC++202.0kb2023-12-07 13:44:242023-12-07 13:44:25

Judging History

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

  • [2023-12-07 13:44:25]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-12-07 13:44:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

void solve(){
	int n,k;
	cin >> n >> k;
	vector<vector<char>> a(n,vector<char>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> a[i][j];
		}
	}
	vector<int> x(n);
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	int ans = 0;
	vector<vector<bool>> placed(n,vector<bool>(n));
	auto place = [&](int x,int y,int len,int dx,int dy)->bool {
		for(int i=0;i<len;i++){
			int cx = x+i*dx;
			int cy = y+i*dy;
			if(cx>=n||cy>=n) return false;
			if(a[cx][cy]=='X'||placed[cx][cy]) return false;
		}
		for(int i=0;i<len;i++){
			int cx = x+i*dx;
			int cy = y+i*dy;
			placed[cx][cy] = true;
		}
		return true;
	};
	auto unplace = [&](int x,int y,int len,int dx,int dy)->void {
		for(int i=0;i<len;i++){
			int cx = x+i*dx;
			int cy = y+i*dy;
			placed[cx][cy] = false;
		}
	};
	struct Record{
		int x,y,len,dx,dy;
	};
	vector<Record> history;
	function<void(int)> search = [&](int sid)->void {
		if(sid==n){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(a[i][j]=='X'){
						if(placed[i][j]) return;
					}
					if(a[i][j]=='O'){
						if(!placed[i][j]) return;
					}
				}
			}
			// for(auto [x,y,len,dx,dy]:history){
			// 	cerr << x << ' ' << y << ' ' << len << ' ' << dx << ' ' << dy << '\n';
			// }
			// cerr << "DONE" << '\n';
			ans++;
			return;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(place(i,j,x[sid],0,1)){
					// history.push_back({i,j,x[sid],0,1});
					search(sid+1);
					// history.pop_back();
					unplace(i,j,x[sid],0,1);
				}
				if(x[sid]!=1&&place(i,j,x[sid],1,0)){
					// history.push_back({i,j,x[sid],1,0});
					search(sid+1);
					// history.pop_back();
					unplace(i,j,x[sid],1,0);
				}
			}
		}
	};
	search(0);
	cout << ans << '\n';
}

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int T;
	// cin >> T;
	T = 1;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

10 5
5 1 3 4 2 4 2 1 2 1
4 5 3 4 1 5 3 1 1 4
4 2 4 1 5 4 5 2 4 1
5 2 1 5 5 3 5 2 3 2
5 5 2 3 2 3 1 5 5 5
3 4 2 4 2 2 4 4 2 3
1 5 1 1 2 5 4 1 5 3
2 2 4 1 2 5 1 4 3 5
5 3 2 1 4 3 5 2 3 1
3 4 2 5 2 5 3 4 4 2

output:


result: