Submission #1195468

#TimeUsernameProblemLanguageResultExecution timeMemory
1195468Yusif_NazarliLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
319 ms327680 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define Mor_Te ios_base::sync_with_stdio(0); cin.tie(); cout.tie(0); #define intt long long #define pb push_back #define gcd __gcd #define all(v) v.begin() , v.end() using namespace std; using namespace __gnu_pbds; template<typename T> using indexed_set = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>; const intt sz = 5e3 + 5; const intt INF = 1e18; const intt MOD = 1e9 + 7; intt used[sz]; void Yusiff(){ intt n; cin >> n; intt a[n + 1], k[n + 1]; for(intt i = 0; i < n; ++i){ cin >> a[i]; } for(intt i = 0; i < n; i++){ cin >> k[i]; } intt dp[sz] , par[sz]; for(intt i = 0; i < n; i++){ dp[i] = 1; par[i] = -1; for(intt j = 0; j < n; j++){ if(__builtin_popcount(a[j] & a[i]) == k[i]){ if(dp[j] + 1 > dp[i]){ dp[i] = dp[j] + 1; par[i] = j; } } } } intt mx = 0 , idx = -1; for(intt i = 0; i < n; i++){ if(dp[i] > mx){ mx = dp[i]; idx = i; } } vector<intt> res; while(idx != -1){ res.pb(idx + 1); idx = par[idx]; } reverse(all(res)); cout << mx << endl; for(auto x: res) cout << x << " "; cout << '\n'; } signed main(){ Mor_Te intt t = 1; // cin >> t; while(t--){ Yusiff(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...