# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344005 | KWang31 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 191 ms | 158444 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |