結果

問題 No.2367 Painting Gascket
ユーザー logxlogx
提出日時 2021-06-22 22:53:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 210,432 KB
実行使用メモリ 28,996 KB
最終ジャッジ日時 2023-09-21 12:30:53
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 47 ms
28,892 KB
testcase_09 AC 33 ms
20,516 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 41 ms
25,728 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 13 ms
9,828 KB
testcase_14 AC 7 ms
6,736 KB
testcase_15 AC 7 ms
6,484 KB
testcase_16 AC 17 ms
11,956 KB
testcase_17 AC 42 ms
26,476 KB
testcase_18 AC 33 ms
21,208 KB
testcase_19 AC 21 ms
14,324 KB
testcase_20 AC 41 ms
26,252 KB
testcase_21 AC 24 ms
16,168 KB
testcase_22 AC 44 ms
27,836 KB
testcase_23 AC 33 ms
20,972 KB
testcase_24 AC 14 ms
9,848 KB
testcase_25 AC 15 ms
10,584 KB
testcase_26 AC 4 ms
4,864 KB
testcase_27 AC 35 ms
21,932 KB
testcase_28 AC 29 ms
19,124 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 45 ms
28,996 KB
testcase_34 AC 45 ms
28,848 KB
testcase_35 AC 46 ms
28,932 KB
testcase_36 AC 46 ms
28,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint=atcoder::modint1000000007;

int K,N;
/*
dp[i][j][k]:レベルiのガスケットについて、外のj個の辺の外の色が決まっている(ただし、決まっているものについて、種類数はk)時の塗り方の場合の数
*/

int main(){
    std::cin >> K >> N;
    std::vector dp(K+1,std::vector(4,std::vector<mint>(4)));
    dp[0][0][0]=N;
    dp[0][1][1]=N-1;
    dp[0][2][1]=N-1;
    dp[0][2][2]=std::max(N-2,0);
    dp[0][3][1]=N-1;
    dp[0][3][2]=std::max(N-2,0);
    dp[0][3][3]=std::max(N-3,0);
    for(int i=0;i<K;i++){
        auto &now=dp[i];
        auto &ne=dp[i+1];
        ne[0][0]=N*now[1][1]*now[1][1]*now[1][1];
        ne[1][1]=1*now[2][1]*now[2][1]*now[1][1] + (N-1)*now[2][2]*now[2][2]*now[1][1];

        ne[2][1]=1*now[3][1]*now[2][1]*now[2][1] + (N-1)*now[3][2]*now[2][2]*now[2][2];
        if(N>=2)ne[2][2]=2*now[3][2]*now[2][2]*now[2][1] + (N-2)*now[3][3]*now[2][2]*now[2][2];

        ne[3][1]=1*now[3][1]*now[3][1]*now[3][1] + (N-1)*now[3][2]*now[3][2]*now[3][2];
        if(N>=2)ne[3][2]=1*now[3][2]*now[3][2]*now[3][2] + 1*now[3][1]*now[3][2]*now[3][2] + (N-2)*now[3][2]*now[3][3]*now[3][3];
        if(N>=3)ne[3][3]=3*now[3][2]*now[3][2]*now[3][3] + (N-3)*now[3][3]*now[3][3]*now[3][3];
    }
    std::cout << dp[K][0][0].val() << '\n';
}
0