이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const int maxN = 2e6 + 5;
const int maxD = (1 << 10) + 5;
int f[maxN],n,a[maxN],k[maxN],tr[maxN];
int dp[11][maxD][maxD];
vector<int> q;
void input()
{
cin >> n;
for (int i = 1;i <= n;++i) cin >> a[i];
for (int i = 1;i <= n;++i) cin >> k[i];
}
void solve()
{
f[0] = 0;
int res = 1;
for (int i = 1;i <= n;++i)
{
f[i] = 1;
int pre = a[i] / (1 << 10);
int suf = a[i] % (1 << 10);
for (int k0 = 0;k0 < 11;++k0)
for (int j = 0;j < (1 << 10);++j)
if (k0 + __builtin_popcountll(suf & j) == k[i] && f[dp[k0][pre][j]] + 1 > f[i])
{
f[i] = f[dp[k0][pre][j]] + 1;
tr[i] = dp[k0][pre][j];
}
for (int j = 0;j < (1 << 10);++j)
if (f[dp[__builtin_popcountll(j & pre)][j][suf]] < f[i]) dp[__builtin_popcountll(j & pre)][j][suf] = i;
if (f[res] < f[i]) res = i;
}
cout << f[res] << "\n";
do
{
q.push_back(res);
res = tr[res];
}
while (res != 0);
reverse(q.begin(),q.end());
for (int v : q) cout << v << " ";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("A.inp","r",stdin);
// freopen("A.out","w",stdout);
input();
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... |