Submission #502599

#TimeUsernameProblemLanguageResultExecution timeMemory
502599AktanLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms420 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define int long long #define ft first #define sc second using namespace std; const int mod=1e9+7,INF=1e17,N=1e5; int a[5005],b[5005]; vector<int> dp[5005]; main(){ int n; cin >> n; for(int i=1;i<=n;i++){ cin >> a[i]; } for(int i=1;i<=n;i++){ cin >> b[i]; } int ans=-1; dp[1].push_back(1); int m=0,e=-1; for(int i=1;i<=n;i++){ bool h=0; for(int j=i-1;j>=1;j--){ if(__builtin_popcount(a[i]&a[j])==b[i] && dp[j].size()>dp[i].size()){ h=1; dp[i]=dp[j]; dp[i].push_back(i); } } if(dp[i].empty()){ dp[i].push_back(i); } if(dp[i].size()>m){ m=dp[i].size(); e=i; } } cout << dp[e].size() << endl; for(auto x : dp[e]){ cout << x << " "; } }

Compilation message (stderr)

subsequence.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
subsequence.cpp: In function 'int main()':
subsequence.cpp:38:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |   if(dp[i].size()>m){
      |      ~~~~~~~~~~~~^~
subsequence.cpp:27:8: warning: variable 'h' set but not used [-Wunused-but-set-variable]
   27 |   bool h=0;
      |        ^
subsequence.cpp:23:6: warning: unused variable 'ans' [-Wunused-variable]
   23 |  int ans=-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...