Submission #1006738

#TimeUsernameProblemLanguageResultExecution timeMemory
1006738emad234Longest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
49 ms6504 KiB
#include "bits/stdc++.h" #define F first #define S second #define ll long long #define pii pair<ll,ll> const ll mxN = 5e5 + 5; const ll mod = 1e9 + 7; using namespace std; int a[mxN],b[mxN]; int dp[mxN]; int prv[mxN]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i = 1;i <= n;i++){ cin >>a[i]; } for(int i = 1;i <= n;i++){ cin >>b[i]; } int ans = 1; int mxid = 1; dp[1] = 1; for(int i = 2;i <= n;i++){ dp[i] = 1; int t = 1000; while(t--){ int j = rand() % n; j++; if(j == i) continue; if(__builtin_popcount(a[i] & a[j]) == b[i]) { if(dp[j] + 1 > dp[i]){ dp[i] = dp[j] + 1; prv[i] = j; } } } if(dp[i] > ans){ ans = dp[i]; mxid = i; } } cout<< ans<<'\n'; vector<int>v; while(mxid){ v.push_back(mxid); mxid = prv[mxid]; } reverse(v.begin(),v.end()); for(auto x : v) cout<<x<<' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...