# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299390 | luciocf | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 5586 ms | 93520 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>
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+10;
int n;
int a[maxn], b[maxn];
int dp[maxn], ant[maxn];
pii best[1<<10][1<<10][11];
void print(int ans)
{
printf("%d\n", ans);
int at;
for (int i = 1; i <= n; i++)
if (dp[i] == ans)
at = i;
vector<int> out;
while (at)
{
out.push_back(at);
at = ant[at];
}
reverse(out.begin(), out.end());
for (auto x: out)
printf("%d ", x);
printf("\n");
}
int main(void)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &b[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
{
dp[i] = 1, ant[i] = 0;
int half1 = 0, half2 = 0;
for (int j = 0; j < 10; j++)
{
if (a[i]&(1<<j))
half1 += (1<<j);
if (a[i]&(1<<(j+10)))
half2 += (1<<j);
}
for (int mask = 0; mask < (1<<10); mask++)
{
int x = __builtin_popcount(half1&mask);
if (b[i] >= x && b[i]-x <= 10)
{
if (1 + best[mask][half2][b[i]-x].ff > dp[i])
{
dp[i] = 1 + best[mask][half2][b[i]-x].ff;
ant[i] = best[mask][half2][b[i]-x].ss;
}
}
}
for (int mask = 0; mask < (1<<10); mask++)
{
int x = __builtin_popcount(half2&mask);
if (dp[i] > best[half1][mask][x].ff)
best[half1][mask][x] = {dp[i], i};
}
ans = max(ans, dp[i]);
}
print(ans);
}
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... |