# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1157802 | jahongir | Longest beautiful sequence (IZhO17_subsequence) | C++20 | 2896 ms | 47208 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
template<class T> using ormset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define popcount __builtin_popcount
void setIO(string name = ""){
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr);
if(name.empty()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}else{
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
const int mxn = 1e5+10;
int ans[mxn], dp[1<<10][1<<10][11];
int par[mxn], a[mxn], k[mxn], ind;
void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++){
cin >> k[i];
int pref = a[i]>>10, suf = a[i]&((1<<10)-1);
ans[i] = 1;
//pull-dp
for(int j = 0; j < (1<<10); j++){
int need = k[i]-popcount(j&pref);
if(need < 0 || need > 10) continue;
if(ans[dp[j][suf][need]]+1 > ans[i]){
ans[i] = ans[dp[j][suf][need]]+1;
par[i] = dp[j][suf][need];
}
}
//push-dp
for(int j = 0; j < (1<<10); j++){
if(ans[dp[pref][j][popcount(j&suf)]] < ans[i]){
dp[pref][j][popcount(j&suf)] = i;
}
}
if(ans[ind] <= ans[i])
ind = i;
}
cout << ans[ind] << '\n';
vector<int> res;
while(ind){
res.pb(ind);
ind = par[ind];
}
reverse(all(res));
for(auto x : res) cout << x << ' ';
}
int main(){
// setIO("subsequence");
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |