이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(a) ((int) a.size())
const int N = 1e5 + 15;
const int L = 10;
int n, a[N], k[N], pr[N];
pair<int, int> dp[(1 << L)][(1 << (L + 1))][21];
int cnt[(1 << L)][(1 << L)];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
cin >> k[i];
}
for(int x = 0; x < (1 << L); x++) for(int y = 0; y < (1 << L); y++) {
cnt[x][y] = __builtin_popcount(x & y);
}
int ans = 1, pos = 1;
for(int i = 1; i <= n; i++) {
int l = a[i] % (1 << L);
int r = a[i] >> L;
int cur = 1;
for(int j = 0; j < (1 << L); j++) {
int nd = k[i] - cnt[j][r];
if(nd >= 0 && nd <= L) {
if(dp[j][l][nd].first + 1 > cur) {
cur = dp[j][l][nd].first + 1;
pr[i] = dp[j][l][nd].second;
}
}
}
if(cur > ans) {
ans = cur;
pos = i;
}
for(int j = 0; j < (1 << L); j++) {
if(dp[r][j][cnt[j][l]].first < cur) {
dp[r][j][cnt[j][l]].first = cur;
dp[r][j][cnt[j][l]].second = i;
}
}
}
cout << ans << '\n';
vector<int> res;
while(pos) {
res.pb(pos);
pos = pr[pos];
}
reverse(res.begin(),res.end());
for(int x : res) cout << x << ' ';
}
| # | 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... |