(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 #343667

#TimeUsernameProblemLanguageResultExecution timeMemory
343667GurbanLongest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
3545 ms93868 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn=1e5+5; const int B = (1<<10); int n,k[maxn],a[maxn],p[B],pos; pair<int,int>dp[maxn],jog[B][B][11]; vector<int>v; int main(){ ios::sync_with_stdio(false); cin.tie(0); for(int i = 0;i < B;i++) p[i] = __builtin_popcount(i); memset(jog,-1,sizeof(jog)); cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; for(int i = 1;i <= n;i++) cin >> k[i]; for(int i = 1;i <= n;i++){ int lf = (a[i]>>10); int rg = a[i] - (lf<<10); dp[i] = {1,-1}; for(int j = 0;j < B;j++){ int lp = p[j & lf]; if(lp <= k[i] and lp+10 >= k[i] and jog[j][rg][k[i]-lp].first + 1 > dp[i].first){ dp[i] = jog[j][rg][k[i]-lp]; dp[i].first++; } } if(dp[pos].first < dp[i].first) pos = i; for(int j = 0;j < B;j++){ int lp = p[rg & j]; if(jog[lf][j][lp].first < dp[i].first) jog[lf][j][lp] = {dp[i].first,i}; } } cout<<dp[pos].first<<'\n'; while(pos != -1){ v.push_back(pos); pos = dp[pos].second; } reverse(v.begin(),v.end()); for(auto i : v) cout<<i<<' '; } /* 4 1 2 3 4 10 0 1 0 2 8 9 20 0 5 5 3 5 3 5 10 1 20 1 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...