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

14318번 - Watson and Intervals (Small) 다국어

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

문제

Sherlock and Watson have mastered the intricacies of the language C++ in their programming course, so they have moved on to algorithmic problems. In today's class, the tutor introduced the problem of merging one-dimensional intervals. N intervals are given, and the ith interval is defined by the inclusive endpoints [Li, Ri], where Li ≤ Ri.

The tutor defined the covered area of a set of intervals as the number of integers appearing in at least one of the intervals. (Formally, an integer p contributes to the covered area if there is some j such that Ljp ≤ Rj.)

Now, Watson always likes to challenge Sherlock. He has asked Sherlock to remove exactly one interval such that the covered area of the remaining intervals is minimized. Help Sherlock find this minimum possible covered area, after removing exactly one of the N intervals.

입력

Each test case consists of one line with eight integers N, L1, R1, A, B, C1, C2, and M. N is the number of intervals, and the other seven values are parameters that you should use to generate the other intervals, as follows:

First define x1 = L1 and y1 = R1. Then, use the recurrences below to generate xi, yi for i = 2 to N:

  • xi = ( A*xi-1 + B*yi-1 + C1 ) modulo M.
  • yi = ( A*yi-1 + B*xi-1 + C2 ) modulo M.

We define Li = min(xi, yi) and Ri = max(xi, yi), for all i = 2 to N.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum possible covered area of all of the intervals remaining after removing exactly one interval.

제한

  • 1 ≤ T ≤ 50.
  • 0 ≤ L1 ≤ R1 ≤ 109.
  • 0 ≤ A ≤ 109.
  • 0 ≤ B ≤ 109.
  • 0 ≤ C1 ≤ 109.
  • 0 ≤ C2 ≤ 109.
  • 1 ≤ M ≤ 109.
  • 1 ≤ N ≤ 1000.

예제 입력 1

3
1 1 1 1 1 1 1 1
3 2 5 1 2 3 4 10
4 3 4 3 3 8 10 10

예제 출력 1

Case #1: 0
Case #2: 4
Case #3: 9

힌트

In case 1, using the generation method, the set of intervals generated are: {[1, 1]}. Removing the only interval, the covered area is 0.

In case 2, using the generation method, the set of intervals generated are: {[2, 5], [3, 5], [4, 7]}. Removing the first, second or third interval would cause the covered area of remaining intervals to be 5, 6 and 4, respectively.

In case 3, using the generation method, the set of intervals generated are: {[3, 4], [1, 9], [0, 8], [2, 4]}. Removing the first, second, third or fourth interval would cause the covered area of remaining intervals to be 10, 9, 9 and 10, respectively.

출처

Contest > Google > Google's Coding Competitions > Google APAC 2017 University Test > Round B APAC Test 2017 C1번

Contest > Google > Kick Start > Google Kick Start 2016 > Round B C1번

채점 및 기타 정보

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

출처

대학교 대회

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

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