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
245
246
247
248
249
250
251
252
253
254
255
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#include <limits.h>

using namespace std;

typedef long long LL;
typedef long double LD;

typedef vector<int> VI;
typedef pair<int,int> PII;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(VAR(i,a);i<=(b);++i)
#define FORD(i,a,b) for(VAR(i,a);i>=(b);--i)
#define FORE(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define VAR(a,b) __typeof(b) a=(b)
#define SIZE(a) ((int)((a).size()))
#define ALL(x) (x).begin(),(x).end()
#define CLR(x,a) memset(x,a,sizeof(x))
#define ZERO(x) memset(x,0,sizeof(x))
#define S(t,i) scanf("%" ## t, &i)
#define SI(i) scanf("%d", &i)

const int INF=INT_MAX-400000;
const int MAXL=200000+5;
const long double EPS=0.0000000001;

int L, v[4];
long double result;

struct Slot {
    int x;
    int l;
    long double vt=INF;
    long double vx=INF;
    bool visited=false;
};

Slot lane[3][MAXL/2];
int laneLength[3];

struct SlotCoordinate {
    int lane;
    int slot;
    long double t;
    long double x;
};

inline bool comparePossitionsWithinSlot(long double t1, long double x1, long double t2, long double x2) {
    long double diff = t1 + (x2-x1)/v[3] - t2;
    return abs(diff) < EPS ? t1 < t2 : diff < 0;
//    long double diff = t1 - t2;
//    return abs(diff) < EPS ? x1<x2 : t1 < t2;
}
auto compareSlots = [](const SlotCoordinate &b, const SlotCoordinate &a) {
//    return abs(a.t-b.t) <EPS ? a.x>b.x : a.t<b.t;
    return comparePossitionsWithinSlot(a.t, a.x, b.t, b.x);
};
priority_queue<SlotCoordinate, std::vector<SlotCoordinate>, decltype(compareSlots)> q(compareSlots);

long double getIntersectionTime(long double ta, long double xa, long double va, long double xs, long double vs) {
    return max(ta, ((xs-xa)+ta*va)/(va-vs));
}

int getFirstSlotInLane(int targetLaneId, long double x0) {
    Slot *targetLane = &lane[targetLaneId][0];
    int l=-1;
    int r=laneLength[targetLaneId];
    while (l+1<r) {
        int k=(l+r)/2;
        Slot &s = targetLane[k];
        if (s.visited || (x0 - (s.x+(long double)s.l-1) > EPS)) {
            l=k;
        } else {
            r=k;
        }
    }
    return l+1;
//    int firstSlotInLane = (int) (lower_bound(&targetLane[0], &targetLane[laneLength[targetLaneId]], x0, [](Slot &s, long double value){
//        return s.visited || s.x+(long double)s.l-1 - value < EPS;
//    }) - targetLane);
//    return firstSlotInLane;
}

inline void addToQueue(long double intersetionTime, long double intersetionX, int targetLaneId, int targetSlotId) {
    Slot &targetSlot = lane[targetLaneId][targetSlotId];
    
    if (comparePossitionsWithinSlot(intersetionTime, intersetionX, targetSlot.vt, targetSlot.vx)) {

        targetSlot.vt =intersetionTime;
        targetSlot.vx =intersetionX;

        SlotCoordinate new_sc;
        new_sc.lane = targetLaneId;
        new_sc.slot = targetSlotId;
        new_sc.t = intersetionTime;
        new_sc.x = intersetionX;
        q.push(new_sc);
//        printf("a %d %d %.10Lf %.10Lf\n", new_sc.lane, new_sc.slot, new_sc.t, new_sc.x);
        
//        assert(targetSlot.x+intersetionTime*v[targetLaneId] <= intersetionX+EPS);
//        assert(targetSlot.x+(long double)targetSlot.l-1+intersetionTime*v[targetLaneId] >= intersetionX-EPS);
//        return true;
    }
//    return false;
}

long double findmaxval (long double num1, long double num2){
    return num1 > num2 ? num1 : num2;
}


int main() {
    ios_base::sync_with_stdio(0);
    
    SI(L);
    
    SI(v[3]);
    REP(i, 3) {
        SI(v[i]);
    }
    FOR(i, 0, 2) {
        char c, prevc;
        scanf(" ");
        fread(&c, 1, sizeof(char), stdin);
        c='.';
        laneLength[i]=1;
        lane[i][0].l=1;
        lane[i][0].x=0;
        lane[i][0].vt=INF;
        lane[i][0].vx=INF;
        FOR(x, 1, L-1) {
            prevc=c;
            fread(&c, 1, sizeof(char), stdin);
            if (c=='.') {
                if (prevc == '.') {
                    Slot &s = lane[i][laneLength[i]-1];
                    s.l++;
                } else {
                    laneLength[i]++;
                    Slot &s = lane[i][laneLength[i]-1];
                    s.x = x;
                    s.l = 1;
                    s.vt=INF;
                    s.vx=INF;
                }
            }
        }
        if  (c=='#') {
            laneLength[i]++;
            Slot &s = lane[i][laneLength[i]-1];
            s.x = L;
            s.l = INF;
        } else {
            Slot &s = lane[i][laneLength[i]-1];
            s.l = INF;
        }
    }
    
    SlotCoordinate new_sc;
    new_sc.lane = 2;
    new_sc.slot = 0;
    new_sc.t = 0;
    new_sc.x = 0;
    lane[2][0].vt = 0;
    lane[2][0].vx = 0;
    q.push(new_sc);
    while (!q.empty()) {
        SlotCoordinate sc = q.top();
        q.pop();
        Slot &s = lane[sc.lane][sc.slot];
        if (!s.visited) {
//            printf("v %d %d %.10Lf %.10Lf\n", sc.lane, sc.slot, s.vt, s.vx);
            
            s.visited = true;
            int currentLaneId = sc.lane;
            if (sc.lane < 2) {
                int targetLaneId = sc.lane+1;
                Slot *targetLane = &lane[targetLaneId][0];
                long double x0 = s.vx - v[sc.lane]*s.vt;
                
                
                int firstSlotInLane = getFirstSlotInLane(targetLaneId, s.vx - v[targetLaneId]*s.vt);
                
                FORD(targetSlotId, laneLength[targetLaneId]-1, firstSlotInLane) {
                    long double intersetionTime = getIntersectionTime(s.vt, s.vx, v[3], targetLane[targetSlotId].x, v[targetLaneId]);
                    long double maxFullSpeedTime = (s.x + (long double)s.l-1 - x0)/(v[3]-v[currentLaneId]);
                    long double intersetionX;
                    if (maxFullSpeedTime + EPS >= intersetionTime - s.vt) {
                        intersetionX = s.vx+(intersetionTime - s.vt)*v[3];
                    } else {
                        long double timeAtTheEndOdSlot = maxFullSpeedTime + s.vt;
                        long double positionAtTheEndOdSlot = s.vx + maxFullSpeedTime*v[3];
                        intersetionTime = getIntersectionTime(timeAtTheEndOdSlot, positionAtTheEndOdSlot, v[currentLaneId], targetLane[targetSlotId].x, v[targetLaneId]);
                        intersetionX = positionAtTheEndOdSlot+(intersetionTime - timeAtTheEndOdSlot)*v[currentLaneId];
                    }
                    addToQueue(intersetionTime, intersetionX, targetLaneId, targetSlotId);
//                    if (!qaddresult) {
//                        break;
//                    }
                    
                }
            }
            if (sc.lane > 0) {
                int targetLaneId = sc.lane-1;
                Slot *targetLane = &lane[targetLaneId][0];
                long double x0 = s.vx - v[sc.lane]*s.vt;

//                int firstSlotInLane = getFirstSlotInLane(targetLaneId, x0);
                int firstSlotInLane = getFirstSlotInLane(targetLaneId, s.vx - v[targetLaneId]*s.vt);
                long double maxFullSpeedTime = (s.x + (long double)s.l-1 - x0)/(v[3]-v[currentLaneId]);
                int lastSlotInLane = max(firstSlotInLane, getFirstSlotInLane(targetLaneId, s.vx+v[3]*maxFullSpeedTime - v[targetLaneId]*(s.vt+maxFullSpeedTime))-1);

                FOR(targetSlotId, lastSlotInLane, laneLength[targetLaneId]-1) {
                    long double intersetionTime = getIntersectionTime(s.vt, s.vx, v[3], targetLane[targetSlotId].x, v[targetLaneId]);
//                    long double maxFullSpeedTime = ((long double)s.l-1 + v[currentLaneId]*s.vt - s.vx)/(v[3]-v[currentLaneId]);
                    long double maxFullSpeedTime = (s.x + (long double)s.l-1 - x0)/(v[3]-v[currentLaneId]);
                    long double intersetionX;
                    if (maxFullSpeedTime + EPS >= intersetionTime - s.vt) {
                        intersetionX = s.vx+(intersetionTime - s.vt)*v[3];
                    } else {
                        break;
                    }
                    addToQueue(intersetionTime, intersetionX, targetLaneId, targetSlotId);
                }
                
                                if (firstSlotInLane > 0) {
                    int targetSlotId = firstSlotInLane-1;
                    if (targetLane[targetSlotId].visited == false) {
//                        long double intersetionTime = getIntersectionTime(s.vt, s.vx, v[currentLaneId], targetLane[targetSlotId].x, v[targetLaneId]);
                        long double intersetionTime = getIntersectionTime(s.vt, targetLane[targetSlotId].x+targetLane[targetSlotId].l-1 + s.vt*v[targetLaneId], v[targetLaneId], s.vx - s.vt*v[currentLaneId], v[currentLaneId]);
                        long double intersetionX = s.vx+(intersetionTime - s.vt)*v[currentLaneId];
                        addToQueue(intersetionTime, intersetionX, targetLaneId, targetSlotId);
                    }
                }
            }
        }
    }
    
    result = findmaxval(findmaxval(lane[0][laneLength[0]-1].vt, lane[1][laneLength[1]-1].vt), lane[2][laneLength[2]-1].vt);
    
    printf("%.12Lf\n", result);
    
    return 0;
}