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>
#define pb push_back
#define F first
#define S second
#define ll long long
#define it int
#define ld long double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
const int M = 1e9 + 7;
const int N = 1e5 + 7;
it n, x[N], k[N], kol[(1<<10)], dp[(1<<10)][(1<<10)][11], pr[(1<<10)][(1<<10)][11], ans = 0, pos = 0;
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
vector<it> p(N, 0), res(N, 1);
cin >> n;
for (it i = 1; i <= n; i++)
cin >> x[i];
for (it i = 1; i <= n; i++)
cin >> k[i];
for (size_t i = 1; i <= n; i++){
it a = (x[i]>>10);
it b = x[i] - (a<<10);
for (size_t j = 0; j < 1024; j++){
it need = k[i] - __builtin_popcount(b&j);
if (need >= 0 && need <= 10 && dp[a][j][need] + 1 > res[i])
res[i] = dp[a][j][need] + 1, p[i] = pr[a][j][need];
}
for (size_t j = 0; j < 1024; j++){
it cur = __builtin_popcount(a&j);
if (dp[j][b][cur] < res[i])
dp[j][b][cur] = res[i], pr[j][b][cur] = i;
}
if (res[i] > ans)
ans = res[i], pos = i;
}
vector<it> path;
while (pos){
path.pb(pos);
pos = p[pos];
}
reverse(path.begin(), path.end());
cout << path.size() << endl;
for (auto itt : path) cout << itt << ' ';
return 0;
}
Compilation message (stderr)
subsequence.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
subsequence.cpp: In function 'int main()':
subsequence.cpp:35:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (size_t i = 1; i <= n; 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... |