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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define p_ary(ary, a, b, i) \
do { \
cout << "["; \
for (int(i) = (a); (i) < (b); ++(i)) \
cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
double dp[300][300][300];
double rec(int n, int a, int b, int c) {
if (dp[a][b][c] > -0.5)
return dp[a][b][c];
dp[a][b][c] = n;
if (a)
dp[a][b][c] += rec(n, a - 1, b, c) * a;
if (b)
dp[a][b][c] += rec(n, a + 1, b - 1, c) * b;
if (c)
dp[a][b][c] += rec(n, a, b + 1, c - 1) * c;
dp[a][b][c] /= a + b + c;
return dp[a][b][c];
}
int main() {
int n, a[3] = {0, 0, 0};
cin >> n;
for (int i = 0; i < n + 1; ++i)
for (int j = 0; j < n + 1; ++j)
for (int k = 0; k < n + 1; ++k)
dp[i][j][k] = -1;
dp[0][0][0] = 0;
for (int i = 0; i < n; ++i) {
int b;
cin >> b;
a[b - 1]++;
}
cout << fixed << setprecision(12) << rec(n, a[0], a[1], a[2]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define p_ary(ary, a, b, i) \
do { \
cout << "["; \
for (int(i) = (a); (i) < (b); ++(i)) \
cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \
cout << "]\n"; \
} while (0)
#define p_map(map, it) \
do { \
cout << "{"; \
for (auto(it) = map.begin();; ++(it)) { \
if ((it) == map.end()) { \
cout << "}\n"; \
break; \
} else \
cout << "" << (it)->first << "=>" << (it)->second << ", "; \
} \
} while (0)
double dp[310][310][310];
double rec(int n, int a, int b, int c) {
if (dp[a][b][c] > -0.5)
return dp[a][b][c];
dp[a][b][c] = n;
if (a)
dp[a][b][c] += rec(n, a - 1, b, c) * a;
if (b)
dp[a][b][c] += rec(n, a + 1, b - 1, c) * b;
if (c)
dp[a][b][c] += rec(n, a, b + 1, c - 1) * c;
dp[a][b][c] /= a + b + c;
return dp[a][b][c];
}
int main() {
int n, a[3] = {0, 0, 0};
cin >> n;
for (int i = 0; i < n + 1; ++i)
for (int j = 0; j < n + 1; ++j)
for (int k = 0; k < n + 1; ++k)
dp[i][j][k] = -1;
dp[0][0][0] = 0;
for (int i = 0; i < n; ++i) {
int b;
cin >> b;
a[b - 1]++;
}
cout << fixed << setprecision(12) << rec(n, a[0], a[1], a[2]) << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
double dp[301][301][301];
int a[4];
int main() {
int n, ai;
cin >> n;
rep(i, n) {
cin >> ai;
++a[ai - 1];
}
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) {
int c = i + j + k;
if (c == 0)
continue;
if (k != 0)
dp[k][j][i] += dp[k - 1][j][i] * k;
if (j != 0)
dp[k][j][i] += dp[k + 1][j - 1][i] * j;
if (i != 0)
dp[k][j][i] += dp[k][j + 1][i - 1] * i;
dp[k][j][i] += n;
dp[k][j][i] /= c;
}
cout << setprecision(10) << fixed << dp[a[0]][a[1]][a[2]] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
double dp[304][304][304];
int a[4];
int main() {
int n, ai;
cin >> n;
rep(i, n) {
cin >> ai;
++a[ai - 1];
}
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) {
int c = i + j + k;
if (c == 0)
continue;
if (k != 0)
dp[k][j][i] += dp[k - 1][j][i] * k;
if (j != 0)
dp[k][j][i] += dp[k + 1][j - 1][i] * j;
if (i != 0)
dp[k][j][i] += dp[k][j + 1][i - 1] * i;
dp[k][j][i] += n;
dp[k][j][i] /= c;
}
cout << setprecision(10) << fixed << dp[a[0]][a[1]][a[2]] << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;
struct Node {
int x, y, w;
};
double dp[301][301][301];
int za[301];
int zt[4];
void solve() {
double result = 0;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> za[i];
zt[za[i]]++;
}
dp[0][0][0] = 0;
for (int k = 0; k <= zt[3]; ++k) {
for (int j = 0; j <= zt[2] + zt[3]; ++j) {
for (int i = 0; i <= n; ++i) {
int cc = i + j + k;
if (cc == 0)
continue;
double tt = 0;
if (i > 0) {
tt += double(i) / n * dp[i - 1][j][k];
}
if (j > 0) {
tt += double(j) / n * dp[i + 1][j - 1][k];
}
if (k > 0) {
tt += double(k) / n * dp[i][j + 1][k - 1];
}
dp[i][j][k] = (1 + tt) * n / cc;
}
}
}
result = dp[zt[1]][zt[2]][zt[3]];
cout << setprecision(12) << result << endl;
}
int main() {
const int inId = 0;
const int outId = 0;
if (inId > 0) {
cerr << "redirect stdin to input " << inId << endl;
string s = "input";
s += to_string(inId);
s += ".txt";
auto r = freopen(s.c_str(), "r", stdin);
if (r == nullptr) {
cerr << "invalid input file " << s;
}
}
if (outId > 0) {
cerr << "redirect stdout to stdout " << outId << endl;
string s = "stdout";
s += to_string(outId);
s += ".txt";
auto r = freopen(s.c_str(), "w", stdout);
if (r == nullptr) {
cerr << "invalid output file " << s;
}
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0); // close sync between cout and printf
cout.precision(10);
solve();
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;
struct Node {
int x, y, w;
};
double dp[301][301][301];
int za[301];
int zt[4];
void solve() {
double result = 0;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> za[i];
zt[za[i]]++;
}
dp[0][0][0] = 0;
for (int k = 0; k <= zt[3]; ++k) {
for (int j = 0; j <= zt[2] + zt[3]; ++j) {
for (int i = 0; i <= n; ++i) {
int cc = i + j + k;
if (cc == 0)
continue;
if (cc > n)
continue;
double tt = 0;
if (i > 0) {
tt += double(i) / n * dp[i - 1][j][k];
}
if (j > 0) {
tt += double(j) / n * dp[i + 1][j - 1][k];
}
if (k > 0) {
tt += double(k) / n * dp[i][j + 1][k - 1];
}
dp[i][j][k] = (1 + tt) * n / cc;
}
}
}
result = dp[zt[1]][zt[2]][zt[3]];
cout << setprecision(12) << result << endl;
}
int main() {
const int inId = 0;
const int outId = 0;
if (inId > 0) {
cerr << "redirect stdin to input " << inId << endl;
string s = "input";
s += to_string(inId);
s += ".txt";
auto r = freopen(s.c_str(), "r", stdin);
if (r == nullptr) {
cerr << "invalid input file " << s;
}
}
if (outId > 0) {
cerr << "redirect stdout to stdout " << outId << endl;
string s = "stdout";
s += to_string(outId);
s += ".txt";
auto r = freopen(s.c_str(), "w", stdout);
if (r == nullptr) {
cerr << "invalid output file " << s;
}
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0); // close sync between cout and printf
cout.precision(10);
solve();
}
| insert | 43 | 43 | 43 | 45 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
int n;
ld dp[31][31][31];
ld func(int a, int b, int c) {
int i, j, l;
if (a == 0 && b == 0 && c == 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
ld x, y, z;
j = a + b + c;
x = (ld)n / (ld)j;
y = 0.0;
if (j == 0)
return 0;
if (a > 0)
y = y + a * func(a - 1, b, c);
if (b > 0)
y = y + b * func(a + 1, b - 1, c);
if (c > 0)
y = y + c * func(a, b + 1, c - 1);
y = (ld)y / (ld)j;
x = x + y;
return dp[a][b][c] = x;
}
int main() {
cin >> n;
int i, j, l;
int a = 0, b = 0, c = 0;
// memset(dp,-1.0,sizeof(dp));
for (i = 0; i <= n; i++)
for (j = 0; j <= n; j++)
for (l = 0; l <= n; l++)
dp[i][j][l] = -1;
for (i = 0; i < n; i++) {
cin >> j;
if (j == 1)
a++;
else if (j == 2)
b++;
else
c++;
}
ld ans = func(a, b, c);
cout << fixed << setprecision(20) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
int n;
ld dp[301][301][301];
ld func(int a, int b, int c) {
int i, j, l;
if (a == 0 && b == 0 && c == 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
ld x, y, z;
j = a + b + c;
x = (ld)n / (ld)j;
y = 0.0;
if (j == 0)
return 0;
if (a > 0)
y = y + a * func(a - 1, b, c);
if (b > 0)
y = y + b * func(a + 1, b - 1, c);
if (c > 0)
y = y + c * func(a, b + 1, c - 1);
y = (ld)y / (ld)j;
x = x + y;
return dp[a][b][c] = x;
}
int main() {
cin >> n;
int i, j, l;
int a = 0, b = 0, c = 0;
// memset(dp,-1.0,sizeof(dp));
for (i = 0; i <= n; i++)
for (j = 0; j <= n; j++)
for (l = 0; l <= n; l++)
dp[i][j][l] = -1;
for (i = 0; i < n; i++) {
cin >> j;
if (j == 1)
a++;
else if (j == 2)
b++;
else
c++;
}
ld ans = func(a, b, c);
cout << fixed << setprecision(20) << ans << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld v[301][301][301] = {0.0};
int main() {
int n;
cin >> n;
v[0][0][0] = 0;
for (int z = 0; z <= n; z++) {
for (int y = 0; y <= n; y++) {
for (int x = 0; x <= n; x++) {
if ((x + y + z) != 0) {
v[x][y][z] = (ld)n / (x + y + z);
}
if (x != 0) {
v[x][y][z] += x * v[x - 1][y][z] / (x + y + z);
}
if (y != 0) {
v[x][y][z] += y * v[x + 1][y - 1][z] / (x + y + z);
}
if (z != 0) {
v[x][y][z] += z * v[x][y + 1][z - 1] / (x + y + z);
}
}
}
}
int a[4] = {0};
int x;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
cout << fixed << setprecision(10) << v[a[1]][a[2]][a[3]] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld v[303][303][303] = {0.0};
int main() {
int n;
cin >> n;
v[0][0][0] = 0;
for (int z = 0; z <= n; z++) {
for (int y = 0; y <= n; y++) {
for (int x = 0; x <= n; x++) {
if ((x + y + z) != 0) {
v[x][y][z] = (ld)n / (x + y + z);
}
if (x != 0) {
v[x][y][z] += x * v[x - 1][y][z] / (x + y + z);
}
if (y != 0) {
v[x][y][z] += y * v[x + 1][y - 1][z] / (x + y + z);
}
if (z != 0) {
v[x][y][z] += z * v[x][y + 1][z - 1] / (x + y + z);
}
}
}
}
int a[4] = {0};
int x;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
cout << fixed << setprecision(10) << v[a[1]][a[2]][a[3]] << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ff first
#define endl "\n"
#define ss second
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom pair<int, pair<int, int>>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define mod 1000000007
double dp[301][301][301];
double solve(int x, int y, int z, int n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (x == 0 && y == 0 && z == 0)
return 0;
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp / (x + y + z);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int one = 0;
int two = 0;
int three = 0;
int ex;
for (int i = 0; i < n; i++) {
cin >> ex;
if (ex == 1) {
one++;
} else if (ex == 2) {
two++;
} else {
three++;
}
}
memset(dp, -1, sizeof dp);
cout << fixed << setprecision(9) << solve(one, two, three, n);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ff first
#define endl "\n"
#define ss second
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom pair<int, pair<int, int>>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define mod 1000000007
double dp[301][301][301];
double solve(int x, int y, int z, int n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (x == 0 && y == 0 && z == 0)
return 0;
if (dp[x][y][z] > -0.5) {
return dp[x][y][z];
}
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp / (x + y + z);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int one = 0;
int two = 0;
int three = 0;
int ex;
for (int i = 0; i < n; i++) {
cin >> ex;
if (ex == 1) {
one++;
} else if (ex == 2) {
two++;
} else {
three++;
}
}
memset(dp, -1, sizeof dp);
cout << fixed << setprecision(9) << solve(one, two, three, n);
return 0;
} | insert | 29 | 29 | 29 | 32 | TLE | |
p03169 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (x == 0 && y == 0 && z == 0) {
return 0;
}
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp / (x + y + z);
}
int32_t main() {
int n, x;
cin >> n;
memset(dp, -1, sizeof dp);
int one = 0, two = 0, three = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x == 1) {
one++;
} else if (x == 2) {
two++;
} else
three++;
}
cout << fixed << setprecision(9) << solve(one, two, three, n);
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (x == 0 && y == 0 && z == 0) {
return 0;
}
if (dp[x][y][z] > -0.9) {
return dp[x][y][z];
}
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp / (x + y + z);
}
int32_t main() {
int n, x;
cin >> n;
memset(dp, -1, sizeof dp);
int one = 0, two = 0, three = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x == 1) {
one++;
} else if (x == 2) {
two++;
} else
three++;
}
cout << fixed << setprecision(9) << solve(one, two, three, n);
}
| insert | 14 | 14 | 14 | 17 | TLE | |
p03169 | C++ | Runtime Error | #ifndef BZ
#pragma GCC optimize "-Ofast"
#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 double ld;
typedef unsigned long long ull;
using namespace std;
const int MX = 307;
ld f[MX + 5][MX + 5][MX + 5];
int main() {
#ifdef FASTIO
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
int n;
int c[4] = {0};
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
c[x]++;
}
for (int k = 0; k < MX; k++) {
for (int j = 0; j + k < MX; j++) {
for (int i = 0; i + j + k < MX; i++) {
if (i == 0 && j == 0 && k == 0) {
continue;
}
if (i + j + k > MX) {
continue;
}
ld wait = 1.0 * n / (i + j + k);
ld pi = 1.0 * i / (i + j + k);
ld pj = 1.0 * j / (i + j + k);
ld pk = 1.0 * k / (i + j + k);
f[i][j][k] = wait + pk * f[i][j + 1][k - 1] + pj * f[i + 1][j - 1][k] +
pi * f[i - 1][j][k];
}
}
}
cout.precision(10);
cout << fixed << f[c[1]][c[2]][c[3]] << "\n";
return 0;
}
| #ifndef BZ
#pragma GCC optimize "-Ofast"
#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 double ld;
typedef unsigned long long ull;
using namespace std;
const int MX = 307;
ld f[MX + 5][MX + 5][MX + 5];
int main() {
#ifdef FASTIO
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
int n;
int c[4] = {0};
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
c[x]++;
}
for (int k = 0; k < MX; k++) {
for (int j = 0; j + k < MX; j++) {
for (int i = 0; i + j + k < MX; i++) {
if (i == 0 && j == 0 && k == 0) {
continue;
}
if (i + j + k > MX) {
continue;
}
ld wait = 1.0 * n / (i + j + k);
ld pi = 1.0 * i / (i + j + k);
ld pj = 1.0 * j / (i + j + k);
ld pk = 1.0 * k / (i + j + k);
if (i)
f[i][j][k] += pi * f[i - 1][j][k];
if (j)
f[i][j][k] += pj * f[i + 1][j - 1][k];
if (k)
f[i][j][k] += pk * f[i][j + 1][k - 1];
f[i][j][k] += wait;
}
}
}
cout.precision(10);
cout << fixed << f[c[1]][c[2]][c[3]] << "\n";
return 0;
}
| replace | 51 | 53 | 51 | 59 | -11 | |
p03169 | C++ | Runtime Error |
/*****/
#define TRUE true
/**/
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
/**/
#include <bits/stdc++.h>
// #define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<long long, long long>;
template <class T> using vec = vector<T>;
template <class T> using grapth = vec<vec<T>>;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define step(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
constexpr int INF = numeric_limits<int>::max();
constexpr ll INFL = numeric_limits<ll>::max();
std::string strMulti(const char c, const int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += c;
}
return out;
}
std::string strMulti(const std::string t, const int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
std::string tab(const int n) { return strMulti('\t', n); }
std::string join(const vector<string> &v, const char *delim = 0) {
std::string s;
if (!v.empty()) {
s += v[0];
for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
if (delim)
s += delim;
s += v[i];
}
}
return s;
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { return string({'\'', c, '\''}); }
template <size_t N> string to_string(bitset<N> bs) { return bs.to_string(); }
template <class T1, class T2> string to_string(pair<T1, T2> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class Tuple, size_t... I>
string _to_string_tuple(Tuple &&t, std::index_sequence<I...>) {
vector<string> texts = {to_string(std::get<I>(t))...};
return "(" + join(texts, ", ") + ")";
}
template <class... Args> string to_string(tuple<Args...> t) {
using Tuple = tuple<Args...>;
return _to_string_tuple(
std::forward<Tuple>(t),
std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
}
template <class T> string to_string(vector<T> ar) {
vector<string> texts(ar.size());
for (size_t i = 0; i < ar.size(); ++i) {
texts[i] = to_string(ar[i]);
}
return "{" + join(texts, ", ") + "}";
}
template <class T> string to_string(initializer_list<T> il) {
vector<string> texts(il.size());
size_t i = 0;
for (T v : il) {
texts[i] = to_string(v);
i++;
}
return "{" + join(texts, ", ") + "}";
}
#ifdef DEBUG_BUILD
#define debugvar(x) debugln(#x, (x))
#define debugvartab(x, t) debugln(tab(t) + #x, (x))
void debug(string name) { std::cerr << name; }
void debugln(string name) { std::cerr << name << '\n'; }
template <class T> void debug(string name, T v) {
std::cerr << name << " = " << to_string(v);
}
template <class T> void debugln(string name, T v) {
std::cerr << name << " = " << to_string(v) << '\n';
}
template <class T> void debug(string name, initializer_list<T> il) {
std::cerr << name << " = " << to_string(il);
}
template <class T> void debugln(string name, initializer_list<T> il) {
std::cerr << name << " = " << to_string(il) << '\n';
}
template <class... Args> void debug(string name, Args... args) {
std::cerr << name << " = " << to_string(tuple<Args...>(args...));
}
template <class... Args> void debugln(string name, Args... args) {
std::cerr << name << " = " << to_string(tuple<Args...>(args...)) << '\n';
}
#else
#define debugvar(x)
#define debugvartab(x, t)
void debug(string name) {}
void debugln(string name) {}
template <class T> void debug(string name, T v) {}
template <class T> void debugln(string name, T v) {}
template <class T> void debug(string name, initializer_list<T> il) {}
template <class T> void debugln(string name, initializer_list<T> il) {}
template <class... Args> void debug(string name, Args... args) {}
template <class... Args> void debugln(string name, Args... args) {}
#endif
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
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 <class T> T divup(const T a, const T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
ll modpow(ll x, ll n, const ll &p) {
ll ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
template <class T> T modinv(T a, const T &p) {
T b = p, u = 1, v = 0;
while (b) {
T t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= p;
if (u < 0) {
u += p;
}
return u;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
ll extended_euclidean(ll u, ll v) {
ll r0 = u;
ll r1 = v;
ll s0 = 1;
ll s1 = 0;
ll t0 = 0;
ll t1 = 1;
while (r1 != 0) {
ll q = r0 / r1;
ll r = r0 - q * r1;
ll s = s0 - q * s1;
ll t = t0 - q * t1;
r0 = r1;
s0 = s1;
t0 = t1;
r1 = r;
s1 = s;
t1 = t;
}
if (t0 < 0) {
return t0 + u;
} else {
return t0;
}
}
ll math_C_mod(ll n, ll c, const ll &p) {
ll upe = 1;
ll dow = 1;
for (ll i = 1; i < c + 1; ++i) {
upe = upe * n % p;
dow = dow * i % p;
n -= 1;
}
return (upe * extended_euclidean(p, dow)) % p;
}
template <class T> T math_gcd(T a, T b) {
if (b == 0) {
return a;
} else {
return math_gcd(b, a % b);
}
}
template <class T> T math_lcm(T a, T b) { return a / math_gcd(a, b) * b; }
template <class T> T SumStep(T a, T n, T d) {
return n * (2 * a + (n - 1) * d) / 2;
}
template <class T> T SumRange(T a, T b, T d) {
return SumStep(a, (b - a) / d, d);
}
constexpr ll MOD = 1000000007; // 10^9+7
// constexpr ll MOD = 998244353;
/*****/
vec<vec<vec<ld>>> dp;
int N;
ld rec(int i, int j, int k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0.0;
ld res = 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 *= 1.0 / (i + j + k);
return dp[i][j][k] = res;
}
void Main() {
cin >> N;
vec<int> ac(4);
rep(i, N) {
int a;
cin >> a;
ac[a]++;
}
dp.resize(ac[1] + 100, vec<vec<ld>>(ac[2] + 100, vec<ld>(ac[3] + 100, -1)));
cout << rec(ac[1], ac[2], ac[3]) << endl;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed << std::setprecision(10);
#ifdef TRUE
Main();
#endif
std::cerr << flush;
std::cout << flush;
return 0;
}
|
/*****/
#define TRUE true
/**/
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
/**/
#include <bits/stdc++.h>
// #define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<long long, long long>;
template <class T> using vec = vector<T>;
template <class T> using grapth = vec<vec<T>>;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define step(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
constexpr int INF = numeric_limits<int>::max();
constexpr ll INFL = numeric_limits<ll>::max();
std::string strMulti(const char c, const int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += c;
}
return out;
}
std::string strMulti(const std::string t, const int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
std::string tab(const int n) { return strMulti('\t', n); }
std::string join(const vector<string> &v, const char *delim = 0) {
std::string s;
if (!v.empty()) {
s += v[0];
for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
if (delim)
s += delim;
s += v[i];
}
}
return s;
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { return string({'\'', c, '\''}); }
template <size_t N> string to_string(bitset<N> bs) { return bs.to_string(); }
template <class T1, class T2> string to_string(pair<T1, T2> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class Tuple, size_t... I>
string _to_string_tuple(Tuple &&t, std::index_sequence<I...>) {
vector<string> texts = {to_string(std::get<I>(t))...};
return "(" + join(texts, ", ") + ")";
}
template <class... Args> string to_string(tuple<Args...> t) {
using Tuple = tuple<Args...>;
return _to_string_tuple(
std::forward<Tuple>(t),
std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
}
template <class T> string to_string(vector<T> ar) {
vector<string> texts(ar.size());
for (size_t i = 0; i < ar.size(); ++i) {
texts[i] = to_string(ar[i]);
}
return "{" + join(texts, ", ") + "}";
}
template <class T> string to_string(initializer_list<T> il) {
vector<string> texts(il.size());
size_t i = 0;
for (T v : il) {
texts[i] = to_string(v);
i++;
}
return "{" + join(texts, ", ") + "}";
}
#ifdef DEBUG_BUILD
#define debugvar(x) debugln(#x, (x))
#define debugvartab(x, t) debugln(tab(t) + #x, (x))
void debug(string name) { std::cerr << name; }
void debugln(string name) { std::cerr << name << '\n'; }
template <class T> void debug(string name, T v) {
std::cerr << name << " = " << to_string(v);
}
template <class T> void debugln(string name, T v) {
std::cerr << name << " = " << to_string(v) << '\n';
}
template <class T> void debug(string name, initializer_list<T> il) {
std::cerr << name << " = " << to_string(il);
}
template <class T> void debugln(string name, initializer_list<T> il) {
std::cerr << name << " = " << to_string(il) << '\n';
}
template <class... Args> void debug(string name, Args... args) {
std::cerr << name << " = " << to_string(tuple<Args...>(args...));
}
template <class... Args> void debugln(string name, Args... args) {
std::cerr << name << " = " << to_string(tuple<Args...>(args...)) << '\n';
}
#else
#define debugvar(x)
#define debugvartab(x, t)
void debug(string name) {}
void debugln(string name) {}
template <class T> void debug(string name, T v) {}
template <class T> void debugln(string name, T v) {}
template <class T> void debug(string name, initializer_list<T> il) {}
template <class T> void debugln(string name, initializer_list<T> il) {}
template <class... Args> void debug(string name, Args... args) {}
template <class... Args> void debugln(string name, Args... args) {}
#endif
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
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 <class T> T divup(const T a, const T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
ll modpow(ll x, ll n, const ll &p) {
ll ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
template <class T> T modinv(T a, const T &p) {
T b = p, u = 1, v = 0;
while (b) {
T t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= p;
if (u < 0) {
u += p;
}
return u;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
ll extended_euclidean(ll u, ll v) {
ll r0 = u;
ll r1 = v;
ll s0 = 1;
ll s1 = 0;
ll t0 = 0;
ll t1 = 1;
while (r1 != 0) {
ll q = r0 / r1;
ll r = r0 - q * r1;
ll s = s0 - q * s1;
ll t = t0 - q * t1;
r0 = r1;
s0 = s1;
t0 = t1;
r1 = r;
s1 = s;
t1 = t;
}
if (t0 < 0) {
return t0 + u;
} else {
return t0;
}
}
ll math_C_mod(ll n, ll c, const ll &p) {
ll upe = 1;
ll dow = 1;
for (ll i = 1; i < c + 1; ++i) {
upe = upe * n % p;
dow = dow * i % p;
n -= 1;
}
return (upe * extended_euclidean(p, dow)) % p;
}
template <class T> T math_gcd(T a, T b) {
if (b == 0) {
return a;
} else {
return math_gcd(b, a % b);
}
}
template <class T> T math_lcm(T a, T b) { return a / math_gcd(a, b) * b; }
template <class T> T SumStep(T a, T n, T d) {
return n * (2 * a + (n - 1) * d) / 2;
}
template <class T> T SumRange(T a, T b, T d) {
return SumStep(a, (b - a) / d, d);
}
constexpr ll MOD = 1000000007; // 10^9+7
// constexpr ll MOD = 998244353;
/*****/
vec<vec<vec<ld>>> dp;
int N;
ld rec(int i, int j, int k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0.0;
ld res = 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 *= 1.0 / (i + j + k);
return dp[i][j][k] = res;
}
void Main() {
cin >> N;
vec<int> ac(4);
rep(i, N) {
int a;
cin >> a;
ac[a]++;
}
dp.resize(301, vec<vec<ld>>(301, vec<ld>(301, -1)));
cout << rec(ac[1], ac[2], ac[3]) << endl;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed << std::setprecision(10);
#ifdef TRUE
Main();
#endif
std::cerr << flush;
std::cout << flush;
return 0;
}
| replace | 292 | 293 | 292 | 293 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
ll N;
std::vector<ll> a;
vector<vector<vector<double>>> dp;
double f(ll c1, ll c2, ll c3) {
if (dp[c1][c2][c3] != -1.0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return 0.0;
double ret = 0.0;
if (c1 > 0)
ret += f(c1 - 1, c2, c3) * c1;
if (c2 > 0)
ret += f(c1 + 1, c2 - 1, c3) * c2;
if (c3 > 0)
ret += f(c1, c2 + 1, c3 - 1) * c3;
ret += N;
ret *= 1.0 / (c1 + c2 + c3);
return dp[c1][c2][c3] = ret;
}
void solve() {
dp.resize(3 * N, vector<vector<double>>(3 * N, vector<double>(3 * N, -1.0)));
ll c1 = 0, c2 = 0, c3 = 0;
rep(i, N) {
if (a.at(i) == 1)
c1++;
if (a.at(i) == 2)
c2++;
if (a.at(i) == 3)
c3++;
}
cout << f(c1, c2, c3) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
scanf("%lld", &N);
a.resize(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &a[i]);
}
solve();
return 0;
}
| #include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
ll N;
std::vector<ll> a;
vector<vector<vector<double>>> dp;
double f(ll c1, ll c2, ll c3) {
if (dp[c1][c2][c3] != -1.0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return 0.0;
double ret = 0.0;
if (c1 > 0)
ret += f(c1 - 1, c2, c3) * c1;
if (c2 > 0)
ret += f(c1 + 1, c2 - 1, c3) * c2;
if (c3 > 0)
ret += f(c1, c2 + 1, c3 - 1) * c3;
ret += N;
ret *= 1.0 / (c1 + c2 + c3);
return dp[c1][c2][c3] = ret;
}
void solve() {
dp.resize(310, vector<vector<double>>(310, vector<double>(310, -1.0)));
ll c1 = 0, c2 = 0, c3 = 0;
rep(i, N) {
if (a.at(i) == 1)
c1++;
if (a.at(i) == 2)
c2++;
if (a.at(i) == 3)
c3++;
}
cout << f(c1, c2, c3) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
scanf("%lld", &N);
a.resize(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &a[i]);
}
solve();
return 0;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p03169 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n;
double dp[310][310][310];
double dfs(int x3, int x2, int x1) {
if (x3 == 0 && x2 == 0 && x1 == 0)
return 0.0;
else {
double sum = (double)(x3 + x2 + x1);
double ret = (double)n / sum;
if (x3 > 0)
ret += dfs(x3 - 1, x2 + 1, x1) * (double)x3 / sum;
if (x2 > 0)
ret += dfs(x3, x2 - 1, x1 + 1) * (double)x2 / sum;
if (x1 > 0)
ret += dfs(x3, x2, x1 - 1) * (double)x1 / sum;
return dp[x3][x2][x1] = ret;
}
}
int main() {
cin >> n;
int a[n], x1 = 0, x2 = 0, x3 = 0, x;
for (size_t i = 0; i < n; i++) {
cin >> x;
if (x == 3)
x3++;
if (x == 2)
x2++;
if (x == 1)
x1++;
}
dp[0][0][0] = 0;
int i, j, k, h;
printf("%.12f\n", dfs(x3, x2, x1));
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n;
double dp[310][310][310];
double dfs(int x3, int x2, int x1) {
if (x3 == 0 && x2 == 0 && x1 == 0)
return 0.0;
else if (dp[x3][x2][x1] > 0)
return dp[x3][x2][x1];
else {
double sum = (double)(x3 + x2 + x1);
double ret = (double)n / sum;
if (x3 > 0)
ret += dfs(x3 - 1, x2 + 1, x1) * (double)x3 / sum;
if (x2 > 0)
ret += dfs(x3, x2 - 1, x1 + 1) * (double)x2 / sum;
if (x1 > 0)
ret += dfs(x3, x2, x1 - 1) * (double)x1 / sum;
return dp[x3][x2][x1] = ret;
}
}
int main() {
cin >> n;
int a[n], x1 = 0, x2 = 0, x3 = 0, x;
for (size_t i = 0; i < n; i++) {
cin >> x;
if (x == 3)
x3++;
if (x == 2)
x2++;
if (x == 1)
x1++;
}
dp[0][0][0] = 0;
int i, j, k, h;
printf("%.12f\n", dfs(x3, x2, x1));
return 0;
} | insert | 12 | 12 | 12 | 14 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ld> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
int N;
vi A(4);
vector<vvi> dp(300, vvi(300, vi(300, -1)));
ld f(int a, int b, int c) {
if (a < 0 or b < 0 or c < 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
int v = (a + b + c);
dp[a][b][c] =
N + a * f(a - 1, b, c) + b * f(a + 1, b - 1, c) + c * f(a, b + 1, c - 1);
dp[a][b][c] /= ld(v);
return dp[a][b][c];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int x = 0; x < N; x++) {
int i;
cin >> i;
A[i]++;
}
dp[0][0][0] = 0;
cout << fixed << setprecision(10) << f(A[1], A[2], A[3]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ld> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
int N;
vi A(4);
vector<vvi> dp(305, vvi(305, vi(305, -1)));
ld f(int a, int b, int c) {
if (a < 0 or b < 0 or c < 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
int v = (a + b + c);
dp[a][b][c] =
N + a * f(a - 1, b, c) + b * f(a + 1, b - 1, c) + c * f(a, b + 1, c - 1);
dp[a][b][c] /= ld(v);
return dp[a][b][c];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int x = 0; x < N; x++) {
int i;
cin >> i;
A[i]++;
}
dp[0][0][0] = 0;
cout << fixed << setprecision(10) << f(A[1], A[2], A[3]) << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | -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;
double dp[301][301][301];
int n;
// double dfs(int a, int b, int c){
// if(a+b+c == 0)
// return 0.0;
// if(dp[a][b][c] > -0.5)
// return dp[a][b][c];
// double ks = (double)n/ (a+b+c);
// double ret=0;
// if(a){
// ret += (dfs(a-1,b,c) + ks)*(a/(a+b+c));
// }
// if(b){
// ret += (dfs(a+1,b-1,c) + ks)*(b/(a+b+c));
// }
// if(c){
// ret += (dfs(a,b+1,c-1) + ks)*(c/(a+b+c));
// }
// return dp[a][b][c]=ret;
// }
double rec(int i, int j, int k) {
if (!i && !j && !k)
return 0.0;
if (dp[i][j][k] > 0.0)
return dp[i][j][k];
double sum = i + j + k;
double ret = n / sum;
if (i > 0)
ret += (double)(i / sum) * rec(i - 1, j, k);
if (j > 0)
ret += (double)(j / sum) * rec(i + 1, j - 1, k);
if (k > 0)
ret += (double)(k / sum) * rec(i, j + 1, k - 1);
return dp[i][j][k] = ret;
}
int main() {
// memset(dp, -1, sizeof(dp));
for (int i = 0; i < 310; i++) {
for (int j = 0; j < 310; j++) {
for (int k = 0; k < 310; k++) {
dp[i][j][k] = -1;
}
}
}
int st[4];
memset(st, 0, sizeof(st));
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
st[t]++;
}
// cout<<dfs(st[1],st[2],st[3]);
// cout<<setprecesion(12)<<dfs(st[1],st[2],st[3]);
cout << fixed << setprecision(12) << rec(st[1], st[2], st[3]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n;
// double dfs(int a, int b, int c){
// if(a+b+c == 0)
// return 0.0;
// if(dp[a][b][c] > -0.5)
// return dp[a][b][c];
// double ks = (double)n/ (a+b+c);
// double ret=0;
// if(a){
// ret += (dfs(a-1,b,c) + ks)*(a/(a+b+c));
// }
// if(b){
// ret += (dfs(a+1,b-1,c) + ks)*(b/(a+b+c));
// }
// if(c){
// ret += (dfs(a,b+1,c-1) + ks)*(c/(a+b+c));
// }
// return dp[a][b][c]=ret;
// }
double rec(int i, int j, int k) {
if (!i && !j && !k)
return 0.0;
if (dp[i][j][k] > 0.0)
return dp[i][j][k];
double sum = i + j + k;
double ret = n / sum;
if (i > 0)
ret += (double)(i / sum) * rec(i - 1, j, k);
if (j > 0)
ret += (double)(j / sum) * rec(i + 1, j - 1, k);
if (k > 0)
ret += (double)(k / sum) * rec(i, j + 1, k - 1);
return dp[i][j][k] = ret;
}
int main() {
// memset(dp, -1, sizeof(dp));
for (int i = 0; i < 301; i++) {
for (int j = 0; j < 301; j++) {
for (int k = 0; k < 301; k++) {
dp[i][j][k] = -1;
}
}
}
int st[4];
memset(st, 0, sizeof(st));
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
st[t]++;
}
// cout<<dfs(st[1],st[2],st[3]);
// cout<<setprecesion(12)<<dfs(st[1],st[2],st[3]);
cout << fixed << setprecision(12) << rec(st[1], st[2], st[3]) << endl;
return 0;
} | replace | 42 | 45 | 42 | 45 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int t;
double dp[301][301][301];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
short a[3] = {0};
for (int i = 0; i < t; i++) {
int x;
cin >> x;
a[x - 1]++;
}
for (int threes = 0; threes <= a[2]; threes++) {
for (int twos = 0; twos <= a[1] + a[2]; twos++) {
for (int ones = 0; ones <= a[0] + a[1] + a[2]; ones++) {
double sum = ones + twos + threes;
if (sum <= 0.5)
continue;
double p_waste = t / sum;
auto &p = dp[ones][twos][threes];
if (ones > 0) {
p += (ones) * (p_waste + dp[ones - 1][twos][threes]);
}
if (twos > 0) {
p += (twos) * (p_waste + dp[ones + 1][twos - 1][threes]);
}
if (threes > 0) {
p += (threes) * (p_waste + dp[ones][twos + 1][threes - 1]);
}
p /= sum;
}
}
}
cout << setprecision(10) << dp[a[0]][a[1]][a[2]];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int t;
double dp[301][301][301];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
short a[3] = {0};
for (int i = 0; i < t; i++) {
int x;
cin >> x;
a[x - 1]++;
}
for (int threes = 0; threes <= a[2]; threes++) {
for (int twos = 0; twos <= -threes + a[1] + a[2]; twos++) {
for (int ones = 0; ones <= -threes - twos + a[0] + a[1] + a[2]; ones++) {
double sum = ones + twos + threes;
if (sum <= 0.5)
continue;
double p_waste = t / sum;
auto &p = dp[ones][twos][threes];
if (ones > 0) {
p += (ones) * (p_waste + dp[ones - 1][twos][threes]);
}
if (twos > 0) {
p += (twos) * (p_waste + dp[ones + 1][twos - 1][threes]);
}
if (threes > 0) {
p += (threes) * (p_waste + dp[ones][twos + 1][threes - 1]);
}
p /= sum;
}
}
}
cout << setprecision(10) << dp[a[0]][a[1]][a[2]];
return 0;
} | replace | 16 | 18 | 16 | 18 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int t;
double dp[301][301][301];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
short a[3] = {0};
for (int i = 0; i < t; i++) {
int x;
cin >> x;
a[x - 1]++;
}
for (int threes = 0; threes <= t; threes++) {
for (int twos = 0; twos <= t; twos++) {
for (int ones = 0; ones <= t; ones++) {
double sum = ones + twos + threes;
if (sum <= 0.5)
continue;
double p_waste = t / sum;
auto &p = dp[ones][twos][threes];
if (ones > 0) {
p += (ones) * (p_waste + dp[ones - 1][twos][threes]);
}
if (twos > 0) {
p += (twos) * (p_waste + dp[ones + 1][twos - 1][threes]);
}
if (threes > 0) {
p += (threes) * (p_waste + dp[ones][twos + 1][threes - 1]);
}
p /= sum;
}
}
}
cout << setprecision(10) << dp[a[0]][a[1]][a[2]];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int t;
double dp[301][301][301];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
short a[3] = {0};
for (int i = 0; i < t; i++) {
int x;
cin >> x;
a[x - 1]++;
}
for (int threes = 0; threes <= t; threes++) {
for (int twos = 0; twos <= t - threes; twos++) {
for (int ones = 0; ones <= t - threes - twos; ones++) {
double sum = ones + twos + threes;
if (sum <= 0.5)
continue;
double p_waste = t / sum;
auto &p = dp[ones][twos][threes];
if (ones > 0) {
p += (ones) * (p_waste + dp[ones - 1][twos][threes]);
}
if (twos > 0) {
p += (twos) * (p_waste + dp[ones + 1][twos - 1][threes]);
}
if (threes > 0) {
p += (threes) * (p_waste + dp[ones][twos + 1][threes - 1]);
}
p /= sum;
}
}
}
cout << setprecision(10) << dp[a[0]][a[1]][a[2]];
return 0;
} | replace | 16 | 18 | 16 | 18 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
#define pll pair<long long, long long>
#define pdd pair<long double, long double>
#define vll vector<ll>
#define rep(i, j, n) for (int i = j; i < n; i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll, vector<pll>, greater<pll>> pq;
priority_queue<ll, vector<ll>, greater<ll>> pq1;
ll n;
double dp[301][301][301];
ll arr[301];
double solve(ll a, ll b, ll c) {
// cout<<a<<" "<<b<<" "<<c<<"\n";
if (a < 0 || b < 0 || c < 0)
return 0;
if (a == 0 && b == 0 && c == 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
double p = (1.0) * (a + b + c);
dp[a][b][c] = 0.0;
dp[a][b][c] = (a / p) * solve(a - 1, b, c) +
(b / p) * solve(a + 1, b - 1, c) +
(c / p) * solve(a, b + 1, c - 1) + (double)n / p;
return dp[a][b][c];
}
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// ll n;
cin >> n;
ll a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 1)
a++;
else if (arr[i] == 2)
b++;
else
c++;
}
for (int i = 0; i < 301; i++) {
for (int j = 0; j < 301; j++) {
for (int k = 0; k < 301; k++)
dp[i][j][k] = -1.0;
}
}
// memset(dp,-1.00,sizeof(dp));
// dp[0][0][0]=(1.0);
// dp[1][0][0]=(1.0);
double ans = solve(a, b, c);
cout << setprecision(27) << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
#define pll pair<long long, long long>
#define pdd pair<long double, long double>
#define vll vector<ll>
#define rep(i, j, n) for (int i = j; i < n; i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll, vector<pll>, greater<pll>> pq;
priority_queue<ll, vector<ll>, greater<ll>> pq1;
ll n;
double dp[301][301][301];
ll arr[301];
double solve(ll a, ll b, ll c) {
// cout<<a<<" "<<b<<" "<<c<<"\n";
if (a < 0 || b < 0 || c < 0)
return 0;
if (a == 0 && b == 0 && c == 0)
return 0;
if (dp[a][b][c] != -1)
return dp[a][b][c];
double p = (1.0) * (a + b + c);
dp[a][b][c] = 0.0;
dp[a][b][c] = (a / p) * solve(a - 1, b, c) +
(b / p) * solve(a + 1, b - 1, c) +
(c / p) * solve(a, b + 1, c - 1) + (double)n / p;
return dp[a][b][c];
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// ll n;
cin >> n;
ll a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 1)
a++;
else if (arr[i] == 2)
b++;
else
c++;
}
for (int i = 0; i < 301; i++) {
for (int j = 0; j < 301; j++) {
for (int k = 0; k < 301; k++)
dp[i][j][k] = -1.0;
}
}
// memset(dp,-1.00,sizeof(dp));
// dp[0][0][0]=(1.0);
// dp[1][0][0]=(1.0);
double ans = solve(a, b, c);
cout << setprecision(27) << ans;
return 0;
}
| replace | 41 | 43 | 41 | 43 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr, __VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x, a, b) for (int x = (a), qwerty = (b); x < qwerty; x++)
#define pb push_back
#define mset(a, v) memset((a), (v), sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
typedef long long ll;
const int N = 301;
int A[N], n;
double dp[N][N][N];
int main() {
FIN;
cout << setprecision(12);
cin >> n;
fore(x, 0, n) cin >> A[x];
double nd = n;
fore(c, 0, n + 1) fore(b, 0, n + 1) fore(a, 0, n + 1) {
if (a + b + c == 0)
continue;
double s = a + b + c, &r = dp[a][b][c] = 1;
if (a)
r += dp[a - 1][b][c] * (a / nd);
if (b)
r += dp[a + 1][b - 1][c] * (b / nd);
if (c)
r += dp[a][b + 1][c - 1] * (c / nd);
r /= (1 - (nd - s) / nd);
}
cout << dp[count(A, A + n, 1)][count(A, A + n, 2)][count(A, A + n, 3)]
<< "\n";
} | #include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr, __VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x, a, b) for (int x = (a), qwerty = (b); x < qwerty; x++)
#define pb push_back
#define mset(a, v) memset((a), (v), sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
typedef long long ll;
const int N = 301;
int A[N], n;
double dp[N][N][N];
int main() {
FIN;
cout << setprecision(12);
cin >> n;
fore(x, 0, n) cin >> A[x];
double nd = n;
fore(c, 0, n + 1) fore(b, 0, n + 1) fore(a, 0, n + 1) {
if (a + b + c == 0 || a + b + c > n)
continue;
double s = a + b + c, &r = dp[a][b][c] = 1;
if (a)
r += dp[a - 1][b][c] * (a / nd);
if (b)
r += dp[a + 1][b - 1][c] * (b / nd);
if (c)
r += dp[a][b + 1][c - 1] * (c / nd);
r /= (1 - (nd - s) / nd);
}
cout << dp[count(A, A + n, 1)][count(A, A + n, 2)][count(A, A + n, 3)]
<< "\n";
} | replace | 31 | 32 | 31 | 32 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 301;
double dp[N][N][N];
int n;
int cnt[4];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x]++;
}
for (int k = 0; k <= n; 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)
dp[i][j][k] += 1.0 * i / n * dp[i - 1][j][k];
if (j)
dp[i][j][k] += 1.0 * j / n * dp[i + 1][j - 1][k];
if (k)
dp[i][j][k] += 1.0 * k / n * dp[i][j + 1][k - 1];
dp[i][j][k] /= 1 - 1.0 * (n - i - j - k) / n;
}
}
}
printf("%.10f", dp[cnt[1]][cnt[2]][cnt[3]]);
} | #include <bits/stdc++.h>
using namespace std;
const int N = 302;
double dp[N][N][N];
int n;
int cnt[4];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x]++;
}
for (int k = 0; k <= n; 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)
dp[i][j][k] += 1.0 * i / n * dp[i - 1][j][k];
if (j)
dp[i][j][k] += 1.0 * j / n * dp[i + 1][j - 1][k];
if (k)
dp[i][j][k] += 1.0 * k / n * dp[i][j + 1][k - 1];
dp[i][j][k] /= 1 - 1.0 * (n - i - j - k) / n;
}
}
}
printf("%.10f", dp[cnt[1]][cnt[2]][cnt[3]]);
} | replace | 3 | 4 | 3 | 4 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int main() {
int N;
cin >> N;
vector<int> a(3, 0);
for (int i = 0; i < N; i++) {
int x;
cin >> x;
a[x - 1]++;
}
double dp[N + 1][N + 1][N + 1];
for (int i = 0; i < N + 1; i++) {
for (int j = 0; j < N + 1; j++) {
for (int k = 0; k < N + 1; k++) {
dp[i][j][k] = 0.0;
}
}
}
for (int k = 0; k <= N; k++) {
for (int j = 0; j <= N; j++) {
for (int i = 0; i <= N; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
double sum = i + j + k;
double t = 0.0;
if (j > 0)
t += dp[i + 1][j - 1][k] * j;
if (k > 0)
t += dp[i][j + 1][k - 1] * k;
if (i > 0)
t += dp[i - 1][j][k] * i;
dp[i][j][k] = (t + N) / sum;
}
}
}
cout << setprecision(10) << fixed << dp[a[0]][a[1]][a[2]] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int main() {
int N;
cin >> N;
vector<int> a(3, 0);
for (int i = 0; i < N; i++) {
int x;
cin >> x;
a[x - 1]++;
}
double dp[N + 2][N + 2][N + 2];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
for (int k = 0; k < N + 2; k++) {
dp[i][j][k] = 0.0;
}
}
}
for (int k = 0; k <= N; k++) {
for (int j = 0; j <= N; j++) {
for (int i = 0; i <= N; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
double sum = i + j + k;
double t = 0.0;
if (j > 0)
t += dp[i + 1][j - 1][k] * j;
if (k > 0)
t += dp[i][j + 1][k - 1] * k;
if (i > 0)
t += dp[i - 1][j][k] * i;
dp[i][j][k] = (t + N) / sum;
}
}
}
cout << setprecision(10) << fixed << dp[a[0]][a[1]][a[2]] << endl;
return 0;
}
| replace | 24 | 28 | 24 | 28 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
const int N = 301;
double dp[N][N][N];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vi cnt(3);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x - 1]++;
}
for (int c = 0; c <= n; c++) {
for (int b = 0; b <= n; b++) {
for (int a = 0; a <= n; a++) {
int d = n - a - b - c;
if (d == n) {
continue;
}
double p = 0.0;
if (a)
p += 1.0 * a / n * (1 + dp[a - 1][b][c]);
if (b)
p += 1.0 * b / n * (1 + dp[a + 1][b - 1][c]);
if (c)
p += 1.0 * c / n * (1 + dp[a][b + 1][c - 1]);
if (d)
p = (p + 1.0 * d / n) / (1 - 1.0 * d / n);
dp[a][b][c] = p;
}
}
}
cout << fixed << setprecision(14) << dp[cnt[0]][cnt[1]][cnt[2]] << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
const int N = 303;
double dp[N][N][N];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vi cnt(3);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x - 1]++;
}
for (int c = 0; c <= n; c++) {
for (int b = 0; b <= n; b++) {
for (int a = 0; a <= n; a++) {
int d = n - a - b - c;
if (d == n) {
continue;
}
double p = 0.0;
if (a)
p += 1.0 * a / n * (1 + dp[a - 1][b][c]);
if (b)
p += 1.0 * b / n * (1 + dp[a + 1][b - 1][c]);
if (c)
p += 1.0 * c / n * (1 + dp[a][b + 1][c - 1]);
if (d)
p = (p + 1.0 * d / n) / (1 - 1.0 * d / n);
dp[a][b][c] = p;
}
}
}
cout << fixed << setprecision(14) << dp[cnt[0]][cnt[1]][cnt[2]] << '\n';
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p03169 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int c[4] = {};
for (int i = 0; i < n; i++) {
int a;
cin >> a;
c[a]++;
}
double dp[301][301][301] = {};
for (int k = 0; k <= c[3]; k++)
for (int j = 0; j <= c[2] + c[3]; j++)
for (int i = 0; i <= c[1] + c[2] + c[3]; i++) {
if (i + j + k == 0)
continue;
if (i > 0)
dp[i][j][k] += dp[i - 1][j][k] * i / n;
if (j > 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
if (k > 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] += 1;
dp[i][j][k] *= (double)n / (i + j + k);
}
cout << setprecision(12) << dp[c[1]][c[2]][c[3]] << endl;
}
| #include <iomanip>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int c[4] = {};
for (int i = 0; i < n; i++) {
int a;
cin >> a;
c[a]++;
}
double dp[302][302][302] = {};
for (int k = 0; k <= c[3]; k++)
for (int j = 0; j <= c[2] + c[3]; j++)
for (int i = 0; i <= c[1] + c[2] + c[3]; i++) {
if (i + j + k == 0)
continue;
if (i > 0)
dp[i][j][k] += dp[i - 1][j][k] * i / n;
if (j > 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
if (k > 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] += 1;
dp[i][j][k] *= (double)n / (i + j + k);
}
cout << setprecision(12) << dp[c[1]][c[2]][c[3]] << endl;
}
| replace | 12 | 13 | 12 | 13 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int>>
// #define Matrix vector<vector<int> >
#define double long double
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define td(v) v.begin(), v.end()
#define tdr(v) v.rbegin(), v.rend()
#define endl "\n"
#define Matrix vector<vector<int>>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
double rad(double x) { return x * pi / 180.0; }
bool isleft(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
int det = (b.first - a.first) * (c.second - a.second) -
(c.first - a.first) * (b.second - a.second);
if (det >= 0)
return true;
if (det < 0)
return false;
return false;
}
int exp(int a, int b) {
int result = 1;
while (b > 0) {
if (b & 1)
result = mod(result * a, MOD);
b >>= 1;
a = mod(a * a, MOD);
}
return result;
}
double memo[321][321][321];
int vet[321];
int n;
double dp(int t, int d, int u) {
if (t + d + u == 0)
return 0;
double &x = memo[t][d][u];
if (x != -1)
return x;
x = 0;
for (int i = 0; i < n; i++) {
if (vet[i] == 3) {
vet[i]--;
x += dp(t - 1, d + 1, u);
vet[i]++;
}
if (vet[i] == 2) {
vet[i]--;
x += dp(t, d - 1, u + 1);
vet[i]++;
}
if (vet[i] == 1) {
vet[i]--;
x += dp(t, d, u - 1);
vet[i]++;
}
}
x /= (t + d + u) * 1.0;
x += n * 1.0 / (t + d + u);
return x;
}
void solve() {
cin >> n;
int q[4] = {0, 0, 0};
for (int i = 0; i < n; i++) {
cin >> vet[i];
q[vet[i]]++;
}
for (int i = 0; i < 321; i++)
for (int j = 0; j < 321; j++)
for (int k = 0; k < 321; k++)
memo[i][j][k] = -1;
cout << fixed << setprecision(13);
cout << dp(q[3], q[2], q[1]) << endl;
}
signed main() {
fastio;
int t = 1;
// cin>>t;
while (t--)
solve();
} | #include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int>>
// #define Matrix vector<vector<int> >
#define double long double
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define td(v) v.begin(), v.end()
#define tdr(v) v.rbegin(), v.rend()
#define endl "\n"
#define Matrix vector<vector<int>>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
double rad(double x) { return x * pi / 180.0; }
bool isleft(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
int det = (b.first - a.first) * (c.second - a.second) -
(c.first - a.first) * (b.second - a.second);
if (det >= 0)
return true;
if (det < 0)
return false;
return false;
}
int exp(int a, int b) {
int result = 1;
while (b > 0) {
if (b & 1)
result = mod(result * a, MOD);
b >>= 1;
a = mod(a * a, MOD);
}
return result;
}
double memo[321][321][321];
int vet[321];
int n;
double dp(int t, int d, int u) {
if (t + d + u == 0)
return 0;
double &x = memo[t][d][u];
if (x != -1)
return x;
x = 0;
if (t > 0)
x += t * dp(t - 1, d + 1, u);
if (d > 0)
x += d * dp(t, d - 1, u + 1);
if (u > 0) {
x += u * dp(t, d, u - 1);
}
x /= (t + d + u) * 1.0;
x += n * 1.0 / (t + d + u);
return x;
}
void solve() {
cin >> n;
int q[4] = {0, 0, 0};
for (int i = 0; i < n; i++) {
cin >> vet[i];
q[vet[i]]++;
}
for (int i = 0; i < 321; i++)
for (int j = 0; j < 321; j++)
for (int k = 0; k < 321; k++)
memo[i][j][k] = -1;
cout << fixed << setprecision(13);
cout << dp(q[3], q[2], q[1]) << endl;
}
signed main() {
fastio;
int t = 1;
// cin>>t;
while (t--)
solve();
} | replace | 62 | 78 | 62 | 68 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 301;
double dp[N][N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
int n;
cin >> n;
array<int, 4> cnt{};
int sum = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
++cnt[a];
sum += a;
}
for (int s = 1; s <= sum; ++s) {
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= n; ++k) {
int i = s - 2 * j - 3 * k;
if (i < 0 || i > n)
continue;
dp[i][j][k] = n;
if (i > 0)
dp[i][j][k] += i * dp[i - 1][j][k];
if (j > 0)
dp[i][j][k] += j * dp[i + 1][j - 1][k];
if (k > 0)
dp[i][j][k] += k * dp[i][j + 1][k - 1];
dp[i][j][k] /= (i + j + k);
}
}
}
cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 310;
double dp[N][N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
int n;
cin >> n;
array<int, 4> cnt{};
int sum = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
++cnt[a];
sum += a;
}
for (int s = 1; s <= sum; ++s) {
for (int j = 0; j <= n; ++j) {
for (int k = 0; k <= n; ++k) {
int i = s - 2 * j - 3 * k;
if (i < 0 || i > n)
continue;
dp[i][j][k] = n;
if (i > 0)
dp[i][j][k] += i * dp[i - 1][j][k];
if (j > 0)
dp[i][j][k] += j * dp[i + 1][j - 1][k];
if (k > 0)
dp[i][j][k] += k * dp[i][j + 1][k - 1];
dp[i][j][k] /= (i + j + k);
}
}
}
cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
// struct edge {int from, to, cost;};
constexpr double EPS = 1e-10;
// constexpr double PI = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
template <class T> inline T sqr(T x) { return x * x; }
double dp[101][101][101] = {};
double solve(int c1, int c2, int c3, int n) {
if (c1 <= 0 || c2 < 0 || c3 < 0)
return 0.0;
if (c1 < c2 || c2 < c3 || c1 < c3)
return 0.0;
if (dp[c1][c2][c3] != 0)
return dp[c1][c2][c3];
int sum = c1;
if (sum == 1 && c1 - c2 == 1)
return dp[c1][c2][c3] = 1.0 * n;
return dp[c1][c2][c3] = (solve(c1 - 1, c2, c3, n) * (double)(c1 - c2) / n +
solve(c1, c2 - 1, c3, n) * (double)(c2 - c3) / n +
solve(c1, c2, c3 - 1, n) * (double)c3 / n + 1) *
n / sum;
}
void solve() {
int n;
cin >> n;
VI a(n);
REP(i, 0, n) cin >> a[i];
int cnt[3] = {};
REP(i, 0, n) REP(j, 0, a[i]) cnt[j]++;
// cout<< solve(cnt[0], cnt[1], cnt[2], n) << endl;
printf("%.12lf\n", solve(cnt[0], cnt[1], cnt[2], n));
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
// struct edge {int from, to, cost;};
constexpr double EPS = 1e-10;
// constexpr double PI = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
template <class T> inline T sqr(T x) { return x * x; }
double dp[301][301][301] = {};
double solve(int c1, int c2, int c3, int n) {
if (c1 <= 0 || c2 < 0 || c3 < 0)
return 0.0;
if (c1 < c2 || c2 < c3 || c1 < c3)
return 0.0;
if (dp[c1][c2][c3] != 0)
return dp[c1][c2][c3];
int sum = c1;
if (sum == 1 && c1 - c2 == 1)
return dp[c1][c2][c3] = 1.0 * n;
return dp[c1][c2][c3] = (solve(c1 - 1, c2, c3, n) * (double)(c1 - c2) / n +
solve(c1, c2 - 1, c3, n) * (double)(c2 - c3) / n +
solve(c1, c2, c3 - 1, n) * (double)c3 / n + 1) *
n / sum;
}
void solve() {
int n;
cin >> n;
VI a(n);
REP(i, 0, n) cin >> a[i];
int cnt[3] = {};
REP(i, 0, n) REP(j, 0, a[i]) cnt[j]++;
// cout<< solve(cnt[0], cnt[1], cnt[2], n) << endl;
printf("%.12lf\n", solve(cnt[0], cnt[1], cnt[2], n));
}
int main() {
solve();
return 0;
} | replace | 61 | 62 | 61 | 62 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define mod 1000000007
/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long dice()
{
uniform_int_distribution<long long> uid(1,2);//specify l and r.
return uid(rng) ;
}
int read()
{
int cc = getc(stdin);
for (;cc < '0' || cc > '9';) cc = getc(stdin);
int ret = 0;
for (;cc >= '0' && cc <= '9';)
{
ret = ret * 10 + cc - '0';
cc = getc(stdin);
}
return ret;
}
inline void print(int n)
{
if (n == 0)
{
putchar('0');
putchar('\n');
}
else if (n == -1)
{
putchar('-');
putchar('1');
putchar('\n');
}
else
{
char buf[11];
buf[10] = '\n';
int i = 9;
while (n)
{
buf[i--] = n % 10 + '0';
n /= 10;
}
while (buf[i] != '\n')
putchar(buf[++i]);
}
}
*/
long double dp[301][301][301];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long double n;
int x = 0, y = 0, z = 0;
cin >> n;
int d;
for (int i = 0; i < n; i++) {
cin >> d;
if (d == 1)
x++;
else if (d == 2)
y++;
else
z++;
}
dp[0][0][0] = 0;
for (int i = 0; i <= (z); i++) {
for (int j = 0; j <= (y + z); j++) {
for (int k = 0; k <= (x + y + z); k++) {
if ((i + j + k) > 0)
dp[k][j][i] = (n / (long double)(i + j + k));
if (k > 0)
dp[k][j][i] += (long double)k * dp[k - 1][j][i] / (i + j + k);
if (j > 0)
dp[k][j][i] += (long double)j * dp[k + 1][j - 1][i] / (i + j + k);
if (i > 0)
dp[k][j][i] += (long double)i * dp[k][j + 1][i - 1] / (i + j + k);
}
}
}
cout << fixed << setprecision(13) << dp[x][y][z];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define mod 1000000007
/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long dice()
{
uniform_int_distribution<long long> uid(1,2);//specify l and r.
return uid(rng) ;
}
int read()
{
int cc = getc(stdin);
for (;cc < '0' || cc > '9';) cc = getc(stdin);
int ret = 0;
for (;cc >= '0' && cc <= '9';)
{
ret = ret * 10 + cc - '0';
cc = getc(stdin);
}
return ret;
}
inline void print(int n)
{
if (n == 0)
{
putchar('0');
putchar('\n');
}
else if (n == -1)
{
putchar('-');
putchar('1');
putchar('\n');
}
else
{
char buf[11];
buf[10] = '\n';
int i = 9;
while (n)
{
buf[i--] = n % 10 + '0';
n /= 10;
}
while (buf[i] != '\n')
putchar(buf[++i]);
}
}
*/
long double dp[301][301][301];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long double n;
int x = 0, y = 0, z = 0;
cin >> n;
int d;
for (int i = 0; i < n; i++) {
cin >> d;
if (d == 1)
x++;
else if (d == 2)
y++;
else
z++;
}
dp[0][0][0] = 0;
for (int i = 0; i <= 300; i++) {
for (int j = 0; j <= 300; j++) {
for (int k = 0; k <= 300; k++) {
if (i + j + k > 300)
continue;
if ((i + j + k) > 0)
dp[k][j][i] = (n / (long double)(i + j + k));
if (k > 0)
dp[k][j][i] += (long double)k * dp[k - 1][j][i] / (i + j + k);
if (j > 0)
dp[k][j][i] += (long double)j * dp[k + 1][j - 1][i] / (i + j + k);
if (i > 0)
dp[k][j][i] += (long double)i * dp[k][j + 1][i - 1] / (i + j + k);
}
}
}
cout << fixed << setprecision(13) << dp[x][y][z];
return 0;
}
| replace | 78 | 81 | 78 | 83 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define IO_OP \
std::ios::sync_with_stdio(0); \
std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) \
cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
double dp[303][501][901];
signed main() {
IO_OP;
int n, sum = 0;
cin >> n;
int cnt[3] = {};
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
cnt[x - 1]++;
}
for (int k = 0; k * 3 <= sum; k++)
for (int j = 0; k * 3 + j * 2 <= sum; j++)
for (int i = 0; i + k * 3 + j * 2 <= sum; i++) {
if (i == 0 && j == 0 && k == 0) {
dp[i][j][k] = 0;
} else {
int left = n - i - j - k;
double c = 1 - (double)left / n;
dp[i][j][k] = (1 + (i ? dp[i - 1][j][k] : 0.) * i / n +
(j ? dp[i + 1][j - 1][k] : 0.) * j / n +
(k ? dp[i][j + 1][k - 1] : 0.) * k / n) /
c;
}
}
cout << fixed << setprecision(10) << dp[cnt[0]][cnt[1]][cnt[2]] << endl;
}
| #include <bits/stdc++.h>
#define IO_OP \
std::ios::sync_with_stdio(0); \
std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) \
cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
double dp[901][501][303];
signed main() {
IO_OP;
int n, sum = 0;
cin >> n;
int cnt[3] = {};
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
cnt[x - 1]++;
}
for (int k = 0; k * 3 <= sum; k++)
for (int j = 0; k * 3 + j * 2 <= sum; j++)
for (int i = 0; i + k * 3 + j * 2 <= sum; i++) {
if (i == 0 && j == 0 && k == 0) {
dp[i][j][k] = 0;
} else {
int left = n - i - j - k;
double c = 1 - (double)left / n;
dp[i][j][k] = (1 + (i ? dp[i - 1][j][k] : 0.) * i / n +
(j ? dp[i + 1][j - 1][k] : 0.) * j / n +
(k ? dp[i][j + 1][k - 1] : 0.) * k / n) /
c;
}
}
cout << fixed << setprecision(10) << dp[cnt[0]][cnt[1]][cnt[2]] << endl;
}
| replace | 22 | 23 | 22 | 23 | -11 | |
p03169 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
using namespace std;
// dp[0][0][0] = 0
// ans = dp[#{i| a[i] == 1}][][#{k|a[k] == 3}]
// dp[i][j][k] = 1 + ((N - i - j - k) / N) * dp[i][j][k] + (i / N) * dp[i -
// 1][j][k] + ... (i + j + k) / N * dp[i][j][k] = 1 + (i / N) * dp[i - 1][j][k]
// + (j / N) * dp[i + 1][j - 1][k] + ...
double dp[301][301][301];
int N;
int main() {
int first_cnt[4] = {};
cin >> N;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
first_cnt[a]++;
}
for (int k = 0; k <= first_cnt[3]; k++) {
for (int j = 0; j <= first_cnt[2] + first_cnt[3]; j++) {
for (int i = 0; i <= N; i++) {
if (i == 0 && j == 0 && k == 0) {
continue;
}
dp[i][j][k] += 1.0 * N / (i + j + k);
if (i > 0) {
dp[i][j][k] += 1.0 * i / (i + j + k) * dp[i - 1][j][k];
}
if (j > 0) {
dp[i][j][k] += 1.0 * j / (i + j + k) * dp[i + 1][j - 1][k];
}
if (k > 0) {
dp[i][j][k] += 1.0 * k / (i + j + k) * dp[i][j + 1][k - 1];
}
}
}
}
cout << setprecision(10) << dp[first_cnt[1]][first_cnt[2]][first_cnt[3]]
<< endl;
}
| #include <iomanip>
#include <iostream>
using namespace std;
// dp[0][0][0] = 0
// ans = dp[#{i| a[i] == 1}][][#{k|a[k] == 3}]
// dp[i][j][k] = 1 + ((N - i - j - k) / N) * dp[i][j][k] + (i / N) * dp[i -
// 1][j][k] + ... (i + j + k) / N * dp[i][j][k] = 1 + (i / N) * dp[i - 1][j][k]
// + (j / N) * dp[i + 1][j - 1][k] + ...
double dp[302][302][302];
int N;
int main() {
int first_cnt[4] = {};
cin >> N;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
first_cnt[a]++;
}
for (int k = 0; k <= first_cnt[3]; k++) {
for (int j = 0; j <= first_cnt[2] + first_cnt[3]; j++) {
for (int i = 0; i <= N; i++) {
if (i == 0 && j == 0 && k == 0) {
continue;
}
dp[i][j][k] += 1.0 * N / (i + j + k);
if (i > 0) {
dp[i][j][k] += 1.0 * i / (i + j + k) * dp[i - 1][j][k];
}
if (j > 0) {
dp[i][j][k] += 1.0 * j / (i + j + k) * dp[i + 1][j - 1][k];
}
if (k > 0) {
dp[i][j][k] += 1.0 * k / (i + j + k) * dp[i][j + 1][k - 1];
}
}
}
}
cout << setprecision(10) << dp[first_cnt[1]][first_cnt[2]][first_cnt[3]]
<< endl;
}
| replace | 9 | 10 | 9 | 10 | -11 | |
p03169 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
const int MAX_N = 100;
double p[1 + MAX_N][1 + MAX_N][1 + MAX_N];
int main() {
int n;
scanf("%d", &n);
vector<int> count(3, 0);
for (int i = 0; i < n; i++) {
int ai;
scanf("%d", &ai);
ai--;
count[ai]++;
}
p[count[0]][count[1]][count[2]] = 1;
double answer = 0;
for (int three = n; three >= 0; three--) {
for (int two = n; two >= 0; two--) {
for (int one = n; one >= 0; one--) {
int sum = one + two + three;
if (sum > 0) {
double waitTime = (double)n / sum;
answer += p[one][two][three] * waitTime;
if (two < n && three > 0) {
p[one][two + 1][three - 1] += three * p[one][two][three] / sum;
}
if (one < n && two > 0) {
p[one + 1][two - 1][three] += two * p[one][two][three] / sum;
}
if (one > 0) {
p[one - 1][two][three] += one * p[one][two][three] / sum;
}
}
}
}
}
printf("%.14lf\n", answer);
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
const int MAX_N = 300;
double p[1 + MAX_N][1 + MAX_N][1 + MAX_N];
int main() {
int n;
scanf("%d", &n);
vector<int> count(3, 0);
for (int i = 0; i < n; i++) {
int ai;
scanf("%d", &ai);
ai--;
count[ai]++;
}
p[count[0]][count[1]][count[2]] = 1;
double answer = 0;
for (int three = n; three >= 0; three--) {
for (int two = n; two >= 0; two--) {
for (int one = n; one >= 0; one--) {
int sum = one + two + three;
if (sum > 0) {
double waitTime = (double)n / sum;
answer += p[one][two][three] * waitTime;
if (two < n && three > 0) {
p[one][two + 1][three - 1] += three * p[one][two][three] / sum;
}
if (one < n && two > 0) {
p[one + 1][two - 1][three] += two * p[one][two][three] / sum;
}
if (one > 0) {
p[one - 1][two][three] += one * p[one][two][three] / sum;
}
}
}
}
}
printf("%.14lf\n", answer);
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
//.define
// #define FILE_IN_OUT
#define RET(_x) return cout << (_x) << '\n', 0;
#define all(_obj) std::begin(_obj), std::end(_obj)
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider) \
(((_dividend)-1LL + (_divider)) / (_divider))
#define has(_obj, _val) ((_obj).find(_val) != (_obj).end())
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) \
{}
#endif
#define endl "\n"
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char *_delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
//.constant
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
//.data
int cnt[3];
double dp[301][301][301];
double p[301][301][301];
//.code
int main() {
#ifdef FILE_IN_OUT
std::ifstream cin("input.txt", std::ios::in);
std::ofstream cout("output.txt", std::ios::out);
#else
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int n;
cin >> n;
loop(n) {
int x;
cin >> x;
++cnt[x - 1];
}
const int sum = n;
p[cnt[0]][cnt[1]][cnt[2]] = 1;
for (int x3 = cnt[2]; x3 >= 0; --x3) {
for (int x2 = sum; x2 >= 0; --x2) {
for (int x1 = sum; x1 >= 0; --x1) {
if (x1 + x2 + x3 == 0) {
break;
}
const int zero = sum - x1 - x2 - x3;
double q = 1.0 * zero / sum;
dp[x1][x2][x3] += p[x1][x2][x3] / (1 - q);
if (x3 > 0) {
double curp = 1.0 * x3 / (x1 + x2 + x3);
p[x1][x2 + 1][x3 - 1] += p[x1][x2][x3] * curp;
dp[x1][x2 + 1][x3 - 1] += dp[x1][x2][x3] * curp;
}
if (x2 > 0) {
double curp = 1.0 * x2 / (x1 + x2 + x3);
p[x1 + 1][x2 - 1][x3] += p[x1][x2][x3] * curp;
dp[x1 + 1][x2 - 1][x3] += dp[x1][x2][x3] * curp;
}
if (x1 > 0) {
double curp = 1.0 * x1 / (x1 + x2 + x3);
p[x1 - 1][x2][x3] += p[x1][x2][x3] * curp;
dp[x1 - 1][x2][x3] += dp[x1][x2][x3] * curp;
}
}
}
}
cout << fixed << setprecision(15) << dp[0][0][0] << endl;
#ifdef FILE_IN_OUT
cin.close();
cout.close();
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//.define
// #define FILE_IN_OUT
#define RET(_x) return cout << (_x) << '\n', 0;
#define all(_obj) std::begin(_obj), std::end(_obj)
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider) \
(((_dividend)-1LL + (_divider)) / (_divider))
#define has(_obj, _val) ((_obj).find(_val) != (_obj).end())
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) \
{}
#endif
#define endl "\n"
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char *_delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
//.constant
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
//.data
int cnt[3];
double dp[301][301][301];
double p[301][301][301];
//.code
int main() {
#ifdef FILE_IN_OUT
std::ifstream cin("input.txt", std::ios::in);
std::ofstream cout("output.txt", std::ios::out);
#else
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int n;
cin >> n;
loop(n) {
int x;
cin >> x;
++cnt[x - 1];
}
const int sum = n;
p[cnt[0]][cnt[1]][cnt[2]] = 1;
for (int x3 = cnt[2]; x3 >= 0; --x3) {
for (int x2 = sum; x2 >= 0; --x2) {
for (int x1 = sum; x1 >= 0; --x1) {
if (x1 + x2 + x3 == 0 || x1 + x2 + x3 > n) {
continue;
}
const int zero = sum - x1 - x2 - x3;
double q = 1.0 * zero / sum;
dp[x1][x2][x3] += p[x1][x2][x3] / (1 - q);
if (x3 > 0) {
double curp = 1.0 * x3 / (x1 + x2 + x3);
p[x1][x2 + 1][x3 - 1] += p[x1][x2][x3] * curp;
dp[x1][x2 + 1][x3 - 1] += dp[x1][x2][x3] * curp;
}
if (x2 > 0) {
double curp = 1.0 * x2 / (x1 + x2 + x3);
p[x1 + 1][x2 - 1][x3] += p[x1][x2][x3] * curp;
dp[x1 + 1][x2 - 1][x3] += dp[x1][x2][x3] * curp;
}
if (x1 > 0) {
double curp = 1.0 * x1 / (x1 + x2 + x3);
p[x1 - 1][x2][x3] += p[x1][x2][x3] * curp;
dp[x1 - 1][x2][x3] += dp[x1][x2][x3] * curp;
}
}
}
}
cout << fixed << setprecision(15) << dp[0][0][0] << endl;
#ifdef FILE_IN_OUT
cin.close();
cout.close();
#endif
return 0;
}
| replace | 60 | 62 | 60 | 62 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define RREP(i, m, n) for (int i = (int)(n - 1); i >= m; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define aut(r, v) __typeof(v) r = (v)
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define reach(it, o) for (aut(it, (o).rbegin()); it != (o).rend(); ++it)
#define fi first
#define se second
#define debug(...) \
{ \
cerr << "[L" << __LINE__ << "] "; \
_debug(__VA_ARGS__); \
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
return o << "(" << p.first << ", " << p.second << ")";
}
template <typename T> string join(const vector<T> &v, string del = ", ") {
stringstream s;
rep(i, v.size()) s << del << v[i];
return s.str().substr(del.size());
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
if (v.size())
o << "[" << join(v) << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const vector<vector<T>> &vv) {
int l = vv.size();
if (l) {
o << endl;
rep(i, l) {
o << (i == 0 ? "[ " : ",\n ") << vv[i] << (i == l - 1 ? " ]" : "");
}
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &st) {
vector<T> v(st.begin(), st.end());
o << "{ " << join(v) << " }";
return o;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &m) {
each(p, m) {
o << (p == m.begin() ? "{ " : ",\n ") << *p
<< (p == --m.end() ? " }" : "");
}
return o;
}
inline void _debug() { cerr << endl; }
template <class First, class... Rest>
void _debug(const First &first, const Rest &...rest) {
cerr << first << " ";
_debug(rest...);
}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const double PI = (1 * acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;
inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); }
int N;
double dp[310][310][310];
double rec(int c1, int c2, int c3) {
if (dp[c1][c2][c3] >= 0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return 0.0;
double res = 0.0;
if (c1 > 0)
res += rec(c1 - 1, c2, c3) * c1;
if (c2 > 0)
res += rec(c1 + 1, c2 - 1, c3) * c2;
if (c3 > 0)
res += rec(c1, c2 + 1, c3 - 1) * c3;
res += N;
res *= 1.0 / (c1 + c2 + c3);
return dp[c1][c2][c3] = res;
}
int main() {
ios_base::sync_with_stdio(0);
// finput("./input");
cin >> N;
int C[4];
rep(i, N) {
int a;
cin >> a;
C[a]++;
}
memset(dp, -1, sizeof(dp));
cout << fixed << setprecision(10) << rec(C[1], C[2], C[3]) << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define RREP(i, m, n) for (int i = (int)(n - 1); i >= m; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define aut(r, v) __typeof(v) r = (v)
#define each(it, o) for (aut(it, (o).begin()); it != (o).end(); ++it)
#define reach(it, o) for (aut(it, (o).rbegin()); it != (o).rend(); ++it)
#define fi first
#define se second
#define debug(...) \
{ \
cerr << "[L" << __LINE__ << "] "; \
_debug(__VA_ARGS__); \
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
return o << "(" << p.first << ", " << p.second << ")";
}
template <typename T> string join(const vector<T> &v, string del = ", ") {
stringstream s;
rep(i, v.size()) s << del << v[i];
return s.str().substr(del.size());
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
if (v.size())
o << "[" << join(v) << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const vector<vector<T>> &vv) {
int l = vv.size();
if (l) {
o << endl;
rep(i, l) {
o << (i == 0 ? "[ " : ",\n ") << vv[i] << (i == l - 1 ? " ]" : "");
}
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &st) {
vector<T> v(st.begin(), st.end());
o << "{ " << join(v) << " }";
return o;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &m) {
each(p, m) {
o << (p == m.begin() ? "{ " : ",\n ") << *p
<< (p == --m.end() ? " }" : "");
}
return o;
}
inline void _debug() { cerr << endl; }
template <class First, class... Rest>
void _debug(const First &first, const Rest &...rest) {
cerr << first << " ";
_debug(rest...);
}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const double PI = (1 * acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;
inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); }
int N;
double dp[310][310][310];
double rec(int c1, int c2, int c3) {
if (dp[c1][c2][c3] >= 0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return 0.0;
double res = 0.0;
if (c1 > 0)
res += rec(c1 - 1, c2, c3) * c1;
if (c2 > 0)
res += rec(c1 + 1, c2 - 1, c3) * c2;
if (c3 > 0)
res += rec(c1, c2 + 1, c3 - 1) * c3;
res += N;
res *= 1.0 / (c1 + c2 + c3);
return dp[c1][c2][c3] = res;
}
int main() {
ios_base::sync_with_stdio(0);
// finput("./input");
cin >> N;
int C[4];
memset(C, 0, sizeof(C));
rep(i, N) {
int a;
cin >> a;
C[a]++;
}
memset(dp, -1, sizeof(dp));
cout << fixed << setprecision(10) << rec(C[1], C[2], C[3]) << endl;
return 0;
} | insert | 121 | 121 | 121 | 122 | -11 | |
p03169 | C++ | Runtime Error | // Radhe Radhe
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #include<boost/math/common_factor.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a, n) \
int a[n]; \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define loop(i, a, b, x) for (int i = a; i < b; i += x)
const int MOD = 1000000007;
int N;
long double dp[305][305][305];
long double rec(int i, int j, int k) {
if (i == 0 && j == 0 && k == 0)
return dp[0][0][0];
if (dp[i][j][k] != 0)
return dp[i][j][k];
long double res = 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 += (long double)N;
res /= (long double)(i + j + k);
dp[i][j][k] = res;
return res;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--) {
cin >> N;
int one = 0, two = 0, three = 0;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
if (x == 1)
one++;
else if (x == 2)
two++;
else
three++;
}
memset(dp, 0, sizeof(dp));
long double ans = rec(one, two, three);
cout << setprecision(20) << ans << endl;
}
return 0;
}
| // Radhe Radhe
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #include<boost/math/common_factor.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a, n) \
int a[n]; \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define loop(i, a, b, x) for (int i = a; i < b; i += x)
const int MOD = 1000000007;
int N;
long double dp[305][305][305];
long double rec(int i, int j, int k) {
if (i == 0 && j == 0 && k == 0)
return dp[0][0][0];
if (dp[i][j][k] != 0)
return dp[i][j][k];
long double res = 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 += (long double)N;
res /= (long double)(i + j + k);
dp[i][j][k] = res;
return res;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
cin >> N;
int one = 0, two = 0, three = 0;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
if (x == 1)
one++;
else if (x == 2)
two++;
else
three++;
}
memset(dp, 0, sizeof(dp));
long double ans = rec(one, two, three);
cout << setprecision(20) << ans << endl;
}
return 0;
}
| delete | 51 | 55 | 51 | 51 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
unsigned N;
std::cin >> N;
vector<vector<vector<double>>> dp(
N + 2, vector<vector<double>>(N + 2, vector<double>(N + 2, 0.0)));
vector<int> vals(4, 0);
for (int i = 0; i < N; ++i) {
int x;
std::cin >> x;
vals[x] += 1;
}
int max = vals[1] + vals[2] + vals[3];
for (int z = 0; z <= max; ++z) {
for (int y = 0; y <= max; ++y) {
for (int x = 0; x <= max; ++x) {
if (!x && !y && !z) {
dp[0][0][0] = 0.0;
continue;
}
double sum = N;
if (x > 0)
sum += x * dp[x - 1][y][z];
if (y > 0)
sum += y * dp[x + 1][y - 1][z];
if (z > 0)
sum += z * dp[x][y + 1][z - 1];
dp[x][y][z] = sum / (x + y + z);
if (x == vals[1] && y == vals[2] && z == vals[3]) {
std::cout << std::setprecision(20) << dp[x][y][z];
return 0;
}
}
}
}
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
unsigned N;
std::cin >> N;
vector<vector<vector<double>>> dp(
N + 2, vector<vector<double>>(N + 2, vector<double>(N + 2, 0.0)));
vector<int> vals(4, 0);
for (int i = 0; i < N; ++i) {
int x;
std::cin >> x;
vals[x] += 1;
}
for (int z = 0; z <= vals[3]; ++z) {
for (int y = 0; y <= vals[2] + vals[3]; ++y) {
for (int x = 0; x <= vals[1] + vals[2] + vals[3]; ++x) {
if (x + y + z == 0) {
dp[0][0][0] = 0.0;
continue;
}
double sum = N;
if (x > 0)
sum += x * dp[x - 1][y][z];
if (y > 0)
sum += y * dp[x + 1][y - 1][z];
if (z > 0)
sum += z * dp[x][y + 1][z - 1];
dp[x][y][z] = sum / (x + y + z);
if (x == vals[1] && y == vals[2] && z == vals[3]) {
std::cout << std::setprecision(20) << dp[x][y][z];
return 0;
}
}
}
}
return 0;
} | replace | 25 | 31 | 25 | 29 | TLE | |
p03169 | 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;
double exp_value(ll D1, ll D2, ll D3, ll N,
vector<vector<vector<double>>> &dp) {
if (D1 < 0 || D2 < 0 || D3 < 0)
return (double)0.0;
if (D1 == 0 && D2 == 0 && D3 == 0)
return (double)0.0;
if (dp[D1][D2][D3] >= -0.5)
return dp[D1][D2][D3];
/*
exp_value(D1, D2, D3, N, dp)
= (N-D1-D2-D3)*exp_value(D1, D2, D3, N, dp)/N
+ D1*exp_value(D1-1, D2, D3, N, dp)/N
+ D2*exp_value(D1+1, D2-1, D3, N, dp)/N
+ D3*exp_value(D1, D2+1, D3-1, N, dp)/N
+ 1
*/
ll sum = D1 + D2 + D3;
double tmp1 = (double)D1 * exp_value(D1 - 1, D2, D3, N, dp) / sum;
double tmp2 = (double)D2 * exp_value(D1 + 1, D2 - 1, D3, N, dp) / sum;
double tmp3 = (double)D3 * exp_value(D1, D2 + 1, D3 - 1, N, dp) / sum;
return dp[D1][D2][D3] = tmp1 + tmp2 + tmp3 + (double)N / sum;
}
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;
vll Dishes(4, 0);
ll a;
rep(i, 0, N) {
cin >> a;
++Dishes[a];
}
vector<vector<vector<double>>> dp(
300, vector<vector<double>>(300, vector<double>(300, -1.0)));
printf("%.10lf\n", exp_value(Dishes[1], Dishes[2], Dishes[3], N, dp));
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;
double exp_value(ll D1, ll D2, ll D3, ll N,
vector<vector<vector<double>>> &dp) {
if (D1 < 0 || D2 < 0 || D3 < 0)
return (double)0.0;
if (D1 == 0 && D2 == 0 && D3 == 0)
return (double)0.0;
if (dp[D1][D2][D3] >= -0.5)
return dp[D1][D2][D3];
/*
exp_value(D1, D2, D3, N, dp)
= (N-D1-D2-D3)*exp_value(D1, D2, D3, N, dp)/N
+ D1*exp_value(D1-1, D2, D3, N, dp)/N
+ D2*exp_value(D1+1, D2-1, D3, N, dp)/N
+ D3*exp_value(D1, D2+1, D3-1, N, dp)/N
+ 1
*/
ll sum = D1 + D2 + D3;
double tmp1 = (double)D1 * exp_value(D1 - 1, D2, D3, N, dp) / sum;
double tmp2 = (double)D2 * exp_value(D1 + 1, D2 - 1, D3, N, dp) / sum;
double tmp3 = (double)D3 * exp_value(D1, D2 + 1, D3 - 1, N, dp) / sum;
return dp[D1][D2][D3] = tmp1 + tmp2 + tmp3 + (double)N / sum;
}
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;
vll Dishes(4, 0);
ll a;
rep(i, 0, N) {
cin >> a;
++Dishes[a];
}
vector<vector<vector<double>>> dp(
Dishes[1] + Dishes[2] + Dishes[3] + 1,
vector<vector<double>>(Dishes[2] + Dishes[3] + 1,
vector<double>(Dishes[3] + 1, -1.0)));
printf("%.10lf\n", exp_value(Dishes[1], Dishes[2], Dishes[3], N, dp));
return 0;
} | replace | 103 | 104 | 103 | 106 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03169 | C++ | Runtime Error | // KiSmAt
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18;
const int N = 2 * 1e2 + 10;
ll res;
ll a[N], h[5];
ld dp[N][N][N];
void solve() {
ll n, x;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
++h[x];
}
for (int k = 0; k < N; ++k) {
for (int j = 0; j + k < N; ++j) {
for (int i = 0; i + j + k < N; ++i) {
if (i + j + k == 0)
continue;
if (i + j + k > n)
continue;
ld pi = 1.0 * i / (i + j + k);
ld pj = 1.0 * j / (i + j + k);
ld pk = 1.0 * k / (i + j + k);
dp[i][j][k] = 1.0 * n / (i + j + k);
if (i)
dp[i][j][k] += pi * dp[i - 1][j][k];
if (j)
dp[i][j][k] += pj * dp[i + 1][j - 1][k];
if (k)
dp[i][j][k] += pk * dp[i][j + 1][k - 1];
}
}
}
cout << fixed << setprecision(10) << dp[h[1]][h[2]][h[3]];
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
// nEro | // KiSmAt
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18;
const int N = 3 * 1e2 + 10;
ll res;
ll a[N], h[5];
ld dp[N][N][N];
void solve() {
ll n, x;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
++h[x];
}
for (int k = 0; k < N; ++k) {
for (int j = 0; j + k < N; ++j) {
for (int i = 0; i + j + k < N; ++i) {
if (i + j + k == 0)
continue;
if (i + j + k > n)
continue;
ld pi = 1.0 * i / (i + j + k);
ld pj = 1.0 * j / (i + j + k);
ld pk = 1.0 * k / (i + j + k);
dp[i][j][k] = 1.0 * n / (i + j + k);
if (i)
dp[i][j][k] += pi * dp[i - 1][j][k];
if (j)
dp[i][j][k] += pj * dp[i + 1][j - 1][k];
if (k)
dp[i][j][k] += pk * dp[i][j + 1][k - 1];
}
}
}
cout << fixed << setprecision(10) << dp[h[1]][h[2]][h[3]];
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
// nEro | replace | 8 | 9 | 8 | 9 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mx 1000000007
#define db double
using namespace std;
db dp[100 + 1][100 + 1][100 + 1] = {0}, n;
db solve(int c1, int c2, int c3) {
if (dp[c1][c2][c3] != 0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return dp[c1][c2][c3] = 0;
db j = 0, k = 0, l = 0, sum = c1 + c2 + c3;
if (c1 != 0) {
j = (c1 / sum) * solve(c1 - 1, c2, c3);
}
if (c2 != 0) {
k = (c2 / sum) * solve(c1 + 1, c2 - 1, c3);
}
if (c3 != 0) {
l = (c3 / sum) * solve(c1, c2 + 1, c3 - 1);
}
dp[c1][c2][c3] = (n / (sum)) + j + k + l;
return dp[c1][c2][c3];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int c1 = 0, c2 = 0, c3 = 0;
int sz;
cin >> sz;
n = sz;
int p[sz + 1];
for (int i = 1; i <= sz; ++i) {
cin >> p[i];
if (p[i] == 1)
++c1;
if (p[i] == 2)
++c2;
if (p[i] == 3)
++c3;
}
cout << fixed << setprecision(15) << solve(c1, c2, c3);
return 0;
}
| #include <bits/stdc++.h>
#define mx 1000000007
#define db double
using namespace std;
db dp[301][301][301] = {0}, n;
db solve(int c1, int c2, int c3) {
if (dp[c1][c2][c3] != 0)
return dp[c1][c2][c3];
if (c1 == 0 && c2 == 0 && c3 == 0)
return dp[c1][c2][c3] = 0;
db j = 0, k = 0, l = 0, sum = c1 + c2 + c3;
if (c1 != 0) {
j = (c1 / sum) * solve(c1 - 1, c2, c3);
}
if (c2 != 0) {
k = (c2 / sum) * solve(c1 + 1, c2 - 1, c3);
}
if (c3 != 0) {
l = (c3 / sum) * solve(c1, c2 + 1, c3 - 1);
}
dp[c1][c2][c3] = (n / (sum)) + j + k + l;
return dp[c1][c2][c3];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int c1 = 0, c2 = 0, c3 = 0;
int sz;
cin >> sz;
n = sz;
int p[sz + 1];
for (int i = 1; i <= sz; ++i) {
cin >> p[i];
if (p[i] == 1)
++c1;
if (p[i] == 2)
++c2;
if (p[i] == 3)
++c3;
}
cout << fixed << setprecision(15) << solve(c1, c2, c3);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03169 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (dp[x][y][z] > -0.9) {
return dp[x][y][z];
}
if (x == 0 && y == 0 && z == 0) {
return 0;
}
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = (exp) / (x + y + z);
}
int main() {
int n;
cin >> n;
int one, two, three;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 1) {
one++;
} else if (x == 2) {
two++;
} else if (x == 3) {
three++;
}
}
cout << fixed << setprecision(10) << solve(one, two, three, n);
}
|
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x < 0 || y < 0 || z < 0) {
return 0;
}
if (dp[x][y][z] > -0.9) {
return dp[x][y][z];
}
if (x == 0 && y == 0 && z == 0) {
return 0;
}
double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = (exp) / (x + y + z);
}
int main() {
int n;
cin >> n;
int one = 0, two = 0, three = 0;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 1) {
one++;
} else if (x == 2) {
two++;
} else if (x == 3) {
three++;
}
}
cout << fixed << setprecision(10) << solve(one, two, three, n);
}
| replace | 29 | 30 | 29 | 30 | -11 | |
p03169 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
vector<int> numSushi(4);
int total = 0;
for (int i = 0; i < N; ++i) {
++numSushi[a[i]];
total += a[i];
}
// dp[i][j][k]: 寿司が1個, 2個, 3個の皿が i枚, j枚,
// k枚のとき、全ての寿司を食べるのに必要な操作回数の期待値
double dp[31][31][301] = {};
for (int k = 0; k <= N; ++k) {
for (int j = 0; j <= N; ++j) {
for (int i = 0; i <= N; ++i) {
if (0 < i + j + k and i + j + k <= N) {
if (i != 0)
dp[i][j][k] += dp[i - 1][j][k] * i;
if (j != 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * j;
if (k != 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * k;
dp[i][j][k] = (dp[i][j][k] + N) / (i + j + k);
}
}
}
}
cout << fixed << setprecision(9) << dp[numSushi[1]][numSushi[2]][numSushi[3]]
<< endl;
return 0;
} | #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
vector<int> numSushi(4);
int total = 0;
for (int i = 0; i < N; ++i) {
++numSushi[a[i]];
total += a[i];
}
// dp[i][j][k]: 寿司が1個, 2個, 3個の皿が i枚, j枚,
// k枚のとき、全ての寿司を食べるのに必要な操作回数の期待値
double dp[301][301][301] = {};
for (int k = 0; k <= N; ++k) {
for (int j = 0; j <= N; ++j) {
for (int i = 0; i <= N; ++i) {
if (0 < i + j + k and i + j + k <= N) {
if (i != 0)
dp[i][j][k] += dp[i - 1][j][k] * i;
if (j != 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * j;
if (k != 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * k;
dp[i][j][k] = (dp[i][j][k] + N) / (i + j + k);
}
}
}
}
cout << fixed << setprecision(9) << dp[numSushi[1]][numSushi[2]][numSushi[3]]
<< endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03169 | C++ | Runtime Error | #include <iostream>
using namespace std;
int sum[4];
double dp[31][31][2];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
sum[a]++;
}
double fail;
for (int k = 0; k <= sum[3]; k++)
for (int j = 0; j <= sum[3] + sum[2] - k; j++)
for (int i = 0; i <= N - j - k; i++) {
fail = 1.0 / (1 - (double)(N - i - j - k) / N);
double divis = (i + j + k);
dp[i][j][k % 2] = 0;
if (i) {
dp[i][j][k % 2] += i / divis * (dp[i - 1][j][k % 2]);
}
if (j)
dp[i][j][k % 2] += j / divis * (dp[i + 1][j - 1][k % 2]);
if (k)
dp[i][j][k % 2] += k / divis * (dp[i][j + 1][(k + 1) % 2]);
if (i + j + k)
dp[i][j][k % 2] += fail;
}
printf("%.9lf\n", dp[sum[1]][sum[2]][sum[3] % 2]);
} | #include <iostream>
using namespace std;
int sum[4];
double dp[301][301][2];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
sum[a]++;
}
double fail;
for (int k = 0; k <= sum[3]; k++)
for (int j = 0; j <= sum[3] + sum[2] - k; j++)
for (int i = 0; i <= N - j - k; i++) {
fail = 1.0 / (1 - (double)(N - i - j - k) / N);
double divis = (i + j + k);
dp[i][j][k % 2] = 0;
if (i) {
dp[i][j][k % 2] += i / divis * (dp[i - 1][j][k % 2]);
}
if (j)
dp[i][j][k % 2] += j / divis * (dp[i + 1][j - 1][k % 2]);
if (k)
dp[i][j][k % 2] += k / divis * (dp[i][j + 1][(k + 1) % 2]);
if (i + j + k)
dp[i][j][k % 2] += fail;
}
printf("%.9lf\n", dp[sum[1]][sum[2]][sum[3] % 2]);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03169 | C++ | Runtime Error | #include <iostream>
using namespace std;
int sum[4];
double dp[31][31][31];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
sum[a]++;
}
double fail;
for (int k = 0; k <= sum[3]; k++)
for (int j = 0; j <= sum[3] + sum[2] - k; j++)
for (int i = 0; i <= N - j - k; i++) {
fail = 1.0 / (1 - (double)(N - i - j - k) / N);
double divis = (i + j + k);
if (i) {
dp[i][j][k] += i / divis * (dp[i - 1][j][k]);
}
if (j)
dp[i][j][k] += j / divis * (dp[i + 1][j - 1][k]);
if (k)
dp[i][j][k] += k / divis * (dp[i][j + 1][k - 1]);
if (i + j + k)
dp[i][j][k] += fail;
}
printf("%.9lf\n", dp[sum[1]][sum[2]][sum[3]]);
} | #include <iostream>
using namespace std;
int sum[4];
double dp[301][301][301];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
sum[a]++;
}
double fail;
for (int k = 0; k <= sum[3]; k++)
for (int j = 0; j <= sum[3] + sum[2] - k; j++)
for (int i = 0; i <= N - j - k; i++) {
fail = 1.0 / (1 - (double)(N - i - j - k) / N);
double divis = (i + j + k);
if (i) {
dp[i][j][k] += i / divis * (dp[i - 1][j][k]);
}
if (j)
dp[i][j][k] += j / divis * (dp[i + 1][j - 1][k]);
if (k)
dp[i][j][k] += k / divis * (dp[i][j + 1][k - 1]);
if (i + j + k)
dp[i][j][k] += fail;
}
printf("%.9lf\n", dp[sum[1]][sum[2]][sum[3]]);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
double dp[303][303][303] = {};
double dfs(int i, int j, int k, int n) {
// if(dp[i][j][k]!=-1) return dp[i][j][k];
if ((i < 0) || (j < 0) || (k < 0))
return 0;
else if ((i == 0) && (j == 0) && (k == 0))
return dp[i][j][k] = 0;
else if (dp[i][j][k] != -1)
return dp[i][j][k];
return dp[i][j][k] =
((double)n / (i + j + k)) +
((((double)i) / (i + j + k) * (dfs(i - 1, j, k, n))) +
(((double)j) / (i + j + k) * (dfs(i + 1, j - 1, k, n))) +
(((double)k) / (i + j + k) * (dfs(i, j + 1, k - 1, n))));
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// MEM(dp,-1);
for (int i = 0; i <= 303; i++)
for (int j = 0; j < 303; j++)
for (int k = 0; k < 303; k++)
dp[i][j][k] = -1;
int i, n;
cin >> n;
int a = 0, b = 0, c = 0, z = 0, count[4] = {};
for (i = 0; i < n; i++) {
cin >> z;
if (z == 1)
a++;
if (z == 2)
b++;
if (z == 3)
c++;
}
double ans = dfs(a, b, c, n);
cout << fixed << setprecision(12) << ans;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define MEM(a, b) memset(a, (b), sizeof(a))
double dp[303][303][303] = {};
double dfs(int i, int j, int k, int n) {
// if(dp[i][j][k]!=-1) return dp[i][j][k];
if ((i < 0) || (j < 0) || (k < 0))
return 0;
else if ((i == 0) && (j == 0) && (k == 0))
return dp[i][j][k] = 0;
else if (dp[i][j][k] != -1)
return dp[i][j][k];
return dp[i][j][k] =
((double)n / (i + j + k)) +
((((double)i) / (i + j + k) * (dfs(i - 1, j, k, n))) +
(((double)j) / (i + j + k) * (dfs(i + 1, j - 1, k, n))) +
(((double)k) / (i + j + k) * (dfs(i, j + 1, k - 1, n))));
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// MEM(dp,-1);
for (int i = 0; i < 303; i++)
for (int j = 0; j < 303; j++)
for (int k = 0; k < 303; k++)
dp[i][j][k] = -1;
int i, n;
cin >> n;
int a = 0, b = 0, c = 0, z = 0, count[4] = {};
for (i = 0; i < n; i++) {
cin >> z;
if (z == 1)
a++;
if (z == 2)
b++;
if (z == 3)
c++;
}
double ans = dfs(a, b, c, n);
cout << fixed << setprecision(12) << ans;
}
| replace | 24 | 25 | 24 | 25 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define initialize(array, size, value) \
for (ll i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (lli i = 0; i < size; i++) \
cout << array[i] << " "
#define vl vector<ll>
#define vp vector<pair<ll, ll>>
#define sl set<ll>
#define msp multiset<pair<long long, long long>> S;
#define pll pair<ll, ll>
#define mll \
map<lli, \
lli> // for( map<lli, lli>::iterator
// i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll>>
#define vf vector<pair<pll, pll>>
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque<lli>
#define ptr vector<lli>::iterator
#define bs(array, x) \
binary_search(array.begin(), array.end(), \
x) // also valid for set and multiset
#define lb(array, x) lower_bound(array.begin(), array.end(), x)
#define ub(array, x) upper_bound(array.begin(), array.end(), x)
#define nobw(array, i, j) \
upper_bound(array.begin(), array.end(), j) - \
lower_bound(array.begin(), array.end(), \
i) // number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
ll n;
ll a[305];
ld dp[302][302][302];
ld f(ll b, ll c, ll d) {
// cout<<"call "<<b<<" "<<c<<" "<<d<<endl;
ld aa = n - b - c - d;
if (b < 0 || c < 0 || d < 0 || n - b - c - d < 0)
return 0;
else if (aa == n) {
return 0;
} else if (dp[b][c][d] != 0) {
return dp[b][c][d];
} else {
ld ans = 0;
ld x = (ld)b / (ld)n;
ld y = (ld)c / (ld)n;
ld z = (ld)d / (ld)n;
ans = 1 + x * f(b - 1, c, d) + y * f(b + 1, c - 1, d) +
z * f(b, c + 1, d - 1);
ans = ans / ((ld)1 - (aa / (ld)n));
return dp[b][c][d] = ans;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// ll n;
cin >> n;
// ll a[n];
ll c0 = 0, c1 = 0, c2 = 0, c3 = 0;
loop(i, 0, n) {
cin >> a[i];
if (a[i] == 0)
c0++;
else if (a[i] == 1)
c1++;
else if (a[i] == 2)
c2++;
else if (a[i] == 3)
c3++;
}
memset(dp, 0, sizeof dp);
// cout<<c0<<" "<<c1<<" "<<c2<<" "<<c3<<endl;
cout << fixed << setprecision(15) << f(c1, c2, c3) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define initialize(array, size, value) \
for (ll i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (lli i = 0; i < size; i++) \
cout << array[i] << " "
#define vl vector<ll>
#define vp vector<pair<ll, ll>>
#define sl set<ll>
#define msp multiset<pair<long long, long long>> S;
#define pll pair<ll, ll>
#define mll \
map<lli, \
lli> // for( map<lli, lli>::iterator
// i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll>>
#define vf vector<pair<pll, pll>>
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque<lli>
#define ptr vector<lli>::iterator
#define bs(array, x) \
binary_search(array.begin(), array.end(), \
x) // also valid for set and multiset
#define lb(array, x) lower_bound(array.begin(), array.end(), x)
#define ub(array, x) upper_bound(array.begin(), array.end(), x)
#define nobw(array, i, j) \
upper_bound(array.begin(), array.end(), j) - \
lower_bound(array.begin(), array.end(), \
i) // number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
ll n;
ll a[305];
ld dp[302][302][302];
ld f(ll b, ll c, ll d) {
// cout<<"call "<<b<<" "<<c<<" "<<d<<endl;
ld aa = n - b - c - d;
if (b < 0 || c < 0 || d < 0 || n - b - c - d < 0)
return 0;
else if (aa == n) {
return 0;
} else if (dp[b][c][d] != 0) {
return dp[b][c][d];
} else {
ld ans = 0;
ld x = (ld)b / (ld)n;
ld y = (ld)c / (ld)n;
ld z = (ld)d / (ld)n;
ans = 1 + x * f(b - 1, c, d) + y * f(b + 1, c - 1, d) +
z * f(b, c + 1, d - 1);
ans = ans / ((ld)1 - (aa / (ld)n));
return dp[b][c][d] = ans;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
/* #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
// ll n;
cin >> n;
// ll a[n];
ll c0 = 0, c1 = 0, c2 = 0, c3 = 0;
loop(i, 0, n) {
cin >> a[i];
if (a[i] == 0)
c0++;
else if (a[i] == 1)
c1++;
else if (a[i] == 2)
c2++;
else if (a[i] == 3)
c3++;
}
memset(dp, 0, sizeof dp);
// cout<<c0<<" "<<c1<<" "<<c2<<" "<<c3<<endl;
cout << fixed << setprecision(15) << f(c1, c2, c3) << endl;
} | replace | 80 | 85 | 80 | 85 | -11 | |
p03169 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<vector<ll>> mat;
const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 302;
const int M = 110;
ld d[N * 3][N * 3 / 2][N];
int cnt[N];
int a[N * 2];
void solve() {
int n;
cin >> n;
fr(i, n) {
cin >> a[i];
cnt[a[i]]++;
}
ld k = n;
int ssum = accumulate(a, a + n, 0);
d[0][0][0] = 0;
for (int sum = 1; sum <= ssum; sum++)
for (int c1 = 0; c1 <= sum; c1++)
for (int c2 = 0; 2 * c2 <= sum; c2++) {
int c3 = (sum - c1 - 2 * c2) / 3;
if (c3 < 0 || (sum - c1 - 2 * c2) % 3)
continue;
d[c1][c2][c3] = ((c1 ? (c1 / k) * d[c1 - 1][c2][c3] : 0) +
(c2 ? (c2 / k) * d[c1 + 1][c2 - 1][c3] : 0) +
(c3 ? (c3 / k) * d[c1][c2 + 1][c3 - 1] : 0) + 1) /
(c1 + c2 + c3) * (ld)(n);
}
cout << fixed << setprecision(12) << d[cnt[1]][cnt[2]][cnt[3]];
}
int main() {
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
solve();
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef double ld;
typedef vector<vector<ll>> mat;
const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 302;
const int M = 110;
ld d[N * 3][N * 3 / 2][N];
int cnt[N];
int a[N * 2];
void solve() {
int n;
cin >> n;
fr(i, n) {
cin >> a[i];
cnt[a[i]]++;
}
ld k = n;
int ssum = accumulate(a, a + n, 0);
d[0][0][0] = 0;
for (int sum = 1; sum <= ssum; sum++)
for (int c1 = 0; c1 <= sum; c1++)
for (int c2 = 0; 2 * c2 <= sum; c2++) {
int c3 = (sum - c1 - 2 * c2) / 3;
if (c3 < 0 || (sum - c1 - 2 * c2) % 3)
continue;
d[c1][c2][c3] = ((c1 ? (c1 / k) * d[c1 - 1][c2][c3] : 0) +
(c2 ? (c2 / k) * d[c1 + 1][c2 - 1][c3] : 0) +
(c3 ? (c3 / k) * d[c1][c2 + 1][c3 - 1] : 0) + 1) /
(c1 + c2 + c3) * (ld)(n);
}
cout << fixed << setprecision(12) << d[cnt[1]][cnt[2]][cnt[3]];
}
int main() {
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
solve();
}
| replace | 8 | 9 | 8 | 9 | MLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define maxn 302
using namespace std;
typedef double db;
db dp[maxn][maxn][maxn];
int n, k, cnt[4];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
cnt[k]++;
}
for (int sum = 1; sum <= 3 * n; sum++)
for (int k = 0; k * 3 <= sum; k++)
for (int j = 0; j * 2 + k * 3 <= sum; j++) {
int i = sum - j * 2 - k * 3;
if (i > 0)
dp[i][j][k] += (db)i / (i + j + k) * dp[i - 1][j][k];
if (j > 0)
dp[i][j][k] += (db)j / (i + j + k) * dp[i + 1][j - 1][k];
if (k > 0)
dp[i][j][k] += (db)k / (i + j + k) * dp[i][j + 1][k - 1];
dp[i][j][k] += (db)n / (i + j + k);
}
printf("%.13f\n", dp[cnt[1]][cnt[2]][cnt[3]]);
}
| #include <bits/stdc++.h>
#define maxn 302
using namespace std;
typedef double db;
db dp[maxn][maxn][maxn];
int n, k, cnt[4];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
cnt[k]++;
}
for (int sum = 1; sum <= 3 * n; sum++)
for (int k = 0; k * 3 <= sum; k++)
for (int j = 0; j * 2 + k * 3 <= sum; j++) {
int i = sum - j * 2 - k * 3;
if (i + j + k > n)
continue;
if (i > 0)
dp[i][j][k] += (db)i / (i + j + k) * dp[i - 1][j][k];
if (j > 0)
dp[i][j][k] += (db)j / (i + j + k) * dp[i + 1][j - 1][k];
if (k > 0)
dp[i][j][k] += (db)k / (i + j + k) * dp[i][j + 1][k - 1];
dp[i][j][k] += (db)n / (i + j + k);
}
printf("%.13f\n", dp[cnt[1]][cnt[2]][cnt[3]]);
}
| insert | 17 | 17 | 17 | 19 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a[5] = {0};
long double dp[205][205][205];
long double solve(int n1, int n2, int n3) {
if ((n1 < 0) || (n2 < 0) || (n3 < 0))
return 0;
if (n1 == 0 && n2 == 0 && n3 == 0)
return 0;
if (dp[n1][n2][n3] != 0)
return dp[n1][n2][n3];
long double &ans = dp[n1][n2][n3];
int cnt = 0;
int x = n - n1 - n2 - n3;
long double nn = n1 + n2 + n3;
long double nn1 = (long double)n1 / nn;
long double nn2 = (long double)n2 / nn;
long double nn3 = (long double)n3 / nn;
long double c = solve(n1 - 1, n2, n3);
if (c > 0) {
long double xx = (long double)(((long double)n1 + (long double)x * nn1) /
((long double)n1));
// cout<<xx<<" "<<c<<"\n";
xx += c;
xx *= nn1;
ans += xx;
}
c = solve(n1 + 1, n2 - 1, n3);
if (c > 0) {
long double xx = (long double)(((long double)n2 + (long double)x * nn2) /
((long double)n2));
// cout<<xx<<" ";
xx += c;
xx *= nn2;
ans += xx;
// cnt++;
}
c = solve(n1, n2 + 1, n3 - 1);
if (c > 0) {
long double xx = (long double)(((long double)n3 + (long double)x * nn3) /
((long double)n3));
// cout<<xx<<" ";
xx += c;
xx *= nn3;
ans += xx;
// cnt++;
}
// ans=ans/cnt;
// cout<<n1<<" "<<n2<<" "<<n3<<" "<<ans<<" "<<cnt<<"\n";
return ans;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(dp, 0, sizeof(dp));
cin >> n;
dp[1][0][0] = n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
// cout<<a[1]<<" "<<a[2]<<" "<<a[3]<<"\n";
std::cout << std::setprecision(15) << solve(a[1], a[2], a[3]) << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a[5] = {0};
long double dp[305][305][305];
long double solve(int n1, int n2, int n3) {
if ((n1 < 0) || (n2 < 0) || (n3 < 0))
return 0;
if (n1 == 0 && n2 == 0 && n3 == 0)
return 0;
if (dp[n1][n2][n3] != 0)
return dp[n1][n2][n3];
long double &ans = dp[n1][n2][n3];
int cnt = 0;
int x = n - n1 - n2 - n3;
long double nn = n1 + n2 + n3;
long double nn1 = (long double)n1 / nn;
long double nn2 = (long double)n2 / nn;
long double nn3 = (long double)n3 / nn;
long double c = solve(n1 - 1, n2, n3);
if (c > 0) {
long double xx = (long double)(((long double)n1 + (long double)x * nn1) /
((long double)n1));
// cout<<xx<<" "<<c<<"\n";
xx += c;
xx *= nn1;
ans += xx;
}
c = solve(n1 + 1, n2 - 1, n3);
if (c > 0) {
long double xx = (long double)(((long double)n2 + (long double)x * nn2) /
((long double)n2));
// cout<<xx<<" ";
xx += c;
xx *= nn2;
ans += xx;
// cnt++;
}
c = solve(n1, n2 + 1, n3 - 1);
if (c > 0) {
long double xx = (long double)(((long double)n3 + (long double)x * nn3) /
((long double)n3));
// cout<<xx<<" ";
xx += c;
xx *= nn3;
ans += xx;
// cnt++;
}
// ans=ans/cnt;
// cout<<n1<<" "<<n2<<" "<<n3<<" "<<ans<<" "<<cnt<<"\n";
return ans;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(dp, 0, sizeof(dp));
cin >> n;
dp[1][0][0] = n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
// cout<<a[1]<<" "<<a[2]<<" "<<a[3]<<"\n";
std::cout << std::setprecision(15) << solve(a[1], a[2], a[3]) << '\n';
}
| replace | 5 | 6 | 5 | 6 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#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)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n;
const int max_n = 303;
double dp[max_n][max_n][max_n];
// dp[i1][i2][i3]
// :寿司j個の皿がij枚あるとき、すべての寿司がなくなるまでの操作回数の期待値
double calc(int i, int j, int k) {
if (!i && !j && !k)
return 0.0;
if (dp[i][j][k] > 0)
return dp[i][j][k];
int l = i + j + k;
double ret = 1.0 * n / l;
if (i)
ret += 1.0 * i / l * calc(i - 1, j, k);
if (j)
ret += 1.0 * j / l * calc(i + 1, j - 1, k);
if (k)
ret += 1.0 * k / l * calc(i, j + 1, k - 1);
dp[i][j][k] = ret;
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int cnt[4] = {};
rep(i, n) {
int a;
cin >> a;
cnt[a]++;
}
rep(i, max_n) rep(j, max_n) rep(k, max_n) dp[i][j][k] = 0;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
calc(i, j, k);
}
}
}
cout << fixed << setprecision(11) << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
}
| #include <bits/stdc++.h>
#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)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n;
const int max_n = 303;
double dp[max_n][max_n][max_n];
// dp[i1][i2][i3]
// :寿司j個の皿がij枚あるとき、すべての寿司がなくなるまでの操作回数の期待値
double calc(int i, int j, int k) {
if (!i && !j && !k)
return 0.0;
if (dp[i][j][k] > 0)
return dp[i][j][k];
int l = i + j + k;
double ret = 1.0 * n / l;
if (i)
ret += 1.0 * i / l * calc(i - 1, j, k);
if (j)
ret += 1.0 * j / l * calc(i + 1, j - 1, k);
if (k)
ret += 1.0 * k / l * calc(i, j + 1, k - 1);
dp[i][j][k] = ret;
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int cnt[4] = {};
rep(i, n) {
int a;
cin >> a;
cnt[a]++;
}
rep(i, max_n) rep(j, max_n) rep(k, max_n) dp[i][j][k] = 0;
cout << fixed << setprecision(11) << calc(cnt[1], cnt[2], cnt[3]) << endl;
}
| replace | 52 | 61 | 52 | 53 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100005
#define ld long double
ll fastpower(ll b, ll p) {
ll k = p % 2 ? b : 1;
return p == 0 ? 1 : k * (fastpower(b * b, p / 2));
}
ld dp[105][105][105];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll cnt[4] = {0, 0, 0, 0};
ll x;
for (int i = 0; i < n; i++) {
cin >> x;
cnt[x]++;
}
dp[0][0][0] = 0;
for (ll three = 0; three <= n; three++) {
for (ll two = 0; two <= n; two++) {
for (ll one = 0; one <= n; one++) {
ll zero = n - two - three - one;
if (zero < 0 || zero == n)
continue;
ld value = 1.0;
if (three > 0)
value += (1.0 * three / n) * dp[three - 1][two + 1][one];
if (two > 0)
value += (1.0 * two / n) * dp[three][two - 1][one + 1];
if (one > 0)
value += (1.0 * one / n) * dp[three][two][one - 1];
// dp[three][two][one]=(value)/(1-1.0*zero/n);
dp[three][two][one] = (value * n) / (1.0 * (one + two + three));
}
}
}
ld ans = dp[cnt[3]][cnt[2]][cnt[1]];
cout.precision(20);
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100005
#define ld long double
ll fastpower(ll b, ll p) {
ll k = p % 2 ? b : 1;
return p == 0 ? 1 : k * (fastpower(b * b, p / 2));
}
ld dp[305][305][305];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll cnt[4] = {0, 0, 0, 0};
ll x;
for (int i = 0; i < n; i++) {
cin >> x;
cnt[x]++;
}
dp[0][0][0] = 0;
for (ll three = 0; three <= n; three++) {
for (ll two = 0; two <= n; two++) {
for (ll one = 0; one <= n; one++) {
ll zero = n - two - three - one;
if (zero < 0 || zero == n)
continue;
ld value = 1.0;
if (three > 0)
value += (1.0 * three / n) * dp[three - 1][two + 1][one];
if (two > 0)
value += (1.0 * two / n) * dp[three][two - 1][one + 1];
if (one > 0)
value += (1.0 * one / n) * dp[three][two][one - 1];
// dp[three][two][one]=(value)/(1-1.0*zero/n);
dp[three][two][one] = (value * n) / (1.0 * (one + two + three));
}
}
}
ld ans = dp[cnt[3]][cnt[2]][cnt[1]];
cout.precision(20);
cout << ans;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
double dp[305][305][305];
int cnt[4];
int main() {
freopen("j.in", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
cnt[t]++;
}
dp[0][0][0] = 0;
for (int n3 = 0; n3 <= cnt[3]; n3++) {
for (int n2 = 0; n2 + n3 <= cnt[2] + cnt[3]; n2++) {
for (int n1 = 0; n1 + n2 + n3 <= n - cnt[0]; n1++) {
int s = n1 + n2 + n3;
if (s != 0) {
double temp = double(n);
if (n1 != 0)
temp += double(n1) * dp[n1 - 1][n2][n3];
if (n2 != 0)
temp += double(n2) * dp[n1 + 1][n2 - 1][n3];
if (n3 != 0)
temp += double(n3) * dp[n1][n2 + 1][n3 - 1];
temp /= double(s);
dp[n1][n2][n3] = temp;
}
}
}
}
cout.precision(16);
cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int n;
double dp[305][305][305];
int cnt[4];
int main() {
// freopen("j.in", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
cnt[t]++;
}
dp[0][0][0] = 0;
for (int n3 = 0; n3 <= cnt[3]; n3++) {
for (int n2 = 0; n2 + n3 <= cnt[2] + cnt[3]; n2++) {
for (int n1 = 0; n1 + n2 + n3 <= n - cnt[0]; n1++) {
int s = n1 + n2 + n3;
if (s != 0) {
double temp = double(n);
if (n1 != 0)
temp += double(n1) * dp[n1 - 1][n2][n3];
if (n2 != 0)
temp += double(n2) * dp[n1 + 1][n2 - 1][n3];
if (n3 != 0)
temp += double(n3) * dp[n1][n2 + 1][n3 - 1];
temp /= double(s);
dp[n1][n2][n3] = temp;
}
}
}
}
cout.precision(16);
cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
namespace Base {
#define mr make_pair
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template <typename T> void read(T &x) {
x = 0;
int fh = 1;
double num = 1.0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
fh = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
if (ch == '.') {
ch = getchar();
while (isdigit(ch)) {
num /= 10;
x = x + num * (ch - '0');
ch = getchar();
}
}
x = x * fh;
}
template <typename T> void chmax(T &x, T y) { x = x < y ? y : x; }
template <typename T> void chmin(T &x, T y) { x = x > y ? y : x; }
} // namespace Base
using namespace Base;
const int N = 210;
int n, cnt[4], q1[N * N * N], q2[N * N * N], q3[N * N * N];
bool mp[N][N][N];
double g[N][N][N], f[N][N][N];
int main() {
read(n);
for (int i = 1; i <= n; i++) {
int x;
read(x);
cnt[x]++;
}
mp[cnt[1]][cnt[2]][cnt[3]] = true;
g[cnt[1]][cnt[2]][cnt[3]] = 1;
q1[1] = cnt[1], q2[1] = cnt[2], q3[1] = cnt[3];
int pl = 1, pr = 1;
while (pl <= pr) {
int x = q1[pl], y = q2[pl], z = q3[pl], nx, ny, nz;
f[x][y][z] /= g[x][y][z];
pl++;
double t = 1.0 * n / (x + y + z);
if (x > 0) {
nx = x - 1, ny = y, nz = z;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * x / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
if (y > 0) {
nx = x + 1, ny = y - 1, nz = z;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * y / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
if (z > 0) {
nx = x, ny = y + 1, nz = z - 1;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * z / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
}
printf("%.10lf\n", f[0][0][0]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
namespace Base {
#define mr make_pair
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template <typename T> void read(T &x) {
x = 0;
int fh = 1;
double num = 1.0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
fh = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
if (ch == '.') {
ch = getchar();
while (isdigit(ch)) {
num /= 10;
x = x + num * (ch - '0');
ch = getchar();
}
}
x = x * fh;
}
template <typename T> void chmax(T &x, T y) { x = x < y ? y : x; }
template <typename T> void chmin(T &x, T y) { x = x > y ? y : x; }
} // namespace Base
using namespace Base;
const int N = 310;
int n, cnt[4], q1[N * N * N], q2[N * N * N], q3[N * N * N];
bool mp[N][N][N];
double g[N][N][N], f[N][N][N];
int main() {
read(n);
for (int i = 1; i <= n; i++) {
int x;
read(x);
cnt[x]++;
}
mp[cnt[1]][cnt[2]][cnt[3]] = true;
g[cnt[1]][cnt[2]][cnt[3]] = 1;
q1[1] = cnt[1], q2[1] = cnt[2], q3[1] = cnt[3];
int pl = 1, pr = 1;
while (pl <= pr) {
int x = q1[pl], y = q2[pl], z = q3[pl], nx, ny, nz;
f[x][y][z] /= g[x][y][z];
pl++;
double t = 1.0 * n / (x + y + z);
if (x > 0) {
nx = x - 1, ny = y, nz = z;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * x / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
if (y > 0) {
nx = x + 1, ny = y - 1, nz = z;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * y / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
if (z > 0) {
nx = x, ny = y + 1, nz = z - 1;
if (!mp[nx][ny][nz]) {
pr++;
q1[pr] = nx, q2[pr] = ny, q3[pr] = nz;
mp[nx][ny][nz] = true;
}
double p = 1.0 * z / (x + y + z);
g[nx][ny][nz] += p * g[x][y][z];
f[nx][ny][nz] += p * g[x][y][z] * (f[x][y][z] + t);
}
}
printf("%.10lf\n", f[0][0][0]);
return 0;
}
| replace | 37 | 38 | 37 | 38 | -11 | |
p03169 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
using namespace std;
#define MAXN 310
typedef long double ld;
ld dp[MAXN][MAXN][MAXN];
int N;
int sushi[MAXN];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> sushi[i];
}
for (int k = 0; k <= N; k++) {
for (int j = 0; j <= N; j++) {
for (int i = 0; i <= N; i++) {
if (i + j + k <= N) {
if ((i == 0 && j == 0) && (k == 0)) {
dp[i][j][k] = (ld)0;
} else {
ld temp = (ld)i * dp[i - 1][j][k] + (ld)j * dp[i + 1][j - 1][k] +
(ld)k * dp[i][j + 1][k - 1] + (ld)N;
dp[i][j][k] = temp / ((ld)(i + j + k));
}
}
}
}
}
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < N; i++) {
if (sushi[i] == 1) {
c1++;
} else if (sushi[i] == 2) {
c2++;
} else {
c3++;
}
}
cout << setprecision(10);
cout << dp[c1][c2][c3] << endl;
}
| #include <iomanip>
#include <iostream>
using namespace std;
#define MAXN 310
typedef long double ld;
ld dp[MAXN][MAXN][MAXN];
int N;
int sushi[MAXN];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> sushi[i];
}
for (int k = 0; k <= N; k++) {
for (int j = 0; j <= N; j++) {
for (int i = 0; i <= N; i++) {
if (i + j + k <= N) {
if ((i == 0 && j == 0) && (k == 0)) {
dp[i][j][k] = (ld)0;
} else {
ld temp = (i != 0 ? (ld)i * dp[i - 1][j][k] : 0) +
(j != 0 ? (ld)j * dp[i + 1][j - 1][k] : 0) +
(k != 0 ? (ld)k * dp[i][j + 1][k - 1] : 0) + (ld)N;
dp[i][j][k] = temp / ((ld)(i + j + k));
}
}
}
}
}
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < N; i++) {
if (sushi[i] == 1) {
c1++;
} else if (sushi[i] == 2) {
c2++;
} else {
c3++;
}
}
cout << setprecision(10);
cout << dp[c1][c2][c3] << endl;
} | replace | 24 | 26 | 24 | 27 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
vector<vector<vector<double>>>
dp(300, vector<vector<double>>(300, vector<double>(300, -1)));
ll n;
double dfs(ll i, ll j, ll k) {
if (dp[i][j][k] > -1)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0;
double res = 0;
if (i)
res += dfs(i - 1, j, k) * i;
if (j)
res += dfs(i + 1, j - 1, k) * j;
if (k)
res += dfs(i, j + 1, k - 1) * k;
res += n;
res *= 1.0 / (i + j + k);
return dp[i][j][k] = res;
}
int main() {
cin >> n;
ll one = 0, two = 0, three = 0;
for (ll i = 0; i < n; i++) {
ll a;
cin >> a;
if (a == 1)
one++;
else if (a == 2)
two++;
else
three++;
}
double ans = dfs(one, two, three);
cout << fixed << setprecision(10) << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
vector<vector<vector<double>>>
dp(301, vector<vector<double>>(301, vector<double>(301, -1)));
ll n;
double dfs(ll i, ll j, ll k) {
if (dp[i][j][k] > -1)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0;
double res = 0;
if (i)
res += dfs(i - 1, j, k) * i;
if (j)
res += dfs(i + 1, j - 1, k) * j;
if (k)
res += dfs(i, j + 1, k - 1) * k;
res += n;
res *= 1.0 / (i + j + k);
return dp[i][j][k] = res;
}
int main() {
cin >> n;
ll one = 0, two = 0, three = 0;
for (ll i = 0; i < n; i++) {
ll a;
cin >> a;
if (a == 1)
one++;
else if (a == 2)
two++;
else
three++;
}
double ans = dfs(one, two, three);
cout << fixed << setprecision(10) << ans << endl;
} | replace | 11 | 12 | 11 | 12 | -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 putchar(x) cout << (x)
#define repeat(x) \
int _ = 0; \
_ < (x); \
++_
template <typename T> constexpr auto range(T start, T stop, T step) {
struct iterator {
T i, step;
bool operator!=(const iterator &other) const { return i != other.i; }
auto &operator++() {
i += step;
return *this;
}
auto &operator*() { return i; }
};
struct iterable_wrapper {
T start, stop, step;
auto begin() const { return iterator{start, step}; }
auto end() const { return iterator{stop, step}; }
size_t size() const { return (stop - start) / step; }
iterable_wrapper(T start_, T stop_, T step_)
: start(start_), stop(stop_), step(step_) {
stop = step > 0 ? max(start, stop) : min(start, stop);
stop += (step - (stop - start) % step) % step;
}
};
return iterable_wrapper(start, stop, step);
};
template <typename T> constexpr auto range(T start, T stop) {
return range(start, stop, T(1));
}
template <typename T> constexpr auto range(T stop) {
return range(T(0), stop, T(1));
}
template <typename T, typename Iter = decltype(begin(declval<T>()))>
constexpr auto printer(T &&iterable) {
struct iterator {
Iter iter, ed;
auto operator!=(const iterator &other) const {
auto ret = (iter != other.iter);
if (not ret)
cout << '\n';
return ret;
}
auto &operator++() {
++iter;
if (iter != ed)
cout << ' ';
return *this;
}
auto &operator*() { return *iter; }
};
struct iterable_wrapper {
T iterable;
auto begin() const {
return iterator{std::begin(iterable), std::end(iterable)};
}
auto end() const {
return iterator{std::end(iterable), std::end(iterable)};
}
};
return iterable_wrapper{forward<T>(iterable)};
};
template <size_t... Is, typename T> auto getis(const T &t) {
return tie(get<Is>(t)...);
}
template <class T> void setmax(T &a, const T &b) { a = max(a, b); }
template <class T> void setmin(T &a, const T &b) { a = min(a, b); }
template <typename T> struct is_const_char_arr_ref : false_type {};
template <size_t N>
struct is_const_char_arr_ref<char const (&)[N]> : true_type {};
template <typename T, typename = void> struct is_container : false_type {};
template <typename T>
struct is_container<T,
conditional_t<false, decltype(begin(declval<T>())), void>>
: true_type {};
template <class T>
using IsC = typename enable_if<is_container<T>::value and
not is_same<T, string>::value>::type;
template <class T>
using NotC = typename enable_if<not is_container<T>::value or
is_same<T, string>::value>::type;
template <class T> inline IsC<T> print_1(const T &v);
template <class T> inline NotC<T> print_1(const T &x) { cout << x; }
template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; };
inline void print_1(const tuple<> &) { cout << "()"; };
template <size_t L, size_t I, class T> void print_tuple(const T &t) {
if (I != 0)
cout << ", ";
print_1(get<I>(t));
if (I + 1 < L)
print_tuple<L, (I + 1) % L>(t);
}
template <class... T> inline void print_1(const tuple<T...> &x) {
cout << "(";
print_tuple<sizeof...(T), 0, tuple<T...>>(x);
cout << ")";
}
inline void print_n() {}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail);
template <class T, class U> inline void print_1(const pair<T, U> &p) {
cout << "(";
print_1(p.first);
cout << ", ";
print_1(p.second);
cout << ")";
}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail) {
print_1(head);
if (sizeof...(tail))
cout << " ";
print_n(tail...);
}
template <class T> inline IsC<T> print_1(const T &v) {
cout << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
cout << ", ";
print_1(*it);
}
cout << "]";
}
template <class... T> inline void print(const T &...args) {
print_n(args...);
putchar('\n');
}
inline void read() {}
template <class T, class... U> inline void read(T &head, U &...tail) {
cin >> head;
read(tail...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static int fastio = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(17);
return 0;
}();
template <class T> void print_dbg(const string &s, T &&x) {
if (is_const_char_arr_ref<T>::value) {
print_n(x);
} else {
print_n(s, "=", x);
}
}
#define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define dbg1(a) \
print_dbg(#a, a); \
cout << endl;
#define dbg2(a, b) \
print_dbg(#a, a); \
cout << ", "; \
dbg1(b);
#define dbg3(a, b, c) \
print_dbg(#a, a); \
cout << ", "; \
dbg2(b, c);
#define dbg4(a, b, c, d) \
print_dbg(#a, a); \
cout << ", "; \
dbg3(b, c, d);
#define dbg5(a, b, c, d, e) \
print_dbg(#a, a); \
cout << ", "; \
dbg4(b, c, d, e);
#define dbg6(a, b, c, d, e, f) \
print_dbg(#a, a); \
cout << ", "; \
dbg5(b, c, d, e, f);
#define dbg7(a, b, c, d, e, f, g) \
print_dbg(#a, a); \
cout << ", "; \
dbg6(b, c, d, e, f, g);
#define dbg8(a, b, c, d, e, f, g, h) \
print_dbg(#a, a); \
cout << ", "; \
dbg7(b, c, d, e, f, g, h);
#define debug(...) \
SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1) \
(__VA_ARGS__)
//}}}
using PII = pair<int, int>;
using LL = long long;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 300005;
array<array<array<double, 301>, 301>, 301> dp = {};
struct Solution {
int N;
double dfs(int i, int j, int k) {
if (dp[i][j][k] > -0.5) {
return dp[i][j][k];
}
double y = 0.0;
if (i > 0) {
y += double(i) / N * dfs(i - 1, j, k);
}
if (j > 0) {
y += double(j) / N * dfs(i + 1, j - 1, k);
}
if (k > 0) {
y += double(k) / N * dfs(i, j + 1, k - 1);
}
double a = 1.0 - double(N - i - j - k) / N;
double x = (1.0 + y) / a;
dp[i][j][k] = x;
return x;
}
Solution(int) {
read(N);
array<int, 4> cnt;
for (repeat(N)) {
int a;
read(a);
cnt[a] += 1;
}
for (int i : range(N + 1)) {
for (int j : range(N + 1)) {
for (int k : range(N + 1)) {
dp[i][j][k] = -1.0;
}
}
}
dp[0][0][0] = 0.0;
print(dfs(cnt[1], cnt[2], cnt[3]));
}
};
int main() {
int T = 1;
// cin >> T;
for (int i = 1; i <= T; ++i) {
ignore = Solution(i);
}
return 0;
}
| //{{{
#include <bits/stdc++.h>
using namespace std;
#define putchar(x) cout << (x)
#define repeat(x) \
int _ = 0; \
_ < (x); \
++_
template <typename T> constexpr auto range(T start, T stop, T step) {
struct iterator {
T i, step;
bool operator!=(const iterator &other) const { return i != other.i; }
auto &operator++() {
i += step;
return *this;
}
auto &operator*() { return i; }
};
struct iterable_wrapper {
T start, stop, step;
auto begin() const { return iterator{start, step}; }
auto end() const { return iterator{stop, step}; }
size_t size() const { return (stop - start) / step; }
iterable_wrapper(T start_, T stop_, T step_)
: start(start_), stop(stop_), step(step_) {
stop = step > 0 ? max(start, stop) : min(start, stop);
stop += (step - (stop - start) % step) % step;
}
};
return iterable_wrapper(start, stop, step);
};
template <typename T> constexpr auto range(T start, T stop) {
return range(start, stop, T(1));
}
template <typename T> constexpr auto range(T stop) {
return range(T(0), stop, T(1));
}
template <typename T, typename Iter = decltype(begin(declval<T>()))>
constexpr auto printer(T &&iterable) {
struct iterator {
Iter iter, ed;
auto operator!=(const iterator &other) const {
auto ret = (iter != other.iter);
if (not ret)
cout << '\n';
return ret;
}
auto &operator++() {
++iter;
if (iter != ed)
cout << ' ';
return *this;
}
auto &operator*() { return *iter; }
};
struct iterable_wrapper {
T iterable;
auto begin() const {
return iterator{std::begin(iterable), std::end(iterable)};
}
auto end() const {
return iterator{std::end(iterable), std::end(iterable)};
}
};
return iterable_wrapper{forward<T>(iterable)};
};
template <size_t... Is, typename T> auto getis(const T &t) {
return tie(get<Is>(t)...);
}
template <class T> void setmax(T &a, const T &b) { a = max(a, b); }
template <class T> void setmin(T &a, const T &b) { a = min(a, b); }
template <typename T> struct is_const_char_arr_ref : false_type {};
template <size_t N>
struct is_const_char_arr_ref<char const (&)[N]> : true_type {};
template <typename T, typename = void> struct is_container : false_type {};
template <typename T>
struct is_container<T,
conditional_t<false, decltype(begin(declval<T>())), void>>
: true_type {};
template <class T>
using IsC = typename enable_if<is_container<T>::value and
not is_same<T, string>::value>::type;
template <class T>
using NotC = typename enable_if<not is_container<T>::value or
is_same<T, string>::value>::type;
template <class T> inline IsC<T> print_1(const T &v);
template <class T> inline NotC<T> print_1(const T &x) { cout << x; }
template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; };
inline void print_1(const tuple<> &) { cout << "()"; };
template <size_t L, size_t I, class T> void print_tuple(const T &t) {
if (I != 0)
cout << ", ";
print_1(get<I>(t));
if (I + 1 < L)
print_tuple<L, (I + 1) % L>(t);
}
template <class... T> inline void print_1(const tuple<T...> &x) {
cout << "(";
print_tuple<sizeof...(T), 0, tuple<T...>>(x);
cout << ")";
}
inline void print_n() {}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail);
template <class T, class U> inline void print_1(const pair<T, U> &p) {
cout << "(";
print_1(p.first);
cout << ", ";
print_1(p.second);
cout << ")";
}
template <class T, class... U>
inline void print_n(const T &head, const U &...tail) {
print_1(head);
if (sizeof...(tail))
cout << " ";
print_n(tail...);
}
template <class T> inline IsC<T> print_1(const T &v) {
cout << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
cout << ", ";
print_1(*it);
}
cout << "]";
}
template <class... T> inline void print(const T &...args) {
print_n(args...);
putchar('\n');
}
inline void read() {}
template <class T, class... U> inline void read(T &head, U &...tail) {
cin >> head;
read(tail...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static int fastio = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(17);
return 0;
}();
template <class T> void print_dbg(const string &s, T &&x) {
if (is_const_char_arr_ref<T>::value) {
print_n(x);
} else {
print_n(s, "=", x);
}
}
#define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define dbg1(a) \
print_dbg(#a, a); \
cout << endl;
#define dbg2(a, b) \
print_dbg(#a, a); \
cout << ", "; \
dbg1(b);
#define dbg3(a, b, c) \
print_dbg(#a, a); \
cout << ", "; \
dbg2(b, c);
#define dbg4(a, b, c, d) \
print_dbg(#a, a); \
cout << ", "; \
dbg3(b, c, d);
#define dbg5(a, b, c, d, e) \
print_dbg(#a, a); \
cout << ", "; \
dbg4(b, c, d, e);
#define dbg6(a, b, c, d, e, f) \
print_dbg(#a, a); \
cout << ", "; \
dbg5(b, c, d, e, f);
#define dbg7(a, b, c, d, e, f, g) \
print_dbg(#a, a); \
cout << ", "; \
dbg6(b, c, d, e, f, g);
#define dbg8(a, b, c, d, e, f, g, h) \
print_dbg(#a, a); \
cout << ", "; \
dbg7(b, c, d, e, f, g, h);
#define debug(...) \
SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1) \
(__VA_ARGS__)
//}}}
using PII = pair<int, int>;
using LL = long long;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 300005;
array<array<array<double, 301>, 301>, 301> dp = {};
struct Solution {
int N;
double dfs(int i, int j, int k) {
if (dp[i][j][k] > -0.5) {
return dp[i][j][k];
}
double y = 0.0;
if (i > 0) {
y += double(i) / N * dfs(i - 1, j, k);
}
if (j > 0) {
y += double(j) / N * dfs(i + 1, j - 1, k);
}
if (k > 0) {
y += double(k) / N * dfs(i, j + 1, k - 1);
}
double a = 1.0 - double(N - i - j - k) / N;
double x = (1.0 + y) / a;
dp[i][j][k] = x;
return x;
}
Solution(int) {
read(N);
array<int, 4> cnt = {};
for (repeat(N)) {
int a;
read(a);
cnt[a] += 1;
}
for (int i : range(N + 1)) {
for (int j : range(N + 1)) {
for (int k : range(N + 1)) {
dp[i][j][k] = -1.0;
}
}
}
dp[0][0][0] = 0.0;
print(dfs(cnt[1], cnt[2], cnt[3]));
}
};
int main() {
int T = 1;
// cin >> T;
for (int i = 1; i <= T; ++i) {
ignore = Solution(i);
}
return 0;
}
| replace | 230 | 231 | 230 | 231 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i = k; i < (ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;
}
ll n;
V<V<V<double>>> dp(300, V<V<double>>(300, V<double>(300, 0.0)));
V<V<V<bool>>> flag(300, V<V<bool>>(300, V<bool>(300, false)));
double f(ll c1, ll c2, ll c3) {
if (flag.at(c1).at(c2).at(c3))
return dp.at(c1).at(c2).at(c3);
flag.at(c1).at(c2).at(c3) = true;
double ans = 1 / (1 - (double)(n - c1 - c2 - c3) / n);
if (c1 > 0)
ans += f(c1 - 1, c2, c3) * (c1 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
if (c2 > 0)
ans += f(c1 + 1, c2 - 1, c3) * (c2 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
if (c3 > 0)
ans += f(c1, c2 + 1, c3 - 1) * (c3 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
return dp.at(c1).at(c2).at(c3) = ans;
}
int main() {
flag.at(0).at(0).at(0) = true;
cin >> n;
vll a(n);
REP(i, n) cin >> a.at(i);
vll c(3, 0);
REP(i, n) c.at(a.at(i) - 1)++;
cout << fixed << setprecision(12) << f(c.at(0), c.at(1), c.at(2)) << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i = k; i < (ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;
}
ll n;
V<V<V<double>>> dp(305, V<V<double>>(305, V<double>(305, 0.0)));
V<V<V<bool>>> flag(305, V<V<bool>>(305, V<bool>(305, false)));
double f(ll c1, ll c2, ll c3) {
if (flag.at(c1).at(c2).at(c3))
return dp.at(c1).at(c2).at(c3);
flag.at(c1).at(c2).at(c3) = true;
double ans = 1 / (1 - (double)(n - c1 - c2 - c3) / n);
if (c1 > 0)
ans += f(c1 - 1, c2, c3) * (c1 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
if (c2 > 0)
ans += f(c1 + 1, c2 - 1, c3) * (c2 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
if (c3 > 0)
ans += f(c1, c2 + 1, c3 - 1) * (c3 / (double)n) /
(1 - (double)(n - c1 - c2 - c3) / n);
return dp.at(c1).at(c2).at(c3) = ans;
}
int main() {
flag.at(0).at(0).at(0) = true;
cin >> n;
vll a(n);
REP(i, n) cin >> a.at(i);
vll c(3, 0);
REP(i, n) c.at(a.at(i) - 1)++;
cout << fixed << setprecision(12) << f(c.at(0), c.at(1), c.at(2)) << endl;
return 0;
}
| replace | 39 | 41 | 39 | 41 | -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 ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll, ll>
#define fill_nums(A, n) \
for (ll i = 0; i < n; i++) \
scanf("%lld", &A[i]);
#define fill_edges(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
adj[b - 1].pb(a - 1); \
}
#define fill_direct(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
}
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
vector<vector<vector<double>>>
dp(301, vector<vector<double>>(301, vector<double>(301, 0)));
int main() {
ll n, c1 = 0, c2 = 0, c3 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a == 1)
c1++;
else if (a == 2)
c2++;
else if (a == 3)
c3++;
}
for (int i = 0; i <= c3; i++) {
for (int j = 0; j <= c2 + c3; j++) {
for (int k = 0; k <= c1 + c2 + c3; k++) {
if (i == 0 && k == 0 && j == 0)
continue;
double a = (k > 0) ? k * dp[i][j][k - 1] : 0;
double b = (j > 0) ? j * dp[i][j - 1][k + 1] : 0;
double c = (i > 0) ? i * dp[i - 1][j + 1][k] : 0;
dp[i][j][k] = (a + b + c + n) / (i + j + k);
}
}
}
cout << fixed << setprecision(10);
cout << dp[c3][c2][c1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll, ll>
#define fill_nums(A, n) \
for (ll i = 0; i < n; i++) \
scanf("%lld", &A[i]);
#define fill_edges(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
adj[b - 1].pb(a - 1); \
}
#define fill_direct(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
}
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
vector<vector<vector<double>>>
dp(303, vector<vector<double>>(303, vector<double>(303, 0)));
int main() {
ll n, c1 = 0, c2 = 0, c3 = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a == 1)
c1++;
else if (a == 2)
c2++;
else if (a == 3)
c3++;
}
for (int i = 0; i <= c3; i++) {
for (int j = 0; j <= c2 + c3; j++) {
for (int k = 0; k <= c1 + c2 + c3; k++) {
if (i == 0 && k == 0 && j == 0)
continue;
double a = (k > 0) ? k * dp[i][j][k - 1] : 0;
double b = (j > 0) ? j * dp[i][j - 1][k + 1] : 0;
double c = (i > 0) ? i * dp[i - 1][j + 1][k] : 0;
dp[i][j][k] = (a + b + c + n) / (i + j + k);
}
}
}
cout << fixed << setprecision(10);
cout << dp[c3][c2][c1] << endl;
return 0;
}
| replace | 42 | 43 | 42 | 43 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03169 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a[310], num[4] = {0};
cin >> n;
REP(i, n) {
cin >> a[i];
num[a[i]]++;
}
double dp[30][30][30];
memset(dp, 0, sizeof(dp));
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if ((i + j + k) && i + j + k <= n) {
if (i)
dp[i][j][k] += dp[i - 1][j][k] * i / n;
if (j)
dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
if (k)
dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] += 1;
dp[i][j][k] /= 1.0 * (i + j + k) / n;
}
}
}
}
cout << setprecision(20) << dp[num[1]][num[2]][num[3]] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a[310], num[4] = {0};
cin >> n;
REP(i, n) {
cin >> a[i];
num[a[i]]++;
}
double dp[301][301][301];
memset(dp, 0, sizeof(dp));
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if ((i + j + k) && i + j + k <= n) {
if (i)
dp[i][j][k] += dp[i - 1][j][k] * i / n;
if (j)
dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
if (k)
dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] += 1;
dp[i][j][k] /= 1.0 * (i + j + k) / n;
}
}
}
}
cout << setprecision(20) << dp[num[1]][num[2]][num[3]] << endl;
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p03169 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
double dp[305][305][305];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int x = 0, y = 0, z = 0;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
if (a == 1)
x++;
if (a == 2)
y++;
if (a == 3)
z++;
}
int MX = max(x, max(y * 2, z * 3));
dp[0][0][0] = 0.0;
for (int k = 0; k <= MX; k++) {
for (int j = 0; j <= MX; j++) {
for (int i = 0; i <= MX; i++) {
int T = i + j + k;
if (T == 0)
continue;
dp[i][j][k] = (1.0 * N / T);
double r1 = 0.0;
if (i > 0)
r1 = (1.0 * i / T) * dp[i - 1][j][k];
double r2 = 0.0;
if (j > 0)
r2 = (1.0 * j / T) * dp[i + 1][j - 1][k];
double r3 = 0.0;
if (k > 0)
r3 = (1.0 * k / T) * dp[i][j + 1][k - 1];
dp[i][j][k] += (r1 + r2 + r3);
}
}
}
cout << setprecision(9) << fixed << dp[x][y][z] << "\n";
}
| #include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
double dp[305][305][305];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int x = 0, y = 0, z = 0;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
if (a == 1)
x++;
if (a == 2)
y++;
if (a == 3)
z++;
}
int MX = x + y + z + 2;
dp[0][0][0] = 0.0;
for (int k = 0; k <= MX; k++) {
for (int j = 0; j <= MX; j++) {
for (int i = 0; i <= MX; i++) {
int T = i + j + k;
if (T == 0)
continue;
dp[i][j][k] = (1.0 * N / T);
double r1 = 0.0;
if (i > 0)
r1 = (1.0 * i / T) * dp[i - 1][j][k];
double r2 = 0.0;
if (j > 0)
r2 = (1.0 * j / T) * dp[i + 1][j - 1][k];
double r3 = 0.0;
if (k > 0)
r3 = (1.0 * k / T) * dp[i][j + 1][k - 1];
dp[i][j][k] += (r1 + r2 + r3);
}
}
}
cout << setprecision(9) << fixed << dp[x][y][z] << "\n";
}
| replace | 26 | 27 | 26 | 27 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
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;
}
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n;
// cout << "here" << endl;
cin >> n;
vec<vec<vec<double>>> dp(302, vvec<double>(32, vec<double>(302, 0)));
int num[3] = {0, 0, 0};
rep(i, n) {
int a;
cin >> a;
num[a - 1]++;
}
// cout << "here" << endl;
rep(k, n + 1) rep(j, n + 1) rep(i, n + 1) {
double d = 0.0;
// cout << "here1" << endl;
if (i == 0 && j == 0 && k == 0)
continue;
if (i > 0)
d += i * dp[i - 1][j][k];
if (j > 0)
d += j * dp[i + 1][j - 1][k];
if (k > 0)
d += k * dp[i][j + 1][k - 1];
dp[i][j][k] = (d + n) / (1.0 * (i + j + k));
}
cout << setprecision(10) << dp[num[0]][num[1]][num[2]] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
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;
}
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n;
// cout << "here" << endl;
cin >> n;
vec<vec<vec<double>>> dp(302, vvec<double>(302, vec<double>(302, 0)));
int num[3] = {0, 0, 0};
rep(i, n) {
int a;
cin >> a;
num[a - 1]++;
}
// cout << "here" << endl;
rep(k, n + 1) rep(j, n + 1) rep(i, n + 1) {
double d = 0.0;
// cout << "here1" << endl;
if (i == 0 && j == 0 && k == 0)
continue;
if (i > 0)
d += i * dp[i - 1][j][k];
if (j > 0)
d += j * dp[i + 1][j - 1][k];
if (k > 0)
d += k * dp[i][j + 1][k - 1];
dp[i][j][k] = (d + n) / (1.0 * (i + j + k));
}
cout << setprecision(10) << dp[num[0]][num[1]][num[2]] << endl;
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 62);
const ld pi = acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
#define endn "\n"
#define TO_STRING(VariableName) #VariableName
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
rep(i, (int)v.size() - 1) cout << v[i] << " ";
cout << v[(int)v.size() - 1];
return out;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const map<T1, T2> &p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <class T> void debag(const T &obj) { cout << obj << endl; }
bool solve() {
ll n;
cin >> n;
ll A = 0;
ll B = 0;
ll C = 0;
rep(i, n) {
ll a;
cin >> a;
if (a == 1)
A++;
if (a == 2)
B++;
if (a == 3)
C++;
}
ld dp[n + 1][n + 1][n + 1];
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) dp[i][j][k] = 0;
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) {
dp[i][j][k] = 0;
if (i + j + k == 0)
continue;
if (i > 0)
dp[i][j][k] += dp[i - 1][j + 1][k] * (ld)((ld)i / (ld)(i + j + k));
if (j > 0)
dp[i][j][k] += dp[i][j - 1][k + 1] * (ld)((ld)j / (ld)(i + j + k));
if (k > 0)
dp[i][j][k] += dp[i][j][k - 1] * (ld)((ld)k / (ld)(i + j + k));
// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
dp[i][j][k] += (ld)n / (ld)(i + j + k);
}
cout << dp[C][B][A] << endl;
return false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(30);
solve();
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 62);
const ld pi = acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
#define endn "\n"
#define TO_STRING(VariableName) #VariableName
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
rep(i, (int)v.size() - 1) cout << v[i] << " ";
cout << v[(int)v.size() - 1];
return out;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const map<T1, T2> &p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <class T> void debag(const T &obj) { cout << obj << endl; }
bool solve() {
ll n;
cin >> n;
ll A = 0;
ll B = 0;
ll C = 0;
rep(i, n) {
ll a;
cin >> a;
if (a == 1)
A++;
if (a == 2)
B++;
if (a == 3)
C++;
}
vector<vector<vector<ld>>> dp(
n + 2, vector<vector<ld>>(n + 2, vector<ld>(n + 2, 0)));
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) dp[i][j][k] = 0;
rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) {
dp[i][j][k] = 0;
if (i + j + k == 0)
continue;
if (i > 0)
dp[i][j][k] += dp[i - 1][j + 1][k] * (ld)((ld)i / (ld)(i + j + k));
if (j > 0)
dp[i][j][k] += dp[i][j - 1][k + 1] * (ld)((ld)j / (ld)(i + j + k));
if (k > 0)
dp[i][j][k] += dp[i][j][k - 1] * (ld)((ld)k / (ld)(i + j + k));
// cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
dp[i][j][k] += (ld)n / (ld)(i + j + k);
}
cout << dp[C][B][A] << endl;
return false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(30);
solve();
}
| replace | 66 | 67 | 66 | 68 | 0 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define MAXN 105
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;
int n, sum, a[MAXN], num[4];
LD f[MAXN][MAXN][MAXN];
int main() {
scanf("%d", &n);
for (rint i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
num[a[i]]++;
sum += a[i];
}
for (rint x = 1; x <= sum; ++x) {
for (rint i = 0; i <= x / 3; ++i) {
for (rint j = 0; j <= (x - i * 3) / 2; ++j) {
int k = x - i * 3 - j * 2;
if (i + j + k > n)
continue;
// printf("%d %d %d!!!\n", i, j, k);
f[i][j][k] = n;
if (i > 0)
f[i][j][k] += i * f[i - 1][j + 1][k];
if (j > 0)
f[i][j][k] += j * f[i][j - 1][k + 1];
if (k > 0)
f[i][j][k] += k * f[i][j][k - 1];
f[i][j][k] /= (i + j + k);
// printf("%d %d %d %Lf!!!\n", i, j, k, f[i][j][k]);
}
}
}
printf("%.10Lf\n", f[num[3]][num[2]][num[1]]);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define MAXN 305
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;
int n, sum, a[MAXN], num[4];
LD f[MAXN][MAXN][MAXN];
int main() {
scanf("%d", &n);
for (rint i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
num[a[i]]++;
sum += a[i];
}
for (rint x = 1; x <= sum; ++x) {
for (rint i = 0; i <= x / 3; ++i) {
for (rint j = 0; j <= (x - i * 3) / 2; ++j) {
int k = x - i * 3 - j * 2;
if (i + j + k > n)
continue;
// printf("%d %d %d!!!\n", i, j, k);
f[i][j][k] = n;
if (i > 0)
f[i][j][k] += i * f[i - 1][j + 1][k];
if (j > 0)
f[i][j][k] += j * f[i][j - 1][k + 1];
if (k > 0)
f[i][j][k] += k * f[i][j][k - 1];
f[i][j][k] /= (i + j + k);
// printf("%d %d %d %Lf!!!\n", i, j, k, f[i][j][k]);
}
}
}
printf("%.10Lf\n", f[num[3]][num[2]][num[1]]);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n, num[3] = {0};
ld dp[301][301][301] = {0};
void solve() {
cin >> n;
rep(i, n) {
int a;
cin >> a;
num[a - 1] += 1;
}
// cout << num[0] << " " << num[1] << " " << num[2] << endl;
rep(a3, n + 1) {
rep(a2, n + 1) {
rep(a1, n + 1) {
if (a1 == 0 && a2 == 0 && a3 == 0)
continue;
dp[a1][a2][a3] = (ld)n / (a1 + a2 + a3);
if (a1 >= 1)
dp[a1][a2][a3] += ((ld)a1 / (a1 + a2 + a3)) * dp[a1 - 1][a2][a3];
if (a2 >= 1)
dp[a1][a2][a3] += ((ld)a2 / (a1 + a2 + a3)) * dp[a1 + 1][a2 - 1][a3];
if (a3 >= 1)
dp[a1][a2][a3] += ((ld)a3 / (a1 + a2 + a3)) * dp[a1][a2 + 1][a3 - 1];
// cout << a1 << " " << a2 << " " << a3 << " " << dp[a1][a2][a3] <<
// endl;
}
}
}
cout << dp[num[0]][num[1]][num[2]] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
solve();
} | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n, num[3] = {0};
ld dp[400][400][400] = {0};
void solve() {
cin >> n;
rep(i, n) {
int a;
cin >> a;
num[a - 1] += 1;
}
// cout << num[0] << " " << num[1] << " " << num[2] << endl;
rep(a3, n + 1) {
rep(a2, n + 1) {
rep(a1, n + 1) {
if (a1 == 0 && a2 == 0 && a3 == 0)
continue;
dp[a1][a2][a3] = (ld)n / (a1 + a2 + a3);
if (a1 >= 1)
dp[a1][a2][a3] += ((ld)a1 / (a1 + a2 + a3)) * dp[a1 - 1][a2][a3];
if (a2 >= 1)
dp[a1][a2][a3] += ((ld)a2 / (a1 + a2 + a3)) * dp[a1 + 1][a2 - 1][a3];
if (a3 >= 1)
dp[a1][a2][a3] += ((ld)a3 / (a1 + a2 + a3)) * dp[a1][a2 + 1][a3 - 1];
// cout << a1 << " " << a2 << " " << a3 << " " << dp[a1][a2][a3] <<
// endl;
}
}
}
cout << dp[num[0]][num[1]][num[2]] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
solve();
} | replace | 40 | 41 | 40 | 41 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll, ll> P;
typedef pair<int, int> pii;
typedef vector<P> vpl;
typedef tuple<ll, ll, ll> tapu;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int MAX = 510000;
ll dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
ll dx[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
template <typename T> inline void print(T &a) {
rep(i, a.size()) cout << a[i] << " ";
cout << "\n";
}
template <typename T1, typename T2> inline void print2(T1 a, T2 b) {
cout << a << " " << b << "\n";
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
// const int mod = 998244353;
double dp[103][103][103];
vl cnt(3);
ll n;
double rec(ll x, ll y, ll z) {
if (dp[x][y][z] != -1)
return dp[x][y][z];
dp[x][y][z] = 0.0;
double num = 1.0 * n / (double)x;
if (x != y) {
dp[x][y][z] += (rec(x - 1, y, z) + num) * (x - y) / (double)x;
}
if (y != z) {
dp[x][y][z] += (rec(x, y - 1, z) + num) * (y - z) / (double)x;
}
if (z > 0) {
dp[x][y][z] += (rec(x, y, z - 1) + num) * z / (double)x;
}
return dp[x][y][z];
}
int main() {
cin >> n;
vl a(n);
rep(i, n) cin >> a[i], a[i]--;
rep(i, n) cnt[a[i]]++;
cnt[1] += cnt[2];
cnt[0] += cnt[1];
rep(i, cnt[0] + 1) rep(j, cnt[1] + 1) rep(k, cnt[2] + 1) dp[i][j][k] = -1;
dp[0][0][0] = 0;
printf("%.10f\n", rec(cnt[0], cnt[1], cnt[2]));
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll, ll> P;
typedef pair<int, int> pii;
typedef vector<P> vpl;
typedef tuple<ll, ll, ll> tapu;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1 << 30;
const ll linf = 1LL << 62;
const int MAX = 510000;
ll dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
ll dx[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
template <typename T> inline void print(T &a) {
rep(i, a.size()) cout << a[i] << " ";
cout << "\n";
}
template <typename T1, typename T2> inline void print2(T1 a, T2 b) {
cout << a << " " << b << "\n";
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
// const int mod = 998244353;
double dp[303][303][303];
vl cnt(3);
ll n;
double rec(ll x, ll y, ll z) {
if (dp[x][y][z] != -1)
return dp[x][y][z];
dp[x][y][z] = 0.0;
double num = 1.0 * n / (double)x;
if (x != y) {
dp[x][y][z] += (rec(x - 1, y, z) + num) * (x - y) / (double)x;
}
if (y != z) {
dp[x][y][z] += (rec(x, y - 1, z) + num) * (y - z) / (double)x;
}
if (z > 0) {
dp[x][y][z] += (rec(x, y, z - 1) + num) * z / (double)x;
}
return dp[x][y][z];
}
int main() {
cin >> n;
vl a(n);
rep(i, n) cin >> a[i], a[i]--;
rep(i, n) cnt[a[i]]++;
cnt[1] += cnt[2];
cnt[0] += cnt[1];
rep(i, cnt[0] + 1) rep(j, cnt[1] + 1) rep(k, cnt[2] + 1) dp[i][j][k] = -1;
dp[0][0][0] = 0;
printf("%.10f\n", rec(cnt[0], cnt[1], cnt[2]));
} | replace | 66 | 67 | 66 | 67 | 0 | |
p03169 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long
#define mod 1000000007
double dp[301][301][301];
double solve_ite(int *a, int n, int one, int two, int three) {
for (int i = 0; i <= three; i++) {
for (int j = 0; j <= two + 3 * three / 2 + 1; j++) {
for (int k = 0; k <= one + 2 * two + 3 * three + 2; k++) {
if (i != 0 or j != 0 or k != 0) {
dp[i][j][k] = n / (double)(i + j + k);
}
if (k > 0) {
dp[i][j][k] += k / (double)(i + j + k) * dp[i][j][k - 1];
}
if (j > 0) {
dp[i][j][k] += j / (double)(i + j + k) * dp[i][j - 1][k + 1];
}
if (i > 0) {
dp[i][j][k] += i / (double)(i + j + k) * dp[i - 1][j + 1][k];
}
}
}
}
return dp[three][two][one];
}
int main() {
int n;
cin >> n;
int a[n];
int one = 0, two = 0, three = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == 1)
one++;
if (a[i] == 2)
two++;
if (a[i] == 3)
three++;
}
for (int i = 0; i < 301; ++i)
for (int j = 0; j < 301; ++j)
for (int k = 0; k < 301; ++k)
dp[i][j][k] = 0;
cout << setprecision(14) << solve_ite(a, n, one, two, three);
return 0;
} | #include <algorithm>
#include <climits>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long
#define mod 1000000007
double dp[301][301][301];
double solve_ite(int *a, int n, int one, int two, int three) {
for (int i = 0; i <= three; i++) {
for (int j = 0; j <= two + three; j++) {
for (int k = 0; k <= one + two + three; k++) {
if (i != 0 or j != 0 or k != 0) {
dp[i][j][k] = n / (double)(i + j + k);
}
if (k > 0) {
dp[i][j][k] += k / (double)(i + j + k) * dp[i][j][k - 1];
}
if (j > 0) {
dp[i][j][k] += j / (double)(i + j + k) * dp[i][j - 1][k + 1];
}
if (i > 0) {
dp[i][j][k] += i / (double)(i + j + k) * dp[i - 1][j + 1][k];
}
}
}
}
return dp[three][two][one];
}
int main() {
int n;
cin >> n;
int a[n];
int one = 0, two = 0, three = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == 1)
one++;
if (a[i] == 2)
two++;
if (a[i] == 3)
three++;
}
for (int i = 0; i < 301; ++i)
for (int j = 0; j < 301; ++j)
for (int k = 0; k < 301; ++k)
dp[i][j][k] = 0;
cout << setprecision(14) << solve_ite(a, n, one, two, three);
return 0;
} | replace | 20 | 22 | 20 | 22 | TLE | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<vector<vector<ld>>> dp(
n + 1, vector<vector<ld>>(n + 1, vector<ld>(n + 1, 0)));
vector<ld> weight(n + 1, 0);
for (int i = 0; i <= n; i++) {
ld x = 1;
for (int j = 0; j <= 100000; j++) {
weight[i] += (j + 1) * x;
x = x * i / n;
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
if (i + j + k > n)
continue;
ld x = n - (i + j + k);
if (i > 0) {
dp[i][j][k] += dp[i - 1][j + 1][k] * i / (n - x) + weight[x] * i / n;
}
if (j > 0) {
dp[i][j][k] += dp[i][j - 1][k + 1] * j / (n - x) + weight[x] * j / n;
}
if (k > 0) {
dp[i][j][k] += dp[i][j][k - 1] * k / (n - x) + weight[x] * k / n;
}
}
}
}
int k = count(a.begin(), a.end(), 1);
int j = count(a.begin(), a.end(), 2);
int i = count(a.begin(), a.end(), 3);
cout << fixed << setprecision(10);
cout << dp[i][j][k] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<vector<vector<ld>>> dp(
n + 1, vector<vector<ld>>(n + 1, vector<ld>(n + 1, 0)));
vector<ld> weight(n + 1, 0);
for (int i = 0; i <= n; i++) {
ld x = 1;
for (int j = 0; j <= 10000; j++) {
weight[i] += (j + 1) * x;
x = x * i / n;
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
if (i + j + k > n)
continue;
ld x = n - (i + j + k);
if (i > 0) {
dp[i][j][k] += dp[i - 1][j + 1][k] * i / (n - x) + weight[x] * i / n;
}
if (j > 0) {
dp[i][j][k] += dp[i][j - 1][k + 1] * j / (n - x) + weight[x] * j / n;
}
if (k > 0) {
dp[i][j][k] += dp[i][j][k - 1] * k / (n - x) + weight[x] * k / n;
}
}
}
}
int k = count(a.begin(), a.end(), 1);
int j = count(a.begin(), a.end(), 2);
int i = count(a.begin(), a.end(), 3);
cout << fixed << setprecision(10);
cout << dp[i][j][k] << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | TLE | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
double dp[305][305][305];
bool check[305][305][305];
double n;
double calc(ll a, ll b, ll c) {
if (check[a][b][c] == true) {
// cout<<"true"<<endl;
return dp[a][b][c];
}
double p0 = double((n - a - b - c) / n);
double p1 = double(a / n);
double p2 = double(b / n);
double p3 = double(c / n);
double now = 1;
// cout<<n<<"n"<<(n-a-b-c)<<"a"<<endl;
if (a > 0)
now += p1 * calc(a - 1, b, c);
if (b > 0)
now += p2 * calc(a + 1, b - 1, c);
if (c > 0)
now += p3 * calc(a, b + 1, c - 1);
// cout<<now<<"now"<<p0<<"p0"<<endl;
dp[a][b][c] = double(now / (1 - p0));
check[a][b][c] == true;
// cout<<dp[a][b][c]<<"a"<<a<<"b"<<b<<"c"<<c<<endl;
return dp[a][b][c];
}
int main() {
cin >> n;
vector<ll> a(n);
vector<ll> c(3, 0);
rep(i, n) {
cin >> a[i];
if (a[i] == 1)
c[0]++;
if (a[i] == 2)
c[1]++;
if (a[i] == 3)
c[2]++;
}
// dp[0][0][0]=0;
rep(i, 305) rep(j, 305) rep(k, 305) {
dp[i][j][k] = 0;
check[i][j][k] = false;
}
check[0][0][0] = true;
rep(i, c[0] + 1) rep(j, c[1] + 1) rep(k, c[2] + 1) {
dp[i][j][k] = calc(i, j, k);
check[i][j][k] = true;
}
// cout<<c[0]<<endl;
cout << setprecision(10) << dp[c[0]][c[1]][c[2]];
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
double dp[305][305][305];
bool check[305][305][305];
double n;
double calc(ll a, ll b, ll c) {
if (check[a][b][c] == true) {
// cout<<"true"<<endl;
return dp[a][b][c];
}
double p0 = double((n - a - b - c) / n);
double p1 = double(a / n);
double p2 = double(b / n);
double p3 = double(c / n);
double now = 1;
// cout<<n<<"n"<<(n-a-b-c)<<"a"<<endl;
if (a > 0)
now += p1 * calc(a - 1, b, c);
if (b > 0)
now += p2 * calc(a + 1, b - 1, c);
if (c > 0)
now += p3 * calc(a, b + 1, c - 1);
// cout<<now<<"now"<<p0<<"p0"<<endl;
dp[a][b][c] = double(now / (1 - p0));
check[a][b][c] = true;
// cout<<dp[a][b][c]<<"a"<<a<<"b"<<b<<"c"<<c<<endl;
return dp[a][b][c];
}
int main() {
cin >> n;
vector<ll> a(n);
vector<ll> c(3, 0);
rep(i, n) {
cin >> a[i];
if (a[i] == 1)
c[0]++;
if (a[i] == 2)
c[1]++;
if (a[i] == 3)
c[2]++;
}
// dp[0][0][0]=0;
rep(i, 305) rep(j, 305) rep(k, 305) {
dp[i][j][k] = 0;
check[i][j][k] = false;
}
check[0][0][0] = true;
rep(i, c[0] + 1) rep(j, c[1] + 1) rep(k, c[2] + 1) {
dp[i][j][k] = calc(i, j, k);
check[i][j][k] = true;
}
// cout<<c[0]<<endl;
cout << setprecision(10) << dp[c[0]][c[1]][c[2]];
}
| replace | 31 | 32 | 31 | 32 | TLE | |
p03169 | C++ | Runtime Error | /*
* author: Gary Shih
* created: 2020-05-04 13:27:07
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
int n;
cin >> n;
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (a == 1)
++c1;
if (a == 2)
++c2;
if (a == 3)
++c3;
}
int maxSushi = 900;
vector<vector<vector<double>>> dp(
maxSushi + 1, vector<vector<double>>(maxSushi / 2 + 1,
vector<double>(maxSushi / 3 + 1)));
for (int total = 1; total <= c1 + 2 * c2 + 3 * c3; ++total) {
for (int i = 0; i <= total; ++i)
for (int j = 0; j <= (total - i); ++j) {
if ((total - i - 2 * j) % 3 != 0)
continue;
int k = (total - i - 2 * j) / 3;
int rest = i + j + k;
double prev = 0.0;
if (i > 0)
prev += dp[i - 1][j][k] * i / n;
if (j > 0)
prev += dp[i + 1][j - 1][k] * j / n;
if (k > 0)
prev += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] = (prev + 1) * n / rest;
}
}
cout << dp[c1][c2][c3] << '\n';
}
| /*
* author: Gary Shih
* created: 2020-05-04 13:27:07
*/
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
int n;
cin >> n;
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (a == 1)
++c1;
if (a == 2)
++c2;
if (a == 3)
++c3;
}
int maxSushi = 900;
vector<vector<vector<double>>> dp(
maxSushi + 1, vector<vector<double>>(maxSushi / 2 + 1,
vector<double>(maxSushi / 3 + 1)));
for (int total = 1; total <= c1 + 2 * c2 + 3 * c3; ++total) {
for (int i = 0; i <= total; ++i)
for (int j = 0; j <= (total - i) / 2; ++j) {
if ((total - i - 2 * j) % 3 != 0)
continue;
int k = (total - i - 2 * j) / 3;
int rest = i + j + k;
double prev = 0.0;
if (i > 0)
prev += dp[i - 1][j][k] * i / n;
if (j > 0)
prev += dp[i + 1][j - 1][k] * j / n;
if (k > 0)
prev += dp[i][j + 1][k - 1] * k / n;
dp[i][j][k] = (prev + 1) * n / rest;
}
}
cout << dp[c1][c2][c3] << '\n';
}
| replace | 30 | 31 | 30 | 31 | -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;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const int MX = 307;
ld b[MX + 5][MX + 5][MX + 5];
int main() {
int n;
scanf("%d", &n);
int c[3];
for (int i = 0; i < n; i++) {
int l;
cin >> l;
if (l > 0)
c[l - 1] += 1;
}
b[0][0][0] = 0.0;
for (int k = 0; k < MX; k++) {
for (int j = 0; k + j < MX; j++) {
for (int i = 0; i + j + k < MX; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
b[i][j][k] += 1.0 * n / (i + j + k);
b[i + 1][j][k] += b[i][j][k] * 1.0 * (i + 1) / (i + 1 + j + k);
if (i)
b[i - 1][j + 1][k] += b[i][j][k] * 1.0 * (j + 1) / (i + j + k);
if (j)
b[i][j - 1][k + 1] += b[i][j][k] * 1.0 * (k + 1) / (i + j + k);
}
}
}
cout << fixed << setprecision(10) << b[c[0]][c[1]][c[2]];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const int MX = 307;
ld b[MX + 5][MX + 5][MX + 5];
int main() {
int n;
scanf("%d", &n);
int c[3] = {0, 0, 0};
for (int i = 0; i < n; i++) {
int l;
cin >> l;
if (l > 0)
c[l - 1] += 1;
}
b[0][0][0] = 0.0;
for (int k = 0; k < MX; k++) {
for (int j = 0; k + j < MX; j++) {
for (int i = 0; i + j + k < MX; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
b[i][j][k] += 1.0 * n / (i + j + k);
b[i + 1][j][k] += b[i][j][k] * 1.0 * (i + 1) / (i + 1 + j + k);
if (i)
b[i - 1][j + 1][k] += b[i][j][k] * 1.0 * (j + 1) / (i + j + k);
if (j)
b[i][j - 1][k + 1] += b[i][j][k] * 1.0 * (k + 1) / (i + j + k);
}
}
}
cout << fixed << setprecision(10) << b[c[0]][c[1]][c[2]];
return 0;
}
| replace | 15 | 16 | 15 | 16 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
double dp[301][301][301];
bool done[301][301][301];
int n, a;
int cnt[3];
double solve(int i, int j, int k) {
if (done[i][j][k])
return dp[i][j][k];
done[i][j][k] = true;
double &res = dp[i][j][k];
double p = 1. * (i + j + k) / n;
if (i) {
double p0 = 1. * i / n;
res += (solve(i - 1, j, k) + 1 / p) * i / (i + j + k);
}
if (j) {
double p0 = 1. * j / n;
res += (solve(i + 1, j - 1, k) + 1 / p) * j / (i + j + k);
}
if (k) {
double p0 = 1. * k / n;
res += (solve(i, j + 1, k - 1) + 1 / p) * k / (i + j + k);
}
// cout << i << " " << j <<" " << k <<" " << res << endl;
return res;
}
int main() {
done[0][0][0] = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
cnt[a]++;
}
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if (i + j + k > n)
continue;
}
}
}
printf("%.10lf\n", solve(cnt[1], cnt[2], cnt[3]));
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF (1 << 29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
double dp[301][301][301];
bool done[301][301][301];
int n, a;
int cnt[4];
double solve(int i, int j, int k) {
if (done[i][j][k])
return dp[i][j][k];
done[i][j][k] = true;
double &res = dp[i][j][k];
double p = 1. * (i + j + k) / n;
if (i) {
double p0 = 1. * i / n;
res += (solve(i - 1, j, k) + 1 / p) * i / (i + j + k);
}
if (j) {
double p0 = 1. * j / n;
res += (solve(i + 1, j - 1, k) + 1 / p) * j / (i + j + k);
}
if (k) {
double p0 = 1. * k / n;
res += (solve(i, j + 1, k - 1) + 1 / p) * k / (i + j + k);
}
// cout << i << " " << j <<" " << k <<" " << res << endl;
return res;
}
int main() {
done[0][0][0] = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
cnt[a]++;
}
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if (i + j + k > n)
continue;
}
}
}
printf("%.10lf\n", solve(cnt[1], cnt[2], cnt[3]));
return 0;
} | replace | 23 | 24 | 23 | 24 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef double ll;
int main() {
int n;
cin >> n;
int a1 = 0, a2 = 0, a3 = 0;
ll dp[n + 1][n + 1][n + 1];
for (int i = 0; i < n; ++i) {
ll x;
cin >> x;
if (x == 1)
a1++;
if (x == 2)
a2++;
if (x == 3)
a3++;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
dp[i][0][0] = (dp[i - 1][0][0] + 1) + (ll)((ll)(n - i) / i);
}
for (int j = 1; j <= n; ++j) {
for (int i = 0; i <= n; ++i) {
if (i > 0)
dp[i][j][0] = (n - i - j + (dp[i - 1][j][0] + 1) * (i) +
(dp[i + 1][j - 1][0] + 1) * (j)) /
((ll)(i + j));
else
dp[i][j][0] = (n - j + (dp[i + 1][j - 1][0] + 1) * (j)) / ((ll)j);
}
}
for (int k = 1; k <= n; ++k) {
for (int j = 0; j < n; ++j) {
for (int i = 0; i < n; ++i) {
if (i > 0 && j > 0)
dp[i][j][k] = (n - i - j - k + (dp[i - 1][j][k] + 1) * (i) +
(dp[i + 1][j - 1][k] + 1) * (j) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(i + k + j));
else if (i > 0)
dp[i][j][k] = (n - i - k + (dp[i - 1][j][k] + 1) * (i) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(i + k));
else if (j > 0)
dp[i][j][k] = (n - j - k + (dp[i + 1][j - 1][k] + 1) * (j) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(k + j));
else
dp[i][j][k] = (n - k + (dp[i][j + 1][k - 1] + 1) * (k)) / ((ll)(k));
}
}
}
printf("%0.15lf\n", dp[a1][a2][a3]);
}
| #include <bits/stdc++.h>
using namespace std;
typedef double ll;
int main() {
int n;
cin >> n;
int a1 = 0, a2 = 0, a3 = 0;
ll dp[n + 1][n + 1][n + 1];
for (int i = 0; i < n; ++i) {
ll x;
cin >> x;
if (x == 1)
a1++;
if (x == 2)
a2++;
if (x == 3)
a3++;
}
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
dp[i][0][0] = (dp[i - 1][0][0] + 1) + (ll)((ll)(n - i) / i);
}
for (int j = 1; j <= n; ++j) {
for (int i = 0; i < n; ++i) {
if (i > 0)
dp[i][j][0] = (n - i - j + (dp[i - 1][j][0] + 1) * (i) +
(dp[i + 1][j - 1][0] + 1) * (j)) /
((ll)(i + j));
else
dp[i][j][0] = (n - j + (dp[i + 1][j - 1][0] + 1) * (j)) / ((ll)j);
}
}
for (int k = 1; k <= n; ++k) {
for (int j = 0; j < n; ++j) {
for (int i = 0; i < n; ++i) {
if (i > 0 && j > 0)
dp[i][j][k] = (n - i - j - k + (dp[i - 1][j][k] + 1) * (i) +
(dp[i + 1][j - 1][k] + 1) * (j) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(i + k + j));
else if (i > 0)
dp[i][j][k] = (n - i - k + (dp[i - 1][j][k] + 1) * (i) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(i + k));
else if (j > 0)
dp[i][j][k] = (n - j - k + (dp[i + 1][j - 1][k] + 1) * (j) +
(dp[i][j + 1][k - 1] + 1) * (k)) /
((ll)(k + j));
else
dp[i][j][k] = (n - k + (dp[i][j + 1][k - 1] + 1) * (k)) / ((ll)(k));
}
}
}
printf("%0.15lf\n", dp[a1][a2][a3]);
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03169 | C++ | Time Limit Exceeded | #include <iomanip>
#include <iostream>
using namespace std;
int A, B, C;
int n;
double dp[301][301][301];
double foo(int A, int B, int C) {
if (dp[A][B][C] != -1)
return dp[A][B][C];
double nn = n;
double AA = A;
double BB = B;
double CC = C;
double res = 0;
if (A != 0) {
double E1 = (foo(A - 1, B, C) + 1.0) * AA / nn;
res += E1;
}
if (B != 0) {
double E1 = (foo(A + 1, B - 1, C) + 1.0) * BB / nn;
res += E1;
}
if (C != 0) {
double E1 = (foo(A, B + 1, C - 1) + 1.0) * CC / nn;
res += E1;
}
double kl = 1.0 - (AA + BB + CC) / nn;
res += kl;
res /= (1.0 - kl);
// dp[A][B][C] = res;
return res;
}
int main() {
A = 0;
B = 0;
C = 0;
for (int i = 0; i < 301; ++i) {
for (int j = 0; j < 301; ++j) {
for (int k = 0; k < 301; ++k) {
dp[i][j][k] = -1;
}
}
}
dp[0][0][0] = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (a == 1)
A++;
else if (a == 2)
B++;
else if (a == 3)
C++;
}
cout << fixed << setprecision(10) << foo(A, B, C);
return 0;
} | #include <iomanip>
#include <iostream>
using namespace std;
int A, B, C;
int n;
double dp[301][301][301];
double foo(int A, int B, int C) {
if (dp[A][B][C] != -1)
return dp[A][B][C];
double nn = n;
double AA = A;
double BB = B;
double CC = C;
double res = 0;
if (A != 0) {
double E1 = (foo(A - 1, B, C) + 1.0) * AA / nn;
res += E1;
}
if (B != 0) {
double E1 = (foo(A + 1, B - 1, C) + 1.0) * BB / nn;
res += E1;
}
if (C != 0) {
double E1 = (foo(A, B + 1, C - 1) + 1.0) * CC / nn;
res += E1;
}
double kl = 1.0 - (AA + BB + CC) / nn;
res += kl;
res /= (1.0 - kl);
dp[A][B][C] = res;
return res;
}
int main() {
A = 0;
B = 0;
C = 0;
for (int i = 0; i < 301; ++i) {
for (int j = 0; j < 301; ++j) {
for (int k = 0; k < 301; ++k) {
dp[i][j][k] = -1;
}
}
}
dp[0][0][0] = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (a == 1)
A++;
else if (a == 2)
B++;
else if (a == 3)
C++;
}
cout << fixed << setprecision(10) << foo(A, B, C);
return 0;
} | replace | 38 | 39 | 38 | 39 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 101
using namespace std;
int n, a, b, c, x;
double dp[N][N][N];
double f(int a, int b, int c) {
if (a == 0 && b == 0 && c == 0)
return 0;
if (a < 0 || b < 0 || c < 0)
return 0;
if (dp[a][b][c] != 0)
return dp[a][b][c];
double ea, eb, ec, ans;
ea = f(a - 1, b, c);
eb = f(a + 1, b - 1, c);
ec = f(a, b + 1, c - 1);
ans = (a * ea + b * eb + c * ec + n) / (a + b + c);
// printf("(%d %d %d) -> %.2lf\n",a,b,c,ans);
return dp[a][b][c] = ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 1)
a++;
if (x == 2)
b++;
if (x == 3)
c++;
}
printf("%.20lf\n", f(a, b, c));
return 0;
} | #include <bits/stdc++.h>
#define N 301
using namespace std;
int n, a, b, c, x;
double dp[N][N][N];
double f(int a, int b, int c) {
if (a == 0 && b == 0 && c == 0)
return 0;
if (a < 0 || b < 0 || c < 0)
return 0;
if (dp[a][b][c] != 0)
return dp[a][b][c];
double ea, eb, ec, ans;
ea = f(a - 1, b, c);
eb = f(a + 1, b - 1, c);
ec = f(a, b + 1, c - 1);
ans = (a * ea + b * eb + c * ec + n) / (a + b + c);
// printf("(%d %d %d) -> %.2lf\n",a,b,c,ans);
return dp[a][b][c] = ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 1)
a++;
if (x == 2)
b++;
if (x == 3)
c++;
}
printf("%.20lf\n", f(a, b, c));
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p03169 | C++ | Runtime Error | /*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define mem(i, j) memset(i, j, sizeof(i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
/*-----------------------------------------------------------------------------------------------------*/
const int N = 50;
double dp[N + 2][N + 2][N + 2];
signed main() {
EmiliaMyWife
int n;
cin >> n;
int a[4] = {0};
for (int i = 0, x; i < n; i++)
cin >> x, a[x]++;
for (int k = 0; k <= N; k++)
for (int j = 0; j <= N; j++)
for (int i = 0; i <= N; i++) {
if (i)
dp[i][j][k] += (dp[i - 1][j][k]) * i / n;
if (j)
dp[i][j][k] += (dp[i + 1][j - 1][k]) * j / n;
if (k)
dp[i][j][k] += (dp[i][j + 1][k - 1]) * k / n;
if (i + j + k)
dp[i][j][k] = (dp[i][j][k] + 1) * n / (i + j + k);
}
cout << setprecision(10);
cout << dp[a[1]][a[2]][a[3]] << '\n';
return 0;
}
| /*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define mem(i, j) memset(i, j, sizeof(i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
/*-----------------------------------------------------------------------------------------------------*/
const int N = 300;
double dp[N + 2][N + 2][N + 2];
signed main() {
EmiliaMyWife
int n;
cin >> n;
int a[4] = {0};
for (int i = 0, x; i < n; i++)
cin >> x, a[x]++;
for (int k = 0; k <= N; k++)
for (int j = 0; j <= N; j++)
for (int i = 0; i <= N; i++) {
if (i)
dp[i][j][k] += (dp[i - 1][j][k]) * i / n;
if (j)
dp[i][j][k] += (dp[i + 1][j - 1][k]) * j / n;
if (k)
dp[i][j][k] += (dp[i][j + 1][k - 1]) * k / n;
if (i + j + k)
dp[i][j][k] = (dp[i][j][k] + 1) * n / (i + j + k);
}
cout << setprecision(10);
cout << dp[a[1]][a[2]][a[3]] << '\n';
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll mod = 1000000007;
int N;
double dp[101][101][101];
double rec(int i, int j, int k) {
if (i + j + k == 0)
return 0;
if (dp[i][j][k] > 0)
return dp[i][j][k];
double p0 = (double)(N - i - j - k) / N;
double p1 = (double)i / N;
double p2 = (double)j / N;
double p3 = (double)k / N;
double res = 1;
if (i > 0)
res += rec(i - 1, j, k) * p1;
if (j > 0)
res += rec(i + 1, j - 1, k) * p2;
if (k > 0)
res += rec(i, j + 1, k - 1) * p3;
res /= 1 - p0;
return dp[i][j][k] = res;
}
int main() {
cin >> N;
int a[3] = {};
for (int i = 0; i < N; ++i) {
int x;
cin >> x;
x--;
a[x]++;
}
printf("%.10f\n", rec(a[0], a[1], a[2]));
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll mod = 1000000007;
int N;
double dp[301][301][301];
double rec(int i, int j, int k) {
if (i + j + k == 0)
return 0;
if (dp[i][j][k] > 0)
return dp[i][j][k];
double p0 = (double)(N - i - j - k) / N;
double p1 = (double)i / N;
double p2 = (double)j / N;
double p3 = (double)k / N;
double res = 1;
if (i > 0)
res += rec(i - 1, j, k) * p1;
if (j > 0)
res += rec(i + 1, j - 1, k) * p2;
if (k > 0)
res += rec(i, j + 1, k - 1) * p3;
res /= 1 - p0;
return dp[i][j][k] = res;
}
int main() {
cin >> N;
int a[3] = {};
for (int i = 0; i < N; ++i) {
int x;
cin >> x;
x--;
a[x]++;
}
printf("%.10f\n", rec(a[0], a[1], a[2]));
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n, a[4];
int main() {
cin >> n;
for (int i = 0; i < n; i += 1) {
int b;
cin >> b;
a[b] += 1;
}
for (int sum = 1; sum <= a[1] + a[2] * 2 + a[3] * 3; sum += 1) {
for (int k = 0; 3 * k <= sum && k <= n; k += 1) {
for (int j = 0; 3 * k + 2 * j <= sum && j <= n; j += 1) {
int i = sum - 2 * j - 3 * k;
if (i > n) {
continue;
}
dp[i][j][k] = ((i > 0 ? i * (1.0 + dp[i - 1][j][k]) : 0.0) +
(j > 0 ? j * (1.0 + dp[i + 1][j - 1][k]) : 0.0) +
(k > 0 ? k * (1.0 + dp[i][j + 1][k - 1]) : 0.0) +
double(n - i - j - k)) /
double(i + j + k);
}
}
}
cout << setprecision(9) << fixed;
cout << dp[a[1]][a[2]][a[3]] << endl;
} | #include <bits/stdc++.h>
using namespace std;
double dp[303][303][303];
int n, a[4];
int main() {
cin >> n;
for (int i = 0; i < n; i += 1) {
int b;
cin >> b;
a[b] += 1;
}
for (int sum = 1; sum <= a[1] + a[2] * 2 + a[3] * 3; sum += 1) {
for (int k = 0; 3 * k <= sum && k <= n; k += 1) {
for (int j = 0; 3 * k + 2 * j <= sum && j <= n; j += 1) {
int i = sum - 2 * j - 3 * k;
if (i > n) {
continue;
}
dp[i][j][k] = ((i > 0 ? i * (1.0 + dp[i - 1][j][k]) : 0.0) +
(j > 0 ? j * (1.0 + dp[i + 1][j - 1][k]) : 0.0) +
(k > 0 ? k * (1.0 + dp[i][j + 1][k - 1]) : 0.0) +
double(n - i - j - k)) /
double(i + j + k);
}
}
}
cout << setprecision(9) << fixed;
cout << dp[a[1]][a[2]][a[3]] << endl;
} | replace | 2 | 3 | 2 | 3 | -11 | |
p03169 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, p, q) for (ll i = p; i < q; i++)
#define ll long long
using namespace std;
const long long MAX_N = 1 << 17;
long long dat[2 * MAX_N - 1];
ll ecd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
else {
return ecd(b, a % b);
}
}
ll pow(ll a, ll b) {
vector<ll> d = vector<ll>((ll)(log(b)) + 2);
d[0] = a;
rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
ll ret = 1;
rep(i, 0, log(b) + 1) {
if (b & 1 << i)
ret *= d[i];
}
return ret;
}
// J
vector<vector<vector<long double>>> dp;
ll n;
ll s1, s2, s3;
long double rec(ll i, ll j, ll k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0.0;
long double res = 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 *= 1.0 / (long double)(i + j + k);
return dp[i][j][k] = res;
}
int main(void) {
n;
cin >> n;
s1 = 0, s2 = 0, s3 = 0;
rep(i, 0, n) {
ll sushi;
cin >> sushi;
if (sushi == 1)
s1++;
else if (sushi == 2)
s2++;
else
s3++;
}
dp = vector<vector<vector<long double>>>(
s1 + 2,
vector<vector<long double>>(s2 + 2, vector<long double>(s3 + 2, -1)));
cout << rec(s1, s2, s3) << endl;
} | #include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, p, q) for (ll i = p; i < q; i++)
#define ll long long
using namespace std;
const long long MAX_N = 1 << 17;
long long dat[2 * MAX_N - 1];
ll ecd(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
else {
return ecd(b, a % b);
}
}
ll pow(ll a, ll b) {
vector<ll> d = vector<ll>((ll)(log(b)) + 2);
d[0] = a;
rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
ll ret = 1;
rep(i, 0, log(b) + 1) {
if (b & 1 << i)
ret *= d[i];
}
return ret;
}
// J
vector<vector<vector<long double>>> dp;
ll n;
ll s1, s2, s3;
long double rec(ll i, ll j, ll k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (i == 0 && j == 0 && k == 0)
return 0.0;
long double res = 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 *= 1.0 / (long double)(i + j + k);
return dp[i][j][k] = res;
}
int main(void) {
n;
cin >> n;
s1 = 0, s2 = 0, s3 = 0;
rep(i, 0, n) {
ll sushi;
cin >> sushi;
if (sushi == 1)
s1++;
else if (sushi == 2)
s2++;
else
s3++;
}
dp = vector<vector<vector<long double>>>(
310, vector<vector<long double>>(310, vector<long double>(310, -1)));
cout << setprecision(10) << rec(s1, s2, s3) << endl;
}
| replace | 89 | 92 | 89 | 91 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;
#define fastIO() \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define what_is(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
int N;
cin >> N;
vi a(N);
for (auto &i : a)
cin >> i;
ld dp[N + 1][N + 1][N + 1];
dp[0][0][0] = 0.0;
for (int k = 0; k <= N; ++k) {
for (int j = 0; j <= N; ++j) {
for (int i = 0; i <= N; ++i) {
if (i + j + k <= 0 || i + j + k > N)
continue;
dp[i][j][k] = 0;
if (i >= 1)
dp[i][j][k] += ld(i) * dp[i - 1][j][k];
if (j >= 1)
dp[i][j][k] += ld(j) * dp[i + 1][j - 1][k];
if (k >= 1)
dp[i][j][k] += ld(k) * dp[i][j + 1][k - 1];
assert(i + j + k > 0);
dp[i][j][k] = (dp[i][j][k] + N) / (i + j + k);
// cerr << i << " " << j << " " <<k << " -> " << dp[i][j][k] << endl;
}
}
}
int i, j, k;
i = j = k = 0;
for (auto x : a) {
if (x == 1)
++i;
else if (x == 2)
++j;
else if (x == 3)
++k;
}
assert(i + j + k >= 0 && i + j + k <= N);
cout << fixed << setprecision(12);
cout << dp[i][j][k] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;
#define fastIO() \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define what_is(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
int N;
cin >> N;
vi a(N);
for (auto &i : a)
cin >> i;
int n = 303;
vector<vector<vector<ld>>> dp(
n + 1, vector<vector<ld>>(n + 1, vector<ld>(n + 1, 0.0)));
for (int k = 0; k <= N; ++k) {
for (int j = 0; j <= N; ++j) {
for (int i = 0; i <= N; ++i) {
if (i + j + k <= 0 || i + j + k > N)
continue;
dp[i][j][k] = 0;
if (i >= 1)
dp[i][j][k] += ld(i) * dp[i - 1][j][k];
if (j >= 1)
dp[i][j][k] += ld(j) * dp[i + 1][j - 1][k];
if (k >= 1)
dp[i][j][k] += ld(k) * dp[i][j + 1][k - 1];
assert(i + j + k > 0);
dp[i][j][k] = (dp[i][j][k] + N) / (i + j + k);
// cerr << i << " " << j << " " <<k << " -> " << dp[i][j][k] << endl;
}
}
}
int i, j, k;
i = j = k = 0;
for (auto x : a) {
if (x == 1)
++i;
else if (x == 2)
++j;
else if (x == 3)
++k;
}
assert(i + j + k >= 0 && i + j + k <= N);
cout << fixed << setprecision(12);
cout << dp[i][j][k] << endl;
return 0;
}
| replace | 41 | 43 | 41 | 44 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> s(3);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
s.at(a - 1)++;
}
vector<vector<vector<double>>> dp(
n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1)));
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
if (i)
dp[i][j][k] += i * dp[i - 1][j][k] / (i + j + k);
if (j)
dp[i][j][k] += j * dp[i + 1][j - 1][k] / (i + j + k);
if (k)
dp[i][j][k] += k * dp[i][j + 1][k - 1] / (i + j + k);
dp[i][j][k] += 1.0 * n / (i + j + k);
}
}
}
cout << setprecision(17) << dp[s.at(0)][s.at(1)][s.at(2)] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> s(3);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
s.at(a - 1)++;
}
vector<vector<vector<double>>> dp(
n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1)));
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n - k; j++) {
for (int i = 0; i <= n - k - j; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
if (i)
dp[i][j][k] += i * dp[i - 1][j][k] / (i + j + k);
if (j)
dp[i][j][k] += j * dp[i + 1][j - 1][k] / (i + j + k);
if (k)
dp[i][j][k] += k * dp[i][j + 1][k - 1] / (i + j + k);
dp[i][j][k] += 1.0 * n / (i + j + k);
}
}
}
cout << setprecision(17) << dp[s.at(0)][s.at(1)][s.at(2)] << endl;
}
| replace | 15 | 17 | 15 | 17 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long, long> ii;
#define sz(a) long((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(v, n) \
for (ll i = 0; i < n; i++) \
cin >> v[i]
#define output(v, n) \
for (ll i = 0; i < n; i++) \
cout << v[i] << " "
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
double pro[302][302][302];
double ex[302][302][302];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll one = 0, two = 0, three = 0;
ll n, i, j, k;
cin >> n;
for (i = 0; i < n; i++) {
ll x;
cin >> x;
if (x == 1)
one++;
if (x == 2)
two++;
if (x == 3)
three++;
}
pro[three][two][one] = 1;
for (i = n; i >= 0; i--) {
for (j = n; j >= 0; j--) {
for (k = n; k >= 0; k--) {
if (i == 0 && k == 0 && j == 0)
continue;
if (pro[i][j][k] == 0)
continue;
// debug(i,j,k,ex[i][j][k],pro[i][j][k]);
double pw = 1.0 * (n - i - j - k) / n;
pw = pw / (1 - pw);
ex[i][j][k] /= pro[i][j][k];
ex[i][j][k] += pw;
if (i) {
pro[i - 1][j + 1][k] += pro[i][j][k] * (i) / (i + j + k);
ex[i - 1][j + 1][k] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (i) / (i + j + k));
}
if (j) {
pro[i][j - 1][k + 1] += pro[i][j][k] * (j) / (i + j + k);
ex[i][j - 1][k + 1] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (j) / (i + j + k));
}
if (k) {
pro[i][j][k - 1] += pro[i][j][k] * (k) / (i + j + k);
ex[i][j][k - 1] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (k) / (i + j + k));
}
debug(i, j, k, ex[i][j][k], pro[i][j][k]);
}
}
}
cout << fixed << setprecision(10) << ex[0][0][0];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long, long> ii;
#define sz(a) long((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(v, n) \
for (ll i = 0; i < n; i++) \
cin >> v[i]
#define output(v, n) \
for (ll i = 0; i < n; i++) \
cout << v[i] << " "
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
double pro[302][302][302];
double ex[302][302][302];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll one = 0, two = 0, three = 0;
ll n, i, j, k;
cin >> n;
for (i = 0; i < n; i++) {
ll x;
cin >> x;
if (x == 1)
one++;
if (x == 2)
two++;
if (x == 3)
three++;
}
pro[three][two][one] = 1;
for (i = n; i >= 0; i--) {
for (j = n; j >= 0; j--) {
for (k = n; k >= 0; k--) {
if (i == 0 && k == 0 && j == 0)
continue;
if (pro[i][j][k] == 0)
continue;
// debug(i,j,k,ex[i][j][k],pro[i][j][k]);
double pw = 1.0 * (n - i - j - k) / n;
pw = pw / (1 - pw);
ex[i][j][k] /= pro[i][j][k];
ex[i][j][k] += pw;
if (i) {
pro[i - 1][j + 1][k] += pro[i][j][k] * (i) / (i + j + k);
ex[i - 1][j + 1][k] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (i) / (i + j + k));
}
if (j) {
pro[i][j - 1][k + 1] += pro[i][j][k] * (j) / (i + j + k);
ex[i][j - 1][k + 1] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (j) / (i + j + k));
}
if (k) {
pro[i][j][k - 1] += pro[i][j][k] * (k) / (i + j + k);
ex[i][j][k - 1] +=
(ex[i][j][k] + 1) * (pro[i][j][k] * (k) / (i + j + k));
}
// debug(i,j,k,ex[i][j][k],pro[i][j][k]);
}
}
}
cout << fixed << setprecision(10) << ex[0][0][0];
return 0;
}
| replace | 120 | 121 | 120 | 121 | TLE | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(), s.end()
#define FIN \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
double dp[301][301][301];
ll n;
bool done[301][301][301];
double solve(int on, int tw, int th) {
if (on + tw + th == 0)
return 0;
double &r = dp[on][tw][th];
if (done[on][tw][th])
return r;
double tot = on + tw + th;
r = (double)n / tot;
if (on)
r += (double)on / tot * solve(on - 1, tw, th);
if (tw)
r += (double)tw / tot * solve(on + 1, tw - 1, th);
if (th)
r += (double)th / tot * solve(on, tw + 1, th - 1);
return r;
}
int main() {
FIN;
int x, on = 0, tw = 0, th = 0;
cin >> n;
fore(i, 0, n) {
cin >> x;
on += x == 1;
tw += x == 2;
th += x == 3;
}
cout << fixed << setprecision(10) << solve(on, tw, th) << "\n";
} | #include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(), s.end()
#define FIN \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
double dp[301][301][301];
ll n;
bool done[301][301][301];
double solve(int on, int tw, int th) {
if (on + tw + th == 0)
return 0;
double &r = dp[on][tw][th];
if (done[on][tw][th])
return r;
done[on][tw][th] = 1;
double tot = on + tw + th;
r = (double)n / tot;
if (on)
r += (double)on / tot * solve(on - 1, tw, th);
if (tw)
r += (double)tw / tot * solve(on + 1, tw - 1, th);
if (th)
r += (double)th / tot * solve(on, tw + 1, th - 1);
return r;
}
int main() {
FIN;
int x, on = 0, tw = 0, th = 0;
cin >> n;
fore(i, 0, n) {
cin >> x;
on += x == 1;
tw += x == 2;
th += x == 3;
}
cout << fixed << setprecision(10) << solve(on, tw, th) << "\n";
} | insert | 25 | 25 | 25 | 26 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
double dp[301][301][301];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int n;
cin >> n;
vector<int> a(n);
int o = 0, tw = 0, tr = 0;
for (auto &i : a) {
cin >> i;
if (i == 1)
o++;
else if (i == 2)
tw++;
else
tr++;
}
for (int k = 0; k < 301; ++k)
for (int j = 0; k + j < 301; ++j)
for (int i = 0; i + j + k < 301; ++i) {
if (i + j + k == 0)
continue;
double w = 1.0 * n / (i + j + k);
double pi = 1.0 * i / (i + j + k);
double pj = 1.0 * j / (i + j + k);
double pk = 1.0 * k / (i + j + k);
if (i)
dp[i][j][k] += dp[i - 1][j][k] * pi;
if (j)
dp[i][j][k] += dp[i + 1][j - 1][k] * pj;
if (k)
dp[i][j][k] += dp[i][j + 1][k - 1] * pk;
dp[i][j][k] += w;
}
cout << setprecision(10) << fixed << dp[o][tw][tr] << "\n";
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
double dp[301][301][301];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
int o = 0, tw = 0, tr = 0;
for (auto &i : a) {
cin >> i;
if (i == 1)
o++;
else if (i == 2)
tw++;
else
tr++;
}
for (int k = 0; k < 301; ++k)
for (int j = 0; k + j < 301; ++j)
for (int i = 0; i + j + k < 301; ++i) {
if (i + j + k == 0)
continue;
double w = 1.0 * n / (i + j + k);
double pi = 1.0 * i / (i + j + k);
double pj = 1.0 * j / (i + j + k);
double pk = 1.0 * k / (i + j + k);
if (i)
dp[i][j][k] += dp[i - 1][j][k] * pi;
if (j)
dp[i][j][k] += dp[i + 1][j - 1][k] * pj;
if (k)
dp[i][j][k] += dp[i][j + 1][k - 1] * pk;
dp[i][j][k] += w;
}
cout << setprecision(10) << fixed << dp[o][tw][tr] << "\n";
return 0;
} | delete | 8 | 13 | 8 | 8 | -11 | |
p03169 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h> // [PRIMES] 1777 ~2^10.80
using namespace std; // 10333 ~2^13.33
using ll = long long; // seq 1 128 | factor 100333 ~2^16.61
using vl = vector<ll>; // | grep -v ' .* ' 1300111 ~2^20.31
using vvl = vector<vl>; // 10300777 ~2^23.30
using vb = vector<bool>; // 100400999 ~2^26.58
using vs = vector<string>; // 1300400999 ~2^30.28
using pll = pair<ll, ll>; // 10200500333 ~2^33.25
const ll oo = 0x3f3f3f3f3f3f3f3fLL; // 100200400777 ~2^36.54
const double eps = 1e-9; // 1200300700111 ~2^40.13
#define sz(c) ll((c).size()) // 10200300500777 ~2^43.21
#define all(c) begin(c), end(c) // 100200300400777 ~2^46.51
#define mp make_pair // 1200300400600999 ~2^50.09
#define mt make_tuple // 10200300400600111 ~2^53.18
#define pb push_back // 100200300400600333 ~2^56.48
#define eb emplace_back // 1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X) \
({ \
if (1) \
cerr << "TR: " << (#X) << " = " << (X) << endl; \
})
ll N;
vector<vector<vector<double>>> dp;
double r(double p, ll d) {
if (d == 100)
return p;
return p + (1 - p) * r(p, d + 1);
}
double f(vl in) {
if (in[0] == N)
return 0;
double *dpp = &dp[in[1]][in[2]][in[3]];
if (*dpp > -0.5)
return *dpp;
double p_null = (double)in[0] / (double)N;
double acc = (1.0 / (1.0 - p_null));
FOR(i, 1, sz(in)) {
if (in[i] == 0)
continue;
double p = ((double)in[i] / (double)(N - in[0]));
vl newin = in;
newin[i]--;
newin[i - 1]++;
acc += f(newin) * p;
}
*dpp = acc;
return acc;
}
int main() {
ll n;
cin >> n;
N = 0;
vl a;
dp.resize(900 + 1,
vector<vector<double>>(600 + 1, vector<double>(300 + 1, -1)));
a.resize(4, 0);
FOR(i, 0, n) {
ll in;
cin >> in;
a[in]++;
N = n;
}
cout << fixed << setprecision(10) << f(a) << endl;
} // cin.tie(0) bei schnellem Wechseln
| #include <bits/stdc++.h> // [PRIMES] 1777 ~2^10.80
using namespace std; // 10333 ~2^13.33
using ll = long long; // seq 1 128 | factor 100333 ~2^16.61
using vl = vector<ll>; // | grep -v ' .* ' 1300111 ~2^20.31
using vvl = vector<vl>; // 10300777 ~2^23.30
using vb = vector<bool>; // 100400999 ~2^26.58
using vs = vector<string>; // 1300400999 ~2^30.28
using pll = pair<ll, ll>; // 10200500333 ~2^33.25
const ll oo = 0x3f3f3f3f3f3f3f3fLL; // 100200400777 ~2^36.54
const double eps = 1e-9; // 1200300700111 ~2^40.13
#define sz(c) ll((c).size()) // 10200300500777 ~2^43.21
#define all(c) begin(c), end(c) // 100200300400777 ~2^46.51
#define mp make_pair // 1200300400600999 ~2^50.09
#define mt make_tuple // 10200300400600111 ~2^53.18
#define pb push_back // 100200300400600333 ~2^56.48
#define eb emplace_back // 1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X) \
({ \
if (1) \
cerr << "TR: " << (#X) << " = " << (X) << endl; \
})
ll N;
vector<vector<vector<double>>> dp;
double r(double p, ll d) {
if (d == 100)
return p;
return p + (1 - p) * r(p, d + 1);
}
double f(vl in) {
if (in[0] == N)
return 0;
double *dpp = &dp[in[1]][in[2]][in[3]];
if (*dpp > -0.5)
return *dpp;
double p_null = (double)in[0] / (double)N;
double acc = (1.0 / (1.0 - p_null));
FOR(i, 1, sz(in)) {
if (in[i] == 0)
continue;
double p = ((double)in[i] / (double)(N - in[0]));
vl newin = in;
newin[i]--;
newin[i - 1]++;
acc += f(newin) * p;
}
*dpp = acc;
return acc;
}
int main() {
ll n;
cin >> n;
N = 0;
vl a;
dp.resize(300 + 1,
vector<vector<double>>(300 + 1, vector<double>(300 + 1, -1)));
a.resize(4, 0);
FOR(i, 0, n) {
ll in;
cin >> in;
a[in]++;
N = n;
}
cout << fixed << setprecision(10) << f(a) << endl;
} // cin.tie(0) bei schnellem Wechseln
| replace | 61 | 63 | 61 | 63 | MLE | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
template <typename T> void Max(T &m, const T q) {
if (m < q)
m = q;
}
template <typename T> void Min(T &m, const T q) {
if (m > q)
m = q;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
int N;
vector<vector<vector<double>>> dp;
int main() {
cin >> N;
vector<int> co(4);
REP(_, N) {
int a;
cin >> a;
co[a]++;
}
ndarray(dp, co[1] + co[2] + co[3] + 1, co[2] + co[3] + 1, co[3] + 1);
REP(k, co[3] + 1)
REP(j, co[2] + co[3] + 1) REP(i, co[1] + co[2] + co[3] + 1) if (i + j + k) {
if (i)
dp[i][j][k] += (dp[i - 1][j][k] + 1) * i / N;
if (j and i < co[1] + co[2] + co[3])
dp[i][j][k] += (dp[i + 1][j - 1][k] + 1) * j / N;
if (k and j < co[2] + co[3])
dp[i][j][k] += (dp[i][j + 1][k - 1] + 1) * k / N;
dp[i][j][k] = (dp[i][j][k] + 1) * N / (i + j + k) - 1;
}
cout << dp[co[1]][co[2]][co[3]] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
template <typename T> void Max(T &m, const T q) {
if (m < q)
m = q;
}
template <typename T> void Min(T &m, const T q) {
if (m > q)
m = q;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
int N;
vector<vector<vector<double>>> dp;
int main() {
cin >> N;
vector<int> co(4);
REP(_, N) {
int a;
cin >> a;
co[a]++;
}
ndarray(dp, co[1] + co[2] + co[3] + 1, co[2] + co[3] + 1, co[3] + 1);
REP(k, co[3] + 1)
REP(j, co[2] + co[3] - k + 1)
REP(i, co[1] + co[2] + co[3] - j - k + 1) if (i + j + k) {
if (i)
dp[i][j][k] += (dp[i - 1][j][k] + 1) * i / N;
if (j and i < co[1] + co[2] + co[3])
dp[i][j][k] += (dp[i + 1][j - 1][k] + 1) * j / N;
if (k and j < co[2] + co[3])
dp[i][j][k] += (dp[i][j + 1][k - 1] + 1) * k / N;
dp[i][j][k] = (dp[i][j][k] + 1) * N / (i + j + k) - 1;
}
cout << dp[co[1]][co[2]][co[3]] << endl;
}
| replace | 127 | 128 | 127 | 129 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define inf 9e18
#define pii pair<int, int>
#define setp(x) fixed << showpoint << setprecision(x)
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
long double n;
long double dp[303][303][303];
int a[303];
long double solve(int a1, int a2, int a3) {
if (a1 + a2 + a3 == 0)
return 0;
if (dp[a1][a2][a3] != -1)
return dp[a1][a2][a3];
long double cur = n / (a1 + a2 + a3);
long double q1, q2, q3;
q1 = q2 = q3 = 0;
long double n2 = a1 + a2 + a3;
if (a1 > 0)
q1 = a1 * solve(a1 - 1, a2, a3);
if (a2 > 0)
q2 = a2 * solve(a1 + 1, a2 - 1, a3);
if (a3 > 0)
q3 = a3 * solve(a1, a2 + 1, a3 - 1);
cur = cur + (q1 + q2 + q3) / n2;
return dp[a1][a2][a3] = cur;
}
int32_t main() {
fastio
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
cin >> n;
int a1, a3, a2;
a1 = a2 = a3 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
a1++;
else if (a[i] == 2)
a2++;
else
a3++;
}
for (int i = 0; i < 303; i++)
for (int j = 0; j < 303; j++)
for (int k = 0; k < 303; k++)
dp[i][j][k] = -1;
long double ans = solve(a1, a2, a3);
cout << setp(10) << ans;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define inf 9e18
#define pii pair<int, int>
#define setp(x) fixed << showpoint << setprecision(x)
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
long double n;
long double dp[303][303][303];
int a[303];
long double solve(int a1, int a2, int a3) {
if (a1 + a2 + a3 == 0)
return 0;
if (dp[a1][a2][a3] != -1)
return dp[a1][a2][a3];
long double cur = n / (a1 + a2 + a3);
long double q1, q2, q3;
q1 = q2 = q3 = 0;
long double n2 = a1 + a2 + a3;
if (a1 > 0)
q1 = a1 * solve(a1 - 1, a2, a3);
if (a2 > 0)
q2 = a2 * solve(a1 + 1, a2 - 1, a3);
if (a3 > 0)
q3 = a3 * solve(a1, a2 + 1, a3 - 1);
cur = cur + (q1 + q2 + q3) / n2;
return dp[a1][a2][a3] = cur;
}
int32_t main() {
fastio
cin >>
n;
int a1, a3, a2;
a1 = a2 = a3 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
a1++;
else if (a[i] == 2)
a2++;
else
a3++;
}
for (int i = 0; i < 303; i++)
for (int j = 0; j < 303; j++)
for (int k = 0; k < 303; k++)
dp[i][j][k] = -1;
long double ans = solve(a1, a2, a3);
cout << setp(10) << ans;
return 0;
} | replace | 39 | 46 | 39 | 42 | -11 | |
p03169 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
using namespace std;
const int maxn = 300;
double dp[maxn + 1][maxn + 1][maxn + 1] = {0};
int occur[3] = {0};
void test() {
double sum = 0;
double n = 50, e = 30;
for (double i = 0; i <= 1000; i++) {
sum += (n - e) / n * pow(e / n, i) * (i + 1);
}
cout << sum << endl;
cout << e / (n - e) << endl;
cout << n / (n - e) << endl;
}
int main() {
// test();
// return 0;
int n;
cin >> n;
for (int i = 0, x; i < n; i++) {
cin >> x;
occur[x - 1]++;
}
for (int k = 0; k <= occur[2]; k++) {
for (int j = 0; j <= occur[1] + occur[2]; j++) {
for (int i = 0; i <= occur[0] + occur[1] + occur[2]; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
double s = i + j + k;
dp[i][j][k] = (k ? dp[i][j + 1][k - 1] * k / s : 0) +
(j ? dp[i + 1][j - 1][k] * j / s : 0) +
(i ? dp[i - 1][j][k] * i / s : 0) + +n / s;
}
}
}
cout.precision(10);
cout << dp[occur[0]][occur[1]][occur[2]] << '\n';
}
| #include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
using namespace std;
const int maxn = 300;
double dp[3 * maxn + 1][2 * maxn][maxn + 1] = {0};
int occur[3] = {0};
void test() {
double sum = 0;
double n = 50, e = 30;
for (double i = 0; i <= 1000; i++) {
sum += (n - e) / n * pow(e / n, i) * (i + 1);
}
cout << sum << endl;
cout << e / (n - e) << endl;
cout << n / (n - e) << endl;
}
int main() {
// test();
// return 0;
int n;
cin >> n;
for (int i = 0, x; i < n; i++) {
cin >> x;
occur[x - 1]++;
}
for (int k = 0; k <= occur[2]; k++) {
for (int j = 0; j <= occur[1] + occur[2]; j++) {
for (int i = 0; i <= occur[0] + occur[1] + occur[2]; i++) {
if (i == 0 && j == 0 && k == 0)
continue;
double s = i + j + k;
dp[i][j][k] = (k ? dp[i][j + 1][k - 1] * k / s : 0) +
(j ? dp[i + 1][j - 1][k] * j / s : 0) +
(i ? dp[i - 1][j][k] * i / s : 0) + +n / s;
}
}
}
cout.precision(10);
cout << dp[occur[0]][occur[1]][occur[2]] << '\n';
}
| replace | 7 | 8 | 7 | 8 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) \
for (int i = x; i < (a).size(); ++i) \
cin >> (a)[i]
#define out(a) \
for (auto qwe : a) \
cout << qwe << " "
const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;
const int mxn = 200000;
int n;
vector<vector<vector<ld>>> dp;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int a = 0, b = 0, c = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x == 1)
++a;
if (x == 2)
++b;
if (x == 3)
++c;
}
dp.assign(n + 2, vector<vector<ld>>(n + 2, vector<ld>(n + 2, 0)));
for (int k = 0; k <= n; ++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] = (ld)n / (i + j + k);
if (i > 0)
dp[i][j][k] += dp[i - 1][j][k] * ((ld)i / (i + j + k));
if (j > 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * ((ld)j / (i + j + k));
if (k > 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * ((ld)k / (i + j + k));
}
}
}
cout.precision(10);
cout << fixed << dp[a][b][c];
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) \
for (int i = x; i < (a).size(); ++i) \
cin >> (a)[i]
#define out(a) \
for (auto qwe : a) \
cout << qwe << " "
const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;
const int mxn = 200000;
int n;
vector<vector<vector<ld>>> dp;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int a = 0, b = 0, c = 0;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x == 1)
++a;
if (x == 2)
++b;
if (x == 3)
++c;
}
dp.assign(n + 2, vector<vector<ld>>(n + 2, vector<ld>(n + 2, 0)));
for (int k = 0; k <= c; ++k) {
for (int j = 0; j <= b + (c - k); ++j) {
for (int i = 0; i <= (n - j - k); ++i) {
if (i == 0 && j == 0 && k == 0)
continue;
dp[i][j][k] = (ld)n / (i + j + k);
if (i > 0)
dp[i][j][k] += dp[i - 1][j][k] * ((ld)i / (i + j + k));
if (j > 0)
dp[i][j][k] += dp[i + 1][j - 1][k] * ((ld)j / (i + j + k));
if (k > 0)
dp[i][j][k] += dp[i][j + 1][k - 1] * ((ld)k / (i + j + k));
}
}
}
cout.precision(10);
cout << fixed << dp[a][b][c];
}
| replace | 67 | 70 | 67 | 70 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAXN 310
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
int n, f[4];
double dp[MAXN][MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
f[t]++;
}
for (int k = 0; k < MAXN; k++) {
for (int j = 0; j < MAXN; j++) {
for (int i = 0; i < MAXN; i++) {
if (i == 0 and j == 0 and k == 0) {
dp[i][j][k] = 0;
continue;
}
double t = 0;
if (i > 0)
t += (double)i * dp[i - 1][j][k] / n;
if (j > 0)
t += (double)j * dp[i + 1][j - 1][k] / n;
if (k > 0)
t += (double)k * dp[i][j + 1][k - 1] / n;
t++;
t /= (double)(i + j + k) / n;
// cout << t;
dp[i][j][k] = t;
}
}
}
cout << fixed << setprecision(11) << dp[f[1]][f[2]][f[3]];
} | #include <bits/stdc++.h>
#define MAXN 310
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
int n, f[4];
double dp[MAXN][MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
f[t]++;
}
for (int k = 0; k < MAXN - 1; k++) {
for (int j = 0; j < MAXN - 1; j++) {
for (int i = 0; i < MAXN - 1; i++) {
if (i == 0 and j == 0 and k == 0) {
dp[i][j][k] = 0;
continue;
}
double t = 0;
if (i > 0)
t += (double)i * dp[i - 1][j][k] / n;
if (j > 0)
t += (double)j * dp[i + 1][j - 1][k] / n;
if (k > 0)
t += (double)k * dp[i][j + 1][k - 1] / n;
t++;
t /= (double)(i + j + k) / n;
// cout << t;
dp[i][j][k] = t;
}
}
}
cout << fixed << setprecision(11) << dp[f[1]][f[2]][f[3]];
} | replace | 20 | 23 | 20 | 23 | -11 | |
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 FASTIO \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
#define ll long long int
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> new_data_set;
// struct compare {
// bool operator() (const pair<int, int> &a, const pair<int, int> &b) const
// { if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F)); else
// return (a.F < b.F);
// }
// };
const int mx = 305;
double ev[mx][mx][mx];
int n;
double calc(int a, int b, int c) {
if (ev[a][b][c] != -1)
return ev[a][b][c];
double ans = 0;
if (a != 0) {
ans += (double)a / n * calc(a - 1, b, c);
}
if (b != 0) {
ans += (double)b / n * calc(a + 1, b - 1, c);
}
if (c != 0) {
ans += (double)c / n * calc(a, b + 1, c - 1);
}
ans += 1;
ans *= (double)n / (a + b + c);
ev[a][b][c] = ans;
return ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
FASTIO;
cin >> n;
vector<int> cnt(4);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
cnt[temp]++;
}
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
for (int k = 0; k < mx; k++) {
ev[i][j][k] = -1;
}
}
}
ev[1][0][0] = n;
ev[0][0][0] = 0;
double ans = calc(cnt[1], cnt[2], cnt[3]);
printf("%.10lf\n", ans);
} | #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 FASTIO \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
#define ll long long int
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> new_data_set;
// struct compare {
// bool operator() (const pair<int, int> &a, const pair<int, int> &b) const
// { if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F)); else
// return (a.F < b.F);
// }
// };
const int mx = 305;
double ev[mx][mx][mx];
int n;
double calc(int a, int b, int c) {
if (ev[a][b][c] != -1)
return ev[a][b][c];
double ans = 0;
if (a != 0) {
ans += (double)a / n * calc(a - 1, b, c);
}
if (b != 0) {
ans += (double)b / n * calc(a + 1, b - 1, c);
}
if (c != 0) {
ans += (double)c / n * calc(a, b + 1, c - 1);
}
ans += 1;
ans *= (double)n / (a + b + c);
ev[a][b][c] = ans;
return ans;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
FASTIO;
cin >> n;
vector<int> cnt(4);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
cnt[temp]++;
}
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
for (int k = 0; k < mx; k++) {
ev[i][j][k] = -1;
}
}
}
ev[1][0][0] = n;
ev[0][0][0] = 0;
double ans = calc(cnt[1], cnt[2], cnt[3]);
printf("%.10lf\n", ans);
} | replace | 45 | 49 | 45 | 49 | -11 | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define For(i, n) rep(i, 0, n)
// #define int long long
// const int INF=1e18;
const int MOD = 1000000007;
typedef pair<int, int> P;
int c[3] = {0, 0, 0}, n;
double mem[305][305][305];
bool f[305][305][305];
double dp(int a, int b, int c) {
if (!a && !b && !c) {
return 0;
}
f[a][b][c] = 1;
double ret = n;
if (a) {
ret += dp(a - 1, b, c) * a;
}
if (b) {
ret += dp(a + 1, b - 1, c) * b;
}
if (c) {
ret += dp(a, b + 1, c - 1) * c;
}
return mem[a][b][c] = ret / (a + b + c);
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a;
cin >> n;
rep(i, 0, n) {
int a;
cin >> a;
a--;
c[a]++;
}
cout << setprecision(20) << dp(c[0], c[1], c[2]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define For(i, n) rep(i, 0, n)
// #define int long long
// const int INF=1e18;
const int MOD = 1000000007;
typedef pair<int, int> P;
int c[3] = {0, 0, 0}, n;
double mem[305][305][305];
bool f[305][305][305];
double dp(int a, int b, int c) {
if (!a && !b && !c) {
return 0;
}
if (f[a][b][c]) {
return mem[a][b][c];
}
f[a][b][c] = 1;
double ret = n;
if (a) {
ret += dp(a - 1, b, c) * a;
}
if (b) {
ret += dp(a + 1, b - 1, c) * b;
}
if (c) {
ret += dp(a, b + 1, c - 1) * c;
}
return mem[a][b][c] = ret / (a + b + c);
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a;
cin >> n;
rep(i, 0, n) {
int a;
cin >> a;
a--;
c[a]++;
}
cout << setprecision(20) << dp(c[0], c[1], c[2]) << endl;
return 0;
} | insert | 16 | 16 | 16 | 19 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
double dp[101][101][101];
bool vis[101][101][101] = {0};
int n;
double solve(int x, int y, int z) {
if (x <= 0 && y <= 0 && z <= 0)
return 0;
// cout << x << y << z << endl;
if (vis[x][y][z])
return dp[x][y][z];
vis[x][y][z] = 1;
double ans = 1.0;
// cout << x << " ";
if (x > 0) {
// cout << (double)x / n << " ";
ans += ((double)x / n) * solve(x - 1, y, z);
// cout << ans << endl;
}
if (y > 0)
ans += ((double)y / n) * solve(x + 1, y - 1, z);
if (z > 0)
ans += ((double)z / n) * solve(x, y + 1, z - 1);
ans /= ((1.0 - ((double)n - x - y - z) / n));
// cout << ans << endl;
return dp[x][y][z] = ans;
}
int main() {
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1)
x++;
else if (a[i] == 2)
y++;
else if (a[i] == 3)
z++;
}
printf("%.10lf", solve(x, y, z));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
bool vis[301][301][301] = {0};
int n;
double solve(int x, int y, int z) {
if (x <= 0 && y <= 0 && z <= 0)
return 0;
// cout << x << y << z << endl;
if (vis[x][y][z])
return dp[x][y][z];
vis[x][y][z] = 1;
double ans = 1.0;
// cout << x << " ";
if (x > 0) {
// cout << (double)x / n << " ";
ans += ((double)x / n) * solve(x - 1, y, z);
// cout << ans << endl;
}
if (y > 0)
ans += ((double)y / n) * solve(x + 1, y - 1, z);
if (z > 0)
ans += ((double)z / n) * solve(x, y + 1, z - 1);
ans /= ((1.0 - ((double)n - x - y - z) / n));
// cout << ans << endl;
return dp[x][y][z] = ans;
}
int main() {
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1)
x++;
else if (a[i] == 2)
y++;
else if (a[i] == 3)
z++;
}
printf("%.10lf", solve(x, y, z));
return 0;
}
| replace | 4 | 6 | 4 | 6 | 0 | |
p03169 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a, b) for (int i = a; i < b; i++)
#define mod 10000code200007
#define printDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<int, pair<int, int>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
/*E(x,y,z) = (1 + p1*E(x-1,y,z) + p2*E(x+1,y-1,z) + p3*E(x,y+1,z-1))/(1-p0)
(1 - N-(x+y+z))/N = N - N + x + y + z
E(x,y,z) = (n + x*E(x-1,y,z) + y*E(x+1,y-1,z) + z*E(x,y+1,z-1))/(x + y + z);*/
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x == 0 && y == 0 && z == 0)
return 0;
if (x < 0 || y < 0 || z < 0)
return 0;
if (dp[x][y][z] < 0)
return dp[x][y][z];
int remaining = n - (x + y + z);
double exp_val = n + x * solve(x - 1, y, z, n) +
y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp_val / (x + y + z);
}
int main() {
ll i, j, t, n, m, x, p, k;
fast_io;
// cin>>t;
t = 1;
while (t--) {
memset(dp, -1, sizeof dp);
int n, x = 0, y = 0, z = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int sushi;
cin >> sushi;
if (sushi == 1)
x++;
else if (sushi == 2)
y++;
else
z++;
}
printDouble(solve(x, y, z, n));
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a, b) for (int i = a; i < b; i++)
#define mod 10000code200007
#define printDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<int, pair<int, int>>
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
using namespace std;
/*E(x,y,z) = (1 + p1*E(x-1,y,z) + p2*E(x+1,y-1,z) + p3*E(x,y+1,z-1))/(1-p0)
(1 - N-(x+y+z))/N = N - N + x + y + z
E(x,y,z) = (n + x*E(x-1,y,z) + y*E(x+1,y-1,z) + z*E(x,y+1,z-1))/(x + y + z);*/
double dp[301][301][301];
double solve(int x, int y, int z, int &n) {
if (x == 0 && y == 0 && z == 0)
return 0;
if (x < 0 || y < 0 || z < 0)
return 0;
if (dp[x][y][z] > -0.5)
return dp[x][y][z];
int remaining = n - (x + y + z);
double exp_val = n + x * solve(x - 1, y, z, n) +
y * solve(x + 1, y - 1, z, n) +
z * solve(x, y + 1, z - 1, n);
return dp[x][y][z] = exp_val / (x + y + z);
}
int main() {
ll i, j, t, n, m, x, p, k;
fast_io;
// cin>>t;
t = 1;
while (t--) {
memset(dp, -1, sizeof dp);
int n, x = 0, y = 0, z = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int sushi;
cin >> sushi;
if (sushi == 1)
x++;
else if (sushi == 2)
y++;
else
z++;
}
printDouble(solve(x, y, z, n));
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(10);
int n;
cin >> n;
vi cnt(4);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
cnt[a]++;
}
vector<vector<vector<double>>> dp(
cnt[1] + 1,
vector<vector<double>>(cnt[2] + 1, vector<double>(cnt[3] + 1)));
function<double(int, int, int)> dfs = [&](int i, int j, int k) {
if (i + j + k == 0)
return 0.0;
if (dp[i][j][k])
return dp[i][j][k];
double ret = (i ? dfs(i - 1, j, k) * i / (i + j + k) : 0) +
(j ? dfs(i + 1, j - 1, k) * j / (i + j + k) : 0) +
(k ? dfs(i, j + 1, k - 1) * k / (i + j + k) : 0) +
n / double(i + j + k);
dp[i][j][k] = ret;
return ret;
};
cout << dfs(cnt[1], cnt[2], cnt[3]) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(10);
int n;
cin >> n;
vi cnt(4);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
cnt[a]++;
}
vector<vector<vector<double>>> dp(
301, vector<vector<double>>(301, vector<double>(301)));
function<double(int, int, int)> dfs = [&](int i, int j, int k) {
if (i + j + k == 0)
return 0.0;
if (dp[i][j][k])
return dp[i][j][k];
double ret = (i ? dfs(i - 1, j, k) * i / (i + j + k) : 0) +
(j ? dfs(i + 1, j - 1, k) * j / (i + j + k) : 0) +
(k ? dfs(i, j + 1, k - 1) * k / (i + j + k) : 0) +
n / double(i + j + k);
dp[i][j][k] = ret;
return ret;
};
cout << dfs(cnt[1], cnt[2], cnt[3]) << endl;
} | replace | 24 | 26 | 24 | 25 | 0 | |
p03169 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
static int c[3];
for (int i = 0, t; i < N; ++i) {
cin >> t;
++c[t - 1];
}
static double dp[301][601][901];
/*function<double(int, int, int)> dfs = [&](int a, int b, int c) {
if (a + b + c == 0) return 0.0;
if (vis[a][b][c]) return dp[a][b][c];
vis[a][b][c] = 1;
if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N;
if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N;
if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N;
int d = N - a - b - c;
// if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N;
return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d);
};*/
for (int i = 0; i < c[2] + 1; ++i) {
for (int j = 0; j < c[1] + c[2] + 1; ++j) {
for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) {
if (i + j + k == 0)
continue;
if (i)
dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N;
if (j)
dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N;
if (k)
dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N;
int l = N - i - j - k;
dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l);
}
}
}
cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
static int c[3];
for (int i = 0, t; i < N; ++i) {
cin >> t;
++c[t - 1];
}
static double dp[301][301][301];
/*function<double(int, int, int)> dfs = [&](int a, int b, int c) {
if (a + b + c == 0) return 0.0;
if (vis[a][b][c]) return dp[a][b][c];
vis[a][b][c] = 1;
if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N;
if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N;
if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N;
int d = N - a - b - c;
// if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N;
return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d);
};*/
for (int i = 0; i < c[2] + 1; ++i) {
for (int j = 0; j < c[1] + c[2] + 1; ++j) {
for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) {
if (i + j + k == 0)
continue;
if (i)
dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N;
if (j)
dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N;
if (k)
dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N;
int l = N - i - j - k;
dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l);
}
}
}
cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | MLE | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cin.exceptions(cin.failbit)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(), v.end()
#define endl '\n'
#define show(a) \
for (auto i : a) \
cout << i << " "; \
cout << endl
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> mypair;
typedef priority_queue<int> max_heap;
typedef priority_queue<mypair, vector<mypair>, greater<mypair>> min_heap;
const int mod = 1000000007;
const int inf = 1e9 + 100;
const int N = 300;
ld dp[N + 1][N + 1][N + 1];
int a[4];
int main() {
boost;
ld n;
cin >> n;
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if (i or j or k)
dp[i][j][k] =
(n / (ld(i + j + k))) +
((k > 0) ? (dp[i][j + 1][k - 1] * k) / (ld(i + j + k)) : 0.0) +
((j > 0) ? (dp[i + 1][j - 1][k] * j) / (ld(i + j + k)) : 0.0) +
((i > 0) ? (dp[i - 1][j][k] * i) / (ld(i + j + k)) : 0.00);
// cout<<i<<" "<<j<<" "<<k<<" :
// "<<fixed<<setprecision(15)<<dp[i][j][k]<<endl;
// check((n/(ld(i+j+k))));
}
}
}
int cn = int(n);
while (cn--) {
int t;
cin >> t;
a[t]++;
}
cout << fixed << setprecision(15) << dp[a[1]][a[2]][a[3]];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cin.exceptions(cin.failbit)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(), v.end()
#define endl '\n'
#define show(a) \
for (auto i : a) \
cout << i << " "; \
cout << endl
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> mypair;
typedef priority_queue<int> max_heap;
typedef priority_queue<mypair, vector<mypair>, greater<mypair>> min_heap;
const int mod = 1000000007;
const int inf = 1e9 + 100;
const int N = 315;
ld dp[N + 1][N + 1][N + 1];
int a[4];
int main() {
boost;
ld n;
cin >> n;
for (int k = 0; k <= n; k++) {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= n; i++) {
if (i or j or k)
dp[i][j][k] =
(n / (ld(i + j + k))) +
((k > 0) ? (dp[i][j + 1][k - 1] * k) / (ld(i + j + k)) : 0.0) +
((j > 0) ? (dp[i + 1][j - 1][k] * j) / (ld(i + j + k)) : 0.0) +
((i > 0) ? (dp[i - 1][j][k] * i) / (ld(i + j + k)) : 0.00);
// cout<<i<<" "<<j<<" "<<k<<" :
// "<<fixed<<setprecision(15)<<dp[i][j][k]<<endl;
// check((n/(ld(i+j+k))));
}
}
}
int cn = int(n);
while (cn--) {
int t;
cin >> t;
a[t]++;
}
cout << fixed << setprecision(15) << dp[a[1]][a[2]][a[3]];
return 0;
} | replace | 27 | 28 | 27 | 28 | -11 | |
p03169 | C++ | Runtime Error | // By TheOneYouWant
#pragma GCC optimize("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a, 0, sizeof(a))
#define testcase(t) \
int t; \
cin >> t; \
while (t--)
#define forstl(i, v) for (auto &i : v)
#define forn(i, e) for (int i = 0; i < e; i++)
#define forsn(i, s, e) for (int i = s; i < e; i++)
#define rforn(i, s) for (int i = s; i >= 0; i--)
#define rforsn(i, s, e) for (int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr << #x << " = " << x << endl
#define dbg2(x, y) \
cerr << #x << " = " << x << " & " << #y << " = " << y << endl;
#define dbgstl32(v) \
cerr << #v << " = \n"; \
{ \
int c = 0; \
forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \
} \
cerr << endl
#define dbgstlp32(v) \
cerr << #v << " = \n"; \
{ \
int c = 0; \
forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \
<< it.se << ln; \
} \
cerr << endl
#define dbgarr(v, s, e) \
cerr << #v << " = "; \
forsn(i, s, e) cerr << v[i] << ", "; \
cerr << endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &c, pair<T1, T2> &v) {
c << "(" << v.fi << "," << v.se << ")";
return c;
}
template <template <class...> class TT, class... T>
ostream &operator<<(ostream &out, TT<T...> &c) {
out << "{ ";
forstl(x, c) out << x << " ";
out << "}";
return out;
}
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll, ll> p64;
typedef pair<int, int> p32;
typedef pair<int, p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int, int> m32;
const ll MOD = 1e9 + 7, LIM = 302;
const ld EPS = 1e-9;
ld dp[300][300][300];
int n;
ld answer(int a, int b, int c) {
// cout<<a<<" "<<b<<" "<<c<<ln;
if (a < 0 || b < 0 || c < 0)
return 0;
if (a == 0 && b == 0 && c == 0)
return 0;
ld ans = 0;
if (dp[a][b][c] + EPS >= 0)
return dp[a][b][c];
ans = n + a * answer(a - 1, b, c) + b * answer(a + 1, b - 1, c) +
c * answer(a, b + 1, c - 1);
// cout<<ans<<ln;
ans = ans / (a + b + c);
return dp[a][b][c] = ans;
}
int main() {
fastio;
cin >> n;
int a[3] = {0};
forn(i, LIM) {
forn(j, LIM) { forn(k, LIM) dp[i][j][k] = -1; }
}
forn(i, n) {
int x;
cin >> x;
a[x - 1]++;
}
cout << fixed << setprecision(12) << ln;
ld x = answer(a[0], a[1], a[2]);
cout << x << ln;
return 0;
} | // By TheOneYouWant
#pragma GCC optimize("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a, 0, sizeof(a))
#define testcase(t) \
int t; \
cin >> t; \
while (t--)
#define forstl(i, v) for (auto &i : v)
#define forn(i, e) for (int i = 0; i < e; i++)
#define forsn(i, s, e) for (int i = s; i < e; i++)
#define rforn(i, s) for (int i = s; i >= 0; i--)
#define rforsn(i, s, e) for (int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr << #x << " = " << x << endl
#define dbg2(x, y) \
cerr << #x << " = " << x << " & " << #y << " = " << y << endl;
#define dbgstl32(v) \
cerr << #v << " = \n"; \
{ \
int c = 0; \
forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \
} \
cerr << endl
#define dbgstlp32(v) \
cerr << #v << " = \n"; \
{ \
int c = 0; \
forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \
<< it.se << ln; \
} \
cerr << endl
#define dbgarr(v, s, e) \
cerr << #v << " = "; \
forsn(i, s, e) cerr << v[i] << ", "; \
cerr << endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &c, pair<T1, T2> &v) {
c << "(" << v.fi << "," << v.se << ")";
return c;
}
template <template <class...> class TT, class... T>
ostream &operator<<(ostream &out, TT<T...> &c) {
out << "{ ";
forstl(x, c) out << x << " ";
out << "}";
return out;
}
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll, ll> p64;
typedef pair<int, int> p32;
typedef pair<int, p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int, int> m32;
const ll MOD = 1e9 + 7, LIM = 302;
const ld EPS = 1e-9;
ld dp[LIM][LIM][LIM];
int n;
ld answer(int a, int b, int c) {
// cout<<a<<" "<<b<<" "<<c<<ln;
if (a < 0 || b < 0 || c < 0)
return 0;
if (a == 0 && b == 0 && c == 0)
return 0;
ld ans = 0;
if (dp[a][b][c] + EPS >= 0)
return dp[a][b][c];
ans = n + a * answer(a - 1, b, c) + b * answer(a + 1, b - 1, c) +
c * answer(a, b + 1, c - 1);
// cout<<ans<<ln;
ans = ans / (a + b + c);
return dp[a][b][c] = ans;
}
int main() {
fastio;
cin >> n;
int a[3] = {0};
forn(i, LIM) {
forn(j, LIM) { forn(k, LIM) dp[i][j][k] = -1; }
}
forn(i, n) {
int x;
cin >> x;
a[x - 1]++;
}
cout << fixed << setprecision(12) << ln;
ld x = answer(a[0], a[1], a[2]);
cout << x << ln;
return 0;
} | replace | 92 | 93 | 92 | 93 | -11 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
double dp[101][101][101];
int n;
double solve(int i, int j, int k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (!(i | j | k))
return 0.0;
double res = 0.0;
if (i)
res += solve(i - 1, j, k) * i;
if (j)
res += solve(i + 1, j - 1, k) * j;
if (k)
res += solve(i, j + 1, k - 1) * k;
res += n;
res /= (i + j + k);
return dp[i][j][k] = res;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int a, c[4] = {0};
for (int i = 0; i < n; i++) {
cin >> a;
c[a]++;
// if(a<3)c[3-a]++;
}
memset(dp, -1, sizeof(dp));
doublecout(solve(c[1], c[2], c[3]));
return 0;
}
| #include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
double dp[301][301][301];
int n;
double solve(int i, int j, int k) {
if (dp[i][j][k] >= 0)
return dp[i][j][k];
if (!(i | j | k))
return 0.0;
double res = 0.0;
if (i)
res += solve(i - 1, j, k) * i;
if (j)
res += solve(i + 1, j - 1, k) * j;
if (k)
res += solve(i, j + 1, k - 1) * k;
res += n;
res /= (i + j + k);
return dp[i][j][k] = res;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int a, c[4] = {0};
for (int i = 0; i < n; i++) {
cin >> a;
c[a]++;
// if(a<3)c[3-a]++;
}
memset(dp, -1, sizeof(dp));
doublecout(solve(c[1], c[2], c[3]));
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03169 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double memo[305][305][305];
double dp(ll s1, ll s2, ll s3, ll empty, ll full) {
if (s1 == 0 && s2 == 0 && s3 == 0)
return 0;
if (memo[s1][s2][s3] != -1)
return memo[s1][s2][s3];
double ret = 0;
ret = (double)full *
(1 + ((double)s1 * dp(s1 - 1, s2, s3, empty + 1, full) +
(double)s2 * dp(s1 + 1, s2 - 1, s3, empty, full) +
(double)s3 * dp(s1, s2 + 1, s3 - 1, empty, full)) /
full) /
(double)(full - empty);
return memo[s1][s2][s3] = ret;
}
ll sushi[5];
int main() {
for (int i = 0; i <= 300; i++) {
for (int j = 0; j <= 300; j++) {
for (int k = 0; k <= 300; k++) {
memo[i][j][k] = -1;
}
}
}
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
ll num;
scanf("%lld", &num);
sushi[num]++;
}
double ans = dp(sushi[1], sushi[2], sushi[3], 0, n);
printf("%.12lf\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double memo[305][305][305];
double dp(ll s1, ll s2, ll s3, ll empty, ll full) {
if (s1 == 0 && s2 == 0 && s3 == 0)
return 0;
if (memo[s1][s2][s3] != -1)
return memo[s1][s2][s3];
double ret = 0;
double temp1 = 0, temp2 = 0, temp3 = 0;
if (s1 != 0) {
temp1 = (double)s1 * dp(s1 - 1, s2, s3, empty + 1, full);
}
if (s2 != 0) {
temp2 = (double)s2 * dp(s1 + 1, s2 - 1, s3, empty, full);
}
if (s3 != 0) {
temp3 = (double)s3 * dp(s1, s2 + 1, s3 - 1, empty, full);
}
ret = (double)full * (1 + (temp1 + temp2 + temp3) / full) /
(double)(full - empty);
return memo[s1][s2][s3] = ret;
}
ll sushi[5];
int main() {
for (int i = 0; i <= 300; i++) {
for (int j = 0; j <= 300; j++) {
for (int k = 0; k <= 300; k++) {
memo[i][j][k] = -1;
}
}
}
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
ll num;
scanf("%lld", &num);
sushi[num]++;
}
double ans = dp(sushi[1], sushi[2], sushi[3], 0, n);
printf("%.12lf\n", ans);
} | replace | 13 | 19 | 13 | 24 | -11 | |
p03170 | C++ | Runtime Error | #include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>>
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define FRE \
freopen("explicit.in", "r", stdin); \
freopen("explicit.out", "w", stdout)
#define mp make_pair
#define pll pair<lli, lli>
#define vll vector<lli>
#define pq2 priority_queue<pair<lli, lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define ld long double
const long double pi = 3.1415926535898;
#define dec greater<lli>()
// const lli mod=1000000007;
const lli mod = 100000000;
using namespace std;
lli lcm(lli a, lli b) { return ((a * b) / __gcd(a, b)); }
lli modpower(lli a, lli b) {
if (b == 0)
return 1;
lli c = modpower(a, b / 2) % mod;
if (b % 2)
return (((a * c) % mod) * c) % mod;
else
return (c * c) % mod;
}
lli power(lli a, lli b) {
if (b == 0)
return 1;
lli c = power(a, b / 2);
if (b % 2)
return (a * c * c);
else
return c * c;
}
lli sieve(int n) {
bool qrr[n + 1];
for (int i = 0; i <= n; i++)
qrr[i] = 1;
qrr[0] = 0;
qrr[1] = 0;
for (int i = 2; i * i <= n; i++) {
if (qrr[i] == 1) {
for (int j = i * i; j <= n; j += i) {
qrr[j] = 0;
}
}
}
return 0;
}
int main() {
fio;
lli n, k;
cin >> n >> k;
lli a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
bool b[k + 1];
memset(b, 0, sizeof(b));
for (int i = 0; i <= k; i++) {
if (b[i] == 1)
continue;
for (int j = 0; j < n; j++)
b[i + a[j]] = 1;
}
if (b[k] == 1)
cout << "First";
else
cout << "Second";
return 0;
} | #include <bits/stdc++.h>
#define lli long long int
#define vec2 vector<vector<lli>>
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define FRE \
freopen("explicit.in", "r", stdin); \
freopen("explicit.out", "w", stdout)
#define mp make_pair
#define pll pair<lli, lli>
#define vll vector<lli>
#define pq2 priority_queue<pair<lli, lli>>
#define f first
#define s second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define ld long double
const long double pi = 3.1415926535898;
#define dec greater<lli>()
// const lli mod=1000000007;
const lli mod = 100000000;
using namespace std;
lli lcm(lli a, lli b) { return ((a * b) / __gcd(a, b)); }
lli modpower(lli a, lli b) {
if (b == 0)
return 1;
lli c = modpower(a, b / 2) % mod;
if (b % 2)
return (((a * c) % mod) * c) % mod;
else
return (c * c) % mod;
}
lli power(lli a, lli b) {
if (b == 0)
return 1;
lli c = power(a, b / 2);
if (b % 2)
return (a * c * c);
else
return c * c;
}
lli sieve(int n) {
bool qrr[n + 1];
for (int i = 0; i <= n; i++)
qrr[i] = 1;
qrr[0] = 0;
qrr[1] = 0;
for (int i = 2; i * i <= n; i++) {
if (qrr[i] == 1) {
for (int j = i * i; j <= n; j += i) {
qrr[j] = 0;
}
}
}
return 0;
}
int main() {
fio;
lli n, k;
cin >> n >> k;
lli a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
bool b[k + 1];
memset(b, 0, sizeof(b));
for (int i = 0; i <= k; i++) {
if (b[i] == 1)
continue;
for (int j = 0; j < n; j++) {
if (i + a[j] <= k)
b[i + a[j]] = 1;
}
}
if (b[k] == 1)
cout << "First";
else
cout << "Second";
return 0;
} | replace | 71 | 73 | 71 | 75 | 0 | |
p03170 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
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<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<double>> vvd;
typedef vector<vector<string>> vvs;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
// cout<<fixed<<setprecision(10);
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;
}
template <class T> void debug(T v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
gearup;
ll n, k;
cin >> n >> k;
vl a(n);
rep(i, n) cin >> a[i];
vb dp(n + 100);
rep1(i, k + 1) {
rep(j, n) {
if (i - a[j] >= 0)
dp[i] = (dp[i] | !dp[i - a[j]]);
}
}
if (dp[k])
out("First");
else
out("Second");
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
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<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<double>> vvd;
typedef vector<vector<string>> vvs;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
// cout<<fixed<<setprecision(10);
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;
}
template <class T> void debug(T v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
gearup;
ll n, k;
cin >> n >> k;
vl a(n);
rep(i, n) cin >> a[i];
vb dp(k + 100, false);
rep1(i, k + 1) {
rep(j, n) {
if (i - a[j] >= 0)
dp[i] = (dp[i] | !dp[i - a[j]]);
}
}
if (dp[k])
out("First");
else
out("Second");
}
| replace | 65 | 66 | 65 | 66 | 0 | |
p03170 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
int i;
for (i = 0; i < n; i++)
cin >> a[i];
int dp[n + 1];
memset(dp, 0, sizeof(dp));
for (i = 0; i <= k; i++) {
for (int j = 0; j < n; j++) {
if (i >= a[j] && dp[i - a[j]] == 0)
dp[i] = 1;
}
}
cout << (dp[k] == 1 ? "First" : "Second") << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
int i;
for (i = 0; i < n; i++)
cin >> a[i];
int dp[k + 1];
memset(dp, 0, sizeof(dp));
for (i = 0; i <= k; i++) {
for (int j = 0; j < n; j++) {
if (i >= a[j] && dp[i - a[j]] == 0)
dp[i] = 1;
}
}
cout << (dp[k] == 1 ? "First" : "Second") << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03170 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 2, K = 1e5 + 5;
int a[MAXN];
bool dp[K];
int n, k;
void input();
void solve();
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
input();
solve();
return 0;
}
void input() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
}
void solve() {
for (int i = 1; i <= k; i++)
for (int j = 0; j < n; j++)
if (a[j] >= i && dp[i - a[j]] == false)
dp[i] = true;
dp[k] ? cout << "First" << endl : cout << "Second" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 2, K = 1e5 + 5;
int a[MAXN];
bool dp[K];
int n, k;
void input();
void solve();
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
input();
solve();
return 0;
}
void input() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
}
void solve() {
for (int i = 1; i <= k; i++)
for (int j = 0; j < n; j++)
if (a[j] <= i && dp[i - a[j]] == false)
dp[i] = true;
dp[k] ? cout << "First" << endl : cout << "Second" << endl;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03170 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
// dp[i] : TRUE if first player wins with i stones left
vector<bool> dp(k + 1);
for (int i = 0; i <= k; i++) {
for (int x : a) {
if (i >= x && !dp[i - k])
dp[i] = true;
}
}
cout << (dp[k] ? "First" : "Second") << '\n';
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
// dp[i] : TRUE if first player wins with i stones left
vector<bool> dp(k + 1);
for (int i = 0; i <= k; i++) {
for (int x : a) {
if (i >= x && !dp[i - x])
dp[i] = true;
}
}
cout << (dp[k] ? "First" : "Second") << '\n';
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03170 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> memo(1e5 + 5, -1);
int dp(vector<int> &v, int i) {
if (i == 0)
return 0;
memo[i] = 0;
for (int e : v) {
if (e <= i) {
if (!dp(v, i - e))
memo[i] = 1;
}
}
return memo[i];
}
signed main() {
cin.tie(0);
cin.sync_with_stdio();
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int &i : v)
cin >> i;
cout << (dp(v, k) ? "First" : "Second");
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> memo(1e5 + 5, -1);
int dp(vector<int> &v, int i) {
if (i == 0)
return 0;
if (memo[i] != -1)
return memo[i];
memo[i] = 0;
for (int e : v) {
if (e <= i) {
if (!dp(v, i - e))
memo[i] = 1;
}
}
return memo[i];
}
signed main() {
cin.tie(0);
cin.sync_with_stdio();
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int &i : v)
cin >> i;
cout << (dp(v, k) ? "First" : "Second");
}
| insert | 8 | 8 | 8 | 10 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.