이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define nl "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int N = 1e3 + 11;
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
int dp[N][N], p[N][N], a[N], k[N];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> k[i];
dp[1][i] = 1;
}
int len = n;
int ind = n;
for(int l = 2; l <= n; l++){
int ok = 0;
for(int i = l; i <= n; i++){
for(int j = 1; j < i; j++){
if(__builtin_popcount((a[i] & a[j])) == k[i]){
if(dp[l - 1][j]){
dp[l][i] = 1;
p[l][i] = j;
}
}
}
ok |= dp[l][i];
// cout << l << " " << i << " " << dp[l][i] << "\n";
if(dp[l][i]){
ind = i;
}
}
if(!ok){
len = l - 1;
break;
}
}
vector <int> ans;
while(len > 0){
ans.pb(ind);
ind = p[len][ind];
len--;
}
cout << sz(ans) << "\n";
reverse(all(ans));
for(int i = 0; i < sz(ans); i++){
cout << ans[i] << " ";
}
}
# | 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... |