結果
| 問題 |
No.3316 Make 81181819 with only 0,1,or 8
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2025-11-01 08:33:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,586 bytes |
| コンパイル時間 | 4,150 ms |
| コンパイル使用メモリ | 302,156 KB |
| 実行使用メモリ | 222,608 KB |
| 最終ジャッジ日時 | 2025-11-01 08:34:43 |
| 合計ジャッジ時間 | 55,670 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/modint>
// using namespace atcoder;
// using mint = modint998244353;
using ll = long long;
#define fix(x) fixed << setprecision(x)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
const int X = 81181819;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
unordered_map<int, vector<int>> mp;
vector<pair<int,vector<int>>> a;
vector<int> v(5559);
for(int i=1;i<=5558;++i){
int x = 0, m = i, o = 1;
while(m){
x += (m%3 + (m%3)/2*6)*o;
m /= 3;
o *= 10;
}
v[i] = x;
mp[x] = {x};
for(int j=1;j<=i;++j) mp[v[j]+x] = {v[j], x};
}
for(auto p:mp) a.emplace_back(p);
sort(all(a));
int m = a.size();
int t;
cin >> t;
while(t--){
int n;
cin >> n;
n = 81181819 - n;
vector<int> ans;
ans.assign(7,0);
int k = n, o = 1;
while(k){
int x = k % 10;
if(x>=8) ans[0] += 7 * o, x -= 7;
rep(i,x) ans[i] += o;
k /= 10, o *= 10;
}
while(ans.back()==0) ans.pop_back();
if(mp.count(n)) ans = mp[n];
else{
for(int l=0,r=m-1;;++l){
while(r>=0 || a[l].first+a[r].first>n) --r;
if(r<l) break;
if(a[l].first+a[r].first==n && ans.size()>a[l].second.size()+a[r].second.size()){
ans.resize(0);
for(int x:a[l].second) ans.emplace_back(x);
for(int x:a[r].second) ans.emplace_back(x);
}else if(mp.count(n-a[l].first-a[r].first)){
cout << a[l].first << " " << a[r].first << " " << n-a[l].first-a[r].first << '\n';
auto& v = mp[n-a[l].first-a[r].first];
if(ans.size()>a[l].second.size()+a[r].second.size()+v.size()){
ans.resize(0);
for(int x:a[l].second) ans.emplace_back(x);
for(int x:a[r].second) ans.emplace_back(x);
for(int x:v) ans.emplace_back(x);
}
}
}
}
cout << ans.size() << '\n';
for(int x:ans) cout << x << '\n';
}
return 0;
}
houren