이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 510;
const int N2 = N * N;
const int PW = 20;
const int oo = 2e9;
vector<int> vc;
int n, a[N], k[N], f[N], ans, nm;
bool ok(int x, int y, int vl){
return (__builtin_popcount(a[x] & a[y]) == k[vl]);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> k[i];
for (int i = 0; i < n; i++){
f[i] = 1;
for (int j = i - 1; j >= 0; j--)
if (ok(j, i, f[j]))
f[i] = max(f[i], f[j] + 1);
if (ans < f[i]){
ans = f[i];
nm = i;
}
}
cout << ans << '\n';
vc.clear();
for (int i = nm; ;){
vc.PB(i);
if (f[i] == 1) break;
for (int j = i - 1; ; j--)
if (f[j] + 1 == f[i] && ok(j, i, f[j])){
i = j;
break;
}
}
reverse(all(vc));
for (int x : vc)
cout << x + 1 << " ";
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... |