Advertisement
limimage

TASK G MEPHICOCK

Sep 24th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = (1 << 10);
  10.  
  11. int ans[N], num[9], n, t, answer = 0;
  12. char c;
  13. string s[] = {
  14. "111000000",
  15. "000111000",
  16. "000000111",
  17. "100100100",
  18. "010010010",
  19. "001001001",
  20. "100010001",
  21. "001010100"
  22. };
  23.  
  24. bool getbit(int mask, int i){
  25. return (mask & (1 << i));
  26. }
  27.  
  28. bool check(int mask){
  29. for (int i = 0; i < 8; i++)
  30. if (mask == num[i])
  31. return true;
  32. return false;
  33. }
  34.  
  35. void dfs(int mask = 0){
  36. if (check(mask))
  37. return;
  38. bool used[10];
  39. for (int i = 0; i < 9; i++){
  40. if (!(getbit(mask, i))){
  41. if (!ans[mask ^ (1 << i)])
  42. dfs(mask ^ (1 << i));
  43. used[ans[mask ^ (1 << i)]] = 1;
  44. }
  45. }
  46. for (int i = 0; i < 10; i++)
  47. if (!used[i]){
  48. ans[mask] = i;
  49. return;
  50. }
  51. }
  52.  
  53. void Solve(){
  54. for (int i = 0; i < 8; i++)
  55. for (int j = 0; j < 9; j++)
  56. if (s[i][j] == '1')
  57. num[i] += (1 << j);
  58. dfs();
  59. cin >> n;
  60. while(n--){
  61. t = 0;
  62. for (int i = 0; i < 9; i++){
  63. cin >> c;
  64. if (c == 'X')
  65. t += (1 << i);
  66. }
  67. answer ^= ans[t];
  68. }
  69. cout << (answer ? "First" : "Second");
  70. }
  71.  
  72. int main(){
  73. ios::sync_with_stdio(false);
  74. cin.tie(nullptr);
  75. cout.tie(nullptr);
  76. Solve();
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement