ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1208. Legendary Teams Contest

In case of WA#7
Posted by daftcoder [Yaroslavl SU] 19 Aug 2011 16:36
Notice that there are 18*3=54 participants, 64bit-type should be used for masks.
Re: In case of WA#7
Posted by Leonid (SLenik) Andrievskiy 23 Sep 2011 01:17
It's possible to solve that problem with only 32-bit masks. Encode team number k as  2^k (in c "1 << k", in pascal "1 shl k").

Create an array (I named it "check"):

forall (i)
{
  check[i] = 0;
  forall (j, not equal i)
  {
    if (there is a member in team j that exists also in team i)
      then check[i] = check[i] bitwise or (2 ^ j);
  }
}

You can encode every possible teams combination in one number from interval [0 .. (2^k) - 1]. Note that the number is less than 2 ^ 18 (or 262144).

Then enumerate all numbers from that interval and for every number S for every bit p in position q in number S check inequality "S & check[q] > 0".

If for some p in position q in number S this inequality is true, than state S is inacceptable.

Edited by author 23.09.2011 01:18