# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134460 | Kastanda | Sequence (BOI14_sequence) | C++11 | 276 ms | 1528 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.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll Solve(vector < int > A, bool w)
{
int n = (int)A.size();
bool Fail = 1;
for (int a : A)
if (a) Fail = 0;
if (Fail)
return (!w);
if (n == 1)
{
ll rs = 0;
for (int i = 1; i <= 9; i ++)
if (A[0] >> i & 1)
{
rs = rs * 10 + i;
if (A[0] & 1)
rs *= 10, A[0] ^= 1;
}
if (A[0] & 1)
rs = 10;
return (rs);
}
ll rs = (ll)1e18;
for (int i = 0; i <= 9; i ++)
{
int d = i;
vector < int > B;
for (int j = 0; j < n; j ++)
{
if (!j || !d)
B.push_back(0);
int b = A[j];
if (b >> d & 1)
b ^= (1 << d);
B.back() |= b;
d ++;
if (d == 10)
d = 0;
}
if (A == B) continue;
ll rt = Solve(B, w | (i > 0)) * 10 + i;
if (!rt && (!w || A[0] & 1))
continue;
rs = min(rs, rt);
}
return (rs);
}
int main()
{
int n;
scanf("%d", &n);
vector < int > A(n);
for (int &a : A)
scanf("%d", &a), a = 1 << a;
return !printf("%lld\n", Solve(A, 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... |