제출 #498262

#제출 시각아이디문제언어결과실행 시간메모리
498262couplefireDevil's Share (RMI19_devil)C++17
100 / 100
155 ms5184 KiB
#include <bits/stdc++.h> 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; if(idx != 0 && (d.empty() || cur != d.front())) { while((int)s.size() > idx) { d.push_back(s.back()); s.pop_back(); } } idx--; if(idx == -1) idx = s.size()-1; } for(auto x : s) X += x; return X; } int main() { cin.tie(0)->sync_with_stdio(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 = ""; 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.push_back(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(suffix.begin(), suffix.end()); cout << x + suffix << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...