# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700967 | messiuuuuu | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 22 ms | 41328 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 task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;
int n;
int a[MAXN], k[MAXN];
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> k[i];
}
int f[1 << 10][1 << 10][11], dp[MAXN], trace[MAXN];
void Solve()
{
for (int i = 1; i <= n; i++)
{
int prei = a[i] & 1023;
int sufi = a[i] >> 10;
dp[i] = 1;
for (int suf = 0; suf < (1 << 10); suf++)
{
if (__builtin_popcount(suf & sufi) <= k[i] && dp[f[prei][suf][k[i] - __builtin_popcount(suf & sufi)]] + 1 > dp[i])
{
dp[i] = dp[f[prei][suf][k[i] - __builtin_popcount(suf & sufi)]] + 1;
trace[i] = f[prei][suf][k[i] - __builtin_popcount(suf & sufi)];
}
}
for (int pre = 0; pre < (1 << 10); pre++)
{
if (dp[f[pre][sufi][__builtin_popcount(pre & prei)]] < dp[i])
{
f[pre][sufi][__builtin_popcount(pre & prei)] = i;
}
}
}
int p = max_element(dp + 1, dp + n + 1) - dp;
cout << dp[p] << '\n';
vector<int> res;
while (p)
{
res.pb(p);
p = trace[p];
}
reverse(res.begin(), res.end());
for (int x : res)
cout << x << ' ';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
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... |