# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89664 | antimirage | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 6084 ms | 69196 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[N], ans, ind[25][1025][1025], last;
vector <int> path;
main()
{
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &ar[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &k[i]);
for (int i = 1; i <= n; i++)
{
int pref = (ar[i] >> 10), suf = ar[i] % 1024, res = 0;
for (int j = 0; j < 1024; j++)
{
if ( __builtin_popcount( j & suf ) > k[i] ) continue;
if ( dp[ k[i] - __builtin_popcount( j & suf ) ][pref][j] > res )
{
res = dp[ k[i] - __builtin_popcount( j & suf ) ][pref][j];
p[i] = ind[ k[i] - __builtin_popcount( j & suf ) ][pref][j];
}
}
res++;
if (res > ans){
ans = res;
last = i;
}
for (int j = 0; j < 1024; j++){
if (res > dp[__builtin_popcount(pref & j) ][j][suf])
{
dp[__builtin_popcount(pref & j) ][j][suf] = res;
ind[__builtin_popcount(pref & j) ][j][suf] = i;
}
}
}
cout << ans << endl;
while (last){
path.push_back( last );
last = p[last];
}
reverse(all(path));
for (auto it : path)
printf("%d ", it);
}
/**
4
1 2 3 4
10 0 1 0
2
8 9
20 0
5
5 3 5 3 5
10 1 20 1 20
**/
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... |