# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388369 | Dymo | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 5608 ms | 102540 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;
#define ll long long
#define ull long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn =4e5+10;
const ll mod=998244353 ;
const ll base=1e18;
ll n;
ll a[maxn];
ll k[maxn];
ll ans[maxn];
ll dp[(1ll<<10)][(1ll<<10)][12];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
cin>> n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
for (int i=1;i<=n;i++)
{
cin>>k[i];
}
ll pos=-1;
ll mx=0;
for (int i=1;i<=n;i++)
{
ans[i]=1;
ll lf=a[i]>>10;
ll rt=a[i]&((1ll<<10)-1);
for (int j=0;j<(1ll<<10);j++)
{
ll cnt=__builtin_popcount(j&rt);
if (k[i]-cnt>=0&&k[i]-cnt<=10)
ans[i]=max(ans[i],dp[lf][j][k[i]-cnt]+1);
}
for (int j=0;j<(1ll<<10);j++)
{
dp[j][rt][__builtin_popcount(lf&j)]=max(dp[j][rt][__builtin_popcount(lf&j)],ans[i]);
}
if (ans[i]>mx)
{
mx=ans[i];
pos=i;
}
}
cout <<mx<<endl;
ll t=pos;
vector<ll> vt;
vt.pb(pos);
for (int i=pos-1;i>=1;i--)
{
// cout <<ans[i]<<" "<<ans[t]<<" "<<<<endl;
if (ans[i]+1==ans[t]&&__builtin_popcount(a[i]&a[t])==k[t])
{
// cout <<"WYTF"<<endl;
vt.pb(i);
t=i;
if (ans[t]==1) break;
}
}
reverse(vt.begin(),vt.end());
for (auto to:vt) cout<<to<<" ";
/*4
1 2 3 4
10 0 1 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... |