QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414404 | #5646. Uniform Chemistry | Andycipation | AC ✓ | 3ms | 3984kb | C++20 | 1.5kb | 2024-05-18 22:46:29 | 2024-05-18 22:46:31 |
Judging History
answer
/*
* author: ADMathNoob
* created: 05/17/24 20:37:57
* problem: https://qoj.ac/problem/5646
*/
/*
Comments about problem:
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
// prob that i gets to n from doing the t-th fusion
vector<vector<double>> prob(m, vector<double>(n));
for (int i = 0; i < m; i++) {
int s;
cin >> s;
--s;
vector<vector<double>> dp(n, vector<double>(n));
dp[0][s] = 1;
for (int t = 0; t < n - 1; t++) {
for (int x = 0; x < n - 1; x++) {
double p = 1.0 / (n - 1 - x);
for (int y = x + 1; y < n; y++) {
dp[t + 1][y] += dp[t][x] * p;
}
}
}
for (int t = 0; t < n; t++) {
prob[i][t] = dp[t][n - 1];
}
}
vector<vector<double>> suf(m, vector<double>(n + 1));
for (int i = 0; i < m; i++) {
for (int t = n - 1; t >= 0; t--) {
suf[i][t] = suf[i][t + 1] + prob[i][t];
}
assert(abs(suf[i][0] - 1.0) < 1e-8);
}
for (int i = 0; i < m; i++) {
double ret = 0;
for (int w = 0; w < n; w++) {
double others = 1.0;
for (int j = 0; j < m; j++) {
if (j == i) {
continue;
}
others *= suf[j][w];
}
ret += prob[i][w] * others;
}
cout.precision(10);
cout << fixed;
cout << ret << " \n"[i == m - 1];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3776kb
input:
2 3 1 1 1
output:
1.0000000000 1.0000000000 1.0000000000
result:
ok 3 numbers, max absolute error 0
Test #2:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
3 3 1 1 2
output:
0.5000000000 0.5000000000 1.0000000000
result:
ok 3 numbers, max absolute error 0
Test #3:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
3 3 1 1 1
output:
0.6250000000 0.6250000000 0.6250000000
result:
ok 3 numbers, max absolute error 0
Test #4:
score: 0
Accepted
time: 2ms
memory: 3876kb
input:
100 7 1 2 4 8 16 32 64
output:
0.1785934686 0.1798104547 0.1823067706 0.1875653656 0.1993004295 0.2293563224 0.3487225179
result:
ok 7 numbers, max absolute error 5.00000014e-10
Test #5:
score: 0
Accepted
time: 3ms
memory: 3960kb
input:
100 10 28 58 38 53 1 19 66 60 68 31
output:
0.1320312447 0.1954783754 0.1472783260 0.1801694505 0.1044952834 0.1211120330 0.2277441756 0.2025068243 0.2379248933 0.1362072688
result:
ok 10 numbers, max absolute error 4.86312102e-11
Test #6:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
100 10 86 50 88 42 88 20 29 83 89 34
output:
0.2633535451 0.0960168456 0.2973462847 0.0852667612 0.2973462847 0.0658616476 0.0724970696 0.2259810388 0.3184278057 0.0768756085
result:
ok 10 numbers, max absolute error 4.29709601e-11
Test #7:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
2 1 1
output:
1.0000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
10 3 4 6 7
output:
0.3721354167 0.5234953704 0.6678433642
result:
ok 3 numbers, max absolute error 3.33333916e-11
Test #9:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
20 10 6 6 9 3 14 15 13 8 6 11
output:
0.1519177372 0.1519177372 0.1871464692 0.1284275431 0.3162342034 0.3704345703 0.2766977534 0.1735820763 0.1519177372 0.2226133627
result:
ok 10 numbers, max absolute error 4.67095806e-11
Test #10:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
99 2 40 55
output:
0.5366140249 0.6295926938
result:
ok 2 numbers, max absolute error 4.64274175e-11
Test #11:
score: 0
Accepted
time: 3ms
memory: 3832kb
input:
99 9 86 68 85 83 75 70 71 73 70
output:
0.2945741171 0.1492344902 0.2780294762 0.2505140657 0.1824354299 0.1572638754 0.1616578500 0.1713381716 0.1572638754
result:
ok 9 numbers, max absolute error 4.65337768e-11