#C2859. Safety Module Prioritization

    ID: 46221 Type: Default 1000ms 256MiB

Safety Module Prioritization

Safety Module Prioritization

You are given a priority status and a JSON object representing various sectors. Each sector contains a list of modules, and each module has a name and a status. Your task is to generate a safety report by counting, for each sector, the number of modules that match the given priority status. Only sectors with at least one matching module should be included in the output.

The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).

The problem can be formulated mathematically as follows. Let (S) be the set of all sectors. For each sector (s \in S) with modules (M_s), let the report value be defined as:

[ \text{report}(s) = \sum_{m \in M_s} \mathbb{I}(status(m) = p), ]

where (p) is the given priority and (\mathbb{I}(\cdot)) is the indicator function. Only include sector (s) in the final result if (\text{report}(s) > 0).

inputFormat

The input consists of two parts provided via stdin:

  1. The first line contains a string which is the priority status (for example, "Critical" or "Warning").
  2. The remaining lines form a JSON string representing an object. This object maps sector names (strings) to an array of module objects. Each module object has two keys:
    • "name": a string representing the module name.
    • "status": a string representing the module status.

Note: The JSON input may span multiple lines.

outputFormat

Output a JSON object (printed to stdout) where each key is a sector name and its value is the count of modules in that sector that have a status equal to the given priority. Only include sectors with a count greater than zero.## sample

Critical
{"Sector 1": [{"name": "Module A", "status": "Safe"}, {"name": "Module B", "status": "Critical"}, {"name": "Module C", "status": "Warning"}], "Sector 2": [{"name": "Module D", "status": "Critical"}, {"name": "Module E", "status": "Critical"}], "Sector 3": [{"name": "Module F", "status": "Safe"}, {"name": "Module G", "status": "Warning"}]}
{"Sector 1":1,"Sector 2":2}