#P13262. [GCJ 2014 #3] Crime House

    ID: 15128 远端评测题 3000~10000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心2014二分分类讨论Google Code Jam

[GCJ 2014 #3] Crime House

题目描述

While working for the police, you've identified a house where people go to commit crimes, called Crime House. One day, you set up a camera over the door of the house and record a video.

You don't know how many people were in Crime House at the start of the day, but you can see people enter and leave through the front door. Unfortunately, because the people entering and leaving Crime House are criminals, sometimes they wear masks; and you aren't quite sure if the front door is the only way in or out.

Sometimes you can guess who was wearing a mask. If criminal #5 entered the house, then someone wearing a mask left, then criminal #5 entered the house again, then either the person wearing the mask was criminal #5, or there is another way out of Crime House.

At the end of the day, when Crime House has closed its doors for the night, you watch your video. Because you're an optimist, you want to figure out if it's possible that there are no other entrances or exits from crime house; and if so, you want to figure out the minimum number of people who could be in Crime House at the end of the day.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case starts with a line containing a single integer N\mathbf{N}, the number of times people pass through the front door of Crime House in the day. Next follows N\mathbf{N} lines, each of which contains information about one person entering or leaving Crime House through the front door.

That information consists of a single character, E\mathbf{E} or L\mathbf{L}, followed by a space and then an integer id\mathbf{i d}. If the first character is E\mathbf{E}, that indicates someone entered Crime House through the front door; if it's L\mathbf{L}, someone left through the front door. If id\mathbf{i d} is greater than zero, the person with that identifier entered or left Crime House. If id\mathbf{i d} is zero, then the person who entered or left Crime House was wearing a mask, and we don't know who he or she was.

输出格式

For each test case, output one line containing "Case #x: yy", where x\mathrm{x} is the test case number (starting from 1). If it's possible that there are no other entrances or exits from Crime House, then yy should be the minimum number of people who could be in Crime House at the end of the day. If that's impossible, yy should be "CRIME TIME".

5
3
E 5
L 0
E 5
2
L 1
L 1
4
L 1
E 0
E 0
L 1
7
L 2
E 0
E 1
E 2
E 0
E 3
L 4
13
L 4
L 1
L 2
E 0
L 1
E 0
L 2
E 0
L 2
E 0
E 0
L 1
L 4
Case #1: 1
Case #2: CRIME TIME
Case #3: 1
Case #4: 4
Case #5: 0

提示

Limits

  • 1T100.1 \leq \mathbf{T} \leq 100 .
  • 0id2000.0 \leq \text {id} \leq 2000 .

Small dataset(12 Pts)

  • Time limit: 60 3 seconds.
  • 1N15.1 \leq \mathbf{N} \leq 15 .

Large dataset(22 Pts)

  • Time limit: 120 10 seconds.
  • 1N10001 \leq \mathbf{N} \leq 1000