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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
const ld INF=1e9+7, M=0.0000000001;
ld V[4], odl[3][LIM], jeden=1;
string T[3];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, lst[3];
	cin >> n; ++n;
	rep(i, 4) cin >> V[i];
	rep(i, 3) {
		lst[i]=-1;
		cin >> T[i];
		T[i]+=".";
		rep(j, n) if(T[i][j]=='#') lst[i]=j;
	}
	rep(i, 3) rep(j, n) odl[i][j]=INF;
	priority_queue<pair<ld,pair<int,int>>>q;
	q.push({-0, {2, 0}});
	ld ans=INF;
	while(!q.empty()) {
		ld o=-q.top().st;
		int a=q.top().nd.st, b=q.top().nd.nd;
		q.pop();
		if(odl[a][b]<=o) continue;
		odl[a][b]=o;
		if(b>lst[a]) {
			ld p=0;
			rep(i, 3) {
				ld x=b+1, y=lst[i]+2;
				x+=o*V[a+1];
				y+=o*V[i+1];
				if(x-M<=y) p=max(p, (y-x)/(V[0]-V[i+1]));
			}
			ans=min(ans, p+o);
		}
		if(b<n-1 && T[a][b+1]=='.') {
			q.push({-o-jeden/(V[0]-V[a+1]), {a, b+1}});
		}
		if(a) {
			rep(i, n) if(T[a-1][i]=='.') {
				ld x=b+1, y=i+1;
				x+=o*V[a+1];
				y+=o*V[a];
				if(x+M<y) {
					if((!i || T[a-1][i-1]=='.') && x>=y-1-M ||
							(i<n-1 && T[a][b+1]=='.' && jeden/(V[0]-V[a+1])>=(y-x)/(V[0]-V[a])-M)) {
						q.push({-o-(y-x)/(V[0]-V[a]), {a-1, i}});	
					} else continue;
				} else {
					q.push({-o-(x-y)/(V[a]-V[a+1]), {a-1, i}});
				}
			}
		}
		if(a<2) {
			rep(i, n) if(T[a+1][i]=='.') {
				ld x=b+1, y=i+1;
				x+=o*V[a+1];
				y+=o*V[a+2];
				if(x>y+M) continue;
				if(((!i || T[a+1][i-1]=='.') && x>=y-1-M) || 
						(i<n-1 && T[a][b+1]=='.' && jeden/(V[0]-V[a+1])>=(y-x)/(V[0]-V[a+2])-M)) {
					q.push({-o-(y-x)/(V[0]-V[a+2]), {a+1, i}});
				} else {
					q.push({-o-(y-x)/(V[a+1]-V[a+2]), {a+1, i}});
				}
			}
			ld x=b+1, y=lst[a+1]+2;
			x+=o*V[a+1];
			y+=o*V[a+2];
			if(x>=y-M) {
				ld p=0;
				rep(i, 3) {
					ld y=lst[i]+2;
					y+=o*V[i+1];
					if(x-M<=y) p=max(p, (y-x)/(V[0]-V[i+1]));
				}
				ans=min(ans, p+o);
			}
		}
	}
	cout << fixed << setprecision(10) << ans << '\n';
}