# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112962 | adiyer | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 6038 ms | 3232 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 optimize ("g",on)
// #pragma GCC optimize("inline")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC optimize ("03")
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1e5 + 2;
const int M = (1 << 8);
ll n, pos;
ll a[N], k[N], dp[N];
void sol(){
cin >> n, pos = 1;
for(ll i = 1; i <= n; i++) cin >> a[i];
for(ll i = 1; i <= n; i++) cin >> k[i];
for(ll i = 1; i <= n; i++){
dp[i] = 1;
for(ll j = 1; j < i; j++)
if((__builtin_popcount(a[j] & a[i]) == k[i]))
dp[i] = max(dp[i], dp[j] + 1);
if(dp[i] > dp[pos]) pos = i;
// cout << dp[i] << '\n';
}
vector < ll > ans;
ans.pb(pos);
while(ans.size() < dp[ans[0]]){
if(ans.size() == dp[ans[0]]) break;
for(ll i = pos - 1; i >= 1; i--){
if(__builtin_popcountll(a[pos] & a[i]) == k[pos] && dp[pos] == dp[i] + 1){
pos = i;
break;
}
}
ans.pb(pos);
}
reverse(ans.begin(), ans.end());
cout << ans.size() << '\n';
for(ll x : ans) cout << x << ' ';
}
signed main(){
ios
sol();
// slow();
// stress();
}
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... |