This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author : pham van sam
* created : 16 June 2023 (Friday)
**/
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 1e5 + 5;
int N, a[MAXN], b[MAXN], dp[MAXN], trace[MAXN];
int f[MASK(10)][MASK(10)][11];
void process(void) {
cin >> N;
FOR(i, 1, N) cin >> a[i];
FOR(i, 1, N) cin >> b[i];
int ans = 0, id;
FOR(i, 1, N) {
int fi = a[i] >> 10, se = a[i] & (MASK(10) - 1); // the first and second 10 bits of a[i]
REP(mask, MASK(10)) {
int want = b[i] - __builtin_popcount(mask & fi);
if(want < 0 || want > 10) continue;
if(maximize(dp[i], dp[f[mask][se][want]] + 1)) {
trace[i] = f[mask][se][want];
}
}
REP(mask, MASK(10)) {
if(dp[f[fi][mask][__builtin_popcount(mask & se)]] < dp[i]) {
f[fi][mask][__builtin_popcount(mask & se)] = i;
}
}
if(maximize(ans, dp[i])) id = i;
}
cout << ans << '\n';
stack <int> st;
while(id) {
st.push(id);
id = trace[id];
}
while(!st.empty()) cout << st.top() << " ", st.pop();
}
signed main() {
#define TASK "subsequence"
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);
auto start_time = steady_clock::now();
int test = 1;
// cin >> test;
for (int i = 1; i <= test; ++i) {
process();
// cout << '\n';
}
auto end_time = steady_clock::now();
cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp: In function 'void process()':
subsequence.cpp:53:22: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | id = trace[id];
| ~~~~~~~~^
# | 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... |