Submission #685429

#TimeUsernameProblemLanguageResultExecution timeMemory
685429dostigatorLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(),a.end() #define pb push_back #define vt vector #define endl '\n' #define Y second #define X first typedef long long ll; typedef long double ld; const ll mod=1e9+7; const ll INF=1e18; const int inf=1e9; const int N=2e6+505; const int M=3e3+10; const int dx[]={0,0,1,-1}; const int dy[]={1,-1,0,0}; /*From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH*/ int n,a[N],k[N]; int dp[N],pr[N],pos[N]; void solve(){ cin>>n; for(int i=0; i<=256; ++i){ pos[i]=-1; pr[i]=-1; } for(int i=1; i<=n; ++i){ cin>>a[i]; dp[i]=1; }for(int i=1; i<=n; ++i)cin>>k[i]; int ans=1,r=1; for(int i=1; i<=n; ++i){ for(int x=0; x<=256; ++x){ if(__builtin_popcount(a[i]&x)==k[i] && pos[x]!=-1){ int ps=pos[x]; dp[i]=max(dp[i],dp[ps]+1); if(dp[i]==dp[ps]+1)pr[i]=ps; ans=max(ans,dp[i]); if(ans==dp[i])r=i; } }pos[a[i]]=i; }cout<<ans<<endl; vt<int>lst; while(r!=-1){ lst.pb(r); r=pr[r]; }if(ans!=lst.size())cout<<1/0; reverse(all(lst)); for(int x:lst){ cout<<x<<' '; }cout<<endl; } int main(){ //srand(time(0)); //freopen("hotel.in","r",stdin); //freopen("hotel.out","w",stdout); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int tt=1,lolol=0; // cin>>tt; while(tt--) { //cout<<"Case "<<++lolol<<": "; solve(); } }

Compilation message (stderr)

subsequence.cpp: In function 'void solve()':
subsequence.cpp:58:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  }if(ans!=lst.size())cout<<1/0;
      |      ~~~^~~~~~~~~~~~
subsequence.cpp:58:29: warning: division by zero [-Wdiv-by-zero]
   58 |  }if(ans!=lst.size())cout<<1/0;
      |                            ~^~
subsequence.cpp: In function 'int main()':
subsequence.cpp:70:11: warning: unused variable 'lolol' [-Wunused-variable]
   70 |  int tt=1,lolol=0;
      |           ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...