結果

問題 No.4 おもりと天秤
ユーザー packet0packet0
提出日時 2015-12-24 18:47:58
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 684 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 173,864 KB
実行使用メモリ 6,320 KB
最終ジャッジ日時 2023-10-19 02:54:26
合計ジャッジ時間 7,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 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 #

use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();

    let input: Vec<_> = stdin.lock().lines().map(|r| r.unwrap()).collect();

    let w: Vec<u32> = input[1].split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = w.len() as u32;


    println!("{}", if is_possible(0, 0, 0, n, &w) {"possible"} else {"impossible"});
}

fn is_possible(num_used: u32, wl: u32, wr: u32, n: u32, ws: &[u32]) -> bool {
    if num_used == n {
        return wr == wl;
    }
    let num_used_next = num_used + 1;
    let w = ws[num_used as usize];
    return is_possible(num_used_next, wl + w, wr, n, ws) ||
        is_possible(num_used_next, wl, wr + w, n, ws);
}
0