結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-11-22 23:15:11 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 842 bytes |
コンパイル時間 | 15,665 ms |
コンパイル使用メモリ | 379,272 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 04:51:01 |
合計ジャッジ時間 | 14,138 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
use std::io::{Read, stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); let mut x = get() .as_bytes() .iter() .cloned() .collect::<Vec<_>>(); x.sort(); let (p, _) = x .iter() .enumerate() .rfind(|(_,s)| **s == x[0]) .unwrap(); let find = x .iter() .enumerate() .find(|(_,s)| **s != x[0]); let ans = match find { None => "-1".to_string(), Some((i, _)) if i+1 == x.len() && x[0] == b'0' => "-1".to_string(), Some((i, _)) => { x.swap(p, i); x.reverse(); String::from_utf8(x).unwrap() } }; println!("{}", ans); }