# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384537 | antimirage | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 3472 ms | 56064 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 fr first
#define sc second
#define mk make_pair
#define pb emplace_back
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 1e5 + 5;
int dp[25][1025][1025], p[N], n, ar[N], k, ans, ind[25][1025][1025], last, path[N], sz, cn[N];
main()
{
for (int j = 0; j < 1024; j++)
cn[j] = __builtin_popcount(j);
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &ar[i]);
for (int i = 1; i <= n; i++){
scanf("%d", &k);
int pref = (ar[i] >> 10);
int suf = ar[i] - (pref << 10), res = 0;
for (int j = 0; j < 1024; j++)
{
if ( cn[ j & suf ] <= k && dp[ k - cn[ j & suf ] ][pref][j] > res )
{
res = dp[ k - cn[ j & suf ] ][pref][j];
p[i] = ind[ k - cn[ j & suf ] ][pref][j];
}
}
res++;
if (res > ans){
ans = res;
last = i;
}
for (int j = 0; j < 1024; j++){
if (res > dp[cn[pref & j] ][j][suf])
{
dp[cn[pref & j] ][j][suf] = res;
ind[cn[pref & j] ][j][suf] = i;
}
}
}
cout << ans << endl;
while (ans--){
path[++sz] = last;
last = p[last];
}
for (int i = sz; i >= 1; i--)
printf("%d ", path[i]);
}
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... |