結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2020-02-19 21:43:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 563 bytes |
コンパイル時間 | 15,575 ms |
コンパイル使用メモリ | 377,476 KB |
実行使用メモリ | 12,996 KB |
最終ジャッジ日時 | 2024-10-08 18:18:44 |
合計ジャッジ時間 | 14,464 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
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;for i in 2..len {if n[len-1] < n[len-i] {border = len-i;break;}}if border == len-1 {println!("-1");} else {n.swap(border, border+1);println!("{}", n.iter().cloned().collect::<Vec<String>>().join(""));}}