Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Last active October 19, 2022 00:15
Show Gist options
  • Save qjatn0120/e07b7075eadee67bb9e35e93a723e7e3 to your computer and use it in GitHub Desktop.
Save qjatn0120/e07b7075eadee67bb9e35e93a723e7e3 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int CAND = 100;
const int MX = 1e6;
int n;
string s;
bool cmp(bitset <MX> b1, bitset <MX> b2){
for(int i = n - 1; i >= 0; i--){
if(b1.test(i) ^ b2.test(i)) return b2.test(i);
}
return false;
}
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
cin >> n >> s;
reverse(s.begin(), s.end());
bitset <MX> b1, b2, MAX;
for(int i = 0; i < n; i++){
if(s[i] == '1') b1.set(i), b2.set(i);
}
for(int i = 0; i < 100; i++){
MAX = max(MAX, b1 | (b2 >> i), cmp);
}
if(MAX.none()){
cout << "0";
return 0;
}
bool flag = false;
for(int i = n - 1; i >= 0; i--){
if(MAX.test(i)) flag = true;
if(flag) cout << MAX.test(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment