結果

問題 No.4 おもりと天秤
ユーザー nobuta05nobuta05
提出日時 2016-11-12 22:50:20
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,300 bytes
コンパイル時間 13,038 ms
コンパイル使用メモリ 378,080 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2024-05-04 11:09:43
合計ジャッジ時間 18,045 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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");
	}
}
0