Submission #465427

#TimeUsernameProblemLanguageResultExecution timeMemory
465427YuisuyunoLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5383 ms93888 KiB
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define bc(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 100005
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"

using namespace std;

typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;

int n;
int a[N];
int k[N];
ii dp[(1<<10)+5][(1<<10)+5][11];
int now[N], pr[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++) cin >> k[i];
    int res = -1; int res_p = -1;
    for(int i=1; i<=n; i++){
        now[i] = 1;
        int j=0, ori = (a[i]>>10), fori = (a[i]>>10);
        for(int mask=0; mask < (1<<10); mask++){
            int lef = k[i] - bc(ori&mask);
            if (lef >= 0 && lef <= 10){
                int lsthalf = (a[i] & ((1<<10)-1));
                if (dp[mask][lsthalf][lef].fi + 1 > now[i]){
                    now[i] = dp[mask][lsthalf][lef].fi+1;
                    j = dp[mask][lsthalf][lef].se;
                }
            }
        }
        pr[i] = j;
        for(int msk = 0; msk < (1<<10); msk++){
            int changed = bc(a[i]&msk);
            if (dp[fori][msk][changed].fi < now[i]){
                dp[fori][msk][changed] = ii(now[i],i);
            }
        }
        if (now[i]>res){
            res = now[i];
            res_p = i;
        }
    }
    vector<int> ans;
    cout << res << '\n';
    while (res_p){
        ans.pb(res_p);
        res_p = pr[res_p];
    }
    reverse(all(ans));
    for(auto x : ans) cout << x << ' ';
    return 0;
}

Compilation message (stderr)

subsequence.cpp:24:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   24 | const int inf = 1e10;
      |                 ^~~~
subsequence.cpp:25:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+10' to '-2147483648' [-Woverflow]
   25 | const int minf = -1e10;
      |                  ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...