fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. typedef long long ll;
  5.  
  6. const int MAX = 8;
  7. int solutions=0;
  8. bool visitedCol[MAX], rightDia[2*MAX+1],leftDia[2*MAX+1],available[MAX][MAX];
  9.  
  10. void Queens(int w){
  11. if (w == 8){
  12. solutions++;
  13. return;
  14. }
  15. for (int k = 0;k <8;k++){
  16. if(!visitedCol[k]&&!rightDia[k+w]&&!leftDia[MAX+k-w]&&!available[w][k]){
  17. visitedCol[k] = rightDia[k+w] = leftDia[MAX+k-w] = 1;
  18. Queens(w+1);
  19. visitedCol[k] = rightDia[k+w] = leftDia[MAX+k-w] = 0;
  20. }
  21. }
  22.  
  23.  
  24.  
  25. }
  26.  
  27. int main() {
  28. FAST
  29. char c;
  30. for (int i = 0;i<8;i++){
  31. for (int j = 0;j<8;j++){
  32. cin >> c;
  33. if (c == '*'){
  34. available[i][j]=1;
  35. }
  36. }
  37. }
  38. Queens(0);
  39.  
  40. cout << solutions << "\n";
  41. //system("pause");
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
92