Submission #724320

#TimeUsernameProblemLanguageResultExecution timeMemory
724320nishkarshLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
17 ms41328 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 10; const int middle = 1<<N; int ones[middle]; int dp[middle][middle][N]; int main(){ for(int i = 0; i < 1<<(N-1); ones[(i<<1)+1]++, i++) ones[(i<<1)+1] = ones[i<<1] = ones[i]; int n; cin >> n; int a[n],k[n],siz[n],link[n]; fill(link,link+n,-1); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> k[i]; int ans = 0, ind = 0; for(int i = 0; i < middle; i++) for(int j = 0; j < middle; j++) for(int m = 0; m < N; m++) dp[i][j][m] = -1; for(int i = 0; i < n; i++){ siz[i] = 0; for(int j = 0; j < middle; j++){ if(k[i] < ones[(a[i]>>N) & j]) continue; int *ptr = &dp[a[i]>>N][a[i]&(middle-1)][k[i] - ones[(a[i]>>N) & j]]; if(*ptr != -1) if(siz[*ptr] > siz[i]) siz[i]=siz[*ptr],link[i]=*ptr; } siz[i]++; for(int j = 0; j < middle; j++){ int *ptr = &dp[a[i]>>N][j][ones[a[i]&j]]; if((*ptr == -1) || (siz[*ptr] < siz[i])) *ptr=i; } if(ans < siz[i]){ ans = siz[i]; ind = i; } // for(int i = 0; i < middle; i++) for(int j = 0; j < middle; j++) for(int m = 0; m < N; m++) cout << i << " " << j << " " << m << " " << dp[i][j][m] << "\n"; // cout << i << " " << siz[i] << "\n"; } cout << ans << "\n"; vector<int> nums; while(ind >= 0){ nums.push_back(ind); ind = link[ind]; } reverse(nums.begin(),nums.end()); for(int i : nums) cout << i+1 << " "; 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...