結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-13 16:14:38 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 5,000 ms |
| コード長 | 769 bytes |
| コンパイル時間 | 12,686 ms |
| コンパイル使用メモリ | 404,304 KB |
| 実行使用メモリ | 6,912 KB |
| 最終ジャッジ日時 | 2024-11-13 16:14:53 |
| 合計ジャッジ時間 | 13,993 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
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);
}