# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919487 | KactusJack | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 6020 ms | 25176 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.
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n+1), b(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
vector<vector<int>> dp(n+1, vector<int> (20)), from(n+1, vector<int> (20));
int len = 0, j = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
if(__builtin_popcount(a[j]&a[i]) == b[i] && 1+dp[j][b[j]] > dp[i][b[i]]){
dp[i][b[i]] = 1+dp[j][b[j]];
from[i][b[i]] = j;
}
}
if(dp[i][b[i]] > len){
len = dp[i][b[i]];
j = i;
}
}
len++;
vector<int> v;
while(j && v.size() < len){
v.push_back(j);
j = from[j][b[j]];
}
reverse(v.begin(), v.end());
cout << len << '\n';
for(int x : v){
cout << x << ' ';
}
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... |