結果
| 問題 |
No.39 桁の数字を入れ替え
|
| コンテスト | |
| ユーザー |
cra77756176
|
| 提出日時 | 2022-12-13 00:00:08 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 691 bytes |
| コンパイル時間 | 13,471 ms |
| コンパイル使用メモリ | 386,540 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 21:33:24 |
| 合計ジャッジ時間 | 14,509 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
use std::collections::HashMap;
fn main() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).ok();
let mut n: Vec<char> = n.trim().chars().collect();
let mut max_right = vec!['0'; n.len()];
let mut rpos = HashMap::new();
for (i, &c) in n.iter().enumerate().rev() {
if i == n.len() - 1 {
max_right[i] = c;
} else {
max_right[i] = c.max(max_right[i + 1]);
}
rpos.entry(c).or_insert(i);
}
for i in 0..n.len() {
if max_right[i] != n[i] {
n.swap(i, rpos[&max_right[i]]);
break;
}
}
let n: String = n.iter().collect();
println!("{}", n);
}
cra77756176