#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FOD(i,a,b) for(int i = a; i >= b; i--)
//#define int long long
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define db double
#define lcm(a,b) a / __gcd(a, b) * b
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define iv pair<pair<int,int>,pair<int,int>>
#define sq(a) (a) * (a)
#define MASK(i) (1LL << i)
#define task "task"
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
const int B = 10;
int n;
int a[N], k[N], trace[N], cnt[MASK(B) + 5];
ii dp[MASK(B) + 5][MASK(B) + 5][B + 5];
void Solve() {
FOR(mask, 0, MASK(B) - 1) cnt[mask] = __builtin_popcount(mask);
FOR(i, 1, n) {
ii cur = {1, i};
int l = (a[i] & (MASK(B) - 1));
int r = a[i] >> B;
FOR(mask, 0, (1 << B) - 1) {
int tmp = k[i] - cnt[mask & l];
if(tmp >= 0 && tmp <= B) {
ii st = dp[mask][r][tmp];
if(st.fi + 1 > cur.fi) {
cur.fi = st.fi + 1;
trace[i] = st.se;
}
}
}
FOR(mask, 0, MASK(B) - 1) {
if(cur.fi > dp[l][r][cnt[r]].fi) dp[l][r][cnt[r]] = cur;
}
}
vector<int> pos;
int ans = 0, best;
FOR(l, 0, MASK(B) - 1) {
FOR(r, 0, MASK(B) - 1) {
FOR(k, 0, 10) {
if(ans < dp[l][r][k].fi) {
ans = dp[l][r][k].fi;
best = dp[l][r][k].se;
}
}
}
}
cout << ans << '\n';
while(best != 0) {
pos.pb(best);
best = trace[best];
}
reverse(pos.begin(), pos.end());
for(int p : pos) cout << p << ' ';
}
signed main() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) {
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> k[i];
Solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
subsequence.cpp: In function 'int main()':
subsequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |