結果

問題 No.927 Second Permutation
ユーザー 37zigen37zigen
提出日時 2019-11-22 21:59:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 77,612 KB
実行使用メモリ 58,568 KB
最終ジャッジ日時 2024-04-19 11:23:40
合計ジャッジ時間 8,220 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
52,796 KB
testcase_01 AC 104 ms
53,600 KB
testcase_02 AC 97 ms
52,804 KB
testcase_03 AC 107 ms
54,252 KB
testcase_04 AC 105 ms
53,952 KB
testcase_05 AC 108 ms
54,004 KB
testcase_06 AC 97 ms
54,456 KB
testcase_07 AC 102 ms
53,104 KB
testcase_08 AC 177 ms
57,668 KB
testcase_09 AC 114 ms
54,680 KB
testcase_10 AC 204 ms
57,796 KB
testcase_11 AC 239 ms
58,568 KB
testcase_12 AC 195 ms
56,564 KB
testcase_13 AC 146 ms
54,184 KB
testcase_14 AC 223 ms
57,756 KB
testcase_15 AC 203 ms
56,936 KB
testcase_16 AC 240 ms
58,096 KB
testcase_17 AC 243 ms
58,416 KB
testcase_18 AC 247 ms
58,196 KB
testcase_19 AC 246 ms
58,472 KB
testcase_20 AC 239 ms
58,196 KB
testcase_21 AC 246 ms
58,104 KB
testcase_22 AC 243 ms
58,368 KB
testcase_23 AC 237 ms
58,264 KB
testcase_24 AC 162 ms
54,536 KB
testcase_25 AC 169 ms
54,512 KB
testcase_26 AC 162 ms
54,248 KB
testcase_27 AC 144 ms
53,988 KB
testcase_28 AC 180 ms
54,604 KB
testcase_29 AC 174 ms
54,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        char[] cs = sc.next().toCharArray();
        int[] a = new int[cs.length];
        int cnt0 = 0;
        for (int i = 0; i < a.length; ++i) {
            a[i] = (int) (cs[i] - '0');
            if (a[i] == 0) ++cnt0;
        }
        Arrays.sort(a);
        boolean same = true;
        for (int i = 0; i < a.length; ++i) same &= a[i] == a[0];
        if (same || cnt0 == a.length - 1) {
            System.out.println(-1);
            return;
        }
        int p = 0;
        while (a[p] == a[p + 1]) ++p;
        a[p + 1] ^= a[p];
        a[p] ^= a[p + 1];
        a[p + 1] ^= a[p];
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = a.length - 1; i >= 0; --i) {
            pw.print(a[i]);
        }
        pw.println();
        pw.close();
    }
}
0