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 god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
long long a = rng();
return a;
}
int n;
int v[100002], v2[100002];
int dp[100002];
int fw[100002];
int mx[5002], mxval;
int countbit[2000002];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i < (1<<20); ++i)
countbit[i] = __builtin_popcount(i);
for(int i = 1; i <= n; ++i)
cin >> v[i], mxval = max(mxval, v[i]);
for(int i = 1; i <= n; ++i)
cin >> v2[i];
int anss = 0;
if(mxval <= 5000)
{
for(int i = 1; i <= n; ++i)
{
for(int j = 0; j <= mxval; ++j)
if(!mx[j])
continue;
else
{
int xx = countbit[v[i] & j];
if(xx == v2[i] && dp[mx[j]] + 1 > dp[i])
{
dp[i] = dp[mx[j]] + 1;
fw[i] = mx[j];
}
}
dp[i] = max(dp[i], 1);
if(dp[i] > dp[mx[v[i]]])
mx[v[i]] = i;
if(dp[i] > dp[anss])
anss = i;
}
}
else
{
for(int i = 1; i <= n; ++i)
{
if(countbit[v[i]] >= v2[i])
for(int j = i-1; j >= 1; --j)
{
if(dp[i] > j)
break;
int xx = countbit[v[i] & v[j]];
if(xx == v2[i] && dp[j] + 1 > dp[i])
{
dp[i] = dp[j] + 1;
fw[i] = j;
}
}
dp[i] = max(dp[i], 1);
if(dp[i] > dp[anss])
anss = i;
}
}
cout << dp[anss] << '\n';
deque<int> ans;
while(anss)
{
ans.push_front(anss);
anss = fw[anss];
}
for(int i = 0; i < ans.size(); ++i)
cout << ans[i] << " ";
return 0;
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:118:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < ans.size(); ++i)
~~^~~~~~~~~~~~
# | 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... |