結果

問題 No.2529 Treasure Hunter
ユーザー maksimmaksim
提出日時 2023-11-03 21:50:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,047 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 166,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-25 20:00:33
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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;}}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--) {
    int n,m;cin>>n>>m;
    int ans[3]={1,n,(n-2)*(n-1)/2-1};ans[2]%=p;
    for(int i=1;i<m;++i)
    {
        int ans2[3]={0,0,0};
        int h2=((n-2)*(n-3)/2)-(n-4);h2%=p;int h1=((n-1)*(n-2)/2)-(n-2);h1%=p;int h0=(n-2)*(n-1)/2-1;h0%=p;
        if(n>=4) {ans2[2]+=ans[2]*h2;ans2[2]%=p;}
        if(n>=3) {ans2[2]+=ans[1]*h1;ans2[2]%=p;}
        if(n>=2) {ans2[2]+=ans[0]*h0;ans2[2]%=p;}
        ans2[1]+=ans[2]*(n-2);ans2[1]%=p;ans2[1]+=ans[1]*(n-1);ans2[1]%=p;ans2[1]+=ans[0]*n;ans2[1]%=p;
        ans2[0]+=ans[0];ans2[0]+=ans[1];ans2[0]+=ans[2];ans2[0]%=p;
        for(int i=0;i<3;++i) ans[i]=ans2[i];
    }
    int s=ans[0]+ans[1]+ans[2];s%=p;
    cout<<(s%p+p)%p<<'\n';
    }
    return 0;
}
0