結果
問題 |
No.2367 Painting Gascket
|
ユーザー |
|
提出日時 | 2023-07-01 01:12:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,230 ms / 2,000 ms |
コード長 | 2,610 bytes |
コンパイル時間 | 1,753 ms |
コンパイル使用メモリ | 185,512 KB |
実行使用メモリ | 53,504 KB |
最終ジャッジ日時 | 2024-07-07 12:26:52 |
合計ジャッジ時間 | 20,529 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int p=1e9+7; const int maxn=2e5+5; int dp[maxn][4][4][4]; vector<int> go(int x,int y,int z) { vector<int> h={x,y,z}; sort(h.begin(),h.end());h.erase(unique(h.begin(),h.end()),h.end()); vector<int> u; if(x==3) u.push_back(3); else u.push_back(lower_bound(h.begin(),h.end(),x)-h.begin()); if(y==3) u.push_back(3); else u.push_back(lower_bound(h.begin(),h.end(),y)-h.begin()); if(z==3) u.push_back(3); else u.push_back(lower_bound(h.begin(),h.end(),z)-h.begin()); return u; } vector<int> g[5][5][5]; vector<int> gl[5][5][5]; int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); for(int i=0;i<5;++i) for(int j=0;j<5;++j) for(int l=0;l<5;++l) g[i][j][l]=go(i,j,l); for(int i=0;i<5;++i) for(int j=0;j<5;++j) for(int l=0;l<5;++l) if(gl[g[i][j][l][0]][g[i][j][l][1]][g[i][j][l][2]].empty()) gl[g[i][j][l][0]][g[i][j][l][1]][g[i][j][l][2]]={i,j,l}; int n,k;cin>>k>>n; for(int i=0;i<4;++i) { for(int j=0;j<4;++j) { for(int l=0;l<4;++l) { int n1=n; set<int> o;o.insert(i);o.insert(j);o.insert(l); if(o.count(3)) o.erase(3); n1-=o.size(); dp[0][i][j][l]=n1; } } } for(int i=1;i<=k;++i) { for(int j=0;j<4;++j) { for(int l=0;l<4;++l) { for(int m=0;m<4;++m) { vector<int> h=g[j][l][m]; vector<int> o=gl[h[0]][h[1]][h[2]]; if(o[0]!=j || o[1]!=l || o[2]!=m) { dp[i][j][l][m]=dp[i][o[0]][o[1]][o[2]]; continue; } for(int u:{0,1,2,4}) { bool used[4]={0};used[j]=1;used[l]=1;used[m]=1; int ways; if(u==4) ways=n-accumulate(used,used+4,0LL)+used[3]; else ways=used[u]; vector<int> v1=g[j][l][u];vector<int> v2=g[l][m][u];vector<int> v3=g[m][j][u]; int h=ways; h*=dp[i-1][v1[0]][v1[1]][v1[2]];h%=p; h*=dp[i-1][v2[0]][v2[1]][v2[2]];h%=p; h*=dp[i-1][v3[0]][v3[1]][v3[2]];h%=p; dp[i][j][l][m]+=h;dp[i][j][l][m]%=p; } } } } } cout<<(dp[k][3][3][3]%p+p)%p; return 0; }