結果

問題 No.927 Second Permutation
ユーザー gemmarogemmaro
提出日時 2020-02-06 08:17:22
言語 Ruby
(3.3.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 345 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 27,020 KB
最終ジャッジ日時 2023-10-25 06:15:05
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
16,228 KB
testcase_01 AC 88 ms
16,228 KB
testcase_02 AC 87 ms
16,224 KB
testcase_03 AC 88 ms
16,228 KB
testcase_04 AC 91 ms
16,228 KB
testcase_05 AC 89 ms
16,232 KB
testcase_06 AC 88 ms
16,228 KB
testcase_07 AC 88 ms
16,228 KB
testcase_08 AC 127 ms
19,428 KB
testcase_09 AC 94 ms
16,232 KB
testcase_10 AC 144 ms
21,884 KB
testcase_11 AC 184 ms
23,716 KB
testcase_12 AC 133 ms
20,652 KB
testcase_13 AC 97 ms
16,644 KB
testcase_14 AC 150 ms
22,052 KB
testcase_15 AC 135 ms
20,492 KB
testcase_16 AC 190 ms
27,020 KB
testcase_17 AC 197 ms
27,020 KB
testcase_18 AC 194 ms
27,020 KB
testcase_19 AC 194 ms
27,020 KB
testcase_20 AC 194 ms
27,020 KB
testcase_21 AC 195 ms
27,020 KB
testcase_22 AC 195 ms
27,020 KB
testcase_23 AC 194 ms
27,020 KB
testcase_24 AC 139 ms
24,440 KB
testcase_25 AC 115 ms
20,836 KB
testcase_26 AC 111 ms
20,040 KB
testcase_27 AC 108 ms
19,412 KB
testcase_28 AC 127 ms
23,728 KB
testcase_29 AC 121 ms
22,508 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

X = gets.chomp.chars.map(&:to_i).sort

if X.uniq.size == 1 || X[-2].zero?
  puts(-1)
else
  result = []
  swapped = false
  X.each_cons(2) do |a, b|
    if swapped
      result << b
    elsif a != b
      result << b << a
      swapped = true
    else
      result << a
    end
  end
  puts result.reverse.join
end
0