# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133860 | Kastanda | Longest beautiful sequence (IZhO17_subsequence) | C++11 | 6013 ms | 54024 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;
const int N = 100005, SQ = 1024;
int n, A[N], P[N];
pair < int , int > dp[21][SQ][SQ];
inline void Max(pair < int , int > &a, pair < int , int > b) {a = max(a, b);}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i ++)
scanf("%d", &A[i]);
int Mx = 0, Bi = 0;
for (int i = 1; i <= n; i ++)
{
int k, a = A[i];
scanf("%d", &k);
pair < int , int > Bst = {0, 0};
for (int j = 0; j < SQ; j ++)
if (k >= __builtin_popcount(a >> 10 & j))
Max(Bst, dp[k - __builtin_popcount(a >> 10 & j)][a & 1023][j]);
P[i] = Bst.second; Bst.first ++; Bst.second = i;
for (int j = 0; j < SQ; j ++)
Max(dp[__builtin_popcount(a & j)][j][a >> 10], Bst);
if (Bst.first > Mx)
Mx = Bst.first, Bi = i;
}
vector < int > R;
while (Bi)
R.push_back(Bi), Bi = P[Bi];
reverse(R.begin(), R.end());
printf("%d\n", (int)R.size());
for (int v : R)
printf("%d ", v);
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... |