# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258622 | dantoh000 | Devil's Share (RMI19_devil) | C++14 | 443 ms | 1912 KiB |
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;
typedef long long ll;
int k;
int d[10];
int ans[100005];
int n;
int main(){
int TC;
scanf("%d",&TC);
while (TC--){
scanf("%d",&k);
n = 0;
for (int i = 1; i <= 9; i++){
scanf("%d",&d[i]);
n += d[i];
}
if (k == 2){
int F = 1, S = 9;
for (int i = n-1; i >= 0; i--){
while (d[F] == 0) F++;
while (d[S] == 0) S--;
//printf("%d digit: %d %d\n",i,F,S);
if ((n-i) % 2 == 1){
ans[i] = S;
d[S]--;
}
else{
ans[i] = F;
d[F]--;
}
}
for (int i = 0; i < n; i++){
printf("%d",ans[i]);
}
printf("\n");
}
else if (n <= 12){
vector<int> v;
for (int i = 1; i <= 4; i++) for (int j = 0; j < d[i]; j++) v.emplace_back(i);
vector<int> ans(n);
ll best = 100000000000;
do{
ll mx = 0;
for (int i = 0; i <= n-k; i++){
ll cur = 0;
for (int j = 0; j < k; j++){
cur = (10*cur + v[j+i]);
}
mx = max(cur,mx);
}
if (best > mx){
//printf("%d: ",mx);
best = mx;
for (int i = 0; i < n; i++){
ans[i] = v[i];
//printf("%d",ans[i]);
}
//printf("\n");
}
}
while (next_permutation(v.begin(),v.end()));
for (int i = 0; i < n; i++){
printf("%d",ans[i]);
}
printf("\n");
}
}
}
Compilation message (stderr)
# | 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... |