# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000288 | Hanksburger | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1 ms | 604 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>
using namespace std;
int dp[100005], pre[100005], a[100005], k[100005], ind[260];
stack<int> s;
int bitCount(int x, int y)
{
int cnt=0;
for (int i=0; i<8; i++)
if (x&y&(1<<i))
cnt++;
return cnt;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, cur, mx=0;
cin >> n;
for (int i=1; i<=n; i++)
cin >> a[i];
for (int i=1; i<=n; i++)
cin >> k[i];
for (int i=1; i<=n; i++)
{
dp[i]=1;
for (int j=0; j<256; j++)
{
if (ind[j] && bitCount(a[i], j)==k[i])
{
if (dp[i]<dp[ind[j]]+1)
{
dp[i]=dp[ind[j]]+1;
pre[i]=ind[j];
}
}
}
if (mx<dp[i])
{
mx=dp[i];
cur=i;
}
if (dp[ind[a[i]]]<dp[i])
ind[a[i]]=i;
}
cout << dp[cur] << '\n';
while (cur)
{
s.push(cur);
cur=pre[cur];
}
while (!s.empty())
{
cout << s.top() << ' ';
s.pop();
}
}
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... |