結果

問題 No.2745 String Swap Battle
コンテスト
ユーザー detteiuu
提出日時 2026-10-03 16:20:40
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 992 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 76 ms
コンパイル使用メモリ 82,516 KB
実行使用メモリ 148,372 KB
最終ジャッジ日時 2026-10-03 16:20:53
合計ジャッジ時間 4,000 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline
from collections import defaultdict

def code(s):
    return ord(s)-ord("a")
def codeR(n):
    return chr(ord("a")+n)

N = int(input())
S = [list(input().rstrip("\n")) for _ in range(N)]

for i in range(N):
    L = len(S[i])
    C = [[0]*26 for _ in range(L+1)]
    for j in reversed(range(L)):
        for k in range(26):
            C[j][k] = C[j+1][k]
        C[j][code(S[i][j])] += 1
    for j in range(L-1):
        if 1 <= code(S[i][j]) and 1 <= sum(C[j+1][:code(S[i][j])]):
            for k in reversed(range(j+1, L)):
                if S[i][k] < S[i][j]:
                    S[i][j], S[i][k] = S[i][k], S[i][j]
                    break
            break
    else:
        if len(set(S[i])) == L:
            S[i][-1], S[i][-2] = S[i][-2], S[i][-1]

MIN = "~"
D = defaultdict(int)
S = ["".join(s) for s in S]
for s in S:
    MIN = min(MIN, s)
    D[s] += 1

for s in S:
    if MIN == s:
        print(N+1-D[s])
    else:
        print(0)
0