Submission #1108839

#TimeUsernameProblemLanguageResultExecution timeMemory
1108839dubabubaLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 5050; int a[mxn], dp[mxn]; int b[mxn], pr[mxn]; int n; int main() { // #ifndef LOCAL freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); // #endif cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; int id = 1; for(int i = 1; i <= n; i++) { dp[i] = 1; for(int j = 1; j < i; j++) { int t = a[i] & a[j]; if(__builtin_popcount(t) != b[i]) continue; if(dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; pr[i] = j; } } if(dp[id] < dp[i]) id = i; } vector<int> ind; while(id) { ind.push_back(id); id = pr[id]; } reverse(ind.begin(), ind.end()); // if(ind.size()) return 1; cout << (int)ind.size() << endl; for(int i : ind) cout << i << ' '; cout << endl; return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen("subsequence.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen("subsequence.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...