結果
| 問題 |
No.3316 Make 81181819 with only 0,1,or 8
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-10-31 23:24:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,767 bytes |
| コンパイル時間 | 3,869 ms |
| コンパイル使用メモリ | 259,948 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-10-31 23:25:07 |
| 合計ジャッジ時間 | 7,151 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 WA * 17 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template <int m> istream& operator>>(istream& is, static_modint<m>& a) {long long x; is >> x; a = x; return is;}
template <int m> istream& operator>>(istream& is, dynamic_modint<m>& a) {long long x; is >> x; a = x; return is;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}
const int K = 10;
const int INF = 1001001001;
using T = tuple<int, int, int>;
int solve(){
int n;
cin >> n;
vector<int> dig(K);
n = 81181819 - n;
rep(i, K){
dig[(K - 1) - i] = n % 10;
n /= 10;
}
vector<vector<T>> dp(K + 1, vector<T>(10, make_tuple(INF, INF, INF)));
dp[0][0] = T{0, 0, 0};
vector<pair<int, int>> memo(100, make_pair(INF, INF));
for(int one = 0; one <= 7; one++){
for(int eight = 0; eight <= 7; eight++){
int sum = one * 1 + eight * 8;
if(one + eight < memo[sum].first + memo[sum].second){
memo[sum] = make_pair(one, eight);
}
}
}
rep(i, K){
for(int down = 0; down < 10; down++){
int rest = down * 10 + dig[i];
auto [val1, one1, eight1] = dp[i][down];
for(int minus = 0; minus < 100; minus++){
auto [one, eight] = memo[minus];
int val_new = max(val1, one + eight);
if(0 <= rest - minus and rest - minus < 10){
auto [val2, one2, eight2] = dp[i + 1][rest - minus];
if(val_new < val2){
dp[i + 1][rest - minus] = T{val_new, one, eight};
}
}
}
}
}
{
vector<int> ans;
{
auto [val, one, eight] = dp[K][0];
ans.resize(val);
}
int ten = 1;
int down = 0;
for(int i = K; i > 0; i--){
auto [val, one, eight] = dp[i][down];
int j = 0;
rep(_, one){
ans[j] += 1 * ten;
j++;
}
rep(_, eight){
ans[j] += 8 * ten;
j++;
}
ten *= 10;
down = (one * 1 + eight * 8) / 10;
// cout << ans;
// cout << down << "\n";
// flush(cout);
}
cout << ans.size() << "\n";
for(auto x : ans){
cout << x << "\n";
}
}
return 0;
}
int main(){
int t;
cin >> t;
rep(_, t) solve();
return 0;
}