結果

問題 No.1964 sum = length
ユーザー NanashimaNanashima
提出日時 2022-06-03 23:10:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,568 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 175,976 KB
実行使用メモリ 261,000 KB
最終ジャッジ日時 2023-10-21 02:21:14
合計ジャッジ時間 20,888 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 14 ms
5,976 KB
testcase_13 AC 41 ms
11,160 KB
testcase_14 AC 104 ms
22,344 KB
testcase_15 AC 152 ms
31,056 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 20 ms
7,372 KB
testcase_18 AC 29 ms
8,952 KB
testcase_19 AC 9 ms
5,012 KB
testcase_20 AC 11 ms
5,448 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1,167 ms
200,016 KB
testcase_23 AC 1,099 ms
187,608 KB
testcase_24 AC 416 ms
76,200 KB
testcase_25 AC 545 ms
97,848 KB
testcase_26 AC 1,313 ms
224,568 KB
testcase_27 AC 739 ms
131,376 KB
testcase_28 AC 500 ms
90,192 KB
testcase_29 AC 946 ms
162,264 KB
testcase_30 AC 557 ms
100,488 KB
testcase_31 AC 1,308 ms
224,568 KB
testcase_32 AC 205 ms
40,560 KB
testcase_33 AC 188 ms
37,128 KB
testcase_34 AC 1,073 ms
185,496 KB
testcase_35 AC 296 ms
55,608 KB
testcase_36 AC 630 ms
113,160 KB
testcase_37 AC 918 ms
156,720 KB
testcase_38 AC 1,471 ms
245,952 KB
testcase_39 AC 523 ms
94,152 KB
testcase_40 AC 572 ms
101,808 KB
testcase_41 AC 1,224 ms
206,616 KB
testcase_42 AC 1,568 ms
261,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

const ll mod=998244353;

int f(ll num) {
    int cnt=0;
    while(num>=10) {
        num/=10;
        cnt++;
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    ll len=4*n;
    vector<vector<vector<ll>>> dp(n,vector<vector<ll>> (len,vector<ll> (n,0)));
    for(int i=1;i<len;i++) dp[0][i][f(i)]=1;
    for(int i=0;i<n-1;i++) {
        rep(j,len) rep(k,n) { 
            for(int l=1;l<=1000;l*=10) {
                if(j+l<len&&k+f(l)<n) dp[i+1][j+l][k+f(l)]=(dp[i+1][j+l][k+f(l)]+dp[i][j][k])%mod;
                if(j+l*10<len&&k+f(l)<n) dp[i+1][j+l*10][k+f(l)]=(dp[i+1][j+l*10][k+f(l)]+(-dp[i][j][k]+mod)%mod)%mod;
            }
        }
        rep(j,n) for(int k=1;k<len;k++) dp[i+1][k][j]=(dp[i+1][k][j]+dp[i+1][k-1][j])%mod;
    }
    ll ans=0;
    for(int i=0;i<n;i++) {
        if(2*n-1+i<len) ans=(ans+dp[n-1][2*n-1+i][i])%mod;
    }
    cout << ans << endl;
    return 0;
}
0