Submission #672201

#TimeUsernameProblemLanguageResultExecution timeMemory
672201Alihan_8Longest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
3395 ms93784 KiB
#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)

subsequence.cpp: In function 'int main()':
subsequence.cpp:29:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   29 |         int L = p[i] >> P, R = p[i] & (1 << P)-1, Mx = 1;
      |                                       ~~~~~~~~^~
subsequence.cpp: In function 'void IO(std::string)':
subsequence.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...