이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
int n; cin >> n;
vi a(n);
vector<short> k(n);
for(auto& i : a) cin >> i;
for(auto& i : k) cin >> i;
vi dp(n),par(n,-1);
for(int i=0;i<n;++i) {
for(int j=0;j<i;++j) if(__builtin_popcount(a[i]&a[j])==k[i]){
dp[i] = max(dp[i],dp[j]);
}
for(int j=i-1;j>=0;--j) {
if(dp[i]==dp[j]) {
par[i]=j;
break;
}
}
dp[i]++;
}
auto it = max_element(all(dp));
int i = it-dp.begin();
cout << *it << '\n';
vi b;
while(i!=-1) {
b.push_back(i+1);
i=par[i];
}
reverse(all(b));
cout << b << '\n';
}
# | 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... |