結果

問題 No.301 サイコロで確率問題 (1)
ユーザー pekempeypekempey
提出日時 2015-11-13 23:49:07
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,553 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 146,532 KB
実行使用メモリ 16,324 KB
最終ジャッジ日時 2023-10-11 17:03:52
合計ジャッジ時間 5,638 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void companion(std::vector<long double>, D (*)[256])’:
main.cpp:40:27: warning: ‘sizeof’ on array function parameter ‘res’ will return size of ‘D (*)[256]’ {aka ‘long double (*)[256]’} [-Wsizeof-array-argument]
  memset(res, 0, sizeof(res));
                           ^
main.cpp:39:33: note: declared here
 void companion(vector<D> a, mat res) {
                             ~~~~^~~

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

typedef long double D;

const int maxdim = 256;
int dim;
typedef D mat[maxdim][maxdim];
mat M0, M1, M2, M3;

void matmul(mat A, mat B, mat res) {
    memset(M0, 0, sizeof(M0));
    rep (i, dim) rep (k, dim) rep (j, dim) {
        M0[i][j] += A[i][k] * B[k][j];
    }
    memcpy(res, M0, sizeof(M0));
}

void matpow(mat A, ll b, mat res) {
    memcpy(M1, A, sizeof(M1));
    rep (i, dim) rep (j, dim) M2[i][j] = i == j;
    while (b > 0) {
        if (b & 1) matmul(M1, M2, M2);
        matmul(M1, M1, M1);
        b >>= 1;
    }
    memcpy(res, M2, sizeof(M2));
}
void companion(vector<D> a, mat res) {
	memset(res, 0, sizeof(res));
	int n = a.size();
	rep (i, n - 1) res[i][i + 1] = 1;
	rep (i, n) res[n - 1][i] = a[i];
	res[n][1] = res[n][n] = 1;
}

int main() {
	int T;
	cin >> T;
	dim = 7;
	mat C;
	D p = 1.0 / 6;
	companion(vector<D>(6, p), C);
	rep (i_, T) {
		ll N;
		cin >> N;
		matpow(C, N + 4, M3);
		D s = M3[6][4], t = M3[6][5];
		D ans = t / (s - t * 5.0 / 6.0);
		printf("%.20f\n", (double)ans);
	}
	return 0;
}
0