Submission #867481

#TimeUsernameProblemLanguageResultExecution timeMemory
867481Halym2007Longest beautiful sequence (IZhO17_subsequence)C++11
0 / 100
1 ms2396 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 int a[N], k[N], dp[N], jogap, n, par[N], idx; vector <int> cykar; int main () { // freopen("subsequence.in", "r", stdin); // freopen("subsequence.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); 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) { dp[i] = 1; par[i] = i; for (int j = i - 1; j > 0; j--) { int x = a[j] & a[i]; if (__builtin_popcount(x) == k[i]) { if (dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; par[i] = j; break; } } } if (jogap < dp[i]) { jogap = dp[i]; idx = i; } } 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...