Submission #344007

#TimeUsernameProblemLanguageResultExecution timeMemory
344007KWang31Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
170 ms158444 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back const int MAX = 1 << 10; const int MAXN=100001; int a[MAXN]; int k[MAXN]; int ans[MAXN]; int q,z,r; int M[MAX][MAX][11]; int ind[MAX][MAX][11]; 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]); } 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 prev[N]; 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: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]);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...