Submission #1000288

#TimeUsernameProblemLanguageResultExecution timeMemory
1000288HanksburgerLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms604 KiB
#include <bits/stdc++.h> using namespace std; int dp[100005], pre[100005], a[100005], k[100005], ind[260]; stack<int> s; int bitCount(int x, int y) { int cnt=0; for (int i=0; i<8; i++) if (x&y&(1<<i)) cnt++; return cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, cur, mx=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; for (int j=0; j<256; j++) { if (ind[j] && bitCount(a[i], j)==k[i]) { if (dp[i]<dp[ind[j]]+1) { dp[i]=dp[ind[j]]+1; pre[i]=ind[j]; } } } if (mx<dp[i]) { mx=dp[i]; cur=i; } if (dp[ind[a[i]]]<dp[i]) ind[a[i]]=i; } cout << dp[cur] << '\n'; while (cur) { s.push(cur); cur=pre[cur]; } while (!s.empty()) { cout << s.top() << ' '; s.pop(); } }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:46:24: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     cout << dp[cur] << '\n';
      |                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...