結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-31 13:25:27 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,075 bytes |
| コンパイル時間 | 12,837 ms |
| コンパイル使用メモリ | 402,064 KB |
| 実行使用メモリ | 14,008 KB |
| 最終ジャッジ日時 | 2024-07-31 13:25:47 |
| 合計ジャッジ時間 | 19,781 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
コンパイルメッセージ
warning: unused imports: `BTreeSet`, `HashMap`, `HashSet`, `VecDeque`, `io::stdin`, `str::FromStr`, `sync::OnceLock`
--> src/main.rs:2:19
|
2 | collections::{BTreeSet, HashMap, HashSet, VecDeque},
| ^^^^^^^^ ^^^^^^^ ^^^^^^^ ^^^^^^^^
3 | fmt::Debug,
4 | io::stdin,
| ^^^^^^^^^
5 | str::FromStr,
| ^^^^^^^^^^^^
6 | sync::OnceLock,
| ^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `proconio::marker::Chars`
--> src/main.rs:9:5
|
9 | use proconio::marker::Chars;
| ^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
use std::{
collections::{BTreeSet, HashMap, HashSet, VecDeque},
fmt::Debug,
io::stdin,
str::FromStr,
sync::OnceLock,
};
use proconio::marker::Chars;
fn main() {
proconio::input! {
n: u32,
t: u32,
a: [u32; n],
}
let result = f(a[0], t, &mut Vec::new(), &a[1..]).unwrap();
let result = result
.into_iter()
.map(|o| match o {
Op::Plus => '+',
Op::Mult => '*',
})
.collect::<String>();
println!("{result}");
}
#[derive(Debug, Clone, Copy)]
enum Op {
Plus,
Mult,
}
fn f(v: u32, t: u32, op: &mut Vec<Op>, a: &[u32]) -> Option<Vec<Op>> {
if a.is_empty() {
return (v == t).then(|| op.clone());
}
if v >= t {
return None;
}
op.push(Op::Plus);
let plus_v = v + a[0];
if let Some(r) = f(plus_v, t, op, &a[1..]) {
return Some(r);
}
op.pop();
op.push(Op::Mult);
let mult_v = v * a[0];
if let Some(r) = f(mult_v, t, op, &a[1..]) {
return Some(r);
}
op.pop();
None
}