이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int M = (1<<10);
const int maxn = 1e5+3;
int i,j,p,q,n,m,a[maxn],k[maxn],previous[maxn];
pair<int,int> dp[M][M][11],ans;///fixed (previous) left half,(current) right half, number of bits for & with the right half
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n;i++)
cin>>k[i];
for(i=1;i<=n;i++)
{
pair <int,int> cur={0,0};
int left = (a[i]>>10);
int right = (a[i]&((1<<10)-1));
for(j=0;j<M;j++)
{
int ost = k[i]-__builtin_popcount(j&left);
if(ost<0 || ost>10)continue;
cur = max(cur,dp[j][right][ost]);
}
cur.first++;
previous[i] = cur.second;
cur.second = i;
ans=max(ans,cur);
for(int j=0;j<M;j++)
{
p = __builtin_popcount(j&right);
dp[left][j][p]=max(cur,dp[left][j][p]);
}
}
cout<<ans.first<<endl;
p=ans.second;
stack <int> s;
while(p>0)
{
s.push(p);
p=previous[p];
}
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
return 0;
}
# | 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... |