結果

問題 No.2367 Painting Gascket
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-17 04:50:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,024 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 169,336 KB
実行使用メモリ 16,952 KB
最終ジャッジ日時 2023-10-18 00:16:58
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,724 KB
testcase_01 AC 3 ms
5,672 KB
testcase_02 AC 2 ms
5,828 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
5,668 KB
testcase_05 AC 2 ms
5,664 KB
testcase_06 AC 2 ms
5,668 KB
testcase_07 AC 2 ms
5,664 KB
testcase_08 AC 28 ms
16,952 KB
testcase_09 AC 18 ms
12,812 KB
testcase_10 AC 3 ms
5,900 KB
testcase_11 AC 24 ms
15,400 KB
testcase_12 AC 2 ms
5,908 KB
testcase_13 AC 9 ms
8,532 KB
testcase_14 AC 6 ms
7,128 KB
testcase_15 AC 6 ms
7,112 KB
testcase_16 AC 11 ms
9,408 KB
testcase_17 AC 25 ms
15,784 KB
testcase_18 AC 19 ms
13,196 KB
testcase_19 AC 13 ms
10,360 KB
testcase_20 AC 25 ms
15,672 KB
testcase_21 AC 15 ms
11,092 KB
testcase_22 AC 26 ms
16,344 KB
testcase_23 AC 19 ms
13,104 KB
testcase_24 AC 9 ms
8,552 KB
testcase_25 AC 10 ms
8,816 KB
testcase_26 AC 4 ms
6,296 KB
testcase_27 AC 20 ms
13,548 KB
testcase_28 AC 18 ms
12,188 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
5,724 KB
testcase_32 AC 2 ms
5,728 KB
testcase_33 AC 29 ms
16,892 KB
testcase_34 AC 29 ms
16,892 KB
testcase_35 AC 29 ms
16,952 KB
testcase_36 AC 29 ms
16,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
const int N = 1e5 + 10, P = 1e9 + 7;

int k, n;

int qpow(int b, int k) {
    int ret = 1;
    while(k > 0) {
        if(k & 1) ret = (i64)ret * b % P;
        b = (i64)b * b % P;
        k >>= 1;
    }
    return ret;
}

i64 ch(i64 x) {
    return max(x, 0ll);
}

int sav[N][7], vis[N][7];

int solve(int k, int type) {
    if(k == 0) {
        if(type == 0) return n;
        else if(type == 1 || type == 3 || type == 6) return ch(n - 1);
        else if(type == 2 || type == 5) return ch(n - 2);
        else if(type == 4) return ch(n - 3);
    }
    if(!vis[k][type]) {
        vis[k][type] = true;
        if(type == 0) sav[k][type] = (i64)n * qpow(solve(k - 1, 1), 3) % P;
        else if(type == 1) sav[k][type] = solve(k - 1, 1) * (qpow(solve(k - 1, 3), 2) + ch(n - 1ll) * qpow(solve(k - 1, 2), 2) % P) % P;
        else if(type == 2) sav[k][type] = ((i64)solve(k - 1, 5) * solve(k - 1, 2) % P * solve(k - 1, 3) * 2 + ch(n - 2ll) * solve(k - 1, 4) % P * qpow(solve(k - 1, 2), 2)) % P;
        else if(type == 3) sav[k][type] = ((i64)solve(k - 1, 6) * qpow(solve(k - 1, 3), 2) + ch(n - 1ll) * solve(k - 1, 5) % P * qpow(solve(k - 1, 2), 2)) % P;
        else if(type == 4) sav[k][type] = (3ll * solve(k - 1, 4) % P * qpow(solve(k - 1, 5), 2) + ch(n - 3ll) * qpow(solve(k - 1, 4), 3)) % P;
        else if(type == 5) sav[k][type] = (solve(k - 1, 6) * (i64)qpow(solve(k - 1, 5), 2) + qpow(solve(k - 1, 5), 3) + ch(n - 2ll) * solve(k - 1, 5) % P * qpow(solve(k - 1, 4), 2)) % P;
        else if(type == 6) sav[k][type] = (qpow(solve(k - 1, 6), 3) + ch(n - 1ll) * qpow(solve(k - 1, 5), 3)) % P;
    }
    return sav[k][type];
}

/*
0: uncolored
1: 1 side colored
2: 2 side colored with different colors
3: 2 side colored with the same color
4: 3 side colored with 3 colors
5: 3 side colored with 2 colors
6: 3 side colored with 1 color
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> k >> n;

    cout << solve(k, 0);
}

0