< Back to forum

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

#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;

}

 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

Please Explain your code...                   

Shubham_Kumar_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.