Submission #343964

#TimeUsernameProblemLanguageResultExecution timeMemory
343964KWang31Longest beautiful sequence (IZhO17_subsequence)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <iostream> #define pb push_back using namespace std; const int MAX = 1 << 10; const int MAXN=100001; int a[MAXN]; int k[MAXN]; int prev[MAXN]; int ans[MAXN]; int main(){ int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);} int N; scanf("%d",&N); for(int i=0;i<N;i++){ scanf("%d",&a[i]); } for(int i=0;i<N;i++){ scanf("%d",&k[i]); } int M[MAX][MAX][11]; int ind[MAX][MAX][11]; for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) for(int k=0;k<11; k++) M[i][j][k]=-1; int q,z; int r=a[0]&(MAX-1); for(int i=0;i<N;i++) { q=a[i]>>10; r=a[i]&(MAX-1); ans[i]++; for(int j=0;j<MAX;j++) {//QUERY z=k[i]-btcnt[r&j]; if(z>=0 && z<=10 ) { //The first 10 bits have EXACTLY z bits in common if( M[q][j][z]+1>ans[i]) { ans[i]=M[q][j][z]+1; prev[i]=ind[q][j][z]; } } } //UPDATE for(int j=0;j<MAX;j++) { if(M[j][r][btcnt[j&q]]<ans[i]) { M[j][r][btcnt[j&q]]=ans[i]; ind[j][r][btcnt[j&q]]=i; } } } int mx=0; int cur=-1; for(int i=0;i<N;i++) { if(ans[i]>mx) { mx=ans[i]; cur=i; } } printf("%d\n", mx); vector<int> seq; seq.pb(cur+1); while(cur>0){ cur=prev[cur]; seq.pb(cur+1); } for (int i=mx-1; i>=0; i--){ printf("%d ", seq[i]); } return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:38:57: error: reference to 'prev' is ambiguous
   38 |                                    ans[i]=M[q][j][z]+1; prev[i]=ind[q][j][z];
      |                                                         ^~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:66,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from subsequence.cpp:1:
/usr/include/c++/9/bits/stl_iterator_base_funcs.h:224:5: note: candidates are: 'template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)'
  224 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
subsequence.cpp:8:31: note:                 'int prev [100001]'
    8 | int a[MAXN]; int k[MAXN]; int prev[MAXN]; int ans[MAXN];
      |                               ^~~~
subsequence.cpp:59:7: error: reference to 'prev' is ambiguous
   59 |   cur=prev[cur]; seq.pb(cur+1);
      |       ^~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:66,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from subsequence.cpp:1:
/usr/include/c++/9/bits/stl_iterator_base_funcs.h:224:5: note: candidates are: 'template<class _BidirectionalIterator> _BidirectionalIterator std::prev(_BidirectionalIterator, typename std::iterator_traits<_Iter>::difference_type)'
  224 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
subsequence.cpp:8:31: note:                 'int prev [100001]'
    8 | int a[MAXN]; int k[MAXN]; int prev[MAXN]; int ans[MAXN];
      |                               ^~~~
subsequence.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |  scanf("%d",&N);
      |  ~~~~~^~~~~~~~~
subsequence.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   scanf("%d",&a[i]);
      |   ~~~~~^~~~~~~~~~~~
subsequence.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d",&k[i]);
      |   ~~~~~^~~~~~~~~~~~