結果

問題 No.2514 Twelvefold Way Returns
ユーザー maksimmaksim
提出日時 2023-10-20 23:19:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,639 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 168,628 KB
実行使用メモリ 9,936 KB
最終ジャッジ日時 2023-10-20 23:20:46
合計ジャッジ時間 10,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 163 ms
9,856 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
const int maxn=4e5+5;
int fact[maxn];int invf[maxn];
int c1(int n1,int n2,int n3)
{
    int ans=fact[n1+n2+n3];ans*=invf[n1];ans%=p;ans*=invf[n2];ans%=p;ans*=invf[n3];ans%=p;return ans;
}
array<int,3> po1(array<int,3> v,int n)
{
    if(n==1) return v;
    if(n%2==0)
    {
        array<int,3> u=po1(v,n/2);
        array<int,3> res={0,0,0};
        for(int i=0;i<3;++i)
        {for(int j=0;j<3;++j)
        {
            res[(i+j)%3]+=u[i]*u[j];res[(i+j)%3]%=p;
        }}
        return res;
    }
    else
    {
        array<int,3> u=po1(v,n-1);
        array<int,3> res={0,0,0};
        for(int i=0;i<3;++i)
        {for(int j=0;j<3;++j)
        {
            res[(i+j)%3]+=u[i]*v[j];res[(i+j)%3]%=p;
        }}
        return res;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    fact[0]=1;for(int i=1;i<maxn;++i) {fact[i]=(fact[i-1]*i)%p;}
    for(int i=0;i<maxn;++i) {invf[i]=inv(fact[i]);}
    assert((p+1)%3==0);int inv3=(p+1)/3;
    int n,m;cin>>n>>m;
    int res=0;
    for(int a=0;a<=m;++a)
    {
        for(int b=0;a+b<=m;++b)
        {
            int c=m-a-b;
            int h=c1(a,b,c);
            array<int,3> v={a,b,c};
            array<int,3> u=po1(v,n);
            res+=h*u[(333333-2*b-c)%3];res%=p;
        }
    }
    for(int i=0;i<m;++i) {res*=inv3;res%=p;}
    cout<<(res%p+p)%p;
    return 0;
}
0