# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38301 | mirbek01 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 4809 ms | 93828 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>
#pragma GCC optimize("Ofast")
# define pb push_back
# define fr first
# define sc second
# define mk make_pair
using namespace std;
const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e5 + 5;
typedef long long ll;
int n, a[N], k[N], bit[N], pr[N], M = 1024;
pair <int, int> dp[11][1024][1024], ans;
vector <int> res;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &a[i]);
for(int i = 1; i <= n; i ++)
scanf("%d", &k[i]);
for(int i = 0; i < M; i ++)
bit[i] = __builtin_popcount(i);
for(int i = 1; i <= n; i ++){
int pref = (a[i] >> 10), suff = a[i] % M, cur = 1, p = 0;
for(int mask = 0; mask < M; mask ++){
int need = k[i] - bit[mask & pref];
if(need < 0 || need > 10) continue;
if(cur < dp[need][mask][suff].fr + 1)
cur = dp[need][mask][suff].fr + 1, p = dp[need][mask][suff].sc;
}
pr[i] = p;
for(int mask = 0; mask < M; mask ++){
int need = bit[mask & suff];
if(dp[need][pref][mask].fr < cur)
dp[need][pref][mask] = mk(cur, i);
}
if(ans.fr < cur)
ans = mk(cur, i);
}
while(ans.sc){
res.pb(ans.sc);
ans.sc = pr[ans.sc];
}
reverse(res.begin(), res.end());
printf("%d\n", res.size());
for(int i = 0; i < res.size(); i ++)
printf("%s%d", i ? " ":"", res[i]);
}
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... |