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];
if (n<=5000)
{
for (int i=1; i<=n; i++)
{
dp[i]=1;
for (int j=1; j<i; j++)
{
if (bitCount(a[i], a[j])==k[i])
{
if (dp[i]<dp[j]+1)
{
dp[i]=dp[j]+1;
pre[i]=j;
}
}
}
if (mx<dp[i])
{
mx=dp[i];
cur=i;
}
}
}
else
{
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)
subsequence.cpp: In function 'int main()':
subsequence.cpp:73:24: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | cout << dp[cur] << '\n';
| ^~~~
# | 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... |