結果

問題 No.559 swapAB列
ユーザー _KingdomOfMoray_KingdomOfMoray
提出日時 2020-01-03 13:15:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 743 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-02 07:13:51
合計ジャッジ時間 1,006 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,624 KB
testcase_01 AC 25 ms
10,624 KB
testcase_02 AC 25 ms
10,496 KB
testcase_03 AC 25 ms
10,624 KB
testcase_04 AC 24 ms
10,624 KB
testcase_05 AC 25 ms
10,624 KB
testcase_06 WA -
testcase_07 AC 25 ms
10,624 KB
testcase_08 AC 24 ms
10,624 KB
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()

s_list = list(s)
num_a = s_list.count('A')
border = num_a
count = 0

while 'B' in s_list[ : border] and 'A' in s_list[border : ]:
    index_b = s_list[ : border].index('B')
    s_list[index_b] = 'X'
    count += (border - 1 - index_b + 1)
    
    s_list[border - 1] = s_list[border]
    s_list[border] = 'B'
    if s_list[border - 1] == s_list[border]:
        count -= 1
    if 'B' not in s_list[ : border] or 'A' not in s_list[border : ]:
        break
    
    index_a = s_list[border : ].index('A')
    s_list[border + index_a] = 'X'
    count += (index_a + 1)
    
    s_list[border] = s_list[border - 1]
    s_list[border - 1] = 'A'
    if s_list[border - 1] == s_list[border]:
        count -= 1
        
    
print(count)
0