Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /*
  2. PROG : milk2
  3. LANG : C++
  4. */
  5. #include<bits/stdc++.h>
  6. typedef long long ll;
  7. typedef long double ld;
  8. #define pii pair<int, int>
  9. #define pll pair<ll, ll>
  10. #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. #define FOR(i, a, b) for(int i = (a);i < (b);i++)
  12. #define pb push_back
  13. #define mp make_pair
  14. #define mod 1000000007
  15. #define fi first
  16. #define se second
  17. #define sqr(a) ((a) * (a))
  18. #define pi 3.1415926535897932
  19. #define read ifstream in("input.txt")
  20. #define write ofstream out("output.txt")
  21. #define vii vector<int>
  22. #define mii map<int, int>
  23.  
  24. using namespace std;
  25.  
  26. int n, m, k;
  27. int x[1005], a[1005], b[1005];
  28. bool was[1005];
  29.  
  30. void go(int pos, int step, int A, int B){
  31. if (pos >= n || pos < 0 || !x[pos] || was[pos])
  32. return;
  33. was[pos] = 1;
  34. if (step == 4)
  35. a[pos] = abs(pos - A) / 4;
  36. else
  37. b[pos] = abs(pos - B) / 7;
  38. go(pos + step, step, A, B);
  39. go(pos - step, step, A, B);
  40. }
  41.  
  42. int main()
  43. {
  44. //ifstream in("moocast.in");
  45. //ofstream out("moocast.out");
  46. int A, B;
  47. string s;
  48. cin >> n >> A >> B;
  49. cin >> s;
  50.  
  51. A--, B--;
  52. for(int i = 0;i < n;i++){
  53. x[i] = s[i] - '0';
  54. a[i] = -1;
  55. b[i] = -1;
  56. }
  57.  
  58. go(A, 4, A, B);
  59. memset(was, 0, 1005);
  60. go(B, 7, A, B);
  61. int ans = mod;
  62. for(int i = 0;i < n;i++){
  63. if (x[i] == 0 || a[i] == - 1 || b[i] == - 1)
  64. continue;
  65. //cout << a[i] << " " << b[i] << " " << i << endl;
  66. ans = min(ans, a[i] + b[i]);
  67. }
  68.  
  69. if (ans == mod)
  70. ans = - 1;
  71. cout << ans;
  72.  
  73. return 0;
  74. ///dont forget about initialization array please
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement