Submission #952921

#TimeUsernameProblemLanguageResultExecution timeMemory
952921NeroZeinLongest beautiful sequence (IZhO17_subsequence)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int M = 1 << 10; 
const int N = 1e5 + 5; 

int count[M];
int a[N], k[N];
int dp[N], pre[N];
int best[M][M][22], id[M][M][22];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  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 < M; ++i) {
    count[i] = cnt[i / 2] + (i & 1); 
  }
  for (int i = 1; i <= n; ++i) {
    dp[i] = 1; 
    for (int x = 0; x < M; ++x) {//fix first 10 bits.
      int t = k[i] - count[a[i] & x];
      if (t < 0 || t > 10) continue; 
      int suf = a[i] >> 10;
      if (best[x][suf][t] >= dp[i]) {
        dp[i] = best[x][suf][t] + 1;
        pre[i] = id[x][suf][t];
      }
    }
    for (int suf = 0; suf < M; ++suf) {
      int pref = a[i] & (M - 1);
      int cnt = count[(a[i] >> 10) & suf];
      if (dp[i] > best[pref][suf][cnt]) {
        id[pref][suf][cnt] = i; 
        best[pref][suf][cnt] = dp[i]; 
      }
    }
  }
  int ind = max_element(dp + 1, dp + 1 + n) - dp;
  vector<int> seq;
  while (ind) {
    seq.push_back(ind); 
    ind = pre[ind]; 
  }
  reverse(seq.begin(), seq.end()); 
  cout << seq.size() << '\n';
  for (int i : seq) {
    cout << i << ' ';
  }
  return 0;
}

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:30:5: error: reference to 'count' is ambiguous
   30 |     count[i] = cnt[i / 2] + (i & 1);
      |     ^~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4077:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4077 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
subsequence.cpp:13:5: note:                 'int count [1024]'
   13 | int count[M];
      |     ^~~~~
subsequence.cpp:30:16: error: 'cnt' was not declared in this scope; did you mean 'int'?
   30 |     count[i] = cnt[i / 2] + (i & 1);
      |                ^~~
      |                int
subsequence.cpp:35:22: error: reference to 'count' is ambiguous
   35 |       int t = k[i] - count[a[i] & x];
      |                      ^~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4077:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4077 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
subsequence.cpp:13:5: note:                 'int count [1024]'
   13 | int count[M];
      |     ^~~~~
subsequence.cpp:45:17: error: reference to 'count' is ambiguous
   45 |       int cnt = count[(a[i] >> 10) & suf];
      |                 ^~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from subsequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4077:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4077 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
subsequence.cpp:13:5: note:                 'int count [1024]'
   13 | int count[M];
      |     ^~~~~