結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
Maricom_tkg
|
| 提出日時 | 2018-11-04 22:23:09 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 756 bytes |
| コンパイル時間 | 13,609 ms |
| コンパイル使用メモリ | 383,600 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-20 20:08:34 |
| 合計ジャッジ時間 | 12,325 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 23 |
ソースコード
use std::io::Read;
fn main() {
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut iter = buf.split_whitespace().map(|w| w.parse::<isize>().unwrap());
let n: usize = iter.next().unwrap() as usize;
let half: isize = iter.clone().sum();
let mut weights: Vec<isize> = iter.collect();
weights.sort();
println!("{}", brute_force(0, half, &weights, n));
}
fn brute_force(pos: usize, remaining: isize, weights: &Vec<isize>, n: usize) -> bool {
if remaining == 0 {
return true
} else if remaining < 0 || pos == n {
return false
}
brute_force(pos + 1, remaining - weights[pos], weights, n) ||
brute_force(pos + 1, remaining, weights, n)
}
Maricom_tkg