Binary Inversion WA

Hey all can u check why my code is not working

#include<bits/stdc++.h>
using namespace std;

pair<long long int,int> countinversions(string s,int m){
vector v;
for(int i=0;i<m;++i){
if(s[i]==‘1’){
v.push_back(i+1);
}
}
long long int ans=0,rem=v.size()-1 ;
for(int i=0;i<v.size();i++){
ans+=m-v[i]-rem;
rem–;
}
return {ans,v.size()};
}

int main(){
int t;
cin>>t;
while(t–){
int n,m;
cin>>n>>m;
vectorv(n);
for(int i=0;i<n;++i){
cin>>v[i];
}
long long int inv=0;
inv+=countinversions(v[0],m).first;
long long int x,y;
y=countinversions(v[0],m).second;
x=m-y;
for(int i=1;i<n;++i){
inv+=countinversions(v[i],m).first;
int x1,y1;
y1=countinversions(v[i],m).second;
x1=m-y1;
inv+=min(x1y,xy1);
x+=x1;
y+=y1;

	}
	cout<<inv<<endl;
	











}

}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

1 Like