이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define y1 theboatman
#define make_struct(args...) {args}
using namespace std;
int main() {
cin.tie(0);
ios :: sync_with_stdio(0);
int n;
cin >> n;
vector <int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector <int> k(n);
for(int i = 0; i < n; i++) {
cin >> k[i];
}
vector <int> dp(n, 1), from(n, -1);
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if (__builtin_popcount(a[i] & a[j]) == k[j]) {
if (dp[j] < dp[i] + 1) {
dp[j] = dp[i] + 1;
from[j] = i;
}
}
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
ans = max(ans, dp[i]);
}
for(int i = 0; i < n; i++) {
if (dp[i] == ans) {
vector <int> way;
int now = i;
while(now != -1) {
way.push_back(now + 1);
now = from[now];
}
reverse(way.begin(), way.end());
cout << way.size() << "\n";
for(auto i : way) {
cout << i << " ";
}
return 0;
}
}
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... |