| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 333989 | Kerim | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1 ms | 492 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"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=256;
PII dp[N];
int a[MAXN],k[MAXN],bit[N],par[MAXN];
int main(){
for(int i=0;i<N;i++)
bit[i]=__builtin_popcount(i);
// freopen("file.in", "r", stdin);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
for(int i=1;i<=n;i++)
scanf("%d",k+i);
int ans=0,who;
vector<int>res;
for(int i=1;i<=n;i++){
int res=1;
for(int j=0;j<N;j++){
if(bit[j&a[i]]==k[i])
if(umax(res,dp[j].ff+1))
par[i]=dp[j].ss;
}
if(par[i]>=i)
par[i]=0;
if(res>dp[a[i]].ff)
dp[a[i]]=mp(res,i);
if(umax(ans,res))
who=i;
}
while(who){
res.pb(who);
who=par[who];
}reverse(all(res));
printf("%d\n",ans);
tr(it,res)
printf("%d ",*it);
puts("");
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... | ||||
