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

#TimeUsernameProblemLanguageResultExecution timeMemory
334601amunduzbaevLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5629 ms48604 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ll long long #define ld long double #define pii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define prc(n) fixed << setprecision(n) #define count(x) __builtin_popcount(x) #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi acos(-1); const int inf = 1e9+7; const int N = 1e5+5; int n, a[N], k[N], par[N], dp[N]; int ddp[1024][1024][11]; void solve(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ cin>>k[i]; } memset(par, -1, sizeof(par)); for(int i=1;i<=n;i++){ int l = (a[i] >> 10); int r = (a[i] & 1023); int best = 0; for(int j=0;j<1024;j++){ int tmp = count(j & r); tmp = k[i] - tmp; if(tmp < 0 || tmp > 10) continue; if(dp[best] < dp[ddp[l][j][tmp]]) best = ddp[l][j][tmp]; } dp[i] = dp[best]+1; par[i] = best; for(int j=0;j<1024;j++){ int tmp = count(j & l); if(dp[i] > dp[ddp[j][r][tmp]]) ddp[j][r][tmp] = i; } } int mx = 1; for(int i=1;i <= n;i++){ if(dp[i] > dp[mx]) mx = i; } int start = mx; vector<int>way; while(start != 0){ way.pb(start); start = par[start]; } cout<<sz(way)<<"\n"; reverse(all(way)); for(auto x:way) cout<<x<<" "; cout<<"\n"; return; } /* 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 */ int main(){ fastios int t = 1; //cin>>t; while(t--) solve(); 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...