이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define F first
#define S second
const int N = 1e5 + 5;
const int MX = (1 << 8) + 5;
int n, a[N], k[N], pre[N], dp[N], pos[MX];
vector <int> vec;
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) {
pos[i] = -1;
pre[i] = -1;
}
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
for (int m = 0; m < MX-5; ++m) {
if (__builtin_popcount((a[i] & m)) != k[i] || pos[m] == -1) { continue; }
if (dp[i] < dp[pos[m]] + 1) {
dp[i] = dp[pos[m]] + 1;
pre[i] = pos[m];
}
}
if (pos[a[i]] == -1) { pos[a[i]] = i; continue; }
if (dp[i] > dp[pos[a[i]]]) {
pos[a[i]] = i;
}
}
int ans = 0, ps = 0;
for (int i = 1; i <= n; ++i) {
if (ans < dp[i]) {
ans = dp[i];
ps = i;
}
}
while (ps != -1) {
vec.pb(ps);
ps = pre[ps];
}
reverse(all(vec));
cout << sz(vec) <<"\n";
for (int i = 0; i < sz(vec); ++i) {
cout << vec[i] <<" ";
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
//cin >> tests;
while (tests --) {
solve();
}
return 0;
}
/*
Just Chalish!
4
1 2 3 4
10 0 1 0
2
8 9
20 0
5
5 3 5 3 5
10 1 20 1 20
*/
# | 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... |