제출 #1101661

#제출 시각아이디문제언어결과실행 시간메모리
1101661orcslopLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
183 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") bool ckmin(int& a, int b){ return b < a ? a = b, true : false; } bool ckmax(int& a, int b){ return b > a ? a = b, true : false; } const int N = 1e5 + 5; int n; int a[N]; int k[N]; int p[N]; int dp[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> k[i]; } fill(dp + 1, dp + n + 1, 1); for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ if(__builtin_popcount(a[i] & a[j]) == k[i]){ if(ckmax(dp[i], dp[j] + 1)){ p[i] = j; } } } } int ans = 0, curr = 0; for(int i = 1; i <= n; i++){ if(ckmax(ans, dp[i])){ curr = i; } } cout << ans << '\n'; vector<int> ret; while(curr){ ret.push_back(curr); curr = p[curr]; } reverse(ret.begin(), ret.end()); for(auto x : ret) cout << x << ' '; 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...