(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.

Submission #502286

#TimeUsernameProblemLanguageResultExecution timeMemory
502286Ronin13Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
2308 ms89344 KiB
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define pb push_back #define epb emplace_back #define inf 1e9+1 #define linf 1e18+1 using namespace std; int cnt[1025]; int dp[100001]; int dp2[100001]; int dp1[1025][1025][21]; void pre(){ for(int i=0;i<=1024;i++){ cnt[i]=__builtin_popcount(i); } } int main(){ pre(); int n;cin>>n; int a[n+1]; for(int i=1;i<=n;i++)cin>>a[i]; int k[n+1]; for(int i=1;i<=n;i++){ cin>>k[i]; } for(int i=1;i<=n;i++){ int x=0,y=0; y=a[i]%1024; x=a[i]/1024; for(int j=0;j<1024;j++){ int t=y&j; t=cnt[t]; int v=dp1[j][x][k[i]-t]; if(dp[i]<dp[v]+1)dp[i]=dp[v]+1,dp2[i]=v; } for(int j=0;j<1024;j++){ int t=x&j; t=cnt[t]; int v=dp1[y][j][t]; if(dp[i]>dp[v])dp1[y][j][t]=i; } } int mx=-1; int mxi; for(int i=1;i<=n;i++){ if(dp[i]>mx)mx=dp[i],mxi=i; } vector<int>vec; while(mxi){ vec.pb(mxi); mxi=dp2[mxi]; } cout<<vec.size()<<"\n"; reverse(vec.begin(),vec.end()); for(int to:vec){ cout<<to<<' '; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...