結果

問題 No.2745 String Swap Battle
ユーザー 👑 rin204rin204
提出日時 2024-04-20 14:21:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 79,704 KB
最終ジャッジ日時 2024-04-20 14:21:58
合計ジャッジ時間 2,391 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
75,752 KB
testcase_01 AC 54 ms
75,608 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 41 ms
59,648 KB
testcase_05 AC 41 ms
59,840 KB
testcase_06 AC 59 ms
75,524 KB
testcase_07 AC 61 ms
75,912 KB
testcase_08 AC 58 ms
75,660 KB
testcase_09 AC 61 ms
75,804 KB
testcase_10 AC 53 ms
70,304 KB
testcase_11 AC 52 ms
67,684 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 86 ms
76,564 KB
testcase_17 AC 83 ms
76,356 KB
testcase_18 AC 37 ms
52,884 KB
testcase_19 AC 37 ms
52,664 KB
testcase_20 AC 37 ms
53,616 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
        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(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