# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337918 | boykut | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 8 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <int> a(n);
vector <int> k(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> k[i];
}
if (n <= 15) {
int ans = 0, ans_size = 0;
for (int i = 0; i < (1 << n); i++) {
int num = i, index = n - 1;
vector <int> j;
while (num) {
if (num & 1)
j.push_back(index);
index--;
num >>= 1;
}
reverse(j.begin(), j.end());
int ok = true;
for (int l = 1; l < j.size(); l++) {
if (__builtin_popcount(a[j[l]] & a[j[l - 1]]) != k[j[l]])
ok = false;
}
if (ok) {
if (j.size() >= ans_size) {
ans_size = j.size();
ans = i;
}
}
}
int num = ans, index = n - 1;
vector <int> j;
while (num) {
if (num & 1)
j.push_back(index);
index--;
num >>= 1;
}
reverse(j.begin(), j.end());
cout << j.size() << '\n';
for (int i = 0; i < j.size(); i++) {
cout << j[i] + 1 << ' ';
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |