結果
| 問題 | 
                            No.1106 🦉 何事もバランスが大事
                             | 
                    
| コンテスト | |
| ユーザー | 
                             fastmath
                         | 
                    
| 提出日時 | 2020-07-03 23:00:35 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,681 bytes | 
| コンパイル時間 | 1,702 ms | 
| コンパイル使用メモリ | 171,180 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-17 04:40:40 | 
| 合計ジャッジ時間 | 3,628 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 77 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
int n;
int ans = 0;
vector <int> c;
const int N = 101;
int suff[N];
int dp[N][N];
void gen(int i, int bal, int sum) {
    if (sum + suff[i] < 1)
        return;    
    if (sum - suff[i] >= 1 && sum + suff[i] <= n) {
        int r = (int)c.size() - i;
        ans += dp[r][abs(bal)];
        return;
    }   
    if (sum - suff[i] > n)
        return;
    if (i == c.size()) {        
        if (bal == 0 && sum <= n)
            ++ans;
        return;
    }   
    for (int x = -2; x <= 2; ++x) {
       gen(i + 1, bal + x, sum + c[i] * x);
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    dp[0][0] = 1;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            for (int add = -2; add <= 2; ++add) {
                int to = abs(j+add);
                dp[i][j] += dp[i - 1][to];
            }   
        }   
    }   
    cin >> n;
    int cur = 1;
    while (1) {
        c.app(cur);
        if (cur > n)
            break;
        cur *= 5;
    }   
    reverse(all(c));
    suff[c.size()] = 0;
    for (int i = (int)c.size() - 1; i >= 0; --i)
        suff[i] = 2 * c[i] + suff[i+1];
    //debug(c.size());
    gen(0, 0, 0);
    cout << ans << endl;
}
            
            
            
        
            
fastmath