#P11092. [ROI 2021] 莫斯科数字 (Day 2)
[ROI 2021] 莫斯科数字 (Day 2)
Problem Description
Translated from ROI 2021 D2T1。
You may be familiar with Roman numerals, and you may also have heard the saying that Moscow is the Third Rome, so we proudly introduce Moscow numbers. This is an advanced version of Roman numerals and is similar to it. In the Moscow number system, numbers are represented by uppercase English letters A to Z. Each letter corresponds to a specific value:

The rules of Moscow numbers are as follows: the value of a number equals the sum of the values of its letters. A letter can contribute positively or negatively. If there is no letter greater than it to its right, then its contribution equals its own value; otherwise, its contribution equals the negation of its own value. For example:
- The value of
BBAis ; - The value of
BBBCis ; - The value of
ABCis ; - The value of
BACis ; - The value of
ACAis ; - The value of
CFFis 。
You are given some numbers, each consisting of uppercase English letters (i.e., Moscow numbers), but some positions have been replaced by question marks. For each number, determine the maximum possible value that can be obtained after replacing each question mark with a Moscow-number letter.
Input Format
The first line contains an integer , the number of test cases, i.e., the number of given numbers ()。
The next lines each contain a string consisting of uppercase English letters and question marks. The sum of lengths of all strings does not exceed 。
Output Format
For each input, output two lines, both describing the maximum result after replacing the question marks with Moscow-number letters. The first line is the maximum value in decimal. The second line is the corresponding maximum Moscow number after replacement.
4
BBBC
????
A?B?C?D
YYYYY?
-5
BBBC
20000000000000
ZZZZ
15000000000034
AZBZCZD
6000000000000
YYYYYY
Hint
Let 。
| Subtask | Score | Special Property | |
|---|---|---|---|
does not contain ? |
|||
contains no more than three ? |
|||
Translated by ChatGPT 5