CF28B.pSort
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = d__i, where d__i is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited.
The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state.
某天,某个数组的 n 个单元格决定玩一个游戏。初始时,每个单元格中存放的数等于其序号(从 1 开始)。此外,每个单元格还确定了它最喜欢的数。在第 i 个单元格进行操作时,它可以将其当前值与另一个第 j 个单元格的值交换,当且仅当 ∣i−j∣=di,其中 di 是第 i 个单元格最喜欢的数。单元格可以以任意顺序进行操作,操作次数不限。
你将获得每个单元格最喜欢的数。同时,你还会获得一个 1 到 n 的排列。你需要判断:游戏是否可能达到该状态?
输入格式
The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.
第一行包含一个正整数 n(1≤n≤100)—— 数组中的单元格数量。
第二行包含 n 个互不相同的、取值范围为 1 到 n 的整数——一个排列。
最后一行包含 n 个取值范围为 1 到 n 的整数——各单元格的喜好数字。
输出格式
If the given state is reachable in the described game, output YES, otherwise NO.
如果给定的状态在所述游戏中可达,则输出 YES,否则输出 NO。
输入输出样例
输入#1
5 5 4 3 2 1 1 1 1 1 1
输出#1
YES
输入#2
7 4 3 5 1 2 7 6 4 6 6 1 6 6 1
输出#2
NO
输入#3
7 4 2 5 1 3 7 6 4 6 6 1 6 6 1
输出#3
YES
输入解题思路,AI测评打分。不知道怎么写?