This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ui unsigned int
#define ld long double
#define pl pair<long long int, long long int>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define sz size()
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 2e5 + 11;
const int inf = 1e17 + 1;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1 , 0, -1, 1, -1, 1};
const double eps = 1e-10;
void solve() {
int n;
cin >> n;
if(n <= 15) {
int a[n + 1];
int c[n + 1];
for(int i = 0; i < n; i++) {
cin >> a[ i ];
}
for(int i = 0; i < n; i++) {
cin >> c[ i ];
}
vector<int> v;
vector<int> ans;
for(int mask = 1; mask < (1 << n); mask++) {
v.clear();
for(int i = 0; i < n; i++) {
if(mask & (1 << i)) {
v.pb( i );
}
}
bool fl = true;
for(int k = 1; k < v.sz; k++) {
int x = a[v[ k ]];
int y = a[v[k - 1]];
int bit = c[v[ k ]];
if(__builtin_popcount(x & y) != bit) {
fl = false;
break;
}
}
if(fl) {
if(ans.sz < v.sz) {
ans = v;
}
}
}
cout << ans.sz << "\n";
for(auto it : ans) {
cout << it + 1 << ' ';
}
}
}
signed main() {
// freopen("sum.in", "r", stdin);
// freopen("sum.out", "w", stdout);
boost;
int tt = 1;
// cin >> tt;
for(int i = 1; i <= tt; i++) {
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message (stderr)
subsequence.cpp: In function 'void solve()':
subsequence.cpp:55:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int k = 1; k < v.sz; k++) {
| ^
# | 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... |