Submission #18296197


Source Code Expand

Copy
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

ll div(ll& d, int x) {
    ll ret = 0;
    while(d % x == 0) {
        ++ret;
        d /= x;
    }
    return ret;
}

void solve() {
    ll n, d;
    cin >> n >> d;
    ll n2 = div(d, 2);
    ll n3 = div(d, 3);
    ll n5 = div(d, 5);
    if(d > 1) {
        cout << 0.0 << endl;
        return;
    }
    using vvld = vector<vld>;
    using vvvld = vector<vvld>;
    vvvld dp(n2+1, vvld(n3+1, vld(n5+1, 0.0)));
    dp[0][0][0] = 1.0;
    while(n--) {
        vvvld dp2(n2+1, vvld(n3+1, vld(n5+1, 0.0)));
        rep(i, n2+1) rep(j, n3+1) rep(k, n5+1) {
            ll i1 = min(i+1, n2);
            ll i2 = min(i+2, n2);
            ll j1 = min(j+1, n3);
            ll k1 = min(k+1, n5);
            ld add = dp[i][j][k] / 6.0;
            dp2[i][j][k] += add;
            dp2[i1][j][k] += add;
            dp2[i][j1][k] += add;
            dp2[i2][j][k] += add;
            dp2[i][j][k1] += add;
            dp2[i1][j1][k] += add;
        }
        dp = dp2;
    }
    cout << dp[n2][n3][n5] << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Submission Info

Submission Time
Task D - サイコロ
User Yoko_303
Language C++ (GCC 9.2.1)
Score 4
Code Size 2431 Byte
Status AC
Exec Time 10 ms
Memory 3824 KB

Judge Result

Set Name All
Score / Max Score 4 / 4
Status
AC × 13
Set Name Test Cases
All 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 90, 91
Case Name Status Exec Time Memory
00 AC 3 ms 3696 KB
01 AC 5 ms 3664 KB
02 AC 4 ms 3824 KB
03 AC 4 ms 3724 KB
04 AC 3 ms 3672 KB
05 AC 5 ms 3720 KB
06 AC 10 ms 3812 KB
07 AC 7 ms 3800 KB
08 AC 4 ms 3760 KB
09 AC 2 ms 3752 KB
10 AC 2 ms 3748 KB
90 AC 3 ms 3680 KB
91 AC 2 ms 3660 KB