Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- PROG : milk2
- LANG : C++
- */
- #include<bits/stdc++.h>
- typedef long long ll;
- typedef long double ld;
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define FOR(i, a, b) for(int i = (a);i < (b);i++)
- #define pb push_back
- #define mp make_pair
- #define mod 1000000007
- #define fi first
- #define se second
- #define sqr(a) ((a) * (a))
- #define pi 3.1415926535897932
- #define read ifstream in("input.txt")
- #define write ofstream out("output.txt")
- #define vii vector<int>
- #define mii map<int, int>
- using namespace std;
- int n, m, k;
- int x[1005], a[1005], b[1005];
- bool was[1005];
- void go(int pos, int step, int A, int B){
- if (pos >= n || pos < 0 || !x[pos] || was[pos])
- return;
- was[pos] = 1;
- if (step == 4)
- a[pos] = abs(pos - A) / 4;
- else
- b[pos] = abs(pos - B) / 7;
- go(pos + step, step, A, B);
- go(pos - step, step, A, B);
- }
- int main()
- {
- //ifstream in("moocast.in");
- //ofstream out("moocast.out");
- int A, B;
- string s;
- cin >> n >> A >> B;
- cin >> s;
- A--, B--;
- for(int i = 0;i < n;i++){
- x[i] = s[i] - '0';
- a[i] = -1;
- b[i] = -1;
- }
- go(A, 4, A, B);
- memset(was, 0, 1005);
- go(B, 7, A, B);
- int ans = mod;
- for(int i = 0;i < n;i++){
- if (x[i] == 0 || a[i] == - 1 || b[i] == - 1)
- continue;
- //cout << a[i] << " " << b[i] << " " << i << endl;
- ans = min(ans, a[i] + b[i]);
- }
- if (ans == mod)
- ans = - 1;
- cout << ans;
- return 0;
- ///dont forget about initialization array please
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement