Submission #484094

#TimeUsernameProblemLanguageResultExecution timeMemory
484094vinnipuh01Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms204 KiB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>

using namespace std;

const long long oo = 1000000000000000000;

long long int  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    freopen ( "sum.in", "r", stdin )
*/

int dp[ 21 ], p[ 3000001 ], mp[ 3000001 ], mpp[ 3000001 ];
vector <int> v;

int main () {
	int n;
	cin >> n;
	int a[ n + 1 ];
	int b[ n + 1 ];
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ];
	}
	for ( int j = 1; j <= n; j ++ ) {
		cin >> b[ j ];
		p[ j ] = -1;
	}
	for ( int i = 0; i < 20; i ++ ) {
		dp[ i ] = 1;
		p[ 1 ] = -1;
		mp[ i ] = a[ 1 ];
		mpp[ i ] = 1;
	}
	for ( int i = 2; i <= n; i ++ ) {
		for ( int j = 0; j < 20; j ++ ) {
			if ( __builtin_popcount( mp[ j ] & a[ i ] ) == b[ i ] ) {
				dp[ j ] ++;
				p[ i ] = mpp[ j ];
				mp[ j ] = a[ i ];
				mpp[ j ] = i;
			}
		}
	}
	for ( int i = 0; i < 20; i ++ ) {
		if ( mx < dp[ i ] ) {
			pos = mpp[ i ];
			mx = dp[ i ];
		}
	}
	cout << mx << "\n";
	for ( int i = pos; i != -1; i = p[ i ] ) {
		v.push_back( i );
	}
	for ( int i = v.size() - 1; i >= 0; i -- )
		cout << v[ i ] << " ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...