이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, half = (1 << 10) + 5, K = 21;
int n, a[N], k[N], f[half][half][K], dp[N], trace[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("IZhO17_subsequence.INP", "r", stdin);
// freopen("IZhO17_subsequence.OUT", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i)
cin >> k[i];
int halve = (1 << 10) - 1, res = 0;
for (int i = 1; i <= n; ++i) {
int s = (a[i] & halve);
dp[i] = 1;
for (int fd = 0; fd < halve; ++fd) {
int fbc = __builtin_popcount((a[i] >> 10) & fd);
if (fbc > k[i]) continue;
int val = dp[f[fd][s][k[i] - fbc]] + 1;
if (dp[i] < val) {
dp[i] = val;
trace[i] = f[fd][s][k[i] - fbc];
}
}
for (int sc = 0; sc < halve; ++sc) {
int pre = dp[f[a[i] >> 10][sc][__builtin_popcount(s & sc)]];
if (pre < dp[i]) {
f[a[i] >> 10][sc][__builtin_popcount(s & sc)] = i;
}
}
res = max(res, dp[i]);
}
cout << res << endl;
int i;
for (i = 1; i <= n; ++i) if (dp[i] == res)
break;
vector <int> ans; ans.clear();
while (i) {
ans.push_back(i);
i = trace[i];
}
reverse(ans.begin(), ans.end());
for (int j : ans) cout << j << ' ';
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... |