結果

問題 No.927 Second Permutation
ユーザー simansiman
提出日時 2020-08-11 12:05:33
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 274 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-04-17 17:12:27
合計ジャッジ時間 6,828 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,288 KB
testcase_01 AC 87 ms
12,288 KB
testcase_02 AC 84 ms
12,288 KB
testcase_03 AC 83 ms
12,288 KB
testcase_04 AC 84 ms
12,160 KB
testcase_05 AC 90 ms
12,032 KB
testcase_06 AC 84 ms
12,160 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 287 ms
15,616 KB
testcase_25 AC 183 ms
14,080 KB
testcase_26 AC 148 ms
13,696 KB
testcase_27 AC 110 ms
12,928 KB
testcase_28 AC 157 ms
14,464 KB
testcase_29 AC 143 ms
13,952 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:14: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:19: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

X = gets.to_i
N = X.to_s.size

nums = X.digits.sort.reverse

l = nums.last
idx = N - 1

while idx >= 0 && nums[idx] == l
  idx -= 1
end

if idx < 0
  puts -1
else
  nums[idx], nums[-1] = nums[-1], nums[idx]

  if nums[0] == 0
    puts -1
  else
    puts nums.join
  end
end
0