結果

問題 No.2745 String Swap Battle
ユーザー tassei903tassei903
提出日時 2024-04-18 01:09:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 89,984 KB
最終ジャッジ日時 2024-04-18 01:09:17
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
89,856 KB
testcase_01 AC 89 ms
89,984 KB
testcase_02 AC 42 ms
58,240 KB
testcase_03 AC 37 ms
51,968 KB
testcase_04 AC 48 ms
61,952 KB
testcase_05 AC 48 ms
62,080 KB
testcase_06 AC 57 ms
77,332 KB
testcase_07 AC 55 ms
77,224 KB
testcase_08 AC 57 ms
77,088 KB
testcase_09 AC 57 ms
76,672 KB
testcase_10 AC 46 ms
69,632 KB
testcase_11 AC 44 ms
64,768 KB
testcase_12 AC 216 ms
83,840 KB
testcase_13 AC 214 ms
84,136 KB
testcase_14 AC 235 ms
83,840 KB
testcase_15 AC 78 ms
76,160 KB
testcase_16 AC 80 ms
76,328 KB
testcase_17 AC 80 ms
76,288 KB
testcase_18 AC 37 ms
52,096 KB
testcase_19 AC 37 ms
52,352 KB
testcase_20 AC 42 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())


def f(s):
    b = [[] for _ in range(26)]
    for i in range(len(s)-1,-1,-1):
        b[ord(s[i]) - 97].append(i)
    for i in range(len(s)   ):
        for j in range(ord(s[i]) - 97):
            if len(b[j]) > 0:
                s = list(s)
                s[i], s[b[j][0]] = s[b[j][0]], s[i]
                return "".join(s)
        b[ord(s[i]) - 97].pop()
    for j in range(26):
        if s.count(chr(j+97)) >= 2:
            return s
    s = list(s)
    s[-1], s[-2] = s[-2], s[-1]
    return "".join(s)

s = [input() for _ in range(n)]
z = []
a = chr(97+26)

for i in range(n):
    s[i] = f(s[i])
    #print(s[i])
    a = min(a, s[i])

c = s.count(a)

for i in range(n):
    #print(s[i])
    if s[i] == a:
        print(n+1-c)
    else:
        print(0)
0