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>
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 <= 4; ++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 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... |