제출 #1006736

#제출 시각아이디문제언어결과실행 시간메모리
1006736emad234Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms6488 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 = 10; while(t--){ int j = rand() % n; j++; 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...