Submission #19729637


Source Code Expand

Copy
n=int(input())
cnt0=0
cnt1=0
cnt2=0
ans=0
 
for i in range(n):
  s=input()
  ans+=s.count("AB")
  if s[0]=="B" and s[-1]=="A":
    cnt0+=1
  elif s[-1]=="A":
    cnt1+=1
  elif s[0]=="B":
    cnt2+=1
    
if cnt0==0:
  ans+=min(cnt1,cnt2)
else:
  ans+=cnt0-1
  if cnt1==0 and cnt2==0:
    ans+=0
  elif cnt1==0:
    ans+=1
  elif cnt2==0:
    ans+=1
  else:
    ans+=min(cnt1,cnt2)+1
    
print(ans)

Submission Info

Submission Time
Task C - AB Substrings
User yasutakah
Language PyPy3 (7.3.0)
Score 400
Code Size 428 Byte
Status AC
Exec Time 101 ms
Memory 69848 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 48
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_06.txt, rand_07.txt, rand_08.txt, rand_09.txt, rand_10.txt, rand_11.txt, rand_12.txt, rand_13.txt, rand_14.txt, rand_15.txt, rand_16.txt, rand_17.txt, rand_18.txt, rand_19.txt, rand_20.txt, rand_21.txt, rand_22.txt, rand_23.txt, rand_24.txt, rand_25.txt, rand_26.txt, rand_27.txt, rand_28.txt, rand_29.txt, rand_30.txt, rand_31.txt, rand_32.txt, rand_33.txt, rand_34.txt, rand_35.txt, rand_36.txt, rand_37.txt, rand_38.txt, rand_39.txt, rand_40.txt, rand_41.txt, rand_42.txt, rand_43.txt, rand_44.txt, rand_45.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
rand_01.txt AC 101 ms 69540 KB
rand_02.txt AC 85 ms 69448 KB
rand_03.txt AC 93 ms 69740 KB
rand_04.txt AC 86 ms 69416 KB
rand_05.txt AC 91 ms 69600 KB
rand_06.txt AC 91 ms 69496 KB
rand_07.txt AC 86 ms 69376 KB
rand_08.txt AC 89 ms 69776 KB
rand_09.txt AC 86 ms 69380 KB
rand_10.txt AC 84 ms 69508 KB
rand_11.txt AC 83 ms 69376 KB
rand_12.txt AC 87 ms 69704 KB
rand_13.txt AC 89 ms 69452 KB
rand_14.txt AC 91 ms 69800 KB
rand_15.txt AC 86 ms 69744 KB
rand_16.txt AC 88 ms 69796 KB
rand_17.txt AC 81 ms 69508 KB
rand_18.txt AC 86 ms 69400 KB
rand_19.txt AC 81 ms 69444 KB
rand_20.txt AC 84 ms 69568 KB
rand_21.txt AC 93 ms 69648 KB
rand_22.txt AC 91 ms 69560 KB
rand_23.txt AC 87 ms 69540 KB
rand_24.txt AC 89 ms 69508 KB
rand_25.txt AC 90 ms 69784 KB
rand_26.txt AC 92 ms 69612 KB
rand_27.txt AC 86 ms 69544 KB
rand_28.txt AC 88 ms 69648 KB
rand_29.txt AC 88 ms 69668 KB
rand_30.txt AC 87 ms 69788 KB
rand_31.txt AC 83 ms 69608 KB
rand_32.txt AC 90 ms 69608 KB
rand_33.txt AC 91 ms 69740 KB
rand_34.txt AC 86 ms 69484 KB
rand_35.txt AC 85 ms 69624 KB
rand_36.txt AC 89 ms 69540 KB
rand_37.txt AC 81 ms 69364 KB
rand_38.txt AC 88 ms 69520 KB
rand_39.txt AC 89 ms 69364 KB
rand_40.txt AC 92 ms 69800 KB
rand_41.txt AC 90 ms 69808 KB
rand_42.txt AC 86 ms 69372 KB
rand_43.txt AC 91 ms 69784 KB
rand_44.txt AC 86 ms 69848 KB
rand_45.txt AC 87 ms 69496 KB
sample_01.txt AC 52 ms 61620 KB
sample_02.txt AC 49 ms 62028 KB
sample_03.txt AC 51 ms 61652 KB