Submission #343999

#TimeUsernameProblemLanguageResultExecution timeMemory
343999KWang31Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
188 ms158572 KiB
#include <bits/stdc++.h> #include <iostream> #define pb push_back using namespace std; const int MAX = 1 << 10; int main(){ int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);} int N; scanf("%d",&N);int a[N]; int k[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); int prev[N]; int ans[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:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%d",&N);int a[N]; int k[N];
      |  ~~~~~^~~~~~~~~
subsequence.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d",&a[i]);
      |   ~~~~~^~~~~~~~~~~~
subsequence.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   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...