# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699510 | nguyentunglam | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1751 ms | 43176 KiB |
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 fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N], bit[1 << 11], f[11][1 << 10][1 << 10], k[N], dp[N];
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int n; cin >> n;
for(int mask = 0; mask < (1 << 10); mask++) bit[mask] = __builtin_popcount(mask);
for(int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = (a[i] >> 10);
a[i] ^= (b[i] << 10);
}
int trace = 0;
for(int i = 1; i <= n; i++) {
cin >> k[i];
dp[i] = 1;
for(int j = 0; j < (1 << 10); j++) {
int x = bit[a[i] & j];
int y = k[i] - x;
if (y < 0 || y > 10) continue;
dp[i] = max(dp[i], f[y][j][b[i]] + 1);
}
for(int j = 0; j < (1 << 10); j++) {
int y = bit[b[i] & j];
f[y][a[i]][j] = max(f[y][a[i]][j], dp[i]);
}
if (dp[trace] < dp[i]) trace = i;
}
vector<int> ans;
ans.push_back(trace);
for(int i = trace - 1; i >= 1; i--) {
if (bit[a[i] & a[trace]] + bit[b[i] & b[trace]] == k[trace] && dp[i] + 1 == dp[trace]) {
ans.push_back(i);
trace = i;
}
}
cout << ans.size() << endl;
reverse(ans.begin(), ans.end());
for(int &j : ans) cout << j << " ";
}
Compilation message (stderr)
# | 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... |