#P10087. [ROIR 2022] 跳跃机器人 (Day 1)

    ID: 10740 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP数学树形数据结构线段树线性数据结构树状数组单调队列2022Special Judge基础算法动态规划优化队列其它技巧ROIR(俄罗斯)

[ROIR 2022] 跳跃机器人 (Day 1)

Background

Translated from ROIR 2022 D1T2

A company is developing a jumping robot. To test the robot, they set up a circular route on a polygonal platform, consisting of nn special platforms numbered from 11 to nn. The distance between platform ii and platform i+1i+1 is did_i, and the distance between the last platform and the first platform is dnd_n (assume that edges with lengths d1,d2,,dnd_1, d_2, \dots, d_n can form an nn-gon)。

The robot is equipped with artificial intelligence and learns to jump farther during testing. At any moment, the robot uses an integer aa to represent its sensitivity. If aa is greater than or equal to did_i, the robot can jump from platform ii to platform i+1i+1; similarly, if aa is greater than or equal to dnd_n, the robot can jump from the last platform to the first platform. After each jump, the robot's sensitivity increases by 11

Problem Description

The robot's developers choose one platform as the starting platform. If the robot can complete nn jumps and return to the original platform, they consider the experiment successful. The developers need to determine the minimum initial sensitivity of the robot, and which platform to choose as the starting platform。

Input Format

The first line contains an integer nn

The second line contains an integer ff

  • If f=1f = 1, then the third line contains nn integers d1,d2,,dnd_1, d_2, \dots, d_n, as described in the Background.
  • If f=2f = 2, then the third line contains an integer mm and three integers x,y,zx, y, z. The fourth line contains mm integers c1,c2,,cmc_1, c_2, \dots, c_m. In this case, the distance values did_i are computed by the following formulas:
    • If 1im1 \le i \le m, then di=cid_i = c_i
    • If m+1inm + 1 \le i \le n, then $d_i = ((x \times d_{i−2} + y \times d_{i−1} + z) \bmod 10^9) + 1$。

Output Format

Output two integers: the minimum allowed initial sensitivity aa and the index of a starting platform where the robot can be placed. If there are multiple starting platforms corresponding to the same minimum initial sensitivity, output any one of them。

5
1
3 7 4 2 5
4 3
10
2
5 1 2 3
1 2 3 4 5
653 1

Hint

Sample explanation:

In the second example, the distance array is [1,2,3,4,5,18,45,112,273,662][1, 2, 3, 4, 5, 18, 45, 112, 273, 662]

Compute the values of d6d_6 to d10d_{10} using the formula:

  • $d_6 = ((1 \cdot d_4 + 2 \cdot d_5 + 3) \bmod 10^9) + 1 = ((1 \cdot 4 + 2 \cdot 5 + 3) \bmod 10^9) + 1 = 18$;
  • $d_7 = ((1 \cdot d_5 + 2 \cdot d_6 + 3) \bmod 10^9) + 1 = ((1 \cdot 5 + 2 \cdot 18 + 3) \bmod 10^9) + 1 = 45$;
  • $d_8 = ((1 \cdot d_6 + 2 \cdot d_7 + 3) \bmod 10^9) + 1 = ((1 \cdot 18 + 2 \cdot 45 + 3) \bmod 10^9) + 1 = 112$;
  • $d_9 = ((1 \cdot d_7 + 2 \cdot d_8 + 3) \bmod 10^9) + 1 = ((1 \cdot 45 + 2 \cdot 112 + 3) \bmod 10^9) + 1 = 273$;
  • $d_{10} = ((1 \cdot d_8 + 2 \cdot d_9 + 3) \bmod 10^9) + 1 = ((1 \cdot 112 + 2 \cdot 273 + 3) \bmod 10^9) + 1 = 662$。

This problem uses bundled testdata。

Subtask Points Special Properties
00 1515 n300,f=1,d300n \le 300, f = 1, d \le 300
11 1717 n5000,f=2n \le 5000, f = 2
22 1010 n100000,f=1n \le 100000, f = 1 and it is guaranteed that starting from the first platform is the best choice
33 2020 n100000,f=1n \le 100000, f = 1
44 55 f=2f = 2 and it is guaranteed that starting from the first platform is the best choice
55 3333 f=2f = 2

For 100%100\% of the data, 3n1073 \le n \le 10^7. When f=1f = 1, 1di1091 \le d_i \le 10^9; when f=2f = 2, 2mmin(n,105)2 \le m \le \min(n, 10^5), 0x,y,z1090 \le x, y, z \le 10^9, and 1ci1091 \le c_i \le 10^9

Note: the algorithm tags of this problem refer to the methods used in the official solution.

Translated by ChatGPT 5