結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー IKyopro
提出日時 2020-07-03 23:45:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,316 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 196,404 KB
最終ジャッジ日時 2025-01-11 15:11:30
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 2
other AC * 43 WA * 34
権限があれば一括ダウンロードができます

ソースコード

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[30][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;
    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