Submission
Status:
-PPPPPPP-P
Subtask/Task Score:
80/100
Score: 80
User: Dormon
Problemset: เลขฐานเบญจภาคได้ดุล
Language: cpp
Time: 0.035 second
Submitted On: 2025-10-14 19:53:08
#include <iostream>
#include <vector>
using namespace std;
const vector<int> v = {-2, -1, 0, 1, 2};
bool solve(int n, int s, int _5, vector<int> &ans){
if (n == s){
// cout << n << ' ' << s << '\n';
for (auto e:ans)
cout << e << ' ';
cout << '\n';
return true;
}
if (_5 >= 5000) return false; // 5^6 > 5000
for (auto e:v){
ans.push_back(e);
if (solve(n, s + _5 * e, _5 * 5, ans)) return true;
ans.pop_back();
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--){
int n;
cin >> n;
vector<int> ans;
solve(n, 0, 1, ans);
}
}