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 <stdio.h>
#include <vector>
using namespace std;
long long findN(vector<int> in, int sum)
{
long long res = 1e18;
bool good = false;
for (int p : in) if (p) good = true;
if (!good) return (sum == 0) ? 1 : 0;
if (in.size() == 1){
res = 0;
int x=0;
if (in[0] & 1){
res = 1;
for (x++;x<=9;x++) if (in[0] & (1 << x)){
res = x; break;
}
res *= 10;
}
for (x++;x<=9;x++) if (in[0] & (1 << x)){
res = res * 10 + x;
}
}
else{
for (int x=0;x<=9;x++){
vector<int> reduce;
for (int i=0,v=x;i<in.size();i++){
if (i == 0 || v == 0) reduce.push_back(0);
int h = in[i];
if (h & (1 << v)) h ^= (1 << v);
reduce.back() |= h;
if (++v == 10) v = 0;
}
if (in != reduce){
long long g = findN(reduce,sum+x) * 10 + x;
if (g == 0 && (sum == 0 || in[0] & 1)) continue;
if (res > g)
res = g;
}
}
}
return res;
}
int main()
{
vector<int> input;
int N,x; scanf ("%d",&N); while (N--){
scanf ("%d",&x);
input.push_back(1<<x);
}
printf ("%lld\n",findN(input,0));
return 0;
}
# | 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... |