This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void TestCase() {
int k;
cin >> k;
vector<int> f(10);
for (int i = 1; i < 10; ++i) {
cin >> f[i];
}
string last = "";
for (int i = 9; i > 0 && (int)last.size() < k - 1; --i) {
int use = min(f[i], k - 1 - (int)last.size());
f[i] -= use;
for (int j = 0; j < use; ++j) {
last += '0' + i;
}
}
reverse(last.begin(), last.end());
deque<string> dq, q;
for (int i = 9; i > 0; --i) {
if (f[i]) {
for (int j = 0; j < f[i]; ++j) {
dq.emplace_back(string(1, '0' + i));
}
f[i] = 0;
break;
}
}
for (int i = 1; i < 10; ++i) {
for (int j = 0; j < f[i]; ++j) {
q.emplace_back(string(1, '0' + i));
}
}
while (!q.empty()) {
auto s = q.front();
q.pop_front();
dq.back() += s;
if (dq.back() != dq.front()) {
q.emplace_back(dq.back());
dq.pop_back();
}
while (!q.empty() && q.back() == dq.front()) {
dq.emplace_back(q.back());
q.pop_back();
}
}
for (auto it : dq) {
cout << it;
}
cout << last << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tests;
cin >> tests;
for (int tc = 1; tc <= tests; ++tc) {
TestCase();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |