This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 5005;
int a[maxn], k[maxn];
int dp[maxn], pre[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> k[i];
}
a[0] = 1048575;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
if (j == 0 || __builtin_popcount(a[i] & a[j]) == k[i]) {
if (dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
pre[i] = j;
}
}
}
}
int mx = 0, pos = 0;
for (int i = 1; i <= n; i++) {
if (dp[i] > mx) {
mx = dp[i];
pos = i;
}
}
cout << mx << endl;
stack<int> s;
while (pos) {
s.push(pos);
pos = pre[pos];
}
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... |