이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int NM = 1e5;
int n, a[NM+5], k[NM+5], dp[NM+5], trace[NM+5], best = 1;
vector <int> v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> k[i];
for (int i = 1; i <= n; i++){
dp[i] = 1;
for (int j = 1; j < i; j++)
if (__builtin_popcount(a[j]&a[i]) == k[i] && dp[j]+1 > dp[i]){
dp[i] = dp[j]+1;
trace[i] = j;
}
if (dp[i] > dp[best]) best = i;
}
cout << dp[best] << '\n';
while (best > 0){
v.push_back(best);
best = trace[best];
}
for (int i = (int)v.size()-1; i >= 0; i--) cout << v[i] << ' ';
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... |