Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz(x) (int)(x).size()
- #define ll long long
- #define ld long double
- #define ft first
- #define sc second
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define forn(i, t) for(int i = 0; i < (t); i++)
- #define fore(i, f, t) for(int i = (f); i < (t); i++)
- #define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- void encode(string s){
- int n = sz(s);
- int m = 0;
- while ((1 << m) < m + n + 1)
- m++;
- forn(i, m)
- s.insert((1 << i) - 1, "0");
- n = sz(s);
- forn(i, m){
- int cur = 0;
- forn(j, n)
- if (((j + 1) & (1 << i)) != 0)
- cur ^= (s[j] == '1');
- s[(1 << i) - 1] = ('0' + cur);
- }
- cout << s << "\n";
- }
- void decode(string s){
- int ans = 0, n = sz(s);
- int m = 0;
- while ((1 << m) < n)
- m++;
- forn(i, m){
- int cur = (s[(1 << i) - 1] == '1');
- forn(j, n)
- if (((j + 1) & (1 << i)) != 0)
- cur ^= (s[j] == '1');
- if (s[(1 << i) - 1] != ('0' + cur))
- ans ^= (1 << i);
- }
- if (ans != 0)
- s[ans - 1] = (s[ans - 1] == '0' ? '1' : '0');
- string t = "";
- forn(i, n)
- if (__builtin_popcount(i + 1) > 1)
- t += s[i];
- cout << ans << " " << t << "\n";
- }
- int main(){
- string s = "0000000000000";
- // encode(s);
- // decode(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement