結果

問題 No.10 +か×か
コンテスト
ユーザー ooaiu
提出日時 2024-11-13 16:14:38
言語 Rust
(1.92.0 + proconio + num)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 769 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 12,253 ms
コンパイル使用メモリ 402,500 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-06 15:05:03
合計ジャッジ時間 13,340 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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;
            }
        }
    }

    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