이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* user: puzic-97a
* fname: Mladen
* lname: Puzic
* task: devil
* score: 27.0
* date: 2019-10-10 06:27:52.611650
*/
#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl;cout.flush();
#define NL(x) " \n"[(x)]
#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define lld long long
#define pii pair<int,int>
#define pli pair<lld,int>
#define pil pair<int,lld>
#define pll pair<lld,lld>
#define INF 1000000000
#define LINF 1000000000000000000LL
#define EPS 1e-9
using namespace std;
int K, c[10];
vector<string> s;
deque<string> d;
string solve() {
string X = "";
int idx = s.size()-1;
while(!d.empty()) {
string cur = d.front(); d.pop_front();
s[idx] += cur;
//PRINT(idx);
//PRINT(cur);
if(idx != 0 && !d.empty() && cur != d.front()) {
while(sz(s) > idx) {
d.pb(s.back());
//PRINT(s.back());
s.pop_back();
}
}
//PRINT(cur);
//PRINT(s.size());
idx--;
if(idx == -1) idx = s.size()-1;
}
for(auto x : s) X += x;
return X;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
int T; cin >> T;
while(T--) {
s.clear(); d.clear();
cin >> K;
for(int i = 1; i <= 9; i++) cin >> c[i];
string suffix = ""; ///obrnut!!!!
int cif = 9;
for(int i = 0; i < K-1; i++) {
while(c[cif] == 0) cif--;
suffix += cif+'0';
c[cif]--;
}
while(c[cif] == 0) cif--;
while(c[cif]) s.pb(string(1, cif+'0')), c[cif]--;
for(int i = 1; i <= 9; i++) {
while(c[i]) {
d.push_back(string(1, i+'0'));
c[i]--;
}
}
string x = solve();
reverse(all(suffix));
cout << x + suffix << endl;
}
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... |