結果

問題 No.3316 Make 81181819 with only 0,1,or 8
コンテスト
ユーザー こめだわら
提出日時 2025-08-15 16:47:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 6,000 ms
コード長 2,122 bytes
コンパイル時間 2,877 ms
コンパイル使用メモリ 284,756 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-25 17:03:19
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define rep(i,n) for(ll i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }


void solve() {
    ll N;
    cin>>N;
    ll len=8;
    ll sum=81181819-N;
    vector<vector<ll>> dp(10,vector<ll> (10,0));
    dp[0]={};
    rep(d,8){
        vector<vector<ll>> ndp(10,vector<ll> (10,0));
        ll p=intpow(10,d);
        ll tar=sum%10;
        sum/=10;
        rep(i,10){
            if (dp[i].size()==10)continue;
            rep(u1,8){
                rep(u8,8){
                    ll use=u1+u8;
                    chmax(use,dp[i].size());
                    ll v=i+u1+u8*8;
                    if ((v-tar)%10!=0)continue;
                    ll ni=(v-tar)/10;
                    if (ndp[ni].size()<=use)continue;
                    vector<ll> nxt(use,0);
                    rep(j,dp[i].size()){
                        nxt[j]+=dp[i][j];
                    }
                    for (ll j=0;j<u1;j++){
                        nxt[j]+=p;
                    }
                    for (ll j=u1;j<u1+u8;j++){
                        nxt[j]+=8*p;
                    }
                    
                    ndp[ni]=nxt;
                }
            }
        }
        swap(dp,ndp);
    }
    vector<ll> ans=dp[0];
    cout<<ans.size()<<endl;
    for (ll i:ans){
        cout<<i<<endl;
    }
    return;
}


int main() {
    ll T=1;
    cin>>T;
    while (T--){
        solve();
    }
    return 0;
}
0