MARCHA2 Problem

The link to question : https://www.codechef.com/problems/MARCHA2
#include <bits/stdc++.h>
using namespace std;

  typedef long long ll;

  int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
    int k;
    cin>>k;
    vector<int> v(k);
    for(int i=0;i<k;i++) cin>>v[i];
    
    reverse(v.begin(),v.end());
    for(int i=0;i<k-1;i++)
    {
        
        if(v[i] % 2 == 1)
        {
            cout<<"No"<<endl;
            exit(0);
        }
        else
        {
            v[i+1] += v[i]/2;
        }
        
    }
    if(v[v.size()-1] == 1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}
return 0;
 }

Why is my code not working?

Consider the test input:

2
3
0 0 3
3
0 1 2
1 Like

Ohh got it… the exit(0) function is causing the trouble… Thanks!

1 Like