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>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
int main() {
#ifdef HOME
ifstream cin("A.in");
ofstream cout("A.out");
#endif
int t, i, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> t;
while(t--) {
cin >> k;
vector <int> num(10);
for(i = 1; i <= 9; i++) {
cin >> num[i];
}
string b;
int cur = 0;
for(i = 9; i >= 1; i--) {
while(num[i] > 0 && cur < k - 1) {
cur++;
b.push_back(i + '0');
num[i]--;
}
}
reverse(b.begin(), b.end());
vector <string> a;
for(i = 9; i >= 1; i--) {
if(num[i]) {
a.resize(num[i], string(1, i + '0'));
num[i] = 0;
break;
}
}
deque <string> deq;
for(i = 1; i <= 9; i++) {
while(num[i] > 0) {
num[i]--;
deq.push_back(string(1, i + '0'));
}
}
int pos = (int)a.size() - 1;
while(deq.size()) {
auto cur = deq.front();
deq.pop_front();
a[pos].append(cur);
if(deq.size() && deq.front() != cur && pos != 0) {
while(a.size() > pos) {
deq.push_back(a.back());
a.pop_back();
}
}
pos = (pos == 0 ? a.size() : pos) - 1;
}
for(auto it : a) {
cout << it;
}
cout << b << "\n";
}
return 0;
}
Compilation message (stderr)
devil.cpp: In function 'int main()':
devil.cpp:67:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(a.size() > pos) {
~~~~~~~~~^~~~~
# | 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... |