結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
12,032 KB
testcase_01 AC 94 ms
12,288 KB
testcase_02 AC 95 ms
12,288 KB
testcase_03 AC 95 ms
12,160 KB
testcase_04 AC 95 ms
12,288 KB
testcase_05 AC 92 ms
12,032 KB
testcase_06 AC 95 ms
12,160 KB
testcase_07 AC 96 ms
12,032 KB
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 303 ms
15,488 KB
testcase_25 AC 197 ms
14,208 KB
testcase_26 AC 163 ms
13,568 KB
testcase_27 AC 122 ms
12,928 KB
testcase_28 AC 173 ms
14,464 KB
testcase_29 AC 157 ms
13,952 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:16: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:21: 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
r = N - 1
idx = N - 2

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

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

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