My issue
My approach is find the prefix sum array and checking for prefix sum and suffix sum for each and every element in prefix array if they are equal increase good. At the end print good
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long tc=0;
cin>>tc;
while(tc--) {
long long n=0,m=0;
cin>>n>>m;
string str="";
cin>>str;
long long i=0,j=1,k=n*m;
vector<long long> prefix(k,0);
prefix[0]=str[0]-'0';
for(i=1;i<k;i++) {
prefix[i]=prefix[i-1]+(str[j%n]-'0');
j++;
}
j=0;
for(i=0;i<k;i++) {
if(2*prefix[i]==prefix[k-1])
j++;
}
cout<<j<<endl;
}
return 0;
}
Problem Link: Copy and Paste Practice Coding Problem - CodeChef