Submission #1797160


Source Code Expand

#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_N 100
#define MAX_A 60
#define MAX_B 40
#define MAX_C 30
#define p double(1) / double(6)
// dp[n][a][b][c] : サイコロをn回振った時に素因数2,3,5がそれぞれa,b,c個以上含まれる確率
double dp[MAX_N][MAX_A][MAX_B][MAX_C];

int main(int argc, const char * argv[]) {
    
    int N;
    long long D;
    scanf("%d %lld", &N, &D);
    
    const long long prime[] = {2, 3, 5};
    int r[3] = {0, 0, 0};  // r[i] : prime[i]が含まれる個数
    for (int i = 0; i < 3; i++) {
        while (D % prime[i] == 0) {
            D = D / prime[i];
            r[i] += 1;
        }
    }
    if (D != 1) {
        printf("%f\n", 0.0);
        return 0;
    }
    // dp[n][a][b][c] : サイコロをn回振った時に素因数2,3,5がそれぞれa,b,c個以上含まれる確率
    //double dp[MAX_N][MAX_A][MAX_B][MAX_C];
    for (int n = 0; n < N+1; n++) {
        for (int a = 0; a < r[0]+1; a++) {
            for (int b = 0; b < r[1]+1; b++) {
                for (int c = 0; c < r[2]+1; c++) {
                    if (n == 0) {
                        if (a == 0 && b == 0 && c == 0) {
                            dp[n][a][b][c] = double(1);
                        } else {
                            dp[n][a][b][c] = double(0);
                        }
                    } else {
                        dp[n][a][b][c] =
                              p * dp[n-1][a][b][c]
                            + p * dp[n-1][max(a-1, 0)][b][c]
                            + p * dp[n-1][a][max(b-1, 0)][c]
                            + p * dp[n-1][max(a-2, 0)][b][c]
                            + p * dp[n-1][a][b][max(c-1, 0)]
                            + p * dp[n-1][max(a-1, 0)][max(b-1, 0)][c];
                    }
                }
            }
        }
    }
    
    printf("%f\n", dp[N][r[0]][r[1]][r[2]]);
    
    return 0;
}

Submission Info

Submission Time
Task D - サイコロ
User habara_k
Language C++14 (GCC 5.4.1)
Score 4
Code Size 1985 Byte
Status AC
Exec Time 11 ms
Memory 49664 KB

Compile Error

./Main.cpp: In function ‘int main(int, const char**)’:
./Main.cpp:16:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &N, &D);
                             ^

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 4 ms 16512 KB
01 AC 10 ms 45440 KB
02 AC 9 ms 41216 KB
03 AC 5 ms 18688 KB
04 AC 4 ms 18816 KB
05 AC 11 ms 49664 KB
06 AC 11 ms 45952 KB
07 AC 10 ms 43904 KB
08 AC 3 ms 9088 KB
09 AC 9 ms 41728 KB
10 AC 1 ms 128 KB
90 AC 1 ms 128 KB
91 AC 1 ms 128 KB