이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ldb long double
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define All(x,n) x+1,x+1+n
#define Alll(x,n) x,x+n
#define sz(x) (signed)x.size()
#define unq(x) x.resize(unique(all(x))-x.begin())
#define mpa make_pair
#ifdef NCGM
#include"debug.h"
#else
#define debug(...) "fr";
#endif
using namespace std;
const int N=1e5+3;
int f[N],n,a[N],b[N];
int op[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
For(i,1,n) cin >> a[i];
For(i,1,n) cin >> b[i];
For(i,1,n) {
f[i]=1;
op[i]=0;
For(j,1,i-1)
if (__builtin_popcount(a[i]&a[j])==b[i])
if (f[i]<f[j]+1) {
f[i]=f[j]+1;
op[i]=j;
}
}
int ans=0,lst=-1;
For(i,1,n) {
if (ans<f[i]) {
ans=f[i];
lst=i;
}
}
vector<int> track;
while(lst!=0) {
track.pb(lst);
lst=op[lst];
}
reverse(all(track));
cout << ans << endl;
for(auto el: track) cout << el << " ";
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... |