A11479 | Swap Adjacent Elements
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have an array $a$ consisting of $n$ integers. Each integer from $1$ to $n$ appears exactly once in this array.
For some indices $i$ ( $1<=i<=n-1$ ) it is possible to swap $i$ -th element with $(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 $i$ -th element with $(i+1)$ -th (if the position is not forbidden).
Can you make this array sorted in ascending order performing some sequence of swapping operations?
For some indices $i$ ( $1<=i<=n-1$ ) it is possible to swap $i$ -th element with $(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 $i$ -th element with $(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 $n$ ( $2<=n<=200000$ ) — the number of elements in the array.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=200000$ ) — the elements of the array. Each integer from $1$ to $n$ appears exactly once.
The third line contains a string of $n-1$ characters, each character is either 0 or 1. If $i$ -th character is 1, then you can swap $i$ -th element with $(i+1)$ -th any number of times, otherwise it is forbidden to swap $i$ -th element with $(i+1)$ -th.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=200000$ ) — the elements of the array. Each integer from $1$ to $n$ appears exactly once.
The third line contains a string of $n-1$ characters, each character is either 0 or 1. If $i$ -th character is 1, then you can swap $i$ -th element with $(i+1)$ -th any number of times, otherwise it is forbidden to swap $i$ -th element with $(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 $a_{3}$ and $a_{4}$ , and then swap $a_{4}$ and $a_{5}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted