Submission #1025249

#TimeUsernameProblemLanguageResultExecution timeMemory
1025249hasan2006Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
630 ms5200 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 1e5 + 9 , mod = 1e9 + 7; int a[N] , b[N] , dp[11][1 << 10][1 << 10][2] , c[N] , d[N] ; void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n; for(i = 1; i <= n; i++) cin>>a[i]; for(i = 1; i <= n; i++) cin>>b[i]; pair<int,int>p; for(i = 0; i < (1 << 10); i++) c[i] = __builtin_popcount(i); pair<int,int>ans = {-1, -1}; for(i = 1; i <= n; i++){ l = r= 0; x = 1 , y = 0; for(j = 0; j < 10; j++){ if((1 << j) & a[i]) l += (1 << j); if((1 << (j + 10)) & a[i]) r += (1 << j); } for(j = 0; j < (1 << 10); j++){ f = b[i] - c[l & j]; if(f < 0 || f > 10) continue; if(x < dp[f][j][r][0] + 1) x = dp[f][j][r][0] + 1 , y = dp[f][j][r][1]; } d[i] = y; for(j = 0; j < (1 << 10); j++){ f = c[r & j]; if(dp[f][l][j][0] < x) dp[f][l][j][0] = x , dp[f][l][j][1] = i; } if(ans.fi < x) ans = {x , i}; } vector<int>vc; while(ans.se){ vc.pb(ans.se); ans.se = d[ans.se]; } cout<<vc.size()<<"\n"; reverse(all(vc)); for(auto to : vc) cout<<to<<" "; } int main(){ TL; // #ifndef ONLINE_JUDGE freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); //#endif int t = 1; // cin>>t; while(t--) { solve(); } } // Author : حسن

Compilation message (stderr)

subsequence.cpp: In function 'void solve()':
subsequence.cpp:27:12: warning: unused variable 'q' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
subsequence.cpp:27:38: warning: unused variable 's' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
subsequence.cpp:27:50: warning: unused variable 'k' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                  ^
subsequence.cpp:27:54: warning: unused variable 'm' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                      ^
subsequence.cpp:27:58: warning: unused variable 'mn' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                          ^~
subsequence.cpp:27:69: warning: unused variable 'mx' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                                     ^~
subsequence.cpp: In function 'int main()':
subsequence.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen("subsequence.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         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...