結果
問題 | No.2367 Painting Gascket |
ユーザー | 鴨志田卓 |
提出日時 | 2023-07-17 04:50:16 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 2,024 bytes |
コンパイル時間 | 1,638 ms |
コンパイル使用メモリ | 169,008 KB |
実行使用メモリ | 16,752 KB |
最終ジャッジ日時 | 2024-09-17 21:20:48 |
合計ジャッジ時間 | 2,925 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 28 ms
16,640 KB |
testcase_09 | AC | 17 ms
12,556 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 23 ms
15,104 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 9 ms
8,280 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 5 ms
6,944 KB |
testcase_16 | AC | 10 ms
9,152 KB |
testcase_17 | AC | 22 ms
15,616 KB |
testcase_18 | AC | 18 ms
13,072 KB |
testcase_19 | AC | 12 ms
10,620 KB |
testcase_20 | AC | 23 ms
15,488 KB |
testcase_21 | AC | 14 ms
11,352 KB |
testcase_22 | AC | 25 ms
16,024 KB |
testcase_23 | AC | 19 ms
12,672 KB |
testcase_24 | AC | 9 ms
8,296 KB |
testcase_25 | AC | 10 ms
8,684 KB |
testcase_26 | AC | 3 ms
6,944 KB |
testcase_27 | AC | 20 ms
13,636 KB |
testcase_28 | AC | 16 ms
11,928 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
testcase_33 | AC | 26 ms
16,752 KB |
testcase_34 | AC | 28 ms
16,512 KB |
testcase_35 | AC | 26 ms
16,512 KB |
testcase_36 | AC | 27 ms
16,640 KB |
ソースコード
#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); }