이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, v[nx], k[nx];
pair<int, int> t, vl[nx], dp[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>v[i], dp[i]={1, i};
for (int i=1; i<=n; i++) cin>>k[i];
for (int i=0; i<256; i++) vl[i]={-1, -1};
for (int i=1; i<=n; i++)
{
for (int j=0; j<256; j++)
{
if (vl[j].first==-1) continue;
if (__builtin_popcount(v[i]&j)==k[i]) dp[i]=max(dp[i], {vl[j].first+1, vl[j].second});
}
vl[v[i]]=max(vl[v[i]], {dp[i].first, i});
//cout<<"here "<<i<<' '<<v[i]<<' '<<vl[v[i]].first<<' '<<vl[v[i]].second<<'\n';
//cout<<"dp "<<i<<' '<<dp[i].first<<' '<<dp[i].second<<'\n';
t=max(t, {dp[i].first, i});
}
cout<<t.first<<'\n';
vector<int> res;
while (dp[t.second].second!=t.second) res.push_back(t.second), t.second=dp[t.second].second;
res.push_back(t.second);
reverse(res.begin(), res.end());
for (auto x:res) cout<<x<<' ';
}
# | 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... |