結果

問題 No.4 おもりと天秤
ユーザー nobuta05nobuta05
提出日時 2016-11-12 23:25:58
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 930 bytes
コンパイル時間 13,029 ms
コンパイル使用メモリ 377,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 11:11:00
合計ジャッジ時間 14,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: value assigned to `inp` is never read
  --> src/main.rs:12:10
   |
12 |     let mut inp: String = getline();
   |             ^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

ソースコード

diff #

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),
	}
}

fn main()
{
	let mut inp: String = getline();
	inp = getline();
	let mut weight: Vec<i32> = Vec::new();
	let tmp: Vec<_> = inp.split(" ").collect();
	for x in tmp {
		match x.parse::<i32>() {
			Ok(var) => weight.push(var),
			Err(e) => println!("{}", e),
		}
	}
	let n: usize = weight.len() as usize;
	let half: i32 = weight.iter().fold(0, | half, a | half + a) / 2;
	
	let mut dp = [0;6000];
	let mut nxt = [0;6000];
	dp[0] = 1;

	for k in 0..n as usize {
		for i in 0..half as usize {
			if dp[i] != 1 {
				continue;
			}

			nxt[i] = 1;
			if i as i32 + weight[k] <= half {
				nxt[i+weight[k] as usize] = 1;
			}
		}

		dp.copy_from_slice(&nxt);
	}

	if dp[half as usize] == 1 {
		println!("possible");
	}
	else {
		println!("impossible");
	}
}
0