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
// Arti1990, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,K,FUN)             ({auto SSS=P, PPP = P-1, KKK=(K)+1; while(PPP+1!=KKK) {SSS = (PPP+(KKK-PPP)/2); if(FUN(SSS)) KKK = SSS; else PPP = SSS;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1e30d
#define EPS 1e-13d

using namespace std;

int n;
long double koniec[3];
long double v[3], vk;
char slowo[3][300007];

struct samochod
{
    long double pos;
    long double v;
    long double next;
};
samochod s[3];

long long nwd(long long a, long long b)
{
    if(b == 0)
        return a;
    return nwd(b, a%b);
}

long long nww(long long a, long long b)
{
    return a/nwd(a, b)*b;
}

long double przesun(samochod ss, long double t, long double vs, long double vp)
{
    return ss.pos + (vs-vp)*t;
}

bool jest_calkowita(long double d)
{
    return ceil(d-EPS) == floor(d+EPS);
}

long long calkowita(long double d)
{
    return floor(d+EPS);
}

int comp(long double a, long double b)
{
    if(a+EPS < b)
        return 1;
    if(b+EPS < a)
        return -1;
    return 0;
}

long double przelicz_pozycje(long double pos, long double t, int p1, int p2)
{
//    cout <<   "  przeliczenie pozycji " << pos << " w czasie " << t << " z pasa " << p1 << " na pas " << p2 << " to " << pos - t*(v[p2]-v[p1]) << endl;
    return pos - t*(v[p2]-v[p1]);
}

long double ustaw_next(samochod ss, long double t, int p1, int p2)
{
    long double pos = przelicz_pozycje(ss.pos, t, p1, p2);

    if(pos < 0 || pos > n)
        return ss.next;

    if(ss.v > v[p2])
    {
        long double ile = jest_calkowita(pos) ? 1 : ceil(pos) - pos;
        //cout << "ile1: " << ile << ", pos: " << pos << ", calkowita: " << jest_calkowita(pos) << endl;
        return min(ss.next, t + ile/(ss.v-v[p2]));
    }
    else if(ss.v < v[p2])
    {
        long double ile = jest_calkowita(pos) ? 1 : pos - floor(pos);
        //cout << "ile2: " << ile << endl;
        return min(ss.next, t + ile/(v[p2]-ss.v));
    }
    else cout << " ERRRROOOORRRR!!!!!!!!!!!!!!!!!!!!!1" << endl;
    return ss.next;
}

bool wolne(int p, int pos)
{
    if(pos < 1 || pos > n)
        return true;
    return slowo[p][pos] != '#';
}

void wypisz(long double t)
{
    cout << "czas: " << t << endl;
    forr(i, 3)
        cout << "   s[" << i << "] - pos = " << s[i].pos << ", v = " << s[i].v << ", next = " << s[i].next << endl;
}

int solve()
{
    //std::cout << std::numeric_limits<long double>::digits10 << std::endl;
    //cout << sizeof(vk) << endl;
    cout << setprecision(15) << fixed;
    cin >> n >> vk >> v[0] >> v[1] >> v[2];
    forr(i, 3)
    {
        scanf("%s", slowo[i]);
        koniec[i] = n;
        while(koniec[i] > 0 && wolne(i, koniec[i]-1))
            koniec[i]--;
    }

    //vk -= v[2];
    forr(i, 3)
    {
        //v[i] -= v[2];
        s[i].v = vk;
        s[i].pos = 0;
        s[i].next = 0;
    }

    long double t = 0;
    int xx = 200000000;
    bool przesuniecie = 0;
    while(xx-->0)
    {
//        cout << "\n\n\n";

//        cout << "sprawdza czy koniec" << endl;
        bool ok = 1;
        forr(i, 3)
        {
            if(comp(koniec[i], s[i].pos) < 0)
                ok = 0;
        }
        if(ok)
            break;


//        wypisz(t);
//        cout << "przesuwa" << endl;
        long double t2 = przesuniecie ? t2 : min(min(s[0].next, s[1].next), s[2].next);
        przesuniecie = 0;
        forr(i, 3)
        {
            s[i].pos = przesun(s[i], t2-t, s[i].v, v[i]);
        }
//        wypisz(t2);


//        cout << "przestawia na inne pasy" << endl;
        forr(i, 3)
        {
            forr(j, 3)
                if(abs(i-j) == 1)
                {
                    long double pos2 = przelicz_pozycje(s[i].pos, t2, i, j);
                    // jesli jest na rownej pozycji na pasie j
                    if((jest_calkowita(pos2) && wolne(j, calkowita(pos2))) ||
                       (wolne(j, calkowita(pos2)) && wolne(j, calkowita(pos2)+1))) // i wolne po drodze
                    {
                        if(comp(s[j].pos, pos2) == 1)
                        {
//                            cout << " !!!!!!!!!!!!!  przestawia samochod z " << i << " na " << j << "  !!!!!!!!!!!" << endl;
                            przesuniecie = 1;
                            s[j].pos = pos2;
                            s[j].v = vk;
                            s[j].next = t2;
                        }
                    }
                }
        }
//        wypisz(t2);
//        cout << "aktualizuje predkosci" << endl;
        forr(i, 3)
        {
            if(jest_calkowita(s[i].pos))
            {
                if(!wolne(i, calkowita(s[i].pos+1)))
                {
                    s[i].v = v[i];
                    s[i].next = INF;
                }
                else
                {
                    s[i].v = vk;
                    s[i].next = t2 + 1/(vk-v[i]);
                }
            }
            else
            {
                s[i].v = vk;
                s[i].next = t2 + (ceil(s[i].pos) - s[i].pos)/(vk-v[i]);
            }
        }
//        wypisz(t2);
//        cout << "aktualizuje next" << endl;
        forr(i, 3)
        {
            forr(j, 3)
                if(i != j)
                {
                    s[i].next = ustaw_next(s[i], t2, i, j);
//                    cout << "   po poprawce next od " << i << " do " << j << " to " << s[i].next << endl;
                }
        }
//        wypisz(t2);
        t = t2;
    }

    cout << t << endl;









    return 0;
}

int main()
{
    solve();

    return 0;
}