Submission #38250

#TimeUsernameProblemLanguageResultExecution timeMemory
38250antimirageLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
0 ms3580 KiB
#include <iostream> #include <vector> #include <deque> #include <math.h> #include <set> #include <iomanip> #include <time.h> #include <list> #include <stdio.h> #include <queue> #include <map> #include <algorithm> #include <assert.h> #include <memory.h> #define mk make_pair #define sc second #define fr first #define pb emplace_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) using namespace std; const int N = 1e5 + 5; int n, a[N], b[N], dp[N], ans, p[N], res; int mx[500]; vector <int> path; main () { cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { scanf("%d", &b[i]), dp[i] = 1; if (!mx[ a[i] ]) mx[ a[i] ] = i; } for (int i = 1; i <= n; i++) { for (int j = 0; j < 256; j++) { if ( __builtin_popcount(a[i] & j) == b[i] ) { if (dp[i] < dp[ mx[j] ] + 1) { p[i] = mx[j]; dp[i] = dp[ mx[j] ] + 1; } } } if ( dp[ mx[a[i]] ] < dp[i] ) mx[ a[i] ] = i; } for (int i = 1; i <= n; i++) { if (dp[i] > ans) { ans = dp[i]; res = i; } } cout << ans << endl; while (res) { path.pb( res ); res = p[res]; } reverse(all(path)); for (auto x : path) printf("%d ", x); } /** 4 1 2 3 4 10 0 1 0 **/

Compilation message (stderr)

subsequence.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:37:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
subsequence.cpp:41:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b[i]), dp[i] = 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...