이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 1e5 + 5;
int a[N], k[N], dp1[N], ans[N];
pair<int, int> dp2[N];
vector<int> v;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n;
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++) {
for (int j = 0; j < (1 << 8); j++) {
if (__builtin_popcount(a[i] & j) != k[i] or dp2[a[i]].fi > dp2[j].fi) continue;
dp2[a[i]].fi = dp2[j].fi + 1, ans[i] = dp2[j].se, dp2[a[i]].se = i;
}
if (dp2[a[i]].fi == 0) dp2[a[i]].fi = 1, dp2[a[i]].se = i;
}
int id = 0;
for (int i = 1; i <= n; i++) if (dp2[a[i]].fi > dp2[a[id]].fi) id = i;
cout << dp2[a[id]].fi << "\n";
while (id != 0) {
v.push_back(id);
id = ans[id];
}
reverse(v.begin(), v.end());
for (auto x : v) cout << x << " ";
cout << "\n";
}
# | 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... |