C. Leading the Scoreboard

Codeforces
IDCF10148C
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Marge is the newest member of GEMA, a programming competition study group at her university. One of the first things she did as a new member was to look at the last year's regionals scoreboard to see how well the team representing her university performed. Looking at it, she noticed that she had no idea how the teams were ranked in the scoreboard. After searching on the internet she found the following text in the rules section of the ACM-ICPC website, describing how teams are ranked in the scoreboard: _"Teams are ranked according to the most problems solved, ... teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved."_ Marge already knows that ACM-ICPC contests have a duration of 300 minutes and, if at any moment there are multiple teams tied for the first position (same number of problems solved and same total time), she considers that all those teams are leading the scoreboard at the same time. She found the list of submissions of the contest and now she is interested in finding out the total amount of time in minutes that her university's team was leading the scoreboard. The first line of the input contains three integers N (2 ≤ N ≤ 200), M (1 ≤ M ≤ 104) and P (8 ≤ P ≤ 14), indicating respectively the number of teams in the competition, the total number of submissions and the total number of problems in the contest. The next N lines contain each a single word, consisting of 1 to 10 uppercase Latin letters, indicating the name of each team. The first team listed corresponds to Marge's university's team. The next M lines contain each the information about a submission: the name of the team that made the submission, an uppercase letter indicating the problem associated with the submission (one of the first P letters of the alphabet), an integer t (1 ≤ t ≤ 300) indicating the time in minutes at which the submission was made, and a string containing either "OK" (accepted run) or "NO" (rejected run) indicating the result of the submission. The submissions are in nondecreasing order by submitted time (t). In your calculations, consider that a submission sent at minute t was sent and judged exactly t minutes and 0 seconds after the beginning of the contest. No team made more than one submission in a given minute and no team submitted an answer for a problem they have already solved. Output a single integer, the total amount of time in minutes during which Marge's university's team was leading the scoreboard. In the first example, BOB was leading the scoreboard between minutes 0 and 1 and between minutes 180 and 185. In the second example, BOB was leading the scoreboard between minutes 0 and 300, but lost the leadership at the last moment. ## Input The first line of the input contains three integers N (2 ≤ N ≤ 200), M (1 ≤ M ≤ 104) and P (8 ≤ P ≤ 14), indicating respectively the number of teams in the competition, the total number of submissions and the total number of problems in the contest.The next N lines contain each a single word, consisting of 1 to 10 uppercase Latin letters, indicating the name of each team. The first team listed corresponds to Marge's university's team.The next M lines contain each the information about a submission: the name of the team that made the submission, an uppercase letter indicating the problem associated with the submission (one of the first P letters of the alphabet), an integer t (1 ≤ t ≤ 300) indicating the time in minutes at which the submission was made, and a string containing either "OK" (accepted run) or "NO" (rejected run) indicating the result of the submission. The submissions are in nondecreasing order by submitted time (t).In your calculations, consider that a submission sent at minute t was sent and judged exactly t minutes and 0 seconds after the beginning of the contest.No team made more than one submission in a given minute and no team submitted an answer for a problem they have already solved. ## Output Output a single integer, the total amount of time in minutes during which Marge's university's team was leading the scoreboard. [samples] ## Note In the first example, BOB was leading the scoreboard between minutes 0 and 1 and between minutes 180 and 185.In the second example, BOB was leading the scoreboard between minutes 0 and 300, but lost the leadership at the last moment.
**Definitions** Let $ N \in \mathbb{Z} $ be the number of teams, $ M \in \mathbb{Z} $ the number of submissions, $ P \in \mathbb{Z} $ the number of problems. Let $ T = \{t_1, t_2, \dots, t_N\} $ be the set of team names, with $ t_1 $ being Marge’s team. Let $ S = \{(t_i, p_j, \tau, r) \mid i \in \{1,\dots,N\}, j \in \{1,\dots,P\}, \tau \in \{1,\dots,300\}, r \in \{\text{OK}, \text{NO}\}\} $ be the sequence of $ M $ submissions, ordered by non-decreasing $ \tau $. For each team $ t_i $, define: - $ s_i \in \mathbb{Z}_{\geq 0} $: number of solved problems. - $ w_i \in \mathbb{Z}_{\geq 0} $: total penalty time, computed as: $$ w_i = \sum_{\substack{\text{problem } p \\ \text{successfully solved}}} \left( \tau_{\text{OK}}^{(p)} + 20 \cdot r_{\text{NO}}^{(p)} \right) $$ where $ r_{\text{NO}}^{(p)} $ is the number of rejected submissions for problem $ p $ before the first OK. Let $ L(\tau) \subseteq T $ be the set of teams leading at time $ \tau \in [0, 300] $, i.e., those maximizing $ (s_i, -w_i) $ lexicographically. **Constraints** 1. $ 2 \leq N \leq 200 $, $ 1 \leq M \leq 10^4 $, $ 8 \leq P \leq 14 $ 2. All submission times $ \tau \in [1, 300] $, non-decreasing. 3. No team submits twice for the same problem after solving it. 4. No two submissions occur at the same minute for the same team. **Objective** Compute the total measure (in minutes) of the set: $$ \left\{ \tau \in [0, 300] \mid t_1 \in L(\tau) \right\} $$ where $ L(\tau) $ is constant between consecutive submission times (and at $ \tau = 0 $). The value is the sum of lengths of all intervals $ [\tau_k, \tau_{k+1}) $ (and $ [\tau_M, 300] $) during which Marge’s team is among the leaders.
API Response (JSON)
{
  "problem": {
    "name": "C. Leading the Scoreboard",
    "description": {
      "content": "Marge is the newest member of GEMA, a programming competition study group at her university. One of the first things she did as a new member was to look at the last year's regionals scoreboard to see ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10148C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Marge is the newest member of GEMA, a programming competition study group at her university. One of the first things she did as a new member was to look at the last year's regionals scoreboard to see ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z} $ be the number of teams, $ M \\in \\mathbb{Z} $ the number of submissions, $ P \\in \\mathbb{Z} $ the number of problems.  \nLet $ T = \\{t_1, t_2, \\dots, t_N\\} $ b...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments