CSES Solutions
#1624Introductory Problems

Chessboard and Queens

View on CSES

Solution

1624-Chessboard_and_Queens.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  string a[8]; for(auto&x:a) cin>>x;
7  int p[8],ans=0; iota(p,p+8,0);
8  do{
9    bool f=1;
10    for(int i=0;i<8&&f;++i) f=(a[i][p[i]]=='.');
11    if(!f) continue;
12    map<int,bool> x,y;
13    for(int i=0;i<8;++i) x[i+p[i]]=1,y[i-p[i]]=1;
14    if(x.size()<8||y.size()<8) continue;
15    ++ans;
16  }while(next_permutation(p,p+8));
17  cout<<ans<<'\n';
18  return 0;
19}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.