(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

제출 #89990

#제출 시각아이디문제언어결과실행 시간메모리
89990Bodo171Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
4706 ms219768 KiB
#include <iostream> #include <fstream> #include <vector> #include <algorithm> using namespace std; const int nmax=(1<<17); const int valmax=(1<<20)+1; const int lim=(1<<10); const int zr=20; vector<int> seq; int dp[valmax][42]; int v[nmax],k[nmax],best[nmax]; int pc[(1<<20)+5]; int n,i,j,ans,curr; void ins(int x,int val) { for(int i=0;i<lim;i++) dp[(x^i)][pc[i]-pc[x]+zr]=max(dp[(x^i)][pc[i]-pc[x]+zr],val); } int gt(int x,int b,int btot) { int ret=0; for(int i=0;i<lim;i++) if(btot-pc[i]-2*b+zr>=0&&btot-pc[i]-2*b+zr<=40) ret=max(ret,dp[(x^(i<<10))][btot-pc[i]-2*b+zr]); return ret; } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n; for(i=1;i<(1<<20);i++) pc[i]=pc[(i&(i-1))]+1; for(i=1;i<=n;i++) { cin>>v[i]; } for(i=1;i<=n;i++) { cin>>k[i]; } for(int cnt=1;cnt<=n;cnt++) { best[cnt]=gt(v[cnt],k[cnt],pc[v[cnt]])+1; ins(v[cnt],best[cnt]); ans=max(ans,best[cnt]); if(ans==best[cnt]) curr=cnt; } cout<<ans<<'\n'; seq.push_back(curr); int act=curr; for(i=act-1;i>=1;i--) { if(best[i]==best[curr]-1&&pc[(v[i]&v[curr])]==k[curr]) { seq.push_back(i); curr=i; } } reverse(seq.begin(),seq.end()); for(int i=0;i<seq.size();i++) cout<<seq[i]<<' '; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<seq.size();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...