#include <bits/stdc++.h> #define MP make_pair #define PB push_back #define int long long #define st first #define nd second #define rd third #define FOR(i, a, b) for(int i =(a); i <=(b); ++i) #define RE(i, n) FOR(i, 1, n) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define REP(i, n) for(int i = 0;i <(n); ++i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define __builtin_ctz __builtin_ctzll #define __builtin_clz __builtin_clzll #define __builtin_popcount __builtin_popcountll using namespace std; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define cerr if(0)cout #endif #define next ____next #define prev ____prev #define left ____left #define hash ____hash typedef long long ll; typedef long double LD; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<pair<int, int> > VPII; typedef vector<pair<ll, ll> > VPLL; template<class C> void mini(C&a4, C b4){a4=min(a4, b4); } template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); } template<class T1, class T2> ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";} template<class A, class B, class C> struct Triple { A first; B second; C third; bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } }; template<class T> void ResizeVec(T&, vector<int>) {} template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) { vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; } for (T& v : vec) { ResizeVec(v, sz); } } typedef Triple<int, int, int> TIII; template<class A, class B, class C> ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; } template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } const int N = 3e5 + 6; const int kInf = 1e18; char road[4][N]; int dp[N]; int32_t main() { ios_base::sync_with_stdio(0); cout << fixed << setprecision(15); cerr << fixed << setprecision(10); cin.tie(0); //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC; int L, v0, v1, v2, v3; cin>>L>>v0>>v1>>v2>>v3; VI last(4); VI last_free1(L + 2); VVI fir_taken(4, VI(L + 3)); RE (t, 3) { road[t][0] = '.'; RE (i, L) { cin>>road[t][i]; if (t == 3 && i == 1) { road[3][1] = '.'; } if (road[t][i] == '#') { last[t] = i; } if (t == 1) { if (road[t][i] == '.') { last_free1[i] = i; } else { last_free1[i] = last_free1[i - 1]; } } } } RE (t, 3) { fir_taken[t][L + 2] = kInf; FORD (i, L + 1, 1) { if (road[t][i] == '#') { fir_taken[t][i] = i; } else { fir_taken[t][i] = fir_taken[t][i + 1]; } } } int M = (v0 - v2) * (v1 - v2) * (v0 - v1) * (v0 - v3) * (v2 - v3); // skalujemy droge przez M RE (i, L + 1) { dp[i] = 1e18; } VPII stos; vector<VPII> ops(L + 2); stos.PB({kInf, last[3] + 1}); int prv = last[3]; for (int j = last[3] - 1; j >= 1; j--) { if (road[3][j] == '#') { int przerwa = prv - j - 1; //debug(przerwa); if (przerwa >= 2) { while (stos.back().st <= przerwa) { ops[j].PB(stos.back()); stos.pop_back(); } ops[j].PB({-1, -1}); stos.PB({przerwa, j + 1}); } prv = j; } } //debug(stos); set<PII> active_przerwy(ALL(stos)); int finger = 0; //debug(active_przerwy); dp[1] = 0; for (int i = 1; i <= last[2]; ) { int j = i + 1; while (road[2][j] == '#') { j++; } if (j == i + 1) { dp[j] = dp[i] + M / (v0 - v2); //debug(j, dp[j] * 1. / M); i = j; continue; } int p, l, r; #ifndef WYWALDOL // jade dolem int t = (j - i) * M / (v0 - v2); int need_space = t * (v0 - v3) + M; p = i * M + dp[i] * (v2 - v3); l = p / M; r = (p + M - 1) / M; //debug(l, r); mini(l, L + 1); mini(r, L + 1); if (road[3][r] == '.' && road[3][l] == '.') { int g = fir_taken[3][r]; if (g == kInf || g * M - p >= need_space) { dp[j] = dp[i] + t; } r = min(g, L + 1); } int need_free_cells = (need_space + M - 1) / M; //debug(need_free_cells); while (finger <= l - 1) { auto& v = ops[finger]; while (SZ(v)) { if (v.back().st == -1) { active_przerwy.erase(active_przerwy.begin()); } else { active_przerwy.insert(v.back()); } v.pop_back(); } finger++; } //debug(active_przerwy); { int a = active_przerwy.lower_bound({need_free_cells, -1})->nd; //debug("waiting for", a, "to come to ", i); //debug(dp[i], (a - i) * M / (v2 - v3)); //debug( mini(dp[j], max(dp[i], (a - i) * M / (v2 - v3)) + t); } #endif #ifndef WYWALGORA // jade gora p = max(0ll, i * M - dp[i] * (v1 - v2)); l = p / M; r = (p + M - 1) / M; if (road[1][r] == '#' || road[1][l] == '#') { // musze poczekac az sie zrobi miejsce na gorze int a = last_free1[l]; mini(dp[j], (j - a) * M / (v1 - v2)); } else { // moge od razu przejechac na gore int a = min(fir_taken[1][r] - 1, j); int na_ogonie = (j - a) * M / (v1 - v2); int prosto = dp[i] + (j - i) * M / (v0 - v2); mini(dp[j], max(prosto, na_ogonie)); } #endif //debug(j, dp[j] * 1. / M); i = j; } //debug(last[2], dp[last[2] + 1]); int my_back = (last[2] + 1) * M; #ifndef WYWALGORA int wh_front_last_1 = (last[1] + 1) * M + dp[last[2] + 1] * (v1 - v2); assert((wh_front_last_1 - my_back) % (v0 - v1) == 0); int t1 = dp[last[2] + 1] + max(0ll, wh_front_last_1 - my_back) / (v0 - v1); #else int t1 = 0; #endif #ifndef WYWALDOL int wh_front_last_3 = (last[3] + 1) * M + dp[last[2] + 1] * (v3 - v2); assert((wh_front_last_3 - my_back) % (v0 - v3) == 0); //debug(dp[last[2] + 1] + max(0ll, wh_front_last_3 - my_back) * 1. / (v0 - v3) / M); int t2 = dp[last[2] + 1] + max(0ll, wh_front_last_3 - my_back) / (v0 - v3); #else int t2 = 0; #endif cout<<max(t1, t2) * (LD)1. / M<<endl; return 0; }
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 | #include <bits/stdc++.h> #define MP make_pair #define PB push_back #define int long long #define st first #define nd second #define rd third #define FOR(i, a, b) for(int i =(a); i <=(b); ++i) #define RE(i, n) FOR(i, 1, n) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define REP(i, n) for(int i = 0;i <(n); ++i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define __builtin_ctz __builtin_ctzll #define __builtin_clz __builtin_clzll #define __builtin_popcount __builtin_popcountll using namespace std; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define cerr if(0)cout #endif #define next ____next #define prev ____prev #define left ____left #define hash ____hash typedef long long ll; typedef long double LD; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<pair<int, int> > VPII; typedef vector<pair<ll, ll> > VPLL; template<class C> void mini(C&a4, C b4){a4=min(a4, b4); } template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); } template<class T1, class T2> ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";} template<class A, class B, class C> struct Triple { A first; B second; C third; bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } }; template<class T> void ResizeVec(T&, vector<int>) {} template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) { vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; } for (T& v : vec) { ResizeVec(v, sz); } } typedef Triple<int, int, int> TIII; template<class A, class B, class C> ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; } template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } const int N = 3e5 + 6; const int kInf = 1e18; char road[4][N]; int dp[N]; int32_t main() { ios_base::sync_with_stdio(0); cout << fixed << setprecision(15); cerr << fixed << setprecision(10); cin.tie(0); //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC; int L, v0, v1, v2, v3; cin>>L>>v0>>v1>>v2>>v3; VI last(4); VI last_free1(L + 2); VVI fir_taken(4, VI(L + 3)); RE (t, 3) { road[t][0] = '.'; RE (i, L) { cin>>road[t][i]; if (t == 3 && i == 1) { road[3][1] = '.'; } if (road[t][i] == '#') { last[t] = i; } if (t == 1) { if (road[t][i] == '.') { last_free1[i] = i; } else { last_free1[i] = last_free1[i - 1]; } } } } RE (t, 3) { fir_taken[t][L + 2] = kInf; FORD (i, L + 1, 1) { if (road[t][i] == '#') { fir_taken[t][i] = i; } else { fir_taken[t][i] = fir_taken[t][i + 1]; } } } int M = (v0 - v2) * (v1 - v2) * (v0 - v1) * (v0 - v3) * (v2 - v3); // skalujemy droge przez M RE (i, L + 1) { dp[i] = 1e18; } VPII stos; vector<VPII> ops(L + 2); stos.PB({kInf, last[3] + 1}); int prv = last[3]; for (int j = last[3] - 1; j >= 1; j--) { if (road[3][j] == '#') { int przerwa = prv - j - 1; //debug(przerwa); if (przerwa >= 2) { while (stos.back().st <= przerwa) { ops[j].PB(stos.back()); stos.pop_back(); } ops[j].PB({-1, -1}); stos.PB({przerwa, j + 1}); } prv = j; } } //debug(stos); set<PII> active_przerwy(ALL(stos)); int finger = 0; //debug(active_przerwy); dp[1] = 0; for (int i = 1; i <= last[2]; ) { int j = i + 1; while (road[2][j] == '#') { j++; } if (j == i + 1) { dp[j] = dp[i] + M / (v0 - v2); //debug(j, dp[j] * 1. / M); i = j; continue; } int p, l, r; #ifndef WYWALDOL // jade dolem int t = (j - i) * M / (v0 - v2); int need_space = t * (v0 - v3) + M; p = i * M + dp[i] * (v2 - v3); l = p / M; r = (p + M - 1) / M; //debug(l, r); mini(l, L + 1); mini(r, L + 1); if (road[3][r] == '.' && road[3][l] == '.') { int g = fir_taken[3][r]; if (g == kInf || g * M - p >= need_space) { dp[j] = dp[i] + t; } r = min(g, L + 1); } int need_free_cells = (need_space + M - 1) / M; //debug(need_free_cells); while (finger <= l - 1) { auto& v = ops[finger]; while (SZ(v)) { if (v.back().st == -1) { active_przerwy.erase(active_przerwy.begin()); } else { active_przerwy.insert(v.back()); } v.pop_back(); } finger++; } //debug(active_przerwy); { int a = active_przerwy.lower_bound({need_free_cells, -1})->nd; //debug("waiting for", a, "to come to ", i); //debug(dp[i], (a - i) * M / (v2 - v3)); //debug( mini(dp[j], max(dp[i], (a - i) * M / (v2 - v3)) + t); } #endif #ifndef WYWALGORA // jade gora p = max(0ll, i * M - dp[i] * (v1 - v2)); l = p / M; r = (p + M - 1) / M; if (road[1][r] == '#' || road[1][l] == '#') { // musze poczekac az sie zrobi miejsce na gorze int a = last_free1[l]; mini(dp[j], (j - a) * M / (v1 - v2)); } else { // moge od razu przejechac na gore int a = min(fir_taken[1][r] - 1, j); int na_ogonie = (j - a) * M / (v1 - v2); int prosto = dp[i] + (j - i) * M / (v0 - v2); mini(dp[j], max(prosto, na_ogonie)); } #endif //debug(j, dp[j] * 1. / M); i = j; } //debug(last[2], dp[last[2] + 1]); int my_back = (last[2] + 1) * M; #ifndef WYWALGORA int wh_front_last_1 = (last[1] + 1) * M + dp[last[2] + 1] * (v1 - v2); assert((wh_front_last_1 - my_back) % (v0 - v1) == 0); int t1 = dp[last[2] + 1] + max(0ll, wh_front_last_1 - my_back) / (v0 - v1); #else int t1 = 0; #endif #ifndef WYWALDOL int wh_front_last_3 = (last[3] + 1) * M + dp[last[2] + 1] * (v3 - v2); assert((wh_front_last_3 - my_back) % (v0 - v3) == 0); //debug(dp[last[2] + 1] + max(0ll, wh_front_last_3 - my_back) * 1. / (v0 - v3) / M); int t2 = dp[last[2] + 1] + max(0ll, wh_front_last_3 - my_back) / (v0 - v3); #else int t2 = 0; #endif cout<<max(t1, t2) * (LD)1. / M<<endl; return 0; } |