th0m45s5helby

Untitled

Mar 25th, 2022
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. m,n=map(int,input().split())
  2. matrix=[]
  3. dic = {}
  4. coins=0
  5. calories=0
  6. for i in range(m):
  7.     matrix.append(list(input()))
  8.    
  9.  
  10. for i in range(m):
  11.     for j in range(n):
  12.         if matrix[i][j]=="C":
  13.             if dic.get(j,-1)==-1:
  14.                 calories += 2*(m-i-1)
  15.                 dic[j]=1
  16.             coins+=1
  17.         elif matrix[i][j]=="H":
  18.             if dic.get(j,-1)==-1:
  19.                 dic[j]="H"+str(i)
  20.         elif matrix[i][j]=="0" and str(dic.get(j,-1))[0]=="H":
  21.             calories += 2*(m-i-1)
  22.             dic[j]=2
  23. for k,v in dic.items():
  24.     if str(v)[0]=="H":
  25.         calories += 2*(m-int(str(v)[1:]))
  26. print(coins,calories)
  27.            
  28.            
  29.                
Advertisement
Add Comment
Please, Sign In to add comment