이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>
using namespace std;
const int N = 5003, mod = 1e9 + 7;
int n;
int a[N], k[N];
vector<int> pv[N];
int dp[N], pr[N];
int cnt(int x)
{
int res = 0;
while (x)
{
res += x & 1;
x >>= 1;
}
return res;
}
void solve()
{
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++)
{
pv[i].push_back(0);
for (int j = i - 1; j > 0; j--)
{
if (cnt(a[i] & a[j]) == k[i])
{
pv[i].push_back(j);
}
}
}
int ans = 0, ai = 0;
for (int i = 1; i <= n; i++)
{
for (int p : pv[i])
{
if (dp[p] + 1 > dp[i])
{
dp[i] = dp[p] + 1;
pr[i] = p;
}
}
if (ans < dp[i])
{
ans = dp[i];
ai = i;
}
}
vector<int> av;
while (ai != 0)
{
av.push_back(ai);
ai = pr[ai];
}
cout << ans << endl;
for (int i = ans - 1; i >= 0; i--)
cout << av[i] << ' ';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
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... |