結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー IKyoproIKyopro
提出日時 2020-07-04 00:24:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 203,708 KB
実行使用メモリ 12,052 KB
最終ジャッジ日時 2023-10-17 06:39:25
合計ジャッジ時間 6,417 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,348 KB
testcase_01 AC 5 ms
5,908 KB
testcase_02 AC 5 ms
5,908 KB
testcase_03 AC 9 ms
5,908 KB
testcase_04 AC 31 ms
12,052 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
5,908 KB
testcase_09 AC 8 ms
5,908 KB
testcase_10 AC 9 ms
5,908 KB
testcase_11 AC 10 ms
5,908 KB
testcase_12 AC 13 ms
7,956 KB
testcase_13 AC 14 ms
7,956 KB
testcase_14 AC 17 ms
7,956 KB
testcase_15 AC 17 ms
7,956 KB
testcase_16 AC 16 ms
7,956 KB
testcase_17 AC 16 ms
7,956 KB
testcase_18 AC 16 ms
7,956 KB
testcase_19 AC 16 ms
7,956 KB
testcase_20 AC 21 ms
10,004 KB
testcase_21 AC 24 ms
10,004 KB
testcase_22 AC 26 ms
10,004 KB
testcase_23 AC 28 ms
10,004 KB
testcase_24 AC 29 ms
12,052 KB
testcase_25 AC 30 ms
12,052 KB
testcase_26 AC 33 ms
12,052 KB
testcase_27 AC 32 ms
12,052 KB
testcase_28 AC 33 ms
12,052 KB
testcase_29 AC 34 ms
12,052 KB
testcase_30 AC 33 ms
12,052 KB
testcase_31 AC 33 ms
12,052 KB
testcase_32 AC 33 ms
12,052 KB
testcase_33 AC 33 ms
12,052 KB
testcase_34 AC 33 ms
12,052 KB
testcase_35 AC 33 ms
12,052 KB
testcase_36 AC 34 ms
12,052 KB
testcase_37 AC 33 ms
12,052 KB
testcase_38 AC 33 ms
12,052 KB
testcase_39 AC 33 ms
12,052 KB
testcase_40 AC 35 ms
12,052 KB
testcase_41 AC 32 ms
12,052 KB
testcase_42 AC 33 ms
12,052 KB
testcase_43 AC 32 ms
12,052 KB
testcase_44 AC 33 ms
12,052 KB
testcase_45 AC 33 ms
12,052 KB
testcase_46 AC 32 ms
12,052 KB
testcase_47 AC 35 ms
12,052 KB
testcase_48 AC 34 ms
12,052 KB
testcase_49 AC 34 ms
12,052 KB
testcase_50 AC 36 ms
12,052 KB
testcase_51 AC 34 ms
12,052 KB
testcase_52 AC 34 ms
12,052 KB
testcase_53 AC 34 ms
12,052 KB
testcase_54 AC 35 ms
12,052 KB
testcase_55 AC 34 ms
12,052 KB
testcase_56 AC 34 ms
12,052 KB
testcase_57 AC 34 ms
12,052 KB
testcase_58 AC 34 ms
12,052 KB
testcase_59 AC 31 ms
12,052 KB
testcase_60 AC 33 ms
12,052 KB
testcase_61 AC 35 ms
12,052 KB
testcase_62 AC 34 ms
12,052 KB
testcase_63 AC 35 ms
12,052 KB
testcase_64 AC 34 ms
12,052 KB
testcase_65 AC 34 ms
12,052 KB
testcase_66 AC 36 ms
12,052 KB
testcase_67 AC 33 ms
12,052 KB
testcase_68 AC 34 ms
12,052 KB
testcase_69 AC 34 ms
12,052 KB
testcase_70 AC 35 ms
12,052 KB
testcase_71 AC 35 ms
12,052 KB
testcase_72 AC 36 ms
12,052 KB
testcase_73 AC 34 ms
12,052 KB
testcase_74 AC 35 ms
12,052 KB
testcase_75 AC 34 ms
12,052 KB
testcase_76 AC 38 ms
12,052 KB
testcase_77 AC 38 ms
12,052 KB
testcase_78 AC 39 ms
12,052 KB
testcase_79 AC 39 ms
12,052 KB
testcase_80 AC 39 ms
12,052 KB
testcase_81 AC 39 ms
12,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll dp[40][100][100][2][2] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll five = 1;
    while(5*five<=N) five *= 5;
    string S = "";
    ll n = N;
    while(five){
        ll a = n/five;
        S += (char) '0'+a;
        n -= five*a;
        five /= 5;
    }
    cerr << S << "\n";
    int M = S.size();
    int A = 60;
    dp[0][0][0][0][0] = 1;
    dp[0][1][0][0][1] = 1;
    for(int i=0;i<M;i++) for(int l=0;l<A;l++) for(int r=0;r<A;r++) for(int k=0;k<2;k++) for(int j=0;j<2;j++){
        int x = S[i]-'0';
        for(int n=0;n<5;n++){
            int nk = (k || n<x);
            if(!k && n>x) continue;
            for(int a=0;a<3;a++) for(int b=0;b<3;b++){
                if(a+b>2) continue;
                if(a==b && a>0) continue;
                int nl = l+a,nr = r+b;
                int nj = 0;
                if(a+5*j-b==n) nj = 0;
                else if(a+5*j-b==n+1) nj = 1;
                else continue;
                dp[i+1][nl][nr][nk][nj] += dp[i][l][r][k][j];
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<A;i++) ans += dp[M][i][i][0][0]+dp[M][i][i][1][0];
    cout << ans-1 << "\n";
}
0