Submission #867506

#TimeUsernameProblemLanguageResultExecution timeMemory
867506Halym2007Longest beautiful sequence (IZhO17_subsequence)C++11
23 / 100
6045 ms5260 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5 + 5; #define pb push_back #define sz size() #define ff first #define ss second #define birlarysana __builtin_popcount int a[N], k[N], dp[N], jogap, n, par[N], idx; vector <int> cykar; vector <pair <int, int>> v[25]; int main () { // freopen("subsequence.in", "r", stdin); // freopen("subsequence.out", "w", stdout); // freopen("input.txt", "r", stdin); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n; int git = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { cin >> k[i]; } jogap = 1; idx = 1; for (int i = 1; i <= n; ++i) { dp[i] = 1; par[i] = i; if (birlarysana(a[i]) < k[i]) { v[birlarysana(a[i])].pb ({a[i], i}); git = max (birlarysana(a[i]), git); continue; } for (int j = k[i]; j <= git; ++j) { if (v[j].empty()) continue; for (pair <int, int> jj : v[j]) { int x = jj.ff & a[i]; if (birlarysana(x) == k[i]) { if (dp[i] < dp[jj.ss] + 1) { dp[i] = dp[jj.ss] + 1; par[i] = jj.ss; } } } } if (jogap < dp[i]) { jogap = dp[i]; idx = i; } v[birlarysana(a[i])].pb ({a[i], i}); git = max (birlarysana(a[i]), git); } cout << jogap << "\n"; while (1) { cykar.pb (idx); if (idx == par[idx]) break; idx = par[idx]; } reverse(cykar.begin(), cykar.end()); for (int i : cykar) { cout << 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...