Submission #518674

#TimeUsernameProblemLanguageResultExecution timeMemory
518674LptN21Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
3122 ms92096 KiB
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL); #define PI acos(-1.0) #define eps 1e-9 #define FF first #define SS second // VECTOR (6) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() ); // BIT (6) #define CNTBIT(x) __builtin_popcountll(x) #define ODDBIT(x) __builtin_parityll(x) #define MASK(i) (1LL<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define MINBIT(x) (x)&(-x) //typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, int> ii; /* CODE BELOW */ const int N = 1e5 + 7, M = 10; const int oo = 1e9 + 7; const int MOD = 1e9 + 7; int n, m, k, t; int _dp[MASK(M)][MASK(M)][M+1]; int pos[MASK(M)][MASK(M)][M+1]; int trace[N], a[N], b[N]; int cnt[MASK(M)]; signed main() { //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); fastIO; //scanf("%d", &n); cin>>n; for(int i=1;i<=n;i++) { //scanf("%d", &a[i]); cin>>a[i]; } for(int i=1;i<=n;i++) { //scanf("%d", &b[i]); cin>>b[i]; } for(int i=0;i<MASK(M);i++) { cnt[i] = CNTBIT(i); } int ans = 0, ansIdx = 0; for(int i=1;i<=n;i++) { int pref = a[i]>>M; int suff = a[i]&(MASK(M)-1); int mx = 0, idx = 0; for(int j=0;j<MASK(M);j++) { int need = b[i] - cnt[pref&j]; if(need < 0 || need > M) continue; if(mx <= _dp[j][suff][need]) { mx = _dp[j][suff][need]; idx = pos[j][suff][need]; } } trace[i] = idx; if((++mx) > ans) { ans = mx, ansIdx = i; } for(int j=0;j<MASK(M);j++) { int need = cnt[suff&j]; if(_dp[pref][j][need] < mx) { _dp[pref][j][need] = mx; pos[pref][j][need] = i; } } } vector<int> result; while(ansIdx) { result.pb(ansIdx); ansIdx = trace[ansIdx]; } reverse(all(result)); //printf("%d\n", ans); cout<<ans<<"\n"; for(int v:result) { //printf("%d ", v); cout<<v<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...