CF1927G.Paint Charges

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A horizontal grid strip of nn cells is given. In the ii-th cell, there is a paint charge of size aia_i. This charge can be:

  • either used to the left — then all cells to the left at a distance less than aia_i (from max⁡(i−ai+1,1)\max(i - a_i + 1, 1) to ii inclusive) will be painted,
  • or used to the right — then all cells to the right at a distance less than aia_i (from ii to min⁡(i+ai−1,n)\min(i + a_i - 1, n) inclusive) will be painted,
  • or not used at all.

Note that a charge can be used no more than once (that is, it cannot be used simultaneously to the left and to the right). It is allowed for a cell to be painted more than once.

What is the minimum number of times a charge needs to be used to paint all the cells of the strip?

给定一个包含 nn 个格子的水平网格条带。在第 ii 个格子中,有一个大小为 aia_i 的颜料电荷。该电荷可以:

  • 向左使用——此时所有距离小于 aia_i 的左侧格子(即从 max⁡(i−ai+1,1)\max(i - a_i + 1, 1) 到 ii(含)的所有格子)将被涂色;
  • 向右使用——此时所有距离小于 aia_i 的右侧格子(即从 ii 到 min⁡(i+ai−1,n)\min(i + a_i - 1, n)(含)的所有格子)将被涂色;
  • 完全不使用。

注意:每个电荷最多只能使用一次(即不能同时向左和向右使用)。允许一个格子被多次涂色。

为使条带中所有格子均被涂色,最少需要使用多少次电荷?

输入格式

The first line of the input contains an integer tt (1≤t≤1001 \le t \le 100) — the number of test cases in the test. This is followed by descriptions of tt test cases.

Each test case is specified by two lines. The first one contains an integer nn (1≤n≤1001 \le n \le 100) — the number of cells in the strip. The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n), where aia_i is the size of the paint charge in the ii-th cell from the left of the strip.

It is guaranteed that the sum of the values of nn in the test does not exceed 10001000.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是 tt 个测试用例的描述。

每个测试用例由两行组成。第一行包含一个整数 nn(1≤n≤1001 \le n \le 100),表示条带中的单元格数量。第二行包含 nn 个正整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n),其中 aia_i 表示条带中从左往右第 ii 个单元格内的颜料容量。

保证所有测试用例中 nn 的总和不超过 10001000。

输出格式

For each test case, output the minimum number of times the charges need to be used to paint all the cells of the strip.

对于每个测试用例,输出将条带的所有单元格涂色所需的最小充能使用次数。

输入输出样例

  • 输入#1

    13
    1
    1
    2
    1 1
    2
    2 1
    2
    1 2
    2
    2 2
    3
    1 1 1
    3
    3 1 2
    3
    1 3 1
    7
    1 2 3 1 2 4 2
    7
    2 1 1 1 2 3 1
    10
    2 2 5 1 6 1 8 2 8 2
    6
    2 1 2 1 1 2
    6
    1 1 4 1 3 2

    输出#1

    1
    2
    1
    1
    1
    3
    1
    2
    3
    4
    2
    3
    3

说明/提示

In the third test case of the example, it is sufficient to use the charge from the 11-st cell to the right, then it will cover both cells 11 and 22.

In the ninth test case of the example, you need to:

  • use the charge from the 33-rd cell to the left, covering cells from the 11-st to the 33-rd;
  • use the charge from the 55-th cell to the left, covering cells from the 44-th to the 55-th;
  • use the charge from the 77-th cell to the left, covering cells from the 66-th to the 77-th.

In the eleventh test case of the example, you need to:

  • use the charge from the 55-th cell to the right, covering cells from the 55-th to the 1010-th;
  • use the charge from the 77-th cell to the left, covering cells from the 11-st to the 77-th.

在示例的第三个测试用例中,只需使用第 11 个单元格向右释放的电荷,即可覆盖第 11 和第 22 个单元格。

在示例的第九个测试用例中,你需要:

  • 使用第 33 个单元格向左释放的电荷,覆盖第 11 至第 33 个单元格;
  • 使用第 55 个单元格向左释放的电荷,覆盖第 44 至第 55 个单元格;
  • 使用第 77 个单元格向左释放的电荷,覆盖第 66 至第 77 个单元格。

在示例的第十一个测试用例中,你需要:

  • 使用第 55 个单元格向右释放的电荷,覆盖第 55 至第 1010 个单元格;
  • 使用第 77 个单元格向左释放的电荷,覆盖第 11 至第 77 个单元格。

输入解题思路,AI测评打分。不知道怎么写?

首页