# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502455 | wwdd | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 2105 ms | 50328 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>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
const int MB = 10;
const int MA = 1<<MB;
const int LIM = MA-1;
int dp[MA][MA][MB+1];
int poc[MA];
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
vl mol(n,0),pt(n,-1);
vl wo,wk;
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++) {
ll t;
cin >> t;
wo.push_back(t);
}
for(int i=0;i<n;i++) {
ll t;
cin >> t;
wk.push_back(t);
}
poc[0] = 0;
for(int i=1;i<MA;i++) {
poc[i] = poc[i>>1]+(i&1);
}
for(int i=0;i<n;i++) {
int ho = wo[i]>>MB;
int lo = wo[i]&LIM;
mol[i] = 1;
for(int j=0;j<MA;j++) {
int rem = wk[i]-poc[ho&j];
if(rem < 0 || rem > MB) {continue;}
int cand = dp[j][lo][rem];
if(cand == -1) {continue;}
if(mol[cand]+1 > mol[i]) {
mol[i] = mol[cand]+1;
pt[i] = cand;
}
}
for(int j=0;j<MA;j++) {
int kt = poc[j&lo];
int dv = dp[ho][j][kt];
if(dv == -1 || mol[dv] < mol[i]) {
dp[ho][j][kt] = i;
}
}
}
int mi = 0;
for(int i=0;i<n;i++) {
if(mol[i] > mol[mi]) {
mi = i;
}
}
vl ans;
while(mi != -1) {
ans.push_back(mi);
mi = pt[mi];
}
reverse(ans.begin(),ans.end());
cout << ans.size() << '\n';
for(int i=0;i<ans.size();i++) {
if(i > 0) {cout << " ";}
cout << ans[i]+1;
}
cout << '\n';
}
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... |