CF2145F.Long Journey
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a strip divided into cells, numbered from 0 to m from left to right. You are controlling a chip that is initially in the cell 0.
There is a trap in each cell; they are activated according to the following rules:
- at the end of moves 1,(1+n),(1+2n),…, traps are activated in cells x where xmoda1=b1;
- at the end of moves 2,(2+n),(2+2n),…, traps are activated in cells x where xmoda2=b2;
- ⋯
- at the end of moves n,(n+n),(n+2n),…, traps are activated in cells x where xmodan=bn.
In one turn, you can either move from the current cell to the next or stay in place. Then all the traps for this turn are activated. If the chip is in a cell with an activated trap at the beginning of the turn, the game ends.
Your task is to calculate the minimum number of turns to reach the cell m, or report that it is impossible. If the chip reaches the cell m and at the end of the same turn, a trap in the cell m activates, it is not considered a valid way to reach the cell m.
有一条被划分为若干格子的长条,格子从左到右编号为 0 到 m。你控制一个初始位于格子 0 的芯片。
每个格子中均设有一个陷阱,其激活规则如下:
- 在第 1, (1+n), (1+2n), … 步结束时,所有满足 xmoda1=b1 的格子 x 中的陷阱被激活;
- 在第 2, (2+n), (2+2n), … 步结束时,所有满足 xmoda2=b2 的格子 x 中的陷阱被激活;
- ⋯
- 在第 n, (n+n), (n+2n), … 步结束时,所有满足 xmodan=bn 的格子 x 中的陷阱被激活。
每一轮中,你可以选择将芯片从当前格子移动至右侧相邻格子,或保持不动。随后,该轮对应的所有陷阱将被激活。若芯片在本轮开始时所处格子中存在已被激活的陷阱,则游戏立即结束。
你的任务是计算到达格子 m 所需的最少轮数;若无法到达,则报告不可能。特别地,若芯片在某轮中抵达格子 m,但该轮结束时格子 m 的陷阱恰好被激活,则此路径不被视为有效到达格子 m 的方式。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains two integers n and m (1≤n≤10; 1≤m≤1012).
The second line contains n integers a1,a2,…,an (2≤ai≤10).
The third line contains n integers b1,b2,…,bn (0≤bi<ai).
第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤n≤10;1≤m≤1012)。
第二行包含 n 个整数 a1,a2,…,an(2≤ai≤10)。
第三行包含 n 个整数 b1,b2,…,bn(0≤bi<ai)。
输出格式
For each test case, print a single integer — the minimum number of turns to reach cell m. If it is impossible, print -1.
对于每个测试用例,输出一个整数——到达单元格 m 所需的最少步数。如果无法到达,则输出 −1。
输入输出样例
输入#1
5 2 5 2 2 0 1 2 5 2 2 1 0 1 7 3 2 4 212398151713 3 2 5 2 0 1 3 0 2 4 3 4 0 0
输出#1
5 6 -1 424796303424 5
输入解题思路,AI测评打分。不知道怎么写?