結果
問題 | No.387 ハンコ |
ユーザー | vwxyz |
提出日時 | 2023-03-09 17:15:40 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,807 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 231,356 KB |
最終ジャッジ日時 | 2024-09-18 02:54:23 |
合計ジャッジ時間 | 12,717 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
ソースコード
import sys readline=sys.stdin.readline from itertools import zip_longest class Bit_Set: def __init__(self,x=None,bit_set=[],word=64,complement=False): self.word=word self.complement=complement if x==None: self.bit_set=bit_set else: self.bit_set=[] while x: print(x,x&((1<<self.word)-1)) self.bit_set.append(x&((1<<self.word)-1)) x>>=self.word 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>>self.word-n|x%(1<<self.word-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)<<self.word-n) return Bit_Set(bit_set=bit_set,word=self.word,complement=self.complement) def __and__(self,other): if type(other)!=Bit_Set: other=Bit_Set(x=other,word=self.word,complement=False) 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): if type(other)!=Bit_Set: other=Bit_Set(x=other,word=self.word,complement=False) 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): if type(other)!=Bit_Set: other=Bit_Set(x=other,word=self.word,complement=False) 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(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(bit_set=[1])<<i): ans="ODD" else: ans="EVEN" print(ans)