This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)
using namespace std;
const int N = 1e5 + 7;
const int W = 3e5 + 7;
const int maxA = 1e5 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 998244353;
const ld eps = 1e-9;
pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start = clock();
//#define int long long
int n, a[N], k[N], p[N];
pii dp[(1ll << 10)][(1ll << 10)][21];//[0, 9], [10, 19]
void solve() {
cin >> n;
for (int i = 1;i <= n;i++)cin >> a[i];
for (int i = 1;i <= n;i++)cin >> k[i];
int mx = 0, pos = 0;
for (int i = 1;i <= n;i++) {
int x = a[i] % (1ll << 10), y = (a[i] >> 10);
pii cur_dp = {1, 0};
for (int m1 = 0;m1 < (1ll << 10);m1++) {
int cnt = k[i] - bpop(m1 & x);
if (cnt < 0)skip;
cur_dp = max(cur_dp, dp[m1][y][cnt]);
}
p[i] = cur_dp.y;
if (cur_dp.x > mx)mx = cur_dp.x, pos = i;
for (int m2 = 0;m2 < (1ll << 10);m2++) {
int cnt = bpop(y & m2);
dp[x][m2][cnt] = max(dp[x][m2][cnt], {cur_dp.x + 1, i});
}
}
vector <int> ans;
while (pos != 0)ans.pb(pos), pos = p[pos];
reverse(all(ans));
cout << sz(ans) << '\n';
for (auto i : ans)cout << i << ' ';
}
signed main() {
//srand(time(NULL));
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("subsequence.in", "r", stdin);
//freopen("subsequence.out", "w", stdout);
int test = 1;
//cin >> test;
for (int t = 1;t <= test;t++) {
//cout << "Case " << t << ": ";
solve();
}
return 0;
}
Compilation message (stderr)
subsequence.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
4 | #pragma comment(linker, "/stack:200000000")
|
# | 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... |