# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465492 | prvocislo | Sequence (BOI14_sequence) | C++17 | 154 ms | 972 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 <iostream>
#include <vector>
#include <set>
#include <algorithm>
typedef long long ll;
using namespace std;
ll solve(const vector<int>& v, bool not9)
{
if (v.size() == 1)
{
ll ans = 0;
for (int i = 1; i <= 9; i++) if (v[0] & (1 << i))
{
ans = ans * 10 + i;
if (ans == i && (v[0] & 1)) ans *= 10;
}
if (!ans && (v[0] & 1)) ans = 10;
return ans;
}
else
{
ll ans = 1e16;
for (int last = 0; last <= 9 - (int)not9; last++)
{
vector<int> v2;
int mask = 0;
bool zero = false;
for (int i = 0, j = last; i < v.size(); i++, j = (j + 1) % 10)
{
int my = v[i];
if (my & (1 << j)) my ^= (1 << j);
mask |= my;
if (!j && (v[i] & 1)) zero = true;
if (j == 9 || i + 1 == v.size())
{
v2.push_back(mask);
mask = 0;
}
}
ll num = solve(v2, (v.size() == 2 && last == 9));
if (!num && zero) num = 1; // potrebujeme mat nieco na zaciatku, aby nam neodisla ta 0
num = num * 10 + last;
ans = min(ans, num);
}
return ans;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int k;
cin >> k;
vector<int> v(k);
for (int i = 0; i < k; i++) cin >> v[i], v[i] = (1 << v[i]);
cout << solve(v, false) << "\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... |