結果

問題 No.2367 Painting Gascket
ユーザー logxlogx
提出日時 2021-06-22 22:59:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 209,028 KB
実行使用メモリ 28,904 KB
最終ジャッジ日時 2023-09-21 12:30:44
合計ジャッジ時間 4,212 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 48 ms
28,848 KB
testcase_09 AC 31 ms
20,356 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 41 ms
25,720 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 13 ms
9,852 KB
testcase_14 AC 7 ms
6,708 KB
testcase_15 AC 7 ms
6,600 KB
testcase_16 AC 16 ms
12,072 KB
testcase_17 AC 43 ms
26,588 KB
testcase_18 AC 32 ms
21,148 KB
testcase_19 AC 21 ms
14,288 KB
testcase_20 AC 42 ms
26,220 KB
testcase_21 AC 24 ms
16,192 KB
testcase_22 AC 45 ms
27,652 KB
testcase_23 AC 32 ms
21,012 KB
testcase_24 AC 13 ms
10,116 KB
testcase_25 AC 14 ms
10,628 KB
testcase_26 AC 4 ms
4,984 KB
testcase_27 AC 35 ms
22,100 KB
testcase_28 AC 28 ms
18,968 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 44 ms
28,836 KB
testcase_34 AC 45 ms
28,848 KB
testcase_35 AC 46 ms
28,904 KB
testcase_36 AC 46 ms
28,844 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;
    assert(0<=K && K<=100000 && 1<=N && N<=1000000000);
    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