Advertisement
supremeXD

Untitled

Oct 17th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. bool inF0(string s) {
  8. return s[0] == '0';
  9. }
  10.  
  11. bool inF1(string s) {
  12. return s.back() == '1';
  13. }
  14.  
  15. string ten_to_2(int val, int need_size) {
  16. string s;
  17. while(val > 0) {
  18. s.push_back((val % 2) + '0');
  19. val /= 2;
  20. }
  21. for(int i = (int)s.size(); i < need_size; i++) {
  22. s.push_back('0');
  23. }
  24. //reverse(s.begin(), s.end());
  25. return s;
  26. }
  27.  
  28. bool dominanted(string first, string second) {
  29. for(int i = 0; i < min(first.size(), second.size()); i++) {
  30. if(first[i] > second[i]) {
  31. return false;
  32. }
  33. }
  34. return true;
  35. }
  36.  
  37. bool inFm(string s) {
  38. for(int i = 0; i < s.size(); i++) {
  39. for(int j = 0; j < s.size(); j++) {
  40. if(i == j) continue;
  41. string f1 = ten_to_2(i, s.size());
  42. string f2 = ten_to_2(j, s.size());
  43. if(dominanted(f1, f2)) {
  44. if(s[i] > s[j]) {
  45. return false;
  46. }
  47. }
  48. }
  49. }
  50. return true;
  51. }
  52.  
  53. bool inFs(string s) {
  54. if(s.size() == 1) {
  55. return false;
  56. }
  57. for(int i = 0, j = s.size() - 1; i < j; i++, j--) {
  58. if(s[i] == s[j]) {
  59. return false;
  60. }
  61. }
  62. return true;
  63. }
  64.  
  65. string not_string(string& s) {
  66. string to_return;
  67. for(char i : s) {
  68. if(i == '0') to_return.push_back('1');
  69. if(i == '1') to_return.push_back('0');
  70. }
  71. return to_return;
  72. }
  73.  
  74. bool check_left_right(string&s, int l, int r) {
  75. if(r - l == 1) {
  76. return true;
  77. }
  78. string f1 = s.substr(0, s.size() / 2);
  79. string f2 = s.substr(s.size() / 2, s.size() / 2);
  80. if(f1 == f2 || f1 == not_string(f2)) {
  81. return check_left_right(f1, l, r/2);
  82. } else {
  83. return false;
  84. }
  85. }
  86.  
  87. bool inFl(string s) {
  88. return check_left_right(s, 0, s.size());
  89. }
  90.  
  91. int main() {
  92. int n; cin >> n;
  93. vector<string>functions(n);
  94. for(int i = 0; i < n; i++) {
  95. int sz; cin >> sz;
  96. cin >> functions[i];
  97. }
  98. vector<bool>notPost(5, false);
  99. for(int i = 0; i < n; i++) {
  100. if(!inF0(functions[i])) {
  101. notPost[0] = true;
  102. }
  103. if(!inF1(functions[i])) {
  104. notPost[1] = true;
  105. }
  106. if(!inFm(functions[i])) {
  107. notPost[2] = true;
  108. }
  109. if(!inFs(functions[i])) {
  110. notPost[3] = true;
  111. }
  112. if(!inFl(functions[i])) {
  113. notPost[4] = true;
  114. }
  115. }
  116. for(int i = 0; i < 5; i++) {
  117. if(!notPost[i]) {
  118. cout << "NO\n";
  119. return 0;
  120. }
  121. }
  122. cout << "YES\n";
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement