Submission #1091722

#TimeUsernameProblemLanguageResultExecution timeMemory
1091722ULTRABIG7Longest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
6072 ms2396 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using db = long double; #define ff first #define ss second #define pb push_back #define all(x) begin(x),end(x) #define FOR(i,a,b) for(int i = (a);i<(b);i++) #define F0R(i,a) FOR(i,0,a) #define rep(a) F0R(_,a) #define each(a,x) for(auto& a:x) #define sz(x) (int)size(x) #define vi vector<int> const int MOD = 1e9+7; const db PI = acos((db)-1); int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin>>n; vi A(n+1), K(n+1); FOR(i,1,n+1){ cin>>A[i]; } FOR(i,1,n+1){ cin>>K[i]; } vi dp(n+1,1), memo(n+1,-1); FOR(i,1,n+1){ FOR(j,1,i){ if(__builtin_popcount(A[i]&A[j]) == K[i] && dp[j]+1>dp[i]){ dp[i] = dp[j] + 1; memo[i] = j; } } } int ans = 0, id = -1; FOR(i,1,n+1){ if(dp[i]>ans){ id = i; ans = dp[i]; } } cout<<ans<<"\n"; vi sol; while(id != -1){ sol.pb(id); id = memo[id]; } reverse(all(sol)); each(x,sol){ 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...