이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 5e3 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 10000 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
int n, a[N], k[N], dp[N], p[N], mx = 0, st;
int main(){
speed;
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 = 1; i <= n; i++){
dp[i] = 1;
p[i] = -1;
for(int j = 1; j < i; j++){
int temp = (a[i] & a[j]);
if(__builtin_popcount(temp) == k[i] && dp[j] + 1 > dp[i]){
dp[i] = dp[j] + 1;
p[i] = j;
}
}
if(dp[i] > mx){
mx = dp[i];
st = i;
}
}
vector <int> ans;
while(st != -1){
ans.pb(st);
st = p[st];
}
reverse(all(ans));
cout << ans.size() << endl;
for(auto to : ans)
cout << to << " ";
}
/*
%I64d
%I64d
*/
# | 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... |