CHARGES WA result

#include <bits/stdc++.h>
#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
const int INF = INT_MAX;
const int NINF = INT_MIN;
typedef long long int  ll;
using namespace std;


void solve(){
    int n,k;
    cin>>n>>k;
    string s;cin>>s;
    ll tot = 0;
    for (int i = 0; i < n-1; ++i) {
        if(s[i]==s[i+1]) tot+=2;
        else tot+=1;
    }
    for (int i = 0; i < k; ++i) {
        int num;cin>>num;
        if(n==1){cout<<"0"<<endl;continue;}
        if(num==1){
            if(s[0]==s[1]) tot-=1;
            else tot++;
            if(s[0]=='1') s[0] = '0';
            else s[0] = '1';
        } 
        else if(num==n){
            if(s[n-1]==s[n-2]) tot-=1;
            else tot++;
            if(s[n-1]=='1') s[n-1] = '0';
            else s[n-1] = '1';
        }
        else{
            if(s[num-2] != s[num]){
                if(s[num-1]=='1') s[num-1] = '0';
                else s[num-1] = '1';
                continue;
            }
            if((s[num-2] == s[num]) && (s[num-1] == s[num])) tot-=2;
            else tot+=2;
            if(s[num-1]=='1') s[num-1] = '0';
            else s[num-1] = '1';
        }
        cout<<tot<<endl;
    }
}


int main()
{
    int t;
    cin>>t;
    while (t--) solve();
}

Can someone help me with this? I can’t identify the problem
[updated] CodeChef: Practical coding for everyone
CodeChef: Practical coding for everyone

Checkout this :slightly_smiling_face:
1
1 3
0
1 1 1

1 Like

https://www.codechef.com/viewsolution/47294814

handled it here, but still gets WA
Thanks for replying.

Input:
1
1 3
0
1 1 1

Expected Output:
0
0
0

https://www.codechef.com/viewsolution/47295240

Still WA, I guess it’s some another edge case

try

1
1 2
1
1 1

Your Output
1
2

Expected
0
0

1 Like

works but still WA, For n==1 I’m printing 0 (k times)
CodeChef: Practical coding for everyone [updated]
Thanks for the reply!

put conditions for
n == 1
n == 2
and in else n > 2

1 Like

CodeChef: Practical coding for everyone No,still WA

for n == 1 you’re not taking the input string and the k position switches which are then shifted to the next test case resulting in error

1 Like

CodeChef: Practical coding for everyone got AC with this solution

Previous code is commented ,still cant figure out what was wrong

CodeChef: Practical coding for everyone tried with that too @arnav_07 but still WA

@arnav_07 @ksai3072001 @rushi2001 Thanks for helping.

did u finally find out whats the issue??