# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
661045 | Kaztaev_Alisher | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 3 ms | 468 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.
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 505;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
ll a[N] , k[N] , b[N] , res[N];
void solve(){
int n;
cin >> n;
int ans = 0;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> k[i];
for(int mask = 1; mask < (1 << n) ; mask++){
int cnt = 0;
for(int j = 0 ; j < n; j++){
if((mask >> j) & 1) b[cnt++] = j;
}
bool ok = 1;
for(int i = 1; i < cnt; i++){
if(bpop((a[b[i]] & a[b[i-1]])) != k[b[i]]) ok = 0;
}
if(ok){
if(cnt > ans){
for(int i = 0; i <cnt ; i++) res[i] = b[i];
ans = cnt;
}
}
}
cout << ans <<"\n";
for(int i = 0; i < ans; i++) cout <<res[i]+1 <<" ";
}
signed main(){
file("subsequence");
ios;
solve();
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... |