이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define vr(v) v.begin(),v.end()
#define rv(v) v.rbegin(),v.rend()
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Davit cout.tie(NULL);
using namespace std;
//#include "algo/debug.h"
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> k(n);
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < n; i++)cin >> k[i];
vector<int> dp(n, 1);
int ans = 1;
int last = 0;
vector<int> prev(n);
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[i]) {
if (dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
prev[i] = j;
}
}
}
if (dp[i] > ans) {
ans = dp[i];
last = i;
}
}
cout << ans << endl;
vector<int> res;
while (prev[last] != last) {
res.pb(last);
last = prev[last];
}
res.pb(last);
reverse(vr(res));
for (int i = 0; i < (int) res.size(); i++) {
cout << res[i] + 1 << " ";
}
}
# | 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... |