i am doing right but due to multiple answer my code is submiting wrong ,,it is also given any one is accepted.. so why this code is not submiting link to qestn : https://codeforces.com/contest/1072/problem/B

codeforces round517 div 2

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

#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

int main()
{

	ll n,m,k,i,j,l,sum,x,w,h,x1=0,x2=0,f,y,g;

	cin>>n;
	ll a[n-1];
	ll b[n-1];
	ll t[n]={0};

	for(i=0;i<n-1;i++)
     cin>>a[i];


	for(i=0;i<n-1;i++)
     cin>>b[i];



    f=0;
    g=0;
    
    for(j=0;j<=3;j++)
    {
     for(k=0;k<=3;k++)
     {
      if(((j|k)==a[0])&&((j&k)==b[0]))
      {
              g=1;
              t[0]=k;
              x1=k;
              t[1]=j;
              x2=j;
              f=1;
              break;

      }
     }
    }

  // cout<<t[0]<<" "<<t[1]<<" "<<f;
   
   
   for(i=2;i<n;i++)
   {
     f=0;

    for(j=0;j<=3;j++)
    {

    // cout<<t[i-1]<<" t[] ";
     x=j|t[i-1];
     y=j&t[i-1];
     
    // cout<<x<<" x "<<y<<" y \n";
      if((x==a[i-1])&&(y==b[i-1]))
      {
             //cout<<" ye ";
              t[i]=j;
              f=1;
              break;
        }
      }
      
    }
    

 if((g==1)&&(f==0))
 {  
     t[0]=x2;
     t[1]=x1;
     
  for(i=2;i<n;i++)
   {
     f=0;

    for(j=0;j<=3;j++)
    {

    // cout<<t[i-1]<<" t[] ";
     x=(j|t[i-1]);
     y=(j&t[i-1]);
     
    // cout<<x<<" x "<<y<<" y \n";
      if((x==a[i-1])&&(y==b[i-1]))
      {
             //cout<<" ye ";
              t[i]=j;
              f=1;
              break;
        }
      }
      
    }
 }
    


   if(f==0)
    cout<<"NO"<<endl;

   else
   {
      cout<<"YES"<<endl;

       for(i=0;i<n;i++)
       {
           cout<<t[i]<<" ";
       }
   }




	return 0;

}

 

manish_kumar
Manish Kumar Savita
manish_kumar

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load



Please make sure the answer is not too short

1 Answer

preda2or
preda2or 12:48, Jan 20
Shubham Kumar Gupta

Please Explain your code...                   




Please make sure the answer is not too short
1 Upvotes
Comments
manish_kumar (Manish Kumar Savita) 21:53, Dec 13

my ans is going wrong on case 8,,but if i swap j and k,,,then 1 case is giving another ans(although correct ) but not submiting..