| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1128039 | _Temirhan | Longest beautiful sequence (IZhO17_subsequence) | C++20 | 6102 ms | 192220 KiB | 
#include <bits/stdc++.h>
using namespace std;
  
#define int long long
#define pb push_back
#define sz(x) x.size()
#define F first
#define S second
#define nl '\n'
void Tima() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}  
const int N = 2e5 + 1;
const int inf = 1e12;
const int mod = 998244353;
signed main() 
{
    Tima();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >>n;
    int a[n + 1], k[n + 1];
    for( int i = 1; i <= n; ++i )
        cin >>a[i];
    for( int i = 1; i <= n; ++i )
        cin >>k[i];
    vector< int >dp(n + 1, 1), p(n + 1, -1);
    int mx = 1, r = 1;
    for( int i = 1; i <= n; ++i )
    {
        for( int j = 1; j < i; ++j )
            if( __builtin_popcount(a[j] & a[i]) == k[i] && dp[j] + 1 > dp[i] )
            {
                dp[i] = dp[j] + 1;
                p[i] = j;
            }
        if( dp[i] > mx )
        {
            mx = dp[i];
            r = i;
        }
    }
    vector< int >ans;
    while( p[r] != -1 )
    {
        ans.pb( r );
        r = p[r];
    }
    ans.pb( r );
    reverse(ans.begin(), ans.end());
    cout <<mx <<nl;
    for( int i: ans )
        cout <<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... | ||||
