結果

問題 No.3316 Make 81181819 with only 0,1,or 8
コンテスト
ユーザー Carpenters-Cat
提出日時 2025-10-31 21:23:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 964 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 201,120 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-31 21:23:54
合計ジャッジ時間 5,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int N = 81181819;

std::vector<int> Bs;
vector<int> calc(int X, int mx, int mlen = 7, vector<int> ans = {}) {
	if (!X) {
		return ans;
	}
	if (ans.size() >= mlen) return {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	vector<int> ret = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	for (auto& a : Bs) {
		if (a > mx || a > X) continue;
		int Y = X - a;
		ans.push_back(a);
		auto b = calc(Y, a, mlen, ans);
		if (b.size() <= mlen) {
			ret = b;
			mlen = b.size();
		}
		ans.pop_back();
	}
	return ans;
}
int main () {
	int L = (((((((2 * 3) + 1) * 3 + 1) * 3 + 2) * 3 + 1) * 3 + 2) * 3 + 1) * 3 + 2;
	int XX[] = {0, 1, 8};
	for (int i = L; i >= 0; i --) {
		int y = 0;
		int b = 1;
		int j = i;
		while (j) {
			y += b * XX[j % 3];
			j /= 3;
			b *= 10;
		}
		Bs.push_back(y);
	}
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		auto ret = calc(N - n, N);
		cout << ret.size() << endl;
		for (auto a : ret) cout << a << endl;
	}
}
0