Submission #824086

#TimeUsernameProblemLanguageResultExecution timeMemory
824086phiLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
76 ms172656 KiB
#include <iostream> #include <vector> #include <array> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> k(n); for (int i = 0; i < n; i++) cin >> k[i]; constexpr int mk = 20; constexpr int b = mk / 2; constexpr int mask = (1 << b) - 1; array<array<array<int, mk + 1>, 1 << b>, 1 << b> dp = {}; array<array<array<int, mk + 1>, 1 << b>, 1 << b> current = {}; vector<int> prev(n); int ans = -1; int end; for (int i = 0; i < n; i++) { int lbs = 1; int p = -1; for (int j = 0; j < (1 << b); j++) { if (k[i] < __builtin_popcount(j & a[i])) continue; int c = dp[j][a[i] >> b][k[i] - __builtin_popcount(j & a[i])]; if (lbs < c + 1) { lbs = c + 1; p = current[j][a[i] >> b][k[i] - __builtin_popcount(j & a[i])]; } } for (int j = 0; j < (1 << b); j++) { int c = __builtin_popcount(j & (a[i] > b)); if (dp[a[i] & mask][j][c] < lbs) { dp[a[i] & mask][j][c] = lbs; current[a[i] & mask][j][c] = i; } } prev[i] = p; if (lbs > ans) { ans = lbs; end = i; } } vector<int> arr; while (end != -1) { arr.push_back(end + 1); end = prev[end]; } cout << arr.size() << "\n"; for (int i = arr.size() - 1; i >= 0; i--) cout << arr[i] << " \n"[i == 0]; return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:59:27: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |         arr.push_back(end + 1);
      |                       ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...