1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef long double real_t;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

constexpr int N = 1 << 18;

int n, v0, v1, v2, v3;
real_t t0, t1, t2, t3;

real_t T = 0.0;
int pos = 0;
char a[3][N];
int last_car = 0;
real_t eps = 1e-9;

bool equals(real_t x, real_t y) {
	return (abs(x - y) < eps);
}

int next_car(int p) {
	for (int i = p; i < n; ++i) {
		if (a[0][i] == '#')
			return i;
	}
	
	return N; // TODO: ZMIENIĆ STAŁĄ
}

int block(int p) {
	int res = 0;
	while (a[0][p - res] == '#') {
		++res;
	}
	
	return res;
}

real_t overtake1(int l) {
	real_t mv = T * (v1 - v2);
	
	if (equals(mv, round(mv))) {
		int asked = pos - (int)round(mv);
		
		if (asked >= n) {
			return t0 * (real_t)l;
		}
		
		if (asked <= 0) {
			int nxt = next_car(0);
			real_t meet = (real_t)(nxt - asked) / (real_t)(v0 - v1);
			real_t required = t0 * (real_t)l;
			
			if (required <= meet)
				return required;
			
			return meet + ((required - meet) * (real_t)v0 / (real_t)v1);
		}

		int blk = block(asked);
		
		if (blk == 0) {
			int nxt = next_car(asked);
			real_t meet = (real_t)(nxt - asked) / (real_t)(v0 - v1);
			real_t required = t0 * (real_t)l;
			
			if (required <= meet)
				return required;
			
			return meet + ((required - meet) * (real_t)v0 / (real_t)v1);
		}
		
		return (real_t)blk / (real_t)(v1 - v2) + (real_t)l * t1;
	}
	
//////////////////////////////////////////////////////////////////////////////////
	
	int asked = pos - (int)ceil(mv); // asked oraz asked + 1
	real_t dif = ceil(mv) - mv;
	
	if (asked >= n) {
		return t0 * (real_t)l;
	}
	
	if (asked < 0) {
		int nxt = next_car(0);
		real_t meet = ((real_t)(nxt - asked) - dif) / (real_t)(v0 - v1);
		real_t required = t0 * (real_t)l;
		
		if (required <= meet)
			return required;
		
		return meet + ((required - meet) * (real_t)v0 / (real_t)v1);
	}
	
	if (a[0][asked] == '|' && a[0][asked + 1] == '|') {
		int nxt = next_car(asked);
		real_t meet = (real_t)(nxt - asked) / (real_t)(v0 - v1);
		real_t required = t0 * (real_t)l;
		
		if (required <= meet)
			return required;
		
		return meet + ((required - meet) * (real_t)v0 / (real_t)v1);
	}
	
	real_t wait = dif / (real_t)(v1 - v2);
	
	int blk = block(asked);
	
	if (blk == 0) {
		int nxt = next_car(asked);
		real_t meet = (real_t)(nxt - asked) / (real_t)(v0 - v1);
		real_t required = t0 * (real_t)l;
		
		if (required <= meet)
			return wait + required;
		
		return wait + meet + ((required - meet) * (real_t)v0 / (real_t)v1);
	}
	
	return wait + ((real_t)blk / (real_t)(v1 - v2)) + ((real_t)l * t1);
}

// chcemy szukać takich samochodów które są conajmniej na pozycji x
// i mają przed sobą conajmniej y miejsca wolnego przed sobą
// gdzie x to jest takie miejsce że nasz samochód dociera tam 
// natychmiast po wyprzedzeniu środkowych samochodów
// NAJPIERW ODSTĘP POTEM POZYCJA

set<pair<real_t, real_t>> brum;
real_t last_slow; // ma być pozycją wolnego miejsca za najdalszym samochodem !!!

real_t overtake3(int l) {
	real_t curr = (real_t)pos + T * (v2 - v3);
	
	real_t overtake_time = (real_t)l / (real_t)(v0 - v2);
	real_t free_space = overtake_time * (v0 - v3) + 1.0;
	real_t closest_opponent = curr + free_space;
	
	auto opponent = brum.lower_bound(mp(free_space, closest_opponent));
	
	while (opponent != brum.end() && opponent->ss < closest_opponent) {
		brum.erase(opponent);
		opponent = brum.lower_bound(mp(free_space, closest_opponent));
	}
	
	real_t beg, wait = 0.0;
	
	if (opponent != brum.end()) {
		beg = opponent->ss - opponent->ff;
		wait = max(0.0l, beg - curr) * (real_t)(v2 - v3);
	}
	else {
		wait = max(0.0l, last_slow - curr) * (real_t)(v2 - v3);
	}
	
	return wait + overtake_time;
}

real_t last_fast;

int main() {
	cerr << setprecision(10);
	
	scanf("%d%d%d%d%d", &n, &v0, &v1, &v2, &v3);
	t0 = 1.0 / (real_t)v0;
	t1 = 1.0 / (real_t)v1;
	t2 = 1.0 / (real_t)v2;
	t3 = 1.0 / (real_t)v3;
	
	scanf(" %s", a[0]);
	scanf(" %s", a[1]);
	scanf(" %s", a[2]);
	a[2][0] = '.';
	
	if (a[1][n - 1] == '#') {
		a[0][n] = '.';
		a[1][n] = '.';
		a[2][n] = '.';
		++n;
	}
	
	last_slow = -1.0l;
	last_car = -1.0l;
	last_fast = -1.0l;
	
	for (int i = 0; i < n; ++i) {
		if (a[1][i] == '#')
			last_car = i;
			
		if (a[0][i] == '#')
			last_fast = i;
			
		if (a[2][i] == '#') {
			if (last_slow == -1.0l) {
				brum.insert(mp(1e9l, (real_t)i));
			}
			else {
				brum.insert(mp((real_t)i - last_slow, (real_t)i));
			}
			last_slow = (real_t)i + 1.0l;
		}
		
	}	
	
	while (pos <= last_car) {
		while (a[1][pos + 1] == '.') {
			++pos;
			T += t0;
		}
		
		// l to długość kolumny razem z Karolem
		int l = 1;
		
		while (a[1][pos + l] == '#') {
			++l;
		}
		
		real_t overtake_time = min(overtake1(l), overtake3(l));
		
		//cerr << "moment: " << T << " pozycja: " << pos << " do wyprzedzenia: " << l << endl;
		//cerr << "wyprzedzanie wolne: " << overtake1(l) << endl;
		//cerr << "wyprzedzanie szybkie: " << overtake3(l) << endl;
		//cerr << "wybrałem: " << overtake_time << endl;
		
		T += overtake_time;
		pos += l;	
	}
	
	real_t mv = T * (v1 - v2);
	real_t wait1 = max(0.0l, last_fast - ((real_t)pos - mv)) / (v0 - v1);
	mv = T * (v2 - v3);
	real_t wait3 = max(0.0l, last_slow - ((real_t)pos + mv)) / (v0 - v3);
	T += max(wait1, wait3);
	
	cout << setprecision(10) << T << endl;
	
	return 0;
}