이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int b = 10;
int n;
vector<int> a;
vector<int> k;
void solution() {
vector<int> l(n), r(n);
for (int i = 0; i < n; i++) {
int mask = (1<<b) - 1;
r[i] = (a[i] & mask);
l[i] = ((a[i]^r[i]) >> b);
}
vector<int> dp(n);
vector<int> prev(n);
int table[1<<b][1<<b][21];
for (int i = 0; i < (1<<b); i++) {
for (int j = 0; j < (1<<b); j++) {
for (int k = 0; k < 21; k++) {
table[i][j][k] = -1;
}
}
}
for (int i = 0; i < n; i++) {
dp[i] = 1;
prev[i] = i;
// cout << "SOLVING FOR " << i+1 << endl;
//get answer for dp[i]
for (int s = 0; s < (1<<b); s++) {
int bc = __builtin_popcount(s&l[i]);
if (bc > k[i]) continue;
int j = table[s][r[i]][k[i]-bc];
// cout << bitset<4>(s) << " " << bitset<4>(r[i]) << " " << k[i]-bc << endl;
if (j == -1) continue;
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j]+1;
prev[i] = j;
}
}
// cout << endl;
//insert dp[i]'s value to table
for (int s = 0; s < (1<<b); s++) {
int bc = __builtin_popcount(s&r[i]);
int j = table[l[i]][s][bc];
if (j == -1 || dp[i] > dp[j]) table[l[i]][s][bc] = i;
// cout << bitset<4>(l[i]) << " " << bitset<4>(s) << " " << bc << endl;
}
// cout << endl;
for (int s = 0; s < (1<<b); s++) {
for (int i = 0; i <= 3; i++) {
// cout << bitset<4>(s) << " " << i << " " << table[0][s][i] << endl;
}
// cout << endl;
}
}
int globans = 0;
for (int i = 1; i < n; i++) {
if (dp[i] > dp[globans]) globans = i;
}
int x = globans;
vector<int> ans;
while (true) {
ans.push_back(x+1);
if (x == prev[x]) break;
x = prev[x];
}
reverse(ans.begin(), ans.end());
cout << dp[globans] << endl;
for (int x : ans) cout << x << " ";
cout << endl;
}
void solve() {
cin >> n;
a = k = vector<int>(n);
for (int& x : a) cin >> x;
for (int& x : k) cin >> x;
solution();
}
int main() {
int t = 1;
//cin >> t;
while (t--) solve();
}
# | 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... |