結果

問題 No.58 イカサマなサイコロ
ユーザー momoyuumomoyuu
提出日時 2022-08-16 15:28:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 1,569 bytes
コンパイル時間 3,454 ms
コンパイル使用メモリ 277,028 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 09:24:09
合計ジャッジ時間 4,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 222 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 39 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 39 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b

using namespace std;


void calc(int n, int k,bool p,int a,int now,vector<unsigned ll>& A){
    int b = 0;
    if (p){
        if (now <= k){
            rep(i,4,7){
                b = a + i;
                if (now == n){
                    A[b] ++;
                    A[b] ++;
                }else{
                    calc(n,k,p,b,now+1,A);
                    calc(n,k,p,b,now+1,A);
                }
            }
        }else{
            rep(i,1,7){
                b = a + i;
                if (now == n){
                    A[b] ++;
                }else{
                    calc(n,k,p,b,now+1,A);
                }
            }
        }
    }else{
        rep(i,1,7){
            b = a + i;
            if (now == n){
                A[b] ++;
            }else{
                calc(n,k,p,b,now+1,A);
            }
        }
    }
}

int main(){
    cout << fixed << setprecision(15);
    int N,K;cin>>N>>K;
    vector<unsigned ll> A(6*N+1,0);
    vector<unsigned ll> B(6*N+1,0);

    calc(N,K,true,0,1,A);
    calc(N,K,false,0,1,B);

    ll ok = 0;
    unsigned ll all = 1;
    rep(i,0,N){all*=6;}
    all *= all;;

    rep(i,1,6*N+1){
        //cout << A[i] << " " << B[i] << endl;
        rep(j,1,i){
            ok += A[i]*B[j];
        }
    }
    print((long double)ok/all);

    //system("pause");
    return 0;
}
0