| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 945264 | vjudge1 | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1 ms | 3420 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
using namespace std;
const int N = 1e5  + 2;
const int base = ((1 << 20) - 1) ^ ((1 <<  10) - 1);
int val[(1 << 10)][(1 << 10)][22];
int a[N  + 2];
int  k[N  + 2];
int bit_count[(1 << 10)];
int dp[N + 2];
int tv[N + 2];
void solve() {
    int n;
    cin >> n;
    for(int i = 0 ; i <(1 << 10) ; i ++){
        bit_count[i] = __builtin_popcount(i);
    }
    for(int i  = 1; i <= n ; i ++)cin >> a[i];
    for(int i = 1; i <= n ;i ++)cin >> k[i];
    int res = 0;
    for(int i = 1; i <= n ; i ++){
        int first =  a[i] ^ (a[i] & base);
        int second = a[i] >> 10;
        for(int j = 0 ; j < (1 << 5) ;j ++){
            int x = bit_count[(j & first)];
            if(k[i] < x) continue;
            if(dp[tv[i]] < dp[val[second][j][k[i] - x]]){
                tv[i] = val[second][j][k[i] - x];
            }
        }
        dp[i] = dp[tv[i]] + 1;
        for(int j = 0 ; j < ( 1 << 5) ; j ++){
          //  if(j == 0) cout << first << " " <<bit_count[j & second] << "\n";
            if(dp[val[j][first][bit_count[j & second]]] < dp[i]){
              //  cout << j << " " << first << " " << bit_count[j & second]  << " " << i <<"\n";
                val[j][first][bit_count[j & second]] = i;
            }
        }
        if(dp[res] < dp[i])res = i;
    }
    vector < int > ans;
    while(res > 0){
        ans.push_back(res);
        res =tv[res];
    }
    reverse(ans.begin() , ans.end());
    cout << ans.size() << '\n';
    for(auto vl : ans)cout << vl << " ";
    
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "test."
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}
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... | ||||
