You are not logged in. Please login at www.codechef.com to post your questions!

×

[closed] problem in understanding solution?

I've attended a contest on codeforces. Here is the question. solution::

#include <iostream>
#include <cstdio>
#define rep(a,b) for (int a=0;a<b;a++)
using namespace std;

int n,a[1000100],d[1<<22];

int main()
{
    cin >> n;
    rep(i,1<<22) d[i]=-1;
    rep(i,n) scanf("%d",&a[i]), d[a[i]]=a[i];
    rep(i,1<<22) 
        if (d[i]<0)
            rep(j,22)
                if (((i>>j)&1) && d[i^(1<<j)]>=0)
                    d[i]=d[i^(1<<j)];
    rep(i,n) printf("%d ",d[(1<<22)-a[i]-1]);
}

But how it is working I'm not able to understand. Need help..!

asked 19 Mar '12, 11:11

tarun_007's gravatar image

3★tarun_007
55671220
accept rate: 80%

closed 28 Mar '12, 10:47

(16 Jan '13, 01:32) bondoc734★

The question has been closed for the following reason "Other" by tarun_007 28 Mar '12, 10:47

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×690
×148

question asked: 19 Mar '12, 11:11

question was seen: 1,580 times

last updated: 16 Jan '13, 01:32