Submission #1356077

#TimeUsernameProblemLanguageResultExecution timeMemory
1356077blackscreen1Longest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
6095 ms1968 KiB
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
int n, a[100005], b[100005], c[100005], p[100005], m, x;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	iloop(0, n) cin >> a[i];
	iloop(0, n) cin >> b[i];
	iloop(0, n) c[i] = 1;
	memset(p, -1, sizeof(p));
	iloop(1, n) jloop(0, i) if (__builtin_popcount(a[j]&a[i]) == b[i] && c[i] < c[j] + 1) c[i] = c[j] + 1, p[i] = j;
	m = *max_element(c, c+n);
	cout << m << "\n";
	vector<ll> v;
	iloop(0, n) if (c[i] == m) {x = i; break;}
	iloop(0, m) {v.push_back(x); x = p[x];}
	while (v.size()) {cout << v.back() + 1 << " "; v.pop_back();}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...