結果
| 問題 |
No.3021 Maximize eval
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-14 22:20:01 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,242 bytes |
| コンパイル時間 | 13,543 ms |
| コンパイル使用メモリ | 401,644 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-02-14 22:20:19 |
| 合計ジャッジ時間 | 14,968 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 |
ソースコード
use proconio::{fastout, input, marker::Chars};
#[fastout]
fn main() {
input! {
t: usize,
ss: [Chars; t],
}
for s in &ss {
println!("{}", solve(s));
}
}
fn solve(s: &[char]) -> String {
let is_operator = |c: char| c == '+' || c == '-';
let check_placeable_operator = |pos: usize| {
pos != s.len() - 1 && (pos == 0 || !is_operator(s[pos - 1])) && !is_operator(s[pos + 1])
};
let mut output = String::new();
output.reserve(s.len());
let mut positive = true;
for (i, &c) in s.iter().enumerate() {
match c {
'1'..='9' => {
output.push(c);
}
'+' => {
positive = true;
output.push('+');
}
'-' => {
positive = false;
output.push('-');
}
'?' => {
if positive {
output.push('9');
} else if check_placeable_operator(i) {
output.push('+');
positive = true;
} else {
output.push('1');
}
}
_ => panic!(),
}
}
output
}