您的位置:首页 > 其它

codeforces 743 A Vladik and flights(水题)

2016-12-15 13:54 309 查看
A. Vladik and flights

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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.

Input

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.

Output

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

Examples

input
4 1 4
1010


output
1


input
5 5 2
10110


output
0


Note

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.

题解:如果是在同一个公司的机场那是0,否则,肯定有2个机场是相邻且属于不同公司的,在那边变就可以了。

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
const int maxn = 1e5+5;
char s[maxn];
int n,a,b;
int main(){
#ifdef HandsomeHow
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
#endif
gn(n);gn(a);gn(b);
scanf("%s",s+1);
int ans;
if(s[a] == s[b]) ans = 0;
else ans = 1;
cout<<ans<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: