제출 #1102099

#제출 시각아이디문제언어결과실행 시간메모리
1102099dead0neLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
149 ms262144 KiB
#pragma GCC optimize("unroll-loops,Ofast,O3") #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define spc << " " << #define endl "\n" #define all(x) x.begin(), x.end() #define int long long #define ii pair<long long,int> #define vi vector<int> #define vii vector<ii> #define st first #define nd second #define mid (l+r)/2 #define inf 1e15 #define MOD 1000000007 #define MX 1505 using namespace std; ii dp[1<<10][1<<10][20]; void solve(){ int n; cin >> n; int a[n], k[n]; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<n; i++) cin >> k[i]; for(int i=0; i<1<<10; i++) for(int j=0; j<1<<10; j++) for(int k=0; k<20; k++) dp[i][j][k]={0, -1}; int ans=0, bestie=0; int pre[n]; pre[0]=-1; for(int i=0; i<n; i++){ ii cur={a[i]>>10, a[i]&((1<<10)-1)}; int res=1; for(int j=0; j<1<<10; j++){ if(dp[j][cur.nd][k[i]-__builtin_popcount(cur.st&j)].st+1>res){ res = dp[j][cur.nd][k[i]-__builtin_popcount(cur.st&j)].st+1; pre[i] = dp[j][cur.nd][k[i]-__builtin_popcount(cur.st&j)].nd; } } if(res>ans){ ans=res; bestie=i; } for(int j=0; j<1<<10; j++){ if(res > dp[cur.st][j][__builtin_popcount(cur.nd&j)].st){ dp[cur.st][j][__builtin_popcount(cur.nd&j)].st = res; dp[cur.st][j][__builtin_popcount(cur.nd&j)].nd = i; } } } cout << ans << endl; vi wow; while(bestie>-1){ wow.pb(bestie); bestie=pre[bestie]; } for(int i=wow.size()-1; i>=0; i--) cout << wow[i]+1 << " "; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif /*freopen(".in","r",stdin); freopen(".out","w",stdout);*/ int t=1; //cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...