結果

問題 No.10 +か×か
ユーザー ooaiuooaiu
提出日時 2024-11-13 16:14:03
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 13,001 ms
コンパイル使用メモリ 405,240 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-13 16:14:22
合計ジャッジ時間 16,010 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 OLE -
testcase_04 OLE -
testcase_05 WA -
testcase_06 OLE -
testcase_07 OLE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn main() {
    input! {
        n: usize,
        tot: usize,
        a: [usize; n]
    }
    let mut dp = vec![vec![false; tot + 1]; n + 1];
    dp[n][tot] = true;
    for i in (0..n).rev() {
        for j in 0..=tot {
            if j + a[i] <= tot && dp[i + 1][j + a[i]] {
                dp[i][j] = true;
            }
            if j * a[i] <= tot && dp[i + 1][j * a[i]] {
                dp[i][j] = true;
            }
        }
    }
    for i in 0..=n {
        println!("{:?}", dp[i]);
    }
    let mut cur = a[0];
    let mut ans: String = String::new();
    for i in 1..n {
        if cur + a[i] <= tot && dp[i + 1][cur + a[i]] {
            cur += a[i];
            ans.push('+');
        }else {
            cur *= a[i];
            ans.push('*');
        }
    }
    println!("{}", ans);
}
0