12898 - AND OR

All about problems in Volume 128. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
musfiqur.cse
New poster
Posts: 10
Joined: Tue Dec 03, 2013 8:48 pm

12898 - AND OR

Post by musfiqur.cse » Fri Dec 19, 2014 5:03 pm

I am getting output limit exceed.. Need Some help

Code: Select all


#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
#define ll long long
#define mem(a) memset(a,0,sizeof(a));
#define M 10000007

vector<  ll>vt;
vector<  ll>qt;
  ll bitcount(  ll n){
  ll i,j=n,cnt=0;
while(j!=0){
    cnt++;
    j/=2;

}
return cnt;

}
void pop(ll n,ll m){
     ll i=n,j=m,k,l;
    vt.clear();
    qt.clear();
    while(i!=0){
        k=i%2;
        vt.push_back(k);
        i/=2;

    }
    while(j!=0){
        k=j%2;
        qt.push_back(k);
        j/=2;

    }




}




int main()
{

  ll i,j,k,l,n,m,tcase,count=1,chk1,chk2,lk,mk,chkk1;
vector<ll>ct,dt;
bool chkk2;
scanf("%lld",&tcase);
while(tcase--){
    lk=0;mk=0;
    chkk1=0;
   scanf("%lld%lld",&n,&m);
   chk1=bitcount(n);
   chk2=bitcount(m);
if(chk1!=chk2){
    ll pp=0,qq=pow(2,chk2)-1;

    printf("Case %lld: %lld %lld\n",count++,qq,pp);
   }
   else{
     pop(n,m);
     //cout<<"Poped"<<endl;
     for(i=vt.size()-1;i>=0;i--){
            if(qt[i]==vt[i]&&(chkk1==0)){

                ct.push_back(qt[i]);
                dt.push_back(qt[i]);

            }

       else if(qt[i]!=vt[i]&&(chkk1==0)){
                ct.push_back(qt[i]);
                dt.push_back(0);
                chkk1++;


            }


     else{

        ct.push_back(1);
        dt.push_back(0);
        chkk1++;


     }


   }
   for(i=vt.size()-1,j=0;i>=0;i--,j++){

    lk+=ct[i]*pow(2,j);
    mk+=dt[i]*pow(2,j);
   }

   printf("Case %lld: %lld %lld\n",count++,lk,mk);

}
ct.clear();
dt.clear();
}
return 0;
}






brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12898 - AND OR

Post by brianfry713 » Fri Dec 19, 2014 10:37 pm

http://uva.onlinejudge.org/index.php?op ... tegory=861
This problem has a red check so the I/O is probably not ready yet.
Check input and AC output for thousands of problems on uDebug!

musfiqur.cse
New poster
Posts: 10
Joined: Tue Dec 03, 2013 8:48 pm

Re: 12898 - AND OR

Post by musfiqur.cse » Sat Dec 20, 2014 6:44 pm

Now I/O is updated. They give me WA. I can't find the bugs in my solution.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12898 - AND OR

Post by brianfry713 » Sun Dec 21, 2014 7:50 am

Replace pow(2, x) with (1LL << x).
Avoid floating point when possible.
Check input and AC output for thousands of problems on uDebug!

sabbir_alam_ufo
New poster
Posts: 16
Joined: Fri Nov 15, 2013 9:33 pm

Re: 12898 - AND OR

Post by sabbir_alam_ufo » Mon Dec 22, 2014 10:48 am

Thanks brianfry713 :) :D

Code: Select all

Removed after AC
Last edited by sabbir_alam_ufo on Tue Dec 23, 2014 2:56 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12898 - AND OR

Post by brianfry713 » Tue Dec 23, 2014 3:45 am

Input:

Code: Select all

1
999999999999999999 1000000000000000000
AC output:

Code: Select all

Case 1: 1000000000000262143 999999999999737856
Check input and AC output for thousands of problems on uDebug!

Aseem chakrabarthy
New poster
Posts: 5
Joined: Mon Jan 19, 2015 12:12 pm
Location: University of Chittagong

Re: 12898 - AND OR

Post by Aseem chakrabarthy » Mon Feb 09, 2015 7:27 am

Why i'm getting wrong answer....

Code: Select all

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int test,i;
    cin>>test;
    for(i=1;i<=test;i++)
    {
          long long int a,b,a_or,b_and;
        cin>>a>>b;
        a_or=a|b;
        b_and=a&b;
        cout<<"Case "<<i<<": "<<a_or<<" "<<b_and<<endl;
    }
}
Last edited by brianfry713 on Tue Feb 10, 2015 2:31 am, edited 1 time in total.
Reason: Added code blocks

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12898 - AND OR

Post by brianfry713 » Tue Feb 10, 2015 2:34 am

http://www.udebug.com/UVa/12898
Click "Random Input", "Go!"

Read the problem statement again.
X is the result of bitwise (inclusive) OR of numbers from A to B inclusive and
Y is the result of bitwise AND of numbers from A to B , inclusive.

Input:

Code: Select all

1
1 3
Output should be 3 0

In decimal:
X = 1 | 2 | 3 = 3
Y = 1 & 2 & 3 = 0

In binary:
X = 01 | 10 | 11 = 11
Y = 01 & 10 & 11 = 00
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 128 (12800-12899)”