結果

問題 No.2745 String Swap Battle
ユーザー PNJPNJ
提出日時 2024-04-20 16:16:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 96,452 KB
最終ジャッジ日時 2024-04-20 16:16:26
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
96,452 KB
testcase_01 AC 86 ms
93,004 KB
testcase_02 AC 38 ms
59,428 KB
testcase_03 AC 35 ms
53,192 KB
testcase_04 AC 48 ms
63,352 KB
testcase_05 AC 48 ms
63,060 KB
testcase_06 AC 70 ms
86,912 KB
testcase_07 AC 75 ms
86,784 KB
testcase_08 AC 70 ms
86,764 KB
testcase_09 AC 67 ms
86,140 KB
testcase_10 AC 51 ms
72,884 KB
testcase_11 AC 47 ms
67,664 KB
testcase_12 AC 309 ms
95,056 KB
testcase_13 AC 324 ms
93,924 KB
testcase_14 AC 310 ms
95,228 KB
testcase_15 AC 79 ms
76,344 KB
testcase_16 AC 81 ms
76,480 KB
testcase_17 AC 82 ms
76,472 KB
testcase_18 AC 33 ms
52,804 KB
testcase_19 AC 34 ms
52,996 KB
testcase_20 AC 35 ms
54,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
# K = 1になる。
S = []
for i in range(N):
  s = input()
  n = len(s)
  T = [s[j] for j in range(n)]
  TT = T[:]
  TT[-1],TT[-2] = TT[-2],TT[-1]
  t = ''.join(TT)
  C = [[-1] for j in range(26)]
  for j in range(n):
    C[ord(s[j]) - 97].append(j)
  TTT = T[:]
  f = 0
  for j in range(n):
    if f:
      break
    c = ord(s[j]) - 97
    if c == 0:
      continue
    for k in range(c):
      if C[k][-1] > j:
        l = C[k][-1]
        TTT[j],TTT[l] = TTT[l],TTT[j]
        f = 1
        break
  Q = [t]
  if f:
    Q.append(''.join(TTT))
  else:
    for j in range(26):
      if len(C[j]) >= 3:
        Q.append(s)
        break
  Q.sort()
  S.append(Q[0])

T = S[:]
T.sort()
t = T[0]
ans = []
for i in range(N):
  if S[i] == t:
    ans.append(1)
  else:
    ans.append(0)
sco = N + 1 - sum(ans)
for i in range(N):
  if ans[i]:
    ans[i] = sco
for res in ans:
  print(res)
0