Advertisement
K1R1LL

game

Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<map>
  4. #include<algorithm>
  5. #include<clocale>
  6. #include<cmath>
  7.  
  8. using namespace std;
  9.  
  10. int a[10000001];
  11.  
  12. int main()
  13. {
  14.     int T1 , T2 , S1 , S2 , n , m;
  15.     cin >> n >> m >> S1 >> S2 >> T1 >> T2;
  16.     if(S1 < S2)
  17.         swap(S1 , S2);
  18.     if(T2 < T1)
  19.     {
  20.         T1 = n - T1;
  21.         T2 = n - T2;
  22.     }
  23.     fill(a , a + 10000001, 10000001);
  24.     a[T1] = 0;
  25.    
  26.     int i;
  27.  
  28.     if(T1 + S2 - S1 > 0)
  29.         a[T1 + S2 - S1] = min(a[T1 + S2 - S1] , 2);
  30.     else if(T1 + S2 + S2 - S1 <= n)
  31.         a[T1 + S2 + S2 - S1] = min(a[T1 + S2 + S2 - S1] , 3);
  32.     if(T2 + S1 - S2 > 0)
  33.         a[T1 + S1 - S2] = min(a[T1 + S1 - S2] , 2);
  34.     else if(T1 + S1 + S1 - S2 <= n)
  35.         a[T1 + S1 + S1 - S2] = min(a[T1 + S1 + S1 - S2] , 3);
  36.    
  37.     for(i = 0 ;a[i] == 10000001; i++);
  38.    
  39.     for(i; i < T2; i++)
  40.     {
  41.         if(a[i] < 10000001)
  42.         {
  43.             a[i + S1] = min(a[i + S1] , a[i] + 1);
  44.             a[i + S2] = min(a[i + S2] , a[i] + 1);
  45.         }
  46.     }
  47.     if(a[T2] <= m)
  48.         cout << a[T2];
  49.     else
  50.         cout << -1;
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement