J. How Much Memory Your Code Is Using?

Codeforces
IDCF10195J
Time8000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
In the C++ language, the values of variables are stored somewhere in the computer memory as zeros and ones. Our program does not need to know the exact location where a variable is stored since one can simply refer to it by its name. What the program needs to be aware of is the kind of data stored in every variable. Storing a simple integer is not the same as storing a letter or a large floating-point number. Even though they are all represented by zeros and ones, they are not interpreted in the same way, and in many cases, they don't occupy the same amount of memory. Fundamental data types, implemented directly by the language, represent the basic storage units supported natively by most systems. They can be mainly classified into four types. *Character types:* They can represent a single character, such as 'A' or '$'. The most basic type is _char_, which is a one-byte character. *Numerical integer types:* They can store a whole number value, such as $7$ or $1024$. They exist in a variety of sizes. The most basic one is _int_, which is a four-byte integer. _long long_ is a larger one which occupies twice as many memories as _int_ does. A wider type of integer ___int128_ may appear in some new systems, which is a $16$-byte integer and rarely useful. *Floating-point types:* They can represent real values, such as $3. 14$ or $0. 01$, with different levels of precision, depending on which of the three floating-point types is used. _float_, _double_ and _long double_ correspond to _int_, _long long_ and ___int128_ where the former types hold the same amount of memory as the latter types used respectively. *Boolean type:* The boolean type, known in C++ as _bool_, can only represent one of two states, true or false. It is a one-byte type. Now you have a code in C++, $n$ lines of which apply several variables and arrays. Also, I have checked it so I can claim that all variables and arrays in this code are global without any conflicts. As a novice, each line in your code may only apply for one variable or one array; all types of these variables and arrays are mentioned above; any other types unmentioned can not appear in the code. Your task in this problem is to calculate the number of memories in total that the code is using. Output your answer in Kibibyte ($1$ Kibibyte is $1024$ bytes) and round it up to the nearest integer. The input contains several test cases, and the first line contains a positive integer $T$ indicating the number of test cases which is up to $100$. For each test case, the first line contains a positive integer $n$, which is up to $1000$, indicating the total number of lines to apply (i. e. allocate memory) for variables and arrays in the code. Each of the following $n$ lines may declare a variable in the form or declare a new array in the form where _type_ must be one name of the aforementioned types. All _variable_name_ and _array_name_ are distinct strings containing only lowercase letters whose lengths are up to $10$, and all _array_size_ are positive integers which are up to $10^5$. Except for spaces in or after the name of some type, no extra spaces are allowed in the input. In other words, we guarantee that no consecutive spaces appear in the input. For each test case, output a line containing "_Case #x: y_" (without quotes), where _x_ is the test case number starting from $1$, and _y_ indicates the total number of allocated memories in Kibibyte which is rounded up to the nearest integer. In the second sample case, the memory usage is $4000$ bytes, which should be rounded up to $4$ Kibibytes. ## Input The input contains several test cases, and the first line contains a positive integer $T$ indicating the number of test cases which is up to $100$.For each test case, the first line contains a positive integer $n$, which is up to $1000$, indicating the total number of lines to apply (i. e. allocate memory) for variables and arrays in the code. Each of the following $n$ lines may declare a variable in the form _type variable_name;_ or declare a new array in the form _type array_name[array_size];_ where _type_ must be one name of the aforementioned types. All _variable_name_ and _array_name_ are distinct strings containing only lowercase letters whose lengths are up to $10$, and all _array_size_ are positive integers which are up to $10^5$. Except for spaces in or after the name of some type, no extra spaces are allowed in the input. In other words, we guarantee that no consecutive spaces appear in the input. ## Output For each test case, output a line containing "_Case #x: y_" (without quotes), where _x_ is the test case number starting from $1$, and _y_ indicates the total number of allocated memories in Kibibyte which is rounded up to the nearest integer. [samples] ## Note In the second sample case, the memory usage is $4000$ bytes, which should be rounded up to $4$ Kibibytes.
**Definitions** Let $ N \in \mathbb{Z} $ be the number of floors. Let $ V = (V_0, V_1, \dots, V_{N-1}) $ be a sequence of non-negative integers, where $ V_i $ is the token value on floor $ i $. Let $ G = (V, E) $ be an undirected tree with $ N $ vertices (floors) and $ N-1 $ edges (escalators), where each edge connects two distinct floors. **Constraints** 1. $ 1 \leq N \leq 3 \cdot 10^5 $ 2. $ 0 \leq V_i < 2^{20} $ for all $ i \in \{0, 1, \dots, N-1\} $ 3. The graph $ G $ is a tree (connected, acyclic, undirected). **Objective** Find the maximum sum of token values over any connected subtree of $ G $: $$ \max_{S \subseteq V,\, S \text{ connected}} \sum_{i \in S} V_i $$
API Response (JSON)
{
  "problem": {
    "name": "J. How Much Memory Your Code Is Using?",
    "description": {
      "content": "In the C++ language, the values of variables are stored somewhere in the computer memory as zeros and ones. Our program does not need to know the exact location where a variable is stored since one ca",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 8000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10195J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In the C++ language, the values of variables are stored somewhere in the computer memory as zeros and ones. Our program does not need to know the exact location where a variable is stored since one ca...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z} $ be the number of floors.  \nLet $ V = (V_0, V_1, \\dots, V_{N-1}) $ be a sequence of non-negative integers, where $ V_i $ is the token value on floor $ i $.  \n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments