이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int MAXN = 1e5 + 15;
int dp[1025][1025][11], n, a[MAXN], b[MAXN];
int pos[1025][1025][11];
int prv[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
memset(prv, -1, sizeof(prv));
pair<int, int> best = {0, 0};
for (int i = 0; i < n; i++){
int lhs = a[i] % (1 << 10), rhs = (a[i] >> 10);
int opt = 0;
for (int j = 0; j < 1024; j++)
if (b[i] - __popcount(j&rhs) <= 10 && b[i] - __popcount(j&rhs) >= 0 && ckmax(opt, dp[j][lhs][b[i] - __popcount(j&rhs)]))
prv[i] = pos[j][lhs][b[i] - __popcount(j&rhs)];
for (int j = 0; j < 1024; j++)
if (ckmax(dp[rhs][j][__popcount(j&lhs)], opt + 1))
pos[rhs][j][__popcount(j&lhs)] = i;
ckmax(best, {opt + 1, i});
}
vector<int> ans;
for (int i = best.second; i != -1; ans.push_back(i), i = prv[i]);
reverse(ans.begin(), ans.end());
cout << ans.size() << endl;
for (auto it : ans) cout << it + 1 << ' ';
}
# | 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... |