problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define printWithPrecision(x) cout << fixed << setprecision(10) << x << endl; double dp[3001][3001]; double solve(vector<double> v, ll i, ll x) { if (x == 0) return 1; if (i == 0) return 0; if (dp[i][x] > -0.9) return dp[i][x]; return dp[i][x] = (v[i] * solve(v, i - 1, x - 1)) + (((double)1 - v[i]) * solve(v, i - 1, x)); } void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); ll n; cin >> n; memset(dp, -1, sizeof dp); vector<double> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i]; printWithPrecision(solve(v, n, (n + 1) / 2ll)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define printWithPrecision(x) cout << fixed << setprecision(10) << x << endl; double dp[3001][3001]; double solve(vector<double> &v, ll i, ll x) { if (x == 0) return 1; if (i == 0) return 0; if (dp[i][x] > -0.9) return dp[i][x]; return dp[i][x] = (v[i] * solve(v, i - 1, x - 1)) + (((double)1 - v[i]) * solve(v, i - 1, x)); } void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fast(); ll n; cin >> n; memset(dp, -1, sizeof dp); vector<double> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i]; printWithPrecision(solve(v, n, (n + 1) / 2ll)); return 0; }
replace
8
9
8
9
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mod 1000000007; vector<vector<double>> dp; // dp(i,j) probablity of coming j heads when i coins vector<double> p; double probhead(int n, int heads) { if (dp[n][heads] != -1) { return dp[n][heads]; } return probhead(n - 1, heads) * (1 - p[n]) + probhead(n - 1, heads - 1) * p[n]; } void solve() { int n; cin >> n; dp.resize(n + 1, vector<double>(n + 1, -1)); p.resize(n + 1); for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 0; i <= n; i++) { dp[0][i] = 0; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } double pr = 0; for (int i = (n + 1) / 2; i <= n; i++) { pr += probhead(n, i); } cout << pr << "\n"; } int main() { cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0); cout.precision(10); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007; vector<vector<double>> dp; // dp(i,j) probablity of coming j heads when i coins vector<double> p; double probhead(int n, int heads) { if (dp[n][heads] != -1) { return dp[n][heads]; } return dp[n][heads] = probhead(n - 1, heads) * (1 - p[n]) + probhead(n - 1, heads - 1) * p[n]; } void solve() { int n; cin >> n; dp.resize(n + 1, vector<double>(n + 1, -1)); p.resize(n + 1); for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 0; i <= n; i++) { dp[0][i] = 0; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } double pr = 0; for (int i = (n + 1) / 2; i <= n; i++) { pr += probhead(n, i); } cout << pr << "\n"; } int main() { cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0); cout.precision(10); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
11
13
11
13
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> //Carefully Crafted by hetp111 using namespace std; #define int long long #define double long double #define all(v) (v).begin(), (v).end() #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vii vector<pii> #define MOD 1000000007 #define PI acos(-1) #define eps (1e-8) #define INF (1e18) #define FASTER \ ios_base::sync_with_stdio(0); \ cin.tie(0) template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a) { return out << "(" << a.first << "," << a.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out; } template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { return in >> a.first >> a.second; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &i : a) in >> i; return in; } // ifstream cinn("input.txt");ofstream coutt("output.txt"); double dp[3000][3000]; int n; vector<double> v; double f(int i, int head) { if (i == n) return head > (n / 2); double ans = dp[i][head]; if (ans > -1) return ans; ans = 0; ans += v[i] * f(i + 1, head + 1); ans += (1 - v[i]) * f(i + 1, head); return ans; } signed main() { FASTER; for (int i = 0; i < 3000; i++) for (int j = 0; j < 3000; j++) dp[i][j] = -1000.0; cin >> n; v = vector<double>(n); cin >> v; double ans = 0; ans += f(0, 0); cout << fixed << setprecision(10) << ans; }
#include <bits/stdc++.h> //Carefully Crafted by hetp111 using namespace std; #define int long long #define double long double #define all(v) (v).begin(), (v).end() #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vii vector<pii> #define MOD 1000000007 #define PI acos(-1) #define eps (1e-8) #define INF (1e18) #define FASTER \ ios_base::sync_with_stdio(0); \ cin.tie(0) template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a) { return out << "(" << a.first << "," << a.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out; } template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { return in >> a.first >> a.second; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &i : a) in >> i; return in; } // ifstream cinn("input.txt");ofstream coutt("output.txt"); double dp[3000][3000]; int n; vector<double> v; double f(int i, int head) { if (i == n) return head > (n / 2); double &ans = dp[i][head]; if (ans > -1) return ans; ans = 0; ans += v[i] * f(i + 1, head + 1); ans += (1 - v[i]) * f(i + 1, head); return ans; } signed main() { FASTER; for (int i = 0; i < 3000; i++) for (int j = 0; j < 3000; j++) dp[i][j] = -1000.0; cin >> n; v = vector<double>(n); cin >> v; double ans = 0; ans += f(0, 0); cout << fixed << setprecision(10) << ans; }
replace
42
43
42
43
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define f(i, x, n) for (int i = x; i < n; i++) #define all(c) c.begin(), c.end() const int MOD = 1e9 + 7, N = 2e3 + 10; const int LINF = LLONG_MAX; double dp[N][N]; double C[N]; int n; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(10) << fixed; memset(dp, 0, sizeof(dp)); cin >> n; f(i, 0, n) { cin >> C[i]; } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] += dp[i][j] * C[i]; dp[i + 1][j] += dp[i][j] * (1 - C[i]); } } double ans = 0; for (int j = (n + 1) / 2; j <= n; j++) { ans += dp[n][j]; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define f(i, x, n) for (int i = x; i < n; i++) #define all(c) c.begin(), c.end() const int MOD = 1e9 + 7, N = 3e3 + 10; const int LINF = LLONG_MAX; double dp[N][N]; double C[N]; int n; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(10) << fixed; memset(dp, 0, sizeof(dp)); cin >> n; f(i, 0, n) { cin >> C[i]; } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] += dp[i][j] * C[i]; dp[i + 1][j] += dp[i][j] * (1 - C[i]); } } double ans = 0; for (int j = (n + 1) / 2; j <= n; j++) { ans += dp[n][j]; } cout << ans; return 0; }
replace
5
6
5
6
0
p03168
C++
Runtime Error
//****** @mdazmat9 ********** #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define UB upper_bound #define LB lower_bound #define BS binary_search #define EB emplace_back #define PB push_back #define endl "\n" #define MOD 1000000007 #define MOD2 998244353 #define F first #define S second #define ALL(a) (a).begin(), (a).end() typedef pair<int, int> pr; typedef vector<int> VI; typedef vector<pr> VP; typedef vector<string> VS; typedef vector<vector<int>> VV; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define trace(v) \ for (auto it = v.begin(); it != v.end(); it++) \ cout << *it << " "; \ cout << endl; const int INF = 1e9; int fast_pow(int x, int y, int p); int n; long double a[3000], dp[3001]; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (i == 0) { dp[0] = 1 - a[i]; dp[1] = a[i]; continue; } long double b[3001] = {0}; for (int j = 0; j < 3000; j++) { b[j] += ((1 - a[i]) * dp[j]); b[j + 1] += (a[i] * dp[j]); } for (int j = 0; j < 3000; j++) { dp[j] = b[j]; } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[i]; } cout << fixed << setprecision(10) << ans << endl; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int test = 1; // cin>>test; for (int i = 1; i <= test; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; } int fast_pow(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; }
//****** @mdazmat9 ********** #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define UB upper_bound #define LB lower_bound #define BS binary_search #define EB emplace_back #define PB push_back #define endl "\n" #define MOD 1000000007 #define MOD2 998244353 #define F first #define S second #define ALL(a) (a).begin(), (a).end() typedef pair<int, int> pr; typedef vector<int> VI; typedef vector<pr> VP; typedef vector<string> VS; typedef vector<vector<int>> VV; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define trace(v) \ for (auto it = v.begin(); it != v.end(); it++) \ cout << *it << " "; \ cout << endl; const int INF = 1e9; int fast_pow(int x, int y, int p); int n; long double a[3000], dp[3001]; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (i == 0) { dp[0] = 1 - a[i]; dp[1] = a[i]; continue; } long double b[3001] = {0}; for (int j = 0; j < 3000; j++) { b[j] += ((1 - a[i]) * dp[j]); b[j + 1] += (a[i] * dp[j]); } for (int j = 0; j < 3000; j++) { dp[j] = b[j]; } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[i]; } cout << fixed << setprecision(10) << ans << endl; } int32_t main() { IOS; int test = 1; // cin>>test; for (int i = 1; i <= test; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; } int fast_pow(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; }
replace
78
82
78
79
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define pb push_back #define pf push_front #define loop(i, n) for (int i = 0; i < n; ++i) #define LOOP(i, a, b) for (int i = a; i < b; ++i) #define max3(a, b, c) max(a, max(b, c)) #define max4(a, b, c, d) max3(a, b, max(c, d)) #define ff first #define ss second #define mkp make_pair #define pii pair<int, int> #define vi vector<int> #define vvi vector<vi> #define vii vector<pii> #define vvii vector<vii> #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define nmbr(c) (int)(c - '0') #define ltr(c) (int)(c - 'a') #define INF 1e18 #define inf 1e9 #define MOD 1000000007 // check #define _69e27 \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int n; long double dp[3001][3001], p[3000]; bool dpb[3001][3001]; long double prb(int i, int h) { if (i == n) return (2 * h > n); long double &ans = dp[i][h]; if (dpb[i][h]) return ans; return ans = p[i] * prb(i + 1, h + 1) + (1 - p[i]) * prb(i + 1, h); } int main() { _69e27; memset(dpb, 0, sizeof(dpb)); cin >> n; loop(i, n) cin >> p[i]; cout << fixed << setprecision(10) << prb(0, 0); return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define pb push_back #define pf push_front #define loop(i, n) for (int i = 0; i < n; ++i) #define LOOP(i, a, b) for (int i = a; i < b; ++i) #define max3(a, b, c) max(a, max(b, c)) #define max4(a, b, c, d) max3(a, b, max(c, d)) #define ff first #define ss second #define mkp make_pair #define pii pair<int, int> #define vi vector<int> #define vvi vector<vi> #define vii vector<pii> #define vvii vector<vii> #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define nmbr(c) (int)(c - '0') #define ltr(c) (int)(c - 'a') #define INF 1e18 #define inf 1e9 #define MOD 1000000007 // check #define _69e27 \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int n; long double dp[3001][3001], p[3000]; bool dpb[3001][3001]; long double prb(int i, int h) { if (i == n) return (2 * h > n); long double &ans = dp[i][h]; if (dpb[i][h]) return ans; dpb[i][h] = 1; return ans = p[i] * prb(i + 1, h + 1) + (1 - p[i]) * prb(i + 1, h); } int main() { _69e27; memset(dpb, 0, sizeof(dpb)); cin >> n; loop(i, n) cin >> p[i]; cout << fixed << setprecision(10) << prb(0, 0); return 0; }
insert
42
42
42
43
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define show(x) cout << (#x) << " : " << x << endl; #define ll long long #define ld long double #define mp make_pair #define ff first #define ss second #define pii pair<ll, ll> #define sq(x) ((x) * (x)) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() const ll MOD = 1000 * 1000 * 1000 + 7; using namespace std; long double dp[4000][4000]; ll N; long double P[4000]; long double seno(ll idx, ll H) { if (idx == 1) { if (H == 0) return dp[idx][0] = 1 - P[idx]; else return dp[idx][1] = P[idx]; } if (dp[idx][H] != 4) return dp[idx][H]; dp[idx][H] = (long double)(P[idx] * seno(idx - 1, H - 1)) + (long double)((idx - 1 - H >= 0 ? (1 - P[idx]) * seno(idx - 1, H) : 0)); return dp[idx][H]; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); cin >> N; for (int i = N; i >= 1; i--) cin >> P[i]; for (int i = 1; i <= 3000; i++) { for (int j = 1; j <= 3000; j++) dp[i][j] = 4; } dp[1][0] = 1 - P[1]; for (int i = 2; i <= N; i++) { dp[i][0] = (1 - P[i]) * dp[i - 1][0]; } long double sum = 0; for (int i = (N / 2) + 1; i <= N; i++) { sum += seno(N, i); } cout << setprecision(9) << sum; return 0; }
#include <bits/stdc++.h> #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define show(x) cout << (#x) << " : " << x << endl; #define ll long long #define ld long double #define mp make_pair #define ff first #define ss second #define pii pair<ll, ll> #define sq(x) ((x) * (x)) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() const ll MOD = 1000 * 1000 * 1000 + 7; using namespace std; long double dp[4000][4000]; ll N; long double P[4000]; long double seno(ll idx, ll H) { if (idx == 1) { if (H == 0) return dp[idx][0] = 1 - P[idx]; else return dp[idx][1] = P[idx]; } if (dp[idx][H] != 4) return dp[idx][H]; dp[idx][H] = (long double)(P[idx] * seno(idx - 1, H - 1)) + (long double)((idx - 1 - H >= 0 ? (1 - P[idx]) * seno(idx - 1, H) : 0)); return dp[idx][H]; } int main() { fastio(); cin >> N; for (int i = N; i >= 1; i--) cin >> P[i]; for (int i = 1; i <= 3000; i++) { for (int j = 1; j <= 3000; j++) dp[i][j] = 4; } dp[1][0] = 1 - P[1]; for (int i = 2; i <= N; i++) { dp[i][0] = (1 - P[i]) * dp[i - 1][0]; } long double sum = 0; for (int i = (N / 2) + 1; i <= N; i++) { sum += seno(N, i); } cout << setprecision(9) << sum; return 0; }
delete
47
52
47
47
-11
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; ll N; double dp[3099][3099], p[3099], head[3099], tail[3099]; double f(ll n, ll m) { if (n == 0) { if (m == 0) return 1; else return 0; } if (m == 0) { return tail[n]; } if (m == n) { return head[n]; } if (dp[n][m] < 0) return dp[n][m]; dp[n][m] = p[n] * f(n - 1, m - 1) + (1 - p[n]) * f(n - 1, m); return dp[n][m]; } int main() { cin >> N; memset(dp, -1, sizeof dp); for (int i = 1; i <= N; i++) { cin >> p[i]; } head[1] = p[1]; tail[1] = 1 - p[1]; for (int i = 2; i <= N; i++) { head[i] = p[i] * head[i - 1]; tail[i] = (1 - p[i]) * tail[i - 1]; } double jwb = 0; for (int i = (N + 1) / 2; i <= N; i++) { jwb += f(N, i); } cout << fixed << setprecision(10) << jwb << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; ll N; double dp[3099][3099], p[3099], head[3099], tail[3099]; double f(ll n, ll m) { if (n == 0) { if (m == 0) return 1; else return 0; } if (m == 0) { return tail[n]; } if (m == n) { return head[n]; } if (dp[n][m] > -1) return dp[n][m]; dp[n][m] = p[n] * f(n - 1, m - 1) + (1 - p[n]) * f(n - 1, m); return dp[n][m]; } int main() { cin >> N; memset(dp, -1, sizeof dp); for (int i = 1; i <= N; i++) { cin >> p[i]; } head[1] = p[1]; tail[1] = 1 - p[1]; for (int i = 2; i <= N; i++) { head[i] = p[i] * head[i - 1]; tail[i] = (1 - p[i]) * tail[i - 1]; } double jwb = 0; for (int i = (N + 1) / 2; i <= N; i++) { jwb += f(N, i); } cout << fixed << setprecision(10) << jwb << endl; }
replace
19
20
19
20
TLE
p03168
C++
Runtime Error
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; // #define FILE_INPUT // #define DEBUG_MODE void DebugPrint(double a[], int n) { #ifdef DEBUG_MODE for (int i = 0; i < min(20, n); ++i) { cout << a[i] << ","; } cout << endl; #endif } double dp[3000 / 2][3000]; int main() { #ifdef FILE_INPUT ifstream in("test3.txt"); cin.rdbuf(in.rdbuf()); #endif /* FILE_INPUT */ int n; cin >> n; vector<double> p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; } dp[0][0] = 1.0; for (int i = 0; i < n / 2 + 1; ++i) { for (int j = i; j < n; ++j) { dp[i][j + 1] += dp[i][j] * p[j]; dp[i + 1][j + 1] = dp[i][j] * (1.0 - p[j]); } DebugPrint(dp[i], n + 1); } double sum = 0.0; for (int i = 0; i < n / 2 + 1; ++i) { sum += dp[i][n]; } cout << fixed << setprecision(10) << sum << endl; return 0; }
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; // #define FILE_INPUT // #define DEBUG_MODE void DebugPrint(double a[], int n) { #ifdef DEBUG_MODE for (int i = 0; i < min(20, n); ++i) { cout << a[i] << ","; } cout << endl; #endif } double dp[2999 / 2 + 2][2999 + 1]; int main() { #ifdef FILE_INPUT ifstream in("test3.txt"); cin.rdbuf(in.rdbuf()); #endif /* FILE_INPUT */ int n; cin >> n; vector<double> p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; } dp[0][0] = 1.0; for (int i = 0; i < n / 2 + 1; ++i) { for (int j = i; j < n; ++j) { dp[i][j + 1] += dp[i][j] * p[j]; dp[i + 1][j + 1] = dp[i][j] * (1.0 - p[j]); } DebugPrint(dp[i], n + 1); } double sum = 0.0; for (int i = 0; i < n / 2 + 1; ++i) { sum += dp[i][n]; } cout << fixed << setprecision(10) << sum << endl; return 0; }
replace
20
21
20
21
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define Mod 1000000007 #define ll long long #define dd double #define pb push_back #define ff first #define ss second #define Mp make_pair #define INF 999999999999999999 #define NN (ll)(3e3 + 5) int mod(string s, int a) { int ans = 0; for (int i = 0; i < s.length(); i++) ans = (ans * 10 + (int)s[i] - '0') % a; return ans; } ll min(ll x, ll y) { if (x < y) return x; return y; } ll max(ll x, ll y) { if (x > y) return x; return y; } ll power(ll x, unsigned ll y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } ll hcf(ll a, ll b) { if (b == 0) return a; return hcf(b, a % b); } ll n; vector<dd> v(NN); ll vis[NN][NN]; dd dp[NN][NN]; dd func(ll ind, ll heads) { if (ind == n + 1) return (heads * 2 >= n); if (vis[ind][heads]) return dp[ind][heads]; dd &ans = dp[ind][heads]; return ans = v[ind] * func(ind + 1, heads + 1) + (1 - v[ind]) * func(ind + 1, heads); } int main() { fio; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif*/ ll TT = 1; // cin>>TT; while (TT--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> v[i]; dd ans = func(1, 0); cout << fixed << setprecision(12) << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define Mod 1000000007 #define ll long long #define dd double #define pb push_back #define ff first #define ss second #define Mp make_pair #define INF 999999999999999999 #define NN (ll)(3e3 + 5) int mod(string s, int a) { int ans = 0; for (int i = 0; i < s.length(); i++) ans = (ans * 10 + (int)s[i] - '0') % a; return ans; } ll min(ll x, ll y) { if (x < y) return x; return y; } ll max(ll x, ll y) { if (x > y) return x; return y; } ll power(ll x, unsigned ll y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } ll hcf(ll a, ll b) { if (b == 0) return a; return hcf(b, a % b); } ll n; vector<dd> v(NN); ll vis[NN][NN]; dd dp[NN][NN]; dd func(ll ind, ll heads) { if (ind == n + 1) return (heads * 2 >= n); if (vis[ind][heads]) return dp[ind][heads]; vis[ind][heads] = 1; dd &ans = dp[ind][heads]; return ans = v[ind] * func(ind + 1, heads + 1) + (1 - v[ind]) * func(ind + 1, heads); } int main() { fio; /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif*/ ll TT = 1; // cin>>TT; while (TT--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> v[i]; dd ans = func(1, 0); cout << fixed << setprecision(12) << ans << "\n"; } }
insert
53
53
53
54
TLE
p03168
C++
Runtime Error
#pragma GCC optimize("O3") #pragma GCC target("avx") // #include<bits/stdc++.h> #include <algorithm> #include <cstdio> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int cm = 1 << 14; char cn[cm], *ci = cn, ct; const double p = 0.01; int main() { // cin.tie(0); // ios::sync_with_stdio(false); fread(ci, 1, cm, stdin); int N = 0; while ((ct = *ci++) >= '0') N = N * 10 + ct - '0'; int M = N / 2; vector<double> dp(M + 1); dp[0] = 1.0; rep(i, N) { ci += 2; int k = (*ci++ - '0') * 10; k += *ci++ - '0'; double P = p * k; ci++; for (int j = min(M, i); j >= max(0, i - M); j--) { dp[j + 1] += dp[j] * P; dp[j] *= 1 - P; } } printf("%.15f", dp[M + 1]); Would you please return 0; }
#pragma GCC optimize("O3") #pragma GCC target("avx") // #include<bits/stdc++.h> #include <algorithm> #include <cstdio> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int cm = 1 << 14; char cn[cm], *ci = cn, ct; const double p = 0.01; int main() { // cin.tie(0); // ios::sync_with_stdio(false); fread(ci, 1, cm, stdin); int N = 0; while ((ct = *ci++) >= '0') N = N * 10 + ct - '0'; int M = N / 2; vector<double> dp(M + 2); dp[0] = 1.0; rep(i, N) { ci += 2; int k = (*ci++ - '0') * 10; k += *ci++ - '0'; double P = p * k; ci++; for (int j = min(M, i); j >= max(0, i - M); j--) { dp[j + 1] += dp[j] * P; dp[j] *= 1 - P; } } printf("%.15f", dp[M + 1]); Would you please return 0; }
replace
37
38
37
38
0
p03168
C++
Runtime Error
// Author rahuliitkgp /*A thing of beauty is a joy forever, Its loveliness increases, it will never pass into nothingness.*/ // Men at Work :) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void cpp() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { cpp(); ll n; cin >> n; vector<double> v(n); for (ll i = 0; i < n; i++) cin >> v[i]; vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0)); for (ll i = 0; i <= n; i++) { dp[i][0] = 1; } dp[0][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * (1 - v[i - 1]) + dp[i - 1][j - 1] * (v[i - 1]); } } cout << ps(dp[n][(n + 1) / 2], 9) << endl; return 0; }
// Author rahuliitkgp /*A thing of beauty is a joy forever, Its loveliness increases, it will never pass into nothingness.*/ // Men at Work :) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; #define ff first #define ss second #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void cpp() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { cpp(); ll n; cin >> n; vector<double> v(n); for (ll i = 0; i < n; i++) cin >> v[i]; vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0)); for (ll i = 0; i <= n; i++) { dp[i][0] = 1; } dp[0][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * (1 - v[i - 1]) + dp[i - 1][j - 1] * (v[i - 1]); } } cout << ps(dp[n][(n + 1) / 2], 9) << endl; return 0; }
delete
39
43
39
39
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03168
C++
Runtime Error
/*input 1 0.5 */ // author - Madhav Thakker #include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; #define ll long long #define ld long double #define int ll #define endl '\n' typedef pair<int, int> pii; typedef pair<ld, ld> pdd; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define FileIn(file) freopen(file, "r", stdin) #define FileOut(file) freopen(file, "w", stdout) #define all(c) c.begin(), c.end() #define tr(container, it) \ for (__typeof__(container.begin()) it = container.begin(); \ it != container.end(); it++) #define present(container, element) \ (container.find(element) != container.end()) // map, set #define cpresent(container, element) \ (find(aint(container), element) != container.end()) // vector #define what_is(x) cout << #x << " is " << x << endl; #define all(c) c.begin(), c.end() #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; const int MOD = 1e9 + 7; int fast_pow(int a, int b) { int res = a, ret = 1; while (b > 0) { if (b % 2) ret = (ret * res) % MOD; res = (res * res) % MOD; b /= 2; } return ret; } // -- // -- // -- // std::cout << std::fixed; // std::cout << std::setprecision(26) << f << '\n'; // str = to_string(n) // stoi , stoll, stol // sort(arr, arr+n, greater<int>()); // fill(prefix.begin(), prefix.end(), 0); // // //// const int maxN = 1e3 + 7; ld p[maxN]; ld dp[maxN][maxN]; //// signed main() { fastio; time_t time_t1, time_t2; time_t1 = clock(); //////////////////////////////// int t = 1; // cin >> t ; while (t--) { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> p[i]; } memset(dp, 0, sizeof dp); dp[1][1] = 1.0 * p[1]; dp[1][0] = 1.0 * (1 - p[1]); for (int i = 2; i <= n; ++i) { dp[i][0] = 1.0 * dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= n; ++j) { dp[i][j] = 1.0 * dp[i - 1][j - 1] * (p[i]); dp[i][j] = dp[i][j] + 1.0 * dp[i - 1][j] * (1 - p[i]); } } ld ans = 0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n][i]; } printf("%0.12Lf\n", ans); } /////////////////////////////// // time_t2 = clock(); // cerr << "time taken :" << time_t2 - time_t1 << endl; return 0; }
/*input 1 0.5 */ // author - Madhav Thakker #include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; #define ll long long #define ld long double #define int ll #define endl '\n' typedef pair<int, int> pii; typedef pair<ld, ld> pdd; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define FileIn(file) freopen(file, "r", stdin) #define FileOut(file) freopen(file, "w", stdout) #define all(c) c.begin(), c.end() #define tr(container, it) \ for (__typeof__(container.begin()) it = container.begin(); \ it != container.end(); it++) #define present(container, element) \ (container.find(element) != container.end()) // map, set #define cpresent(container, element) \ (find(aint(container), element) != container.end()) // vector #define what_is(x) cout << #x << " is " << x << endl; #define all(c) c.begin(), c.end() #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; const int MOD = 1e9 + 7; int fast_pow(int a, int b) { int res = a, ret = 1; while (b > 0) { if (b % 2) ret = (ret * res) % MOD; res = (res * res) % MOD; b /= 2; } return ret; } // -- // -- // -- // std::cout << std::fixed; // std::cout << std::setprecision(26) << f << '\n'; // str = to_string(n) // stoi , stoll, stol // sort(arr, arr+n, greater<int>()); // fill(prefix.begin(), prefix.end(), 0); // // //// const int maxN = 3e3 + 7; ld p[maxN]; ld dp[maxN][maxN]; //// signed main() { fastio; time_t time_t1, time_t2; time_t1 = clock(); //////////////////////////////// int t = 1; // cin >> t ; while (t--) { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> p[i]; } memset(dp, 0, sizeof dp); dp[1][1] = 1.0 * p[1]; dp[1][0] = 1.0 * (1 - p[1]); for (int i = 2; i <= n; ++i) { dp[i][0] = 1.0 * dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= n; ++j) { dp[i][j] = 1.0 * dp[i - 1][j - 1] * (p[i]); dp[i][j] = dp[i][j] + 1.0 * dp[i - 1][j] * (1 - p[i]); } } ld ans = 0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n][i]; } printf("%0.12Lf\n", ans); } /////////////////////////////// // time_t2 = clock(); // cerr << "time taken :" << time_t2 - time_t1 << endl; return 0; }
replace
86
87
86
87
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define debug(x) cerr << #x << " = " << (x) << endl; template <typename T> ostream &operator<<(ostream &o, vector<T> &v) { for (auto &x : v) o << x << ' '; return o; } int n; double arr[1010]; double memo[1010][1010]; double dp(int i, int heads) { double &res = memo[i][heads]; if (res == res) return res; if (i == n) return (heads == 0) ? 1.0 : 0.0; res = arr[i] * dp(i + 1, heads - 1) + (1 - arr[i]) * dp(i + 1, heads); return res; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; memset(memo, -1, sizeof memo); double prob = 0.0; for (int i = n / 2 + 1; i <= n; i++) { prob += dp(0, i); } cout << fixed << setprecision(10) << prob << endl; }
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define debug(x) cerr << #x << " = " << (x) << endl; template <typename T> ostream &operator<<(ostream &o, vector<T> &v) { for (auto &x : v) o << x << ' '; return o; } int n; double arr[3030]; double memo[3030][3030]; double dp(int i, int heads) { double &res = memo[i][heads]; if (res == res) return res; if (i == n) return (heads == 0) ? 1.0 : 0.0; res = arr[i] * dp(i + 1, heads - 1) + (1 - arr[i]) * dp(i + 1, heads); return res; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; memset(memo, -1, sizeof memo); double prob = 0.0; for (int i = n / 2 + 1; i <= n; i++) { prob += dp(0, i); } cout << fixed << setprecision(10) << prob << endl; }
replace
17
19
17
19
0
p03168
C++
Runtime Error
#include <cstdio> #include <iostream> #include <vector> #define DEBUG 0 constexpr int kMax = 301; int main() { int N; std::cin >> N; std::vector<double> p(N + 1); for (int i = 1; i <= N; ++i) std::cin >> p[i]; double dp[kMax][kMax]; dp[0][0] = 1.0; for (int j = 1; j <= N; ++j) { dp[0][j] = 0.0; } #if DEBUG for (int j = 0; j <= N; ++j) { std::cout << dp[0][j] << "\t"; } std::cout << std::endl; #endif for (int i = 1; i <= N; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= N; ++j) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } #if DEBUG for (int j = 0; j <= N; ++j) { std::cout << dp[i][j] << "\t"; } std::cout << std::endl; #endif } double sum_p = 0.0; for (int j = N; j > N / 2; --j) { sum_p += dp[N][j]; } printf("%.10f\n", sum_p); }
#include <cstdio> #include <iostream> #include <vector> #define DEBUG 0 constexpr int kMax = 3001; int main() { int N; std::cin >> N; std::vector<double> p(N + 1); for (int i = 1; i <= N; ++i) std::cin >> p[i]; double dp[kMax][kMax]; dp[0][0] = 1.0; for (int j = 1; j <= N; ++j) { dp[0][j] = 0.0; } #if DEBUG for (int j = 0; j <= N; ++j) { std::cout << dp[0][j] << "\t"; } std::cout << std::endl; #endif for (int i = 1; i <= N; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= N; ++j) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } #if DEBUG for (int j = 0; j <= N; ++j) { std::cout << dp[i][j] << "\t"; } std::cout << std::endl; #endif } double sum_p = 0.0; for (int j = N; j > N / 2; --j) { sum_p += dp[N][j]; } printf("%.10f\n", sum_p); }
replace
4
5
4
5
0
p03168
C++
Runtime Error
// Write correct codes,then there is no need to debug // Implement after solving several problems // - GENNADY KOROTKEVICH #include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define ll long long #define ld long double #define int int64_t #define be(v) v.begin(), v.end() #define ff(i, n) for (int i = 0; i < n; i++) #define ii(it, v) for (auto it = v.begin(); it != v.end(); it++) #define vii vector<vector<int>> #define vi vector<int> #define vP vector<pair<int, int>> #define P pair<int, int> #define case \ cout << "Case #" << hh + 1 << ": "; \ hh++; // int T;cin>>T;int hh=0;while(T--) #define fi first #define se second #define endl "\n" #define mem(a, b) memset(a, b, sizeof(a)) #define sf(n) scanf("%d", &n) #define sff(a, b) scanf("%d %d", &a, &b) #define sfff(a, b, c) scanf("%d %d %d", &a, &b, &c) #define pfn(n) printf("%d\n", n) #define pfs(n) printf("%d ", n) #define H (ll)(1e9 + 7) #define bg (ll)998244353 bool *Seive(ll n, bool *p) // boolean 1 means prime { /* bool p[21]; //write this in main() *p=Seive(20,p); //replace 20 by the given value */ mem(p, 1); ll i, j; for (i = 2; i <= n; i++) { if (p[i] == 1) for (j = i * i; j <= n; j += i) { p[j] = 0; } } p[1] = 0; return p; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll modexp(ll x, ll y) // x^y//Inverse modulo where y=H-2(use when H is prime) { if (y == 0) return 1; else if (y % 2 == 0) { return modexp((x * x) % H, y / 2); } else { return (x * modexp((x * x) % H, (y - 1) / 2)) % H; } } ll fact(ll n) // n! { ll f = 1; for (ll i = 2; i <= n; i++) { f = (i % H * f % H) % H; } return f; } ll nCr(ll n, ll r) { return (fact(n) * modexp((fact(n - r) * fact(r)) % H, H - 2)) % H; } void showlist(list<int> g) { list<int>::iterator it; for (it = g.begin(); it != g.end(); ++it) cout << *it << " "; cout << '\n'; } void swap(int &a, int &b) { int t; t = a; a = b; b = t; } // Segment tree Functions void build(int l, int r, int i) // array 'a[4*n+4]' is the segment tree { if (l == r) { // a[i]++; } else { int mid = (l + r) / 2; build(l, mid, 2 * i); build(mid + 1, r, 2 * i + 1); // a[i]=a[2*i]+a[2*i+1]; } } // in main() : build(0,n-1,1); void update(int p, int l, int r, int i) // update at position 'p' { if (l == r) { // a[i]--; // a[i]++; } else { int mid = (l + r) / 2; if (p <= mid) { update(p, l, mid, 2 * i); } else { update(p, mid + 1, r, 2 * i + 1); } // a[i]--; // a[i]++; } } // in main(): update(p,0,n-1,1); void query(int y, int z, int l, int r, int i) // query: find ans for range y to z { if (y <= l && z >= r) { } else { int mid = (l + r) / 2; if (z <= mid) { query(y, z, l, mid, 2 * i); } else if (y > mid) { query(y, z, mid + 1, r, 2 * i + 1); } else { query(y, z, l, mid, 2 * i); query(y, z, mid + 1, r, 2 * i + 1); } } } // in main(): query(y,z,0,n-1); // dsu Functions void make_set(int v) { /* parent[v] = v; size[v] = 1;*/ } int find_set(int v) { /*if (v == parent[v]) return v; return parent[v] = find_set(parent[v]);*/ } void union_sets(int a, int b) { /*a = find_set(a); b = find_set(b); if (a != b) { if (size[a] < size[b]) swap(a, b); parent[b] = a; size[a] += size[b]; }*/ } int32_t main() { IOS #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif /* int T,hh=0; cin>>T; while(T--) { } */ int n, i, j; cin >> n; ld a[n], x; ld m = 1; for (i = 0; i < n; i++) { cin >> a[i]; m *= a[i]; } ld g[n + 1][n + 1]; for (i = 0; i <= n; i++) { g[i][0] = 0; } for (i = 1; i <= n; i++) { g[1][i] = g[1][i - 1] + (m / a[i - 1]) * (1 - a[i - 1]); } for (i = 2; i <= n / 2; i++) { for (j = i; j <= n; j++) { g[i][j - i + 1] = g[i][j - i] + (g[i - 1][j - i + 1] / a[j - 1]) * (1 - a[j - 1]); } } ld s = m; for (i = 1; i <= n / 2; i++) { s += g[i][n - i + 1]; } cout << fixed << setprecision(10) << s << endl; return 0; }
// Write correct codes,then there is no need to debug // Implement after solving several problems // - GENNADY KOROTKEVICH #include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define ll long long #define ld long double #define int int64_t #define be(v) v.begin(), v.end() #define ff(i, n) for (int i = 0; i < n; i++) #define ii(it, v) for (auto it = v.begin(); it != v.end(); it++) #define vii vector<vector<int>> #define vi vector<int> #define vP vector<pair<int, int>> #define P pair<int, int> #define case \ cout << "Case #" << hh + 1 << ": "; \ hh++; // int T;cin>>T;int hh=0;while(T--) #define fi first #define se second #define endl "\n" #define mem(a, b) memset(a, b, sizeof(a)) #define sf(n) scanf("%d", &n) #define sff(a, b) scanf("%d %d", &a, &b) #define sfff(a, b, c) scanf("%d %d %d", &a, &b, &c) #define pfn(n) printf("%d\n", n) #define pfs(n) printf("%d ", n) #define H (ll)(1e9 + 7) #define bg (ll)998244353 bool *Seive(ll n, bool *p) // boolean 1 means prime { /* bool p[21]; //write this in main() *p=Seive(20,p); //replace 20 by the given value */ mem(p, 1); ll i, j; for (i = 2; i <= n; i++) { if (p[i] == 1) for (j = i * i; j <= n; j += i) { p[j] = 0; } } p[1] = 0; return p; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll modexp(ll x, ll y) // x^y//Inverse modulo where y=H-2(use when H is prime) { if (y == 0) return 1; else if (y % 2 == 0) { return modexp((x * x) % H, y / 2); } else { return (x * modexp((x * x) % H, (y - 1) / 2)) % H; } } ll fact(ll n) // n! { ll f = 1; for (ll i = 2; i <= n; i++) { f = (i % H * f % H) % H; } return f; } ll nCr(ll n, ll r) { return (fact(n) * modexp((fact(n - r) * fact(r)) % H, H - 2)) % H; } void showlist(list<int> g) { list<int>::iterator it; for (it = g.begin(); it != g.end(); ++it) cout << *it << " "; cout << '\n'; } void swap(int &a, int &b) { int t; t = a; a = b; b = t; } // Segment tree Functions void build(int l, int r, int i) // array 'a[4*n+4]' is the segment tree { if (l == r) { // a[i]++; } else { int mid = (l + r) / 2; build(l, mid, 2 * i); build(mid + 1, r, 2 * i + 1); // a[i]=a[2*i]+a[2*i+1]; } } // in main() : build(0,n-1,1); void update(int p, int l, int r, int i) // update at position 'p' { if (l == r) { // a[i]--; // a[i]++; } else { int mid = (l + r) / 2; if (p <= mid) { update(p, l, mid, 2 * i); } else { update(p, mid + 1, r, 2 * i + 1); } // a[i]--; // a[i]++; } } // in main(): update(p,0,n-1,1); void query(int y, int z, int l, int r, int i) // query: find ans for range y to z { if (y <= l && z >= r) { } else { int mid = (l + r) / 2; if (z <= mid) { query(y, z, l, mid, 2 * i); } else if (y > mid) { query(y, z, mid + 1, r, 2 * i + 1); } else { query(y, z, l, mid, 2 * i); query(y, z, mid + 1, r, 2 * i + 1); } } } // in main(): query(y,z,0,n-1); // dsu Functions void make_set(int v) { /* parent[v] = v; size[v] = 1;*/ } int find_set(int v) { /*if (v == parent[v]) return v; return parent[v] = find_set(parent[v]);*/ } void union_sets(int a, int b) { /*a = find_set(a); b = find_set(b); if (a != b) { if (size[a] < size[b]) swap(a, b); parent[b] = a; size[a] += size[b]; }*/ } int32_t main() { IOS /* int T,hh=0; cin>>T; while(T--) { } */ int n, i, j; cin >> n; ld a[n], x; ld m = 1; for (i = 0; i < n; i++) { cin >> a[i]; m *= a[i]; } ld g[n + 1][n + 1]; for (i = 0; i <= n; i++) { g[i][0] = 0; } for (i = 1; i <= n; i++) { g[1][i] = g[1][i - 1] + (m / a[i - 1]) * (1 - a[i - 1]); } for (i = 2; i <= n / 2; i++) { for (j = i; j <= n; j++) { g[i][j - i + 1] = g[i][j - i] + (g[i - 1][j - i + 1] / a[j - 1]) * (1 - a[j - 1]); } } ld s = m; for (i = 1; i <= n / 2; i++) { s += g[i][n - i + 1]; } cout << fixed << setprecision(10) << s << endl; return 0; }
replace
168
181
168
178
-11
p03168
C++
Runtime Error
// turmak-_- #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define nl "\n" #define IOI return 0; #define pb push_back #define ll long long #define ld long double #define IOS \ ios_base ::sync_with_stdio(NULL); \ cin.tie(0); \ cout.tie(0); #define pii pair<int, int> #define X first #define Y second using namespace std; const int N = (int)2e5 + 7; const int MOD = (int)1e9 + 7; const int INF = (int)1e9 + 7; const int UNDEF = -1; pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; double p[301]; double dp[301]; int main() { IOS // freopen("lepus.in", "r", stdin); // freopen("lepus.out", "w", stdout); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; dp[0] = 1.0; for (int i = 1; i <= n; ++i) { for (int j = i; j >= 0; --j) { dp[j] = dp[j - 1] * p[i] + dp[j] * (1.0 - p[i]); } } double ans = 0.0; for (int i = 0; i <= n; ++i) { if (i > n - i) { ans += dp[i]; } } cout << setprecision(9) << fixed << ans; IOI }
// turmak-_- #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define nl "\n" #define IOI return 0; #define pb push_back #define ll long long #define ld long double #define IOS \ ios_base ::sync_with_stdio(NULL); \ cin.tie(0); \ cout.tie(0); #define pii pair<int, int> #define X first #define Y second using namespace std; const int N = (int)2e5 + 7; const int MOD = (int)1e9 + 7; const int INF = (int)1e9 + 7; const int UNDEF = -1; pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; double p[3001]; double dp[3001]; int main() { IOS // freopen("lepus.in", "r", stdin); // freopen("lepus.out", "w", stdout); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; dp[0] = 1.0; for (int i = 1; i <= n; ++i) { for (int j = i; j >= 0; --j) { dp[j] = dp[j - 1] * p[i] + dp[j] * (1.0 - p[i]); } } double ans = 0.0; for (int i = 0; i <= n; ++i) { if (i > n - i) { ans += dp[i]; } } cout << setprecision(9) << fixed << ans; IOI }
replace
25
27
25
27
0
p03168
C++
Time Limit Exceeded
// Copyright © 2020 Pradeep Singh. All rights reserved. /* Zeckendrof's theorem : Each positive number can be represented as a sum of three fibonacci numbers such that no two consecutive fib number is used. binomial : C(n,r) = C(n-1,r-1)+C(n-1,r) , C(n,0)=1 catalan : C(2*n,n)/(n+1); */ #include <algorithm> #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define str(a) to_string(a) #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define SORT(c) sort(c.begin(), c.end()) #define mod 1000000007 #define max_heap priority_queue<int> #define min_heap priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcount(x) #define ps(x, y) fixed << setprecision(y) << x #define start(t) \ int x; \ cin >> x; \ while (x--) #define inf LLONG_MAX mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define endl "\n" vector<vector<double>> dp(3001, vector<double>(3001, -1)); double rec(int i, int heads, vector<double> &prob) { if (heads == 0) return 1; if (i == 0) return 0; if (dp[i][heads] > -0.9) return dp[i][heads]; return rec(i - 1, heads - 1, prob) * prob[i] + rec(i - 1, heads, prob) * (1 - prob[i]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector<double> prob(n + 1); // cerr << dp.size() << " " << for (int i = 1; i <= n; i++) cin >> prob[i]; cout << ps(rec(n, (n + 1) / 2, prob), 10) << endl; }
// Copyright © 2020 Pradeep Singh. All rights reserved. /* Zeckendrof's theorem : Each positive number can be represented as a sum of three fibonacci numbers such that no two consecutive fib number is used. binomial : C(n,r) = C(n-1,r-1)+C(n-1,r) , C(n,0)=1 catalan : C(2*n,n)/(n+1); */ #include <algorithm> #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define str(a) to_string(a) #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define SORT(c) sort(c.begin(), c.end()) #define mod 1000000007 #define max_heap priority_queue<int> #define min_heap priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcount(x) #define ps(x, y) fixed << setprecision(y) << x #define start(t) \ int x; \ cin >> x; \ while (x--) #define inf LLONG_MAX mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define endl "\n" vector<vector<double>> dp(3001, vector<double>(3001, -1)); double rec(int i, int heads, vector<double> &prob) { if (heads == 0) return 1; if (i == 0) return 0; if (dp[i][heads] > -0.9) return dp[i][heads]; return dp[i][heads] = rec(i - 1, heads - 1, prob) * prob[i] + rec(i - 1, heads, prob) * (1 - prob[i]); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector<double> prob(n + 1); // cerr << dp.size() << " " << for (int i = 1; i <= n; i++) cin >> prob[i]; cout << ps(rec(n, (n + 1) / 2, prob), 10) << endl; }
replace
42
44
42
44
TLE
p03168
C++
Runtime Error
#pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long int typedef complex<long double> cd; const long double pi = acos(-1); typedef double db; typedef long double ldb; typedef pair<int, int> pii; typedef pair<db, db> pdd; typedef vector<int> vi; typedef vector<vector<int>> matrix; #define m1 make_pair #define pb push_back #define flush fflush(stdout) #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define reset(x, v) memset(x, v, sizeof(x)) #define fi first #define se second #define endl "\n" #define debug(x) (cerr << #x << ": " << x << "\n") #define setbits(x) __builtin_popcount(x) #define setbitsll(x) __builtin_popcountll(x) #define all(x) x.begin(), x.end() #define pii pair<int, int> inline ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } inline ll power(ll a, ll n, ll m) { if (n == 0) return 1; ll p = power(a, n / 2, m); p = (p % m * p % m) % m; if (n % 2) return (p % m * a % m) % m; else return p; } const double EPS = 1e-9; const ll MOD = 998244353; const ll hell = 1000000007; const int INF = 1e18; const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); std::mt19937 rng(seed); double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; const int N = 100005; ldb dp[3000][300]; void solve() { int n; cin >> n; ldb p[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (!j) dp[i][j] = (1 - p[i]) * dp[i - 1][j]; else dp[i][j] = (1 - p[i]) * dp[i - 1][j] + p[i] * dp[i - 1][j - 1]; } } cout << setprecision(20); ldb ans = 0; for (int i = (n + 1) / 2; i <= n; i++) ans = ans + dp[n][i]; cout << ans << endl; } int32_t main() { IOS; int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; typedef long long ll; #define int long long int typedef complex<long double> cd; const long double pi = acos(-1); typedef double db; typedef long double ldb; typedef pair<int, int> pii; typedef pair<db, db> pdd; typedef vector<int> vi; typedef vector<vector<int>> matrix; #define m1 make_pair #define pb push_back #define flush fflush(stdout) #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define reset(x, v) memset(x, v, sizeof(x)) #define fi first #define se second #define endl "\n" #define debug(x) (cerr << #x << ": " << x << "\n") #define setbits(x) __builtin_popcount(x) #define setbitsll(x) __builtin_popcountll(x) #define all(x) x.begin(), x.end() #define pii pair<int, int> inline ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } inline ll power(ll a, ll n, ll m) { if (n == 0) return 1; ll p = power(a, n / 2, m); p = (p % m * p % m) % m; if (n % 2) return (p % m * a % m) % m; else return p; } const double EPS = 1e-9; const ll MOD = 998244353; const ll hell = 1000000007; const int INF = 1e18; const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); std::mt19937 rng(seed); double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; const int N = 100005; ldb dp[3000][3000]; void solve() { int n; cin >> n; ldb p[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (!j) dp[i][j] = (1 - p[i]) * dp[i - 1][j]; else dp[i][j] = (1 - p[i]) * dp[i - 1][j] + p[i] * dp[i - 1][j - 1]; } } cout << setprecision(20); ldb ans = 0; for (int i = (n + 1) / 2; i <= n; i++) ans = ans + dp[n][i]; cout << ans << endl; } int32_t main() { IOS; int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
77
78
77
78
0
p03168
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define ll long long int #define mt make_tuple #define pb push_back const int N = 1e3 + 10; double dp[N][N], p[N]; int main() { int n; double ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= n; i++) dp[0][i] = 0; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i]); else dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * (p[i]); } } for (int i = (n / 2) + 1; i <= n; i++) ans += dp[n][i]; cout.precision(12); cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define mt make_tuple #define pb push_back const int N = 3010; double dp[N][N], p[N]; int main() { int n; double ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= n; i++) dp[0][i] = 0; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i]); else dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * (p[i]); } } for (int i = (n / 2) + 1; i <= n; i++) ans += dp[n][i]; cout.precision(12); cout << ans << endl; return 0; }
replace
5
6
5
6
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; double dp[110][110]; int main() { int n; cin >> n; vector<double> p(n + 1); for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= n; i++) dp[0][i] = 1; for (int i = 1; i <= n; i++) for (int x = 0; x <= i; x++) if (!x) dp[x][i] = (1 - p[i]) * dp[x][i - 1]; else dp[x][i] = (1 - p[i]) * dp[x][i - 1] + p[i] * dp[x - 1][i - 1]; double ans = 0; for (int x = 1; x <= n; x++) if (x + x > n) ans += dp[x][n]; printf("%.9lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double dp[3001][3001]; int main() { int n; cin >> n; vector<double> p(n + 1); for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= n; i++) dp[0][i] = 1; for (int i = 1; i <= n; i++) for (int x = 0; x <= i; x++) if (!x) dp[x][i] = (1 - p[i]) * dp[x][i - 1]; else dp[x][i] = (1 - p[i]) * dp[x][i - 1] + p[i] * dp[x - 1][i - 1]; double ans = 0; for (int x = 1; x <= n; x++) if (x + x > n) ans += dp[x][n]; printf("%.9lf\n", ans); return 0; }
replace
3
4
3
4
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 100; int n; double a[maxn], dp[maxn][maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] += dp[i - 1][j - 1] * a[i]; } for (int j = 0; j <= i; j++) { dp[i][j] += dp[i - 1][j] * (1 - a[i]); } } double ans = 0; for (int i = 1; i <= n; i++) { if (i > n - i) ans += dp[n][i]; } printf("%.20f\n", ans); }
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 100; int n; double a[maxn], dp[maxn][maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] += dp[i - 1][j - 1] * a[i]; } for (int j = 0; j <= i; j++) { dp[i][j] += dp[i - 1][j] * (1 - a[i]); } } double ans = 0; for (int i = 1; i <= n; i++) { if (i > n - i) ans += dp[n][i]; } printf("%.20f\n", ans); }
replace
2
3
2
3
0
p03168
C++
Runtime Error
#include <cassert> #include <cstdio> int n, licz; long double start; long double tab[3003][3003]; long double res; long double chance(int t, long double x, long double y) { if (t == 0) return (1.0 - x) * (1.0 - y); if (t == 1) return 1.0 - (1.0 - x) * (1.0 - y) - x * y; else return x * y; } // 0 -> -n/2 // 1 -> -n/2+1 // n/2 -> -1 // n/2+1 -> 1... int main() { scanf("%d", &n); scanf("%Lf", &start); tab[0][n / 2] = 1.0 - start; tab[0][n / 2 + 1] = start; for (int i = 0; i < n / 2; i++) { ++licz; long double x, y; scanf("%Lf %Lf", &x, &y); tab[licz][0] = tab[licz - 1][0] * chance(1, x, y) + tab[licz - 1][1] * chance(0, x, y); for (int j = 1; j <= n; j++) { tab[licz][j] = tab[licz - 1][j - 1] * chance(2, x, y) + tab[licz - 1][j] * chance(1, x, y) + tab[licz - 1][j + 1] * chance(0, x, y); } } for (int i = n / 2 + 1; i <= n; i++) { res += tab[licz][i]; } assert(res <= 1); printf("%.10Lf\n", res); }
#include <cassert> #include <cstdio> int n, licz; long double start; long double tab[3003][3003]; long double res; long double chance(int t, long double x, long double y) { if (t == 0) return (1.0 - x) * (1.0 - y); if (t == 1) return 1.0 - (1.0 - x) * (1.0 - y) - x * y; else return x * y; } // 0 -> -n/2 // 1 -> -n/2+1 // n/2 -> -1 // n/2+1 -> 1... int main() { scanf("%d", &n); scanf("%Lf", &start); tab[0][n / 2] = 1.0 - start; tab[0][n / 2 + 1] = start; for (int i = 0; i < n / 2; i++) { ++licz; long double x, y; scanf("%Lf %Lf", &x, &y); tab[licz][0] = tab[licz - 1][0] * chance(1, x, y) + tab[licz - 1][1] * chance(0, x, y); for (int j = 1; j <= n; j++) { tab[licz][j] = tab[licz - 1][j - 1] * chance(2, x, y) + tab[licz - 1][j] * chance(1, x, y) + tab[licz - 1][j + 1] * chance(0, x, y); } } for (int i = n / 2 + 1; i <= n; i++) { res += tab[licz][i]; } // assert(res<=1); printf("%.10Lf\n", res); }
replace
44
45
44
45
-11
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; const int MAX = 3010; double moedas[MAX]; double memo[MAX][MAX]; double pd(int i, int k) { if (i >= n) return k >= (n / 2 + 1); if (memo[i][k] != -1.0) return memo[i][k]; return ((1.0 - moedas[i]) * pd(i + 1, k)) + (moedas[i] * pd(i + 1, k + 1)); } int main() { cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { memo[i][j] = -1.0; } } for (int i = 0; i < n; ++i) { cin >> moedas[i]; } double ans = pd(0, 0); printf("%.10f\n", ans); }
#include <bits/stdc++.h> using namespace std; int n; const int MAX = 3010; double moedas[MAX]; double memo[MAX][MAX]; double pd(int i, int k) { if (i >= n) return k >= (n / 2 + 1); if (memo[i][k] != -1.0) return memo[i][k]; return memo[i][k] = ((1.0 - moedas[i]) * pd(i + 1, k)) + (moedas[i] * pd(i + 1, k + 1)); } int main() { cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { memo[i][j] = -1.0; } } for (int i = 0; i < n; ++i) { cin >> moedas[i]; } double ans = pd(0, 0); printf("%.10f\n", ans); }
replace
13
14
13
15
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define endl '\n' #define pb push_back #define mp make_pair #define sp(x) fixed << setprecision(x) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // vector<vector<double>> dp(3001,vector<double>(3001,-1)); double dp[3001][3001]; double fun(vector<double> &p, int i, int atleast_heads) { // Base case if (atleast_heads == 0) return 1; if (i == 0) return 0; // Lookup if (dp[i][atleast_heads] > -0.9) return dp[i][atleast_heads]; // Rec case // double op1 = p[i]*fun(p,i-1,atleast_heads-1); // double op2 = (1-p[i])*fun(p,i-1,atleast_heads); return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) + (1 - p[i]) * fun(p, i - 1, atleast_heads); } int main() { fast_io; memset(dp, -1, sizeof(dp)); int n; cin >> n; vector<double> p(n); for (int i = 1; i <= n; i++) cin >> p[i]; cout << sp(10) << fun(p, n, (n + 1) / 2) << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define endl '\n' #define pb push_back #define mp make_pair #define sp(x) fixed << setprecision(x) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // vector<vector<double>> dp(3001,vector<double>(3001,-1)); double dp[3001][3001]; double fun(vector<double> &p, int i, int atleast_heads) { // Base case if (atleast_heads == 0) return 1; if (i == 0) return 0; // Lookup if (dp[i][atleast_heads] > -0.9) return dp[i][atleast_heads]; // Rec case // double op1 = p[i]*fun(p,i-1,atleast_heads-1); // double op2 = (1-p[i])*fun(p,i-1,atleast_heads); return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) + (1 - p[i]) * fun(p, i - 1, atleast_heads); } int main() { fast_io; memset(dp, -1, sizeof(dp)); int n; cin >> n; vector<double> p(n + 1); for (int i = 1; i <= n; i++) cin >> p[i]; cout << sp(10) << fun(p, n, (n + 1) / 2) << endl; return 0; }
replace
42
43
42
43
-6
munmap_chunk(): invalid pointer
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<ll, ll>; const int MAXN = 3030; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int n, t, h; double p[MAXN]; map<int, double> dp[MAXN]; double solve(int i, int h) { if (i == n) { if (h > n - h) return 1; return 0; } if (dp[i].count(h)) return dp[i][h]; return dp[i][h] = p[i] * solve(i + 1, h + 1) + (1 - p[i]) * solve(i + 1, h); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << setprecision(10) << fixed; cin >> n; for (int i = 0; i < n; ++i) { cin >> p[i]; } cout << solve(0, 0) << endl; return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<ll, ll>; const int MAXN = 3030; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int n, t, h; double p[MAXN]; unordered_map<int, double> dp[MAXN]; double solve(int i, int h) { if (i == n) { if (h > n - h) return 1; return 0; } if (dp[i].count(h)) return dp[i][h]; return dp[i][h] = p[i] * solve(i + 1, h + 1) + (1 - p[i]) * solve(i + 1, h); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << setprecision(10) << fixed; cin >> n; for (int i = 0; i < n; ++i) { cin >> p[i]; } cout << solve(0, 0) << endl; return 0; }
replace
43
44
43
44
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF (1 << 29) #define INFF 0x7fffffff #define LINF (1ll << 60) #define LINFF 0x7fffffffffffffff #define PI 3.14159265359 #define _fi(n) for (int i = 0; i < n; i++) #define _fj(n) for (int j = 0; j < n; j++) #define _fk(n) for (int k = 0; k < n; k++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define prec(x) cout << fixed << setprecision(x) #define hash sodnf9843bsd #define ll long long #define pqueue priority_queue #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); } int n; double p[3003] = {}; double dp[3003][3003] = {}; bool vis[3003][3003] = {}; double full = 1; double solve(int i, int j) { if (i == n) { if (j > n / 2) return 1; return 0; } if (vis[i][j] == false) { dp[i][j] = (1. - p[i]) * solve(i + 1, j) + p[i] * solve(i + 1, j + 1); } return dp[i][j]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; _fi(n) { cin >> p[i]; full *= p[i]; } prec(10); cout << solve(0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF (1 << 29) #define INFF 0x7fffffff #define LINF (1ll << 60) #define LINFF 0x7fffffffffffffff #define PI 3.14159265359 #define _fi(n) for (int i = 0; i < n; i++) #define _fj(n) for (int j = 0; j < n; j++) #define _fk(n) for (int k = 0; k < n; k++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define prec(x) cout << fixed << setprecision(x) #define hash sodnf9843bsd #define ll long long #define pqueue priority_queue #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); } int n; double p[3003] = {}; double dp[3003][3003] = {}; bool vis[3003][3003] = {}; double full = 1; double solve(int i, int j) { if (i == n) { if (j > n / 2) return 1; return 0; } if (vis[i][j] == false) { vis[i][j] = true; dp[i][j] = (1. - p[i]) * solve(i + 1, j) + p[i] * solve(i + 1, j + 1); } return dp[i][j]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; _fi(n) { cin >> p[i]; full *= p[i]; } prec(10); cout << solve(0, 0) << endl; return 0; }
insert
43
43
43
44
TLE
p03168
C++
Time Limit Exceeded
/* "miles to go before I sleep." */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 #define pi 3.14159265358979323846 #define pb push_back #define mk make_pair #define popcnt(a) \ _Generic((a), int \ : __builtin_popcount(a), \ long long \ : __builtin_popcountll(a)) #define precise(x) cout << fixed << setprecision(10) << x #define test cout << "#"; #define input freopen("input.txt", "r", stdin) #define output freopen("output.txt", "w", stdout) const ll inf = 1e18L + 2; double dp[3001][3001]; double solve(vector<double> &v, ll n, ll x) { if (x == 0) return 1; if (n == 0) return 0; if (dp[n][x] >= -0.9) dp[n][x]; return dp[n][x] = solve(v, n - 1, x - 1) * v[n - 1] + solve(v, n - 1, x) * (1 - v[n - 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vector<double> v(n); for (ll x = 0; x < n; x++) cin >> v[x]; memset(dp, -1, sizeof(dp)); precise(solve(v, n, (n + 2) / 2)); }
/* "miles to go before I sleep." */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 #define pi 3.14159265358979323846 #define pb push_back #define mk make_pair #define popcnt(a) \ _Generic((a), int \ : __builtin_popcount(a), \ long long \ : __builtin_popcountll(a)) #define precise(x) cout << fixed << setprecision(10) << x #define test cout << "#"; #define input freopen("input.txt", "r", stdin) #define output freopen("output.txt", "w", stdout) const ll inf = 1e18L + 2; double dp[3001][3001]; double solve(vector<double> &v, ll n, ll x) { if (x == 0) return 1; if (n == 0) return 0; if (dp[n][x] >= -0.9) return dp[n][x]; return dp[n][x] = solve(v, n - 1, x - 1) * v[n - 1] + solve(v, n - 1, x) * (1 - v[n - 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vector<double> v(n); for (ll x = 0; x < n; x++) cin >> v[x]; memset(dp, -1, sizeof(dp)); precise(solve(v, n, (n + 2) / 2)); }
replace
29
30
29
30
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<double> p(n, 0); vector<vector<double>> pb = vector<vector<double>>(n + 1, vector<double>(n + 1, 0)); pb[0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%lf", &p[i]); for (int j = 0; j < i; j++) { if (pb[i - 1][j] <= 1e-14) { continue; } pb[i][j] += pb[i - 1][j] * (1 - p[i]); pb[i][j + 1] += pb[i - 1][j] * p[i]; } } double r = 0; for (int j = n / 2 + 1; j <= n; j++) { r += pb[n][j]; } printf("%.10lf", r); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<double> p(n + 1, 0); vector<vector<double>> pb = vector<vector<double>>(n + 1, vector<double>(n + 1, 0)); pb[0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%lf", &p[i]); for (int j = 0; j < i; j++) { if (pb[i - 1][j] <= 1e-14) { continue; } pb[i][j] += pb[i - 1][j] * (1 - p[i]); pb[i][j + 1] += pb[i - 1][j] * p[i]; } } double r = 0; for (int j = n / 2 + 1; j <= n; j++) { r += pb[n][j]; } printf("%.10lf", r); return 0; }
replace
7
8
7
8
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define ll long long int #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define MOD 1000000007 #define pb push_back #define S second #define F first #define P pair<ll, ll> #define PI 3.1415926535897932384626433832795028 // #define ordered_set tree<ll, null_type,less_equal<>, // rb_tree_tag,tree_order_statistics_node_update> int mul(int a, int b) { return (long long)a * b % MOD; } int power(int a, int b) { int ans = 1; while (b > 0) { if (b & 1) ans = mul(ans, a); a = mul(a, a); b >>= 1; } return ans; } // bitset<400000010> b; // ll n=100000; ll p[1000100] = {0}; vector<ll> v[1000000]; void sieve(ll n) { for (ll i = 2; i * i <= n; i++) { if (!p[i]) // primes.push_back(i); for (ll j = i; j <= n; j += i) { if (i != j) ; p[j] = 1; } } } // ll nextPowerOf2(ll n) // { // ll p = 1; // if (n && !(n & (n - 1))) // return n; // while (p < n) // p <<= 1; // return p; // } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { if (n == 0) return 1; return n * factorial(n - 1); } struct segmenttree { vector<int> st; int n; void init(int _n) { n = _n; st.clear(); st.resize(4 * _n, 0); } void update(int l, int r, int indup, int val, int node) { if (l == r) { st[node] += val; return; } else { int mid = (l + r) / 2; if (indup >= l && indup <= mid) { update(l, mid, indup, val, node * 2 + 1); } else { update(mid + 1, r, indup, val, node * 2 + 2); } st[node] = st[2 * node + 1] + st[2 * node + 2]; } } int query(int si, int se, int l, int r, int node) { if (se < l || si > r || l > r) { return 0; } if (si >= l && se <= r) { return st[node]; } int mid = (si + se) / 2; int q1 = query(si, mid, l, r, node * 2 + 1); int q2 = query(mid + 1, se, l, r, node * 2 + 2); return q1 + q2; } int query(int l, int r) { return query(0, n - 1, l, r, 0); } void update(int index, int val) { update(0, n - 1, index, val, 0); } } tree; bool chkcow(ll n, vector<ll> &a, ll k, ll mis) { ll sum = 0; for (ll i = 0; i < n; i++) { if (a[i] > mis) sum += a[i] - mis; if (sum >= k) return true; } return false; } struct cmp { bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b) const { ll lena = a.S - a.F; ll lenb = b.S - b.F; if (lena == lenb) return a.F < b.F; return lena > lenb; } }; double dp[3001][3001]; double solv(vector<double> &a, ll i, ll j) { if (j == 0) return 1; if (i == 0) return 0; if (dp[i][j] <= -0.9) return dp[i][j]; return dp[i][j] = a[i] * solv(a, i - 1, j - 1) + (1 - a[i]) * solv(a, i - 1, j); } int32_t main() { fast // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif // ll t; // cin >> t; // while (t--) { ll n; cin >> n; memset(dp, -1, sizeof dp); vector<double> a(n + 1); for (ll i = 1; i <= n; i++) { cin >> a[i]; } cout << fixed << setprecision(10) << solv(a, n, (n + 1) / 2); return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define ll long long int #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define MOD 1000000007 #define pb push_back #define S second #define F first #define P pair<ll, ll> #define PI 3.1415926535897932384626433832795028 // #define ordered_set tree<ll, null_type,less_equal<>, // rb_tree_tag,tree_order_statistics_node_update> int mul(int a, int b) { return (long long)a * b % MOD; } int power(int a, int b) { int ans = 1; while (b > 0) { if (b & 1) ans = mul(ans, a); a = mul(a, a); b >>= 1; } return ans; } // bitset<400000010> b; // ll n=100000; ll p[1000100] = {0}; vector<ll> v[1000000]; void sieve(ll n) { for (ll i = 2; i * i <= n; i++) { if (!p[i]) // primes.push_back(i); for (ll j = i; j <= n; j += i) { if (i != j) ; p[j] = 1; } } } // ll nextPowerOf2(ll n) // { // ll p = 1; // if (n && !(n & (n - 1))) // return n; // while (p < n) // p <<= 1; // return p; // } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { if (n == 0) return 1; return n * factorial(n - 1); } struct segmenttree { vector<int> st; int n; void init(int _n) { n = _n; st.clear(); st.resize(4 * _n, 0); } void update(int l, int r, int indup, int val, int node) { if (l == r) { st[node] += val; return; } else { int mid = (l + r) / 2; if (indup >= l && indup <= mid) { update(l, mid, indup, val, node * 2 + 1); } else { update(mid + 1, r, indup, val, node * 2 + 2); } st[node] = st[2 * node + 1] + st[2 * node + 2]; } } int query(int si, int se, int l, int r, int node) { if (se < l || si > r || l > r) { return 0; } if (si >= l && se <= r) { return st[node]; } int mid = (si + se) / 2; int q1 = query(si, mid, l, r, node * 2 + 1); int q2 = query(mid + 1, se, l, r, node * 2 + 2); return q1 + q2; } int query(int l, int r) { return query(0, n - 1, l, r, 0); } void update(int index, int val) { update(0, n - 1, index, val, 0); } } tree; bool chkcow(ll n, vector<ll> &a, ll k, ll mis) { ll sum = 0; for (ll i = 0; i < n; i++) { if (a[i] > mis) sum += a[i] - mis; if (sum >= k) return true; } return false; } struct cmp { bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b) const { ll lena = a.S - a.F; ll lenb = b.S - b.F; if (lena == lenb) return a.F < b.F; return lena > lenb; } }; double dp[3001][3001]; double solv(vector<double> &a, ll i, ll j) { if (j == 0) return 1; if (i == 0) return 0; if (dp[i][j] >= -0.9) return dp[i][j]; return dp[i][j] = a[i] * solv(a, i - 1, j - 1) + (1 - a[i]) * solv(a, i - 1, j); } int32_t main() { fast // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif // ll t; // cin >> t; // while (t--) { ll n; cin >> n; memset(dp, -1, sizeof dp); vector<double> a(n + 1); for (ll i = 1; i <= n; i++) { cin >> a[i]; } cout << fixed << setprecision(10) << solv(a, n, (n + 1) / 2); return 0; }
replace
135
136
135
136
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #if defined __has_include #if __has_include(<bits/debug_aamir.h>) #define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__); #include <bits/debug_aamir.h> #else #define dbg(...) #endif #endif typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef long long ll; typedef pair<ll, ll> pll; #define sz(x) int(x.size()) #define eb emplace_back #define mp make_pair #define mt make_tuple #define rep(i, begin, end) for (__typeof(end) i = begin; i < end; i++) #define per(i, begin, end) for (__typeof(end) i = begin; i >= end; i--) #define fi first #define se second #define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) constexpr int INF = 1e9 + 1; constexpr ll LLINF = 1e18 + 1; template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } const int nax = 30005; vector<vector<double>> dp(nax, vector<double>(nax)); vector<double> p(nax); int main() { fastio; int n; cin >> n; rep(i, 0, n) cin >> p[i]; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; rep(i, 0, n - 1) { rep(j, 0, n) { dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]); dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; } } double ans = 0; rep(i, (n + 1) / 2, n + 1) ans += dp[n - 1][i]; dbg(p); rep(i, 0, n) dbg(dp[i]); printf("%.10lf\n", ans); }
#include <bits/stdc++.h> using namespace std; #if defined __has_include #if __has_include(<bits/debug_aamir.h>) #define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__); #include <bits/debug_aamir.h> #else #define dbg(...) #endif #endif typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef long long ll; typedef pair<ll, ll> pll; #define sz(x) int(x.size()) #define eb emplace_back #define mp make_pair #define mt make_tuple #define rep(i, begin, end) for (__typeof(end) i = begin; i < end; i++) #define per(i, begin, end) for (__typeof(end) i = begin; i >= end; i--) #define fi first #define se second #define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) constexpr int INF = 1e9 + 1; constexpr ll LLINF = 1e18 + 1; template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } const int nax = 3005; vector<vector<double>> dp(nax, vector<double>(nax)); vector<double> p(nax); int main() { fastio; int n; cin >> n; rep(i, 0, n) cin >> p[i]; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; rep(i, 0, n - 1) { rep(j, 0, n) { dp[i + 1][j] += dp[i][j] * (1 - p[i + 1]); dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; } } double ans = 0; rep(i, (n + 1) / 2, n + 1) ans += dp[n - 1][i]; dbg(p); rep(i, 0, n) dbg(dp[i]); printf("%.10lf\n", ans); }
replace
31
32
31
32
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; #define INF ((1 << 30) - 1) #define LLINF (1LL << 60) #define EPS (1e-10) // 分解 // dp[i][j] := i番目までのコインを投げて,表がちょうどj枚になる確率 double dp[3030][3030]; // dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j]) // 排反 // i枚目に表が出る確率 dp[i-1][j-1] * p[j] // i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j]) int main() { int N; cin >> N; vector<double> p(N); rep(i, N) cin >> p[i + 1]; dp[0][0] = 1.0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= i; ++j) { if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1] * p[i]; dp[i][j] += dp[i - 1][j] * (1 - p[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { if (i > N - i) ans += dp[N][i]; } printf("%.15lf\n", ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; #define INF ((1 << 30) - 1) #define LLINF (1LL << 60) #define EPS (1e-10) // 分解 // dp[i][j] := i番目までのコインを投げて,表がちょうどj枚になる確率 double dp[3030][3030]; // dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j]) // 排反 // i枚目に表が出る確率 dp[i-1][j-1] * p[j] // i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j]) int main() { int N; cin >> N; vector<double> p(N + 1); rep(i, N) cin >> p[i + 1]; dp[0][0] = 1.0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= i; ++j) { if (j - 1 >= 0) dp[i][j] += dp[i - 1][j - 1] * p[i]; dp[i][j] += dp[i - 1][j] * (1 - p[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { if (i > N - i) ans += dp[N][i]; } printf("%.15lf\n", ans); }
replace
23
24
23
24
-6
munmap_chunk(): invalid pointer
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; #define INF ((1 << 30) - 1) #define LLINF (1LL << 60) #define EPS (1e-10) // どういうDPか // dp[i][j] := i枚目のコインを投げたとき,表がj枚である確率 // 計算方法 // 1-index // dp[0][0] = 1.0 // dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i])) // 表が出ることと,出なかったことで場合分け // どういう順番 // 小さい順から // j > N-j のときの総和 double dp[3030][3030]; int main() { int N; cin >> N; vector<double> p(N); rep(i, N) cin >> p[i + 1]; dp[0][0] = 1.0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= N; ++j) { if (j > 0) { dp[i][j] += dp[i - 1][j - 1] * p[i]; } dp[i][j] += dp[i - 1][j] * (1 - p[i]); // dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { if (i > N - i) ans += dp[N][i]; } printf("%.10f\n", ans); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; #define INF ((1 << 30) - 1) #define LLINF (1LL << 60) #define EPS (1e-10) // どういうDPか // dp[i][j] := i枚目のコインを投げたとき,表がj枚である確率 // 計算方法 // 1-index // dp[0][0] = 1.0 // dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i])) // 表が出ることと,出なかったことで場合分け // どういう順番 // 小さい順から // j > N-j のときの総和 double dp[3030][3030]; int main() { int N; cin >> N; vector<double> p(N + 1); rep(i, N) cin >> p[i + 1]; dp[0][0] = 1.0; for (int i = 1; i <= N; ++i) { for (int j = 0; j <= N; ++j) { if (j > 0) { dp[i][j] += dp[i - 1][j - 1] * p[i]; } dp[i][j] += dp[i - 1][j] * (1 - p[i]); // dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { if (i > N - i) ans += dp[N][i]; } printf("%.10f\n", ans); }
replace
28
29
28
29
-6
munmap_chunk(): invalid pointer
p03168
C++
Runtime Error
#include <iomanip> #include <iostream> using namespace std; const long long MAXN = 1001; double dp[MAXN][MAXN]; double p[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } double ans = 0; for (int i = (n + 1) / 2; i <= n; i++) { ans += dp[n][i]; } cout << setprecision(10) << ans << endl; }
#include <iomanip> #include <iostream> using namespace std; const long long MAXN = 3001; double dp[MAXN][MAXN]; double p[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } double ans = 0; for (int i = (n + 1) / 2; i <= n; i++) { ans += dp[n][i]; } cout << setprecision(10) << ans << endl; }
replace
4
5
4
5
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define N 1005 #define all(v) v.begin(), v.end() #define pii pair<int, int> #define piii pair<int, pii> #define print(x) cout << #x << "=" << x << "\t"; #define endl "\n" #define newline cout << endl; int n; double p[N]; double dp[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][0] = 1 - p[1]; dp[1][1] = p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= i; j++) dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } double ans = 0; for (int j = (n + 1) / 2; j <= n; j++) ans += dp[n][j]; cout << fixed << setprecision(12) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define N 3005 #define all(v) v.begin(), v.end() #define pii pair<int, int> #define piii pair<int, pii> #define print(x) cout << #x << "=" << x << "\t"; #define endl "\n" #define newline cout << endl; int n; double p[N]; double dp[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][0] = 1 - p[1]; dp[1][1] = p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= i; j++) dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } double ans = 0; for (int j = (n + 1) / 2; j <= n; j++) ans += dp[n][j]; cout << fixed << setprecision(12) << ans << endl; return 0; }
replace
4
5
4
5
0
p03168
C++
Runtime Error
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> p; p.resize(n + 1); int i, j, k; for (i = 1; i <= n; i++) cin >> p[i]; vector<vector<double>> prob; prob.resize(n + 1); for (i = 0; i <= n; i++) prob[i].resize(n); prob[1][1] = p[1]; prob[1][0] = 1.0 - p[1]; for (i = 2; i <= n; i++) { prob[i][0] = (1.0 - p[i]) * prob[i - 1][0]; for (j = 1; j <= i; j++) { prob[i][j] = prob[i - 1][j] * (1.0 - p[i]) + prob[i - 1][j - 1] * p[i]; } } double ans = 0.0; int lim = (n + 1) / 2; for (i = lim; i <= n; i++) ans = ans + prob[n][i]; cout << setprecision(12) << ans << endl; return 0; }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> p; p.resize(n + 1); int i, j, k; for (i = 1; i <= n; i++) cin >> p[i]; vector<vector<double>> prob; prob.resize(n + 1); for (i = 0; i <= n; i++) prob[i].resize(n + 1); prob[1][1] = p[1]; prob[1][0] = 1.0 - p[1]; for (i = 2; i <= n; i++) { prob[i][0] = (1.0 - p[i]) * prob[i - 1][0]; for (j = 1; j <= i; j++) { prob[i][j] = prob[i - 1][j] * (1.0 - p[i]) + prob[i - 1][j - 1] * p[i]; } } double ans = 0.0; int lim = (n + 1) / 2; for (i = lim; i <= n; i++) ans = ans + prob[n][i]; cout << setprecision(12) << ans << endl; return 0; }
replace
16
17
16
17
-6
malloc(): corrupted top size
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define ld long double #define fio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define nl '\n' #define pb push_back #define mp make_pair using namespace std; const int N = 1005; ld dp[N][N]; int32_t main() { fio(); int n; cin >> n; ld p[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); dp[0][i] = 0; } cout << fixed << setprecision(15); ld ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] += dp[i - 1][j] * (1 - p[i]); dp[i][j] += dp[i - 1][j - 1] * p[i]; } } /*for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) cout<<dp[i][j]<<" "; cout<<endl; }*/ for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; cout << ans << endl; // cout<<dp[n][m]; }
#include <bits/stdc++.h> #define int long long #define ld long double #define fio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define nl '\n' #define pb push_back #define mp make_pair using namespace std; const int N = 3005; ld dp[N][N]; int32_t main() { fio(); int n; cin >> n; ld p[n + 1]; for (int i = 1; i <= n; i++) cin >> p[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); dp[0][i] = 0; } cout << fixed << setprecision(15); ld ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] += dp[i - 1][j] * (1 - p[i]); dp[i][j] += dp[i - 1][j - 1] * p[i]; } } /*for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) cout<<dp[i][j]<<" "; cout<<endl; }*/ for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; cout << ans << endl; // cout<<dp[n][m]; }
replace
12
13
12
13
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define endl "\n" #define ar array #define pb push_back #define sz(X) ((int)(X).size()) #define ordered_set \ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> #define sort_unique(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define get_pos(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define all(X) (X).begin(), (X).end() #define No cout << "NO" << endl; #define Yes cout << "YES" << endl; #define nl cout << endl; template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out << x << " "; } out << "\n"; return out; } template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out + x; } return out; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (auto &x : vec) { in >> x; } return in; } // DEBUG void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG // compile with -DLOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int mod2 = 998244353; const ll INF = 1e9 + 6; ll add(ll a, ll b) { a += b; return a % mod; } ll mul(ll a, ll b) { a *= b; return a % mod; } inline ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } inline ll modInverse(ll x, ll p) { return power(x, p - 2, p); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int MXN = 1e3 + 1; double p[MXN]; double cache[MXN][MXN]; int n; double dp(int idx, int heads) { if (idx > n) { if (heads > n / 2) return 1; else return 0; } double &ans = cache[idx][heads]; if (ans != -1) { return ans; } ans = dp(idx + 1, heads + 1) * p[idx] + dp(idx + 1, heads) * (1 - p[idx]); return ans; } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 0; i < MXN; i++) { for (int j = 0; j < MXN; ++j) { cache[i][j] = -1; } } cout << fixed << setprecision(10) << dp(1, 0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); // cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " // ms" << '\n'; return 0; } // look if it requires ll
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define endl "\n" #define ar array #define pb push_back #define sz(X) ((int)(X).size()) #define ordered_set \ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> #define sort_unique(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define get_pos(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define all(X) (X).begin(), (X).end() #define No cout << "NO" << endl; #define Yes cout << "YES" << endl; #define nl cout << endl; template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out << x << " "; } out << "\n"; return out; } template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) { for (const auto &x : vec) { out + x; } return out; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (auto &x : vec) { in >> x; } return in; } // DEBUG void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG // compile with -DLOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int mod2 = 998244353; const ll INF = 1e9 + 6; ll add(ll a, ll b) { a += b; return a % mod; } ll mul(ll a, ll b) { a *= b; return a % mod; } inline ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } inline ll modInverse(ll x, ll p) { return power(x, p - 2, p); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int MXN = 3e3 + 1; double p[MXN]; double cache[MXN][MXN]; int n; double dp(int idx, int heads) { if (idx > n) { if (heads > n / 2) return 1; else return 0; } double &ans = cache[idx][heads]; if (ans != -1) { return ans; } ans = dp(idx + 1, heads + 1) * p[idx] + dp(idx + 1, heads) * (1 - p[idx]); return ans; } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 0; i < MXN; i++) { for (int j = 0; j < MXN; ++j) { cache[i][j] = -1; } } cout << fixed << setprecision(10) << dp(1, 0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); // cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " // ms" << '\n'; return 0; } // look if it requires ll
replace
97
98
97
98
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ul unsigned long long int #define ld long double #define mp make_pair #define pb push_back #define ff first #define ss second #define pll pair<long long int, long long int> #define pii pair<int, int> #define vii vector<int> #define vll vector<long long int> #define sii set<int> #define sll set<long long int> #define usi unordered_set<int, custom_hash> #define usl unordered_set<long long int, custom_hash> #define mii map<int, int> #define mll map<long long int, long long int> #define umi unordered_map<int, int, custom_hash> #define uml unordered_map<long long int, long long int, custom_hash> #define ski stack<int> #define skl stack<long long int> #define all(v) v.begin(), v.end() using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c` x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; const int N = 1e3 + 1; const int mod = 998244353; ld a[N], b[N], c[N]; ld dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef _DEBUG freopen("input.txt", "r", stdin); #endif int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - a[i]); continue; } dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i]; } } ld ans = 0.0; for (int i = (n + 1) / 2; i <= n; ++i) { ans += dp[n][i]; } cout << setprecision(15); cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long int #define ul unsigned long long int #define ld long double #define mp make_pair #define pb push_back #define ff first #define ss second #define pll pair<long long int, long long int> #define pii pair<int, int> #define vii vector<int> #define vll vector<long long int> #define sii set<int> #define sll set<long long int> #define usi unordered_set<int, custom_hash> #define usl unordered_set<long long int, custom_hash> #define mii map<int, int> #define mll map<long long int, long long int> #define umi unordered_map<int, int, custom_hash> #define uml unordered_map<long long int, long long int, custom_hash> #define ski stack<int> #define skl stack<long long int> #define all(v) v.begin(), v.end() using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c` x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; const int N = 3e3 + 1; const int mod = 998244353; ld a[N], b[N], c[N]; ld dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef _DEBUG freopen("input.txt", "r", stdin); #endif int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - a[i]); continue; } dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i]; } } ld ans = 0.0; for (int i = (n + 1) / 2; i <= n; ++i) { ans += dp[n][i]; } cout << setprecision(15); cout << ans << endl; }
replace
40
41
40
41
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int64 INF = 1LL << 59; const int mod = 1e9 + 7; int N; double P[3000]; double dp[6002][3000]; bool memo[6002][3000]; double rec(int up, int idx) { if (idx == N) return up > 3000 ? 1.0 : 0.0; if (exchange(memo[up][idx], true)) return dp[up][idx]; double ret = 0.0; ret += rec(up + 1, idx + 1) * P[idx]; ret += rec(up - 1, idx + 1) * (1 - P[idx]); return dp[up][idx] = ret; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> P[i]; cout << fixed << setprecision(10) << rec(2000, 0) << endl; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int64 INF = 1LL << 59; const int mod = 1e9 + 7; int N; double P[3000]; double dp[6002][3000]; bool memo[6002][3000]; double rec(int up, int idx) { if (idx == N) return up > 3000 ? 1.0 : 0.0; if (exchange(memo[up][idx], true)) return dp[up][idx]; double ret = 0.0; ret += rec(up + 1, idx + 1) * P[idx]; ret += rec(up - 1, idx + 1) * (1 - P[idx]); return dp[up][idx] = ret; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> P[i]; cout << fixed << setprecision(10) << rec(3000, 0) << endl; }
replace
28
29
28
29
-11
p03168
C++
Runtime Error
// I - Coins #include <bits/stdc++.h> using namespace std; using dl = double; int main() { int N; cin >> N; vector<dl> P(N + 1); for (int i = 1; i <= N; i++) cin >> P[i]; int C = (N + 1) / 2; // ceil vector<dl> dp(N + 2); dp[1] = 1.; for (int lv = 1; lv <= N; lv++) { dl f = P[lv], b = 1. - f; for (int i = lv + 1; i >= lv + 2 - C; i--) dp[i] = b * dp[i] + f * dp[i - 1]; } dl a = 0; for (int i = N + 1; i > C; i--) a += dp[i]; printf("%.10g\n", a); }
// I - Coins #include <bits/stdc++.h> using namespace std; using dl = double; int main() { int N; cin >> N; vector<dl> P(N + 1); for (int i = 1; i <= N; i++) cin >> P[i]; int C = (N + 1) / 2; // ceil vector<dl> dp(N + 2); dp[1] = 1.; for (int lv = 1; lv <= N; lv++) { dl f = P[lv], b = 1. - f; int e = max(1, lv - C + 2); for (int i = lv + 1; i >= e; i--) dp[i] = b * dp[i] + f * dp[i - 1]; } dl a = 0; for (int i = N + 1; i > C; i--) a += dp[i]; printf("%.10g\n", a); }
replace
18
19
18
20
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define debug1(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define debug3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define pii pair<ll, ll> #define vi vector<int> #define vii vector<pii> #define pb push_back #define mp make_pair #define ll long long int int main() { int n; cin >> n; double a[3000]; int i, j; for (i = 1; i <= n; i++) cin >> a[i]; double dp[1000][1000]; dp[1][0] = 1 - a[1]; dp[1][1] = a[1]; for (i = 2; i <= n; i++) dp[i][0] = dp[i - 1][0] * (1 - a[i]); for (i = 2; i <= n; i++) dp[i][i] = dp[i - 1][i - 1] * a[i]; for (i = 2; i <= n; i++) for (j = 1; j < i; j++) { dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]); } long double ans = 0; for (j = n / 2 + 1; j <= n; j++) ans += dp[n][j]; cout << fixed << setprecision(9); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define debug1(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define debug3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define pii pair<ll, ll> #define vi vector<int> #define vii vector<pii> #define pb push_back #define mp make_pair #define ll long long int int main() { int n; cin >> n; double a[3000]; int i, j; for (i = 1; i <= n; i++) cin >> a[i]; double dp[3000][3000]; dp[1][0] = 1 - a[1]; dp[1][1] = a[1]; for (i = 2; i <= n; i++) dp[i][0] = dp[i - 1][0] * (1 - a[i]); for (i = 2; i <= n; i++) dp[i][i] = dp[i - 1][i - 1] * a[i]; for (i = 2; i <= n; i++) for (j = 1; j < i; j++) { dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]); } long double ans = 0; for (j = n / 2 + 1; j <= n; j++) ans += dp[n][j]; cout << fixed << setprecision(9); cout << ans << endl; }
replace
21
22
21
22
0
p03168
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <climits> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; template <typename T> T gcd(T a, T b) { if (a < b) gcd(b, a); if (b == 1) return 1; T r; while ((r = a % b)) { a = b; b = r; } return b; } #define MOD (1'000'000'000 + 7) bool _less(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } double dp[3000][3000]; int main() { int N; cin >> N; vector<double> p(N); REP(i, 1, N + 1) { cin >> p[i]; } dp[0][0] = 1.0; REP(i, 1, N + 1) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); REP(j, 1, i + 1) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } } double sum = 0.0; REP(i, N / 2 + 1, N + 1) { sum += dp[N][i]; } cout << setprecision(10) << sum << endl; }
#include <algorithm> #include <assert.h> #include <climits> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; template <typename T> T gcd(T a, T b) { if (a < b) gcd(b, a); if (b == 1) return 1; T r; while ((r = a % b)) { a = b; b = r; } return b; } #define MOD (1'000'000'000 + 7) bool _less(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } double dp[3000][3000]; int main() { int N; cin >> N; vector<double> p(N + 1); REP(i, 1, N + 1) { cin >> p[i]; } dp[0][0] = 1.0; REP(i, 1, N + 1) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); REP(j, 1, i + 1) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } } double sum = 0.0; REP(i, N / 2 + 1, N + 1) { sum += dp[N][i]; } cout << setprecision(10) << sum << endl; }
replace
41
42
41
42
-6
munmap_chunk(): invalid pointer
p03168
C++
Runtime Error
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair #define ts to_string #define ub upper_bound #define lb lower_bound const char nl = '\n'; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; // The following debugging code was taken from Benjamin Qi's template :) str ts(char c) { return str(1, c); } str ts(bool b) { return b ? "true" : "false"; } str ts(const char *s) { return (str)s; } str ts(str s) { return s; } template <class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); } str ts(vector<bool> v) { str res = "{"; for (int i = 0; i < (int)v.size(); i++) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> str ts(bitset<SZ> b) { str res = ""; for (int i = 0; i < b.size(); i++) res += char('0' + b[i]); return res; } template <class A, class B> str ts(pair<A, B> p); template <class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto &x : v) { if (!fst) res += ", "; fst = 0; res += ts(x); } res += "}"; return res; } template <class A, class B> str ts(pair<A, B> p) { return "(" + ts(p.f) + ", " + ts(p.s) + ")"; } void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // CODE STARTS // HERE-----------------------------------------------------------------------------------------// const int N = 1e3 + 10; int n; double a[N], dp[N][N]; signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[1][1] = a[1]; dp[1][0] = 1 - a[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j) { dp[i][j] += dp[i - 1][j - 1] * a[i]; } dp[i][j] += dp[i - 1][j] * (1 - a[i]); dbg(dp[i][j], i, j); } } int m = (n + 2) / 2; double ans = 0; for (int i = m; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(9) << ans << nl; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair #define ts to_string #define ub upper_bound #define lb lower_bound const char nl = '\n'; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; // The following debugging code was taken from Benjamin Qi's template :) str ts(char c) { return str(1, c); } str ts(bool b) { return b ? "true" : "false"; } str ts(const char *s) { return (str)s; } str ts(str s) { return s; } template <class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); } str ts(vector<bool> v) { str res = "{"; for (int i = 0; i < (int)v.size(); i++) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> str ts(bitset<SZ> b) { str res = ""; for (int i = 0; i < b.size(); i++) res += char('0' + b[i]); return res; } template <class A, class B> str ts(pair<A, B> p); template <class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto &x : v) { if (!fst) res += ", "; fst = 0; res += ts(x); } res += "}"; return res; } template <class A, class B> str ts(pair<A, B> p) { return "(" + ts(p.f) + ", " + ts(p.s) + ")"; } void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // CODE STARTS // HERE-----------------------------------------------------------------------------------------// const int N = 3e3 + 10; int n; double a[N], dp[N][N]; signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[1][1] = a[1]; dp[1][0] = 1 - a[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j) { dp[i][j] += dp[i - 1][j - 1] * a[i]; } dp[i][j] += dp[i - 1][j] * (1 - a[i]); dbg(dp[i][j], i, j); } } int m = (n + 2) / 2; double ans = 0; for (int i = m; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(9) << ans << nl; }
replace
76
77
76
77
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define F first #define S second #define ld long douroote #define pb push_back #define sz size #define ll long long #define ull unsigned long long #define INF 0x7f7f7f7f #define sc(a) scanf("%d", &a) #define scll(a) scanf("%lld", &a) #define scd(a) scanf("%lf", &a) #define scc(a) scanf(" %c", &a) #define scs(a) scanf(" %s", a) #define me(a, b) memset(a, b, sizeof a) #define all(a) a.begin(), a.end() #define allr(a, n) a, a + n #define loop(a, s, e) for (ll a = s; a <= e; a++) #define read_arr(a, s, n) \ for (int i = s; i < n + s; i++) { \ sc(a[i]); \ } #define read_arr_ll(a, s, n) \ for (int i = s; i < n + s; i++) { \ scll(a[i]); \ } #define err(a, s) cerr << a << s; #define err_arr(a, s, n) \ for (int i = s; i < n + s; i++) { \ cerr << a[i] << " "; \ } \ cerr << endl; #define prtll(x) printf("%lld", x); #define prt(x) printf("%d", x); using namespace std; const int N = 1e4 + 10; int n, m; bool vis[N][N]; double mem[N][N], a[N]; double dp(int i, int co) { if ((co > ((n) / 2))) { return 0.0; } if (i == n) { return (co <= ((n) / 2)); } if (vis[i][co]) { return mem[i][co]; } double &ret = mem[i][co]; ret = 0.0; ret += 1.0 * a[i] * (dp(i + 1, co)); ret += 1.0 * (1.0 - a[i]) * (dp(i + 1, co + 1)); return ret; } int main() { cin >> n; loop(i, 0, n - 1) { cin >> a[i]; } double ans = dp(0, 0); printf("%.9lf\n", ans); return 0; } /** **/
#include <bits/stdc++.h> #define F first #define S second #define ld long douroote #define pb push_back #define sz size #define ll long long #define ull unsigned long long #define INF 0x7f7f7f7f #define sc(a) scanf("%d", &a) #define scll(a) scanf("%lld", &a) #define scd(a) scanf("%lf", &a) #define scc(a) scanf(" %c", &a) #define scs(a) scanf(" %s", a) #define me(a, b) memset(a, b, sizeof a) #define all(a) a.begin(), a.end() #define allr(a, n) a, a + n #define loop(a, s, e) for (ll a = s; a <= e; a++) #define read_arr(a, s, n) \ for (int i = s; i < n + s; i++) { \ sc(a[i]); \ } #define read_arr_ll(a, s, n) \ for (int i = s; i < n + s; i++) { \ scll(a[i]); \ } #define err(a, s) cerr << a << s; #define err_arr(a, s, n) \ for (int i = s; i < n + s; i++) { \ cerr << a[i] << " "; \ } \ cerr << endl; #define prtll(x) printf("%lld", x); #define prt(x) printf("%d", x); using namespace std; const int N = 1e4 + 10; int n, m; bool vis[N][N]; double mem[N][N], a[N]; double dp(int i, int co) { if ((co > ((n) / 2))) { return 0.0; } if (i == n) { return (co <= ((n) / 2)); } if (vis[i][co]) { return mem[i][co]; } double &ret = mem[i][co]; ret = 0.0; ret += 1.0 * a[i] * (dp(i + 1, co)); ret += 1.0 * (1.0 - a[i]) * (dp(i + 1, co + 1)); vis[i][co] = 1; return ret; } int main() { cin >> n; loop(i, 0, n - 1) { cin >> a[i]; } double ans = dp(0, 0); printf("%.9lf\n", ans); return 0; } /** **/
insert
53
53
53
54
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define ll long long #define hii cout << "hii" << endl #define pii pair<int, int> #define pll pair<ll, ll> #define int ll #define mpp make_pair #define endl '\n' #define ff first #define ss second #define all(s) s.begin(), s.end() #define fuck_you_scanf \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define si size() const int N = 1e6 + 5; double arr[N]; double DP[3005][3005][2]; double f(int idx, int reqd, int n) { if (reqd <= 0) return 1; if (idx == n) { return 0; } int type = 0; if (reqd < 0) type = 1; if (DP[idx][abs(reqd)][type] > 0) return DP[idx][abs(reqd)][type]; double ans1 = (arr[idx]) * f(idx + 1, reqd - 1, n) * 1.0; double ans2 = (1.0 - arr[idx]) * f(idx + 1, reqd, n) * 1.0; return DP[idx][abs(reqd)][type] = ans1 + ans2; } int32_t main() { int n; cin >> n; memset(DP, -1, sizeof(DP)); for (int i = 0; i < n; i++) { cin >> arr[i]; } int reqd = (n + 1) / 2; if (n % 2 == 0) reqd++; cout << setprecision(10) << fixed; cout << f(0, reqd, n); }
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define ll long long #define hii cout << "hii" << endl #define pii pair<int, int> #define pll pair<ll, ll> #define int ll #define mpp make_pair #define endl '\n' #define ff first #define ss second #define all(s) s.begin(), s.end() #define fuck_you_scanf \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define si size() const int N = 1e6 + 5; double arr[N]; double DP[3005][3005][2]; double f(int idx, int reqd, int n) { if (reqd <= 0) return 1; if (idx == n) { return 0; } int type = 0; if (reqd < 0) type = 1; if (DP[idx][abs(reqd)][type] >= 0) return DP[idx][abs(reqd)][type]; double ans1 = (arr[idx]) * f(idx + 1, reqd - 1, n) * 1.0; double ans2 = (1.0 - arr[idx]) * f(idx + 1, reqd, n) * 1.0; return DP[idx][abs(reqd)][type] = ans1 + ans2; } int32_t main() { int n; cin >> n; memset(DP, -1, sizeof(DP)); for (int i = 0; i < n; i++) { cin >> arr[i]; } int reqd = (n + 1) / 2; if (n % 2 == 0) reqd++; cout << setprecision(10) << fixed; cout << f(0, reqd, n); }
replace
33
34
33
34
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define pb push_back #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define rs(v, n) v.resize(n) #define hell 1000000007 #define peak 9123372036854775807 #define pii acos(-1) #define clr(a, x) memset(a, x, sizeof(a)) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ordered_set \ tree<ll int, null_type, less<ll int>, rb_tree_tag, \ tree_order_statistics_node_update> using namespace std; template <class x, class y> x sum(x a, y b) { return a + b; } template <class x, class y> x mul(x a, y b) { return a * b; } template <class x, class y> x sub(x a, y b) { return a - b; } template <class x, class y> x divi(x a, y b) { return a / b; } template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) { in >> p.F >> p.S; return in; } template <class x> istream &operator>>(istream &in, vector<x> &v) { for (auto &i : v) in >> i; return in; } template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) { out << "(" << p.F << "," << p.S << ") "; return out; } template <class x> ostream &operator<<(ostream &out, vector<x> &v) { out << v.size() << endl; for (auto i : v) out << i << " "; out << endl; return out; } #define N 1000005 int main() { ios; ll tt = 1; // cin>>tt; while (tt--) { ll i, j, k, l, m, n; cin >> n; vector<double> v(n); cin >> v; double dp[30][30]; clr(dp, 0); dp[0][0] = 1 - v[0]; dp[0][1] = v[0]; for (i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] * (1 - v[i]); for (j = 1; j <= i + 1; j++) { dp[i][j] = dp[i - 1][j] * (1 - v[i]); dp[i][j] += dp[i - 1][j - 1] * (v[i]); // cout<<dp[i][j]<<" "; } // cout<<endl; } double ans; for (i = (n + 1) / 2; i <= n; i++) { ans += dp[n - 1][i]; } cout << setprecision(10) << ans; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define pb push_back #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define rs(v, n) v.resize(n) #define hell 1000000007 #define peak 9123372036854775807 #define pii acos(-1) #define clr(a, x) memset(a, x, sizeof(a)) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ordered_set \ tree<ll int, null_type, less<ll int>, rb_tree_tag, \ tree_order_statistics_node_update> using namespace std; template <class x, class y> x sum(x a, y b) { return a + b; } template <class x, class y> x mul(x a, y b) { return a * b; } template <class x, class y> x sub(x a, y b) { return a - b; } template <class x, class y> x divi(x a, y b) { return a / b; } template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) { in >> p.F >> p.S; return in; } template <class x> istream &operator>>(istream &in, vector<x> &v) { for (auto &i : v) in >> i; return in; } template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) { out << "(" << p.F << "," << p.S << ") "; return out; } template <class x> ostream &operator<<(ostream &out, vector<x> &v) { out << v.size() << endl; for (auto i : v) out << i << " "; out << endl; return out; } #define N 1000005 int main() { ios; ll tt = 1; // cin>>tt; while (tt--) { ll i, j, k, l, m, n; cin >> n; vector<double> v(n); cin >> v; double dp[3000][3000]; clr(dp, 0); dp[0][0] = 1 - v[0]; dp[0][1] = v[0]; for (i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] * (1 - v[i]); for (j = 1; j <= i + 1; j++) { dp[i][j] = dp[i - 1][j] * (1 - v[i]); dp[i][j] += dp[i - 1][j - 1] * (v[i]); // cout<<dp[i][j]<<" "; } // cout<<endl; } double ans; for (i = (n + 1) / 2; i <= n; i++) { ans += dp[n - 1][i]; } cout << setprecision(10) << ans; } return 0; }
replace
61
62
61
62
0
p03168
C++
Time Limit Exceeded
#include "bits/stdc++.h" typedef long long ll; #define int ll #define fi first #define se second #define SORT(a) sort(a.begin(), a.end()) #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define MP(a, b) make_pair(a, b) #define pb(a) push_back(a) #define INF LLONG_MAX / 2 #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cerr << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl using namespace std; int MOD = 1000000007; double dp[3010][3010]; double p[3010]; signed main() { ll n; cin >> n; rep(i, n) cin >> p[i]; rep(i, n) dp[0][i] = 0; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]); } else { dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]; } } } double ans = 0.0; rep(i, n / 2 + 1) ans += dp[n][i]; printf("%0.10lf\n", 1.0 - ans); rep(i, n) { rep(j, n) { cerr << dp[i][j] << "\t"; } cerr << endl; } return 0; } // g++ -std=c++14 code1.cpp // rm -r -f test;oj dl // https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a rm -r -f // test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f
#include "bits/stdc++.h" typedef long long ll; #define int ll #define fi first #define se second #define SORT(a) sort(a.begin(), a.end()) #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define MP(a, b) make_pair(a, b) #define pb(a) push_back(a) #define INF LLONG_MAX / 2 #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cerr << #v << ":"; \ rep(i, v.size()) cerr << " " << v[i]; \ cerr << endl using namespace std; int MOD = 1000000007; double dp[3010][3010]; double p[3010]; signed main() { ll n; cin >> n; rep(i, n) cin >> p[i]; rep(i, n) dp[0][i] = 0; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]); } else { dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]; } } } double ans = 0.0; rep(i, n / 2 + 1) ans += dp[n][i]; printf("%0.10lf\n", 1.0 - ans); // rep(i,n){ // rep(j,n){ // cerr << dp[i][j] << "\t"; // }cerr << endl; // } return 0; } // g++ -std=c++14 code1.cpp // rm -r -f test;oj dl // https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a rm -r -f // test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f
replace
45
49
45
50
TLE
p03168
C++
Runtime Error
#pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; double dp[3003][3003]; void solve() { int n; cin >> n; double data[n + 5], ans = 0; for (int i = 1; i <= n; i++) cin >> data[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - data[i]); for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j - 1] * data[i] + dp[i - 1][j] * (1 - data[i]); } } for (int i = 1; i <= n; i++) { if (2 * i < n) continue; ans += dp[n][i]; } cout << setprecision(12) << ans << '\n'; } signed main() { int t = 1; // cin >> t; while (t--) { solve(); } // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl; }
// #pragma GCC optimize("O3", "unroll-loops") // #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; double dp[3003][3003]; void solve() { int n; cin >> n; double data[n + 5], ans = 0; for (int i = 1; i <= n; i++) cin >> data[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - data[i]); for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j - 1] * data[i] + dp[i - 1][j] * (1 - data[i]); } } for (int i = 1; i <= n; i++) { if (2 * i < n) continue; ans += dp[n][i]; } cout << setprecision(12) << ans << '\n'; } signed main() { int t = 1; // cin >> t; while (t--) { solve(); } // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl; }
replace
0
2
0
2
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long int ll; long double dp[3001][3001] = {0}; long double p[3001] = {0}; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(20) << fixed; int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * ((long double)1 - p[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * ((long double)1 - p[i]) + dp[i - 1][j - 1] * p[i]; } } long double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long int ll; long double dp[3001][3001] = {0}; long double p[3001] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(20) << fixed; int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * ((long double)1 - p[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * ((long double)1 - p[i]) + dp[i - 1][j - 1] * p[i]; } } long double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << ans << endl; return 0; }
delete
11
16
11
11
-11
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int double dp[3002][3002]; double solve(vector<double> &v, int n, int x) { // 0 heads required always 1 if (x == 0) return 1; // for (0,0) it will be 1 only // Can't get the desired no. of heads in 0 tosses if (n == 0) return 0; if (dp[n][x] > -0.9) return dp[n][x]; dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x); // cout<<dp[n][x]<<endl; return dp[n][x]; } int main() { FASTIO; int n; cin >> n; vector<double> v(n); memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { cin >> v[i]; } // out of n tosses we want atleast (n+1)/2 heads double ans = solve(v, n, (n + 1) / 2); cout << fixed << setprecision(10) << ans; }
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int double dp[3002][3002]; double solve(vector<double> &v, int n, int x) { // 0 heads required always 1 if (x == 0) return 1; // for (0,0) it will be 1 only // Can't get the desired no. of heads in 0 tosses if (n == 0) return 0; if (dp[n][x] > -0.9) return dp[n][x]; dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x); // cout<<dp[n][x]<<endl; return dp[n][x]; } int main() { FASTIO; int n; cin >> n; vector<double> v(n + 1); memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { cin >> v[i]; } // out of n tosses we want atleast (n+1)/2 heads double ans = solve(v, n, (n + 1) / 2); cout << fixed << setprecision(10) << ans; }
replace
35
36
35
36
-6
munmap_chunk(): invalid pointer
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long template <class T> using v = std::vector<T>; template <class T> using vv = v<v<T>>; const int mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; double dp[2999][2999]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; dp[0][0] = 1; rep(i, n) { double p; cin >> p; for (int j = 0; j <= i; ++j) { dp[j + 1][i + 1] += dp[j][i] * p; dp[j][i + 1] += dp[j][i] * (1 - p); } } // rep(i,n+1) { // rep(j,n+1) { // printf("%.5f ",dp[i][j]); // } // printf("\n"); // } double ans = 0; for (int i = n; i > n / 2; --i) { // cout << dp[i][n] << endl; ans += dp[i][n]; } cout << fixed << setprecision(10) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long template <class T> using v = std::vector<T>; template <class T> using vv = v<v<T>>; const int mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; double dp[3002][3002]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; dp[0][0] = 1; rep(i, n) { double p; cin >> p; for (int j = 0; j <= i; ++j) { dp[j + 1][i + 1] += dp[j][i] * p; dp[j][i + 1] += dp[j][i] * (1 - p); } } // rep(i,n+1) { // rep(j,n+1) { // printf("%.5f ",dp[i][j]); // } // printf("\n"); // } double ans = 0; for (int i = n; i > n / 2; --i) { // cout << dp[i][n] << endl; ans += dp[i][n]; } cout << fixed << setprecision(10) << ans << endl; return 0; }
replace
88
89
88
89
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; double mem[3000][3000]; int vis[3000][3000]; int n; double arr[3000]; double go(int x, int y) { if (x >= n) return (y > n - y); if (vis[x][y]) return mem[x][y]; return mem[x][y] = (arr[x] * go(x + 1, y + 1) + (1 - arr[x]) * go(x + 1, y)); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; cout << fixed << setprecision(15) << go(0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; double mem[3000][3000]; int vis[3000][3000]; int n; double arr[3000]; double go(int x, int y) { if (x >= n) return (y > n - y); if (vis[x][y]) return mem[x][y]; vis[x][y] = 1; return mem[x][y] = (arr[x] * go(x + 1, y + 1) + (1 - arr[x]) * go(x + 1, y)); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; cout << fixed << setprecision(15) << go(0, 0) << endl; }
insert
14
14
14
15
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 using namespace std; ll h; ll w; double dp[1000][1000]; int main() { ll n; cin >> n; double a[40000]; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][0] = 1.0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - a[i]); } dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i]; } } double ans = 0; for (ll i = (n + 1) / 2; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(10) << ans; }
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 using namespace std; ll h; ll w; double dp[3000][3000]; int main() { ll n; cin >> n; double a[40000]; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][0] = 1.0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - a[i]); } dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i]; } } double ans = 0; for (ll i = (n + 1) / 2; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(10) << ans; }
replace
6
7
6
7
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, l, r) for (int i = (int)l; i <= (int)r; ++i) #define REP(i, r) for (int i = (int)0; i < (int)r; ++i) using namespace std; typedef long long ll; const int Nmax = 1e3 + 11; int n; double p[Nmax], f[Nmax][Nmax], ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; FOR(i, 1, n) { cin >> p[i]; } f[1][1] = p[1]; f[1][0] = 1.0 - p[1]; if (n == 1) { printf("%0.9f", p[1]); return 0; } FOR(i, 2, n) FOR(j, 0, i) { f[i][j] = f[i - 1][j] * (1.0 - p[i]); if (j > 0) f[i][j] += f[i - 1][j - 1] * p[i]; if (i == n && j > n / 2) { ans += f[i][j]; } } printf("%0.10f", ans); }
#include <bits/stdc++.h> #define FOR(i, l, r) for (int i = (int)l; i <= (int)r; ++i) #define REP(i, r) for (int i = (int)0; i < (int)r; ++i) using namespace std; typedef long long ll; const int Nmax = 3e3 + 11; int n; double p[Nmax], f[Nmax][Nmax], ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; FOR(i, 1, n) { cin >> p[i]; } f[1][1] = p[1]; f[1][0] = 1.0 - p[1]; if (n == 1) { printf("%0.9f", p[1]); return 0; } FOR(i, 2, n) FOR(j, 0, i) { f[i][j] = f[i - 1][j] * (1.0 - p[i]); if (j > 0) f[i][j] += f[i - 1][j - 1] * p[i]; if (i == n && j > n / 2) { ans += f[i][j]; } } printf("%0.10f", ans); }
replace
6
7
6
7
0
p03168
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<int, pii> pipii; typedef vector<vector<int>> mati; typedef vector<vector<double>> matd; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; #define rep(i, x, y) for (int i = (x); i < (y); ++i) template <typename T> void vec_print(vector<T> VEC) { rep(i, 0, VEC.size()) { cout << VEC[i] << " "; } cout << "\n"; }; template <typename T> void mat_print(vector<vector<T>> MAT){ rep(i, 0, MAT.size()){rep(j, 0, MAT[i].size()){cout << MAT[i][j] << " "; } cout << "\n"; } } ; template <typename CLASS1, typename CLASS2> class HOGE { public: CLASS1 key; CLASS2 value; HOGE(ll key, ll value) { this->key = index; this->value = value; }; ~HOGE(void) { return; }; void print(void) { cout << "key : " << key << ", value : " << value << "\n"; return; }; bool operator==(const HOGE &obj) { return (this->value == obj.value); }; bool operator<(const HOGE &obj) { return (this->value < obj.value); }; bool operator>(const HOGE &obj) { return (this->value > obj.value); }; }; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; void calc_dp(const int start, const vector<double> &p, vector<double> &dp) { if (start == p.size() - 1) { dp[0] = 1.0 - p[start]; dp[1] = p[start]; return; } calc_dp(start + 1, p, dp); dp[p.size() - start] = dp[p.size() - start - 1] * p[start]; for (int i = p.size() - start - 1; i > 0; --i) { dp[i] = dp[i] * (1.0 - p[start]) + dp[i - 1] * p[start]; } dp[0] = dp[0] * (1.0 - p[start]); return; } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll N; cin >> N; // ans 1 /* vector<double> p(N); rep(i, 0, N){ cin >> p[i]; } vector<double> dp(N+1, 0.0); calc_dp(0, p, dp); */ // ans 2 vector<double> dp(N / 2 + 1, 0.0); double tmp; cin >> tmp; dp[0] = tmp; dp[1] = 1.0 - tmp; rep(i, 1, N / 2 + 1) { cin >> tmp; dp[i + 1] = dp[i] * (1.0 - tmp); for (int j = i; j > 0; --j) { dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp); } dp[0] = dp[0] * tmp; } rep(i, N / 2 + 1, N) { cin >> tmp; for (int j = N / 2; j > 0; --j) { dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp); } dp[0] = dp[0] * tmp; } double ans = 0.0; rep(i, 0, N / 2 + 1) { ans += dp[i]; } printf("%.10lf\n", ans); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<int, pii> pipii; typedef vector<vector<int>> mati; typedef vector<vector<double>> matd; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; #define rep(i, x, y) for (int i = (x); i < (y); ++i) template <typename T> void vec_print(vector<T> VEC) { rep(i, 0, VEC.size()) { cout << VEC[i] << " "; } cout << "\n"; }; template <typename T> void mat_print(vector<vector<T>> MAT){ rep(i, 0, MAT.size()){rep(j, 0, MAT[i].size()){cout << MAT[i][j] << " "; } cout << "\n"; } } ; template <typename CLASS1, typename CLASS2> class HOGE { public: CLASS1 key; CLASS2 value; HOGE(ll key, ll value) { this->key = index; this->value = value; }; ~HOGE(void) { return; }; void print(void) { cout << "key : " << key << ", value : " << value << "\n"; return; }; bool operator==(const HOGE &obj) { return (this->value == obj.value); }; bool operator<(const HOGE &obj) { return (this->value < obj.value); }; bool operator>(const HOGE &obj) { return (this->value > obj.value); }; }; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; void calc_dp(const int start, const vector<double> &p, vector<double> &dp) { if (start == p.size() - 1) { dp[0] = 1.0 - p[start]; dp[1] = p[start]; return; } calc_dp(start + 1, p, dp); dp[p.size() - start] = dp[p.size() - start - 1] * p[start]; for (int i = p.size() - start - 1; i > 0; --i) { dp[i] = dp[i] * (1.0 - p[start]) + dp[i - 1] * p[start]; } dp[0] = dp[0] * (1.0 - p[start]); return; } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll N; cin >> N; // ans 1 /* vector<double> p(N); rep(i, 0, N){ cin >> p[i]; } vector<double> dp(N+1, 0.0); calc_dp(0, p, dp); */ // ans 2 vector<double> dp(N / 2 + 2, 0.0); double tmp; cin >> tmp; dp[0] = tmp; dp[1] = 1.0 - tmp; rep(i, 1, N / 2 + 1) { cin >> tmp; dp[i + 1] = dp[i] * (1.0 - tmp); for (int j = i; j > 0; --j) { dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp); } dp[0] = dp[0] * tmp; } rep(i, N / 2 + 1, N) { cin >> tmp; for (int j = N / 2; j > 0; --j) { dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp); } dp[0] = dp[0] * tmp; } double ans = 0.0; rep(i, 0, N / 2 + 1) { ans += dp[i]; } printf("%.10lf\n", ans); return 0; }
replace
99
100
99
100
0
p03168
C++
Runtime Error
#include <cstdio> double dp[3000][3000]; int main() { int n; scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { double p; scanf("%lf", &p); dp[i][0] = dp[i - 1][0] * (1 - p); for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p); dp[i][i] = dp[i - 1][i - 1] * p; } double ans = 0; for (int i = n; i > n / 2; i++) ans += dp[n][i]; printf("%.10lf", ans); return 0; }
#include <cstdio> double dp[3000][3000]; int main() { int n; scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { double p; scanf("%lf", &p); dp[i][0] = dp[i - 1][0] * (1 - p); for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p); dp[i][i] = dp[i - 1][i - 1] * p; } double ans = 0; for (int i = n; i > n / 2; i--) ans += dp[n][i]; printf("%.10lf", ans); return 0; }
replace
15
16
15
16
-11
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { int i, n, j; cin >> n; vector<double> p(n + 1); for (i = 1; i <= n; ++i) cin >> p[i]; vector<double> dp(n + 1, 0); dp[0] = 1; for (i = 1; i <= n; ++i) { for (j = i; j >= 0; --j) { dp[j] = dp[j] * (1 - p[i]); if (j > 0) dp[j] += dp[j - 1] * p[i]; } for (int k = 0; k <= n; k++) cerr << dp[k] << " "; cerr << "\n"; } double ans = 0; for (i = n / 2 + 1; i <= n; ++i) ans += dp[i]; cout << setprecision(10) << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { int i, n, j; cin >> n; vector<double> p(n + 1); for (i = 1; i <= n; ++i) cin >> p[i]; vector<double> dp(n + 1, 0); dp[0] = 1; for (i = 1; i <= n; ++i) { for (j = i; j >= 0; --j) { dp[j] = dp[j] * (1 - p[i]); if (j > 0) dp[j] += dp[j - 1] * p[i]; } // for(int k=0; k<=n; k++) // cerr<<dp[k]<<" "; // cerr<<"\n"; } double ans = 0; for (i = n / 2 + 1; i <= n; ++i) ans += dp[i]; cout << setprecision(10) << ans << "\n"; return 0; }
replace
18
21
18
21
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll MAXN = 2e3 + 10; const ll INF = 1e18; ld dp[MAXN][MAXN]; ld p[MAXN]; ll n; int main() { IOS; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } dp[1][0] = 1 - p[1]; dp[1][1] = p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - p[i]); } for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; // cout << i << ' ' << j << ' '; // cout << fixed << setprecision(20) << dp[i][j] << '\n'; } } ld ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(20) << ans; return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
#include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll MAXN = 3e3 + 10; const ll INF = 1e18; ld dp[MAXN][MAXN]; ld p[MAXN]; ll n; int main() { IOS; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } dp[1][0] = 1 - p[1]; dp[1][1] = p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - p[i]); } for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; // cout << i << ' ' << j << ' '; // cout << fixed << setprecision(20) << dp[i][j] << '\n'; } } ld ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(20) << ans; return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
replace
26
27
26
27
0
p03168
C++
Time Limit Exceeded
// template {{{ #include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define sz(c) (static_cast<int>(c.size())) #define endl "\n" using ld = long double; using ll = long long; inline ll addm(ll __a, ll __b, ll __m); inline ll subm(ll __a, ll __b, ll __m); inline ll mulm(ll __a, ll __b, ll __m); ll powm(ll __a, ll __b, ll __m); ll inv(ll __x, ll __m); // }}} const ll INFL = numeric_limits<ll>::max() / 2; const ll INF = numeric_limits<int>::max() / 2; const ll MOD = 1e9 + 7; const int N = 3050; bool vis[N][2 * N]; double mem[N][2 * N], p[N]; int n; double dp(int cur, int h) { if (cur == n) return (h >= 0) ? 1.0 : 0.0; double &ret = mem[cur][h + n]; if (vis[cur][h + n]) return ret; return ret = p[cur] * dp(cur + 1, h + 1) + (1.0 - p[cur]) * dp(cur + 1, h - 1); } void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> p[i]; cout << fixed << setprecision(12) << dp(0, 0) << endl; } // main {{{ int main() { cin.sync_with_stdio(0); cin.tie(NULL); solve(); return 0; } inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); } inline ll subm(ll __a, ll __b, ll __m = MOD) { return (((__a - __b) % __m + __m) % __m); } inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); } ll powm(ll __a, ll __b, ll __m = MOD) { ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m); return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m); } ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); } // }}}
// template {{{ #include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define sz(c) (static_cast<int>(c.size())) #define endl "\n" using ld = long double; using ll = long long; inline ll addm(ll __a, ll __b, ll __m); inline ll subm(ll __a, ll __b, ll __m); inline ll mulm(ll __a, ll __b, ll __m); ll powm(ll __a, ll __b, ll __m); ll inv(ll __x, ll __m); // }}} const ll INFL = numeric_limits<ll>::max() / 2; const ll INF = numeric_limits<int>::max() / 2; const ll MOD = 1e9 + 7; const int N = 3050; bool vis[N][2 * N]; double mem[N][2 * N], p[N]; int n; double dp(int cur, int h) { if (cur == n) return (h >= 0) ? 1.0 : 0.0; double &ret = mem[cur][h + n]; if (vis[cur][h + n]) return ret; vis[cur][h + n] = true; return ret = p[cur] * dp(cur + 1, h + 1) + (1.0 - p[cur]) * dp(cur + 1, h - 1); } void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> p[i]; cout << fixed << setprecision(12) << dp(0, 0) << endl; } // main {{{ int main() { cin.sync_with_stdio(0); cin.tie(NULL); solve(); return 0; } inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); } inline ll subm(ll __a, ll __b, ll __m = MOD) { return (((__a - __b) % __m + __m) % __m); } inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); } ll powm(ll __a, ll __b, ll __m = MOD) { ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m); return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m); } ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); } // }}}
insert
33
33
33
34
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int n; double a[3000]; double dp[3000][3000]; double func(int i, int kitne) { // base case if (kitne == 0) { return 1; } if (i == n) { return 0; } // recursive case if (dp[i][kitne] > -1.0) { return dp[i][kitne]; } double case1 = a[i] * func(i + 1, kitne - 1); double case2 = (1 - a[i]) * func(i + 1, kitne); dp[i][kitne] = case1 + case2; return dp[i][kitne]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(dp, -1.0, sizeof(dp)); double ans = 0; cout << setprecision(10) << func(0, (n + 1) / 2); }
#include <bits/stdc++.h> using namespace std; #define ll long long int n; double a[3000]; double dp[3000][3000]; double func(int i, int kitne) { // base case if (kitne == 0) { return 1; } if (i == n) { return 0; } // recursive case if (dp[i][kitne] > -1.0) { return dp[i][kitne]; } double case1 = a[i] * func(i + 1, kitne - 1); double case2 = (1 - a[i]) * func(i + 1, kitne); dp[i][kitne] = case1 + case2; return dp[i][kitne]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(dp, -1.0, sizeof(dp)); double ans = 0; cout << setprecision(10) << func(0, (n + 1) / 2); }
delete
32
36
32
32
0
p03168
C++
Runtime Error
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<double> p(N); for (int i = 0; i < N; ++i) cin >> p[i]; // dp[i][head]: i-1 番目までのコインを投げたときに表が head 回出る確率 double dp[301][301] = {}; dp[0][0] = 1; for (int i = 0; i < N; ++i) { for (int head = 0; head < N; ++head) { dp[i + 1][head + 1] += dp[i][head] * p[i]; dp[i + 1][head] += dp[i][head] * (1 - p[i]); } } double ans = 0; for (int i = (N + 1) / 2; i <= N; ++i) ans += dp[N][i]; cout << fixed << setprecision(9) << ans << endl; return 0; }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<double> p(N); for (int i = 0; i < N; ++i) cin >> p[i]; // dp[i][head]: i-1 番目までのコインを投げたときに表が head 回出る確率 double dp[3001][3001] = {}; dp[0][0] = 1; for (int i = 0; i < N; ++i) { for (int head = 0; head < N; ++head) { dp[i + 1][head + 1] += dp[i][head] * p[i]; dp[i + 1][head] += dp[i][head] * (1 - p[i]); } } double ans = 0; for (int i = (N + 1) / 2; i <= N; ++i) ans += dp[N][i]; cout << fixed << setprecision(9) << ans << endl; return 0; }
replace
13
14
13
14
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define ll long double #define int long long int n; vector<long double> v; ll dp[3000][3000]; long double f(int x, int y) { if (x == n) { return y > n / 2; } if (dp[x][y] > 0) return dp[x][y]; return dp[x][y] = (v[x] * f(x + 1, y + 1) + (1 - v[x]) * f(x + 1, y)); } int32_t main() { IOS; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { long double x; cin >> x; v.push_back(x); } cout << fixed << setprecision(9) << f(0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define ll long double #define int long long int n; vector<long double> v; ll dp[3000][3000]; long double f(int x, int y) { if (x == n) { return y > n / 2; } if (dp[x][y] >= 0) return dp[x][y]; return dp[x][y] = (v[x] * f(x + 1, y + 1) + (1 - v[x]) * f(x + 1, y)); } int32_t main() { IOS; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { long double x; cin >> x; v.push_back(x); } cout << fixed << setprecision(9) << f(0, 0) << endl; return 0; }
replace
30
31
30
31
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 #define INFLL 0x3f3f3f3f3f3f3f3fLL #define EPS 10e-9 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define st first #define nd second #define sz(v) int(v.size()) #define all(X) (X).begin(), (X).end() #define FOR(I, A, B) for (int I = A; I < B; I++) #define RFOR(I, A, B) for (int I = A; I >= B; I--) typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<iii> viii; typedef vector<ll> vll; int n; long double p[3000]; long double PD[3000][3000]; bool visited[3000][3000] = {false}; long double pd(int i, int heads) { if (i < 0) { return heads > n / 2 ? 1 : 0; } long double &ans = PD[i][heads]; if (visited[i][heads]) { return ans; } ans = pd(i - 1, heads + 1) * p[i] + pd(i - 1, heads) * (1 - p[i]); return ans; } int main() { scanf("%d", &n); FOR(i, 0, n) { scanf("%Lf", p + i); } printf("%.10Lf\n", pd(n - 1, 0)); return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 #define INFLL 0x3f3f3f3f3f3f3f3fLL #define EPS 10e-9 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define st first #define nd second #define sz(v) int(v.size()) #define all(X) (X).begin(), (X).end() #define FOR(I, A, B) for (int I = A; I < B; I++) #define RFOR(I, A, B) for (int I = A; I >= B; I--) typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<iii> viii; typedef vector<ll> vll; int n; long double p[3000]; long double PD[3000][3000]; bool visited[3000][3000] = {false}; long double pd(int i, int heads) { if (i < 0) { return heads > n / 2 ? 1 : 0; } long double &ans = PD[i][heads]; if (visited[i][heads]) { return ans; } ans = pd(i - 1, heads + 1) * p[i] + pd(i - 1, heads) * (1 - p[i]); visited[i][heads] = true; return ans; } int main() { scanf("%d", &n); FOR(i, 0, n) { scanf("%Lf", p + i); } printf("%.10Lf\n", pd(n - 1, 0)); return 0; }
insert
42
42
42
43
TLE
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int INF = 1145141919; const long long INFL = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } double dp[3000][3000] = {}; vector<double> P; int n; double rec(int d, int x) { if (dp[d][x]) { return dp[d][x]; } if (d == n) { if (n / 2 + n % 2 > x) { return 0; } else { return 1; } } double ret = 1; ret = rec(d + 1, x + 1) * P[d] + rec(d + 1, x) * (1 - P[d]); return dp[d][x] = ret; } int main() { cin >> n; double in; for (int i = 0; i < n; ++i) { cin >> in; P.push_back(in); } printf("%0.15lf\n", rec(0, 0)); }
#include <bits/stdc++.h> using namespace std; const int INF = 1145141919; const long long INFL = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } double dp[3000][3000] = {}; vector<double> P; int n; double rec(int d, int x) { if (dp[d][x]) { return dp[d][x]; } if (d == n) { if (n / 2 + n % 2 > x) { return 0; } else { return 1; } } double ret = 1; ret = rec(d + 1, x + 1) * P[d] + rec(d + 1, x) * (1 - P[d]); return dp[d][x] = ret; } int main() { cin >> n; double in; for (int i = 0; i < n; ++i) { cin >> in; P.push_back(in); } for (int i = n / 2 + 1; i <= n; ++i) { dp[n][i] = 1; } for (int i = n; i > 0; --i) { for (int j = n; j > 0; --j) { dp[i - 1][j - 1] = dp[i][j] * P[i - 1] + dp[i][j - 1] * (1 - P[i - 1]); } } printf("%0.15lf\n", dp[0][0]); }
replace
49
50
49
58
TLE
p03168
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <vector> #define ll long long const ll MOD = 1e9 + 7; int main() { std::ios::sync_with_stdio(false); int N; std::cin >> N; std::vector<double> p(N); double dp[N][N]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++) { std::cin >> p[i]; } dp[0][0] = 1; // i番目まで投げて for (int i = 0; i < N; ++i) { // j枚表が出てる場合 for (int j = 0; j <= i; ++j) { // i番目が表の場合 dp[i + 1][j + 1] += dp[i][j] * p[i]; // 裏の場合 dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } // N枚まで投げた時 半分以上表の確率の合計 double result = 0; for (int i = (N / 2 + 1); i <= N; ++i) { result += dp[N][i]; // std::cout << "表が" << i << "枚出る確率" << dp[N][i] << std::endl; } std::cout << std::fixed << std::setprecision(10) << result; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <vector> #define ll long long const ll MOD = 1e9 + 7; int main() { std::ios::sync_with_stdio(false); int N; std::cin >> N; std::vector<double> p(N); double dp[N + 1][N + 1]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++) { std::cin >> p[i]; } dp[0][0] = 1; // i番目まで投げて for (int i = 0; i < N; ++i) { // j枚表が出てる場合 for (int j = 0; j <= i; ++j) { // i番目が表の場合 dp[i + 1][j + 1] += dp[i][j] * p[i]; // 裏の場合 dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } // N枚まで投げた時 半分以上表の確率の合計 double result = 0; for (int i = (N / 2 + 1); i <= N; ++i) { result += dp[N][i]; // std::cout << "表が" << i << "枚出る確率" << dp[N][i] << std::endl; } std::cout << std::fixed << std::setprecision(10) << result; }
replace
18
19
18
19
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define sc second #define fr first #define mp make_pair const int N = 2e3 + 10, Max = 50 + 10; const int MOD = 1e9 + 7; double a[N]; double dp[N][N]; int n, m; double solve(int i, int s) { if (i == n + 1) { return s > n / 2 ? 1.0 : 0.0; } double &ret = dp[i][s]; if (ret == ret) return ret; double c1 = solve(i + 1, s) * (1.0 - a[i]); double c2 = solve(i + 1, s + 1) * a[i]; return ret = c1 + c2; } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << solve(1, 0) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define sc second #define fr first #define mp make_pair const int N = 3e3 + 10, Max = 50 + 10; const int MOD = 1e9 + 7; double a[N]; double dp[N][N]; int n, m; double solve(int i, int s) { if (i == n + 1) { return s > n / 2 ? 1.0 : 0.0; } double &ret = dp[i][s]; if (ret == ret) return ret; double c1 = solve(i + 1, s) * (1.0 - a[i]); double c2 = solve(i + 1, s + 1) * a[i]; return ret = c1 + c2; } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << solve(1, 0) << endl; }
replace
7
8
7
8
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define f first #define s second #define int long long using namespace std; const int N = 3005; double p[N]; double dp[N][N]; int32_t main() { ios::sync_with_stdio(false); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> p[i]; } for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) dp[i][j] = 1; } dp[1][0] = double(1 - p[1]); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0 && i == 1) continue; if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i]); } if (i == j) { dp[i][j] = dp[i - 1][j - 1] * p[i]; } else dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * (p[i]); } } int mid = n / 2 + n % 2; double ans = 0; for (int i = mid; i <= n; ++i) { ans += dp[n][i]; } cout << fixed << setprecision(10) << ans; }
#include <bits/stdc++.h> #define f first #define s second #define int long long using namespace std; const int N = 3005; double p[N]; double dp[N][N]; int32_t main() { ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> p[i]; } for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) dp[i][j] = 1; } dp[1][0] = double(1 - p[1]); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0 && i == 1) continue; if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i]); } if (i == j) { dp[i][j] = dp[i - 1][j - 1] * p[i]; } else dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * (p[i]); } } int mid = n / 2 + n % 2; double ans = 0; for (int i = mid; i <= n; ++i) { ans += dp[n][i]; } cout << fixed << setprecision(10) << ans; }
replace
14
16
14
16
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long double ll; const ll MAX = 400; vector<ll> ar(3000); vector<vector<ll>> dp(MAX, vector<ll>(MAX, -1)); ll func(ll n, ll k) { if (n == 0 && k == 0) { return 1; } if (k > n) { return 0; } if (k < 0 || n < 0) { return 0; } if (dp[n][k] != -1) { return dp[n][k]; } else { return dp[n][k] = func(n - 1, k) * (1 - ar[n]) + func(n - 1, k - 1) * ar[n]; } } int main() { int n; cin >> n; for (int x = 1; x <= n; x++) { cin >> ar[x]; } ll a = 0; ll max = 0; while (max <= n) { if (max > n / 2) a += func(n, max); max++; } cout << std::setprecision(10) << a << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long double ll; const ll MAX = 4000; vector<ll> ar(3000); vector<vector<ll>> dp(MAX, vector<ll>(MAX, -1)); ll func(ll n, ll k) { if (n == 0 && k == 0) { return 1; } if (k > n) { return 0; } if (k < 0 || n < 0) { return 0; } if (dp[n][k] != -1) { return dp[n][k]; } else { return dp[n][k] = func(n - 1, k) * (1 - ar[n]) + func(n - 1, k - 1) * ar[n]; } } int main() { int n; cin >> n; for (int x = 1; x <= n; x++) { cin >> ar[x]; } ll a = 0; ll max = 0; while (max <= n) { if (max > n / 2) a += func(n, max); max++; } cout << std::setprecision(10) << a << endl; }
replace
6
7
6
7
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long double P[1003], dp[1003][1003]; int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int N; cin >> N; for (int i = 1; i <= N; i++) cin >> P[i]; dp[0][0] = 1; for (int i = 1; i <= N; i++) for (int j = 0; j <= N; j++) { dp[i][j] = dp[i - 1][j] * (1 - P[i]); if (j >= 1) dp[i][j] += dp[i - 1][j - 1] * P[i]; } long double ans = 0; for (int tail = 0, head = N; head > tail; tail++, head--) ans += dp[N][head]; cout << fixed << setprecision(12) << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long double P[3003], dp[3003][3003]; int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int N; cin >> N; for (int i = 1; i <= N; i++) cin >> P[i]; dp[0][0] = 1; for (int i = 1; i <= N; i++) for (int j = 0; j <= N; j++) { dp[i][j] = dp[i - 1][j] * (1 - P[i]); if (j >= 1) dp[i][j] += dp[i - 1][j - 1] * P[i]; } long double ans = 0; for (int tail = 0, head = N; head > tail; tail++, head--) ans += dp[N][head]; cout << fixed << setprecision(12) << ans << "\n"; return 0; }
replace
3
4
3
4
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define fr first #define sc second #define mp make_pair #define pb push_back #define pf push_front #define ll long long using namespace std; void TxtRead() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void TheTime() { ios_base::sync_with_stdio(false); cin.tie(); } const int N = 1e3 + 5; const ll INF = 1e9 + 5; const ll MOD = 1e9 + 7; const double PI = 3.141592653589793116; int n; double ar[N], dp[N][N]; int main() { // TxtRead(); TheTime(); scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%lf", &ar[i]); dp[i][0] = dp[i - 1][0] * (1 - ar[i]); } dp[1][1] = ar[1]; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { dp[j][i] = dp[j - 1][i - 1] * ar[j] + dp[j - 1][i] * (1 - ar[j]); } } double ans = 0; for (int i = n / 2 + n % 2; i <= n; i++) { ans += dp[n][i]; } printf("%.9lf\n", ans); }
#include <bits/stdc++.h> #define fr first #define sc second #define mp make_pair #define pb push_back #define pf push_front #define ll long long using namespace std; void TxtRead() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void TheTime() { ios_base::sync_with_stdio(false); cin.tie(); } const int N = 3e3 + 5; const ll INF = 1e9 + 5; const ll MOD = 1e9 + 7; const double PI = 3.141592653589793116; int n; double ar[N], dp[N][N]; int main() { // TxtRead(); TheTime(); scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%lf", &ar[i]); dp[i][0] = dp[i - 1][0] * (1 - ar[i]); } dp[1][1] = ar[1]; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { dp[j][i] = dp[j - 1][i - 1] * ar[j] + dp[j - 1][i] * (1 - ar[j]); } } double ans = 0; for (int i = n / 2 + n % 2; i <= n; i++) { ans += dp[n][i]; } printf("%.9lf\n", ans); }
replace
16
17
16
17
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> #define pi acos(-1) #define ll long long #define pii pair<ll, ll> #define debug(a) cout << a << '\n' #define maxn 3009 /// Still trying to be normal #define MOD 1000000007 #define F first #define S second #define rep(i, a, b) for (ll i = a; i < (b); ++i) #define per(i, b, a) for (ll i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (ll)(x).size() using namespace std; const ll INF = 1e9 + 15; double dp[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); ll n; cin >> n; rep(i, 0, maxn) { rep(j, 0, maxn) { dp[i][j] = 0; } } dp[0][0] = 1; double pr[maxn]; rep(i, 0, n) cin >> pr[i]; rep(i, 0, n + 1) { rep(j, 0, n + 1) { if (i == 0 && j == 0) continue; if (i > 0) dp[i][j] += dp[i - 1][j] * pr[i + j - 1]; if (j > 0) dp[i][j] += dp[i][j - 1] * (1 - pr[i + j - 1]); } } double ans = 0; rep(i, 0, n + 1) { rep(j, 0, n + 1) { if (i + j == n && i > j) ans += dp[i][j]; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define pi acos(-1) #define ll long long #define pii pair<ll, ll> #define debug(a) cout << a << '\n' #define maxn 3009 /// Still trying to be normal #define MOD 1000000007 #define F first #define S second #define rep(i, a, b) for (ll i = a; i < (b); ++i) #define per(i, b, a) for (ll i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (ll)(x).size() using namespace std; const ll INF = 1e9 + 15; double dp[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); ll n; cin >> n; rep(i, 0, maxn) { rep(j, 0, maxn) { dp[i][j] = 0; } } dp[0][0] = 1; double pr[maxn]; rep(i, 0, n) cin >> pr[i]; rep(i, 0, n + 1) { rep(j, 0, n + 1) { if (i + j > n) continue; if (i > 0) dp[i][j] += dp[i - 1][j] * pr[i + j - 1]; if (j > 0) dp[i][j] += dp[i][j - 1] * (1 - pr[i + j - 1]); } } double ans = 0; rep(i, 0, n + 1) { rep(j, 0, n + 1) { if (i + j == n && i > j) ans += dp[i][j]; } } cout << ans << "\n"; return 0; }
replace
32
33
32
33
0
p03168
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ms(s) memset(s, 0, sizeof(s)) const int INF = 1e9; inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } double dp[3000][3000]; double dat[3000]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> dat[i]; } dp[0][0] = 1.0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j] += dp[i][j] * (1.0 - dat[i + 1]); dp[i + 1][j + 1] += dp[i][j] * (dat[i + 1]); } } double sum = 0.0; for (int i = (n + 1) / 2; i <= n; i++) { sum += dp[n][i]; } printf("%.9f", sum); return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ms(s) memset(s, 0, sizeof(s)) const int INF = 1e9; inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } double dp[3005][3005]; double dat[3005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> dat[i]; } dp[0][0] = 1.0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j] += dp[i][j] * (1.0 - dat[i + 1]); dp[i + 1][j + 1] += dp[i][j] * (dat[i + 1]); } } double sum = 0.0; for (int i = (n + 1) / 2; i <= n; i++) { sum += dp[n][i]; } printf("%.9f", sum); return 0; }
replace
35
37
35
37
0
p03168
C++
Time Limit Exceeded
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n; vector<double> prob; double dp[3001][3001]; double rec(long long ntail, long long nhead) { if (ntail + nhead == n) return (nhead > ntail); if (dp[ntail + nhead][nhead] != -1.0) return dp[ntail][nhead]; double a = prob[ntail + nhead] * rec(ntail, nhead + 1); double b = (1 - prob[ntail + nhead]) * rec(ntail + 1, nhead); return dp[ntail][nhead] = a + b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < 3001; i++) for (int j = 0; j < 3001; j++) dp[i][j] = -1.0; cin >> n; prob.resize(n); for (int i = 0; i < n; i++) cin >> prob[i]; cout << fixed << setprecision(9) << rec(0, 0); }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n; vector<double> prob; double dp[3001][3001]; double rec(long long ntail, long long nhead) { if (ntail + nhead == n) return (nhead > ntail); if (dp[ntail][nhead] != -1.0) return dp[ntail][nhead]; double a = prob[ntail + nhead] * rec(ntail, nhead + 1); double b = (1 - prob[ntail + nhead]) * rec(ntail + 1, nhead); return dp[ntail][nhead] = a + b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < 3001; i++) for (int j = 0; j < 3001; j++) dp[i][j] = -1.0; cin >> n; prob.resize(n); for (int i = 0; i < n; i++) cin >> prob[i]; cout << fixed << setprecision(9) << rec(0, 0); }
replace
10
11
10
11
TLE
p03168
C++
Time Limit Exceeded
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } ll n; ld p[3000]; ld dp[3000][3000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; i++) { cin >> p[i]; } dp[0][0] = 1; for (ll i = 0; i < n; i++) { for (ll j = 0; j <= n; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; dp[i + 1][j] += dp[i][j] * (1.0 - p[i + 1]); } } ld ans = 0; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) trace1(dp[i][j]); } for (ll i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(18) << ans; return 0; } /* The judge is never wrong! Your code is buggy Look for: * * Read the problem carefully. * * Don't forget to sort(), mod, ll!!!! * * Initial value = +/- infinity instead of zero!!! * * an easier and alternate approach * * read the problem statement carefully * * if concept is correct and still WA, try with a different implementation * * special cases (n=1?) * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/ */
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } ll n; ld p[3000]; ld dp[3000][3000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (ll i = 1; i <= n; i++) { cin >> p[i]; } dp[0][0] = 1; for (ll i = 0; i < n; i++) { for (ll j = 0; j <= n; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i + 1]; dp[i + 1][j] += dp[i][j] * (1.0 - p[i + 1]); } } ld ans = 0; for (ll i = n / 2 + 1; i <= n; i++) { ans += dp[n][i]; } cout << fixed << setprecision(18) << ans; return 0; } /* The judge is never wrong! Your code is buggy Look for: * * Read the problem carefully. * * Don't forget to sort(), mod, ll!!!! * * Initial value = +/- infinity instead of zero!!! * * an easier and alternate approach * * read the problem statement carefully * * if concept is correct and still WA, try with a different implementation * * special cases (n=1?) * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/ */
delete
84
88
84
84
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxS = 1e3 + 7; long double probs[maxS]; long double dp[maxS][maxS]; long double ONE = 1.000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> probs[i]; } for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { dp[i][j] = 0.000000000; } } for (int i = 1; i <= N; i++) { for (int j = 0; j <= i; j++) { if (i == 1 && j == 0) { dp[i][j] = ONE - probs[i]; continue; } if (i == 1 && j == 1) { dp[i][j] = probs[i]; continue; } if (j == 0) { dp[i][j] = dp[i - 1][j] * (ONE - probs[i]); continue; } dp[i][j] = dp[i - 1][j] * (ONE - probs[i]) + (dp[i - 1][j - 1] * probs[i]); // cout << dp[i][j] << " "; } // cout << "\n"; } long double probOfMoreHeadsThanTails = 0.000000000; for (int i = N / 2 + 1; i <= N; i++) { probOfMoreHeadsThanTails += dp[N][i]; // cout << i << " " << dp[N][i] << "\n"; } cout << setprecision(9) << fixed; cout << probOfMoreHeadsThanTails << "\n"; }
#include <bits/stdc++.h> using namespace std; const int maxS = 3e3 + 7; long double probs[maxS]; long double dp[maxS][maxS]; long double ONE = 1.000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> probs[i]; } for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { dp[i][j] = 0.000000000; } } for (int i = 1; i <= N; i++) { for (int j = 0; j <= i; j++) { if (i == 1 && j == 0) { dp[i][j] = ONE - probs[i]; continue; } if (i == 1 && j == 1) { dp[i][j] = probs[i]; continue; } if (j == 0) { dp[i][j] = dp[i - 1][j] * (ONE - probs[i]); continue; } dp[i][j] = dp[i - 1][j] * (ONE - probs[i]) + (dp[i - 1][j - 1] * probs[i]); // cout << dp[i][j] << " "; } // cout << "\n"; } long double probOfMoreHeadsThanTails = 0.000000000; for (int i = N / 2 + 1; i <= N; i++) { probOfMoreHeadsThanTails += dp[N][i]; // cout << i << " " << dp[N][i] << "\n"; } cout << setprecision(9) << fixed; cout << probOfMoreHeadsThanTails << "\n"; }
replace
3
4
3
4
0
p03168
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS // #include <stdafx.h> // #include "targetver.h" #include <stdio.h> // #include <tchar.h> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif> #define LL long long #define MOD 998244353 #define INF 1000000000 #define LINF 1000000000000000000 using namespace std; const int N = 2e3 + 10; double a[N], sum; double b[N]; double dp[N][N]; vector<int> vec; int n; int main() { cout << fixed << setprecision(10); double p1, p2; scanf("%d", &n); for (int i = 0; i < n; i++) cin >> a[i]; // scanf("%f", &a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = 1; dp[0][0] = 1.0 - a[0]; dp[0][1] = a[0]; for (int i = 1; i < n; i++) for (int j = 0; j <= i + 1; j++) { p1 = dp[i - 1][j] != 1 ? dp[i - 1][j] * (1.0 - a[i]) : 0; p2 = j > 0 ? dp[i - 1][j - 1] * a[i] : 0; dp[i][j] = p1 + p2; } for (int i = n / 2 + 1; i <= n; i++) sum += dp[n - 1][i]; cout << sum; }
#define _CRT_SECURE_NO_WARNINGS // #include <stdafx.h> // #include "targetver.h" #include <stdio.h> // #include <tchar.h> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif> #define LL long long #define MOD 998244353 #define INF 1000000000 #define LINF 1000000000000000000 using namespace std; const int N = 4e3 + 10; double a[N], sum; double b[N]; double dp[N][N]; vector<int> vec; int n; int main() { cout << fixed << setprecision(10); double p1, p2; scanf("%d", &n); for (int i = 0; i < n; i++) cin >> a[i]; // scanf("%f", &a[i]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = 1; dp[0][0] = 1.0 - a[0]; dp[0][1] = a[0]; for (int i = 1; i < n; i++) for (int j = 0; j <= i + 1; j++) { p1 = dp[i - 1][j] != 1 ? dp[i - 1][j] * (1.0 - a[i]) : 0; p2 = j > 0 ? dp[i - 1][j - 1] * a[i] : 0; dp[i][j] = p1 + p2; } for (int i = n / 2 + 1; i <= n; i++) sum += dp[n - 1][i]; cout << sum; }
replace
67
68
67
68
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; /*#include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; /*template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; */ typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pl; typedef pair<int, int> pii; #define LOCAL 0 #define dbg(x) cout << #x << " is " << x << "\n" #define gll(x) scanf("%d", &x) #define gll2(x, y) scanf("%d%d", &x, &y) #define gll3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define gllarr(arr, n) f(i, n) gll(arr[i]); #define sz(x) ((int)x.size()) #define s(x) sort(x.begin(), x.end()) #define all(v) v.begin(), v.end() #define rs(v) \ { \ s(v); \ r(v); \ } #define r(v) \ { reverse(all(v)); } #define pb push_back #define f(i, n) for (int i = 0; i < n; i++) #define fr(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) const ll mod = (ll)1e9 + 7; const ll inf = (ll)1e16; const ld eps = 1e-12; const ll N = (int)1e5 + 5; const ll LOGN = 19; const ld PI = 3.14159265358979323846; inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m; } inline ll add(ll a, ll b, ll m = mod) { a += b; if (a >= m) a -= m; if (a < 0) a += m; return a; } inline ll power(ll a, ll b, ll m = mod) { if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if (b % 2) x = mul(x, a, m); return x; } int n; ld p[3002]; ld dp[3002][3002]; bool vis[3002][3002]; ld rec(int pos, int heads) { if (pos >= n) { if (heads > 0) { return (ld)0; } return (ld)1; } ld A = 0, B = 0; if (heads > 0) A = rec(pos + 1, heads - 1) * p[pos]; B = rec(pos + 1, heads) * (1 - p[pos]); vis[pos][heads] = true; return dp[pos][heads] = A + B; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (LOCAL) { freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin); freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout); } cin >> n; f(i, n) cin >> p[i]; memset(vis, false, sizeof(vis)); int to = (n + 1) / 2; ld ans = 0; rep(i, to, n) ans += rec(0, i); cout << setprecision(10) << fixed << ans; return 0; }
#include <bits/stdc++.h> using namespace std; /*#include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; /*template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; */ typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pl; typedef pair<int, int> pii; #define LOCAL 0 #define dbg(x) cout << #x << " is " << x << "\n" #define gll(x) scanf("%d", &x) #define gll2(x, y) scanf("%d%d", &x, &y) #define gll3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define gllarr(arr, n) f(i, n) gll(arr[i]); #define sz(x) ((int)x.size()) #define s(x) sort(x.begin(), x.end()) #define all(v) v.begin(), v.end() #define rs(v) \ { \ s(v); \ r(v); \ } #define r(v) \ { reverse(all(v)); } #define pb push_back #define f(i, n) for (int i = 0; i < n; i++) #define fr(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) const ll mod = (ll)1e9 + 7; const ll inf = (ll)1e16; const ld eps = 1e-12; const ll N = (int)1e5 + 5; const ll LOGN = 19; const ld PI = 3.14159265358979323846; inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m; } inline ll add(ll a, ll b, ll m = mod) { a += b; if (a >= m) a -= m; if (a < 0) a += m; return a; } inline ll power(ll a, ll b, ll m = mod) { if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if (b % 2) x = mul(x, a, m); return x; } int n; ld p[3002]; ld dp[3002][3002]; bool vis[3002][3002]; ld rec(int pos, int heads) { if (pos >= n) { if (heads > 0) { return (ld)0; } return (ld)1; } if (vis[pos][heads]) return dp[pos][heads]; ld A = 0, B = 0; if (heads > 0) A = rec(pos + 1, heads - 1) * p[pos]; B = rec(pos + 1, heads) * (1 - p[pos]); vis[pos][heads] = true; return dp[pos][heads] = A + B; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (LOCAL) { freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin); freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout); } cin >> n; f(i, n) cin >> p[i]; memset(vis, false, sizeof(vis)); int to = (n + 1) / 2; ld ans = 0; rep(i, to, n) ans += rec(0, i); cout << setprecision(10) << fixed << ans; return 0; }
insert
76
76
76
78
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n; double h[3010], t[3010], memo[3010][3010], ret = 0; double dp(int idx, int head) { if (idx == 0 && head == 0) { return (double)1.00; } if (memo[idx][head] != -1) { return memo[idx][head]; } memo[idx][head] = dp(idx - 1, head - 1) * h[idx] + dp(idx - 1, head) * t[idx]; return memo[idx][head]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); for (int i = 0; i < 3010; i++) { for (int j = 0; j < 3010; j++) { memo[i][j] = -1; } } cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; t[i] = 1 - h[i]; } for (int i = (n + 2) / 2; i <= n; i++) { ret = ret + dp(n, i); } cout << fixed << setprecision(10) << ret << endl; }
#include <bits/stdc++.h> using namespace std; long long n; double h[3010], t[3010], memo[3010][3010], ret = 0; double dp(int idx, int head) { if (idx == 0 && head == 0) { return (double)1.00; } else if (idx == 0 && head != 0) { return (double)0.00; } if (memo[idx][head] != -1) { return memo[idx][head]; } memo[idx][head] = dp(idx - 1, head - 1) * h[idx] + dp(idx - 1, head) * t[idx]; return memo[idx][head]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); for (int i = 0; i < 3010; i++) { for (int j = 0; j < 3010; j++) { memo[i][j] = -1; } } cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; t[i] = 1 - h[i]; } for (int i = (n + 2) / 2; i <= n; i++) { ret = ret + dp(n, i); } cout << fixed << setprecision(10) << ret << endl; }
insert
10
10
10
12
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define pb push_back const ll mod = 1e9 + 7; template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } const ll N = 1e6 + 8; const ll INF = 1e18; ll n; ld a[3001]; ld dp[3001][3001]; bool vis[3001][3001]; ld func(ll size, ll req) { if (req < 0) return 0.0; if (size == -1) { if (req == 0) return 1.0; else return 0.0; } if (vis[size][req]) return dp[size][req]; ld res = a[size] * func(size - 1, req - 1) + (1 - a[size]) * func(size - 1, req); return dp[size][req] = res; } int main() { cin >> n; for (ll i = 0; i < n; i++) cin >> a[i]; ld ans = 0.0; memset(vis, 0, sizeof(vis)); for (ll i = (n / 2) + 1; i <= n; i++) { ans += func(n - 1, i); } cout << fixed << setprecision(12) << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define pb push_back const ll mod = 1e9 + 7; template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } const ll N = 1e6 + 8; const ll INF = 1e18; ll n; ld a[3001]; ld dp[3001][3001]; bool vis[3001][3001]; ld func(ll size, ll req) { if (req < 0) return 0.0; if (size == -1) { if (req == 0) return 1.0; else return 0.0; } if (vis[size][req]) return dp[size][req]; ld res = a[size] * func(size - 1, req - 1) + (1 - a[size]) * func(size - 1, req); vis[size][req] = 1; return dp[size][req] = res; } int main() { cin >> n; for (ll i = 0; i < n; i++) cin >> a[i]; ld ans = 0.0; memset(vis, 0, sizeof(vis)); for (ll i = (n / 2) + 1; i <= n; i++) { ans += func(n - 1, i); } cout << fixed << setprecision(12) << ans << endl; }
insert
39
39
39
40
TLE
p03169
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define STI(s) atoi(s.c_str()) #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; vector<vector<vector<double>>> dp(300, vector<vector<double>>(300, vd(300, -1))); int n; double rec(double i, double j, double k) { double res = 0.0; if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += n; res /= (i + j + k); return dp[i][j][k] = res; } int main(void) { cin >> n; vi a(n); rep(i, n) cin >> a[i]; int in[3] = {0}; rep(i, a.size()) { in[a[i] - 1]++; } printf("%.9f\n", rec(in[0], in[1], in[2])); }
#include <algorithm> #include <bitset> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #pragma GCC optimize("Ofast") using namespace std; typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef vector<vector<int>> vvi; typedef vector<vector<char>> vvc; typedef vector<vector<string>> vvs; typedef vector<vector<ll>> vvll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define fin(ans) cout << (ans) << '\n' #define STI(s) atoi(s.c_str()) #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define Rort(a) sort(a.rbegin(), a.rend()) #define MATHPI acos(-1) #define itn int; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; vector<vector<vector<double>>> dp(310, vector<vector<double>>(310, vd(310, -1))); int n; double rec(double i, double j, double k) { double res = 0.0; if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += n; res /= (i + j + k); return dp[i][j][k] = res; } int main(void) { cin >> n; vi a(n); rep(i, n) cin >> a[i]; int in[3] = {0}; rep(i, a.size()) { in[a[i] - 1]++; } printf("%.9f\n", rec(in[0], in[1], in[2])); }
replace
73
75
73
75
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, m, n) for (long long i = (m); i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() #define SPEED \ cin.tie(0); \ ios::sync_with_stdio(false); template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; template <class T> using PQ = priority_queue<T>; template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>; constexpr long long MOD = (long long)1e9 + 7; constexpr long long MOD2 = 998244353; constexpr long long HIGHINF = (long long)1e18; constexpr long long LOWINF = (long long)1e15; constexpr long double PI = 3.1415926535897932384626433; template <class T> vector<T> multivector(size_t N, T init) { return vector<T>(N, init); } template <class... T> auto multivector(size_t N, T... t) { return vector<decltype(multivector(t...))>(N, multivector(t...)); } template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head &&head) { cout << head; print(); } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); } template <class T> void chmax(T &a, const T b) { a = max(a, b); } template <class T> void chmin(T &a, const T b) { a = min(a, b); } void YN(bool flg) { cout << (flg ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << (flg ? "Yes" : "No") << endl; } void yn(bool flg) { cout << (flg ? "yes" : "no") << endl; } int N; auto dp = multivector(300, 300, 300, -1.0); double rec(int i, int j, int k) { if (dp[i][j][k] != -1.0) return dp[i][j][k]; double x = i, y = j, z = k, M = N, res = 1.; if (i) res += x / M * rec(i - 1, j + 1, k); if (j) res += y / M * rec(i, j - 1, k + 1); if (k) res += z / M * rec(i, j, k - 1); if (N != i + j + k) res *= M / (x + y + z); return dp[i][j][k] = res; } int main() { cin >> N; dp[0][0][0] = 0.; int a = 0, b = 0, c = 0; for (int i = 0; i < N; ++i) { int d; cin >> d; if (d == 3) a++; if (d == 2) b++; if (d == 1) c++; } printf("%.10f", rec(a, b, c)); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, m, n) for (long long i = (m); i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() #define SPEED \ cin.tie(0); \ ios::sync_with_stdio(false); template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; template <class T> using PQ = priority_queue<T>; template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>; constexpr long long MOD = (long long)1e9 + 7; constexpr long long MOD2 = 998244353; constexpr long long HIGHINF = (long long)1e18; constexpr long long LOWINF = (long long)1e15; constexpr long double PI = 3.1415926535897932384626433; template <class T> vector<T> multivector(size_t N, T init) { return vector<T>(N, init); } template <class... T> auto multivector(size_t N, T... t) { return vector<decltype(multivector(t...))>(N, multivector(t...)); } template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head &&head) { cout << head; print(); } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); } template <class T> void chmax(T &a, const T b) { a = max(a, b); } template <class T> void chmin(T &a, const T b) { a = min(a, b); } void YN(bool flg) { cout << (flg ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << (flg ? "Yes" : "No") << endl; } void yn(bool flg) { cout << (flg ? "yes" : "no") << endl; } int N; auto dp = multivector(301, 301, 301, -1.0); double rec(int i, int j, int k) { if (dp[i][j][k] != -1.0) return dp[i][j][k]; double x = i, y = j, z = k, M = N, res = 1.; if (i) res += x / M * rec(i - 1, j + 1, k); if (j) res += y / M * rec(i, j - 1, k + 1); if (k) res += z / M * rec(i, j, k - 1); if (N != i + j + k) res *= M / (x + y + z); return dp[i][j][k] = res; } int main() { cin >> N; dp[0][0][0] = 0.; int a = 0, b = 0, c = 0; for (int i = 0; i < N; ++i) { int d; cin >> d; if (d == 3) a++; if (d == 2) b++; if (d == 1) c++; } printf("%.10f", rec(a, b, c)); }
replace
94
95
94
95
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; // まずは状態を定義。寿司の順番に意味が無いことに気づくので、状態としては、残りの寿司の個数がk枚の皿がそれぞれ何枚あるかということになる。 // 状態遷移は、サイコロを一回降った時にどうなるかを考える。遷移式はそのままだと0個の皿を引いたときに無限ループになるので式変形する必要あり。 // dp[x][y][z] 残り一個のものがx, 残り二個のものがy, // 残り三個のものがzのときの期待値 const int maxn = 7; long double dp[maxn][maxn][maxn]; bool done[maxn][maxn][maxn]; int n; long double dfs(int x, int y, int z) { if ((x == 0 && y == 0 && z == 0) || (x < 0 || y < 0 || z < 0)) return 0.0; if (done[x][y][z]) return dp[x][y][z]; long double s = x + y + z; dp[x][y][z] = dfs(x - 1, y, z) * x / s + dfs(x + 1, y - 1, z) * y / s + dfs(x, y + 1, z - 1) * z / s + n / s; done[x][y][z] = true; return dp[x][y][z]; } int main() { cin >> n; int one = 0, two = 0, three = 0, tmp; for (int i = 1; i <= n; i++) { cin >> tmp; if (tmp == 1) one++; if (tmp == 2) two++; if (tmp == 3) three++; } for (int i = 0; i < maxn; i++) { for (int j = 0; j < maxn; j++) { for (int k = 0; k < maxn; k++) { done[i][j][k] = false; } } } long double res = 0.0; res = dfs(one, two, three); cout << fixed << setprecision(10); cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; // まずは状態を定義。寿司の順番に意味が無いことに気づくので、状態としては、残りの寿司の個数がk枚の皿がそれぞれ何枚あるかということになる。 // 状態遷移は、サイコロを一回降った時にどうなるかを考える。遷移式はそのままだと0個の皿を引いたときに無限ループになるので式変形する必要あり。 // dp[x][y][z] 残り一個のものがx, 残り二個のものがy, // 残り三個のものがzのときの期待値 const int maxn = 301; long double dp[maxn][maxn][maxn]; bool done[maxn][maxn][maxn]; int n; long double dfs(int x, int y, int z) { if ((x == 0 && y == 0 && z == 0) || (x < 0 || y < 0 || z < 0)) return 0.0; if (done[x][y][z]) return dp[x][y][z]; long double s = x + y + z; dp[x][y][z] = dfs(x - 1, y, z) * x / s + dfs(x + 1, y - 1, z) * y / s + dfs(x, y + 1, z - 1) * z / s + n / s; done[x][y][z] = true; return dp[x][y][z]; } int main() { cin >> n; int one = 0, two = 0, three = 0, tmp; for (int i = 1; i <= n; i++) { cin >> tmp; if (tmp == 1) one++; if (tmp == 2) two++; if (tmp == 3) three++; } for (int i = 0; i < maxn; i++) { for (int j = 0; j < maxn; j++) { for (int k = 0; k < maxn; k++) { done[i][j][k] = false; } } } long double res = 0.0; res = dfs(one, two, three); cout << fixed << setprecision(10); cout << res << endl; return 0; }
replace
9
10
9
10
0
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lop(i, n) for (ll i = 0; i < n; i++) #define lop1(i, n) for (ll i = 1; i <= n; i++) #define lopr(i, n) for (ll i = n - 1; i >= 0; i--) #define ll long long int #define pb push_back #define all(v) v.begin(), v.end() #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl "\n" #define F first #define S second #define mem(arr, val) memset(arr, val, sizeof(arr)) #define pii pair<int, int> #define pll pair<ll, ll> #define LCM(a, b) (a * b) / __gcd(a, b) #define mii map<int, int> #define mll map<ll, ll> #define ub upper_bound #define lb lower_bound #define sz(x) (ll) x.size() #define ld long double #define pcnt(x) __builtin_popcountll(x) const long long I1 = 1e9; const long long I2 = 1e18; const int32_t M1 = 1e9 + 7; const int32_t M2 = 998244353; template <typename T, typename T1> T maxn(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T minn(T &a, T1 b) { if (b < a) a = b; return a; } int n; ld dp[301][301][301]; /*ld f(int p, int q,int r) { if(p==0 && q==0 && r==0) return 0; ld x,val1=0,val2=0,val3=0; if(p>0) { x=(ld)(p)/(p+q+r); if(dp[p-1][q][r]==0) dp[p-1][q][r]=f(p-1,q,r); val1= (p==0?0:x*dp[p-1][q][r]); } if(q>0) { x=(ld)(q)/(p+q+r); if(dp[p+1][q-1][r]==0) dp[p+1][q-1][r]=f(p+1,q-1,r); val2= (q==0?0:x*dp[p+1][q-1][r]); } if(r>0) { x=(ld)(r)/(p+q+r); if(dp[p][q+1][r-1]==0) dp[p][q+1][r-1]=f(p,q+1,r-1); val3= (r==0?0:x*dp[p][q+1][r-1]); } // cout<<val1<<" "<<val2<<" "<<val3<<endl; ld ans=(ld)(n)/(p+q+r)+val1+val2+val3; // if(p==1) cout<<ans<<endl; return ans; }*/ void solve() { // code begins from here// cin >> n; int a[4] = {0}; lop(i, n) { int x; cin >> x; a[x]++; } lop(k, a[3] + 1) { lop(j, a[2] + 1 + a[3]) { lop(i, a[1] + 1 + a[2] + a[3]) { if (i == j && j == k && i == 0) continue; dp[i][j][k] = (ld)(n) / (i + j + k); if (i) dp[i][j][k] += ((ld)(i) / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += ((ld)(j) / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += ((ld)(k) / (i + j + k)) * dp[i][j + 1][k - 1]; } } } cout << fixed << setprecision(10) << dp[a[1]][a[2]][a[3]] << endl; } signed main() { IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #ifdef MODULO initialize(); #endif #ifdef SIEVE sieve(); #endif int testcase = 1; // cin>>testcase; while (testcase--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define lop(i, n) for (ll i = 0; i < n; i++) #define lop1(i, n) for (ll i = 1; i <= n; i++) #define lopr(i, n) for (ll i = n - 1; i >= 0; i--) #define ll long long int #define pb push_back #define all(v) v.begin(), v.end() #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl "\n" #define F first #define S second #define mem(arr, val) memset(arr, val, sizeof(arr)) #define pii pair<int, int> #define pll pair<ll, ll> #define LCM(a, b) (a * b) / __gcd(a, b) #define mii map<int, int> #define mll map<ll, ll> #define ub upper_bound #define lb lower_bound #define sz(x) (ll) x.size() #define ld long double #define pcnt(x) __builtin_popcountll(x) const long long I1 = 1e9; const long long I2 = 1e18; const int32_t M1 = 1e9 + 7; const int32_t M2 = 998244353; template <typename T, typename T1> T maxn(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T minn(T &a, T1 b) { if (b < a) a = b; return a; } int n; ld dp[301][301][301]; /*ld f(int p, int q,int r) { if(p==0 && q==0 && r==0) return 0; ld x,val1=0,val2=0,val3=0; if(p>0) { x=(ld)(p)/(p+q+r); if(dp[p-1][q][r]==0) dp[p-1][q][r]=f(p-1,q,r); val1= (p==0?0:x*dp[p-1][q][r]); } if(q>0) { x=(ld)(q)/(p+q+r); if(dp[p+1][q-1][r]==0) dp[p+1][q-1][r]=f(p+1,q-1,r); val2= (q==0?0:x*dp[p+1][q-1][r]); } if(r>0) { x=(ld)(r)/(p+q+r); if(dp[p][q+1][r-1]==0) dp[p][q+1][r-1]=f(p,q+1,r-1); val3= (r==0?0:x*dp[p][q+1][r-1]); } // cout<<val1<<" "<<val2<<" "<<val3<<endl; ld ans=(ld)(n)/(p+q+r)+val1+val2+val3; // if(p==1) cout<<ans<<endl; return ans; }*/ void solve() { // code begins from here// cin >> n; int a[4] = {0}; lop(i, n) { int x; cin >> x; a[x]++; } lop(k, a[3] + 1) { lop(j, a[2] + 1 + a[3]) { lop(i, a[1] + 1 + a[2] + a[3]) { if (i + k + j > a[1] + a[2] + a[3]) continue; if (i == j && j == k && i == 0) continue; dp[i][j][k] = (ld)(n) / (i + j + k); if (i) dp[i][j][k] += ((ld)(i) / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += ((ld)(j) / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += ((ld)(k) / (i + j + k)) * dp[i][j + 1][k - 1]; } } } cout << fixed << setprecision(10) << dp[a[1]][a[2]][a[3]] << endl; } signed main() { IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #ifdef MODULO initialize(); #endif #ifdef SIEVE sieve(); #endif int testcase = 1; // cin>>testcase; while (testcase--) solve(); return 0; }
insert
81
81
81
83
-11
p03169
C++
Runtime Error
#include <bits/stdc++.h> // #include "rubo.h" // #define mp make_pair // #define pb push_back #define in int #define ll long long #define vc vector #define SQ(j) (j) * (j) // #define x first // #define y second // #define ld long double #define dbl long double #define pll pair<long long, long long> #define pii pair<int, int> #define all(j) j.begin(), j.end() #define loop(xxx, yyy) for (int xxx = 0; xxx < yyy; xxx++) // #define printf(fmt, ...) (0) // #define HOME // #define y0 ngacaleiebinvoaeu // #define y1 gnarpipipaigare #define j1 adsfndnasfafoasp #define db(x) cout << #x << " = " << x << endl #define dbCont(x) \ cout << #x << ": "; \ for (auto shun : x) \ cout << shun << ' '; \ cout << endl; typedef long double ld; using namespace std; const int K = 100 * 100 + 123; const int N = 100 + 5; const int LG = 20; const int MOD = 1000 * 1000 * 1000 + 7; int n; int a[5]; double memo[N][N][N]; double solve(int c0, int c1, int c2, int c3) { if (memo[c1][c2][c3] >= 0) return memo[c1][c2][c3]; if (c1 + c2 + c3 == 0) return 0; double res = 0; if (c1) res += (c1 + 0.0) / (n) * (solve(c0 + 1, c1 - 1, c2, c3)); if (c2) res += (c2 + 0.0) / (n) * (solve(c0, c1 + 1, c2 - 1, c3)); if (c3) res += (c3 + 0.0) / (n) * (solve(c0, c1, c2 + 1, c3 - 1)); res += 1; res /= 1.0 - (c0 + 0.0) / n; return memo[c1][c2][c3] = res; } int main() { loop(i, N) loop(j, N) loop(k, N) memo[i][j][k] = -1; cin >> n; loop(i, n) { int e; cin >> e; a[e]++; } double res = solve(a[0], a[1], a[2], a[3]); printf("%.15lf\n", res); return 0; }
#include <bits/stdc++.h> // #include "rubo.h" // #define mp make_pair // #define pb push_back #define in int #define ll long long #define vc vector #define SQ(j) (j) * (j) // #define x first // #define y second // #define ld long double #define dbl long double #define pll pair<long long, long long> #define pii pair<int, int> #define all(j) j.begin(), j.end() #define loop(xxx, yyy) for (int xxx = 0; xxx < yyy; xxx++) // #define printf(fmt, ...) (0) // #define HOME // #define y0 ngacaleiebinvoaeu // #define y1 gnarpipipaigare #define j1 adsfndnasfafoasp #define db(x) cout << #x << " = " << x << endl #define dbCont(x) \ cout << #x << ": "; \ for (auto shun : x) \ cout << shun << ' '; \ cout << endl; typedef long double ld; using namespace std; const int K = 100 * 100 + 123; const int N = 300 + 5; const int LG = 20; const int MOD = 1000 * 1000 * 1000 + 7; int n; int a[5]; double memo[N][N][N]; double solve(int c0, int c1, int c2, int c3) { if (memo[c1][c2][c3] >= 0) return memo[c1][c2][c3]; if (c1 + c2 + c3 == 0) return 0; double res = 0; if (c1) res += (c1 + 0.0) / (n) * (solve(c0 + 1, c1 - 1, c2, c3)); if (c2) res += (c2 + 0.0) / (n) * (solve(c0, c1 + 1, c2 - 1, c3)); if (c3) res += (c3 + 0.0) / (n) * (solve(c0, c1, c2 + 1, c3 - 1)); res += 1; res /= 1.0 - (c0 + 0.0) / n; return memo[c1][c2][c3] = res; } int main() { loop(i, N) loop(j, N) loop(k, N) memo[i][j][k] = -1; cin >> n; loop(i, n) { int e; cin >> e; a[e]++; } double res = solve(a[0], a[1], a[2], a[3]); printf("%.15lf\n", res); return 0; }
replace
36
37
36
37
0
p03169
C++
Runtime Error
// #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vii = vector<int>; using pii = pair<int, int>; const ll INF = numeric_limits<ll>::max(), MOD = 1e9 + 7; const int INF_i = numeric_limits<int>::max(), MAX = 2e2 + 1; double dp[MAX][MAX][MAX], n; double f(int i, int j, int k) { if (i == 0 and j == 0 and k == 0) return 0; double &res = dp[i][j][k]; if (res != -1) return res; double m = i + j + k; res = n / m; if (i > 0) res += i * f(i - 1, j, k) / m; if (j > 0) res += j * f(i + 1, j - 1, k) / m; if (k > 0) res += k * f(i, j + 1, k - 1) / m; return res; } int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); // freopen("in.in", "r", stdin); cin >> n; int arr[3] = {}; for (int i = 0; i < n; i++) { int x; cin >> x; arr[x - 1]++; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { dp[i][j][k] = -1; } } } cout << fixed << setprecision(9) << f(arr[0], arr[1], arr[2]) << '\n'; }
// #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vii = vector<int>; using pii = pair<int, int>; const ll INF = numeric_limits<ll>::max(), MOD = 1e9 + 7; const int INF_i = numeric_limits<int>::max(), MAX = 3e2 + 1; double dp[MAX][MAX][MAX], n; double f(int i, int j, int k) { if (i == 0 and j == 0 and k == 0) return 0; double &res = dp[i][j][k]; if (res != -1) return res; double m = i + j + k; res = n / m; if (i > 0) res += i * f(i - 1, j, k) / m; if (j > 0) res += j * f(i + 1, j - 1, k) / m; if (k > 0) res += k * f(i, j + 1, k - 1) / m; return res; } int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); // freopen("in.in", "r", stdin); cin >> n; int arr[3] = {}; for (int i = 0; i < n; i++) { int x; cin >> x; arr[x - 1]++; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { dp[i][j][k] = -1; } } } cout << fixed << setprecision(9) << f(arr[0], arr[1], arr[2]) << '\n'; }
replace
12
13
12
13
0
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define dbl long double const int siz = 307; int n, J, D, T, sum; dbl dp[3][siz][siz]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); sum += x; if (x == 1) J++; if (x == 2) D++; if (x == 3) T++; } dp[0][0][0] = 0.0; int akt = 1, po = 0; for (int s = 1; s <= sum; s++) { for (int j = 0; j <= min(n, s); j++) { for (int d = 0; d <= n; d++) { if ((s - j - 2 * d) % 3 != 0) continue; int t = ((s - j - 2 * d) / 3), z = n - t - j - d; if ((d + t + z + j != n) or (d > D + T) or (t > T) or (j + 2 * d + 3 * t != s)) continue; dbl jeden, dwa, trzy; jeden = ((dbl)j / (dbl)n) * dp[po][j - 1][d]; dwa = ((dbl)d / (dbl)n) * dp[po][j + 1][d - 1]; trzy = ((dbl)t / (dbl)n) * dp[po][j][d + 1]; dp[akt][j][d] = ((dbl)n / (dbl)(n - z)) * ((dbl)1 + jeden + dwa + trzy); // printf("s = %d, jedynek jest %d, dwojek %d -> dp = // %lf\n",s,j,d,dp[s][j][d]); } } if (s == sum) break; if (akt == 1) { akt = 0; po = 1; } else { akt = 1; po = 0; } for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[akt][i][j] = (dbl)0; } printf("%.17Lf\n", dp[akt][J][D]); return 0; } // https://codeforces.com/contest/1245/problem/E
#include <bits/stdc++.h> using namespace std; #define dbl long double const int siz = 307; int n, J, D, T, sum; dbl dp[3][siz][siz]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); sum += x; if (x == 1) J++; if (x == 2) D++; if (x == 3) T++; } dp[0][0][0] = 0.0; int akt = 1, po = 0; for (int s = 1; s <= sum; s++) { for (int j = 0; j <= min(n, s); j++) { for (int d = 0; d <= n; d++) { if ((s - j - 2 * d) % 3 != 0) continue; int t = ((s - j - 2 * d) / 3), z = n - t - j - d; if ((d + t + z + j != n) or (d > D + T) or (t > T) or (j + 2 * d + 3 * t != s)) continue; dbl jeden, dwa, trzy; jeden = ((dbl)j / (dbl)n) * dp[po][max(0, j - 1)][d]; dwa = ((dbl)d / (dbl)n) * dp[po][j + 1][max(0, d - 1)]; trzy = ((dbl)t / (dbl)n) * dp[po][j][d + 1]; dp[akt][j][d] = ((dbl)n / (dbl)(n - z)) * ((dbl)1 + jeden + dwa + trzy); // printf("s = %d, jedynek jest %d, dwojek %d -> dp = // %lf\n",s,j,d,dp[s][j][d]); } } if (s == sum) break; if (akt == 1) { akt = 0; po = 1; } else { akt = 1; po = 0; } for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[akt][i][j] = (dbl)0; } printf("%.17Lf\n", dp[akt][J][D]); return 0; } // https://codeforces.com/contest/1245/problem/E
replace
37
39
37
39
0
p03169
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; typedef vector<int> vi; typedef unsigned long long ull; typedef long double ld; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds; ld dp[301][301][301]; int cnt[3]; bool valid(int x, int y, int z) { return (x >= 0 && y >= 0 && z >= 0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x--; cnt[x]++; } dp[0][0][0] = 0; for (int k = 0; k <= cnt[2]; k++) { for (int j = 0; j <= n; j++) { for (int i = 0; i <= n; i++) { if (i == 0 && j == 0 && k == 0) continue; dp[i][j][k] = 1; if (i > 0) dp[i][j][k] += ld(i) / ld(n) * dp[i - 1][j][k]; if (j > 0) dp[i][j][k] += ld(j) / ld(n) * dp[i + 1][j - 1][k]; if (k > 0) dp[i][j][k] += ld(k) / ld(n) * dp[i][j + 1][k - 1]; dp[i][j][k] *= ld(n) / ld(i + j + k); // cerr<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<'\n'; } } } cout << fixed << setprecision(15) << dp[cnt[0]][cnt[1]][cnt[2]] << '\n'; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; typedef vector<int> vi; typedef unsigned long long ull; typedef long double ld; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds; ld dp[311][311][311]; int cnt[3]; bool valid(int x, int y, int z) { return (x >= 0 && y >= 0 && z >= 0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x--; cnt[x]++; } dp[0][0][0] = 0; for (int k = 0; k <= cnt[2]; k++) { for (int j = 0; j <= n; j++) { for (int i = 0; i <= n; i++) { if (i == 0 && j == 0 && k == 0) continue; dp[i][j][k] = 1; if (i > 0) dp[i][j][k] += ld(i) / ld(n) * dp[i - 1][j][k]; if (j > 0) dp[i][j][k] += ld(j) / ld(n) * dp[i + 1][j - 1][k]; if (k > 0) dp[i][j][k] += ld(k) / ld(n) * dp[i][j + 1][k - 1]; dp[i][j][k] *= ld(n) / ld(i + j + k); // cerr<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<'\n'; } } } cout << fixed << setprecision(15) << dp[cnt[0]][cnt[1]][cnt[2]] << '\n'; }
replace
21
22
21
22
-11
p03169
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; int main() { int n; cin >> n; int k = 0, l = 0, m = 0; rep(i, n) { int a; cin >> a; if (a == 1) k++; else if (a == 2) l++; else m++; } vector<vector<vector<double>>> dp( n + 2, vector<vector<double>>(n + 2, vector<double>(n + 2, 0.0))); rep(z, n + 1) { rep(y, n + 1) { rep(x, n + 1) { if (x + y + z != 0) { double a = (double)x, b = (double)y, c = (double)z, d = (double)n; if (x) dp[x][y][z] += a * dp[x - 1][y][z]; if (y) dp[x][y][z] += b * dp[x + 1][y - 1][z]; if (z) dp[x][y][z] += c * dp[x][y + 1][z - 1]; dp[x][y][z] += d; dp[x][y][z] /= (a + b + c); } } } } printf("%.12f\n", dp[k][l][m]); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; int main() { int n; cin >> n; int k = 0, l = 0, m = 0; rep(i, n) { int a; cin >> a; if (a == 1) k++; else if (a == 2) l++; else m++; } vector<vector<vector<double>>> dp( n + 2, vector<vector<double>>(n + 2, vector<double>(n + 2, 0.0))); rep(z, n + 1) { rep(y, n + 1) { rep(x, n + 1) { if (x + y + z > n) break; if (x + y + z != 0) { double a = (double)x, b = (double)y, c = (double)z, d = (double)n; if (x) dp[x][y][z] += a * dp[x - 1][y][z]; if (y) dp[x][y][z] += b * dp[x + 1][y - 1][z]; if (z) dp[x][y][z] += c * dp[x][y + 1][z - 1]; dp[x][y][z] += d; dp[x][y][z] /= (a + b + c); } } } } printf("%.12f\n", dp[k][l][m]); return 0; }
insert
24
24
24
26
TLE
p03169
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define vi vector<int> #define vl vector<long long> #define vvi vector<vector<int>> #define fin(ar, k, n) \ for (int i = k; i < n; i++) \ cin >> ar[i] #define fout(ar, k, n) \ for (int i = k; i < n; i++) \ cout << ar[i] << ' ' #define all(z) z.begin(), z.end() #define mcc ((int)1e9 + 7) #define mcf 998244353 #define mi map<int, int> #define mem(a, n) memset(a, n, sizeof(a)) #define pii pair<int, int> #define mp(a, b) make_pair(a, b) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> fst; const int N = 307; double dp[N][N][N]; int n, c[4]; void solve() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; c[x]++; } for (int k = 0; k <= c[3]; k++) { for (int j = 0; j <= c[3] + c[2] - k; j++) { for (int i = 0; i <= c[3] + c[2] + c[1] - j - k; i++) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += i * 1.0 * dp[i - 1][j][k]; if (j) dp[i][j][k] += j * 1.0 * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += k * 1.0 * dp[i][j + 1][k - 1]; dp[i][j][k] += n + 0.0; dp[i][j][k] /= 1.0 * (i + k + j); } } } printf("%.12lf", dp[c[1]][c[2]][c[3]]); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define vi vector<int> #define vl vector<long long> #define vvi vector<vector<int>> #define fin(ar, k, n) \ for (int i = k; i < n; i++) \ cin >> ar[i] #define fout(ar, k, n) \ for (int i = k; i < n; i++) \ cout << ar[i] << ' ' #define all(z) z.begin(), z.end() #define mcc ((int)1e9 + 7) #define mcf 998244353 #define mi map<int, int> #define mem(a, n) memset(a, n, sizeof(a)) #define pii pair<int, int> #define mp(a, b) make_pair(a, b) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> fst; const int N = 307; double dp[N][N][N]; int n, c[4]; void solve() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; c[x]++; } for (int k = 0; k <= c[3]; k++) { for (int j = 0; j <= c[3] + c[2] - k; j++) { for (int i = 0; i <= c[3] + c[2] + c[1] - j - k; i++) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += i * 1.0 * dp[i - 1][j][k]; if (j) dp[i][j][k] += j * 1.0 * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += k * 1.0 * dp[i][j + 1][k - 1]; dp[i][j][k] += n + 0.0; dp[i][j][k] /= 1.0 * (i + k + j); } } } printf("%.12lf", dp[c[1]][c[2]][c[3]]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
delete
58
61
58
58
-11
p03169
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define endl '\n' using namespace std; const ll mod = (ll)1e9 + 7; const int INF = 0x3f3f3f3f; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } int n, x; vector<int> v(4); double dp[303][303][303]; double ev[303][303][303]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("C.txt", "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> x; v[x]++; } dp[v[1]][v[2]][v[3]] = 1; for (int c = n; c >= 0; c--) { for (int b = n; b >= 0; b--) { for (int a = n; a >= 0; a--) { if (a + b + c > n || a + b + c == 0) continue; ev[a][b][c] += (double)n / (a + b + c) * dp[a][b][c]; if (a != 0) { dp[a - 1][b][c] += dp[a][b][c] * (double)a / (a + b + c); ev[a - 1][b][c] += ev[a][b][c] * (double)a / (a + b + c); } if (b != 0) { dp[a + 1][b - 1][c] += dp[a][b][c] * (double)b / (a + b + c); ev[a + 1][b - 1][c] += ev[a][b][c] * (double)b / (a + b + c); } if (c != 0) { dp[a][b + 1][c - 1] += dp[a][b][c] * (double)c / (a + b + c); ev[a][b + 1][c - 1] += ev[a][b][c] * (double)c / (a + b + c); } } } } cout << fixed << setprecision(9) << ev[0][0][0]; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define endl '\n' using namespace std; const ll mod = (ll)1e9 + 7; const int INF = 0x3f3f3f3f; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } int n, x; vector<int> v(4); double dp[303][303][303]; double ev[303][303][303]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("C.txt", "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) { cin >> x; v[x]++; } dp[v[1]][v[2]][v[3]] = 1; for (int c = n; c >= 0; c--) { for (int b = n; b >= 0; b--) { for (int a = n; a >= 0; a--) { if (a + b + c > n || a + b + c == 0) continue; ev[a][b][c] += (double)n / (a + b + c) * dp[a][b][c]; if (a != 0) { dp[a - 1][b][c] += dp[a][b][c] * (double)a / (a + b + c); ev[a - 1][b][c] += ev[a][b][c] * (double)a / (a + b + c); } if (b != 0) { dp[a + 1][b - 1][c] += dp[a][b][c] * (double)b / (a + b + c); ev[a + 1][b - 1][c] += ev[a][b][c] * (double)b / (a + b + c); } if (c != 0) { dp[a][b + 1][c - 1] += dp[a][b][c] * (double)c / (a + b + c); ev[a][b + 1][c - 1] += ev[a][b][c] * (double)c / (a + b + c); } } } } cout << fixed << setprecision(9) << ev[0][0][0]; }
replace
19
20
19
20
-11
p03169
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define MOD (1000000007l) #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; double dp[310][310][310]; ll N; double rec(ll one, ll two, ll three) { if (dp[one][two][three] != -1) return dp[one][two][three]; double sum = 0; sum += one; sum += two; sum += three; double ans = N; ans /= sum; if (one > 0) ans += rec(one - 1, two, three) * one / sum; if (two > 0) ans += rec(one + 1, two - 1, three) * two / sum; if (three > 0) ans += rec(one, two + 1, three - 1) * three / sum; return ans; } void solve() { rep(i, 310) rep(j, 310) rep(k, 310) dp[i][j][k] = -1; dp[0][0][0] = 0; cin >> N; vector<ll> input(4); rep(i, N) { ll a; cin >> a; input[a]++; } cout << rec(input[1], input[2], input[3]) << endl; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout.precision(12); cout << fixed; solve(); return 0; }
#include <algorithm> #include <bitset> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define MOD (1000000007l) #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; double dp[310][310][310]; ll N; double rec(ll one, ll two, ll three) { if (dp[one][two][three] != -1) return dp[one][two][three]; double sum = 0; sum += one; sum += two; sum += three; double ans = N; ans /= sum; if (one > 0) ans += rec(one - 1, two, three) * one / sum; if (two > 0) ans += rec(one + 1, two - 1, three) * two / sum; if (three > 0) ans += rec(one, two + 1, three - 1) * three / sum; dp[one][two][three] = ans; return ans; } void solve() { rep(i, 310) rep(j, 310) rep(k, 310) dp[i][j][k] = -1; dp[0][0][0] = 0; cin >> N; vector<ll> input(4); rep(i, N) { ll a; cin >> a; input[a]++; } cout << rec(input[1], input[2], input[3]) << endl; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout.precision(12); cout << fixed; solve(); return 0; }
insert
37
37
37
38
TLE
p03169
Python
Runtime Error
import numpy as np from numba import njit @njit("(f8[:,:,:],i4,i4,i4,i4,)", cache=True) def solve(dp, N, n1, n2, n3): if dp[n1][n2][n3] >= 0.0: return dp[n1][n2][n3] if n1 == n2 == n3 == 0: return 0.0 cnt = n1 + n2 + n3 ret = 0 if n3 >= 1: ret += solve(dp, N, n1, n2 + 1, n3 - 1) * n3 if n2 >= 1: ret += solve(dp, N, n1 + 1, n2 - 1, n3) * n2 if n1 >= 1: ret += solve(dp, N, n1 - 1, n2, n3) * n1 ret = (ret + N) / cnt dp[n1][n2][n3] = ret return ret def main(): N = int(input()) A = list(map(int, input().split())) dp = np.full((N + 1, N + 1, N + 1), -1, dtype=np.float64) a1, a2, a3 = 0, 0, 0 for i in range(N): if A[i] == 1: a1 += 1 elif A[i] == 2: a2 += 1 elif A[i] == 3: a3 += 1 print(solve(dp, N, a1, a2, a3)) if __name__ == "__main__": main()
import numpy as np from numba import njit @njit("(f8[:,:,:],i4,i4,i4,i4,)") def solve(dp, N, n1, n2, n3): if dp[n1][n2][n3] >= 0.0: return dp[n1][n2][n3] if n1 == n2 == n3 == 0: return 0.0 cnt = n1 + n2 + n3 ret = 0 if n3 >= 1: ret += solve(dp, N, n1, n2 + 1, n3 - 1) * n3 if n2 >= 1: ret += solve(dp, N, n1 + 1, n2 - 1, n3) * n2 if n1 >= 1: ret += solve(dp, N, n1 - 1, n2, n3) * n1 ret = (ret + N) / cnt dp[n1][n2][n3] = ret return ret def main(): N = int(input()) A = list(map(int, input().split())) dp = np.full((N + 1, N + 1, N + 1), -1, dtype=np.float64) a1, a2, a3 = 0, 0, 0 for i in range(N): if A[i] == 1: a1 += 1 elif A[i] == 2: a2 += 1 elif A[i] == 3: a3 += 1 print(solve(dp, N, a1, a2, a3)) if __name__ == "__main__": main()
replace
4
5
4
5
TLE
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int, int, int> tpl; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define LB(a, x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a, x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i) #define RREP(i, n) RFOR(i, n, 0) #define en "\n" const double EPS = 1e-9; const double PI = acos(-1.0); const int INT_INF = 2147483647; const long long LL_INF = 1LL << 60; const long long MOD = 1000000007; // 998244353 #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N; VI a; double dp[300][300][300]; double rec(int a, int b, int c) { if (dp[a][b][c] != -1) return dp[a][b][c]; if (a == 0 && b == 0 && c == 0) return dp[a][b][c] = 0; double n = a + b + c; double res = (double)N / n; if (a > 0) res += rec(a - 1, b, c) * a / n; if (b > 0) res += rec(a + 1, b - 1, c) * b / n; if (c > 0) res += rec(a, b + 1, c - 1) * c / n; return dp[a][b][c] = res; } int main(void) { cin >> N; REP(i, N + 1) REP(j, N + 1) REP(k, N + 1) dp[i][j][k] = -1; a.assign(N, 0); int n[3]; REP(i, 3) n[i] = 0; REP(i, N) { cin >> a[i]; n[a[i] - 1]++; } double ans = rec(n[0], n[1], n[2]); cout << fixed << setprecision(12) << ans << en; return 0; }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int, int, int> tpl; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define LB(a, x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a, x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i) #define RREP(i, n) RFOR(i, n, 0) #define en "\n" const double EPS = 1e-9; const double PI = acos(-1.0); const int INT_INF = 2147483647; const long long LL_INF = 1LL << 60; const long long MOD = 1000000007; // 998244353 #define CLR(a) memset((a), 0, sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N; VI a; double dp[301][301][301]; double rec(int a, int b, int c) { if (dp[a][b][c] != -1) return dp[a][b][c]; if (a == 0 && b == 0 && c == 0) return dp[a][b][c] = 0; double n = a + b + c; double res = (double)N / n; if (a > 0) res += rec(a - 1, b, c) * a / n; if (b > 0) res += rec(a + 1, b - 1, c) * b / n; if (c > 0) res += rec(a, b + 1, c - 1) * c / n; return dp[a][b][c] = res; } int main(void) { cin >> N; REP(i, N + 1) REP(j, N + 1) REP(k, N + 1) dp[i][j][k] = -1; a.assign(N, 0); int n[3]; REP(i, 3) n[i] = 0; REP(i, N) { cin >> a[i]; n[a[i] - 1]++; } double ans = rec(n[0], n[1], n[2]); cout << fixed << setprecision(12) << ans << en; return 0; }
replace
66
67
66
67
-11
p03169
C++
Runtime Error
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; /* ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD, --b; } return ans; } */ const int MAXN = 310; int n; int a[MAXN]; int cc[4]; ld dp[301][301][301]; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif cout.precision(20); cout.setf(ios::fixed); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) ++cc[a[i]]; for (int k = 0; k <= cc[3]; ++k) for (int j = 0; j <= cc[2] + cc[3]; ++j) for (int i = 0; i <= cc[1] + cc[2] + cc[3]; ++i) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += i * dp[i - 1][j][k]; if (j) dp[i][j][k] += j * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += k * dp[i][j + 1][k - 1]; dp[i][j][k] /= n; dp[i][j][k] += 1; dp[i][j][k] /= ld(i + j + k) / n; } cout << dp[cc[1]][cc[2]][cc[3]] << "\n"; return 0; }
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; /* ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD, --b; } return ans; } */ const int MAXN = 310; int n; int a[MAXN]; int cc[4]; ld dp[305][305][305]; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif cout.precision(20); cout.setf(ios::fixed); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) ++cc[a[i]]; for (int k = 0; k <= cc[3]; ++k) for (int j = 0; j <= cc[2] + cc[3]; ++j) for (int i = 0; i <= cc[1] + cc[2] + cc[3]; ++i) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += i * dp[i - 1][j][k]; if (j) dp[i][j][k] += j * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += k * dp[i][j + 1][k - 1]; dp[i][j][k] /= n; dp[i][j][k] += 1; dp[i][j][k] /= ld(i + j + k) / n; } cout << dp[cc[1]][cc[2]][cc[3]] << "\n"; return 0; }
replace
34
35
34
35
-11
p03169
C++
Runtime Error
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #pragma clang diagnostic ignored "-Wdeprecated-declarations" #define _CRT_SECURE_NO_WARNINGS #endif #define gc getchar_unlocked() #define pc(x) putchar_unlocked(x) template <typename T> void scan(T &x) { x = 0; register bool _ = 0; register T c = gc; _ = c == 45; c = _ ? gc : c; while (c < 48 || c > 57) c = gc; for (; c < 48 || c > 57; c = gc) ; for (; c > 47 && c < 58; c = gc) x = (x << 3) + (x << 1) + (c & 15); x = _ ? -x : x; } template <typename T> void print(T n) { register bool _ = 0; _ = n < 0; n = _ ? -n : n; char snum[65]; int i = 0; do { snum[i++] = n % 10 + 48; n /= 10; } while (n); --i; if (_) pc(45); while (i >= 0) pc(snum[i--]); pc(10); } template <typename First, typename... Ints> void scan(First &arg, Ints &...rest) { scan(arg); scan(rest...); } using namespace std; const int MM = 302; int n; double dp[MM][MM][MM]; double go(int i, int j, int k) { if (dp[i][j][k] != -1) return dp[i][j][k]; double ret = 1; int sum = i + j + k; if (i) ret += (1.0 * i / n) * go(i - 1, j, k); if (j) ret += (1.0 * j / n) * go(i + 1, j - 1, k); if (k) ret += (1.0 * k / n) * go(i, j + 1, k - 1); return dp[i][j][k] = ret / (1 - (1.0 * n - sum) / n); } int main() { for (int i = 0; i < MM; i++) for (int j = 0; j < MM; j++) for (int k = 0; k < MM; k++) dp[i][j][k] = -1; dp[0][0][0] = 0; scan(n); int a[4]; for (int i = 0, s; i < n; i++) { scan(s); a[s]++; } printf("%.10lf\n", go(a[1], a[2], a[3])); return 0; }
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #pragma clang diagnostic ignored "-Wdeprecated-declarations" #define _CRT_SECURE_NO_WARNINGS #endif #define gc getchar_unlocked() #define pc(x) putchar_unlocked(x) template <typename T> void scan(T &x) { x = 0; register bool _ = 0; register T c = gc; _ = c == 45; c = _ ? gc : c; while (c < 48 || c > 57) c = gc; for (; c < 48 || c > 57; c = gc) ; for (; c > 47 && c < 58; c = gc) x = (x << 3) + (x << 1) + (c & 15); x = _ ? -x : x; } template <typename T> void print(T n) { register bool _ = 0; _ = n < 0; n = _ ? -n : n; char snum[65]; int i = 0; do { snum[i++] = n % 10 + 48; n /= 10; } while (n); --i; if (_) pc(45); while (i >= 0) pc(snum[i--]); pc(10); } template <typename First, typename... Ints> void scan(First &arg, Ints &...rest) { scan(arg); scan(rest...); } using namespace std; const int MM = 302; int n; double dp[MM][MM][MM]; double go(int i, int j, int k) { if (dp[i][j][k] != -1) return dp[i][j][k]; double ret = 1; int sum = i + j + k; if (i) ret += (1.0 * i / n) * go(i - 1, j, k); if (j) ret += (1.0 * j / n) * go(i + 1, j - 1, k); if (k) ret += (1.0 * k / n) * go(i, j + 1, k - 1); return dp[i][j][k] = ret / (1 - (1.0 * n - sum) / n); } int main() { for (int i = 0; i < MM; i++) for (int j = 0; j < MM; j++) for (int k = 0; k < MM; k++) dp[i][j][k] = -1; dp[0][0][0] = 0; scan(n); int a[4] = {0, 0, 0, 0}; for (int i = 0, s; i < n; i++) { scan(s); a[s]++; } printf("%.10lf\n", go(a[1], a[2], a[3])); return 0; }
replace
75
76
75
76
-11
p03169
C++
Runtime Error
// Nicky's template // C #include <inttypes.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> // C++ #include <algorithm> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define FORN(i, n) for (int i = 0; i < int(n); i++) #define NORF(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < int(b); i++) #define ROF(i, a, b) for (int i = int(b) - 1; i <= a; i--) #define FORX(it, x) for (auto it = x.begin(); it != x.end(); it++) #define FORS(i, s) for (int i = 0; s[i]; i++) #define MS0(x) memset((x), 0, sizeof((x))) #define MS1(x) memset((x), -1, sizeof((x))) #define PB push_back #define MP make_pair #define F first #define S second #define SZ(x) ((int)(x).size()) #define ALL(x) begin(x), end(x) typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%" SCNd64, &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class T, class... U> void R(T &head, U &...tail) { _R(head); R(tail...); } template <class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%" PRId64, x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } // print array void WA(const int *a, int n) { for (int i = 0; i < n; _W(a[i++])) if (i != 0) putchar(' '); puts(""); } template <class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template <class T, class... U> void W(const T &head, const U &...tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } template <class Iter> ostream &_out(ostream &s, Iter b, Iter e) { s << "["; for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it; return s << "]"; } template <class A, class B> ostream &operator<<(ostream &s, const pair<A, B> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &s, const vector<T> &c) { return _out(s, ALL(c)); } template <class T, size_t N> ostream &operator<<(ostream &s, const array<T, N> &c) { return _out(s, ALL(c)); } template <class T> ostream &operator<<(ostream &s, const set<T> &c) { return _out(s, ALL(c)); } template <class A, class B> ostream &operator<<(ostream &s, const map<A, B> &c) { return _out(s, ALL(c)); } template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); } template <class T> inline T bit(T x, int i) { return (x >> i) & 1; } template <class T> inline bool chmax(T &a, const T &b) { return b > a ? a = b, true : false; } template <class T> inline bool chmin(T &a, const T &b) { return b < a ? a = b, true : false; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> void _dump(const char *s, T &&head) { cerr << s << "=" << head << endl; } template <class T, class... Args> void _dump(const char *s, T &&head, Args &&...tail) { for (int c = 0; *s != ',' || c != 0; cerr << *s++) { if (*s == '(' || *s == '[' || *s == '{') c++; if (*s == ')' || *s == ']' || *s == '}') c--; } cerr << "=" << head << ","; _dump(s + 1, tail...); } #define dump(...) \ do { \ fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \ _dump(#__VA_ARGS__, __VA_ARGS__); \ } while (0) double dp[301][301][301]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; R(n); int a; int fs[] = {0, 0, 0}; FORN(i, n) { R(a); fs[a - 1]++; } double tmp; double z; dp[0][0][0] = 0; int maxI = fs[0] + fs[1] + fs[2]; int maxJ = fs[1] + fs[2]; int maxK = fs[2]; FORN(k, maxK + 1) FORN(j, maxJ + 1) FORN(i, maxI + 1) { if (i == 0 && j == 0 && k == 0) continue; tmp = 0; z = n - i - j - k; if (z >= n) continue; if (i >= 1) tmp += i * dp[i - 1][j][k]; if (j >= 1) tmp += j * dp[i + 1][j - 1][k]; if (k >= 1) tmp += k * dp[i][j + 1][k - 1]; // W(tmp); tmp /= n; tmp += 1; dp[i][j][k] = tmp / (1 - z / n); // W(dp[i][j][k]); } W(dp[fs[0]][fs[1]][fs[2]]); return 0; }
// Nicky's template // C #include <inttypes.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> // C++ #include <algorithm> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define FORN(i, n) for (int i = 0; i < int(n); i++) #define NORF(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < int(b); i++) #define ROF(i, a, b) for (int i = int(b) - 1; i <= a; i--) #define FORX(it, x) for (auto it = x.begin(); it != x.end(); it++) #define FORS(i, s) for (int i = 0; s[i]; i++) #define MS0(x) memset((x), 0, sizeof((x))) #define MS1(x) memset((x), -1, sizeof((x))) #define PB push_back #define MP make_pair #define F first #define S second #define SZ(x) ((int)(x).size()) #define ALL(x) begin(x), end(x) typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%" SCNd64, &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class T, class... U> void R(T &head, U &...tail) { _R(head); R(tail...); } template <class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const int64_t &x) { printf("%" PRId64, x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } // print array void WA(const int *a, int n) { for (int i = 0; i < n; _W(a[i++])) if (i != 0) putchar(' '); puts(""); } template <class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template <class T, class... U> void W(const T &head, const U &...tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } template <class Iter> ostream &_out(ostream &s, Iter b, Iter e) { s << "["; for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it; return s << "]"; } template <class A, class B> ostream &operator<<(ostream &s, const pair<A, B> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &s, const vector<T> &c) { return _out(s, ALL(c)); } template <class T, size_t N> ostream &operator<<(ostream &s, const array<T, N> &c) { return _out(s, ALL(c)); } template <class T> ostream &operator<<(ostream &s, const set<T> &c) { return _out(s, ALL(c)); } template <class A, class B> ostream &operator<<(ostream &s, const map<A, B> &c) { return _out(s, ALL(c)); } template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); } template <class T> inline T bit(T x, int i) { return (x >> i) & 1; } template <class T> inline bool chmax(T &a, const T &b) { return b > a ? a = b, true : false; } template <class T> inline bool chmin(T &a, const T &b) { return b < a ? a = b, true : false; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> void _dump(const char *s, T &&head) { cerr << s << "=" << head << endl; } template <class T, class... Args> void _dump(const char *s, T &&head, Args &&...tail) { for (int c = 0; *s != ',' || c != 0; cerr << *s++) { if (*s == '(' || *s == '[' || *s == '{') c++; if (*s == ')' || *s == ']' || *s == '}') c--; } cerr << "=" << head << ","; _dump(s + 1, tail...); } #define dump(...) \ do { \ fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \ _dump(#__VA_ARGS__, __VA_ARGS__); \ } while (0) double dp[305][305][305]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; R(n); int a; int fs[] = {0, 0, 0}; FORN(i, n) { R(a); fs[a - 1]++; } double tmp; double z; dp[0][0][0] = 0; int maxI = fs[0] + fs[1] + fs[2]; int maxJ = fs[1] + fs[2]; int maxK = fs[2]; FORN(k, maxK + 1) FORN(j, maxJ + 1) FORN(i, maxI + 1) { if (i == 0 && j == 0 && k == 0) continue; tmp = 0; z = n - i - j - k; if (z >= n) continue; if (i >= 1) tmp += i * dp[i - 1][j][k]; if (j >= 1) tmp += j * dp[i + 1][j - 1][k]; if (k >= 1) tmp += k * dp[i][j + 1][k - 1]; // W(tmp); tmp /= n; tmp += 1; dp[i][j][k] = tmp / (1 - z / n); // W(dp[i][j][k]); } W(dp[fs[0]][fs[1]][fs[2]]); return 0; }
replace
138
139
138
139
-11
p03169
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; double dp[301][301][301]; int main() { int n; cin >> n; int n1 = 0, n2 = 0, n3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) n1++; else if (x == 2) n2++; else n3++; } for (int k = 0; k <= n3; k++) for (int j = 0; j <= n3 + n2; j++) for (int i = 0; i <= n3 + n2 + n1; i++) { if (i == 0 && j == 0 && k == 0) { dp[i][j][k] = 0; continue; } dp[i][j][k] = 1.0 * (n) / (i + j + k); if (i) dp[i][j][k] += (1.0 * i / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += (1.0 * j / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += (1.0 * k / (i + j + k)) * dp[i][j + 1][k - 1]; } printf("%.10lf", dp[n1][n2][n3]); return 0; }
#include <cstdio> #include <iostream> using namespace std; double dp[305][305][305]; int main() { int n; cin >> n; int n1 = 0, n2 = 0, n3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) n1++; else if (x == 2) n2++; else n3++; } for (int k = 0; k <= n3; k++) for (int j = 0; j <= n3 + n2; j++) for (int i = 0; i <= n3 + n2 + n1; i++) { if (i == 0 && j == 0 && k == 0) { dp[i][j][k] = 0; continue; } dp[i][j][k] = 1.0 * (n) / (i + j + k); if (i) dp[i][j][k] += (1.0 * i / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += (1.0 * j / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += (1.0 * k / (i + j + k)) * dp[i][j + 1][k - 1]; } printf("%.10lf", dp[n1][n2][n3]); return 0; }
replace
3
4
3
4
-11
p03169
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, inp, cnt1 = 0, cnt2 = 0, cnt3 = 0; vector<vector<vector<double>>> dp( 305, vector<vector<double>>(305, vector<double>(305))); cin >> n; for (int i = 0; i < n; i++) { cin >> inp; if (inp == 1) cnt1++; else if (inp == 2) cnt2++; else cnt3++; } dp[0][0][0] = 0; for (int k = 0; k <= cnt3; k++) { for (int j = 0; j <= cnt2 + cnt3; j++) { for (int i = 0; i <= cnt1 + cnt2 + cnt3; i++) { if (i == 0 && j == 0 && k == 0) continue; int s = i + j + k; if (k) dp[i][j][k] += 1.0 * k / s * dp[i][j + 1][k - 1]; if (j) dp[i][j][k] += 1.0 * j / s * dp[i + 1][j - 1][k]; if (i) dp[i][j][k] += 1.0 * i / s * dp[i - 1][j][k]; dp[i][j][k] += 1.0 * n / s; } } } printf("%.9f", dp[cnt1][cnt2][cnt3]); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, inp, cnt1 = 0, cnt2 = 0, cnt3 = 0; double dp[305][305][305]; // vector<vector<vector<double>>> dp (305, vector<vector<double>> (305 , // vector<double> (305))); cin >> n; for (int i = 0; i < n; i++) { cin >> inp; if (inp == 1) cnt1++; else if (inp == 2) cnt2++; else cnt3++; } dp[0][0][0] = 0; for (int k = 0; k <= cnt3; k++) { for (int j = 0; j <= cnt2 + cnt3; j++) { for (int i = 0; i <= cnt1 + cnt2 + cnt3; i++) { if (i == 0 && j == 0 && k == 0) continue; int s = i + j + k; if (k) dp[i][j][k] += 1.0 * k / s * dp[i][j + 1][k - 1]; if (j) dp[i][j][k] += 1.0 * j / s * dp[i + 1][j - 1][k]; if (i) dp[i][j][k] += 1.0 * i / s * dp[i - 1][j][k]; dp[i][j][k] += 1.0 * n / s; } } } printf("%.9f", dp[cnt1][cnt2][cnt3]); }
replace
7
9
7
10
TLE
p03169
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<pi>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using Graph = vector<VecP>; #define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i)) #define REPR(i, m, n) for (ll(i) = (m); (i) > (n); --(i)) #define rep(i, n) REP(i, 0, n) #define R cin >> #define repr(i, n) REPR(i, n, 0) #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second #define in(a) insert(a) #define P(p) cout << (p) << endl; #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define SORT(a) sort((a).begin(), (a).end()) typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<long long int> vll; typedef vector<string> vs; void sonic() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } const ll INF = 1e9 + 1; const ll LINF = 1e18 + 1; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ld PI = acos(-1); const ld EPS = 1e-11; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> void co(T e) { cout << e << "\n"; } template <typename T> void co(const vector<T> &v) { for (const auto &e : v) { cout << e << " "; } cout << "\n"; } ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } Vec fac, finv; ll PowMod(ll a, ll n) { if (n == 1) return a; if (n % 2 == 0) return PowMod(a * a % MOD, n / 2); return a * PowMod(a * a % MOD, n / 2) % MOD; } ll combi(ll n, ll k) { if (k > n) return 0; return fac[n] * finv[k] % MOD * finv[n - k] % MOD; } double memo[300][300][300]; double f(int i, int j, int k, int n) { if (i + j + k == 0) return 0.0; if (memo[i][j][k] != 0.0) return memo[i][j][k]; double s = i + j + k; double ret = n - s; if (i) ret += (f(i - 1, j, k, n) + 1) * i; if (j) ret += (f(i + 1, j - 1, k, n) + 1) * j; if (k) ret += (f(i, j + 1, k - 1, n) + 1) * k; ret /= s; memo[i][j][k] = ret; return ret; } int main() { double n, r, a = 0, b = 0, c = 0; cin >> n; rep(i, n) { cin >> r; if (r == 1) a++; else if (r == 2) b++; else c++; } cout << fixed << setprecision(15) << f(a, b, c, n) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pi = pair<int, int>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<pi>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using Graph = vector<VecP>; #define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i)) #define REPR(i, m, n) for (ll(i) = (m); (i) > (n); --(i)) #define rep(i, n) REP(i, 0, n) #define R cin >> #define repr(i, n) REPR(i, n, 0) #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second #define in(a) insert(a) #define P(p) cout << (p) << endl; #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define SORT(a) sort((a).begin(), (a).end()) typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<long long int> vll; typedef vector<string> vs; void sonic() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } const ll INF = 1e9 + 1; const ll LINF = 1e18 + 1; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ld PI = acos(-1); const ld EPS = 1e-11; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> void co(T e) { cout << e << "\n"; } template <typename T> void co(const vector<T> &v) { for (const auto &e : v) { cout << e << " "; } cout << "\n"; } ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } Vec fac, finv; ll PowMod(ll a, ll n) { if (n == 1) return a; if (n % 2 == 0) return PowMod(a * a % MOD, n / 2); return a * PowMod(a * a % MOD, n / 2) % MOD; } ll combi(ll n, ll k) { if (k > n) return 0; return fac[n] * finv[k] % MOD * finv[n - k] % MOD; } double memo[310][310][310]; double f(int i, int j, int k, int n) { if (i + j + k == 0) return 0.0; if (memo[i][j][k] != 0.0) return memo[i][j][k]; double s = i + j + k; double ret = n - s; if (i) ret += (f(i - 1, j, k, n) + 1) * i; if (j) ret += (f(i + 1, j - 1, k, n) + 1) * j; if (k) ret += (f(i, j + 1, k - 1, n) + 1) * k; ret /= s; memo[i][j][k] = ret; return ret; } int main() { double n, r, a = 0, b = 0, c = 0; cin >> n; rep(i, n) { cin >> r; if (r == 1) a++; else if (r == 2) b++; else c++; } cout << fixed << setprecision(15) << f(a, b, c, n) << endl; }
replace
105
106
105
106
-11