제출 #1356078

#제출 시각아이디문제언어결과실행 시간메모리
1356078blackscreen1Longest beautiful sequence (IZhO17_subsequence)C++20
40 / 100
6092 ms1996 KiB
#include <bits//stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,abm,lzcnt,popcnt")
#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))
int n, a[100005], b[100005], c[100005], p[100005], m, x;
vector<int> v;
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";
	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...