QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345255 | #3413. Card Trick | PetroTarnavskyi# | AC ✓ | 338ms | 22012kb | C++20 | 1.6kb | 2024-03-06 18:05:48 | 2024-03-06 18:05:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 1147;
const int SZ = 11;
const int MOD = (1 << 11) - 1;
db dp[N][1 << SZ];
int n;
int read()
{
string s;
cin >> s;
if(SZ(s) == 2 || ('0' <= s[0] && s[0] <= '9'))
return stoi(s);
return 10 + (s == "A");
}
bool hasBit(int mask, int bit)
{
return (mask >> bit) & 1;
}
void solve()
{
VI poses;
int pos;
cin >> pos;
pos--;
poses.PB(pos);
FOR(i, 0, n)
{
poses.PB(poses.back() + read());
}
n = poses.back();
poses.pop_back();
VI ok(n);
for(int i : poses)
ok[i] = 1;
FOR(i, 0, n + 15)
FOR(mask, 0, 1 << SZ)
dp[i][mask] = 0;
dp[n][0] = 1;
RFOR(i, n, 0)
{
FOR(mask, 0, 1 << SZ)
{
int nmask = (mask << 1) & MOD;
if(ok[i])
{
dp[i][nmask + 1] += dp[i + 1][mask];
continue;
}
FOR(move, 2, 12)
{
db prob = 1.0 / 13;
if(move == 10)
prob *= 4;
dp[i][nmask + hasBit(mask, move - 1)] += dp[i + 1][mask] * prob;
}
}
}
db ans = 0;
FOR(i, 0, 10)
{
FOR(mask, 0, 1 << SZ)
{
if(hasBit(mask, 0))
ans += dp[i][mask];
}
}
cout << fixed << setprecision(15) << ans / 10 << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
while(cin >> n)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 4348kb
input:
1 10 2 1 10 3 1 10 4 1 10 5 1 10 6 1 10 7 1 10 8 1 10 9 1 10 10 1 10 J 1 10 Q 1 10 K 1 10 A
output:
0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531 0.174892335702531
result:
ok 13 numbers
Test #2:
score: 0
Accepted
time: 25ms
memory: 21808kb
input:
100 10 A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A 100 10 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
0.999999748730367 0.999997159803874 0.100000000000000 0.100000000000000 0.100000000000000 0.100000000000000 0.100000000000000 0.100000000000000 0.107692307692308 0.115384615384615 0.123668639053254 0.132544378698225 0.142057350933091 0.152253072371416 0.163180560904730 0.174892335702531 0.1748923357...
result:
ok 30 numbers
Test #3:
score: 0
Accepted
time: 48ms
memory: 22012kb
input:
100 10 A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A 100 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
output:
0.999999748730367 0.999980108579517 0.999997159803874 0.999999496502643
result:
ok 4 numbers
Test #4:
score: 0
Accepted
time: 106ms
memory: 17612kb
input:
44 4 Q 10 10 4 K 10 7 10 5 K 10 3 Q 4 10 10 8 10 10 J 10 9 10 9 Q 4 6 10 10 2 A 10 K 3 5 10 3 10 Q 10 3 10 10 10 97 6 10 10 10 3 Q 10 5 10 Q J 5 9 A A 10 10 K 5 10 J A K 10 3 10 7 10 J 10 10 A 10 2 10 Q 10 10 10 10 10 10 10 J 10 10 J 9 10 10 10 2 5 5 9 J 5 10 10 10 10 7 6 10 6 A 2 7 10 7 J 10 K 10 4...
output:
0.995962646915840 0.999993954412715 0.999848612624549 0.999844914308893 0.999955982983904 0.998396182275016 0.999749222331155 0.999889704864482 0.992585526272178 0.998537340306249 0.999951546352956 0.993866350807435 0.999870791103845
result:
ok 13 numbers
Test #5:
score: 0
Accepted
time: 338ms
memory: 7220kb
input:
16 6 9 10 6 10 8 8 6 Q 10 6 10 10 K 7 10 10 11 3 10 10 10 10 10 10 10 10 10 6 10 20 8 K Q 5 10 5 6 10 10 10 5 J 2 3 10 8 10 9 10 10 10 4 9 K 4 6 10 13 8 10 10 10 10 9 2 10 10 4 6 J 10 10 18 6 9 2 4 J 6 Q 3 10 9 10 8 A A 5 Q 10 5 8 1 2 9 10 3 10 10 A 10 10 10 10 9 10 7 3 6 10 10 6 16 1 2 10 10 5 9 9 ...
output:
0.875923576852685 0.707915756424560 0.924457340283070 0.423515145362392 0.799492177276266 0.916096648012267 0.100000000000000 0.684343271576078 0.301716069465084 0.881504253418978 0.894562550448615 0.731920056723172 0.515203046007455 0.785576395001778 0.922827752459239 0.842803302993221 0.2855292181...
result:
ok 226 numbers
Test #6:
score: 0
Accepted
time: 3ms
memory: 4712kb
input:
5 2 2 3 5 3 Q 1 1 A 1 2 A 1 10 A 6 1 2 2 2 2 2 2 7 1 2 2 2 2 2 2 2 3 10 10 J K
output:
0.487137775702333 0.100000000000000 0.100000000000000 0.174892335702531 0.583071321032177 0.627922961111575 0.334656582760327
result:
ok 7 numbers