fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define nl "\n"
  5. #define OO 0x3f3f3f3f
  6. using namespace std;
  7. const int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
  8. const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
  9. void ta2to2a()
  10. {
  11. ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);
  12. #ifndef ONLINE_JUDGE
  13. freopen("input.txt", "r", stdin);
  14. freopen("output.txt", "w", stdout);
  15. #endif
  16. }
  17. vector<vector<char>> grid;
  18. bool isValid(int x, int y)
  19. {
  20. return x >= 0 && x < 8 && y >= 0 && y < 8 && grid[x][y] != '*';
  21. }
  22. bool visited[8][8] = {false};
  23. ll ways(int x)
  24. {
  25. ll ans = 0;
  26. if (x == 8)
  27. {
  28. return 1;
  29. }
  30. for (int i = 0; i < 8; i++)
  31. {
  32. if (isValid(x, i) && !visited[x][i])
  33. {
  34. visited[x][i] = true;
  35. for (int j = 0; j < 8; j++)
  36. {
  37. visited[x][j] = true;
  38. }
  39. for (int j = 0; j < 8; j++)
  40. {
  41. visited[j][i] = true;
  42. }
  43. for (int j = 0; j < 8; j++)
  44. {
  45. for (int k = 0; k < 8; k++)
  46. {
  47. if (abs(k - j) == abs(x - i))
  48. {
  49. visited[j][k] = true;
  50. }
  51. }
  52. }
  53. ans += ways(x + 1);
  54. }
  55. }
  56. return ans;
  57. }
  58. void solve()
  59. {
  60. grid = vector<vector<char>>(8, vector<char>(8));
  61. for (int i = 0; i < 8; i++)
  62. {
  63. for (int j = 0; j < 8; j++)
  64. {
  65. cin >> grid[i][j];
  66. }
  67. }
  68. cout << ways(0);
  69. }
  70. int main()
  71. {
  72. ta2to2a();
  73. int t = 1;
  74. // cin >> t;
  75. while (t--)
  76. {
  77. solve();
  78. }
  79. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty