CF1272E.Nearest Opposite Parity
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i−ai (if 1≤i−ai) or to the position i+ai (if i+ai≤n).
For each position i from 1 to n you want to know the minimum the number of moves required to reach any position j such that aj has the opposite parity from ai (i.e. if ai is odd then aj has to be even and vice versa).
给你一个包含 n 个整数的数组 a。在一次移动中,你可以从位置 i 跳转到位置 i−ai(若 1≤i−ai)或跳转到位置 i+ai(若 i+ai≤n)。
对于每个从 1 到 n 的位置 i,你需要求出到达任意位置 j 所需的最少移动次数,使得 aj 与 ai 的奇偶性相反(即:若 ai 为奇数,则 aj 必须为偶数;反之亦然)。
输入格式
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤n), where ai is the i-th element of a.
输入的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组 a 的元素个数。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n),其中 ai 是数组 a 的第 i 个元素。
输出格式
Print n integers d1,d2,…,dn, where di is the minimum the number of moves required to reach any position j such that aj has the opposite parity from ai (i.e. if ai is odd then aj has to be even and vice versa) or -1 if it is impossible to reach such a position.
输出 n 个整数 d1,d2,…,dn,其中 di 表示到达任意位置 j 所需的最少移动次数,使得 aj 与 ai 的奇偶性相反(即:若 ai 为奇数,则 aj 必须为偶数;反之亦然);若无法到达满足条件的位置,则 di=−1。
输入输出样例
输入#1
10 4 5 7 6 7 5 4 4 6 4
输出#1
1 1 1 2 -1 1 1 3 1 1
输入解题思路,AI测评打分。不知道怎么写?