제출 #522582

#제출 시각아이디문제언어결과실행 시간메모리
522582dostigatorLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms460 KiB
#pragma GCC optimize("O3") #pragma GCC target("popcnt") #include <bits/stdc++.h> using namespace std; #define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define popcnt __builtin_popcount #define all(a) a.begin(),a.end() #define pii pair<ll,ll> #define mii map<ll,ll> #define pll pair<ll,ll> #define mll map<ll,ll> #define pb push_back #define vt vector #define endl '\n' #define X first #define Y second typedef long double ld; typedef long long ll; const ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=1e6; const ll mod=1e9+7,inf=1e18; ll n,a[N],k[N]; ll pos[(1<<10)]; void solve(){ cin>>n; vt<ll>sub[(1<<10)+1000]; for(ll i=1; i<=n; ++i){ cin>>a[i]; if(sub[a[i]].size())continue; sub[a[i]].pb(i); } for(ll i=1; i<=n; ++i)cin>>k[i]; for(ll i=1; i<=n; ++i){ pos[a[i]]=1; for(ll mask=0; mask<(1<<9)+100; ++mask){ ll h=(mask&a[i]); if(pos[mask]==0 || sub[mask].size()==0)continue;// maybe wrong if(popcnt(h)==k[i]){ if(sub[a[i]].size()<=sub[mask].size()){ sub[a[i]]=sub[mask]; sub[a[i]].pb(i); } } } } unsigned long long int mx=0,ans=0; for(ll i=1; i<=n; ++i){ if(mx<sub[a[i]].size()){ mx=sub[a[i]].size(); ans=a[i]; } } cout<<mx<<endl; if(!mx)return; for(ll x:sub[ans])cout<<x<<' '; } int main() { IShowSpeed; ll tt=1; //cin>>tt; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...