제출 #198078

#제출 시각아이디문제언어결과실행 시간메모리
198078model_codeDevil's Share (RMI19_devil)C++17
100 / 100
110 ms5232 KiB
/**
* user:  puzic-97a
* fname: Mladen
* lname: Puzic
* task:  devil
* score: 100.0
* date:  2019-10-10 06:30:24.414140
*/
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...