fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. // #define int long long int
  5. #define ld long double
  6. #define all(x) x.begin(), x.end()
  7. #define sortall(x) sort(all(x))
  8. #define endl '\n'
  9. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. template<class T>
  11. void printC (T Collection)
  12. {
  13. for (auto&i:Collection)
  14. cout << i << " \n";
  15. cout << '\n';
  16. }
  17.  
  18. /*
  19.  * Think twice, code once
  20.  * Think of different approaches to tackle a problem: write them down.
  21.  * Think of different views of the problem. don't look from only one side.
  22.  * don't get stuck in one approach.
  23.  * common mistakes: - over_flow
  24.  * - out_of_bound index
  25.  * - infinite loop
  26.  * - corner cases
  27.  * - duplication counting.
  28. */
  29.  
  30. bool attack(pair<int, int> a, pair<int, int> Q)
  31. {
  32. for (int i = Q.first-1; i >= 0; --i)
  33. if (a.first == i && a.second == Q.second)
  34. return true;
  35. for (int i = Q.first+1; i < 8; ++i)
  36. if (a.first == i && a.second == Q.second)
  37. return true;
  38.  
  39. for (int i = Q.second-1; i >= 0; --i)
  40. if (a.first == Q.first && a.second == i)
  41. return true;
  42. for (int i = Q.second+1; i < 8; ++i)
  43. if (a.first == Q.first && a.second == i)
  44. return true;
  45.  
  46. for (int i = Q.first-1, j = Q.second-1; i >= 0 && j >= 0; --i, --j)
  47. if (a.first == i && a.second == j)
  48. return true;
  49. for (int i = Q.first+1, j = Q.second+1; i < 8 && j < 8; ++i, ++j)
  50. if (a.first == i && a.second == j)
  51. return true;
  52.  
  53. for (int i = Q.first-1, j = Q.second+1; i >= 0 && j < 8; --i, ++j)
  54. if (a.first == i && a.second == j)
  55. return true;
  56. for (int i = Q.first+1, j = Q.second-1; i < 8 && j >= 0; ++i, --j)
  57. if (a.first == i && a.second == j)
  58. return true;
  59. return false;
  60. }
  61.  
  62. void solve()
  63. {
  64. vector<vector<char>> v(8,vector<char>(8));
  65. set<pair<int, int>> pos;
  66. for (int i = 0; i < 8; ++i)
  67. {
  68. for (int j = 0; j < 8; ++j)
  69. {
  70. cin >> v[i][j];
  71. if (v[i][j] == 'Q')
  72. pos.insert({i,j});
  73. }
  74. }
  75. for (auto&i:pos)
  76. for (auto&j:pos)
  77. if (attack(j, i))
  78. {
  79. cout << "invalid";
  80. return;
  81. }
  82. cout << "valid";
  83. }
  84.  
  85. int32_t main()
  86. {
  87. // #ifndef ONLINE_JUDGE
  88. // freopen("input.txt", "r", stdin);
  89. // freopen("output.txt", "w", stdout);
  90. // freopen("Errors.txt", "w", stderr);
  91. // #endif
  92. fast
  93. int t = 1;
  94. // cin >> t;
  95. while (t--)
  96. {
  97. solve();
  98. if (t) cout << '\n';
  99. }
  100. cout << '\n';
  101. return 0;
  102. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
valid