Untitled

 avatar
unknown
plain_text
a year ago
3.1 kB
5
Indexable
#include <bits/stdc++.h>
using namespace std;


#define INF 100000000
#define ll long long

#define file \
  freopen("matrix.in", "r", stdin);
//  freopen("output.txt", "w", stdout)

#define OJudge(in,out) \
      freopen(in, "r", stdin);\
      freopen(out, "w", stdout)


#define FIn   \
  cin.tie(0); \
  cout.tie(0); \
  ios_base::sync_with_stdio(false)

#define endl '\n'

#define all(x) x.begin(), x.end()

const string IN = "input.txt";
const string OUT = "output.txt";

typedef long double T;
typedef complex<T> pt;
//#define x real()
//#define y imag()
const ll MOD = 1e9 + 9;
int tc;
//const T pi = 3.1415926535897;
string alpha = "abcdefghijklmnopqrstuvwxyz";
typedef pair<int,int> pii;


struct cmp {
    bool operator()(const pair<pii, int> &p1, const pair<pii,int> &p2) const {
        return p1.first < p2.first;
    }
};

int n, m, q, f, P;
int z, y;
const int N = 1e6 + 5;
ll arr[N];
string str;

string brute() {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            string ss = str.substr(i, j - i + 1);
            int cur = stoi(ss, nullptr, 2);
            sum += cur;
        }
    }
    string rslt= "";
    for (int i = 0; i <= __lg(sum); i++) {
        if (sum & (1 << i)) {
            rslt += '1';
        }
        else {
            rslt += '0';
        }
    }
    reverse(all(rslt));
    return rslt;
}

string solution () {
    for(int i = 0; i <= n + 10; ++i)
        arr[i] = 0;

    for(int i = 0; i < n; ++i){
        if(str[i] == '0')continue;

        int c = i + 1;
        int R = n - i;

        arr[0] += c;
        arr[R] -= c;
        /*
         * 101
         * 1 0 0 -1
         * 3 -3 0 -1
         * 4 1 1  0
         */
    }

    string ans;

    for(int i = 1; i <= n; ++i)arr[i] += arr[i - 1];

    ll carry = 0;
    for(int i = 0; i <= n + 10; ++i){
        ll cntBits = arr[i] + carry;

        if(cntBits == 0)
            break;

        if(cntBits & 1)
            ans += '1';
        else
            ans += '0';
        carry = cntBits / 2;
    }
    while(ans.back() == '0')
        ans.pop_back();

    reverse(all(ans));
    return ans;
}

string toBin(int x) {
    string rslt= "";
    for (int i = 0; i <= __lg(x); i++) {
        if (x & (1 << i)) {
            rslt += '1';
        }
        else {
            rslt += '0';
        }
    }
    reverse(all(rslt));
    return rslt;
}


void pre();
void solve(int tc) {
//    cin >> str;
//    n = str.length();
    for (int i = 1; i <= 100000; i++) {
        str = toBin(i);
        n = str.length();
        if (brute() != solution()) {
            cout << str << '\n';
            break;
        }
    }
}

int main() {
    FIn;

#ifndef ONLINE_JUDGE
    OJudge(IN.c_str(),OUT.c_str());
#endif

//    file;
    pre();
    tc = 1;
//    cin >> tc;
    for(int i = 1; i <= tc; i++) {
//        cout << "Case #" << i <<": ";
        solve(i);
    }
}

void pre() {}
Editor is loading...
Leave a Comment