結果
問題 |
No.3021 Maximize eval
|
ユーザー |
![]() |
提出日時 | 2025-02-15 00:19:32 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 1,206 bytes |
コンパイル時間 | 3,916 ms |
コンパイル使用メモリ | 96,380 KB |
実行使用メモリ | 20,632 KB |
最終ジャッジ日時 | 2025-02-15 00:21:03 |
合計ジャッジ時間 | 6,312 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
import std.algorithm, std.array, std.bigint, std.conv, std.stdio, std.typecons, std.range; string solve(string exp) { char[][] nums; bool[] is_neg; if (exp[0] == '-') { is_neg ~= true; exp = exp[1 .. $]; } else { is_neg ~= false; } char[] num; foreach (c; exp) { if (c.among!('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?')) { num ~= c; } else if (c == '+') { nums ~= num; is_neg ~= false; num.length = 0; } else if (c == '-') { nums ~= num; is_neg ~= true; num.length = 0; } else assert(0); } nums ~= num; foreach (i; 0 .. nums.length) { if (is_neg[i]) { if (nums[i][0] == '?') nums[i][0] = '1'; auto qi = nums[i].countUntil('?'); if (qi == nums[i].length-1) { nums[i][$-1] = '1'; } else if (qi > 0) { nums[i][qi] = '+'; nums[i] = nums[i].replace('?', '9'); } } else { nums[i] = nums[i].replace('?', '9'); } } string result; if (is_neg[0]) result = "-"; result ~= nums[0]; foreach (i; 1 .. nums.length) { result ~= is_neg[i] ? "-" : "+"; result ~= nums[i]; } return result; } void main() { auto n = readln[0..$-1].to!uint; iota(n).map!(i => readln[0 .. $-1].solve).each!writeln; }