結果
問題 | No.672 最長AB列 |
ユーザー | yn |
提出日時 | 2019-01-26 17:31:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,309 bytes |
コンパイル時間 | 311 ms |
コンパイル使用メモリ | 86,864 KB |
実行使用メモリ | 77,252 KB |
最終ジャッジ日時 | 2023-10-14 14:05:07 |
合計ジャッジ時間 | 3,648 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
71,280 KB |
testcase_01 | AC | 63 ms
71,188 KB |
testcase_02 | AC | 60 ms
71,148 KB |
testcase_03 | AC | 59 ms
71,380 KB |
testcase_04 | AC | 62 ms
71,300 KB |
testcase_05 | AC | 63 ms
71,372 KB |
testcase_06 | AC | 62 ms
71,424 KB |
testcase_07 | AC | 64 ms
71,340 KB |
testcase_08 | AC | 60 ms
71,336 KB |
testcase_09 | AC | 64 ms
71,812 KB |
testcase_10 | AC | 70 ms
76,604 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 79 ms
76,840 KB |
testcase_18 | AC | 70 ms
76,232 KB |
ソースコード
s = input() if s.count("A") == 0 or s.count("B") == 0: print(0) exit() l = 0 r = 2 len_s = len(s) if s[l:r] == "AA": cnt = 1 surplus = "A" elif s[l:r] == "BB": cnt = 1 surplus = "B" else: cnt = 0 surplus = "" while l < len_s and r < len_s: # s[l:r] に含まれるAの個数とBの個数が異なるとき if cnt > 0: if s[l] != s[r]: if s[r] == surplus: cnt += 1 else: cnt -= 1 if cnt == 0: surplus = "" l += 1 r += 1 continue # s[l:r] に含まれるAの個数とBの個数が等しいとき if l - 2 >= 0: if s[l - 2:l] == "AB" or s[l - 2:l] == "BA" == 1: l -= 2 cnt = 0 continue if l - 1 >= 0 and r < len_s: if (s[l - 1] + s[r]) == "AB" or (s[l - 1] + s[r]) == "BA": l -= 1 r += 1 cnt = 0 continue if r + 2 <= len_s: if s[r:r + 2] == "AB" or s[r:r + 2] == "BA": r += 2 cnt = 0 continue # ひとつ右にずらす if s[l] != s[r]: cnt = 1 if s[r] == "A": surplus = "A" else: surplus = "B" l += 1 r += 1 print(r - l)