結果

問題 No.1964 sum = length
ユーザー nyyanyya
提出日時 2022-06-04 00:50:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 742 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 169,164 KB
実行使用メモリ 398,160 KB
最終ジャッジ日時 2023-10-21 02:32:13
合計ジャッジ時間 17,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
11,440 KB
testcase_01 AC 8 ms
9,488 KB
testcase_02 AC 61 ms
40,740 KB
testcase_03 AC 8 ms
9,488 KB
testcase_04 AC 11 ms
11,440 KB
testcase_05 AC 14 ms
13,396 KB
testcase_06 AC 18 ms
15,348 KB
testcase_07 AC 21 ms
17,300 KB
testcase_08 AC 25 ms
19,256 KB
testcase_09 AC 29 ms
21,208 KB
testcase_10 AC 32 ms
23,160 KB
testcase_11 AC 35 ms
25,112 KB
testcase_12 AC 163 ms
89,568 KB
testcase_13 AC 231 ms
126,676 KB
testcase_14 AC 314 ms
169,644 KB
testcase_15 AC 354 ms
191,128 KB
testcase_16 AC 57 ms
38,784 KB
testcase_17 AC 179 ms
101,284 KB
testcase_18 AC 203 ms
113,004 KB
testcase_19 AC 133 ms
75,896 KB
testcase_20 AC 146 ms
81,756 KB
testcase_21 AC 54 ms
36,832 KB
testcase_22 AC 740 ms
364,956 KB
testcase_23 AC 670 ms
357,144 KB
testcase_24 AC 496 ms
263,396 KB
testcase_25 AC 538 ms
286,832 KB
testcase_26 AC 707 ms
378,628 KB
testcase_27 AC 590 ms
316,128 KB
testcase_28 AC 517 ms
279,020 KB
testcase_29 AC 636 ms
339,568 KB
testcase_30 AC 539 ms
288,784 KB
testcase_31 AC 704 ms
378,628 KB
testcase_32 AC 388 ms
210,660 KB
testcase_33 AC 378 ms
204,800 KB
testcase_34 AC 666 ms
355,192 KB
testcase_35 AC 438 ms
236,052 KB
testcase_36 AC 561 ms
300,504 KB
testcase_37 AC 627 ms
335,660 KB
testcase_38 AC 727 ms
390,348 KB
testcase_39 AC 524 ms
282,928 KB
testcase_40 AC 541 ms
290,740 KB
testcase_41 AC 689 ms
368,864 KB
testcase_42 AC 742 ms
398,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
bool chmin(ll& a,ll b){if(a>b){a=b; return 1;} return 0;}
bool chmax(ll& a,ll b){if(a<b){a=b; return 1;} return 0;}

int main(){
    int n;
    cin >> n;

    ll dp[n+2][500][500];

    rep(i,500){
        rep(j,500){
            rep(k,n+2){
                dp[k][i][j]=0;
            }
        }
    }

    dp[1][1][1]=1;
    dp[1][10][1]=-1;
    dp[1][10][2]=1;
    dp[1][100][2]=-1;
    dp[1][100][3]=1;

    //for(int i=1;i<500;i++){
    //    if(i<10) dp[1][i][1]=1;
    //    else if(i<100) dp[1][i][2]=1;
    //    else dp[1][i][3]=1;
    //}

    for(int k=1;k<=n;k++){
        for(int i=1;i<500;i++){
            for(int j=1;j<500;j++){
                dp[k][i][j]+=dp[k][i-1][j];
                dp[k][i][j]%=998244353;

                if(i+1<500 && j+2<500){
                    dp[k+1][i+1][j+2]+=dp[k][i][j];
                    dp[k+1][i+1][j+2]%=998244353;
                }

                if(i+10<500 && j+2<500){
                    dp[k+1][i+10][j+2]+=998244353-dp[k][i][j];
                    dp[k+1][i+10][j+2]%=998244353;
                }

                if(i+10<500 && j+3<500){
                    dp[k+1][i+10][j+3]+=dp[k][i][j];
                    dp[k+1][i+10][j+3]%=998244353;
                } 
                
                if(i+100<500 && j+3<500){
                    dp[k+1][i+100][j+3]+=998244353-dp[k][i][j];
                    dp[k+1][i+100][j+3]%=998244353;
                } 
                
                if(i+100<500 && j+4<500){
                    dp[k+1][i+100][j+4]+=dp[k][i][j];
                    dp[k+1][i+100][j+4]%=998244353;
                } 
                

                //for(int add_a=1;add_a<500;add_a++){
                //    int add_l;
                //    if(add_a<10) add_l=2;
                //    else if(add_a<100) add_l=3;
                //    else add_l=4;
                //
                //    if(i+add_a>=500 || j+add_l>=500) break;
                //    dp[k+1][i+add_a][j+add_l]+=dp[k][i][j];
                //    dp[k+1][i+add_a][j+add_l]%=998244353;
                //}
            }
        }
    }

    ll ans=0;
    for(int i=1;i<500;i++){
        ans += dp[n][i][i];
        ans %=998244353;
    }

    cout << ans << endl;
    return 0;
}
0