CodeChef LogoCodeChef Logo
Courses

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

PracticeCompeteCompiler
Upgrade to Pro
Courses

Programming and DSA

Learn to think like a programmer. Develop your problem-solving skills with essential data structures and algorithms.

Career Paths

From beginner to job-ready. Explore our curated career paths designed to help you succeed in the tech industry.

Other Courses

PracticeCompeteCompiler
Home  »  START181D  »  FLIPPRE  »  Submissions  »  1150951411

Flip Prefix

Status:

Correct Answer

Submission by:

2
leal_al

Submitted:

2 months ago

Problem:

FLIPPRE

Contest:

START181D
Language: C++
#include<bits/stdc++.h>
using namespace std;
int count_distinct_strings(string s){
int n=s.size();
vector<bitset<60>> flips;
int balance=0;
for(int i=0;i<n;++i){
if(s[i]=='1') balance++;
else balance--;
if(balance==0){
bitset<60> flip;
for(int j=0;j<=i;++j) flip[j]=1;
flips.push_back(flip);
}
}
int rank=0;
bitset<60> basis[60];
for(auto&v:flips){
bitset<60> x=v;
for(int i=0;i<60;++i){
if(!x[i]) continue;
if(basis[i].none()){
basis[i]=x;
rank++;
break;
}
x^=basis[i];
}
}
return 1<<rank;
}
int main(){
int t;
cin>>t;
while(t--){
int n;
string s;
cin>>n>>s;
cout<<count_distinct_strings(s)<<'\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Correct Answer
Submission ID: 1150951411
Score:100
Memory:3.6M
Sub-Task Task # Result
(time)
10Correct
(0.00)
11Correct
(0.00)
12Correct
(0.00)
13Correct
(0.00)
14Correct
(0.00)
15Correct
(0.00)
Subtask Score: 100% Result - Correct
Total Score = 100%