Submission #314923

#TimeUsernameProblemLanguageResultExecution timeMemory
314923dolphingarlicLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
8 ms1792 KiB
#include <bits/stdc++.h> using namespace std; const int FM = (1 << 20) - 1, HM = (1 << 10) - 1; int a[100001], k[100001]; pair<int, int> dp[1 << 10][1 << 10][11], ans[100001]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) { scanf("%d", k + i); pair<int, int> best = {0, 0}; for (int j = 0; j < (1 << 10); j++) if (__builtin_popcount(a[i] & j) <= k[i]) best = max(best, dp[j][a[i] >> 10][k[i] - __builtin_popcount(a[i] & j)]); best.first++; ans[i] = best; for (int j = 0; j < (1 << 10); j++) { int cnt = __builtin_popcount((a[i] >> 10) & j); dp[a[i] & HM][j][cnt] = max(dp[a[i] & HM][j][cnt], {best.first, i}); } } int best_idx = max_element(ans + 1, ans + n + 1) - ans; printf("%d\n", ans[best_idx].first); stack<int> seq; while (best_idx) { seq.push(best_idx); best_idx = ans[best_idx].second; } while (seq.size()) { printf("%d ", seq.top()); seq.pop(); } }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
subsequence.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     for (int i = 1; i <= n; i++) scanf("%d", a + i);
      |                                  ~~~~~^~~~~~~~~~~~~
subsequence.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         scanf("%d", k + 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...