結果

問題 No.2745 String Swap Battle
ユーザー 👑 rin204rin204
提出日時 2024-04-20 14:19:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 87,004 KB
最終ジャッジ日時 2024-04-20 14:19:58
合計ジャッジ時間 2,507 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
72,960 KB
testcase_01 AC 54 ms
72,908 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 41 ms
57,856 KB
testcase_05 AC 41 ms
58,112 KB
testcase_06 AC 68 ms
75,520 KB
testcase_07 AC 64 ms
75,520 KB
testcase_08 AC 64 ms
75,520 KB
testcase_09 AC 66 ms
75,776 KB
testcase_10 AC 57 ms
69,632 KB
testcase_11 AC 55 ms
66,268 KB
testcase_12 AC 209 ms
86,784 KB
testcase_13 AC 181 ms
87,004 KB
testcase_14 AC 145 ms
86,784 KB
testcase_15 AC 90 ms
76,416 KB
testcase_16 AC 89 ms
76,672 KB
testcase_17 AC 86 ms
76,416 KB
testcase_18 AC 37 ms
51,712 KB
testcase_19 AC 39 ms
52,128 KB
testcase_20 AC 37 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = [input() for _ in range(n)]
for i in range(n):
    T = S[i]
    mi = "z"
    m = len(T)
    ind = -1
    for j in range(1, m):
        if T[j - 1] > T[j] and T[j] <= mi:
            mi = T[j]
            ind = j

    if ind == -1:
        change = True
        for j in range(1, m):
            if T[j] == T[j - 1]:
                change = False
                break
        if change:
            T = T[:-2] + T[-1] + T[-2]
        S[i] = T
        continue

    for j in range(n):
        if T[j] > mi:
            T = T[:j] + T[ind] + T[j + 1 : ind] + T[j] + T[ind + 1 :]
            S[i] = T
            break

mi = min(S)
c = S.count(mi)
ans = [0] * n
for i in range(n):
    if S[i] == mi:
        ans[i] = n + 1 - c

print(*ans, sep="\n")
0