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>
// #pragma GCC optimize("-O3")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//using namespace __gnu_pbds;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define vec vector
#define getin freopen("input.txt","r",stdin);
#define getout ofstream cout("output.txt");
#define getfiles getin;getout
#define m_p make_pair
#define f first
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define s second
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef long double ld;
template<typename T> bool umax(T &a,const T &b) {return (a<b?a=b,1:0);}
template<typename T> bool umin(T &a,const T &b) {return (a>b?a=b,1:0);}
ll sqr(ll a) { return a * a; }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>o_st;
pii dp[1<<10][1<<10][21];
signed main(){
fast_io;
int n;
cin>>n;
vec<int>a(n);
for(auto &z : a)
cin>>z;
vec<int>b(n);
for(auto &z : b)
cin>>z;
vec<int>mdp(n,1);
vec<int>p(n);
iota(all(p),0);
auto getf=[&](int x){
return ((pw(10)-1)&x);
};
auto getse=[&](int x){
return ((x-getf(x))>>10);
};
for(int i=0;i<n;i++){
int f=getf(a[i]),s=getse(a[i]);
pii vf={0,i};
for(int msk=0;msk<pw(10);msk++){
int o=b[i]-__builtin_popcount(f&msk);
if(o>=0 && umax(vf,dp[msk][s][o])){
o=o;
}
}
vf.f++;
p[i]=vf.s;
mdp[i]=vf.f;
vf.s=i;
for(int msk=0;msk<pw(10);msk++){
int o=__builtin_popcount(s&msk);
umax(dp[f][msk][o],vf);
}
}
cout<<*max_element(all(mdp))<<endl;
int id=max_element(all(mdp))-mdp.begin();
vec<int>ans;
while(p[id]!=id){
ans.pb(id);
id=p[id];
}
ans.pb(id);
reverse(all(ans));
for(auto &z : ans)
cout<<z+1<<' ';
return 0;
}
/*
3
1 2 3
0 0 0
*/
Compilation message (stderr)
subsequence.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
10 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |