Submission #167750

#TimeUsernameProblemLanguageResultExecution timeMemory
167750abilLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
17 ms8824 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = ((1 << 20) + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); int a[100002], dp[100002], path[100002], k[100002], bit[N], ind[N]; 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]); } for(int i = 0;i < (1 << 20); i++){ bit[i] = __builtin_popcount(i); } for(int i = 1;i <= n; i++){ int mx = 1, id = 0; for(int j = 0;j < (1 << 20); j++){ if(bit[(j & a[i])] == k[i]){ if(dp[j] + 1 > mx){ mx = dp[j] + 1; id = ind[j]; } } } if(mx > dp[a[i]]){ dp[a[i]] = mx; path[i] = id; ind[a[i]] = i; } } int mx = 0, val; for(int i = 0; i < (1 << 20); i++){ if(dp[i] > mx){ mx = dp[i]; val = ind[i]; } } printf("%d\n", mx); vector<int > ans; while(val){ ans.pb(val); val = path[val]; } reverse(all(ans)); for(auto to : ans){ printf("%d ", to); } }

Compilation message (stderr)

subsequence.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
subsequence.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k[i]);
   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:48:10: warning: iteration 100002 invokes undefined behavior [-Waggressive-loop-optimizations]
   if(dp[i] > mx){
      ~~~~^
subsequence.cpp:47:19: note: within this loop
  for(int i = 0; i < (1 << 20); 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...