#P8317. [FOI2021] 幸运区间

    ID: 9182 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索2021福建枚举分治深度优先搜索 DFS剪枝

[FOI2021] 幸运区间

Background

Fujian Province Youth Informatics Programming Level Certification 2021, Problem 4.

Problem Description

A lottery event is taking place. Each participant receives nn sequences. Each sequence contains dd positive integers, and there is also a number kk, meaning that among these positive integers, there exist kk lucky numbers.

Each participant chooses several consecutive sequences from their own sequences to form an interval, called a candidate interval. If every sequence in the candidate interval contains at least one lucky number, then this interval is called a lucky interval. Of course, there may be more than one lucky interval. The rules say that the lucky interval containing the most sequences (i.e., with the greatest total length) is called the super lucky interval.

For example, when d=2,k=3d=2,k=3, the sequences are:

  • Sequence 00: 115 120.
  • Sequence 11: 50 80.
  • Sequence 22: 199 30.
  • Sequence 33: 40 40.
  • Sequence 44: 30 30.
  • Sequence 55: 25 40.

The interval from sequence 00 to sequence 22 is a lucky interval, because each sequence from 00 to 22 contains 120120, 5050, or 3030, for a total of 33 lucky numbers. The interval from sequence 11 to sequence 55 is also a lucky interval, because all sequences from 11 to 55 contain 8080, 3030, or 4040, and it contains 55 sequences, so it is the super lucky interval with the greatest total length.

Each participant wants to know what their super lucky interval is. The programming task is: for each participant, output the index of the first element and the index of the last element of the super lucky interval with the greatest total length. If there are multiple intervals with the same maximum length, output the one with the smallest first index. Note that indices start from 00.

Input Format

The first line contains an integer TT, representing the number of participants who received sequences.

Then follow TT groups of data, each describing one participant’s sequence information.

The first line of each group contains three positive integers n,d,kn,d,k, as described above. The next line contains n×dn\times d integers: the first dd integers represent sequence 00, the next dd represent sequence 11, and so on.

Output Format

For each participant, output one line: Case #x: y z, where xx is the case\text{case} number (starting from 11), and yy and zz are the indices of the first and last elements of the answer interval.

(There is one space between Case and #; there is no space between # and x; there is one space after : before y; there is one space between y and z.)

4
8 1 2
1 2 3 2 4 5 4 6
4 3 2
1 2 3 4 5 6 7 8 9 10 11 12
6 2 3
10 20 50 60 70 30 40 40 30 30 20 40
10 1 3
2 4 3 1 4 5 3 1 1 2
Case #1: 1 3
Case #2: 0 1
Case #3: 1 5
Case #4: 1 4

Hint

Constraints

For 45%45\% of the testdata, n1000n\le1000.

For 50%50\% of the testdata, k=2k=2.

The first two parts together account for 70%70\%.

For 100%100\% of the testdata, 2k32\le k\le 3.

The input file is within 4.8M\text{4.8M}, T=10,1d4,1T=10,1\le d\le 4,1\le each number in each sequence 105\le10^5.

For at most 66 case\text{case}, 1n1051\le n\le 10^5; for all other case\text{case}, 1n1031\le n\le 10^3.

Translated by ChatGPT 5