제출 #234008

#제출 시각아이디문제언어결과실행 시간메모리
234008SortingDevil's Share (RMI19_devil)C++14
0 / 100
1591 ms504 KiB
#include <bits/stdc++.h> using namespace std; int d[10], k; string get_largest_string(const string &s){ string answer = ""; for(int i = 0; i < k; ++i) answer += s[i]; for(int i = k; i < (int)s.size(); ++i){ string curr = ""; for(int j = i - k + 1; j <= i; ++j) curr += s[j]; if(curr > answer) answer = curr; } return answer; } pair<string, string> recursion(int cnt, const string &s){ if(!cnt) return {get_largest_string(s), s}; pair<string, string> answer = {"", ""}; for(int i = 1; i <= 9; ++i){ if(d[i]){ --d[i]; pair<string, string> candidate = recursion(cnt - 1, s + (char)('0' + i)); ++d[i]; if(answer.first == "" || candidate < answer) answer = candidate; } } return answer; } void read(){ cin >> k; for(int i = 1; i <= 9; ++i) cin >> d[i]; } void solve_test(){ read(); int cnt = 0; for(int i = 1; i <= 9; ++i) cnt += d[i]; cout << recursion(cnt, "").second << "\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--) solve_test(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...