結果

問題 No.2131 Concon Substrings (COuNt Version)
ユーザー KKT89KKT89
提出日時 2022-11-25 21:39:01
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 211,128 KB
実行使用メモリ 56,960 KB
最終ジャッジ日時 2024-10-02 04:15:35
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr ll mod = 998244353;

ll mod_pow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b==1)return a;
    ll res=mod_pow(a,b/2)%mod;
    res*=res; res%=mod;
    if(b%2)res*=a;
    return res%mod;
}

const int N = 3001;
int dp[3][N][N];

void add(int &x,int y){
    x += y;
    if(x >= mod) x -= mod;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    dp[0][0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i/3;j++){
            for(int k=0;k<3;k++){
                if(!dp[k][i][j]) continue;
                int nk = k+1;
                int nj = j+(nk == 3);
                if(nk == 3) nk = 0;
                add(dp[nk][i+1][nj], dp[k][i][j]);
                add(dp[k][i+1][j], (ll)dp[k][i][j]*25%mod);
            }
        }
    }
    int res = 0;
    for(int i=0;i<=n/3;i++){
        for(int j=0;j<3;j++){
            add(res, (ll)dp[j][n][i]*i%mod);
        }
    }
    cout << res << endl;
}
0