#P15588. [KTSC 2026] 飞扬的松鼠 2 / Flying Squirrel 2

    ID: 17538 远端评测题 5000ms 2048MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>交互题2026KTSC(韩国)

[KTSC 2026] 飞扬的松鼠 2 / Flying Squirrel 2

Problem Description

On a 2D plane, there is a flying squirrel and NN pillars.

We represent a point on the 2D plane as (x,y)(x,y), where the xx-coordinate represents the offset to the right, and the yy-coordinate represents the offset upward.

The pillars are numbered 0∼N−10 \sim N-1 in order. The bottom of pillar ii is at (i,0)(i,0), and its height is infinite. In other words, pillar ii is a ray starting from (i,0)(i,0) and pointing upward. Each pillar is either red or blue. If B[i]=0B[i]=0, pillar ii is red; otherwise if B[i]=1B[i]=1, pillar ii is blue.

In the region outside the pillars, the squirrel flies horizontally to the right, keeping its current height unchanged. Since the squirrel is very agile, the time spent flying to the right is considered 00.

When the squirrel is at a pillar, it can increase its height by 11, or do nothing. More precisely, at pillar ii, the squirrel must perform exactly one of the following operations:

  • Pass through the pillar. The squirrel’s height does not change, and it continues flying to the right. The time cost is 00.
  • Climb up the pillar. This operation can be performed if and only if the pillar is red (B[i]=0B[i]=0). The squirrel’s height increases by 11, then it continues flying to the right. The time cost is A[i]A[i].
  • Jump up the pillar. This operation can be performed if and only if the pillar is blue (B[i]=1B[i]=1). The squirrel’s height increases by 11, then it continues flying to the right. The time cost is A[i]A[i].

In addition, when the squirrel’s xx-coordinate is i+0.5i+0.5 (0≤i≤N−10\le i\le N-1), its height must be within [L[i],R[i]][L[i],R[i]]. When the squirrel’s xx-coordinate is NN, its height must be HH.

Let T[k]T[k] be the minimum time needed for the squirrel to reach (N,H)(N,H) while satisfying all the conditions above and using exactly kk “Jump up” operations. If no such plan exists, let T[k]=−1T[k]=-1.

Compute T[0],T[1],⋯ ,T[H]T[0],T[1],\cdots,T[H].

Implementation Details

This is a functional interactive problem. You do not need to, and should not, implement the main function.

You should implement the following function:

vector<long long> fly(int H, vector<int> A, vector<int> B, vector<int> L, vector<int> R)
  • HH: the squirrel’s final height.
  • A,B,L,RA,B,L,R: integer arrays of length NN.
  • BB: the array describing pillar colors. If B[i]=0B[i]=0, pillar ii is red; otherwise if B[i]=1B[i]=1, pillar ii is blue.
  • This function must return an array TT of length (H+1)(H+1).
  • This function is called exactly once.

Your source code should not call any input/output functions.

Input Format

The input format of the sample grader is as follows:

  • Line 11: NN HH
  • Line 22: A[0]A[0] A[1]A[1] …\ldots A[N−1]A[N - 1]
  • Line 33: B[0]B[0] B[1]B[1] …\ldots B[N−1]B[N - 1]
  • Line 44: L[0]L[0] L[1]L[1] …\ldots L[N−1]L[N - 1]
  • Line 55: R[0]R[0] R[1]R[1] …\ldots R[N−1]R[N - 1]

Output Format

The sample grader prints the answer in the following format:

  • Line 11: T[0]T[0] T[1]T[1] …\ldots T[H]T[H]
4 3
8 8 2 4
1 0 1 0
1 0 2 3
1 2 2 4

-1 20 14 -1

1 1
1000000000
0
1
1

1000000000 -1

7 3
4 7 0 3 8 4 5
0 0 0 0 0 0 0
0 0 0 1 0 1 2
5 1 2 5 5 6 3

7 -1 -1 -1

20 7
3 3 4 1 3 2 0 1 4 3 4 0 0 1 0 4 4 5 5 0
1 1 0 0 1 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1
0 0 1 1 2 1 2 2 1 1 0 1 1 3 2 2 1 6 4 4
3 2 3 3 6 2 2 4 3 4 4 5 3 6 6 5 7 8 8 9

-1 16 11 10 9 10 12 15

Hint

Constraints

  • 1≤N≤200 0001\le N\le 200\, 000;
  • 0≤H≤N0\le H\le N;
  • 0≤A[i]≤1090\le A[i]\le 10^9;
  • 0≤B[i]≤10\le B[i]\le 1;
  • 0≤L[i]≤R[i]≤N0\le L[i]\le R[i] \le N。

Subtasks

ID Score Constraint
11 3 3 N≤300N\le 300
22 4 4 A[i]=B[i]=0A[i]=B[i]=0
33 2525 B[i]=0B[i]=0
44 2020 N≤65 000,A[i]≤5N\le 65\, 000, A[i]\le 5
55 2929 N≤65 000N\le 65\, 000
66 1919 No additional constraints.

Samples

Sample 11

Consider the following call.

fly(3, [8, 8, 2, 4],
    [1, 0, 1, 0],
    [1, 0, 2, 3],
    [1, 2, 2, 4])

::::align{center} ::::

If the squirrel jumps up pillar 00 and climbs up pillars 11 and 33, then the conditions are satisfied. In this case, the number of “Jump up” operations is 11, and the time cost is 2020 seconds.

::::align{center} ::::

If the squirrel jumps up pillars 00 and 22 and climbs up pillar 33, then the conditions are satisfied. In this case, the number of “Jump up” operations is 22, and the time cost is 1414 seconds.

There are no other possible ways. Therefore, the function should return [−1-1, 2020, 1414, −1-1].

Sample 22

Consider the following call.

fly(1, [1000000000],
    [0],
    [1],
    [1])

The function should return [1000000000,−1][1000000000, -1].

Sample 33

Consider the following call.

fly(3, [4, 7, 0, 3, 8, 4, 5],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 1, 0, 1, 2],
    [5, 1, 2, 5, 5, 6, 3])

The function should return [7,−1,−1,−1][7, -1, -1, -1].

Sample 44

Consider the following call.

fly(7, [3, 3, 4, 1, 3, 2, 0, 1, 4, 3, 4, 0, 0, 1, 0, 4, 4, 5, 5, 0],
    [1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1],
    [0, 0, 1, 1, 2, 1, 2, 2, 1, 1, 0, 1, 1, 3, 2, 2, 1, 6, 4, 4],
    [3, 2, 3, 3, 6, 2, 2, 4, 3, 4, 4, 5, 3, 6, 6, 5, 7, 8, 8, 9])

The function should return [−1,16,11,10,9,10,12,15][-1, 16, 11, 10, 9, 10, 12, 15]。

Translated by ChatGPT 5