이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int NM = 1e5;
int n, a[NM+5], k[NM+5], dp[NM+5], trace[NM+5], best = 1;
int popcnt[1024], mx[1024][1024][11];
vector <int> v;
int main(){
ios_base::sync_with_stdio(0);
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];
for (int i = 0; i < 1024; i++) popcnt[i] = __builtin_popcount(i);
for (int i = 0; i < 1024; i++)
for (int j = 0; j < 1024; j++)
for (int t = 0; t <= 10; t++)
mx[i][j][t] = -1;
for (int i = 1; i <= n; i++){
dp[i] = 1;
for (int j = 0; j < 1024; j++){
int tmp = popcnt[a[i]&j];
if (k[i]-tmp < 0 || k[i]-tmp > 10) continue;
int t = mx[j][a[i]>>10][k[i]-tmp];
if (t != -1 && dp[t]+1 > dp[i]){
dp[i] = dp[t]+1;
trace[i] = t;
}
}
for (int j = 0; j < 1024; j++){
int &t = mx[a[i]&1023][j][popcnt[(a[i]>>10)&j]];
if (t == -1 || dp[i] > dp[t]) t = i;
}
if (dp[i] > dp[best]){
best = i;
}
}
cout << dp[best] << '\n';
while (best > 0){
v.push_back(best);
best = trace[best];
}
for (int i = (int)v.size()-1; i >= 0; i--) cout << v[i] << ' ';
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... |