CF920C.Swap Adjacent Elements

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have an array aa consisting of nn integers. Each integer from 11 to nn appears exactly once in this array.

For some indices ii ( 1<=i<=n11<=i<=n-1 ) it is possible to swap ii -th element with (i+1)(i+1) -th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap ii -th element with (i+1)(i+1) -th (if the position is not forbidden).

Can you make this array sorted in ascending order performing some sequence of swapping operations?

输入格式

The first line contains one integer nn ( 2<=n<=2000002<=n<=200000 ) — the number of elements in the array.

The second line contains nn integers a1a_{1} , a2a_{2} , ..., ana_{n} ( 1<=ai<=2000001<=a_{i}<=200000 ) — the elements of the array. Each integer from 11 to nn appears exactly once.

The third line contains a string of n1n-1 characters, each character is either 0 or 1. If ii -th character is 1, then you can swap ii -th element with (i+1)(i+1) -th any number of times, otherwise it is forbidden to swap ii -th element with (i+1)(i+1) -th.

输出格式

If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO.

输入输出样例

  • 输入#1

    6
    1 2 5 3 4 6
    01110
    

    输出#1

    YES
    
  • 输入#2

    6
    1 2 5 3 4 6
    01010
    

    输出#2

    NO
    

说明/提示

In the first example you may swap a3a_{3} and a4a_{4} , and then swap a4a_{4} and a5a_{5} .

首页