Submission #1000291

#TimeUsernameProblemLanguageResultExecution timeMemory
1000291HanksburgerLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
0 ms348 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]; if (n<=5000) { for (int i=1; i<=n; i++) { dp[i]=1; for (int j=1; j<i; j++) { if (bitCount(a[i], a[j])==k[i]) { if (dp[i]<dp[j]+1) { dp[i]=dp[j]+1; pre[i]=j; } } } if (mx<dp[i]) { mx=dp[i]; cur=i; } } } else { 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:73:24: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     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...