이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LINE "--------------------\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
using PII = pair <int, int>;
const int N = 1e5+5;
const int M = (1<<10);
int n;
int nums[N], bits[N], res[N], par[N];
PII dp[M][M][11]; // first value, second parent
int match[M][M];
int bitCnt(int a) {
return bitset <20>(a).count();
}
signed main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int ans = 1;
for (int i = 1; i <= n; i++) cin >> nums[i];
for (int i = 1; i <= n; i++) cin >> bits[i];
for (int i = 0; i < M; i++)
for (int j = i; j < M; j++) { // 2^20 * 20
match[i][j] = match[j][i] = bitCnt(i&j);
}
// cout << match[3][3] << '\n';
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) { // n*2^20
PII cur = {0, 0};
int lhs = nums[i]>>10, rhs = nums[i]%(1<<10);
for (int mask = 0; mask < M; mask++) { // 2^10
int matched = match[lhs][mask], tar = bits[i] - matched;
if (matched > bits[i] || (tar > 10)) continue;
if (dp[mask][rhs][tar].ff > cur.ff) cur = dp[mask][rhs][tar];
}
res[i] = cur.ff+1;
par[i] = cur.ss;
for (int mask = 0; mask < M; mask++) { // 2^20
int matched = match[rhs][mask];
if (dp[lhs][mask][matched].ff < res[i]) {
dp[lhs][mask][matched] = {res[i], i};
}
}
if (res[i] > res[ans]) ans = i;
// cout << res[i] << "," << par[i] << " \n"[i==n];
}
vector <int> tmp;
while(ans != 0) {
tmp.pb(ans);
ans = par[ans];
}
cout << tmp.size() << '\n';
while(!tmp.empty()) {
cout << tmp.back() << " ";
tmp.pop_back();
}
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... |