Logo
(追記) (追記ここまで)

12674번 - Painting a Fence (Large) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 512 MB135375.000%

문제

You need to hire some people to paint a fence. The fence is composed of 10000 contiguous sections, numbered from 1 to 10000.

You get some offers from painters to help paint the fence. Each painter offers to paint a contiguous subset of fence sections in a particular color. You need to accept a set of the offers, such that:

  • Each section of the fence is painted.
  • At most 3 colors are used to paint the fence.

If it is possible to satisfy these two requirements, find the minimum number of offers that you must accept.

입력

  • One line containing an integer T, the number of test cases in the input file.

For each test case, there will be:

  • One line containing an integer N, the number of offers.
  • N lines, one for each offer, each containing "C A B" where C is the color, which is an uppercase string of up to 10 letters, A is the first section and B is the last section to be painted. 1 ≤ AB ≤ 10000.

Limits

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 300

출력

  • T lines, one for each test case in the order they occur in the input file, each containing the string "Case #X: Y", where X is the case number, and Y is the number of offers that need to be accepted, or "Case #X: IMPOSSIBLE" if there is no acceptable set of offers.

제한

예제 입력 1

5
2
BLUE 1 5000
RED 5001 10000
3
BLUE 1 6000
RED 2000 8000
WHITE 7000 10000
4
BLUE 1 3000
RED 2000 5000
ORANGE 4000 8000
GREEN 7000 10000
2
BLUE 1 4000
RED 4002 10000
3
BLUE 1 6000
RED 4000 10000
ORANGE 3000 8000

예제 출력 1

Case #1: 2
Case #2: 3
Case #3: IMPOSSIBLE
Case #4: IMPOSSIBLE
Case #5: 2

힌트

In the first test case, accepting both offers will exactly paint the whole fence, 5000 sections each, with no overlap.

In the second case, the painters will overlap, which is acceptable.

In the third case, accepting all four offers would cover the whole fence, but it would use 4 different colours, so this is not acceptable.

In the fourth case, section 4001 cannot be painted.

In the fifth case, we can accept just the first and second offer and successfully paint the fence.

출처

Contest > Google > Code Jam > Google Code Jam 2008 > EMEA Semifinal B2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /