# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299673 | BeanZ | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 5 ms | 5120 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.
// I_LOVE_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll a[N], k[N], dp[N], par[N][50];
set<ll, greater<ll>> s[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.ans", "w", stdout);
}
ll n;
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> k[i], s[k[i]].insert(i);
for (int i = 1; i <= n; i++) dp[i] = 1;
for (int i = 1; i <= n; i++){
for (int j = 1; j < i; j++){
ll x = a[i] & a[j];
auto it = s[__builtin_popcount(x)].lower_bound(dp[j] + 1);
if (it != s[__builtin_popcount(x)].end()){
dp[i] = max(dp[i], (*it));
par[i][(*it)] = j;
}
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
ll cur;
for (int i = 1; i <= n; i++) if (dp[i] == ans) cur = i;
vector<ll> mem;
mem.push_back(cur);
while (ans > 1){
cur = par[cur][ans];
mem.push_back(cur);
ans--;
}
reverse(mem.begin(), mem.end());
for (auto j : mem) cout << j << " ";
}
/*
5
5 3 5 3 5
10 1 20 1 20
4
1 2 3 4
10 0 1 0
2
8 9
20 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... |