# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206377 | Ruxandra985 | Devil's Share (RMI19_devil) | C++14 | 147 ms | 2168 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;
int n;
int f[10] , f2[10] , sol[1000000];
int possible (int nr){
int i , p , maxi , scz;
//if (nr == 31)
// printf ("a");
for (i = 1 ; i <= 9 ; i++)
f2[i] = f[i];
if (nr % 10 > nr / 10){
/// ar trb ca nr % 10 sa apara o sg data si la sf
sol[n] = nr % 10;
f2[nr % 10]--;
/// daca nr / 10 nu e maxim nu se poate
for (i = nr / 10 + 1 ; i <= 9 ; i++)
if (f2[i])
return 0;
/// now what
p = 0;
for (i = 1 ; i <= 9; i++){
while (f2[i]){ /// le pui cresc si e ok
sol[++p] = i;
f2[i]--;
}
}
return 1;
}
else { /// n % 10 <= n / 10
for (i = 1 ; i <= 9 ; i++)
if (f2[i])
maxi = i;
p = n + 2;
scz = 0;
if (maxi > nr / 10){ /// ai grija
if (f2[maxi] != 1)
return 0;
f2[maxi] = 0;
sol[n] = maxi;
for (i = nr / 10 + 1 ; i <= 9 ; i++)
if (f2[i])
return 0;
/// acum n / 10 = maxi
/// pot sa pun orice dar sa nu am n/10 pe n-1?
i = nr % 10;
if (f2[i]){ /// pun o val cat mai mare
sol[n - 1] = i;
f2[i]--;
}
p = n;
scz = 2;
}
for (i = 9 ; i ; i--){
while (f2[i]){ /// le pui cresc si e ok
if (p - 2 <= 0)
p = n + 1 - scz;
sol[p - 2] = i;
p -= 2;
f2[i]--;
}
}
return 1;
}
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int t , k , i;
fscanf (fin,"%d",&t);
for (;t;t--){
fscanf (fin,"%d",&k);
n = 0;
for (i=1;i<=9;i++){
fscanf (fin,"%d",&f[i]);
n += f[i];
}
if (k == 2){ /// subtask 14p
for (i = 11 ; i <= 99 ; i++){
if (i % 10 != 0 && f[i % 10] && f[i / 10]){
if (possible(i))
break;
}
}
for (i = 1 ; i <= n ; i++)
fprintf (fout,"%d",sol[i]);
fprintf (fout,"\n");
}
}
return 0;
}
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... |