結果

問題 No.2367 Painting Gascket
ユーザー maksimmaksim
提出日時 2023-07-01 01:12:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,364 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 183,200 KB
実行使用メモリ 53,536 KB
最終ジャッジ日時 2023-09-21 18:51:12
合計ジャッジ時間 23,341 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 16 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1,355 ms
53,372 KB
testcase_09 AC 913 ms
37,204 KB
testcase_10 AC 25 ms
4,520 KB
testcase_11 AC 1,193 ms
47,680 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 362 ms
16,796 KB
testcase_14 AC 182 ms
10,056 KB
testcase_15 AC 180 ms
10,212 KB
testcase_16 AC 476 ms
20,836 KB
testcase_17 AC 1,235 ms
49,112 KB
testcase_18 AC 958 ms
38,892 KB
testcase_19 AC 597 ms
25,460 KB
testcase_20 AC 1,221 ms
48,568 KB
testcase_21 AC 691 ms
28,904 KB
testcase_22 AC 1,287 ms
50,980 KB
testcase_23 AC 955 ms
38,476 KB
testcase_24 AC 365 ms
16,824 KB
testcase_25 AC 399 ms
18,064 KB
testcase_26 AC 76 ms
6,256 KB
testcase_27 AC 1,004 ms
40,572 KB
testcase_28 AC 831 ms
34,048 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1,364 ms
53,352 KB
testcase_34 AC 1,350 ms
53,392 KB
testcase_35 AC 1,350 ms
53,468 KB
testcase_36 AC 1,352 ms
53,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0