結果

問題 No.927 Second Permutation
ユーザー conf8o
提出日時 2020-02-19 21:56:38
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 12,685 ms
コンパイル使用メモリ 377,268 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-10-08 18:19:38
合計ジャッジ時間 14,425 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    
    let mut n: Vec<String> = n.trim().chars().map(|c| c.to_string()).collect();
    n.sort_by(|a, b| b.cmp(a));

    let len = n.len();

    let mut border = len-1;
    let min = &n[len-1];
    for i in 2..len {
        if min < &n[len-i] {
            border = len-i;
            break;
        }
    }

    if border == len-1 {
        println!("-1");
    } else {
        n.swap(border, border+1);
        println!("{}", n.join(""));
    }
}
0