제출 #1126613

#제출 시각아이디문제언어결과실행 시간메모리
1126613brover29Longest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
2 ms320 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = int; const ll N=1e5+29; const string br="617283"; ll dp[N],a[N],k[N],n,opt[N],op; vector<ll>pos[257]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); freopen("subsequence.in","r",stdin); freopen("subsequence.out","w",stdout); cin>>n; for(ll i=1;i<=n;i++){ cin>>a[i]; }for(ll i=1;i<=n;i++){ cin>>k[i]; } ll ans=0; if(n<=5000){ for(ll i=1;i<=n;i++){ dp[i]=1; for(ll j=i-1;j>=0;j--){ if(__builtin_popcountll(a[i]&a[j])==k[i]){ dp[i]=max(dp[i],dp[j]+1); if(dp[i]==dp[j]+1)opt[i]=j; } } ans=max(ans,dp[i]); if(ans==dp[i])op=i; } }else{ for(ll i=1;i<=n;i++){ pos[a[i]].push_back(i); dp[i]=1; for(ll j=1;j<=256;j++){ if(__builtin_popcountll(j&a[i])==k[i]){ for(ll ii:pos[j]){ // if(i==3)cout<<(2&3)<<' '; if(dp[ii]+1>dp[i]){ dp[i]=dp[ii]+1; opt[i]=ii; } } } } ans=max(ans,dp[i]); if(ans==dp[i])op=i; } } cout<<ans<<'\n'; vector<ll>v; ll i=op; while(i){ v.push_back(i); i=opt[i]; } reverse(v.begin(),v.end()); for(ll i:v){ cout<<i<<' '; } }

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("subsequence.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     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...