結果

問題 No.4 おもりと天秤
ユーザー nobuta05nobuta05
提出日時 2016-11-12 23:28:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,026 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 151,576 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 17:14:08
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: value assigned to `inp` is never read
  --> 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

warning: 1 warning emitted

ソースコード

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 mut half: i32 = weight.iter().fold(0, | half, a | half + a);
	
	if half % 2 == 1 {
		println!("impossible");
	}

	else {
		half /= 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