제출 #519167

#제출 시각아이디문제언어결과실행 시간메모리
519167nickmet2004Longest beautiful sequence (IZhO17_subsequence)C++11
7 / 100
137 ms82260 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5 , M = 10; int n,a[N] , k[N]; int dp[1<<10][1<<10][M] , p[1<<10][1<<10][M], P[N] , mx , id; int main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i= 0; i< n; ++i) cin >> a[i]; for(int i = 0; i< n; ++i)cin >> k[i]; memset(P , -1 , sizeof(P)); for(int i =0; i < n; ++i){ int A = a[i] >> M , B = a[i] & ((1<<M) - 1) , ans = 0; for(int l =0; l < (1<<M); ++l){ int y = k[i] - __builtin_popcount(l & A); if(y < 0 || y > 10) continue; if(dp[l][B][y] > ans){ ans = dp[l][B][y]; P[i] = p[l][B][y]; } } ans++; if(ans > mx)mx = ans, id = i; for(int r= 0; r< (1<<M);++r){ int y = __builtin_popcount(B & r); if(dp[A][r][y] < ans){ dp[A][r][y] = ans; p[A][r][y] = i; } } } vector<int> X; while(1){ X.emplace_back(id); id = P[id]; if(id == -1)break; } reverse(X.begin() , X.end()); cout << X.size() << endl; for(int x : X)cout << x+1 << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...