結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-11-12 22:50:20 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,300 bytes |
コンパイル時間 | 11,637 ms |
コンパイル使用メモリ | 383,124 KB |
実行使用メモリ | 13,636 KB |
最終ジャッジ日時 | 2024-11-25 21:40:35 |
合計ジャッジ時間 | 72,576 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 TLE * 10 |
ソースコード
#[allow(dead_code)] fn getline() -> String { let mut inp: String = String::new(); match std::io::stdin().read_line(&mut inp) { Ok(_) => inp.trim().to_string(), Err(e) => format!("{}",e), } } #[allow(dead_code)] fn depth_search(flag: &Vec<bool>, weight: &Vec<i32>, depth: i32) -> bool { if depth as usize == weight.len() { let mut lftsum = 0; let mut rhtsum = 0; for i in 0..depth as usize { if flag[i] == true { lftsum += weight[i]; } else { rhtsum += weight[i]; } } if lftsum == rhtsum { return true; } else { return false; } } let mut nxtflag: Vec<bool> = vec![false; weight.len() as usize]; // Left Search nxtflag.copy_from_slice(&flag); if depth_search(&nxtflag, &weight, depth+1) == true { return true; } // Right Search nxtflag[depth as usize] = true; if depth_search(&nxtflag, &weight, depth+1) == true { return true; } false } fn main() { let mut inp = getline(); let mut weight: Vec<i32> = Vec::new(); let n: i32 = inp.parse().unwrap(); let flag: Vec<bool> = vec![false; n as usize]; inp = getline(); let tmp: Vec<_> = inp.split(" ").collect(); for x in tmp { weight.push(x.parse().unwrap()); } if depth_search(&flag, &weight, 0) == true { println!("possible"); } else { println!("impossible"); } }