이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[100005],k[100005],dp[100005],dp1[100005],pth[100005],mx,in;
vector<int>ans;
string to(int x)
{
string s;
while(x)
{
s.push_back('0'+(x%2));
x/=2;
}
while(s.size()!=9)s.push_back('0');
reverse(s.begin(),s.end());
return s;
}
void bt(int x,int nm,string s,int ai,int aj,int i)
{
if(x==s.size()&&nm==0)
{
if(dp[ai]<dp[aj]+1)
{
dp1[ai]=i;
dp[ai]=dp[aj]+1;
pth[i]=dp1[aj];
}
}
if(x==s.size())return;
if(s[x]=='0')
{
bt(x+1,nm,s,ai,aj*2,i);
bt(x+1,nm,s,ai,aj*2+1,i);
}
else
{
bt(x+1,nm,s,ai,aj*2,i);
bt(x+1,nm-1,s,ai,aj*2+1,i);
}
}
void fp(int x)
{
if(x==0)return;
fp(pth[x]);
ans.push_back(x);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("empty.in","r",stdin);
//freopen("empty.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
dp[a[i]]=1;
if(dp1[a[i]]==0)dp1[a[i]]=i;
}
for(int i=1;i<=n;i++)cin>>k[i];
for(int i=1;i<=n;i++)
{
bt(0,k[i],to(a[i]),a[i],0,i);
if(mx<dp[a[i]])
{
mx=dp[a[i]];
in=i;
}
}
fp(in);
cout<<mx<<endl;
for(int i=0;i<mx;i++)cout<<ans[i]<<' ';
}
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'void bt(int, int, std::__cxx11::string, int, int, int)':
subsequence.cpp:20:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(x==s.size()&&nm==0)
~^~~~~~~~~~
subsequence.cpp:29:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(x==s.size())return;
~^~~~~~~~~~
# | 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... |