Advertisement
cosenza987

Untitled

Sep 4th, 2024
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. //Слава Україні, Героям слава
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     string a, b;
  11.     cin >> a >> b;
  12.     int n = a.size(), m = b.size();
  13.     int cnt = 0;
  14.     for(int i = 0; i < n; i++) {
  15.         cnt += a[i] == '*';
  16.     }
  17.     for(int i = 0; i < m; i++) {
  18.         cnt += b[i] == '*';
  19.     }
  20.     for(int msk = 0; msk < (1 << cnt); msk++) {
  21.         int cur = msk;
  22.         string cura = a;
  23.         for(auto &e : cura) {
  24.             if(e == '*') {
  25.                 e = '0' + (cur & 1);
  26.                 cur >>= 1;
  27.             }
  28.         }
  29.         long long mod = 0, pt = 1;
  30.         for(int i = m - 1; i >= 0; i--) {
  31.             if(b[i] == '*') {
  32.                 mod += pt * (cur & 1);
  33.                 cur >>= 1;
  34.             } else {
  35.                 mod += pt * (b[i] == '1');
  36.             }
  37.             pt *= 2;
  38.         }
  39.         pt = 1;
  40.         long long ans = 0;
  41.         for(int i = n - 1; i >= 0; i--) {
  42.             ans = (ans + pt * (cura[i] == '1')) % mod;
  43.             pt = (pt * 2) % mod;
  44.         }
  45.         if(ans == 0) {
  46.             cout << cura << "\n";
  47.             break;
  48.         }
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement