이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int SEP = 10, BIT = 20, mn = 1e5 + 5;
int bestMask[1 << SEP][1 << SEP][SEP + 1], dp[mn], a[mn], k[mn];
void trace (int i) {
for (int j = i - 1; j >= 0; j--) {
if (__builtin_popcount(a[j] & a[i]) == k[i] && dp[j] + 1 == dp[i]) {
trace(j);
break;
}
}
cout << i + 1 << " ";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> k[i];
int full = (1 << SEP) - 1, ans = 0, optPos = -1;
for (int i = 0; i < n; i++) {
// query part
dp[i] = 1;
for (int halfMask = 0; halfMask < (1 << SEP); halfMask++) {
int curCount = __builtin_popcount(halfMask & a[i]), need = k[i] - curCount;
if (0 <= need && need <= SEP)
dp[i] = max(dp[i], bestMask[halfMask][a[i] >> SEP][need] + 1);
}
// update part
for (int halfMask = 0; halfMask < (1 << SEP); halfMask++) {
int curCount = __builtin_popcount((halfMask << SEP) & a[i]);
bestMask[a[i] & full][halfMask][curCount] = max(bestMask[a[i] & full][halfMask][curCount], dp[i]);
}
if (dp[i] > ans) ans = dp[i], optPos = i;
}
cout << ans << "\n";
trace(optPos);
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... |