結果

問題 No.387 ハンコ
ユーザー vwxyzvwxyz
提出日時 2023-03-08 16:53:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 5,241 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,524 KB
実行使用メモリ 32,472 KB
最終ジャッジ日時 2023-10-18 05:57:46
合計ジャッジ時間 13,015 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
from itertools import zip_longest

class Bit_Set:
    def __init__(self,bit_set=[],word=64,complement=False):
        self.bit_set=bit_set
        self.word=word
        self.complement=complement

    def __contains__(self,x):
        if self.complement:
            return len(self.bit_set)<=x//self.word or ~(self.bit_set[x//self.word]&1<<x%self.word)
        else:
            return len(self.bit_set)>x//self.word and self.bit_set[x//self.word]&1<<x%self.word

    def __bool__(self):
        return self.bit_set or self.complement

    def __eq__(self,other):
        if len(self.bit_set)!=len(other.bit_set):
            return False
        if self.complement!=other.complement:
            return False
        for x,y in zip(self.bit_set,other.bit_set):
            if x!=y:
                return False
        return True

    def __ne__(self,other):
        if len(self.bit_set)!=len(other.bit_set):
            return True
        if self.complement!=other.complement:
            return True
        for x,y in zip(self.bit_set,other.bit_set):
            if x!=y:
                return True
        return False
    
    def __lshift__(self,n):
        bit_set=[0]*(n//self.word)
        n%=self.word
        prev=0
        for x in self.bit_set:
            bit_set.append(prev>>64-n|x%(1<<64-n)<<n)
            prev=x
        while bit_set and bit_set[-1]==0:
            bit_set.pop()
        return Bit_Set(bit_set=bit_set,word=self.word,complement=self.complement)

    def __rshift__(self,n):
        bit_set=[]
        nn,n=divmod(n,self.word)
        for x,y in zip_longest(self.bit_set[nn:],self.bit_set[nn+1:],fillvalue=0):
            bit_set.append(x>>n|y%(1<<n)<<64-n)
        return Bit_Set(bit_set=bit_set,word=self.word,complement=self.complement)

    def __and__(self,other):
        complement=self.complement&other.complement
        bit_set=[(~x if self.complement else x)&(~y if other.complement else y) for x,y in zip_longest(self.bit_set,other.bit_set,fillvalue=0)]
        if complement:
            for i in range(len(bit_set)):
                bit_set[i]=~bit_set[i]
        while bit_set and bit_set[-1]==0:
            bit_set.pop()
        return Bit_Set(bit_set=bit_set,word=self.word,complement=complement)

    def __xor__(self,other):
        complement=self.complement^other.complement
        bit_set=[(~x if self.complement else x)^(~y if other.complement else y) for x,y in zip_longest(self.bit_set,other.bit_set,fillvalue=0)]
        if complement:
            for i in range(len(bit_set)):
                bit_set[i]=~bit_set[i]
        while bit_set and bit_set[-1]==0:
            bit_set.pop()
        return Bit_Set(bit_set=bit_set,word=self.word,complement=complement)

    def __or__(self,other):
        complement=self.complement|other.complement
        bit_set=[(~x if self.complement else x)|(~y if other.complement else y) for x,y in zip_longest(self.bit_set,other.bit_set,fillvalue=0)]
        if complement:
            for i in range(len(bit_set)):
                bit_set[i]=~bit_set[i]
        while bit_set and bit_set[-1]==0:
            bit_set.pop()
        return Bit_Set(bit_set=bit_set,word=self.word,complement=complement)

    def __str__(self):
        retu=[]
        for i,x in enumerate(self.bit_set):
            for j in range(self.word):
                if x&1<<j:
                    retu.append(i*self.word+j)
        return "{"+", ".join(map(str,retu))+"}"
    
    def __bool__(self):
        if self.bit_set:
            return True
        else:
            return False

    def set_bit(self,x):
        self.bit_set+=[0]*(x//self.word+1-len(self.bit_set))
        self.bit_set[x//self.word]^=1<<x%self.word

    def clear_bit(self,x):
        if len(self.bit_set)>x//self.word:
            self.bit_set[x//self.word]&=~(1<<x)
        while self.bit_set and self.bit_set[-1]==0:
            self.bit_set.pop()

    def add(self,x):
        if self.complement:
            self.clear_bit(x)
        else:
            self.set_bit(x)

    def remove(self,x):
        if x in self:
            if self.complement:
                self.set_bit(x)
            else:
                self.clear_bit(x)
        else:
            raise KeyError(x)

    def discard(self,x):
        if self.complement:
            self.set_bit(x)
        else:
            self.clear_bit(x)

    def pop(self):
        if self.bit_set:
            retu=len(self.bit-1)*self.word+self.bit_set[-1].bit_length()-1
        else:
            retu=None
        return retu

    def iter(self):
        for i,x in enumerate(self.bit_set):
            for j in range(self.word):
                if x&1<<j:
                    yield i*self.word+j

N=int(readline())
A=list(map(int,readline().split()))
for i in range(N):
    A[i]-=1
M=max(A)+1
idx=[[] for i in range(M)]
for i in range(N):
    idx[A[i]].append(i)
B=Bit_Set()
for i,b in enumerate(map(int,readline().split())):
    if b:
        B|=Bit_Set([1])<<i
ans_set=Bit_Set()
for a in range(M):
    AB=Bit_Set()
    for i in idx[a]:
        AB|=B<<i
    ans_set^=AB
for i in range(2*N-1):
    if ans_set&(Bit_Set([1])<<i):
        ans="ODD"
    else:
        ans="EVEN"
    print(ans)
0