# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
515274 | Mazaalai | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 8 ms | 332 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>
#define pb push_back
using namespace std;
const int N = 1e5+1;
int n;
int nums[N], bits[N];
int bitCnt(int a) {
return bitset <20>(a).count();
}
signed main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
vector <int> ans;
for (int i = 0; i < n; i++) cin >> nums[i];
for (int i = 0; i < n; i++) cin >> bits[i];
for (int i = 0; i < (1<<n); i++) {
vector <int> cur;
for (int j = 0; j < n; j++)
if (i & (1<<j)) cur.pb(j);
bool pos = 1;
for (int j = 1; j < cur.size(); j++) {
pos &= bitCnt(nums[cur[j-1]]&nums[cur[j]]) == bits[cur[j]];
}
if (pos && cur.size() > ans.size()) ans = cur;
}
cout << ans.size() << "\n";
for (auto el : ans) cout << el+1 << ' '; cout << '\n';
}
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... |