結果

問題 No.3316 Make 81181819 with only 0,1,or 8
コンテスト
ユーザー Kude
提出日時 2025-10-31 22:05:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 6,000 ms
コード長 2,102 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 312,332 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-31 22:05:51
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, P> trans;
  trans[0] = {0, 0};
  rep(_, 7) {
    auto nt = trans;
    for (auto [v, c18] : trans) {
      auto [c1, c8] = c18;
      nt.emplace(v + 1, P{c1 + 1, c8});
      nt.emplace(v + 8, P{c1, c8 + 1});
    }
    swap(nt, trans);
  }
  int p10[9];
  p10[0] = 1;
  rep(i, 8) p10[i+1] = p10[i] * 10;
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    n = 81181819 - n;
    map<int, P> dp[9];
    dp[0][0] = {0, -1};
    int digit[8];
    rep(i, 8) {
      int x = n % 10;
      digit[i] = x;
      n /= 10;
      for (auto [v, mxpre] : dp[i]) {
        auto [mx, pre] = mxpre;
        for (auto [add, c18] : trans) if ((v + add) % 10 == x) {
          int nmx = max(mx, c18.first + c18.second);
          auto [it, inserted] = dp[i+1].emplace((v + add) / 10, P{nmx, v});
          if (!inserted && nmx < it->second.first) {
            it->second = P{nmx, v};
          }
        }
      }
    }
    VI ans(dp[8][0].first);
    assert(!ans.empty());
    rrep(i, 8) {
      auto [mx, pre] = dp[i+1][n];
      int add = 10 * n + digit[i] - pre;
      auto [c1, c8] = trans[add];
      int ptr = 0;
      rep(_, c1) ans[ptr++] += p10[i];
      rep(_, c8) ans[ptr++] += p10[i] * 8;
      n = pre;
    }
    cout << ans.size() << '\n';
    for (int x : ans) cout << x << '\n';
  }
}
0