Problem:
どうぶつの盛り2013
Sim Forest 2013というゲームがある。このゲームでは、プレイヤーは森の神様となって森林の動物を育成することができる。
動物は卵から孵化し、繁殖する。卵は特定の条件を満たすと、一定の確率で突然変異し新しい種族の動物が生まれる。
このゲームには動物事典というものが存在し、新しい種類の動物を入手すると動物辞典に記録されていく。
盛さんは Sim Forest 2013の熱狂的なプレイヤーである。彼の動物辞典は残り1種族を埋めると完成となる。
盛さんはこの残りの1種族を、卵からの突然変異により入手することにした。
ゲーム進行は以下のとおりである。
ステージ開始時に n個 の卵が出現する。
ステージ開始から s分後 に n個 の卵が孵化する。
各卵は、
*出現してから孵化するまで*
のすべての期間で（出現時と孵化する瞬間も含む）、特定の曜日かつ特定の時間帯内であればそれぞれ 1/p の確率で目的の動物に突然変異する。
ステージ開始から t分後 にステージが終了し、その直後にまた同じステージが開始する(n個の卵がある状態で開始する。経過時間はリセットされない。)
ステージは連続で m回 繰り返される。
このゲームは、以下の仕様を満たしている。
卵から生まれた動物が卵を生むことは無い。
卵が孵化するタイミングは、1回のステージにつきステージ開始からs分後の1回のみである。
盛さんは、最初のステージの開始曜日・開始時刻を任意に設定できる。(二番目以降のステージの開始時刻は、直前のステージの終了直後となる)
突然変異可能な曜日として、{全ての曜日, 日曜, 月曜, 火曜, 水曜, 木曜, 金曜, 土曜} のいずれかが与えられる。
突然変異可能な時間帯として、{全ての時間帯, 朝, 夜} のいずれかが与えられる。
入力として s, n, t, 突然変異可能な曜日・時間帯, p, m が与えられる。
全ステージ終了までに突然変異が起こる確率が最大になるように最初のステージの開始曜日・開始時刻を設定したときの、その確率をもとめよ。
Input
入力は複数のデータセットからなる。各データセットは以下の形式で与えられる。
s
n
t
weekday
time
p
m
各データセットは、ステージ開始から卵が孵化するのにかかる時間 s, ステージ開始時に出現する卵の数 n, 1つのステージが終了するまでにかかる時間 t,
突然変異可能な曜日 weekday, 突然変異可能な時間帯 time, 突然変異する確率の逆数 p (突然変異する確率は 1 / p である), 全ステージ数 m を含む。
入力は以下の制約を満たす。
0 < s <= 500
0 < n <= 100
s < t <= 1000
weekday ∈ {All, Sun, Mon, Tue, Wed, Thu, Fri, Sat}
All は、全ての曜日を意味する
time ∈ {All, Day, Night}
All は [0:00~24:00), Day は [6:00~18:00), Night は [18:00~6:00) の時間帯を意味する。
1 <= p <= 99999
1 <= m <= 100
入力の終わりは以下の行で与えられる。
0
0
0
None
None
0
0
Output
各データセットごとに、全ステージ終了までに突然変異が起こる確率が最大になるように最初のステージの開始曜日・開始時刻を設定したときの、その確率を出力せよ。
解答の誤差は 0.00000001 (10
-8
) を超えてはならない．精度に関する条件を満たしていれば，小数点以下は何桁数字を出力しても構わない。
Sample Input
1 1 3 All All 1 1
2 37 5 All Night 150 1
16 2 20 All Day 5 10
1 14 15 Mon All 20000 100
0 0 0 None None 0 0
Output for Sample Input
1.0000000000
0.2192439716
0.9884707850
0.0649933899

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

void solve() {
    const vector<string> DOW_STR = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    const int CHUNK_MINS = 6 * 60;

    int s, n, t, p, m;
    string weekday_str, time_str;

    while (cin >> s >> n >> t >> weekday_str >> time_str >> p >> m && (s || n || t || p || m)) {

        vector<int> valid_chunks(28, 0);

        for (int i = 0; i < 7; ++i) {
            if (weekday_str == "All" || weekday_str == DOW_STR[i]) {
                for (int j = 0; j < 4; ++j) {
                    valid_chunks[i * 4 + j] = 1;
                }
            }
        }

        for (int i = 0; i < 28; ++i) {
            if (valid_chunks[i] == 0) continue;

            int block_of_day = i % 4;
            bool time_ok = false;
            if (time_str == "All") {
                time_ok = true;
            } else if (time_str == "Day") {
                time_ok = (block_of_day == 1 || block_of_day == 2);
            } else if (time_str == "Night") {
                time_ok = (block_of_day == 0 || block_of_day == 3);
            }

            if (time_ok) {
                valid_chunks[i] = 2;
            }
        }

        int max_valid_stages = 0;
        const int MINS_IN_WEEK = 7 * 24 * 60;

        for (int start_min = 0; start_min < MINS_IN_WEEK; ++start_min) {
            int current_valid_stages = 0;
            for (int i = 0; i < m; ++i) {
                long long stage_start_abs = start_min + (long long)i * t;

                int start_chunk = stage_start_abs / CHUNK_MINS;
                int end_chunk = (stage_start_abs + s) / CHUNK_MINS;

                bool is_stage_ok = true;
                for (int k = start_chunk; k <= end_chunk; ++k) {
                    if (valid_chunks[k % 28] != 2) {
                        is_stage_ok = false;
                        break;
                    }
                }

                if (is_stage_ok) {
                    current_valid_stages++;
                }
            }
            max_valid_stages = max(max_valid_stages, current_valid_stages);
        }

        long long total_trials = (long long)n * max_valid_stages;

        if (total_trials == 0 || p <= 1) {
            printf("%.10f\n", (p==1 && total_trials > 0) ? 1.0 : 0.0);
        } else {
            long double fail_prob = 1.0L - (1.0L / p);
            long double result = 1.0L - pow(fail_prob, total_trials);
            printf("%.10Lf\n", result);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3712
final_rank: 12

code_snippet: //#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i=0;i<(ll)n;i++)
#define rrep(i,n) for (ll i=n-1;i>=(ll)0;i--)
#define loop(i,m,n) for(ll i=m;i<=(ll)n;i++)
#define rloop(i,m,n) for(ll i=m;i>=(ll)n;i--)
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vdbg(a) rep(ii,a.size()){cout<<a[ii]<<" ";}cout<<endl;
#define vvdbg(a) rep(ii,a.size()){rep(jj,a[ii].size()){cout<<a[ii][jj]<<" ";}cout<<endl;}
#define setdbg(a) for(const auto & ii:a){cout<<ii<<" ";}cout<<endl;
#define inf 4000000000000000000LL
#define mod 998244353LL
#define eps 0.000000001

//#define mod 1000000007LL
random_device rnd;// 非決定的な乱数生成器
mt19937 mt(rnd());// メルセンヌ・ツイスタの32ビット版、引数は初期シード

ll solve(){
	ll s,n,t,p,m;
	string weekday,time;
	cin>>s>>n>>t>>weekday>>time>>p>>m;
	if(s==0){return 1;}

	double ans=0;
	
	rep(i,7*24*60){
		ll cnt=0;

		//i分ずらした所から、m回開始
		rep(j,m){
			ll start=i+j*t;
			ll end=i+j*t+s;
			if(weekday=="All"){
				if(time=="All"){
					cnt++;
				}else{
					if(end-start<12*60&&start%(24*60)<12*60&&end%(24*60)<12*60)cnt++;
				}
			}else{
				if(time=="All"){
					if(end-start<24*60&&start%(7*24*60)<24*60&&end%(7*24*60)<24*60)cnt++;
				}else{
					if(time=="Day"){
						if(end-start<12*60&&start%(7*24*60)<12*60&&end%(7*24*60)<12*60)cnt++;
					}else{
						if(end-start<6*60&&start%(7*24*60)<6*60&&end%(7*24*60)<6*60)cnt++;
						else if(end-start<6*60&&18*60<=start%(7*24*60)&&start%(7*24*60)<24*60&&18*60<=end%(7*24*60)&&end%(7*24*60)<24*60)cnt++;
					}
				}
			}
		}
		
		//1回に変化しない確率
		double kakuritu=(double)(p-1)/p;
		double tmp=1;
		rep(j,cnt)tmp*=kakuritu;
		double tmp2=1;
		rep(j,n)tmp2*=tmp;
		ans=max(ans,1-tmp2);
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
	return 0;
}

//メイン
int main(){
	while(solve()==0);
	return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3840
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
using PP = pair<int, P>;
using PLL = pair<ll, ll>;
using PPLL = pair<ll, PLL>;
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rrep(i, n) for(ll i = n - 1; i >= 0; --i)
#define loop(i, a, b) for(ll i = a; i <= b; ++i)
#define all(v) v.begin(), v.end()
#define nC2(n) n * (n - 1) / 2
constexpr ll INF = 9009009009009009009LL;
constexpr int INF32 = 2002002002;
constexpr ll MOD = 998244353;
constexpr ll MOD107 = 1000000007;

// Linear Algebra ////////////////////////////////////////////////
const double Rad2Deg = 180.0 / M_PI;
const double Deg2Rad = M_PI / 180.0;
//////////////////////////////////////////////////////////////////

int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

template <class T>
inline bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename Container,
          typename = std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              std::is_convertible_v<decltype(std::declval<Container>().begin()),
                                    typename Container::iterator>>>
ostream &operator<<(ostream &os, const Container &container) {
    auto it = container.begin();
    auto end = container.end();

    if (it != end) {
        os << *it;
        ++it;
    }
	for (; it != end; ++it) {
		os << " " << *it;
	}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1) os << " ";
    }
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {
	for (size_t i = 0; i < vv.size(); ++i) {
		os << vv[i];
		if (i != vv.size() - 1) os << "\n";
    }
    return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	assert(v.size() > 0);
	for (size_t i = 0; i < v.size(); ++i) is >> v[i];
	return is;
}
template <typename T>
istream& operator>>(istream& is, vector<vector<T>>& vv) {
	assert(vv.size() > 0);
	for (size_t i = 0; i < vv.size(); ++i) is >> vv[i];
	return is;
}

struct phash {
	template<class T1, class T2>
    inline size_t operator()(const pair<T1, T2> & p) const {
        auto h1 = hash<T1>()(p.first);
        auto h2 = hash<T2>()(p.second);

		size_t seed = h1 + h2; 
		h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b;
        h1 = (h1 >> 16) ^ h1;
        seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
		h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b;
        h2 = (h2 >> 16) ^ h2;
        seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
    }
};




struct Date {
	ll weekday;
	ll hour;
	ll minute;

	Date(ll weekday, ll hour, ll minute) : weekday(weekday), hour(hour), minute(minute) {}

	Date add(ll minute) const {
		Date res(this->weekday, this->hour, this->minute);
		res.minute += minute;

		res.hour += res.minute / 60;
		res.minute %= 60;

		res.weekday += res.hour / 24;
		res.hour %= 24;

		res.weekday %= 7;
		return res;
	}
};

bool isAllNight(Date s, Date g) {
	if (s.hour <= g.hour) {
		return (18 <= s.hour && s.hour < 24 && 18 <= g.hour && g.hour < 24) || (0 <= s.hour && s.hour < 6 && 0 <= g.hour && g.hour < 6);
	}
	else {
		return (18 <= s.hour && s.hour < 24 && 0 <= g.hour && g.hour < 6);
	}
}
bool isAllDay(Date s, Date g) {
	if (s.hour <= g.hour) {
		return (6 <= s.hour && s.hour < 18 && 6 <= g.hour && g.hour < 18);
	}
	return false;
}

unordered_map<string, ll> wd_map = {
	// Sun, Mon, Tue, Wed, Thu, Fri, Sat
	{"Sun", 0},
	{"Mon", 1},
	{"Tue", 2},
	{"Wed", 3},
	{"Thu", 4},
	{"Fri", 5},
	{"Sat", 6}};

int solve()
{
	ll s; cin >> s;
	if (s == 0)
		return 1;
	ll n, t;
	cin >> n >> t;
	string weekday, time;
	cin >> weekday >> time;
	ll p, m;
	cin >> p >> m;

	double ans = -INF32;
	rep(hour, 24) rep(minute, 60) rep(wd, 7)
	{
		ll ok = 0;
		Date now(wd, hour, minute);

		for (ll stage = 0; stage < m; stage++, now = now.add(t)) {
			Date start = now;
			Date end = start.add(s);

			if (weekday != "All" && (start.weekday != wd_map[weekday] || end.weekday != wd_map[weekday])) {
				continue;
			}
			if (time == "Day" && !isAllDay(start, end)) {
				continue;
			}
			else if (time == "Night" && !isAllNight(start, end)) {
				continue;
			}

			ok += n;
		}

		chmax(ans, 1 - pow(1.0 - (1.0 / p), ok));
	}

	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	while (!solve()) {}
	return 0;
}
accuracy: 1
time_ms: 1000
memory_kb: 3964
final_rank: 17

code_snippet: #include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

const int loop = 7 * 24 * 60;

int s, n, t, w, d, p, m;
string week, zone;

bool match(int time) {
    int weekday = time / (24 * 60);
    int day = (time % (24 * 60)) / 60;
    day = (day < 6 || day >= 18) ? 1 : 0;
    return ((w >> weekday) & 1) && ((d >> day) & 1);
}

int main() {
    while (cin >> s >> n >> t >> week >> zone >> p >> m) {
        if(s == 0)break;
        w = (week == "All") ? (1 << 7) - 1 : (1 << 1);
        d = (zone == "All") ? 3 : (zone == "Day") ? 1 : 2;

        double q = pow((p - 1.0) / p, n), ans = -1e+100;
        for (int start = 24 * 60 - s; start <= 24 * 60 * 2; ++start) {
            double sump = 1.0;
            int time = start;
            for (int i = 0; i < m; ++i) {
                if (match(time) && match((time + s) % loop))
                    sump *= q;
                time = (time + t) % loop;
            }
            ans = max(ans, 1.0 - sump);
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3940
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int loop = 7 * 24 * 60;

int s, n, t, w, d, p, m;
string week, zone;

bool match(int time) {
    int weekday = time / (24 * 60);
    int day = (time % (24 * 60)) / 60;
    day = (day < 6 || day >= 18) ? 1 : 0;
    return ((w >> weekday) & 1) && ((d >> day) & 1);
}

int main() {
    while (cin >> s >> n >> t >> week >> zone >> p >> m) {
        if(s == 0)break;
        w = (week == "All") ? (1 << 7) - 1 : (1 << 1);
        d = (zone == "All") ? 3 : (zone == "Day") ? 1 : 2;

        double q = pow((p - 1.0) / p, n), ans = -1e+100;
        for (int start = 24 * 60 - s; start <= 24 * 60 * 2; ++start) {
            double sump = 1.0;
            int time = start;
            for (int i = 0; i < m; ++i) {
                if (match(time) && match((time + s) % loop))
                    sump *= q;
                time = (time + t) % loop;
            }
            ans = max(ans, 1.0 - sump);
        }
        cout << fixed << setprecision(15) << ans << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3936
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int s, n, t, m, p;
bitset<7 * 24 * 60> minutes;
int wbits, tbits;
double ck(int start) {
  int cnt = 0;
  int mod = 7 * 24 * 60;
  for (int i = 0, curMin = start % mod; i < m; i++, curMin = (curMin + t) % mod) {
    bool flag = true;
    for (int j = 0, curJ = curMin; j <= s; j++, curJ = (curJ + 1) % mod) {
      if (!minutes[curJ]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}
int main() {
  string weekday, time;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    minutes.reset();
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = 1;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 830
memory_kb: 3400
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;

int s, n, t, m, p;
bitset<7 * 24 * 60> minutes;
int wbits, tbits;

double ck(int start) {
  int cnt = 0;
  double prob = 1.0 - 1.0 / p;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  double result = 1.0;
  for(int i = 0; i < cnt * n; ++i){
    result *= prob;
  }
  return 1.0 - result;
}

int main() {
  string weekday, time;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      minutes[i] = (wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2)));
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
    minutes.reset();
  }
}
accuracy: 1
time_ms: 440
memory_kb: 3232
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

char minutes[7 * 24 * 60];
int s, n, t, m, p;
int wbits, tbits;

double ck(int start, double diff) {
    int cnt = 0;
    for (int i = 0; i < m; i++, start += t) {
        bool flag = true;
        for (int j = 0; j <= s; j++) {
            if (!minutes[(start + j) % (7 * 24 * 60)]) {
                flag = false;
                break;
            }
        }
        cnt += flag;
    }
    return (1.0 - pow(diff, (double)cnt * n));
}

int main() {
    string weekday, time;
    while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
        if (weekday == "All")
            wbits = (1 << 7) - 1;
        else
            wbits = 1;
        if (time == "Night")
            tbits = 1;
        else if (time == "Day")
            tbits = 2;
        else
            tbits = 3;
        double ans = 0.0;
        double diff = 1.0 - 1.0 / p;
        for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
            minutes[i] = (wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2)));
        }
        for (int i = 24 * 60 - 1; i >= 0; i--) {
            ans = max(ans, ck(i, diff));
        }
        cout << fixed << setprecision(16) << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3388
final_rank: 2

code_snippet: #include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int s, n, t, m, p;
bool minutes[7 * 24 * 60];
int wbits, tbits;
double ck(int start) {
  int cnt = 0;
  start = start % (7 * 24 * 60);
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string weekday, time;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
      else
        minutes[i] = false;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3464
final_rank: 10

code_snippet: #include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

int s, n, t, m, p;
bool minutes[7 * 24 * 60];
int wbits, tbits;
double subtract;

double ck(int start) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(subtract, (double)cnt * n));
}

inline int todays(int i) { return (i / (24 * 60)); }

inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}

int main() {
  string weekday, time;
  cout << fixed << setprecision(16);
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    subtract = 1.0 - 1.0 / p;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
      else
        minutes[i] = false;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3408
final_rank: 5

code_snippet: #include <iostream>
#include <string>
#include <bitset>
#include <iomanip>
#include <cmath>
using namespace std;

int s, n, t, m, p;
bitset<7 * 24 * 60> minutes;
int wbits, tbits;

double ck(int start) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}

int main() {
  string weekday, time;
  int total_minutes = 7 * 24 * 60;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = total_minutes - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
      else
        minutes[i] = false;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 400
memory_kb: 3416
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
int s, n, t, m, p;
bool minutes[7 * 24 * 60];
int wbits, tbits;
double ck(int start) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}
int main() {
  string weekday, time;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if (wbits >> todays(i) & 1 && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
      else
        minutes[i] = false;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3444
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
int s, n, t, m, p;
bool minutes[7 * 24 * 60];
int wbits, tbits;
double ck(int start) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}
int main() {
  string weekday, time;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
      else
        minutes[i] = false;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3404
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAX_MINUTES = 7 * 24 * 60;
bool minutes[MAX_MINUTES];
inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}
double ck(int start, int s, int n, int t, int m, int p) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % MAX_MINUTES]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
int main() {
  string weekday, time;
  int s, n, t, m, p;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    int wbits = 0, tbits = 0;
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    memset(minutes, 0, sizeof(minutes));
    for (int i = MAX_MINUTES - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
    }
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, ck(i, s, n, t, m, p));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3488
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
bool minutes[7 * 24 * 60];
int wbits, tbits;
double ck(int start, int m, int t, int s, int n, int p) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string weekday, time;
  int s, n, t, m, p;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    memset(minutes, 0, sizeof(minutes));
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
    }
    for (int i = 0; i < 24 * 60; i++) {
      ans = max(ans, ck(i, m, t, s, n, p));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3460
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAX_MINUTES = 10080; // 7 days * 24 hours * 60 minutes
bool minutes[MAX_MINUTES];
double ck(int start, int s, int n, int t, int p, int m) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % MAX_MINUTES]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}
int main() {
  string weekday, time;
  int s, n, t, p, m;
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    int wbits, tbits;
    if (weekday == "All")
      wbits = (1 << 7) - 1;
    else
      wbits = 1;
    if (time == "Night")
      tbits = 1;
    else if (time == "Day")
      tbits = 2;
    else
      tbits = 3;
    double ans = 0.0;
    memset(minutes, false, sizeof(minutes));
    for (int i = 0; i < MAX_MINUTES; i++) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2))))
        minutes[i] = true;
    }
    for (int i = 0; i < 24 * 60; i++) {
      ans = max(ans, ck(i, s, n, t, p, m));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3404
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int s, n, t, m, p;
bool minutes[7 * 24 * 60];

double calculateProbability(int start) {
  int cnt = 0;
  for (int i = 0; i < m; i++, start += t) {
    bool flag = true;
    for (int j = 0; j <= s; j++) {
      if (!minutes[(start + j) % (7 * 24 * 60)]) {
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return (1.0 - pow(1.0 - 1.0 / p, (double)cnt * n));
}

inline int todays(int i) { return (i / (24 * 60)); }
inline bool totime(int i) {
  int tm = i % (24 * 60) / 24;
  return (tm >= 18 || tm < 6);
}

int main() {
  string weekday, time;
  
  while (cin >> s >> n >> t >> weekday >> time >> p >> m, m) {
    int wbits = (weekday == "All") ? ((1 << 7) - 1) : 1;
    int tbits = (time == "Night") ? 1 : ((time == "Day") ? 2 : 3);
    
    double ans = 0.0;
    for (int i = 7 * 24 * 60 - 1; i >= 0; i--) {
      if ((wbits & (1 << i / 1440)) && (tbits & (1 << ((i / 360 + 1) % 4 / 2)))) {
        minutes[i] = true;
      } else {
        minutes[i] = false;
      }
    }
    
    for (int i = 24 * 60 - 1; i >= 0; i--) {
      ans = max(ans, calculateProbability(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}
accuracy: 1
time_ms: 350
memory_kb: 3432
final_rank: 6