This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* CODE BELOW */
const int N = 1e5 + 7, M = 10;
const int oo = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, m, k, t;
int _dp[MASK(M)][MASK(M)][M+1];
int pos[MASK(M)][MASK(M)][M+1];
int trace[N], a[N], b[N];
int cnt[MASK(M)];
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d", &n);
for(int i=1;i<=n;i++) {
scanf("%d", &a[i]);
}
for(int i=1;i<=n;i++) {
scanf("%d", &b[i]);
}
for(int i=0;i<MASK(M);i++) {
cnt[i] = CNTBIT(i);
}
int ans = 0, ansIdx = 0;
for(int i=1;i<=n;i++) {
int pref = a[i]>>M;
int suff = a[i]&(MASK(M)-1);
int mx = 0, idx = 0;
for(int j=0;j<MASK(M);j++) {
int need = b[i] - cnt[pref&j];
if(need < 0 || need > M) continue;
if(mx <= _dp[j][suff][need]) {
mx = _dp[j][suff][need];
idx = pos[j][suff][need];
}
}
trace[i] = idx;
if((++mx) > ans) {
ans = mx, ansIdx = i;
}
for(int j=0;j<MASK(M);j++) {
int need = cnt[suff&j];
if(_dp[pref][j][need] < mx) {
_dp[pref][j][need] = mx;
pos[pref][j][need] = i;
}
}
}
vector<int> result;
while(ansIdx) {
result.pb(ansIdx);
ansIdx = trace[ansIdx];
}
reverse(all(result));
printf("%d\n", ans);
for(int v:result) printf("%d ", v);
return 0;
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
subsequence.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
subsequence.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |