Submission #1294607

#TimeUsernameProblemLanguageResultExecution timeMemory
1294607LIALongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms580 KiB
//
// Created by liasa on 23/11/2025.
//
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define v vector
#define lp(i, s, e) for (int i = s; i < e; ++i)
#define pll pair<ll, ll>
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int mx = 260;
  v<v<int>> ba(mx, v<int>(mx));

  lp(i, 0, mx) {
    lp(j, 0, mx) { ba[i][j] = __builtin_popcount(i & j); }
  }
  v<int> a(n), k(n);

  lp(i, 0, n) cin >> a[i];
  lp(i, 0, n) cin >> k[i];

  int ans = 1;
  v<int> pr(n);
  iota(pr.begin(), pr.end(), 0);

  vector<pll> dp(mx, {-1, -1});
  int best_idx = 0;
  lp(i, 0, n) {
    int v = a[i];
    int kv = k[i];
    if (dp[v].first == -1) {
      dp[v] = {1, i};
    }
    lp(j, 0, mx) {
      if (ba[j][v] == kv && dp[j].first + 1 > dp[v].first) {
        dp[v].first = dp[j].first + 1;
        dp[v].second = i;
        pr[i] = dp[j].second;
      }
    }
    if (ans < dp[v].first) {
      ans = dp[v].first;
      best_idx = i;
    }
  }

  cout << ans << '\n';
  vector<int> res;

  while (pr[best_idx] != best_idx) {
    res.push_back(best_idx);
    best_idx = pr[best_idx];
  }
  res.push_back(best_idx);
  reverse(res.begin(), res.end());
  for (int x : res) {
    cout << x + 1 << " ";
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...