#P8791. [蓝桥杯 2022 国 AC] 内存空间

[蓝桥杯 2022 国 AC] 内存空间

Problem Description

Xiao Lan recently likes to calculate how much memory space the variables defined in his code take up.

To simplify the problem, there are only three types of variables:

int: an integer variable. One int variable takes 44 Byte of memory space.

long: a long integer variable. One long variable takes 88 Byte of memory space.

String: a string variable. The space used depends on the string length. Let the string length be LL, then the string takes LL Byte of memory space. If the string length is 00, then it takes 00 Byte of memory space.

There are only two forms of variable definition statements. The first form is:

type var1=value1,var2=value2...;

This defines several variables of type type: var1, var2, ..., and initializes them with value1, value2, ....

Multiple variables are separated by ,, and the statement ends with ;. type can be int, long, or String. For example, int a=1,b=5,c=6; takes 1212 Byte; long a=1,b=5; takes 1616 Byte; String s1="",s2="hello",s3="world"; takes 1010 Byte.

The second form is:

type[] arr1=new type[size1],arr2=new type[size2]…;

This defines several one-dimensional array variables of type type: arr1, arr2, ..., and the array sizes are size1, size2, .... Multiple variables are separated by ,, and the statement ends with ;. Here type can only be int or long. For example, int[] a1=new int[10] takes 4040 Byte; long[] a1=new long[10],a2=new long[10]; takes 160160 Byte.

It is known that Xiao Lan has TT variable definition statements. Please help him count the total memory space used.

The result should be formatted as aGBbMBcKBdB\texttt{aGBbMBcKBdB}, where aa, bb, cc, dd are the computed values, and GB\texttt{GB}, MB\texttt{MB}, KB\texttt{KB}, B\texttt{B} are the units. Prefer using larger units: 1GB=1024MB1\texttt{GB}=1024\texttt{MB}, 1MB=1024KB1\texttt{MB}=1024\texttt{KB}, 1KB=1024B1\texttt{KB}=1024\texttt{B}, where B means Byte. If some of aa, bb, cc, dd are 00, then you do not need to output those numbers and their units.

The problem guarantees that each line contains only one variable definition statement, and every statement satisfies the formats described above. All variable names are valid and do not repeat. The testdata is very regular and similar to the examples above: except for one space after the type, and one space after new when defining arrays, there will be no extra spaces.

Input Format

The first line contains an integer TT, meaning there are TT variable definition statements.

The next TT lines each contain one variable definition statement.

Output Format

Output one line containing a string that represents the total size of memory space used by all statements.

1
long[] nums=new long[131072];
1MB
4
int a=0,b=0;
long x=0,y=0;
String s1="hello",s2="world";
long[] arr1=new long[100000],arr2=new long[100000];
1MB538KB546B

Hint

Sample Explanation

In Sample 1, the space used is 131072×8=1048576131072 \times 8 = 1048576, which converts to exactly 1MB1\texttt{MB}. The numbers before the other three units GB\texttt{GB}, KB\texttt{KB}, B\texttt{B} are all 00, so they are not printed.

In Sample 2, the space used is $4 \times 2 + 8 \times 2 + 10 + 8 \times 100000 \times 2$ B, which converts to 1MB538KB546B1\texttt{MB}538\texttt{KB}546\texttt{B}.

Constraints and Conventions

For all test cases, 1T101 \leq T \leq 10. The length of each variable definition statement does not exceed 10001000. The length of every variable name does not exceed 1010, and all names consist of lowercase letters and digits. For integer variables, the initialized values are decimal integers within their representable ranges, and the initialized values will not be variables. For String variables, the initialized content length does not exceed 5050, and the content contains only lowercase letters and digits, and the initialized values will not be variables. For array variables, the array length is an integer in the range [0,230][0, 2^{30}], and the array length will not be a variable. The total memory space used by all variables defined in the TT statements is greater than 00 B and less than 10241024 GB.

Lanqiao Cup 2022 National Final, Group A, Problem C (Group C, Problem D).

Translated by ChatGPT 5