이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int a[MAXN], k[MAXN], n;
int dp[MAXN], aux[MAXN], prv[MAXN], pos[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> k[i];
memset(aux, -1, sizeof(aux));
memset(prv, -1, sizeof(prv));
for (int i = 0; i < n; i++){
for (int j = 0; j < 256; j++){
if (__popcount(a[i]&j) == k[i] && ckmax(dp[i], aux[j] + 1)){
prv[i] = pos[j];
}
}
if (ckmax(aux[a[i]], dp[i])){
pos[a[i]] = i;
}
}
int mx = *max_element(dp, dp + n);
vector<int> ans;
for (int i = 0; i < n; i++){
if (dp[i] == mx){
int cur = i;
while (prv[cur] != -1){
ans.pb(cur);
cur = prv[cur];
}
ans.pb(cur);
break;
}
}
reverse(all(ans));
cout << mx + 1 << endl;
for (auto it : ans)
cout << it + 1 << ' ';
cout << endl;
}
# | 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... |