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 lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#define test(x...) abc("[" + string(#x) + "]", x);
const int N = 200000;
int bucket[1 << 10][11][1 << 10];
int main () {
freopen("input.txt", "r", stdin);
int n;
cin >> n;
vector <int> a(n), k(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> k[i];
vector <int> dp(n, 1), bck(n, -1);
auto upd = [&](int &i, int j) {
if (i == -1)
i = j;
else if (dp[i] < dp[j])
i = j;
};
for (int s = 0; s < 1 << 10; ++s) for (int i = 0; i < 10; ++i) for (int t = 0; t < 1 << 10; ++t)
bucket[s][i][t] = -1;
for (int i = 0; i < n; ++i) {
for (int s = 0; s < 1 << 10; ++s) for (int j = 0; j < 10; ++j) {
if (__builtin_popcount(s & (a[i] >> 10)) != k[i] - j)
continue;
int x = bucket[a[i] & 1023][j][s];
if (x != -1 && dp[i] < dp[x] + 1)
dp[i] = dp[x] + 1, bck[i] = x, test(i, s, j);
}
for (int s = 0; s < 1 << 10; ++s) {
upd(bucket[s][__builtin_popcount(s & a[i])][a[i] >> 10], i);
}
}
printv(all(dp));
int mx = max_element(all(dp)) - dp.begin();
cout << dp[mx] << endl;
vector <int> ans;
while (mx != -1) {
ans.pb(mx + 1);
mx = bck[mx];
}
reverse(all(ans));
printv(all(ans));
for (int i = 1; i < ans.size(); ++i) {
if (__builtin_popcount(a[ans[i - 1] - 1] & a[ans[i] - 1]) != k[ans[i] - 1])
cout << "fail\n" << i << endl;
}
}
/*
5
5 3 5 3 5
10 1 20 1 20
4
1 2 3 4
10 0 1 0
*/
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 1; i < ans.size(); ++i) {
| ~~^~~~~~~~~~~~
subsequence.cpp:26:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |