CodeCompare
unknown
python
4 years ago
1.5 kB
29
Indexable
#CODE 1
for _ in range(int(input())):
# n = int(input())
m, n = map(int, input().split())
# arr= list(map(int, input().split()))
output_arr =[]
no_of_one= 0
no_of_zero= 0
while m>0:
b= input()
count= b.count('1')
count1= b.count('0')
no_of_one += count
no_of_zero +=count1
output_arr.append([count, b])
m-=1
output_arr= sorted(output_arr)
# print(output_arr)
string=''
for i, value in output_arr:
string = string + value
# print(string)
res=0
for i in string:
if i=='1':
res+= no_of_zero
elif i=='0':
no_of_zero -=1
print(res)
#CODE 2
# cook your dish here
t=int(input())
for _ in range(t):
n,m=input().split(" ")
n=int(n)
m=int(m)
arr=[]
for _ in range(n):
s=input()
arr.append(s)
farr=[]
summ=0
for strs in arr:
count=0
for ch in strs:
if ch=="0":
count+=1
summ+=int(ch)
farr.append((strs,count))
tsum=0
final=sorted(farr,key=lambda x:x[1],reverse=True)
i=0
ans=0
for strs,zerocount in final:
for ch in strs:
# print(ch)
if ch=="1":
summ-=1
rem=(n*m)-i-1
zer=rem-summ
# print(strs,summ,zeros)
ans+=zer
i+=1
print(ans)Editor is loading...