結果
問題 |
No.1630 Sorting Integers (Greater than K)
|
ユーザー |
|
提出日時 | 2022-10-18 21:01:02 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,660 bytes |
コンパイル時間 | 15,300 ms |
コンパイル使用メモリ | 378,516 KB |
実行使用メモリ | 38,596 KB |
最終ジャッジ日時 | 2024-06-29 03:32:07 |
合計ジャッジ時間 | 18,129 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 22 |
コンパイルメッセージ
warning: unused variable: `j` --> src/main.rs:50:13 | 50 | for j in 0..c[i] { | ^ help: if this is intentional, prefix it with an underscore: `_j` | = note: `#[warn(unused_variables)]` on by default
ソースコード
fn main() { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<&str> = temp.trim().split_whitespace().collect(); let n = temp[0].parse::<usize>().unwrap(); let k = temp[1].to_string(); let mut c = String::new(); std::io::stdin().read_line(&mut c).ok(); let mut c: Vec<usize> = c.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); c.insert(0, 0); let maxval = (0..10).rev().map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join(""); if maxval.len() < k.len() || k >= maxval { println!("-1"); return; } if k.len() < n { println!("{}", (0..10).map(|i| i.to_string().repeat(c[i])).collect::<Vec<_>>().join("")); return; } let mut idx = 0usize; let kvals = k.chars().map(|c| c as usize - '0' as usize).collect::<Vec<_>>(); while idx < k.len() && c[kvals[idx]] > 0 { c[kvals[idx]] -= 1; idx += 1; } if idx == k.len() { idx -= 1; c[kvals[idx]] += 1; } let mut result = (0..idx).map(|i| kvals[i]).collect::<Vec<_>>(); loop { let mut flg = false; for i in kvals[result.len()]+1..10 { if c[i] > 0 { result.push(i); c[i] -= 1; flg = true; break; } } if flg { break; } else { c[result.pop().unwrap()] += 1; } } for i in 0..10 { for j in 0..c[i] { result.push(i); } } println!("{}", result.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join("")); }