Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int x, y, n, xl, yl, out;
- pair <long long, long long> bg, en;
- string s;
- vector <pair <int, int>> wind;
- int main(){
- freopen("in.data", "r", stdin);
- cin >> bg.first >> bg.second >> en.first >> en.second >> n >> s;
- wind.push_back(make_pair(0, 0));
- x = bg.first - en.first;
- y = bg.second - en.second;
- for(int i = 1; i <= n; i++){
- if(s[i-1] == 'U')
- yl++;
- if(s[i-1] == 'D')
- yl--;
- if(s[i-1] == 'R')
- xl++;
- if(s[i-1] == 'L')
- xl--;
- wind.push_back(make_pair(xl, yl));
- //cout << xl << " " << wind[i].first << " " << abs(x + wind[i].first) << " ||||||||| " << abs(y + wind[i].second) << endl;
- if(abs(x + wind[i].first) + abs(y + wind[i].second) <= n){
- cout << n;
- return 0;
- }
- }
- //cout << abs(x + wind[n].first) + abs(y + wind[n].second) << " " << n + abs(y) + abs(x) << endl;
- if(abs(x + wind[n].first) + abs(y + wind[n].second) >= n + abs(y) + abs(x)){
- cout << -1;
- return 0;
- }
- out = (abs(x) + abs(y)) / (abs(x) - abs(x + wind[n].first) + abs(y) - abs(y + wind[n].second)) - 1;
- x+= out*wind[n].first;
- y+= out*wind[n].second;
- for(int i = 1; i <= n; i++){
- if(abs(x + wind[i].first) + abs(y + wind[i].second) <= i + n * out){
- cout << n*out + i;
- return 0;
- }
- }
- //for()
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement