結果

問題 No.2614 Delete ABC
ユーザー Ekiben542Ekiben542
提出日時 2024-01-26 21:58:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 729 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 87,048 KB
最終ジャッジ日時 2024-01-26 21:58:17
合計ジャッジ時間 3,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
70,720 KB
testcase_01 TLE -
testcase_02 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#条件をすべて満たすかチェック
def generate_string(N, S):
    if len(S) == 3 * N:
        if check_conditions(S):
            return S
    else:
        for c in 'ABC':
            result = generate_string(N, S + c)
            if result is not None:
                return result
    return None

def check_conditions(S):
    if 'AA' in S or 'BB' in S or 'CC' in S:
        return False
    if sorted(S) != sorted('ABC' * (len(S) // 3)):
        return False

    while 'ABC' in S:
        S = S.replace('ABC', '', 1)
    if S != '':
        return True

    return False

T = int(input())
for _ in range(T):
    N = int(input())
    result = generate_string(N, '')
    if result is not None:
        print(result)
0