A10745 | Vladik and flights
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows $n$ airports. All the airports are located on a straight line. Each airport has unique id from $1$ to $n$ , Vladik's house is situated next to the airport with id $a$ , and the place of the olympiad is situated next to the airport with id $b$ . It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport $a$ and finish it at the airport $b$ .
Each airport belongs to one of two companies. The cost of flight from the airport $i$ to the airport $j$ is zero if both airports belong to the same company, and $|i-j|$ if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
Vladik knows $n$ airports. All the airports are located on a straight line. Each airport has unique id from $1$ to $n$ , Vladik's house is situated next to the airport with id $a$ , and the place of the olympiad is situated next to the airport with id $b$ . It is possible that Vladik's house and the place of the olympiad are located near the same airport.
To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport $a$ and finish it at the airport $b$ .
Each airport belongs to one of two companies. The cost of flight from the airport $i$ to the airport $j$ is zero if both airports belong to the same company, and $|i-j|$ if they belong to different companies.
Print the minimum cost Vladik has to pay to get to the olympiad.
输入格式
The first line contains three integers $n$ , $a$ , and $b$ ( $1<=n<=10^{5}$ , $1<=a,b<=n$ ) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length $n$ , which consists only of characters $0$ and $1$ . If the $i$ -th character in this string is $0$ , then $i$ -th airport belongs to first company, otherwise it belongs to the second.
The second line contains a string with length $n$ , which consists only of characters $0$ and $1$ . If the $i$ -th character in this string is $0$ , then $i$ -th airport belongs to first company, otherwise it belongs to the second.
输出格式
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
输入输出样例
输入 #1
4 1 4 1010
输出 #1
1
输入 #2
5 5 2 10110
输出 #2
0
In the first example Vladik can fly to the airport $2$ at first and pay $|1-2|=1$ (because the airports belong to different companies), and then fly from the airport $2$ to the airport $4$ for free (because the airports belong to the same company). So the cost of the whole flight is equal to $1$ . It's impossible to get to the olympiad for free, so the answer is equal to $1$ .
In the second example Vladik can fly directly from the airport $5$ to the airport $2$ , because they belong to the same company.
In the second example Vladik can fly directly from the airport $5$ to the airport $2$ , because they belong to the same company.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted