結果

問題 No.3625 Find Superfibonacci Number
コンテスト
ユーザー kwm_t
提出日時 2026-08-14 22:28:52
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 51 ms / 2,000 ms
+ 454µs
コード長 2,232 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,628 ms
コンパイル使用メモリ 338,232 KB
実行使用メモリ 9,416 KB
最終ジャッジ日時 2026-08-14 22:29:52
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<int, int>
template<typename A, typename B> inline bool chmax(A& a, const B& b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A& a, const B& b) { if (a > b) { a = b; return true; } return false; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	// 100999999999999をベースに考えて
	// これより-1けた、-2けたで構築が可能か?
	// 適当に固定してやればできそうだけどめんどう
	int t; cin >> t;
	while (t--) {
		int x; cin >> x;
		string s;
		rrep2(i, 1, 10)rrep(j, 10)rrep(k, 10) {
			if (i <= j + k)continue;
			int nx = x - i - j - k;
			if (nx < 0)continue;
			auto upd = [&](string t) {
				if (s.empty()) {
					s = t;
					return;
				}
				if (t.size() > s.size())return;
				if (t.size() < s.size()) {
					s = t;
					return;
				}
				if (t < s) {
					s = t;
					return;
				}
			};
			if (nx == 0) {
				string tmp;
				tmp += char(i + '0');
				tmp += char(j + '0');
				tmp += char(k + '0');
				upd(tmp);
			}
			else if (nx % 9) {
				string tmp;
				if (nx % 9 <= i) {
					tmp += char(nx % 9 + '0');
					tmp += char(i + '0');
					tmp += char(j + '0');
					tmp += char(k + '0');
				}
				else {
					tmp += char(i + '0');
					tmp += char(j + '0');
					tmp += char(k + '0');
					tmp += char(nx % 9 + '0');
				}
				rep(i, nx / 9)tmp += char('9');
				upd(tmp);
			}
			else {
				string tmp;
				tmp += char(i + '0');
				tmp += char(j + '0');
				tmp += char(k + '0');
				rep(i, nx / 9)tmp += char('9');
				upd(tmp);
			}
		}
		cout << s << endl;//tleしたらなきねいり
	}
	return 0;
}
0