結果

問題 No.2745 String Swap Battle
ユーザー 👑 rin204rin204
提出日時 2024-04-20 14:26:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 86,912 KB
最終ジャッジ日時 2024-04-20 14:26:39
合計ジャッジ時間 2,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
75,392 KB
testcase_01 AC 63 ms
76,032 KB
testcase_02 AC 36 ms
52,352 KB
testcase_03 AC 37 ms
52,096 KB
testcase_04 AC 41 ms
58,608 KB
testcase_05 AC 42 ms
58,112 KB
testcase_06 AC 61 ms
75,520 KB
testcase_07 AC 66 ms
75,776 KB
testcase_08 AC 65 ms
75,776 KB
testcase_09 AC 63 ms
75,700 KB
testcase_10 AC 55 ms
70,656 KB
testcase_11 AC 55 ms
66,944 KB
testcase_12 AC 153 ms
86,656 KB
testcase_13 AC 139 ms
86,656 KB
testcase_14 AC 142 ms
86,912 KB
testcase_15 AC 91 ms
76,416 KB
testcase_16 AC 89 ms
76,416 KB
testcase_17 AC 84 ms
76,288 KB
testcase_18 AC 40 ms
52,096 KB
testcase_19 AC 35 ms
52,480 KB
testcase_20 AC 35 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = [input() for _ in range(n)]
for i in range(n):
    T = S[i]
    mi = chr(200)
    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
        elif T[j] == mi:
            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(m):
        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