# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269058 | Thanhs | Longest beautiful sequence (IZhO17_subsequence) | C++20 | 4074 ms | 174468 KiB |
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 1e5 + 5;
const int ALL = 1 << 10;
int n, a[NM], b[NM], f[NM], tr[NM];
pair<int, int> F[1024][1024][21];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
{
f[i] = 1;
cin >> b[i];
int x = a[i] >> 10, y = a[i] & (ALL - 1);
for (int j = 0; j < ALL; j++)
{
int t = b[i] - (int)__builtin_popcount(x & j);
if (t < 0)
continue;
if (f[i] < F[j][y][t].fi)
{
f[i] = F[j][y][t].fi;
tr[i] = F[j][y][t].se;
}
}
for (int j = 0; j < ALL; j++)
setmax(F[x][j][__builtin_popcount(y & j)], make_pair(f[i] + 1, i));
}
pair<int, int> t = {0, 0};
for (int i = 1; i <= n; i++)
setmax(t, make_pair(f[i], i));
cout << t.fi << endl;
int cr = t.se;
vector<int> ans;
while (cr)
{
ans.push_back(cr);
cr = tr[cr];
}
reverse(all(ans));
for (int t : ans)
cout << t << ' ';
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
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... |