이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll=long long;
using pii=pair<int, int>;
const int N=1e5+13;
int n;
int a[N];
int k[N];
int dp[N];
pii sus[1024][1024][13];
int res;
int tr[N];
vector<int> v;
void scan(){
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=n; i++){
cin >> k[i];
}
}
void solve(){
for(int i=1; i<=n; i++){
pii pep=make_pair(0, 0);
for(int pre=0; pre < 1024; pre++){
int z=__builtin_popcount(pre & (a[i] & 1023));
int cc=k[i]-z;
if(cc < 0 || cc >= 10) continue;
pep=max(pep, sus[pre][a[i] >> 10][cc]);
}
dp[i]=pep.fi+1;
tr[i]=pep.se;
for(int suf=0; suf < 1024; suf++){
assert(__builtin_popcount(suf & (a[i] >> 10)) <= 10);
sus[a[i] & 1023][suf][__builtin_popcount(suf & (a[i] >> 10))]=max(sus[a[i] & 1023][suf][__builtin_popcount(suf & (a[i] >> 10))], make_pair(dp[i], i));
}
}
auto sus=max_element(dp+1, dp+n+1);
cout << *sus << '\n';
int id=sus-dp;
while(id!=0){
v.push_back(id);
id=tr[id];
}
reverse(begin(v), end(v));
for(int c: v) cout << c << ' ';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
scan();
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... |