from collections import Counter
full_dic={}
def check_sent(sent:str):
global full_dic
name,sent=sent.split(':')
dic=full_dic[name]
sent=sent[1:]
if sent in ('I am guilty.','I am not guilty.'):
dic[name]=len(sent)<=12
elif sent.endswith('guilty.'):
g_name=sent.split()[0]
dic[g_name]='not'not in sent
if sent.startswith('Today is'):
day=sent.split()[-1][:-1]
dic['day']=day
class find:
def __init__(self):
self.full_dic=full_dic
self.it=iter(self.full_dic)
self.__pretend_dic={x:()for x in full_dic}
self.__days=Counter()
self.pretend(next(self.it))
self.cheat=self.check_TF()
self.check_person()
self.final=self.check_day()
def pretend(self,check):
check_dic=self.full_dic[check]
for d in self.full_dic.values():
if d!=check_dic:
for i in d:
sample=check_dic.get(i)
if sample is not None:
self.__pretend_dic[check]+=(sample==d[i],)
break
else:
if True in d.values():self.__pretend_dic[check]+=(False,)
try:self.pretend(next(self.it))
except StopIteration:...#print(self.__pretend_dic)
def check_TF(self):
cheat={name for name,tp in self.__pretend_dic.items() if tp.count(False)==M-N}
a=len(cheat)
if a!=0 and a<=N and self.__pretend_dic[list(cheat)[0]]!=len(self.full_dic)/2:return cheat
return set()
def check_person(self)->None:
honest=set(self.full_dic.keys())-self.cheat if len(self.cheat)==N else set()
'''if len(honest)>M-N:
self.cheat=honest
honest.clear()'''
self.guilty,self.not_guilty=set(),set()
for person,comment in self.full_dic.items():
for key,value in comment.items():
if isinstance(value,bool):
if person in self.cheat:value=not value
if person in honest|self.cheat:self.guilty.add(key)if value else self.not_guilty.add(key)
#print(self.guilty)
def check_day(self):
for dic in self.full_dic.values():
for v in dic.values():
if not isinstance(v,bool):self.__days.update([v])
s=list(self.__days.values())
guilty=self.guilty
not_guilty=self.not_guilty
if len(s)!=0:
#rint(not_guilty)
x={person:dd.get('day') for person,dd in self.full_dic.items()}
for p,t in x.items():
if len([...for rk in x if rk!=p and x[rk]!=t])>N:self.cheat.add(p)
#print(s)
if s[0]!=s[-1]and(len(s)>=3 or s[0]>len(self.full_dic)//2):
right_day=self.__days.most_common()[0][0]
for d in self.full_dic.values():
if 'day'in d.keys():
for key,value in d.items():
if isinstance(value,bool):
if d['day']!=right_day and key not in self.cheat or key in self.cheat and d['day']==right_day:value=not value
guilty.add(key)if value else not_guilty.add(key)
if len(not_guilty)==M:return 'Impossible'
if len(guilty)>1:return'Cannoot Determine'
if len(guilty)==0:return(set(self.full_dic.keys())-not_guilty)[0]if len(self.full_dic)-1==len(not_guilty)else'Cannot Determine'
else:return list(guilty)[0]
def __call__(self):
return self.final
if __name__=='__main__':
M,N,P=[int(i) for i in input().split()]
for _ in range(M):
full_dic[input()]={}
for _ in range(P):
check_sent(input())
f=find()
#print(full_dic)
print(f())
在线IDE和VSCode两个输入都没问题,结果全都RE,想破脑袋也没发现什么问题