結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2016-10-18 12:30:48 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 178 ms / 5,000 ms |
コード長 | 953 bytes |
コンパイル時間 | 11,185 ms |
コンパイル使用メモリ | 404,840 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-18 10:05:37 |
合計ジャッジ時間 | 13,553 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
fn getline() -> String{ let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); ret } fn getvec(string: String) -> Vec<i32> { string.trim().split_whitespace() .map(|s| s.parse().unwrap()) .collect() } fn bubblesort(v: &Vec<i32>) -> Vec<i32> { let mut dst = v.to_owned(); for i in 0..dst.len() { for j in i..dst.len() { if dst[i] > dst[j] { dst.swap(i, j) } } } dst } fn solve(v: &Vec<i32>, l: i32) -> usize { let sorted = bubblesort(v); let mut acc = 0; for (i, a) in sorted.into_iter().enumerate() { acc += a; if acc > l { return i } else if acc == l { return i+1 } } v.len() } fn main() { let l:i32 = getline().trim().parse().unwrap(); let _:i32 = getline().trim().parse().unwrap(); println!("{}", solve(&getvec(getline()), l)) }