제출 #575207

#제출 시각아이디문제언어결과실행 시간메모리
575207gg123_peLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
5 ms1748 KiB
#include <bits/stdc++.h> using namespace std; typedef unordered_map <int,int> um; #define f(i,a,b) for(int i = a; i < b; i++) const int N = 1e5 + 6, M = 1e6 + 5; int n, a[N], b[N], ans[N], pre[N], id; int dp[1<<10][1<<10][11], ID[1<<10][1<<10][11]; int main(){ int pr = 0; cin >> n; f(i,1,n+1) cin >> a[i]; f(i,1,n+1) cin >> b[i]; f(i,1,n+1){ int x, y; x = a[i] >> 10; y = a[i] - (x << 10); f(j,0,1<<10){ int p = __builtin_popcount((x&j)); if(p <= b[i] and ans[i] < 1 + dp[j][y][b[i]-p]){ pre[i] = ID[j][y][b[i]-p]; ans[i] = 1 + dp[j][y][b[i]-p]; } } f(j,0,1<<10){ int p = __builtin_popcount((y&j)); if(dp[x][j][p] < ans[i]){ dp[x][j][p] = ans[i]; ID[x][j][p] = i; } } if(ans[i] > pr){ id = i; pr = ans[i]; } } vector <int> ra; while(id > 0){ ra.push_back(id); id = pre[id]; } reverse(ra.begin(), ra.end()); cout << ra.size() << "\n"; for(int x: ra) cout << x << " "; cout << "\n"; 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...