#40478: 寫的不好, 我盡力了, 用逆推


mountainwu14@gmail.com (吳小四)

學校 : 不指定學校
編號 : 187101
來源 : [123.193.136.130]
最後登入時間 :
2024-07-25 20:25:33
i400. 2. 字串解碼 -- 2022年6月APCS | From: [122.121.24.82] | 發表日期 : 2024-05-23 20:12

n,m=map(int,input().split());E=[];nbite=[]
for _ in range(n): 
    e=input();e=list(e);sum=0
    for i in range(len(e)):
        if e[i]=="1":
            sum+=1
    E.append(e);nbite.append(sum)
t=list(input())# t =[retywq]
step=n-1
for a in range(n-1,-1,-1):
    e=E[a];ans=""
    s=[0]*len(t);back=len(t)-1;front=0
    if nbite[step]%2==0:
        for i in range(m):
    
            if e[i]=="1":
                s[back]=t[i]#;print(back,"s[back]",s[back])
                back-=1
    
    
        for i in range(m):
            if e[i]=="0":
                s[front]=t[i]
                front+=1    
        t=s.copy()
        for i in range(len(t)):ans+=t[i]        
    else:
        for i in range(m):
    
            if e[i]=="1":
                s[back]=t[i]#;print(back,"s[back]",s[back])
                back-=1
    
    
        for i in range(m):
            if e[i]=="0":
                s[front]=t[i]
                front+=1
        t=s.copy()
        
        for i in range(len(t)):ans+=t[i]
        if len(t)%2==0:
            ans=ans[len(t)//2:]+ans[0:len(t)//2]
        else:
            
            ans=ans[(len(t)//2+1):]+ans[len(t)//2]+ans[0:len(t)//2]
        #print("here t2",ans)
        t=list(ans)
    step-=1            
print(ans)
 
ZeroJudge Forum