이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 1e6 + 5;
int n;
int a[maxn];
int k[maxn];
int dp[maxn], p[maxn];
int store[1024][1024][12];
int count(int mask) {
return __builtin_popcount(mask);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=n; i++) {
cin>>k[i];
}
//store[mask][mask2][cnt]: best index if our top10bits=mask, and we merge with someone whose lower10bits=mask2,
// and we need cnt bits in the top10
for (int i=1; i<=n; i++) {
int l = a[i]>>10;
int r = a[i]&1023;
//qry
for (int mask=0; mask<1024; mask++) {
int need = k[i] - count(mask&r);
if (need>10 || need<0) continue;
if (1+dp[store[l][mask][need]] > dp[i]) {
dp[i]=1+dp[store[l][mask][need]];
p[i]=store[l][mask][need];
}
}
//insert
for (int mask=0; mask<1024; mask++) {
int cnt = count(mask&l);
if (dp[store[mask][r][cnt]] < dp[i]) {
store[mask][r][cnt] = i;
}
}
}
int at = 1;
for (int i=1; i<=n; i++) {
if (dp[at]<dp[i]) at=i;
}
vector<int> ans;
while (at) {
ans.push_back(at);
at=p[at];
}
sort(ans.begin(),ans.end());
cout<<ans.size()<<endl;
for (int i: ans) cout<<i<<" ";
cout<<endl;
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... |