Advertisement
supremeXD

Post's Teorem

Oct 11th, 2021
1,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 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.     for(int i = 0, j = s.size() - 1; i < j; i++, j--) {
  55.         if(s[i] == s[j]) {
  56.             return false;
  57.         }
  58.     }
  59.     return true;
  60. }
  61.  
  62. string not_string(string& s) {
  63.     string to_return;
  64.     for(char i : s) {
  65.         if(i == '0') to_return.push_back('1');
  66.         if(i == '1') to_return.push_back('0');
  67.     }
  68.     return to_return;
  69. }
  70.  
  71. bool check_left_right(string&s, int l, int r) {
  72.     if(r - l == 1) {
  73.         return true;
  74.     }
  75.     string f1 = s.substr(0, s.size() / 2);
  76.     string f2 = s.substr(s.size() / 2, s.size() / 2);
  77.     if(f1 == f2 || f1 == not_string(f2)) {
  78.         return check_left_right(f1, l, r/2);
  79.     } else {
  80.         return false;
  81.     }
  82. }
  83.  
  84. bool inFl(string s) {
  85.     return check_left_right(s, 0, s.size());
  86. }
  87.  
  88. int main() {
  89.     int n; cin >> n;
  90.     vector<string>functions(n);
  91.     for(int i = 0; i < n; i++) {
  92.         int sz; cin >> sz;
  93.         cin >> functions[i];
  94.     }
  95.     vector<bool>notPost(5, false);
  96.     for(int i = 0; i < n; i++) {
  97.         if(!inF0(functions[i])) {
  98.             notPost[0] = true;
  99.         }
  100.         if(!inF1(functions[i])) {
  101.             notPost[1] = true;
  102.         }
  103.         if(!inFm(functions[i])) {
  104.             notPost[2] = true;
  105.         }
  106.         if(!inFs(functions[i])) {
  107.             notPost[3] = true;
  108.         }
  109.         if(!inFl(functions[i])) {
  110.             notPost[4] = true;
  111.         }
  112.     }
  113.     for(int i = 0; i < 5; i++) {
  114.         if(!notPost[i]) {
  115.             cout << "NO\n";
  116.             return 0;
  117.         }
  118.     }
  119.     cout << "YES\n";
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement