# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299680 | BeanZ | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 103 ms | 18936 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[5005][5005];
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];
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];
if (__builtin_popcount(x) == k[i]){
dp[i] = max(dp[i], dp[j] + 1);
par[i][dp[j] + 1] = j;
}
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
ll cur = -1;
for (int i = 1; i <= n; i++) if (dp[i] == ans && cur == -1) 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... |