結果

問題 No.927 Second Permutation
ユーザー 👑 obakyanobakyan
提出日時 2019-11-30 21:23:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 339 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 5,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 09:44:06
合計ジャッジ時間 3,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 69 ms
4,380 KB
testcase_11 AC 116 ms
4,376 KB
testcase_12 AC 55 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 73 ms
4,376 KB
testcase_15 AC 52 ms
4,376 KB
testcase_16 AC 131 ms
4,380 KB
testcase_17 AC 130 ms
4,376 KB
testcase_18 AC 127 ms
4,376 KB
testcase_19 AC 129 ms
4,380 KB
testcase_20 AC 127 ms
4,380 KB
testcase_21 AC 127 ms
4,376 KB
testcase_22 AC 128 ms
4,376 KB
testcase_23 AC 128 ms
4,376 KB
testcase_24 AC 84 ms
4,376 KB
testcase_25 AC 54 ms
4,376 KB
testcase_26 AC 40 ms
4,380 KB
testcase_27 AC 33 ms
4,376 KB
testcase_28 AC 81 ms
4,376 KB
testcase_29 AC 64 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local s = io.read()
local n = #s
local t = {}
for i = 1, n do
  t[i] = tonumber(s:sub(i, i))
end
table.sort(t, function(a, b) return a > b end)
if t[2] == 0 or t[1] == t[n] then
  print(-1)
else
  for i = n, 2, -1 do
    if t[i] ~= t[i - 1] then
      t[i], t[i - 1] = t[i - 1], t[i]
      break
    end
  end
  print(table.concat(t))
end
0