Advertisement
SorahISA

[WIP] [TOI 2020 4th] B. 期望長度

May 20th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. /* https://drive.google.com/open?id=1IC38qlefiVIW7Rm1pSWEdAiIMR5f-V1z */
  2. /* O(n * 2^n) TLE, 32 pts */
  3.  
  4. #pragma GCC target("avx2")
  5. #pragma GCC optimize("O3", "unroll-loops")
  6.  
  7. // #include <bits/extc++.h>
  8. // using namespace __gnu_pbds;
  9.  
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12.  
  13. //#define int long long
  14. #define double long double
  15. // template <typename T>
  16. // using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  17. using pii = pair<int, int>;
  18. template<typename T>
  19. using prior = priority_queue<T, vector<T>, greater<T>>;
  20. template<typename T>
  21. using Prior = priority_queue<T>;
  22.  
  23. #define X first
  24. #define Y second
  25. #define ALL(x) (x).begin(), (x).end()
  26. #define eb emplace_back
  27. #define pb push_back
  28.  
  29. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  30. #define RANDOM() random_device __rd; \
  31.                  mt19937 __gen = mt19937(__rd()); \
  32.                  uniform_int_distribution<int> __dis(1, 1E8); \
  33.                  auto rnd = bind(__dis, __gen)
  34.  
  35. const int INF = 1E18;
  36. const int mod = 1E9 + 7;
  37.  
  38. int32_t main() {
  39.     fastIO();
  40.    
  41.     int n, N, num = 0, ans = 0;
  42.     string s;
  43.     cin >> n >> s, N = 1 << n;
  44.    
  45.     for (auto c : s) num = 2 * num + (c-'0');
  46.    
  47.     for (int i = 0; i < N; ++i) {
  48.         int row = 0, x;
  49.         for (int j = 0; j < n; ++j) {
  50.             if (num >> j & 1) x = row |  i;
  51.             else              x = row | ~i;
  52.             row = x & ((x - ((row << 1) + 1)) ^ x);
  53.         }
  54.         ans += __builtin_popcount(row & N-1);
  55.     }
  56.    
  57.     int gcd = __gcd(N, ans);
  58.     N /= gcd, ans /= gcd;
  59.    
  60.     if (N == 1) cout << ans << "\n";
  61.     else cout << ans << "/" << N << "\n";
  62.    
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement