# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672201 | Alihan_8 | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 3395 ms | 93784 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>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int S = 1 << 10, P = 10, N = 1e5+1;
int dp[S][S][P+1], par[N], id[S][S][P+1];
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(par, -1, sizeof(par));
int n; cin >> n;
vector <int> p(n), k(n);
for ( auto &i: p ) cin >> i;
for ( auto &i: k ) cin >> i;
auto f = [&](int l, int r){
return __builtin_popcount(l & r);
};
int it = -1, ans = 0;
for ( int i = 0; i < n; i++ ){
int L = p[i] >> P, R = p[i] & (1 << P)-1, Mx = 1;
for ( int mask = 0; mask < S; mask++ ){
int req = k[i]-f(mask, R);
if ( req < 0 or req > P ) continue;
if ( Mx < dp[mask][L][req]+1 ){
Mx = dp[mask][L][req]+1;
par[i] = id[mask][L][req];
}
}
for ( int mask = 0; mask < S; mask++ ){
int bits = f(mask, L);
if ( Mx > dp[R][mask][bits] ){
dp[R][mask][bits] = Mx;
id[R][mask][bits] = i;
}
}
if ( ans < Mx ){
ans = Mx, it = i;
}
}
vector <int> res;
while ( it != -1 ){
res.pb(it);
it = par[it];
}
reverse(all(res));
cout << (int)res.size() << ln;
for ( auto i: res ) cout << 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... |