CF743A.Vladik and flights
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
弗拉迪克是一名竞赛程序员。今年他将赢得国际信息学奥林匹克竞赛(IOI)。但这件事并没有听起来那么简单:弗拉迪克当前面临的问题是找出前往奥赛的最便宜路径。
弗拉迪克知道有 n 个机场。所有机场都位于一条直线上。每个机场拥有一个从 1 到 n 的唯一编号;弗拉迪克的家位于编号为 a 的机场旁,而奥赛举办地则位于编号为 b 的机场旁。弗拉迪克的家与奥赛举办地有可能位于同一个机场旁。
为了抵达奥赛举办地,弗拉迪克可以在任意两个机场之间飞行任意多次,但他必须从机场 a 出发,并在机场 b 结束行程。
每个机场隶属于两家公司之一。从机场 i 飞往机场 j 的费用为:若两座机场属于同一家公司,则费用为 0;若属于不同公司,则费用为 ∣i−j∣。
请输出弗拉迪克抵达奥赛所需支付的最小费用。
输入格式
The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 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.
第一行包含三个整数 n、a 和 b(1 ≤ n ≤ 105,1 ≤ a, b ≤ n)—— 分别表示机场的数量、Vladik 出发的机场编号以及他需要到达的机场编号。
第二行包含一个长度为 n 的字符串,该字符串仅由字符 0 和 1 组成。若该字符串中第 i 个字符为 0,则第 i 个机场属于第一家航空公司;否则(即为 1),它属于第二家航空公司。
输出格式
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
输出一个整数——Vladik 到达奥林匹克竞赛所需的最小花费。
输入输出样例
输入#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.
在第一个例子中,弗拉迪克可以先飞往机场 2,支付费用为 |1 - 2| = 1(因为这两个机场属于不同的公司),然后免费从机场 2 飞往机场 4(因为这两个机场属于同一公司)。因此,整个航程的费用为 1。无法免费抵达奥林匹克竞赛举办地,故答案为 1。
在第二个例子中,弗拉迪克可以直接从机场 5 飞往机场 2,因为它们属于同一公司。
输入解题思路,AI测评打分。不知道怎么写?