Submission #3013228


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

double dp[101][70][50][35];

int a, b, c;

int main()
{
	ll N, D;
	cin >> N >> D;
	double p[7];
	rep(i, 7) p[i] = (double) i / 6;
	while(D % 2 == 0) {
		a++;
		D /= 2;
	}
	while(D % 3 == 0) {
		b++;
		D /= 3;
	}
	while(D % 5 == 0) {
		c++;
		D /= 5;
	}
	if (D != 1) {
		cout << 0 << endl;
		return 0;
	}
	rep(j, 70) {
		rep(k, 50) {
			rep(l, 35) {
				dp[0][j][k][j] = 0;
			}
		}
	}
	dp[0][0][0][0] = 1;
	reps(i, 1, N+1) {
		rep(j, a+1) {
			rep(k, b+1) {
				rep(l, c+1) {
					double res = dp[i-1][j][k][l] * p[6];
					if (j > 0) res += (dp[i-1][j-1][k][l]-dp[i-1][j][k][l]) * p[3];
					if (j > 1) res += (dp[i-1][j-2][k][l]-dp[i-1][j-1][k][l]) * p[1];
					if (j > 0 && k > 0) res += (dp[i-1][j-1][k-1][l]-dp[i-1][j][k-1][l]-dp[i-1][j-1][k][l]+dp[i-1][j][k][l]) * p[1];
					if (k > 0) res += (dp[i-1][j][k-1][l]-dp[i-1][j][k][l]) * p[2];
					if (l > 0) res += (dp[i-1][j][k][l-1]-dp[i-1][j][k][l]) * p[1];
					dp[i][j][k][l] = res;
				}
			}
		}
	}
	double t = 0;
	reps(j, a, 70) reps(k, b, 50) reps(l, c, 35) t += dp[N][j][k][l];
	cout << fixed << setprecision(12) << dp[N][a][b][c] << endl;
//	cout << a << " " << b << " " << c << endl;
}

Submission Info

Submission Time
Task D - サイコロ
User spihill
Language C++14 (GCC 5.4.1)
Score 4
Code Size 2184 Byte
Status AC
Exec Time 25 ms
Memory 87296 KB

Compile Error

In function ‘int main()’:
cc1plus: warning: iteration 35u invokes undefined behavior [-Waggressive-loop-optimizations]
./Main.cpp:6:41: note: containing loop
 #define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
                                         ^
./Main.cpp:58:2: note: in expansion of macro ‘rep’
  rep(j, 70) {
  ^

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 9 ms 29824 KB
01 AC 22 ms 79104 KB
02 AC 20 ms 72960 KB
03 AC 10 ms 34048 KB
04 AC 10 ms 34048 KB
05 AC 25 ms 87296 KB
06 AC 23 ms 79232 KB
07 AC 22 ms 75264 KB
08 AC 7 ms 17792 KB
09 AC 21 ms 73088 KB
10 AC 1 ms 256 KB
90 AC 2 ms 1152 KB
91 AC 2 ms 3200 KB