Submission #1294611

#TimeUsernameProblemLanguageResultExecution timeMemory
1294611LIALongest beautiful sequence (IZhO17_subsequence)C++17
Compilation error
0 ms0 KiB
//
// Created by liasa on 23/11/2025.
//
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define v vector
#define lp(i, s, e) for (int i = s; i < e; ++i)
#define pll pair<ll, ll>
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 << " ";
  }
}

Compilation message (stderr)

subsequence.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main() {
      | ^~~~
subsequence.cpp: In function 'int main()':
subsequence.cpp:9:18: error: 'll' was not declared in this scope; did you mean 'pll'?
    9 | #define pll pair<ll, ll>
      |                  ^~
subsequence.cpp:30:10: note: in expansion of macro 'pll'
   30 |   vector<pll> dp(mx, {-1, -1});
      |          ^~~
subsequence.cpp:9:24: error: template argument 1 is invalid
    9 | #define pll pair<ll, ll>
      |                        ^
subsequence.cpp:30:10: note: in expansion of macro 'pll'
   30 |   vector<pll> dp(mx, {-1, -1});
      |          ^~~
subsequence.cpp:30:13: error: template argument 1 is invalid
   30 |   vector<pll> dp(mx, {-1, -1});
      |             ^
subsequence.cpp:30:13: error: template argument 2 is invalid
subsequence.cpp:30:30: error: expression list treated as compound expression in initializer [-fpermissive]
   30 |   vector<pll> dp(mx, {-1, -1});
      |                              ^
subsequence.cpp:30:30: error: cannot convert '<brace-enclosed initializer list>' to 'int' in initialization
subsequence.cpp:35:11: error: invalid types 'int[long long int]' for array subscript
   35 |     if (dp[v].first == -1) {
      |           ^
subsequence.cpp:36:9: error: invalid types 'int[long long int]' for array subscript
   36 |       dp[v] = {1, i};
      |         ^
subsequence.cpp:39:31: error: invalid types 'int[long long int]' for array subscript
   39 |       if (ba[j][v] == kv && dp[j].first + 1 > dp[v].first) {
      |                               ^
subsequence.cpp:39:49: error: invalid types 'int[long long int]' for array subscript
   39 |       if (ba[j][v] == kv && dp[j].first + 1 > dp[v].first) {
      |                                                 ^
subsequence.cpp:40:11: error: invalid types 'int[long long int]' for array subscript
   40 |         dp[v].first = dp[j].first + 1;
      |           ^
subsequence.cpp:40:25: error: invalid types 'int[long long int]' for array subscript
   40 |         dp[v].first = dp[j].first + 1;
      |                         ^
subsequence.cpp:41:11: error: invalid types 'int[long long int]' for array subscript
   41 |         dp[v].second = i;
      |           ^
subsequence.cpp:42:19: error: invalid types 'int[long long int]' for array subscript
   42 |         pr[i] = dp[j].second;
      |                   ^
subsequence.cpp:45:17: error: invalid types 'int[long long int]' for array subscript
   45 |     if (ans < dp[v].first) {
      |                 ^
subsequence.cpp:46:15: error: invalid types 'int[long long int]' for array subscript
   46 |       ans = dp[v].first;
      |               ^