結果

問題 No.927 Second Permutation
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-07 22:52:09
言語 Ruby
(3.3.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 212 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 23,660 KB
最終ジャッジ日時 2023-10-25 23:20:54
合計ジャッジ時間 6,351 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
16,204 KB
testcase_01 AC 76 ms
16,204 KB
testcase_02 AC 74 ms
16,204 KB
testcase_03 AC 76 ms
16,204 KB
testcase_04 AC 76 ms
16,204 KB
testcase_05 AC 75 ms
16,204 KB
testcase_06 AC 79 ms
16,204 KB
testcase_07 AC 73 ms
16,204 KB
testcase_08 AC 108 ms
18,376 KB
testcase_09 AC 81 ms
16,204 KB
testcase_10 AC 136 ms
19,756 KB
testcase_11 AC 195 ms
22,448 KB
testcase_12 AC 118 ms
19,092 KB
testcase_13 AC 78 ms
16,464 KB
testcase_14 AC 135 ms
19,960 KB
testcase_15 AC 115 ms
19,008 KB
testcase_16 AC 216 ms
23,660 KB
testcase_17 AC 221 ms
23,660 KB
testcase_18 AC 211 ms
23,660 KB
testcase_19 AC 213 ms
23,660 KB
testcase_20 AC 218 ms
23,660 KB
testcase_21 AC 220 ms
23,660 KB
testcase_22 AC 216 ms
23,660 KB
testcase_23 AC 219 ms
23,660 KB
testcase_24 AC 120 ms
22,632 KB
testcase_25 AC 103 ms
20,096 KB
testcase_26 AC 95 ms
19,112 KB
testcase_27 AC 96 ms
18,560 KB
testcase_28 AC 118 ms
21,932 KB
testcase_29 AC 108 ms
20,852 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:15: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

x = gets.chomp.chars.sort.reverse
l = x.size - 1

l.downto(1) do |i|
  next if x[i] == x[i - 1]
  next if i == 1 && x[i] == "0"

  tmp = x[i]
  x[i] = x[i - 1]
  x[i - 1] = tmp
  p x.join.to_i
  exit
end

puts -1
0