cp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kobejean/cp-library

:warning: cp_library/math/table/submasks_cls.py

Depends on

Code

import cp_library.math.table.__header__
from cp_library.bit.popcnt32_fn import popcnt32
from cp_library.ds.elist_fn import elist

class Submasks(list[list[int]]):
    def __init__(S,N):
        Z = 1 << N
        super().__init__([elist(popcnt32(m)) for m in range(Z)])
        for s in range(Z):
            sub = S[t := s]
            while t:
                sub.append(t)
                t = (t-1)&s
            sub.append(0)
            sub.reverse()
        
'''
╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
             https://kobejean.github.io/cp-library               
'''


def popcnt32(x):
    x = ((x >> 1)  & 0x55555555) + (x & 0x55555555)
    x = ((x >> 2)  & 0x33333333) + (x & 0x33333333)
    x = ((x >> 4)  & 0x0f0f0f0f) + (x & 0x0f0f0f0f)
    x = ((x >> 8)  & 0x00ff00ff) + (x & 0x00ff00ff)
    x = ((x >> 16) & 0x0000ffff) + (x & 0x0000ffff)
    return x


def elist(est_len: int) -> list: ...
try:
    from __pypy__ import newlist_hint
except:
    def newlist_hint(hint):
        return []
elist = newlist_hint
    

class Submasks(list[list[int]]):
    def __init__(S,N):
        Z = 1 << N
        super().__init__([elist(popcnt32(m)) for m in range(Z)])
        for s in range(Z):
            sub = S[t := s]
            while t:
                sub.append(t)
                t = (t-1)&s
            sub.append(0)
            sub.reverse()
        
Back to top page