Submission #727012


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

//2,3,5の素因数の数
double dp[100][100][100];
double newdp[100][100][100];


int main()
{
    int n;
    ll d;
    cin >>n >>d;

    int X=0,Y=0,Z=0;
    while(d%2==0){d/=2; ++X;}
    while(d%3==0){d/=3; ++Y;}
    while(d%5==0){d/=5; ++Z;}

    if(d>1) printf("0\n");
    else
    {
        memset(dp,0,sizeof(dp));
        dp[0][0][0]=1;

        int add[7][3]={0};
        add[2][0]=1;
        add[3][1]=1;
        add[4][0]=2;
        add[5][2]=1;
        add[6][0]=1;
        add[6][1]=1;

        //サイコロi個目
        rep(i,n)
        {
            memset(newdp,0,sizeof(newdp));
            //jの目が出るとき
            for(int j=1; j<=6; ++j)
            {
                rep(x,X+1)rep(y,Y+1)rep(z,Z+1)
                {
                    int nx=min(x+add[j][0],X);
                    int ny=min(y+add[j][1],Y);
                    int nz=min(z+add[j][2],Z);
                    //printf("now %d: (%d,%d,%d) -> (%d,%d,%d) add %lf\n", j,x,y,z,nx,ny,nz, dp[x][y][z]/6.0);
                    newdp[nx][ny][nz]+=dp[x][y][z]/6.0;
                }
            }

            rep(x,100)rep(y,100)rep(z,100) dp[x][y][z]=newdp[x][y][z];
        }

        printf("%.10lf\n", dp[X][Y][Z]);
    }
    return 0;
}

Submission Info

Submission Time
Task D - サイコロ
User imulan
Language C++11 (GCC 4.8.1)
Score 4
Code Size 1619 Byte
Status AC
Exec Time 381 ms
Memory 16424 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 170 ms 16348 KB
01 AC 356 ms 16420 KB
02 AC 329 ms 16412 KB
03 AC 187 ms 16420 KB
04 AC 180 ms 16420 KB
05 AC 381 ms 16416 KB
06 AC 353 ms 16420 KB
07 AC 335 ms 16420 KB
08 AC 117 ms 16412 KB
09 AC 324 ms 16412 KB
10 AC 25 ms 672 KB
90 AC 62 ms 16300 KB
91 AC 67 ms 16424 KB